moved tool enum to a Tool class

Code cleanup and improvement.
This commit is contained in:
itsmattkc
2019-12-26 17:35:25 +11:00
parent d140094cf5
commit bb9284a894
9 changed files with 92 additions and 95 deletions
+3 -3
View File
@@ -54,7 +54,7 @@ Core olive::core;
Core::Core() :
main_window_(nullptr),
tool_(olive::tool::kPointer),
tool_(Tool::kPointer),
snapping_(true),
queue_autorecovery_(false)
{
@@ -141,7 +141,7 @@ void Core::ImportFiles(const QStringList &urls, ProjectViewModel* model, Folder*
olive::task_manager.AddTask(std::make_shared<ImportTask>(model, parent, urls));
}
const olive::tool::Tool &Core::tool()
const Tool::Item &Core::tool()
{
return tool_;
}
@@ -171,7 +171,7 @@ void Core::StartModalTask(Task *t)
}
}
void Core::SetTool(const olive::tool::Tool &tool)
void Core::SetTool(const Tool::Item &tool)
{
tool_ = tool;
+4 -4
View File
@@ -87,7 +87,7 @@ public:
/**
* @brief Get the currently active tool
*/
const olive::tool::Tool& tool();
const Tool::Item& tool();
/**
* @brief Get current snapping value
@@ -165,7 +165,7 @@ public slots:
*
* @param tool
*/
void SetTool(const olive::tool::Tool& tool);
void SetTool(const Tool::Item& tool);
/**
* @brief Set the current snapping setting
@@ -220,7 +220,7 @@ signals:
/**
* @brief Signal emitted when the tool is changed from somewhere
*/
void ToolChanged(const olive::tool::Tool& tool);
void ToolChanged(const Tool::Item& tool);
/**
* @brief Signal emitted when the snapping setting is changed
@@ -270,7 +270,7 @@ private:
/**
* @brief Currently active tool
*/
olive::tool::Tool tool_;
Tool::Item tool_;
/**
* @brief Current snapping toggle
+35 -38
View File
@@ -21,57 +21,54 @@
#ifndef TOOL_H
#define TOOL_H
namespace olive {
namespace tool {
class Tool {
public:
/**
* @brief A list of tools that can be used throughout the application
*/
enum Item {
/// No tool. This should never be set as the application tool, its only real purpose is to indicate the lack of
/// a tool somewhere similar to nullptr.
kNone,
/**
* @brief A list of tools that can be used throughout the application
*/
enum Tool {
/// No tool. This should never be set as the application tool, its only real purpose is to indicate the lack of
/// a tool somewhere.
kNone,
/// Pointer tool
kPointer,
/// Pointer tool
kPointer,
/// Edit tool
kEdit,
/// Edit tool
kEdit,
/// Ripple tool
kRipple,
/// Ripple tool
kRipple,
/// Rolling tool
kRolling,
/// Rolling tool
kRolling,
/// Razor tool
kRazor,
/// Razor tool
kRazor,
/// Slip tool
kSlip,
/// Slip tool
kSlip,
/// Slide tool
kSlide,
/// Slide tool
kSlide,
/// Hand tool
kHand,
/// Hand tool
kHand,
/// Zoom tool
kZoom,
/// Zoom tool
kZoom,
/// Transition tool
kTransition,
/// Transition tool
kTransition,
/// Record tool
kRecord,
/// Record tool
kRecord,
/// Add tool
kAdd,
/// Add tool
kAdd,
kCount
kCount
};
};
}
}
#endif // TOOL_H
+13 -13
View File
@@ -51,21 +51,21 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
views_.append(new TimelineAndTrackView(kTrackTypeAudio, Qt::AlignTop));
// Create tools
tools_.resize(olive::tool::kCount);
tools_.resize(::Tool::kCount);
tools_.fill(nullptr);
tools_.replace(olive::tool::kPointer, std::make_shared<PointerTool>(this));
// tools_.replace(olive::tool::kEdit, new PointerTool(this)); FIXME: Implement
tools_.replace(olive::tool::kRipple, std::make_shared<RippleTool>(this));
tools_.replace(olive::tool::kRolling, std::make_shared<RollingTool>(this));
tools_.replace(olive::tool::kRazor, std::make_shared<RazorTool>(this));
tools_.replace(olive::tool::kSlip, std::make_shared<SlipTool>(this));
tools_.replace(olive::tool::kSlide, std::make_shared<SlideTool>(this));
tools_.replace(olive::tool::kHand, std::make_shared<HandTool>(this));
tools_.replace(olive::tool::kZoom, std::make_shared<ZoomTool>(this));
tools_.replace(olive::tool::kTransition, std::make_shared<TransitionTool>(this));
//tools_.replace(olive::tool::kRecord, new PointerTool(this)); FIXME: Implement
tools_.replace(olive::tool::kAdd, std::make_shared<AddTool>(this));
tools_.replace(::Tool::kPointer, std::make_shared<PointerTool>(this));
// tools_.replace(::Tool::kEdit, new PointerTool(this)); FIXME: Implement
tools_.replace(::Tool::kRipple, std::make_shared<RippleTool>(this));
tools_.replace(::Tool::kRolling, std::make_shared<RollingTool>(this));
tools_.replace(::Tool::kRazor, std::make_shared<RazorTool>(this));
tools_.replace(::Tool::kSlip, std::make_shared<SlipTool>(this));
tools_.replace(::Tool::kSlide, std::make_shared<SlideTool>(this));
tools_.replace(::Tool::kHand, std::make_shared<HandTool>(this));
tools_.replace(::Tool::kZoom, std::make_shared<ZoomTool>(this));
tools_.replace(::Tool::kTransition, std::make_shared<TransitionTool>(this));
//tools_.replace(::Tool::kRecord, new PointerTool(this)); FIXME: Implement
tools_.replace(::Tool::kAdd, std::make_shared<AddTool>(this));
import_tool_ = std::make_shared<ImportTool>(this);
+16 -16
View File
@@ -34,18 +34,18 @@ Toolbar::Toolbar(QWidget *parent) :
layout_->setMargin(0);
// Create standard tool buttons
btn_pointer_tool_ = CreateToolButton(olive::tool::kPointer);
btn_edit_tool_ = CreateToolButton(olive::tool::kEdit);
btn_ripple_tool_ = CreateToolButton(olive::tool::kRipple);
btn_rolling_tool_ = CreateToolButton(olive::tool::kRolling);
btn_razor_tool_ = CreateToolButton(olive::tool::kRazor);
btn_slip_tool_ = CreateToolButton(olive::tool::kSlip);
btn_slide_tool_ = CreateToolButton(olive::tool::kSlide);
btn_hand_tool_ = CreateToolButton(olive::tool::kHand);
btn_zoom_tool_ = CreateToolButton(olive::tool::kZoom);
btn_record_ = CreateToolButton(olive::tool::kRecord);
btn_transition_tool_ = CreateToolButton(olive::tool::kTransition);
btn_add_ = CreateToolButton(olive::tool::kAdd);
btn_pointer_tool_ = CreateToolButton(Tool::kPointer);
btn_edit_tool_ = CreateToolButton(Tool::kEdit);
btn_ripple_tool_ = CreateToolButton(Tool::kRipple);
btn_rolling_tool_ = CreateToolButton(Tool::kRolling);
btn_razor_tool_ = CreateToolButton(Tool::kRazor);
btn_slip_tool_ = CreateToolButton(Tool::kSlip);
btn_slide_tool_ = CreateToolButton(Tool::kSlide);
btn_hand_tool_ = CreateToolButton(Tool::kHand);
btn_zoom_tool_ = CreateToolButton(Tool::kZoom);
btn_record_ = CreateToolButton(Tool::kRecord);
btn_transition_tool_ = CreateToolButton(Tool::kTransition);
btn_add_ = CreateToolButton(Tool::kAdd);
// Create snapping button, which is not actually a tool, it's a toggle option
btn_snapping_toggle_ = CreateNonToolButton();
@@ -55,7 +55,7 @@ Toolbar::Toolbar(QWidget *parent) :
UpdateIcons();
}
void Toolbar::SetTool(const olive::tool::Tool& tool)
void Toolbar::SetTool(const Tool::Item& tool)
{
// For each tool, set the "checked" state to whether the button's tool is the current tool
for (int i=0;i<toolbar_btns_.size();i++) {
@@ -115,7 +115,7 @@ void Toolbar::UpdateIcons()
btn_snapping_toggle_->setIcon(olive::icon::Snapping);
}
ToolbarButton* Toolbar::CreateToolButton(const olive::tool::Tool& tool)
ToolbarButton* Toolbar::CreateToolButton(const Tool::Item& tool)
{
// Create a ToolbarButton object
ToolbarButton* b = new ToolbarButton(this, tool);
@@ -135,7 +135,7 @@ ToolbarButton* Toolbar::CreateToolButton(const olive::tool::Tool& tool)
ToolbarButton *Toolbar::CreateNonToolButton()
{
// Create a ToolbarButton object
ToolbarButton* b = new ToolbarButton(this, olive::tool::kNone);
ToolbarButton* b = new ToolbarButton(this, Tool::kNone);
// Add it to the layout
layout_->addWidget(b);
@@ -146,7 +146,7 @@ ToolbarButton *Toolbar::CreateNonToolButton()
void Toolbar::ToolButtonClicked()
{
// Get new tool from ToolbarButton object
olive::tool::Tool new_tool = static_cast<ToolbarButton*>(sender())->tool();
Tool::Item new_tool = static_cast<ToolbarButton*>(sender())->tool();
// Set checked state of all tool buttons
// NOTE: Not necessary if this is appropriately connected to Core
+3 -3
View File
@@ -65,7 +65,7 @@ public slots:
*
* Tool to show as selected
*/
void SetTool(const olive::tool::Tool &tool);
void SetTool(const Tool::Item &tool);
/**
* @brief Set snapping checked value
@@ -95,7 +95,7 @@ signals:
*
* Tool that was selected
*/
void ToolChanged(const olive::tool::Tool& t);
void ToolChanged(const Tool::Item& t);
/**
* @brief Emitted whenever the snapping setting is changed
@@ -130,7 +130,7 @@ private:
*
* The created ToolbarButton. The button parent is automatically set to `this`.
*/
ToolbarButton* CreateToolButton(const olive::tool::Tool& tool);
ToolbarButton* CreateToolButton(const Tool::Item& tool);
/**
* @brief Internal convenience function for creating buttons quickly
+2 -2
View File
@@ -20,14 +20,14 @@
#include "toolbarbutton.h"
ToolbarButton::ToolbarButton(QWidget *parent, const olive::tool::Tool &tool) :
ToolbarButton::ToolbarButton(QWidget *parent, const Tool::Item &tool) :
QPushButton(parent),
tool_(tool)
{
setCheckable(true);
}
const olive::tool::Tool &ToolbarButton::tool()
const Tool::Item &ToolbarButton::tool()
{
return tool_;
}
+4 -4
View File
@@ -40,21 +40,21 @@ public:
*
* @param tool
*
* Tool object. Must be a member of enum olive::tool::Tool, including kNone if this button does not represent a tool.
* Tool object. Must be a member of enum Tool::Item, including kNone if this button does not represent a tool.
*/
ToolbarButton(QWidget* parent, const olive::tool::Tool& tool);
ToolbarButton(QWidget* parent, const Tool::Item& tool);
/**
* @brief Retrieve tool ID that this button represents
*
* Set in the constructor and shouldn't change throughout its lifetime.
*/
const olive::tool::Tool& tool();
const Tool::Item& tool();
private:
/**
* @brief Internal tool value
*/
olive::tool::Tool tool_;
Tool::Item tool_;
};
#endif // TOOLBARBUTTON_H
+12 -12
View File
@@ -213,52 +213,52 @@ MainMenu::MainMenu(QMainWindow *parent) :
tools_pointer_item_ = tools_menu_->AddItem("pointertool", this, SLOT(ToolItemTriggered()), "V");
tools_pointer_item_->setCheckable(true);
tools_pointer_item_->setData(olive::tool::kPointer);
tools_pointer_item_->setData(Tool::kPointer);
tools_group_->addAction(tools_pointer_item_);
tools_edit_item_ = tools_menu_->AddItem("edittool", this, SLOT(ToolItemTriggered()), "X");
tools_edit_item_->setCheckable(true);
tools_edit_item_->setData(olive::tool::kEdit);
tools_edit_item_->setData(Tool::kEdit);
tools_group_->addAction(tools_edit_item_);
tools_ripple_item_ = tools_menu_->AddItem("rippletool", this, SLOT(ToolItemTriggered()), "B");
tools_ripple_item_->setCheckable(true);
tools_ripple_item_->setData(olive::tool::kRipple);
tools_ripple_item_->setData(Tool::kRipple);
tools_group_->addAction(tools_ripple_item_);
tools_rolling_item_ = tools_menu_->AddItem("rollingtool", this, SLOT(ToolItemTriggered()), "N");
tools_rolling_item_->setCheckable(true);
tools_rolling_item_->setData(olive::tool::kRolling);
tools_rolling_item_->setData(Tool::kRolling);
tools_group_->addAction(tools_rolling_item_);
tools_razor_item_ = tools_menu_->AddItem("razortool", this, SLOT(ToolItemTriggered()), "C");
tools_razor_item_->setCheckable(true);
tools_razor_item_->setData(olive::tool::kRazor);
tools_razor_item_->setData(Tool::kRazor);
tools_group_->addAction(tools_razor_item_);
tools_slip_item_ = tools_menu_->AddItem("sliptool", this, SLOT(ToolItemTriggered()), "Y");
tools_slip_item_->setCheckable(true);
tools_slip_item_->setData(olive::tool::kSlip);
tools_slip_item_->setData(Tool::kSlip);
tools_group_->addAction(tools_slip_item_);
tools_slide_item_ = tools_menu_->AddItem("slidetool", this, SLOT(ToolItemTriggered()), "U");
tools_slide_item_->setCheckable(true);
tools_slide_item_->setData(olive::tool::kSlide);
tools_slide_item_->setData(Tool::kSlide);
tools_group_->addAction(tools_slide_item_);
tools_hand_item_ = tools_menu_->AddItem("handtool", this, SLOT(ToolItemTriggered()), "H");
tools_hand_item_->setCheckable(true);
tools_hand_item_->setData(olive::tool::kHand);
tools_hand_item_->setData(Tool::kHand);
tools_group_->addAction(tools_hand_item_);
tools_zoom_item_ = tools_menu_->AddItem("zoomtool", this, SLOT(ToolItemTriggered()), "Z");
tools_zoom_item_->setCheckable(true);
tools_zoom_item_->setData(olive::tool::kZoom);
tools_zoom_item_->setData(Tool::kZoom);
tools_group_->addAction(tools_zoom_item_);
tools_transition_item_ = tools_menu_->AddItem("transitiontool", this, SLOT(ToolItemTriggered()), "T");
tools_transition_item_->setCheckable(true);
tools_transition_item_->setData(olive::tool::kTransition);
tools_transition_item_->setData(Tool::kTransition);
tools_group_->addAction(tools_transition_item_);
tools_menu_->addSeparator();
@@ -320,8 +320,8 @@ void MainMenu::ToolItemTriggered()
// Assume the sender is a QAction
QAction* action = static_cast<QAction*>(sender());
// Assume its data() is a member of olive::tool::Tool
olive::tool::Tool tool = static_cast<olive::tool::Tool>(action->data().toInt());
// Assume its data() is a member of Tool::Item
Tool::Item tool = static_cast<Tool::Item>(action->data().toInt());
// Set the Tool in Core
olive::core.SetTool(tool);