19#include "ui_toolboxwidget.h"
25#include <QKeySequence>
26#include <QResizeEvent>
28#include "flowlayout.h"
29#include "spinslider.h"
31#include "toolmanager.h"
32#include "layermanager.h"
33#include "pencilsettings.h"
38 strCommandName =
QString(
"shortcuts/") + strCommandName;
43ToolBoxWidget::ToolBoxWidget(
QWidget* parent) :
50ToolBoxWidget::~ToolBoxWidget()
57void ToolBoxWidget::initUI()
62 "QToolButton { border: 0px; }"
63 "QToolButton:pressed { border: 1px solid #ADADAD; border-radius: 2px; background-color: #D5D5D5; }"
64 "QToolButton:checked { border: 1px solid #ADADAD; border-radius: 2px; background-color: #D5D5D5; }";
65 ui->pencilButton->setStyleSheet(sStyle);
66 ui->selectButton->setStyleSheet(sStyle);
67 ui->moveButton->setStyleSheet(sStyle);
68 ui->handButton->setStyleSheet(sStyle);
69 ui->penButton->setStyleSheet(sStyle);
70 ui->eraserButton->setStyleSheet(sStyle);
71 ui->polylineButton->setStyleSheet(sStyle);
72 ui->bucketButton->setStyleSheet(sStyle);
73 ui->brushButton->setStyleSheet(sStyle);
74 ui->eyedropperButton->setStyleSheet(sStyle);
75 ui->smudgeButton->setStyleSheet(sStyle);
78 ui->pencilButton->setToolTip(
tr(
"Pencil Tool (%1): Sketch with pencil" )
79 .arg( GetToolTips( CMD_TOOL_PENCIL ) ) );
80 ui->selectButton->setToolTip(
tr(
"Select Tool (%1): Select an object" )
81 .arg( GetToolTips( CMD_TOOL_SELECT ) ) );
82 ui->moveButton->setToolTip(
tr(
"Move Tool (%1): Move an object" )
83 .arg( GetToolTips( CMD_TOOL_MOVE ) ) );
84 ui->handButton->setToolTip(
tr(
"Hand Tool (%1): Move the canvas" )
85 .arg( GetToolTips( CMD_TOOL_HAND ) ) );
86 ui->penButton->setToolTip(
tr(
"Pen Tool (%1): Sketch with pen" )
87 .arg( GetToolTips( CMD_TOOL_PEN ) ) );
88 ui->eraserButton->setToolTip(
tr(
"Eraser Tool (%1): Erase" )
89 .arg( GetToolTips( CMD_TOOL_ERASER ) ) );
90 ui->polylineButton->setToolTip(
tr(
"Polyline Tool (%1): Create line/curves" )
91 .arg( GetToolTips( CMD_TOOL_POLYLINE ) ) );
92 ui->bucketButton->setToolTip(
tr(
"Paint Bucket Tool (%1): Fill selected area with a color" )
93 .arg( GetToolTips( CMD_TOOL_BUCKET ) ) );
94 ui->brushButton->setToolTip(
tr(
"Brush Tool (%1): Paint smooth stroke with a brush" )
95 .arg( GetToolTips( CMD_TOOL_BRUSH ) ) );
96 ui->eyedropperButton->setToolTip(
tr(
"Eyedropper Tool (%1): "
97 "Set color from the stage<br>[ALT] for instant access" )
98 .arg( GetToolTips( CMD_TOOL_EYEDROPPER ) ) );
99 ui->smudgeButton->setToolTip(
tr(
"Smudge Tool (%1):<br>Edit polyline/curves<br>"
100 "Liquify bitmap pixels<br> (%1)+[Alt]: Smooth" )
101 .arg( GetToolTips( CMD_TOOL_SMUDGE ) ) );
103 ui->pencilButton->setWhatsThis(
tr(
"Pencil Tool (%1)" )
104 .arg( GetToolTips( CMD_TOOL_PENCIL ) ) );
105 ui->selectButton->setWhatsThis(
tr(
"Select Tool (%1)" )
106 .arg( GetToolTips( CMD_TOOL_SELECT ) ) );
107 ui->moveButton->setWhatsThis(
tr(
"Move Tool (%1)" )
108 .arg( GetToolTips( CMD_TOOL_MOVE ) ) );
109 ui->handButton->setWhatsThis(
tr(
"Hand Tool (%1)" )
110 .arg( GetToolTips( CMD_TOOL_HAND ) ) );
111 ui->penButton->setWhatsThis(
tr(
"Pen Tool (%1)" )
112 .arg( GetToolTips( CMD_TOOL_PEN ) ) );
113 ui->eraserButton->setWhatsThis(
tr(
"Eraser Tool (%1)" )
114 .arg( GetToolTips( CMD_TOOL_ERASER ) ) );
115 ui->polylineButton->setWhatsThis(
tr(
"Polyline Tool (%1)" )
116 .arg( GetToolTips( CMD_TOOL_POLYLINE ) ) );
117 ui->bucketButton->setWhatsThis(
tr(
"Paint Bucket Tool (%1)" )
118 .arg( GetToolTips( CMD_TOOL_BUCKET ) ) );
119 ui->brushButton->setWhatsThis(
tr(
"Brush Tool (%1)" )
120 .arg( GetToolTips( CMD_TOOL_BRUSH ) ) );
121 ui->eyedropperButton->setWhatsThis(
tr(
"Eyedropper Tool (%1)" )
122 .arg( GetToolTips( CMD_TOOL_EYEDROPPER ) ) );
123 ui->smudgeButton->setWhatsThis(
tr(
"Smudge Tool (%1)" )
124 .arg( GetToolTips( CMD_TOOL_SMUDGE ) ) );
138 connect(editor()->layers(), &LayerManager::currentLayerChanged,
this, &ToolBoxWidget::onLayerDidChange);
149 flowlayout->
addWidget(ui->polylineButton);
151 flowlayout->
addWidget(ui->eyedropperButton);
155 delete ui->scrollAreaWidgetContents_2->layout();
156 ui->scrollAreaWidgetContents_2->setLayout(flowlayout);
162void ToolBoxWidget::updateUI()
166void ToolBoxWidget::onToolSetActive(ToolType toolType)
170 case ToolType::BRUSH:
171 ui->brushButton->setChecked(
true);
174 ui->penButton->setChecked(
true);
176 case ToolType::PENCIL:
177 ui->pencilButton->setChecked(
true);
179 case ToolType::SELECT:
180 ui->selectButton->setChecked(
true);
183 ui->handButton->setChecked(
true);
186 case ToolType::CAMERA:
187 ui->moveButton->setChecked(
true);
189 case ToolType::ERASER:
190 ui->eraserButton->setChecked(
true);
192 case ToolType::POLYLINE:
193 ui->polylineButton->setChecked(
true);
195 case ToolType::SMUDGE:
196 ui->smudgeButton->setChecked(
true);
198 case ToolType::BUCKET:
199 ui->bucketButton->setChecked(
true);
201 case ToolType::EYEDROPPER:
202 ui->eyedropperButton->setChecked(
true);
209void ToolBoxWidget::pencilOn()
211 toolOn(PENCIL, ui->pencilButton);
214void ToolBoxWidget::eraserOn()
216 toolOn(ERASER, ui->eraserButton);
219void ToolBoxWidget::selectOn()
221 toolOn(SELECT, ui->selectButton);
224void ToolBoxWidget::moveOn()
226 if (editor()->layers()->currentLayer()->type() == Layer::CAMERA) {
227 toolOn(CAMERA, ui->moveButton);
229 toolOn(MOVE, ui->moveButton);
233void ToolBoxWidget::penOn()
235 toolOn(PEN, ui->penButton);
238void ToolBoxWidget::handOn()
240 toolOn(HAND, ui->handButton);
243void ToolBoxWidget::polylineOn()
245 toolOn(POLYLINE, ui->polylineButton);
248void ToolBoxWidget::bucketOn()
250 toolOn(BUCKET, ui->bucketButton);
253void ToolBoxWidget::eyedropperOn()
255 toolOn(EYEDROPPER, ui->eyedropperButton);
258void ToolBoxWidget::brushOn()
260 toolOn(BRUSH, ui->brushButton);
263void ToolBoxWidget::smudgeOn()
265 toolOn(SMUDGE, ui->smudgeButton);
268int ToolBoxWidget::getMinHeightForWidth(
int width)
270 return ui->toolGroup->layout()->heightForWidth(
width);
273void ToolBoxWidget::deselectAllTools()
275 ui->pencilButton->setChecked(
false);
276 ui->eraserButton->setChecked(
false);
277 ui->selectButton->setChecked(
false);
278 ui->moveButton->setChecked(
false);
279 ui->handButton->setChecked(
false);
280 ui->penButton->setChecked(
false);
281 ui->polylineButton->setChecked(
false);
282 ui->bucketButton->setChecked(
false);
283 ui->eyedropperButton->setChecked(
false);
284 ui->brushButton->setChecked(
false);
285 ui->smudgeButton->setChecked(
false);
288bool ToolBoxWidget::toolOn(ToolType toolType,
QToolButton* toolButton)
290 if (!editor()->tools()->leavingThisTool())
295 editor()->tools()->setCurrentTool(toolType);
299void ToolBoxWidget::onLayerDidChange(
int)
301 BaseTool* currentTool = editor()->tools()->currentTool();
302 if (currentTool->type() == MOVE || currentTool->type() == CAMERA)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void keySequence(QWindow *window, const QKeySequence &keySequence)
char * toString(const T &value)