1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
39 #include "qmltoolbar.h"
40 #include "toolbarcolorbox.h"
44 namespace QmlJSDebugger {
46 QmlToolbar::QmlToolbar(QWidget *parent)
50 , m_animationSpeed(1.0f)
51 , m_previousAnimationSpeed(0.0f)
54 ui->playIcon = QIcon(QLatin1String(":/qml/images/play-24.png"));
55 ui->pauseIcon = QIcon(QLatin1String(":/qml/images/pause-24.png"));
57 ui->designmode = new QAction(QIcon(QLatin1String(":/qml/images/observermode-24.png")),
58 tr("Observer Mode"), this);
59 ui->play = new QAction(ui->pauseIcon, tr("Play/Pause Animations"), this);
60 ui->select = new QAction(QIcon(QLatin1String(":/qml/images/select-24.png")), tr("Select"), this);
61 ui->selectMarquee = new QAction(QIcon(QLatin1String(":/qml/images/select-marquee-24.png")),
62 tr("Select (Marquee)"), this);
63 ui->zoom = new QAction(QIcon(QLatin1String(":/qml/images/zoom-24.png")), tr("Zoom"), this);
64 ui->colorPicker = new QAction(QIcon(QLatin1String(":/qml/images/color-picker-24.png")),
65 tr("Color Picker"), this);
66 ui->toQml = new QAction(QIcon(QLatin1String(":/qml/images/to-qml-24.png")),
67 tr("Apply Changes to QML Viewer"), this);
68 ui->fromQml = new QAction(QIcon(QLatin1String(":/qml/images/from-qml-24.png")),
69 tr("Apply Changes to Document"), this);
70 ui->designmode->setCheckable(true);
71 ui->designmode->setChecked(false);
73 ui->play->setCheckable(false);
74 ui->select->setCheckable(true);
75 ui->selectMarquee->setCheckable(true);
76 ui->zoom->setCheckable(true);
77 ui->colorPicker->setCheckable(true);
79 setWindowTitle(tr("Tools"));
81 addAction(ui->designmode);
85 addAction(ui->select);
86 // disabled because multi selection does not do anything useful without design mode
87 //addAction(ui->selectMarquee);
90 addAction(ui->colorPicker);
91 //addAction(ui->fromQml);
93 ui->colorBox = new ToolBarColorBox(this);
94 ui->colorBox->setMinimumSize(24, 24);
95 ui->colorBox->setMaximumSize(28, 28);
96 ui->colorBox->setColor(Qt::black);
97 addWidget(ui->colorBox);
99 setWindowFlags(Qt::Tool);
101 QMenu *playSpeedMenu = new QMenu(this);
102 QActionGroup *playSpeedMenuActions = new QActionGroup(this);
103 playSpeedMenuActions->setExclusive(true);
104 playSpeedMenu->addAction(tr("Animation Speed"));
105 playSpeedMenu->addSeparator();
106 ui->defaultAnimSpeedAction = playSpeedMenu->addAction(tr("1x"), this,
107 SLOT(changeToDefaultAnimSpeed()));
108 ui->defaultAnimSpeedAction->setCheckable(true);
109 ui->defaultAnimSpeedAction->setChecked(true);
110 playSpeedMenuActions->addAction(ui->defaultAnimSpeedAction);
112 ui->halfAnimSpeedAction = playSpeedMenu->addAction(tr("0.5x"), this,
113 SLOT(changeToHalfAnimSpeed()));
114 ui->halfAnimSpeedAction->setCheckable(true);
115 playSpeedMenuActions->addAction(ui->halfAnimSpeedAction);
117 ui->fourthAnimSpeedAction = playSpeedMenu->addAction(tr("0.25x"), this,
118 SLOT(changeToFourthAnimSpeed()));
119 ui->fourthAnimSpeedAction->setCheckable(true);
120 playSpeedMenuActions->addAction(ui->fourthAnimSpeedAction);
122 ui->eighthAnimSpeedAction = playSpeedMenu->addAction(tr("0.125x"), this,
123 SLOT(changeToEighthAnimSpeed()));
124 ui->eighthAnimSpeedAction->setCheckable(true);
125 playSpeedMenuActions->addAction(ui->eighthAnimSpeedAction);
127 ui->tenthAnimSpeedAction = playSpeedMenu->addAction(tr("0.1x"), this,
128 SLOT(changeToTenthAnimSpeed()));
129 ui->tenthAnimSpeedAction->setCheckable(true);
130 playSpeedMenuActions->addAction(ui->tenthAnimSpeedAction);
132 ui->menuPauseAction = playSpeedMenu->addAction(tr("Pause"), this, SLOT(updatePauseAction()));
133 ui->menuPauseAction->setCheckable(true);
134 ui->menuPauseAction->setIcon(ui->pauseIcon);
135 playSpeedMenuActions->addAction(ui->menuPauseAction);
136 ui->play->setMenu(playSpeedMenu);
138 connect(ui->designmode, SIGNAL(toggled(bool)), SLOT(setDesignModeBehaviorOnClick(bool)));
140 connect(ui->colorPicker, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
142 connect(ui->play, SIGNAL(triggered()), SLOT(activatePlayOnClick()));
144 connect(ui->zoom, SIGNAL(triggered()), SLOT(activateZoomOnClick()));
145 connect(ui->colorPicker, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
146 connect(ui->select, SIGNAL(triggered()), SLOT(activateSelectToolOnClick()));
147 connect(ui->selectMarquee, SIGNAL(triggered()), SLOT(activateMarqueeSelectToolOnClick()));
149 connect(ui->toQml, SIGNAL(triggered()), SLOT(activateToQml()));
150 connect(ui->fromQml, SIGNAL(triggered()), SLOT(activateFromQml()));
153 QmlToolbar::~QmlToolbar()
158 void QmlToolbar::activateColorPicker()
160 m_emitSignals = false;
161 activateColorPickerOnClick();
162 m_emitSignals = true;
165 void QmlToolbar::activateSelectTool()
167 m_emitSignals = false;
168 activateSelectToolOnClick();
169 m_emitSignals = true;
172 void QmlToolbar::activateMarqueeSelectTool()
174 m_emitSignals = false;
175 activateMarqueeSelectToolOnClick();
176 m_emitSignals = true;
179 void QmlToolbar::activateZoom()
181 m_emitSignals = false;
182 activateZoomOnClick();
183 m_emitSignals = true;
186 void QmlToolbar::setAnimationSpeed(qreal slowdownFactor)
188 m_emitSignals = false;
189 if (slowdownFactor != 0) {
190 m_animationSpeed = slowdownFactor;
192 if (slowdownFactor == 1.0f) {
193 ui->defaultAnimSpeedAction->setChecked(true);
194 } else if (slowdownFactor == 2.0f) {
195 ui->halfAnimSpeedAction->setChecked(true);
196 } else if (slowdownFactor == 4.0f) {
197 ui->fourthAnimSpeedAction->setChecked(true);
198 } else if (slowdownFactor == 8.0f) {
199 ui->eighthAnimSpeedAction->setChecked(true);
200 } else if (slowdownFactor == 10.0f) {
201 ui->tenthAnimSpeedAction->setChecked(true);
205 ui->menuPauseAction->setChecked(true);
209 m_emitSignals = true;
212 void QmlToolbar::changeToDefaultAnimSpeed()
214 m_animationSpeed = 1.0f;
218 void QmlToolbar::changeToHalfAnimSpeed()
220 m_animationSpeed = 2.0f;
224 void QmlToolbar::changeToFourthAnimSpeed()
226 m_animationSpeed = 4.0f;
230 void QmlToolbar::changeToEighthAnimSpeed()
232 m_animationSpeed = 8.0f;
236 void QmlToolbar::changeToTenthAnimSpeed()
238 m_animationSpeed = 10.0f;
243 void QmlToolbar::setDesignModeBehavior(bool inDesignMode)
245 m_emitSignals = false;
246 ui->designmode->setChecked(inDesignMode);
247 setDesignModeBehaviorOnClick(inDesignMode);
248 m_emitSignals = true;
251 void QmlToolbar::setDesignModeBehaviorOnClick(bool checked)
253 ui->play->setEnabled(checked);
254 ui->select->setEnabled(checked);
255 ui->selectMarquee->setEnabled(checked);
256 ui->zoom->setEnabled(checked);
257 ui->colorPicker->setEnabled(checked);
258 ui->toQml->setEnabled(checked);
259 ui->fromQml->setEnabled(checked);
262 emit designModeBehaviorChanged(checked);
265 void QmlToolbar::setColorBoxColor(const QColor &color)
267 ui->colorBox->setColor(color);
270 void QmlToolbar::activatePlayOnClick()
279 void QmlToolbar::updatePlayAction()
282 ui->play->setIcon(ui->pauseIcon);
283 if (m_animationSpeed != m_previousAnimationSpeed)
284 m_previousAnimationSpeed = m_animationSpeed;
287 emit animationSpeedChanged(m_animationSpeed);
290 void QmlToolbar::updatePauseAction()
293 ui->play->setIcon(ui->playIcon);
295 emit animationSpeedChanged(0.0f);
298 void QmlToolbar::activateColorPickerOnClick()
300 ui->zoom->setChecked(false);
301 ui->select->setChecked(false);
302 ui->selectMarquee->setChecked(false);
304 ui->colorPicker->setChecked(true);
305 if (m_activeTool != Constants::ColorPickerMode) {
306 m_activeTool = Constants::ColorPickerMode;
308 emit colorPickerSelected();
312 void QmlToolbar::activateSelectToolOnClick()
314 ui->zoom->setChecked(false);
315 ui->selectMarquee->setChecked(false);
316 ui->colorPicker->setChecked(false);
318 ui->select->setChecked(true);
319 if (m_activeTool != Constants::SelectionToolMode) {
320 m_activeTool = Constants::SelectionToolMode;
322 emit selectToolSelected();
326 void QmlToolbar::activateMarqueeSelectToolOnClick()
328 ui->zoom->setChecked(false);
329 ui->select->setChecked(false);
330 ui->colorPicker->setChecked(false);
332 ui->selectMarquee->setChecked(true);
333 if (m_activeTool != Constants::MarqueeSelectionToolMode) {
334 m_activeTool = Constants::MarqueeSelectionToolMode;
336 emit marqueeSelectToolSelected();
340 void QmlToolbar::activateZoomOnClick()
342 ui->select->setChecked(false);
343 ui->selectMarquee->setChecked(false);
344 ui->colorPicker->setChecked(false);
346 ui->zoom->setChecked(true);
347 if (m_activeTool != Constants::ZoomMode) {
348 m_activeTool = Constants::ZoomMode;
350 emit zoomToolSelected();
354 void QmlToolbar::activateFromQml()
357 emit applyChangesFromQmlFileSelected();
360 void QmlToolbar::activateToQml()
363 emit applyChangesToQmlFileSelected();