tool switching implemented
This commit is contained in:
@@ -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