tool switching implemented
This commit is contained in:
@@ -25,6 +25,7 @@ set(OLIVE_SOURCES
|
||||
add_subdirectory(panel)
|
||||
add_subdirectory(project)
|
||||
add_subdirectory(render)
|
||||
add_subdirectory(tool)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(widget)
|
||||
add_subdirectory(window)
|
||||
|
||||
@@ -104,6 +104,13 @@ olive::MainWindow *Core::main_window()
|
||||
return main_window_;
|
||||
}
|
||||
|
||||
void Core::SetTool(const olive::tool::Tool &tool)
|
||||
{
|
||||
tool_ = tool;
|
||||
|
||||
emit ToolChanged(tool_);
|
||||
}
|
||||
|
||||
void Core::AddOpenProject(ProjectPtr p)
|
||||
{
|
||||
open_projects_.append(p);
|
||||
|
||||
+21
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "project/project.h"
|
||||
#include "window/mainwindow/mainwindow.h"
|
||||
#include "tool/tool.h"
|
||||
|
||||
/**
|
||||
* @brief The Core class
|
||||
@@ -66,6 +67,14 @@ public:
|
||||
*/
|
||||
olive::MainWindow* main_window();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Set the current application-wide tool
|
||||
*
|
||||
* @param tool
|
||||
*/
|
||||
void SetTool(const olive::tool::Tool& tool);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when a project is opened
|
||||
@@ -76,6 +85,13 @@ signals:
|
||||
*/
|
||||
void ProjectOpened(Project* p);
|
||||
|
||||
/**
|
||||
* @brief Signal emitted when the tool is changed from somewhere
|
||||
*
|
||||
* @param tool
|
||||
*/
|
||||
void ToolChanged(const olive::tool::Tool& tool);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Creates an empty project and adds it to the "open projects"
|
||||
@@ -99,6 +115,11 @@ private:
|
||||
* @brief List of currently open projects
|
||||
*/
|
||||
QList<ProjectPtr> open_projects_;
|
||||
|
||||
/**
|
||||
* @brief Currently active tool
|
||||
*/
|
||||
olive::tool::Tool tool_;
|
||||
};
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "tool.h"
|
||||
|
||||
#include "core.h"
|
||||
#include "widget/toolbar/toolbar.h"
|
||||
|
||||
ToolPanel::ToolPanel(QWidget *parent) :
|
||||
@@ -9,6 +10,9 @@ ToolPanel::ToolPanel(QWidget *parent) :
|
||||
|
||||
setWidget(t);
|
||||
|
||||
connect(t, SIGNAL(ToolChanged(const olive::tool::Tool&)), &olive::core, SLOT(SetTool(const olive::tool::Tool&)));
|
||||
connect(&olive::core, SIGNAL(ToolChanged(const olive::tool::Tool&)), t, SLOT(SetTool(const olive::tool::Tool&)));
|
||||
|
||||
Retranslate();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Olive - Non-Linear Video Editor
|
||||
# Copyright (C) 2019 Olive Team
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
tool/tool.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef TOOL_H
|
||||
#define TOOL_H
|
||||
|
||||
namespace olive {
|
||||
namespace tool {
|
||||
|
||||
enum Tool {
|
||||
kNone,
|
||||
kPointer,
|
||||
kEdit,
|
||||
kRipple,
|
||||
kRazor,
|
||||
kSlip,
|
||||
kSlide,
|
||||
kHand,
|
||||
kZoom,
|
||||
kTransition,
|
||||
kRecord,
|
||||
kAdd
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TOOL_H
|
||||
@@ -18,5 +18,7 @@ set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/toolbar/toolbar.h
|
||||
widget/toolbar/toolbar.cpp
|
||||
widget/toolbar/toolbarbutton.h
|
||||
widget/toolbar/toolbarbutton.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "toolbar.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QVariant>
|
||||
#include <QButtonGroup>
|
||||
#include <QEvent>
|
||||
|
||||
@@ -12,22 +13,43 @@ Toolbar::Toolbar(QWidget *parent) :
|
||||
layout_ = new FlowLayout(this);
|
||||
layout_->setMargin(0);
|
||||
|
||||
btn_pointer_tool_ = CreateToolButton(olive::icon::ToolPointer);
|
||||
btn_edit_tool_ = CreateToolButton(olive::icon::ToolEdit);
|
||||
btn_ripple_tool_ = CreateToolButton(olive::icon::ToolRipple);
|
||||
btn_razor_tool_ = CreateToolButton(olive::icon::ToolRazor);
|
||||
btn_slip_tool_ = CreateToolButton(olive::icon::ToolSlip);
|
||||
btn_slide_tool_ = CreateToolButton(olive::icon::ToolSlide);
|
||||
btn_hand_tool_ = CreateToolButton(olive::icon::ToolHand);
|
||||
btn_zoom_tool_ = CreateToolButton(olive::icon::ZoomIn);
|
||||
btn_transition_tool_ = CreateToolButton(olive::icon::ToolTransition);
|
||||
btn_snapping_toggle_ = CreateToolButton(olive::icon::Snapping);
|
||||
btn_record_ = CreateToolButton(olive::icon::Record);
|
||||
btn_add_ = CreateToolButton(olive::icon::Add);
|
||||
// Create standard tool buttons
|
||||
btn_pointer_tool_ = CreateToolButton(olive::icon::ToolPointer, olive::tool::kPointer);
|
||||
btn_edit_tool_ = CreateToolButton(olive::icon::ToolEdit, olive::tool::kEdit);
|
||||
btn_ripple_tool_ = CreateToolButton(olive::icon::ToolRipple, olive::tool::kRipple);
|
||||
btn_razor_tool_ = CreateToolButton(olive::icon::ToolRazor, olive::tool::kRazor);
|
||||
btn_slip_tool_ = CreateToolButton(olive::icon::ToolSlip, olive::tool::kSlip);
|
||||
btn_slide_tool_ = CreateToolButton(olive::icon::ToolSlide, olive::tool::kSlide);
|
||||
btn_hand_tool_ = CreateToolButton(olive::icon::ToolHand, olive::tool::kHand);
|
||||
btn_zoom_tool_ = CreateToolButton(olive::icon::ZoomIn, olive::tool::kZoom);
|
||||
btn_transition_tool_ = CreateToolButton(olive::icon::ToolTransition, olive::tool::kTransition);
|
||||
btn_record_ = CreateToolButton(olive::icon::Record, olive::tool::kRecord);
|
||||
btn_add_ = CreateToolButton(olive::icon::Add, olive::tool::kAdd);
|
||||
|
||||
// Create snapping button, which is not actually a tool, it's a toggle option
|
||||
btn_snapping_toggle_ = new ToolbarButton(this, olive::icon::Snapping, olive::tool::kNone);
|
||||
layout_->addWidget(btn_snapping_toggle_);
|
||||
connect(btn_snapping_toggle_, SIGNAL(clicked(bool)), this, SLOT(SnappingButtonClicked(bool)));
|
||||
|
||||
Retranslate();
|
||||
}
|
||||
|
||||
void Toolbar::SetTool(const olive::tool::Tool& 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++) {
|
||||
ToolbarButton* btn = toolbar_btns_.at(i);
|
||||
|
||||
btn->setChecked(btn->tool() == tool);
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbar::SetSnapping(const bool& snapping)
|
||||
{
|
||||
// Set checked state of snapping toggle
|
||||
btn_snapping_toggle_->setChecked(snapping);
|
||||
}
|
||||
|
||||
void Toolbar::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
@@ -52,11 +74,37 @@ void Toolbar::Retranslate()
|
||||
btn_add_->setToolTip(tr("Add Object"));
|
||||
}
|
||||
|
||||
QPushButton* Toolbar::CreateToolButton(const QIcon &icon)
|
||||
ToolbarButton* Toolbar::CreateToolButton(const QIcon &icon, const olive::tool::Tool& tool)
|
||||
{
|
||||
QPushButton* b = new QPushButton();
|
||||
b->setIcon(icon);
|
||||
b->setCheckable(true);
|
||||
// Create a ToolbarButton object
|
||||
ToolbarButton* b = new ToolbarButton(this, icon, tool);
|
||||
|
||||
// Add it to the layout
|
||||
layout_->addWidget(b);
|
||||
|
||||
// Add it to the list for iterating through later
|
||||
toolbar_btns_.append(b);
|
||||
|
||||
// Connect it to the tool button click handler
|
||||
connect(b, SIGNAL(clicked(bool)), this, SLOT(ToolButtonClicked()));
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void Toolbar::ToolButtonClicked()
|
||||
{
|
||||
// Get new tool from ToolbarButton object
|
||||
olive::tool::Tool new_tool = static_cast<ToolbarButton*>(sender())->tool();
|
||||
|
||||
// Set checked state of all tool buttons
|
||||
// NOTE: Not necessary if this is appropriately connected to Core
|
||||
//SetTool(new_tool);
|
||||
|
||||
// Emit signal that the tool just changed
|
||||
emit ToolChanged(new_tool);
|
||||
}
|
||||
|
||||
void Toolbar::SnappingButtonClicked(bool b)
|
||||
{
|
||||
emit SnappingChanged(b);
|
||||
}
|
||||
|
||||
@@ -4,34 +4,52 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "widget/flowlayout/flowlayout.h"
|
||||
#include "widget/toolbar/toolbarbutton.h"
|
||||
#include "tool/tool.h"
|
||||
|
||||
class Toolbar : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Toolbar(QWidget* parent);
|
||||
|
||||
public slots:
|
||||
void SetTool(const olive::tool::Tool &tool);
|
||||
void SetSnapping(const bool &snapping);
|
||||
|
||||
protected:
|
||||
virtual void changeEvent(QEvent* e) override;
|
||||
|
||||
signals:
|
||||
void ToolChanged(const olive::tool::Tool&);
|
||||
void SnappingChanged(const bool&);
|
||||
|
||||
private:
|
||||
void Retranslate();
|
||||
|
||||
QPushButton *CreateToolButton(const QIcon& icon);
|
||||
ToolbarButton* CreateToolButton(const QIcon &icon, const olive::tool::Tool& tool);
|
||||
|
||||
FlowLayout* layout_;
|
||||
|
||||
QPushButton* btn_pointer_tool_;
|
||||
QPushButton* btn_edit_tool_;
|
||||
QPushButton* btn_ripple_tool_;
|
||||
QPushButton* btn_razor_tool_;
|
||||
QPushButton* btn_slip_tool_;
|
||||
QPushButton* btn_slide_tool_;
|
||||
QPushButton* btn_hand_tool_;
|
||||
QPushButton* btn_transition_tool_;
|
||||
QPushButton* btn_snapping_toggle_;
|
||||
QPushButton* btn_zoom_tool_;
|
||||
QPushButton* btn_record_;
|
||||
QPushButton* btn_add_;
|
||||
QList<ToolbarButton*> toolbar_btns_;
|
||||
|
||||
ToolbarButton* btn_pointer_tool_;
|
||||
ToolbarButton* btn_edit_tool_;
|
||||
ToolbarButton* btn_ripple_tool_;
|
||||
ToolbarButton* btn_razor_tool_;
|
||||
ToolbarButton* btn_slip_tool_;
|
||||
ToolbarButton* btn_slide_tool_;
|
||||
ToolbarButton* btn_hand_tool_;
|
||||
ToolbarButton* btn_transition_tool_;
|
||||
ToolbarButton* btn_zoom_tool_;
|
||||
ToolbarButton* btn_record_;
|
||||
ToolbarButton* btn_add_;
|
||||
|
||||
ToolbarButton* btn_snapping_toggle_;
|
||||
|
||||
private slots:
|
||||
void ToolButtonClicked();
|
||||
void SnappingButtonClicked(bool b);
|
||||
};
|
||||
|
||||
#endif // TOOLBAR_H
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "toolbarbutton.h"
|
||||
|
||||
ToolbarButton::ToolbarButton(QWidget *parent, const QIcon &icon, const olive::tool::Tool &tool) :
|
||||
QPushButton(parent),
|
||||
tool_(tool)
|
||||
{
|
||||
setCheckable(true);
|
||||
setIcon(icon);
|
||||
}
|
||||
|
||||
const olive::tool::Tool &ToolbarButton::tool()
|
||||
{
|
||||
return tool_;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef TOOLBARBUTTON_H
|
||||
#define TOOLBARBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "tool/tool.h"
|
||||
|
||||
class ToolbarButton : public QPushButton
|
||||
{
|
||||
public:
|
||||
ToolbarButton(QWidget* parent, const QIcon& icon, const olive::tool::Tool& tool);
|
||||
|
||||
const olive::tool::Tool& tool();
|
||||
private:
|
||||
olive::tool::Tool tool_;
|
||||
};
|
||||
|
||||
#endif // TOOLBARBUTTON_H
|
||||
Reference in New Issue
Block a user