1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/***
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/>.
***/
#include "toolbar.h"
#include <QPushButton>
#include <QVariant>
#include <QButtonGroup>
#include <QEvent>
#include "node/factory.h"
#include "ui/icons/icons.h"
#include "widget/menu/menu.h"
OLIVE_NAMESPACE_ENTER
Toolbar::Toolbar(QWidget *parent) :
QWidget(parent)
{
layout_ = new FlowLayout(this);
layout_->setMargin(0);
// Create standard tool buttons
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();
connect(btn_snapping_toggle_, &QPushButton::clicked, this, &Toolbar::SnappingButtonClicked);
// Connect transition button to menu signal
connect(btn_transition_tool_, &QPushButton::clicked, this, &Toolbar::TransitionButtonClicked);
// Connect add button to menu signal
connect(btn_add_, &QPushButton::clicked, this, &Toolbar::AddButtonClicked);
Retranslate();
UpdateIcons();
}
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++) {
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) {
Retranslate();
} else if (e->type() == QEvent::StyleChange) {
UpdateIcons();
}
QWidget::changeEvent(e);
}
void Toolbar::Retranslate()
{
btn_pointer_tool_->setToolTip(tr("Pointer Tool"));
btn_edit_tool_->setToolTip(tr("Edit Tool"));
btn_ripple_tool_->setToolTip(tr("Ripple Tool"));
btn_rolling_tool_->setToolTip(tr("Rolling Tool"));
btn_razor_tool_->setToolTip(tr("Razor Tool"));
btn_slip_tool_->setToolTip(tr("Slip Tool"));
btn_slide_tool_->setToolTip(tr("Slide Tool"));
btn_hand_tool_->setToolTip(tr("Hand Tool"));
btn_zoom_tool_->setToolTip(tr("Zoom Tool"));
btn_transition_tool_->setToolTip(tr("Transition Tool"));
btn_record_->setToolTip(tr("Record Tool"));
btn_add_->setToolTip(tr("Add Tool"));
btn_snapping_toggle_->setToolTip(tr("Toggle Snapping"));
}
void Toolbar::UpdateIcons()
{
btn_pointer_tool_->setIcon(icon::ToolPointer);
btn_edit_tool_->setIcon(icon::ToolEdit);
btn_ripple_tool_->setIcon(icon::ToolRipple);
btn_rolling_tool_->setIcon(icon::ToolRolling);
btn_razor_tool_->setIcon(icon::ToolRazor);
btn_slip_tool_->setIcon(icon::ToolSlip);
btn_slide_tool_->setIcon(icon::ToolSlide);
btn_hand_tool_->setIcon(icon::ToolHand);
btn_zoom_tool_->setIcon(icon::ZoomIn);
btn_record_->setIcon(icon::Record);
btn_transition_tool_->setIcon(icon::ToolTransition);
btn_add_->setIcon(icon::Add);
btn_snapping_toggle_->setIcon(icon::Snapping);
}
ToolbarButton* Toolbar::CreateToolButton(const Tool::Item& tool)
{
// Create a ToolbarButton object
ToolbarButton* b = new ToolbarButton(this, 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;
}
ToolbarButton *Toolbar::CreateNonToolButton()
{
// Create a ToolbarButton object
ToolbarButton* b = new ToolbarButton(this, Tool::kNone);
// Add it to the layout
layout_->addWidget(b);
return b;
}
void Toolbar::ToolButtonClicked()
{
// Get new tool from ToolbarButton object
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
//SetTool(new_tool);
// Emit signal that the tool just changed
emit ToolChanged(new_tool);
}
void Toolbar::SnappingButtonClicked(bool b)
{
emit SnappingChanged(b);
}
void Toolbar::AddButtonClicked()
{
Menu m(this);
for (int i=0;i<Tool::kAddableCount;i++) {
QAction* action = m.addAction(Tool::GetAddableObjectName(static_cast<Tool::AddableObject>(i)));
action->setData(i);
}
connect(&m, &QMenu::triggered, this, &Toolbar::AddMenuItemTriggered);
m.exec(QCursor::pos());
}
void Toolbar::TransitionButtonClicked()
{
Menu* m = NodeFactory::CreateMenu(this, false, Node::kCategoryTransition);
connect(m, &QMenu::triggered, this, &Toolbar::TransitionMenuItemTriggered);
m->exec(QCursor::pos());
delete m;
}
void Toolbar::AddMenuItemTriggered(QAction* a)
{
emit AddableObjectChanged(static_cast<Tool::AddableObject>(a->data().toInt()));
}
void Toolbar::TransitionMenuItemTriggered(QAction *a)
{
emit SelectedTransitionChanged(NodeFactory::GetIDFromMenuAction(a));
}
OLIVE_NAMESPACE_EXIT
|