Qt 4.8
qmltoolbar.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** 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.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qmltoolbar.h"
43 #include "toolbarcolorbox.h"
44 
45 #include <QtGui/QLabel>
46 #include <QtGui/QIcon>
47 #include <QtGui/QAction>
48 #include <QtGui/QMenu>
49 
50 #include <QtCore/QDebug>
51 
52 namespace QmlJSDebugger {
53 
55  : QToolBar(parent)
56  , m_emitSignals(true)
57  , m_paused(false)
58  , m_animationSpeed(1.0f)
59  , ui(new Ui)
60 {
61  ui->playIcon = QIcon(QLatin1String(":/qml/images/play-24.png"));
62  ui->pauseIcon = QIcon(QLatin1String(":/qml/images/pause-24.png"));
63 
64  ui->designmode = new QAction(QIcon(QLatin1String(":/qml/images/inspectormode-24.png")),
65  tr("Inspector Mode"), this);
66  ui->play = new QAction(ui->pauseIcon, tr("Play/Pause Animations"), this);
67  ui->select = new QAction(QIcon(QLatin1String(":/qml/images/select-24.png")), tr("Select"), this);
68  ui->selectMarquee = new QAction(QIcon(QLatin1String(":/qml/images/select-marquee-24.png")),
69  tr("Select (Marquee)"), this);
70  ui->zoom = new QAction(QIcon(QLatin1String(":/qml/images/zoom-24.png")), tr("Zoom"), this);
71  ui->colorPicker = new QAction(QIcon(QLatin1String(":/qml/images/color-picker-24.png")),
72  tr("Color Picker"), this);
73  ui->toQml = new QAction(QIcon(QLatin1String(":/qml/images/to-qml-24.png")),
74  tr("Apply Changes to QML Viewer"), this);
75  ui->fromQml = new QAction(QIcon(QLatin1String(":/qml/images/from-qml-24.png")),
76  tr("Apply Changes to Document"), this);
77  ui->designmode->setCheckable(true);
78  ui->designmode->setChecked(false);
79 
80  ui->play->setCheckable(false);
81  ui->select->setCheckable(true);
83  ui->zoom->setCheckable(true);
84  ui->colorPicker->setCheckable(true);
85 
86  setWindowTitle(tr("Tools"));
87 
89  addAction(ui->play);
90  addSeparator();
91 
93  // disabled because multi selection does not do anything useful without design mode
94  //addAction(ui->selectMarquee);
95  addSeparator();
96  addAction(ui->zoom);
98  //addAction(ui->fromQml);
99 
100  ui->colorBox = new ToolBarColorBox(this);
101  ui->colorBox->setMinimumSize(24, 24);
102  ui->colorBox->setMaximumSize(28, 28);
105 
107 
108  QMenu *playSpeedMenu = new QMenu(this);
109  ui->playSpeedMenuActions = new QActionGroup(this);
111 
112  QAction *speedAction = playSpeedMenu->addAction(tr("1x"), this, SLOT(changeAnimationSpeed()));
113  speedAction->setCheckable(true);
114  speedAction->setChecked(true);
115  speedAction->setData(1.0f);
116  ui->playSpeedMenuActions->addAction(speedAction);
117 
118  speedAction = playSpeedMenu->addAction(tr("0.5x"), this, SLOT(changeAnimationSpeed()));
119  speedAction->setCheckable(true);
120  speedAction->setData(2.0f);
121  ui->playSpeedMenuActions->addAction(speedAction);
122 
123  speedAction = playSpeedMenu->addAction(tr("0.25x"), this, SLOT(changeAnimationSpeed()));
124  speedAction->setCheckable(true);
125  speedAction->setData(4.0f);
126  ui->playSpeedMenuActions->addAction(speedAction);
127 
128  speedAction = playSpeedMenu->addAction(tr("0.125x"), this, SLOT(changeAnimationSpeed()));
129  speedAction->setCheckable(true);
130  speedAction->setData(8.0f);
131  ui->playSpeedMenuActions->addAction(speedAction);
132 
133  speedAction = playSpeedMenu->addAction(tr("0.1x"), this, SLOT(changeAnimationSpeed()));
134  speedAction->setCheckable(true);
135  speedAction->setData(10.0f);
136  ui->playSpeedMenuActions->addAction(speedAction);
137 
138  ui->play->setMenu(playSpeedMenu);
139 
140  connect(ui->designmode, SIGNAL(toggled(bool)), SLOT(setDesignModeBehaviorOnClick(bool)));
141 
143 
144  connect(ui->play, SIGNAL(triggered()), SLOT(activatePlayOnClick()));
145 
146  connect(ui->zoom, SIGNAL(triggered()), SLOT(activateZoomOnClick()));
150 
151  connect(ui->toQml, SIGNAL(triggered()), SLOT(activateToQml()));
152  connect(ui->fromQml, SIGNAL(triggered()), SLOT(activateFromQml()));
153 }
154 
156 {
157  delete ui;
158 }
159 
161 {
162  m_emitSignals = false;
164  m_emitSignals = true;
165 }
166 
168 {
169  m_emitSignals = false;
171  m_emitSignals = true;
172 }
173 
175 {
176  m_emitSignals = false;
178  m_emitSignals = true;
179 }
180 
182 {
183  m_emitSignals = false;
185  m_emitSignals = true;
186 }
187 
189 {
190  if (m_animationSpeed == slowDownFactor)
191  return;
192 
193  m_emitSignals = false;
194  m_animationSpeed = slowDownFactor;
195 
196  foreach (QAction *action, ui->playSpeedMenuActions->actions()) {
197  if (action->data().toReal() == slowDownFactor) {
198  action->setChecked(true);
199  break;
200  }
201  }
202 
203  m_emitSignals = true;
204 }
205 
207 {
208  if (m_paused == paused)
209  return;
210 
211  m_paused = paused;
213 }
214 
216 {
217  QAction *action = qobject_cast<QAction*>(sender());
218  m_animationSpeed = action->data().toReal();
219  emit animationSpeedChanged(m_animationSpeed);
220 }
221 
222 void QmlToolBar::setDesignModeBehavior(bool inDesignMode)
223 {
224  m_emitSignals = false;
225  ui->designmode->setChecked(inDesignMode);
226  setDesignModeBehaviorOnClick(inDesignMode);
227  m_emitSignals = true;
228 }
229 
231 {
232  ui->select->setEnabled(checked);
233  ui->selectMarquee->setEnabled(checked);
234  ui->zoom->setEnabled(checked);
235  ui->colorPicker->setEnabled(checked);
236  ui->toQml->setEnabled(checked);
237  ui->fromQml->setEnabled(checked);
238 
239  if (m_emitSignals)
241 }
242 
244 {
245  ui->colorBox->setColor(color);
246 }
247 
249 {
250  m_paused = !m_paused;
253 }
254 
256 {
258 }
259 
261 {
262  ui->zoom->setChecked(false);
263  ui->select->setChecked(false);
264  ui->selectMarquee->setChecked(false);
265 
266  ui->colorPicker->setChecked(true);
269  if (m_emitSignals)
271  }
272 }
273 
275 {
276  ui->zoom->setChecked(false);
277  ui->selectMarquee->setChecked(false);
278  ui->colorPicker->setChecked(false);
279 
280  ui->select->setChecked(true);
283  if (m_emitSignals)
285  }
286 }
287 
289 {
290  ui->zoom->setChecked(false);
291  ui->select->setChecked(false);
292  ui->colorPicker->setChecked(false);
293 
294  ui->selectMarquee->setChecked(true);
297  if (m_emitSignals)
299  }
300 }
301 
303 {
304  ui->select->setChecked(false);
305  ui->selectMarquee->setChecked(false);
306  ui->colorPicker->setChecked(false);
307 
308  ui->zoom->setChecked(true);
311  if (m_emitSignals)
313  }
314 }
315 
317 {
318  if (m_emitSignals)
320 }
321 
323 {
324  if (m_emitSignals)
326 }
327 
328 } // namespace QmlJSDebugger
void animationSpeedChanged(qreal factor)
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
void setCheckable(bool)
Definition: qaction.cpp:1094
#define SLOT(a)
Definition: qobjectdefs.h:226
void setMenu(QMenu *menu)
Sets the menu contained by this action to the specified menu.
Definition: qaction.cpp:802
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setMaximumSize(const QSize &)
Definition: qwidget.h:972
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setMinimumSize(const QSize &)
Definition: qwidget.h:969
void setDesignModeBehavior(bool inDesignMode)
Definition: qmltoolbar.cpp:222
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
void setData(const QVariant &var)
Sets the action&#39;s internal data to the given userData.
Definition: qaction.cpp:1297
void setEnabled(bool)
Definition: qaction.cpp:1192
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void setDesignModeBehaviorOnClick(bool inDesignMode)
Definition: qmltoolbar.cpp:230
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
QAction * addAction(QAction *a)
Adds the action to this group, and returns it.
#define emit
Definition: qobjectdefs.h:76
void setWindowFlags(Qt::WindowFlags type)
Definition: qwidget.cpp:10399
Constants::DesignTool m_activeTool
Definition: qmltoolbar.h:125
void setColor(const QColor &color)
void setAnimationPaused(bool paused)
Definition: qmltoolbar.cpp:206
void setExclusive(bool)
QAction * addSeparator()
Adds a separator to the end of the toolbar.
Definition: qtoolbar.cpp:936
void setColorBoxColor(const QColor &color)
Definition: qmltoolbar.cpp:243
void animationPausedChanged(bool paused)
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setChecked(bool)
Definition: qaction.cpp:1138
QAction * addWidget(QWidget *widget)
Adds the given widget to the toolbar as the toolbar&#39;s last item.
Definition: qtoolbar.cpp:973
QVariant data() const
Returns the user data as set in QAction::setData.
Definition: qaction.cpp:1280
void setIcon(const QIcon &icon)
Definition: qaction.cpp:772
void setAnimationSpeed(qreal slowDownFactor)
Definition: qmltoolbar.cpp:188
QList< QAction * > actions() const
Returns the list of this groups&#39;s actions.
QAction * addAction(const QString &text)
Creates a new action with the given text.
Definition: qtoolbar.cpp:868
ToolBarColorBox * colorBox
Definition: qmltoolbar.h:116
QActionGroup * playSpeedMenuActions
Definition: qmltoolbar.h:118
void designModeBehaviorChanged(bool inDesignMode)
QmlToolBar(QWidget *parent=0)
Definition: qmltoolbar.cpp:54
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60