21 #include <QToolButton>
22 #include <QGridLayout>
23 #include <QKeySequence>
25 #include "spinslider.h"
28 #include "toolmanager.h"
29 #include "pencilsettings.h"
32 QString GetToolTips( QString strCommandName )
34 strCommandName = QString(
"shortcuts/" ) + strCommandName;
35 QKeySequence keySequence( pencilSettings().value( strCommandName ).toString() );
36 return QString(
"<b>%1</b>").arg( keySequence.toString() );
40 ToolBoxWidget::ToolBoxWidget( QWidget* parent ) :
BaseDockWidget( parent )
42 setWindowTitle( tr(
"Tools",
"Window title of tool box" ) );
46 void ToolBoxWidget::initUI()
49 QGridLayout* layout =
new QGridLayout();
51 pencilButton = newToolButton( QIcon(
":icons/pencil2.png" ),
52 tr(
"Pencil Tool (%1): Sketch with pencil" )
53 .arg( GetToolTips( CMD_TOOL_PENCIL ) ) );
54 selectButton = newToolButton( QIcon(
":icons/select.png" ),
55 tr(
"Select Tool (%1): Select an object" )
56 .arg( GetToolTips( CMD_TOOL_SELECT ) ) );
57 moveButton = newToolButton( QIcon(
":icons/arrow.png" ),
58 tr(
"Move Tool (%1): Move an object" )
59 .arg( GetToolTips( CMD_TOOL_MOVE ) ) );
60 handButton = newToolButton( QIcon(
":icons/hand.png" ),
61 tr(
"Hand Tool (%1): Move the canvas" )
62 .arg( GetToolTips( CMD_TOOL_HAND ) ) );
63 penButton = newToolButton( QIcon(
":icons/pen.png" ),
64 tr(
"Pen Tool (%1): Sketch with pen" )
65 .arg( GetToolTips( CMD_TOOL_PEN ) ) );
66 eraserButton = newToolButton( QIcon(
":icons/eraser.png" ),
67 tr(
"Eraser Tool (%1): Erase" )
68 .arg( GetToolTips( CMD_TOOL_ERASER ) ) );
69 polylineButton = newToolButton( QIcon(
":icons/polyline.png" ),
70 tr(
"Polyline Tool (%1): Create line/curves" )
71 .arg( GetToolTips( CMD_TOOL_POLYLINE ) ) );
72 bucketButton = newToolButton( QIcon(
":icons/bucket.png" ),
73 tr(
"Paint Bucket Tool (%1): Fill selected area with a color" )
74 .arg( GetToolTips( CMD_TOOL_BUCKET ) ) );
75 colouringButton = newToolButton( QIcon(
":icons/brush.png" ),
76 tr(
"Brush Tool (%1): Paint smooth stroke with a brush" )
77 .arg( GetToolTips( CMD_TOOL_BRUSH ) ) );
78 eyedropperButton = newToolButton( QIcon(
":icons/eyedropper.png" ),
79 tr(
"Eyedropper Tool (%1): "
80 "Set color from the stage<br>[ALT] for instant access" )
81 .arg( GetToolTips( CMD_TOOL_EYEDROPPER ) ) );
82 clearButton = newToolButton( QIcon(
":icons/clear.png" ),
83 tr(
"Clear Frame (%1): Erases content of selected frame" )
84 .arg( GetToolTips( CMD_CLEAR_FRAME ) ) );
85 smudgeButton = newToolButton( QIcon(
":icons/smudge.png" ),
86 tr(
"Smudge Tool (%1):<br>Edit polyline/curves<br>"
87 "Liquify bitmap pixels<br> (%1)+[Alt]: Smooth" )
88 .arg( GetToolTips( CMD_TOOL_SMUDGE ) ) );
90 pencilButton->setWhatsThis( tr(
"Pencil Tool (%1)" )
91 .arg( GetToolTips( CMD_TOOL_PENCIL ) ) );
92 selectButton->setWhatsThis( tr(
"Select Tool (%1)" )
93 .arg( GetToolTips( CMD_TOOL_SELECT ) ) );
94 moveButton->setWhatsThis( tr(
"Move Tool (%1)" )
95 .arg( GetToolTips( CMD_TOOL_MOVE ) ) );
96 handButton->setWhatsThis( tr(
"Hand Tool (%1)" )
97 .arg( GetToolTips( CMD_TOOL_HAND ) ) );
98 penButton->setWhatsThis( tr(
"Pen Tool (%1)" )
99 .arg( GetToolTips( CMD_TOOL_PEN ) ) );
100 eraserButton->setWhatsThis( tr(
"Eraser Tool (%1)" )
101 .arg( GetToolTips( CMD_TOOL_ERASER ) ) );
102 polylineButton->setWhatsThis( tr(
"Polyline Tool (%1)" )
103 .arg( GetToolTips( CMD_TOOL_POLYLINE ) ) );
104 bucketButton->setWhatsThis( tr(
"Paint Bucket Tool (%1)" )
105 .arg( GetToolTips( CMD_TOOL_BUCKET ) ) );
106 colouringButton->setWhatsThis( tr(
"Brush Tool (%1)" )
107 .arg( GetToolTips( CMD_TOOL_BRUSH ) ) );
108 eyedropperButton->setWhatsThis( tr(
"Eyedropper Tool (%1)" )
109 .arg( GetToolTips( CMD_TOOL_EYEDROPPER ) ) );
110 clearButton->setWhatsThis( tr(
"Clear Tool (%1)" )
111 .arg( GetToolTips( CMD_CLEAR_FRAME ) ) );
112 smudgeButton->setWhatsThis( tr(
"Smudge Tool (%1)" )
113 .arg( GetToolTips( CMD_TOOL_SMUDGE ) ) );
115 pencilButton->setCheckable(
true );
116 penButton->setCheckable(
true );
117 polylineButton->setCheckable(
true );
118 bucketButton->setCheckable(
true );
119 colouringButton->setCheckable(
true );
120 smudgeButton->setCheckable(
true );
121 eyedropperButton->setCheckable(
true );
122 selectButton->setCheckable(
true );
123 moveButton->setCheckable(
true );
124 handButton->setCheckable(
true );
125 eraserButton->setCheckable(
true );
126 pencilButton->setChecked(
true );
128 layout->setMargin( 2 );
129 layout->setSpacing( 0 );
131 layout->addWidget( moveButton, 0, 0 );
132 layout->setAlignment( moveButton, Qt::AlignRight );
133 layout->addWidget( clearButton, 0, 1 );
134 layout->setAlignment( clearButton, Qt::AlignLeft );
136 layout->addWidget( selectButton, 1, 0 );
137 layout->setAlignment( selectButton, Qt::AlignRight );
138 layout->addWidget( colouringButton, 1, 1 );
139 layout->setAlignment( colouringButton, Qt::AlignLeft );
141 layout->addWidget( polylineButton, 2, 0 );
142 layout->setAlignment( polylineButton, Qt::AlignRight );
143 layout->addWidget( smudgeButton, 2, 1 );
144 layout->setAlignment( smudgeButton, Qt::AlignLeft );
146 layout->addWidget( penButton, 3, 0 );
147 layout->setAlignment( penButton, Qt::AlignRight );
148 layout->addWidget( handButton, 3, 1 );
149 layout->setAlignment( handButton, Qt::AlignLeft );
151 layout->addWidget( pencilButton, 4, 0 );
152 layout->setAlignment( pencilButton, Qt::AlignRight );
153 layout->addWidget( bucketButton, 4, 1 );
154 layout->setAlignment( bucketButton, Qt::AlignLeft );
156 layout->addWidget( eyedropperButton, 5, 0 );
157 layout->setAlignment( eyedropperButton, Qt::AlignRight );
158 layout->addWidget( eraserButton, 5, 1 );
159 layout->setAlignment( eraserButton, Qt::AlignLeft );
161 QWidget* toolGroup =
new QWidget();
162 setWidget( toolGroup );
163 toolGroup->setLayout( layout );
164 toolGroup->setMaximumHeight( 6 * 32 + 1 );
166 setMaximumHeight( 200 );
168 connect( pencilButton, &QToolButton::clicked,
this, &ToolBoxWidget::pencilOn );
169 connect( eraserButton, &QToolButton::clicked,
this, &ToolBoxWidget::eraserOn );
170 connect( selectButton, &QToolButton::clicked,
this, &ToolBoxWidget::selectOn );
171 connect( moveButton, &QToolButton::clicked,
this, &ToolBoxWidget::moveOn );
172 connect( penButton, &QToolButton::clicked,
this, &ToolBoxWidget::penOn );
173 connect( handButton, &QToolButton::clicked,
this, &ToolBoxWidget::handOn );
174 connect( polylineButton, &QToolButton::clicked,
this, &ToolBoxWidget::polylineOn );
175 connect( bucketButton, &QToolButton::clicked,
this, &ToolBoxWidget::bucketOn );
176 connect( eyedropperButton, &QToolButton::clicked,
this, &ToolBoxWidget::eyedropperOn );
177 connect( colouringButton, &QToolButton::clicked,
this, &ToolBoxWidget::brushOn );
178 connect( smudgeButton, &QToolButton::clicked,
this, &ToolBoxWidget::smudgeOn );
181 connect( clearButton, &QToolButton::clicked,
this, &ToolBoxWidget::clearButtonClicked );
185 void ToolBoxWidget::updateUI()
190 QToolButton* ToolBoxWidget::newToolButton(
const QIcon& icon, QString strToolTip)
192 QToolButton* toolButton =
new QToolButton(
this);
193 toolButton->setAutoRaise(
true);
194 toolButton->setIconSize( QSize(24,24) );
195 toolButton->setFixedSize(32, 32);
196 toolButton->setIcon(icon);
197 toolButton->setToolTip(strToolTip);
202 void ToolBoxWidget::pencilOn()
204 editor()->tools()->setCurrentTool( PENCIL );
207 pencilButton->setChecked(
true);
210 void ToolBoxWidget::eraserOn()
212 editor()->tools()->setCurrentTool( ERASER );
215 eraserButton->setChecked(
true);
218 void ToolBoxWidget::selectOn()
220 editor()->tools()->setCurrentTool( SELECT );
223 selectButton->setChecked(
true);
226 void ToolBoxWidget::moveOn()
228 editor()->tools()->setCurrentTool( MOVE );
231 moveButton->setChecked(
true);
234 void ToolBoxWidget::penOn()
236 editor()->tools()->setCurrentTool( PEN );
239 penButton->setChecked(
true);
242 void ToolBoxWidget::handOn()
244 editor()->tools()->setCurrentTool( HAND );
247 handButton->setChecked(
true);
250 void ToolBoxWidget::polylineOn()
252 editor()->tools()->setCurrentTool( POLYLINE );
255 polylineButton->setChecked(
true);
258 void ToolBoxWidget::bucketOn()
260 editor()->tools()->setCurrentTool( BUCKET );
263 bucketButton->setChecked(
true);
266 void ToolBoxWidget::eyedropperOn()
268 editor()->tools()->setCurrentTool( EYEDROPPER );
271 eyedropperButton->setChecked(
true);
274 void ToolBoxWidget::brushOn()
276 editor()->tools()->setCurrentTool( BRUSH );
279 colouringButton->setChecked(
true);
282 void ToolBoxWidget::smudgeOn()
284 editor()->tools()->setCurrentTool( SMUDGE );
287 smudgeButton->setChecked(
true);
290 void ToolBoxWidget::deselectAllTools()
292 pencilButton->setChecked(
false);
293 eraserButton->setChecked(
false);
294 selectButton->setChecked(
false);
295 moveButton->setChecked(
false);
296 handButton->setChecked(
false);
297 penButton->setChecked(
false);
298 polylineButton->setChecked(
false);
299 bucketButton->setChecked(
false);
300 eyedropperButton->setChecked(
false);
301 colouringButton->setChecked(
false);
302 smudgeButton->setChecked(
false);