From bb9284a8946b6ab6629ed0cd179e4f269d71ead7 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 26 Dec 2019 17:35:25 +1100 Subject: [PATCH] moved tool enum to a Tool class Code cleanup and improvement. --- app/core.cpp | 6 +- app/core.h | 8 +-- app/tool/tool.h | 73 ++++++++++---------- app/widget/timelinewidget/timelinewidget.cpp | 26 +++---- app/widget/toolbar/toolbar.cpp | 32 ++++----- app/widget/toolbar/toolbar.h | 6 +- app/widget/toolbar/toolbarbutton.cpp | 4 +- app/widget/toolbar/toolbarbutton.h | 8 +-- app/window/mainwindow/mainmenu.cpp | 24 +++---- 9 files changed, 92 insertions(+), 95 deletions(-) diff --git a/app/core.cpp b/app/core.cpp index f1e7bcdb1..68bd2b086 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -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(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; diff --git a/app/core.h b/app/core.h index fa3b468de..23e44bd35 100644 --- a/app/core.h +++ b/app/core.h @@ -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 diff --git a/app/tool/tool.h b/app/tool/tool.h index 5e4734b7a..56bb115ae 100644 --- a/app/tool/tool.h +++ b/app/tool/tool.h @@ -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 diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index a33c4f72f..4301d163c 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -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(this)); - // tools_.replace(olive::tool::kEdit, new PointerTool(this)); FIXME: Implement - tools_.replace(olive::tool::kRipple, std::make_shared(this)); - tools_.replace(olive::tool::kRolling, std::make_shared(this)); - tools_.replace(olive::tool::kRazor, std::make_shared(this)); - tools_.replace(olive::tool::kSlip, std::make_shared(this)); - tools_.replace(olive::tool::kSlide, std::make_shared(this)); - tools_.replace(olive::tool::kHand, std::make_shared(this)); - tools_.replace(olive::tool::kZoom, std::make_shared(this)); - tools_.replace(olive::tool::kTransition, std::make_shared(this)); - //tools_.replace(olive::tool::kRecord, new PointerTool(this)); FIXME: Implement - tools_.replace(olive::tool::kAdd, std::make_shared(this)); + tools_.replace(::Tool::kPointer, std::make_shared(this)); + // tools_.replace(::Tool::kEdit, new PointerTool(this)); FIXME: Implement + tools_.replace(::Tool::kRipple, std::make_shared(this)); + tools_.replace(::Tool::kRolling, std::make_shared(this)); + tools_.replace(::Tool::kRazor, std::make_shared(this)); + tools_.replace(::Tool::kSlip, std::make_shared(this)); + tools_.replace(::Tool::kSlide, std::make_shared(this)); + tools_.replace(::Tool::kHand, std::make_shared(this)); + tools_.replace(::Tool::kZoom, std::make_shared(this)); + tools_.replace(::Tool::kTransition, std::make_shared(this)); + //tools_.replace(::Tool::kRecord, new PointerTool(this)); FIXME: Implement + tools_.replace(::Tool::kAdd, std::make_shared(this)); import_tool_ = std::make_shared(this); diff --git a/app/widget/toolbar/toolbar.cpp b/app/widget/toolbar/toolbar.cpp index 9aec0b59f..bec9f63c4 100644 --- a/app/widget/toolbar/toolbar.cpp +++ b/app/widget/toolbar/toolbar.cpp @@ -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;isetIcon(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(sender())->tool(); + Tool::Item new_tool = static_cast(sender())->tool(); // Set checked state of all tool buttons // NOTE: Not necessary if this is appropriately connected to Core diff --git a/app/widget/toolbar/toolbar.h b/app/widget/toolbar/toolbar.h index 40e44f5e4..1444b5d80 100644 --- a/app/widget/toolbar/toolbar.h +++ b/app/widget/toolbar/toolbar.h @@ -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 diff --git a/app/widget/toolbar/toolbarbutton.cpp b/app/widget/toolbar/toolbarbutton.cpp index 547799f67..ea70f8a6a 100644 --- a/app/widget/toolbar/toolbarbutton.cpp +++ b/app/widget/toolbar/toolbarbutton.cpp @@ -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_; } diff --git a/app/widget/toolbar/toolbarbutton.h b/app/widget/toolbar/toolbarbutton.h index 1595c434b..a8cdd51f2 100644 --- a/app/widget/toolbar/toolbarbutton.h +++ b/app/widget/toolbar/toolbarbutton.h @@ -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 diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index eba46faba..1e060b5c4 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -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(sender()); - // Assume its data() is a member of olive::tool::Tool - olive::tool::Tool tool = static_cast(action->data().toInt()); + // Assume its data() is a member of Tool::Item + Tool::Item tool = static_cast(action->data().toInt()); // Set the Tool in Core olive::core.SetTool(tool);