tool switching implemented
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user