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);
146 ui->scrollArea->setMinimumHeight(0);
153 flowlayout->addWidget(ui->pencilButton);
154 flowlayout->addWidget(ui->eraserButton);
155 flowlayout->addWidget(ui->selectButton);
156 flowlayout->addWidget(ui->moveButton);
157 flowlayout->addWidget(ui->penButton);
158 flowlayout->addWidget(ui->handButton);
159 flowlayout->addWidget(ui->polylineButton);
160 flowlayout->addWidget(ui->bucketButton);
161 flowlayout->addWidget(ui->eyedropperButton);
162 flowlayout->addWidget(ui->brushButton);
163 flowlayout->addWidget(ui->smudgeButton);
165 delete ui->scrollAreaWidgetContents_2->layout();
166 ui->scrollAreaWidgetContents_2->setLayout(flowlayout);
167 ui->scrollAreaWidgetContents_2->setContentsMargins(0,0,0,0);
173void ToolBoxWidget::updateUI()
186void ToolBoxWidget::onToolSetActive(ToolType toolType)
190 case ToolType::BRUSH:
191 ui->brushButton->setChecked(
true);
194 ui->penButton->setChecked(
true);
196 case ToolType::PENCIL:
197 ui->pencilButton->setChecked(
true);
199 case ToolType::SELECT:
200 ui->selectButton->setChecked(
true);
203 ui->handButton->setChecked(
true);
206 case ToolType::CAMERA:
207 ui->moveButton->setChecked(
true);
209 case ToolType::ERASER:
210 ui->eraserButton->setChecked(
true);
212 case ToolType::POLYLINE:
213 ui->polylineButton->setChecked(
true);
215 case ToolType::SMUDGE:
216 ui->smudgeButton->setChecked(
true);
218 case ToolType::BUCKET:
219 ui->bucketButton->setChecked(
true);
221 case ToolType::EYEDROPPER:
222 ui->eyedropperButton->setChecked(
true);
229void ToolBoxWidget::pencilOn()
231 toolOn(PENCIL, ui->pencilButton);
234void ToolBoxWidget::eraserOn()
236 toolOn(ERASER, ui->eraserButton);
239void ToolBoxWidget::selectOn()
241 toolOn(SELECT, ui->selectButton);
244void ToolBoxWidget::moveOn()
246 if (editor()->layers()->currentLayer()->type() == Layer::CAMERA) {
247 toolOn(CAMERA, ui->moveButton);
249 toolOn(MOVE, ui->moveButton);
253void ToolBoxWidget::penOn()
255 toolOn(PEN, ui->penButton);
258void ToolBoxWidget::handOn()
260 toolOn(HAND, ui->handButton);
263void ToolBoxWidget::polylineOn()
265 toolOn(POLYLINE, ui->polylineButton);
268void ToolBoxWidget::bucketOn()
270 toolOn(BUCKET, ui->bucketButton);
273void ToolBoxWidget::eyedropperOn()
275 toolOn(EYEDROPPER, ui->eyedropperButton);
278void ToolBoxWidget::brushOn()
280 toolOn(BRUSH, ui->brushButton);
283void ToolBoxWidget::smudgeOn()
285 toolOn(SMUDGE, ui->smudgeButton);
288void ToolBoxWidget::deselectAllTools()
290 ui->pencilButton->setChecked(
false);
291 ui->eraserButton->setChecked(
false);
292 ui->selectButton->setChecked(
false);
293 ui->moveButton->setChecked(
false);
294 ui->handButton->setChecked(
false);
295 ui->penButton->setChecked(
false);
296 ui->polylineButton->setChecked(
false);
297 ui->bucketButton->setChecked(
false);
298 ui->eyedropperButton->setChecked(
false);
299 ui->brushButton->setChecked(
false);
300 ui->smudgeButton->setChecked(
false);
303void ToolBoxWidget::toolOn(ToolType toolType,
QToolButton* toolButton)
305 if (editor()->tools()->currentTool()->type() == toolType) {
310 if (!editor()->tools()->leavingThisTool())
315 editor()->tools()->setCurrentTool(toolType);
318void ToolBoxWidget::onLayerDidChange(
int)
320 BaseTool* currentTool = editor()->tools()->currentTool();
321 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)