From bff9e2618bfaac5b409d85bd3cec2917f5c177a1 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 28 Jun 2011 09:57:55 +0200 Subject: QmlJSInspector: Fix naming of QmlInspectorToolBar Add a 'Js' to make it align with the other classes of the plugin. Change-Id: If9514d7ed3a2244a60e7ebc72256ddfc25695c68 Reviewed-on: http://codereview.qt.nokia.com/817 Reviewed-by: Qt Sanity Bot Reviewed-by: Christiaan Janssen --- src/plugins/qmljsinspector/qmlinspectortoolbar.cpp | 393 -------------------- src/plugins/qmljsinspector/qmlinspectortoolbar.h | 157 -------- src/plugins/qmljsinspector/qmljsinspector.cpp | 4 +- src/plugins/qmljsinspector/qmljsinspector.h | 4 +- src/plugins/qmljsinspector/qmljsinspector.pro | 4 +- .../qmljsinspector/qmljsinspectorplugin.cpp | 25 +- .../qmljsinspector/qmljsinspectortoolbar.cpp | 394 +++++++++++++++++++++ src/plugins/qmljsinspector/qmljsinspectortoolbar.h | 157 ++++++++ 8 files changed, 568 insertions(+), 570 deletions(-) delete mode 100644 src/plugins/qmljsinspector/qmlinspectortoolbar.cpp delete mode 100644 src/plugins/qmljsinspector/qmlinspectortoolbar.h create mode 100644 src/plugins/qmljsinspector/qmljsinspectortoolbar.cpp create mode 100644 src/plugins/qmljsinspector/qmljsinspectortoolbar.h (limited to 'src') diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp b/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp deleted file mode 100644 index 2aebf1a2e3..0000000000 --- a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#include "qmlinspectortoolbar.h" -#include "qmljsinspectorconstants.h" -#include "qmljstoolbarcolorbox.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace QmlJSInspector { -namespace Internal { - -static QToolButton *toolButton(QAction *action) -{ - QToolButton *button = new QToolButton; - button->setDefaultAction(action); - return button; -} - -QmlInspectorToolBar::QmlInspectorToolBar(QObject *parent) : - QObject(parent), - m_fromQmlAction(0), - m_playAction(0), - m_selectAction(0), - m_zoomAction(0), - m_colorPickerAction(0), - m_showAppOnTopAction(0), - m_playSpeedMenuActions(0), - m_playIcon(QIcon(QLatin1String(":/qml/images/play-small.png"))), - m_pauseIcon(QIcon(QLatin1String(":/qml/images/pause-small.png"))), - m_colorBox(0), - m_emitSignals(true), - m_paused(false), - m_animationSpeed(1.0f), - m_designModeActive(false), - m_activeTool(NoTool), - m_barWidget(0) -{ -} - -void QmlInspectorToolBar::setEnabled(bool value) -{ - m_fromQmlAction->setEnabled(value); - m_showAppOnTopAction->setEnabled(value); - m_playAction->setEnabled(value); - m_selectAction->setEnabled(value); - m_zoomAction->setEnabled(value); - m_colorPickerAction->setEnabled(value); - m_colorBox->setEnabled(value); -} - -void QmlInspectorToolBar::enable() -{ - setEnabled(true); - m_emitSignals = false; - m_showAppOnTopAction->setChecked(false); - setAnimationSpeed(1.0f); - m_designModeActive = false; - updateDesignModeActions(NoTool); - m_emitSignals = true; -} - -void QmlInspectorToolBar::disable() -{ - setAnimationSpeed(1.0f); - m_designModeActive = false; - updateDesignModeActions(NoTool); - setEnabled(false); -} - -void QmlInspectorToolBar::activateColorPicker() -{ - updateDesignModeActions(ColorPickerMode); -} - -void QmlInspectorToolBar::activateSelectTool() -{ - updateDesignModeActions(SelectionToolMode); -} - -void QmlInspectorToolBar::activateZoomTool() -{ - updateDesignModeActions(ZoomMode); -} - -void QmlInspectorToolBar::setAnimationSpeed(qreal slowDownFactor) -{ - if (m_animationSpeed == slowDownFactor) - return; - - m_emitSignals = false; - m_animationSpeed = slowDownFactor; - - foreach (QAction *action, m_playSpeedMenuActions->actions()) { - if (action->data().toReal() == slowDownFactor) { - action->setChecked(true); - break; - } - } - - m_emitSignals = true; -} - -void QmlInspectorToolBar::setAnimationPaused(bool paused) -{ - if (m_paused == paused) - return; - - m_paused = paused; - updatePlayAction(); -} - -void QmlInspectorToolBar::setDesignModeBehavior(bool inDesignMode) -{ - m_emitSignals = false; - m_designModeActive = inDesignMode; - updateDesignModeActions(m_activeTool); - m_emitSignals = true; -} - -void QmlInspectorToolBar::setShowAppOnTop(bool showAppOnTop) -{ - m_emitSignals = false; - m_showAppOnTopAction->setChecked(showAppOnTop); - m_emitSignals = true; -} - -void QmlInspectorToolBar::createActions() -{ - Core::Context context(Debugger::Constants::C_QMLDEBUGGER); - Core::ICore *core = Core::ICore::instance(); - Core::ActionManager *am = core->actionManager(); - - m_fromQmlAction = - new QAction(QIcon(QLatin1String(":/qml/images/from-qml-small.png")), - tr("Apply Changes on Save"), this); - m_showAppOnTopAction = - new QAction(QIcon(QLatin1String(":/qml/images/app-on-top.png")), - tr("Show application on top"), this); - m_playAction = - new QAction(m_pauseIcon, tr("Play/Pause Animations"), this); - m_selectAction = - new QAction(QIcon(QLatin1String(":/qml/images/select-small.png")), - tr("Select"), this); - m_zoomAction = - new QAction(QIcon(QLatin1String(":/qml/images/zoom-small.png")), - tr("Zoom"), this); - m_colorPickerAction = - new QAction(QIcon(QLatin1String(":/qml/images/color-picker-small.png")), - tr("Color Picker"), this); - - m_fromQmlAction->setCheckable(true); - m_fromQmlAction->setChecked(true); - m_showAppOnTopAction->setCheckable(true); - m_showAppOnTopAction->setChecked(false); - m_selectAction->setCheckable(true); - m_zoomAction->setCheckable(true); - m_colorPickerAction->setCheckable(true); - - Core::Command *command = am->registerAction(m_playAction, Constants::PLAY_ACTION, context); - command->setAttribute(Core::Command::CA_UpdateIcon); - am->registerAction(m_selectAction, Constants::SELECT_ACTION, context); - am->registerAction(m_zoomAction, Constants::ZOOM_ACTION, context); - am->registerAction(m_colorPickerAction, Constants::COLOR_PICKER_ACTION, context); - am->registerAction(m_fromQmlAction, Constants::FROM_QML_ACTION, context); - am->registerAction(m_showAppOnTopAction, Constants::SHOW_APP_ON_TOP_ACTION, context); - - m_barWidget = new Utils::StyledBar; - m_barWidget->setSingleRow(true); - m_barWidget->setProperty("topBorder", true); - - QMenu *playSpeedMenu = new QMenu(m_barWidget); - m_playSpeedMenuActions = new QActionGroup(this); - m_playSpeedMenuActions->setExclusive(true); - QAction *speedAction = playSpeedMenu->addAction(tr("1x"), this, SLOT(changeAnimationSpeed())); - speedAction->setCheckable(true); - speedAction->setChecked(true); - speedAction->setData(1.0f); - m_playSpeedMenuActions->addAction(speedAction); - - speedAction = playSpeedMenu->addAction(tr("0.5x"), this, SLOT(changeAnimationSpeed())); - speedAction->setCheckable(true); - speedAction->setData(2.0f); - m_playSpeedMenuActions->addAction(speedAction); - - speedAction = playSpeedMenu->addAction(tr("0.25x"), this, SLOT(changeAnimationSpeed())); - speedAction->setCheckable(true); - speedAction->setData(4.0f); - m_playSpeedMenuActions->addAction(speedAction); - - speedAction = playSpeedMenu->addAction(tr("0.125x"), this, SLOT(changeAnimationSpeed())); - speedAction->setCheckable(true); - speedAction->setData(8.0f); - m_playSpeedMenuActions->addAction(speedAction); - - speedAction = playSpeedMenu->addAction(tr("0.1x"), this, SLOT(changeAnimationSpeed())); - speedAction->setCheckable(true); - speedAction->setData(10.0f); - m_playSpeedMenuActions->addAction(speedAction); - - QHBoxLayout *toolBarLayout = new QHBoxLayout(m_barWidget); - toolBarLayout->setMargin(0); - toolBarLayout->setSpacing(5); - - m_operateByInstructionButton = toolButton(am->command(Debugger::Constants::OPERATE_BY_INSTRUCTION)->action()); - - // Add generic debugging controls - toolBarLayout->addWidget(toolButton(Debugger::DebuggerPlugin::visibleDebugAction())); - toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::STOP)->action())); - toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::NEXT)->action())); - toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::STEP)->action())); - toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::STEPOUT)->action())); - toolBarLayout->addWidget(m_operateByInstructionButton); - toolBarLayout->addStretch(1); - - // QML Helpers - toolBarLayout->addWidget(new Utils::StyledSeparator); - toolBarLayout->addWidget(toolButton(am->command(Constants::FROM_QML_ACTION)->action())); - toolBarLayout->addWidget(toolButton(am->command(Constants::SHOW_APP_ON_TOP_ACTION)->action())); - m_playButton = toolButton(am->command(Constants::PLAY_ACTION)->action()); - m_playButton->setMenu(playSpeedMenu); - toolBarLayout->addWidget(m_playButton); - - // Inspector - toolBarLayout->addWidget(new Utils::StyledSeparator); - toolBarLayout->addWidget(toolButton(am->command(Constants::SELECT_ACTION)->action())); - toolBarLayout->addWidget(toolButton(am->command(Constants::ZOOM_ACTION)->action())); - toolBarLayout->addWidget(toolButton(am->command(Constants::COLOR_PICKER_ACTION)->action())); - - m_colorBox = new ToolBarColorBox(m_barWidget); - m_colorBox->setMinimumSize(20, 20); - m_colorBox->setMaximumSize(20, 20); - m_colorBox->setInnerBorderColor(QColor(192, 192, 192)); - m_colorBox->setOuterBorderColor(QColor(58, 58, 58)); - toolBarLayout->addWidget(m_colorBox); - - connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml())); - connect(m_showAppOnTopAction, SIGNAL(triggered()), SLOT(showAppOnTopClick())); - connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick())); - connect(m_colorPickerAction, SIGNAL(triggered(bool)), SLOT(colorPickerTriggered(bool))); - connect(m_selectAction, SIGNAL(triggered(bool)), SLOT(selectToolTriggered(bool))); - connect(m_zoomAction, SIGNAL(triggered(bool)), SLOT(zoomToolTriggered(bool))); - - Debugger::DebuggerMainWindow *mw = Debugger::DebuggerPlugin::mainWindow(); - activeDebugLanguagesChanged(mw->activeDebugLanguages()); - connect(mw, SIGNAL(activeDebugLanguagesChanged(Debugger::DebuggerLanguages)), - this, SLOT(activeDebugLanguagesChanged(Debugger::DebuggerLanguages))); -} - -QWidget *QmlInspectorToolBar::widget() const -{ - return m_barWidget; -} - -void QmlInspectorToolBar::changeAnimationSpeed() -{ - QAction *action = static_cast(sender()); - - m_animationSpeed = action->data().toReal(); - emit animationSpeedChanged(m_animationSpeed); - - updatePlayAction(); -} - -void QmlInspectorToolBar::activatePlayOnClick() -{ - m_paused = !m_paused; - emit animationPausedChanged(m_paused); - updatePlayAction(); -} - -void QmlInspectorToolBar::updatePlayAction() -{ - m_playAction->setIcon(m_paused ? m_playIcon : m_pauseIcon); -} - -void QmlInspectorToolBar::colorPickerTriggered(bool checked) -{ - updateDesignModeActions(ColorPickerMode); - - if (m_designModeActive != checked) { - m_designModeActive = checked; - emit designModeSelected(checked); - } - - if (checked) - emit colorPickerSelected(); -} - -void QmlInspectorToolBar::selectToolTriggered(bool checked) -{ - updateDesignModeActions(SelectionToolMode); - - if (m_designModeActive != checked) { - m_designModeActive = checked; - emit designModeSelected(checked); - } - - if (checked) - emit selectToolSelected(); -} - -void QmlInspectorToolBar::zoomToolTriggered(bool checked) -{ - updateDesignModeActions(ZoomMode); - - if (m_designModeActive != checked) { - m_designModeActive = checked; - emit designModeSelected(checked); - } - - if (checked) - emit zoomToolSelected(); -} - -void QmlInspectorToolBar::showAppOnTopClick() -{ - if (m_emitSignals) - emit showAppOnTopSelected(m_showAppOnTopAction->isChecked()); -} - -void QmlInspectorToolBar::setSelectedColor(const QColor &color) -{ - m_colorBox->setColor(color); -} - -void QmlInspectorToolBar::activateFromQml() -{ - if (m_emitSignals) - emit applyChangesFromQmlFileTriggered(m_fromQmlAction->isChecked()); -} - -void QmlInspectorToolBar::activeDebugLanguagesChanged(Debugger::DebuggerLanguages languages) -{ - m_operateByInstructionButton->setVisible(languages & Debugger::CppLanguage); -} - -void QmlInspectorToolBar::updateDesignModeActions(DesignTool activeTool) -{ - m_activeTool = activeTool; - m_selectAction->setChecked(m_designModeActive && (m_activeTool == SelectionToolMode)); - m_zoomAction->setChecked(m_designModeActive && (m_activeTool == ZoomMode)); - m_colorPickerAction->setChecked(m_designModeActive && (m_activeTool == ColorPickerMode)); -} - -} // namespace Internal -} // namespace QmlJSInspector diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.h b/src/plugins/qmljsinspector/qmlinspectortoolbar.h deleted file mode 100644 index aa7d1d1ff0..0000000000 --- a/src/plugins/qmljsinspector/qmlinspectortoolbar.h +++ /dev/null @@ -1,157 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#ifndef QMLINSPECTORTOOLBAR_H -#define QMLINSPECTORTOOLBAR_H - -#include - -#include -#include - -QT_BEGIN_NAMESPACE -class QAction; -class QActionGroup; -class QColor; -class QToolButton; -QT_END_NAMESPACE - -namespace Utils { -class StyledBar; -} - -namespace QmlJSInspector { - -class ToolBarColorBox; - -namespace Internal { - -class QmlInspectorToolBar : public QObject -{ - Q_OBJECT - -public: - enum DesignTool { - NoTool = 0, - SelectionToolMode = 1, - MarqueeSelectionToolMode = 2, - MoveToolMode = 3, - ResizeToolMode = 4, - ColorPickerMode = 5, - ZoomMode = 6 - }; - - explicit QmlInspectorToolBar(QObject *parent = 0); - void createActions(); - QWidget *widget() const; - -public slots: - void setEnabled(bool value); - void enable(); - void disable(); - - void activateColorPicker(); - void activateSelectTool(); - void activateZoomTool(); - - void setAnimationSpeed(qreal slowDownFactor); - void setAnimationPaused(bool paused); - - void setDesignModeBehavior(bool inDesignMode); - void setShowAppOnTop(bool showAppOnTop); - void setSelectedColor(const QColor &color); - -signals: - void applyChangesFromQmlFileTriggered(bool isChecked); - - void designModeSelected(bool); - void reloadSelected(); - void colorPickerSelected(); - void selectToolSelected(); - void zoomToolSelected(); - - void showAppOnTopSelected(bool isChecked); - - void animationSpeedChanged(qreal slowdownFactor); - void animationPausedChanged(bool paused); - -private slots: - void activatePlayOnClick(); - void colorPickerTriggered(bool checked); - void selectToolTriggered(bool checked); - void zoomToolTriggered(bool checked); - - void showAppOnTopClick(); - - void changeAnimationSpeed(); - - void activateFromQml(); - - void updatePlayAction(); - - void activeDebugLanguagesChanged(Debugger::DebuggerLanguages languages); - -private: - void updateDesignModeActions(DesignTool activeTool); - - QToolButton *m_operateByInstructionButton; - - QAction *m_fromQmlAction; - QAction *m_playAction; - QAction *m_selectAction; - QAction *m_zoomAction; - QAction *m_colorPickerAction; - - QAction *m_showAppOnTopAction; - - QActionGroup *m_playSpeedMenuActions; - - QToolButton *m_playButton; - QIcon m_playIcon; - QIcon m_pauseIcon; - - ToolBarColorBox *m_colorBox; - - bool m_emitSignals; - bool m_paused; - qreal m_animationSpeed; - - bool m_designModeActive; - DesignTool m_activeTool; - - Utils::StyledBar *m_barWidget; -}; - -} // namespace Internal -} // namespace QmlJSInspector - -#endif // QMLINSPECTORTOOLBAR_H diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp index 4ec3dc37e5..98e4390335 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.cpp +++ b/src/plugins/qmljsinspector/qmljsinspector.cpp @@ -32,7 +32,7 @@ #include "qmljsinspectorconstants.h" #include "qmljsinspector.h" -#include "qmlinspectortoolbar.h" +#include "qmljsinspectortoolbar.h" #include "qmljsclientproxy.h" #include "qmljslivetextpreview.h" #include "qmljsprivateapi.h" @@ -157,7 +157,7 @@ InspectorUi::InspectorUi(QObject *parent) , m_cursorPositionChangedExternally(false) { m_instance = this; - m_toolBar = new QmlInspectorToolBar(this); + m_toolBar = new QmlJsInspectorToolBar(this); } InspectorUi::~InspectorUi() diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h index 4fce908d6c..697011f41e 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.h +++ b/src/plugins/qmljsinspector/qmljsinspector.h @@ -66,7 +66,7 @@ class ModelManagerInterface; namespace QmlJSInspector { namespace Internal { -class QmlInspectorToolBar; +class QmlJsInspectorToolBar; class QmlJSPropertyInspector; class ClientProxy; class InspectorSettings; @@ -153,7 +153,7 @@ private: private: bool m_listeningToEditorManager; - QmlInspectorToolBar *m_toolBar; + QmlJsInspectorToolBar *m_toolBar; ContextCrumblePath *m_crumblePath; QLineEdit *m_filterExp; QmlJSPropertyInspector *m_propertyInspector; diff --git a/src/plugins/qmljsinspector/qmljsinspector.pro b/src/plugins/qmljsinspector/qmljsinspector.pro index 50be9aba5d..a8213c62e5 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.pro +++ b/src/plugins/qmljsinspector/qmljsinspector.pro @@ -13,7 +13,7 @@ qmljsinspectorconstants.h \ qmljsinspectorplugin.h \ qmljsclientproxy.h \ qmljsinspector.h \ -qmlinspectortoolbar.h \ +qmljsinspectortoolbar.h \ qmljslivetextpreview.h \ qmljstoolbarcolorbox.h \ qmljsinspectorclient.h \ @@ -25,7 +25,7 @@ SOURCES += \ qmljsinspectorplugin.cpp \ qmljsclientproxy.cpp \ qmljsinspector.cpp \ -qmlinspectortoolbar.cpp \ +qmljsinspectortoolbar.cpp \ qmljslivetextpreview.cpp \ qmljstoolbarcolorbox.cpp \ qmljsinspectorclient.cpp \ diff --git a/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp b/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp index 6fea191029..5ce24ff6c7 100644 --- a/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp +++ b/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp @@ -30,26 +30,23 @@ ** **************************************************************************/ -#include "qmljsinspectorconstants.h" #include "qmljsinspectorplugin.h" -#include "qmljsinspector.h" -#include "qmljsclientproxy.h" -#include "qmlinspectortoolbar.h" - -#include -#include -#include -#include - -#include +#include "qmljsclientproxy.h" +#include "qmljsinspector.h" +#include "qmljsinspectorconstants.h" +#include "qmljsinspectortoolbar.h" -#include +#include #include +#include #include -#include #include - +#include +#include +#include +#include +#include #include #include diff --git a/src/plugins/qmljsinspector/qmljsinspectortoolbar.cpp b/src/plugins/qmljsinspector/qmljsinspectortoolbar.cpp new file mode 100644 index 0000000000..d93dbab701 --- /dev/null +++ b/src/plugins/qmljsinspector/qmljsinspectortoolbar.cpp @@ -0,0 +1,394 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#include "qmljsinspectortoolbar.h" + +#include "qmljsinspectorconstants.h" +#include "qmljstoolbarcolorbox.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace QmlJSInspector { +namespace Internal { + +static QToolButton *toolButton(QAction *action) +{ + QToolButton *button = new QToolButton; + button->setDefaultAction(action); + return button; +} + +QmlJsInspectorToolBar::QmlJsInspectorToolBar(QObject *parent) : + QObject(parent), + m_fromQmlAction(0), + m_playAction(0), + m_selectAction(0), + m_zoomAction(0), + m_colorPickerAction(0), + m_showAppOnTopAction(0), + m_playSpeedMenuActions(0), + m_playIcon(QIcon(QLatin1String(":/qml/images/play-small.png"))), + m_pauseIcon(QIcon(QLatin1String(":/qml/images/pause-small.png"))), + m_colorBox(0), + m_emitSignals(true), + m_paused(false), + m_animationSpeed(1.0f), + m_designModeActive(false), + m_activeTool(NoTool), + m_barWidget(0) +{ +} + +void QmlJsInspectorToolBar::setEnabled(bool value) +{ + m_fromQmlAction->setEnabled(value); + m_showAppOnTopAction->setEnabled(value); + m_playAction->setEnabled(value); + m_selectAction->setEnabled(value); + m_zoomAction->setEnabled(value); + m_colorPickerAction->setEnabled(value); + m_colorBox->setEnabled(value); +} + +void QmlJsInspectorToolBar::enable() +{ + setEnabled(true); + m_emitSignals = false; + m_showAppOnTopAction->setChecked(false); + setAnimationSpeed(1.0f); + m_designModeActive = false; + updateDesignModeActions(NoTool); + m_emitSignals = true; +} + +void QmlJsInspectorToolBar::disable() +{ + setAnimationSpeed(1.0f); + m_designModeActive = false; + updateDesignModeActions(NoTool); + setEnabled(false); +} + +void QmlJsInspectorToolBar::activateColorPicker() +{ + updateDesignModeActions(ColorPickerMode); +} + +void QmlJsInspectorToolBar::activateSelectTool() +{ + updateDesignModeActions(SelectionToolMode); +} + +void QmlJsInspectorToolBar::activateZoomTool() +{ + updateDesignModeActions(ZoomMode); +} + +void QmlJsInspectorToolBar::setAnimationSpeed(qreal slowDownFactor) +{ + if (m_animationSpeed == slowDownFactor) + return; + + m_emitSignals = false; + m_animationSpeed = slowDownFactor; + + foreach (QAction *action, m_playSpeedMenuActions->actions()) { + if (action->data().toReal() == slowDownFactor) { + action->setChecked(true); + break; + } + } + + m_emitSignals = true; +} + +void QmlJsInspectorToolBar::setAnimationPaused(bool paused) +{ + if (m_paused == paused) + return; + + m_paused = paused; + updatePlayAction(); +} + +void QmlJsInspectorToolBar::setDesignModeBehavior(bool inDesignMode) +{ + m_emitSignals = false; + m_designModeActive = inDesignMode; + updateDesignModeActions(m_activeTool); + m_emitSignals = true; +} + +void QmlJsInspectorToolBar::setShowAppOnTop(bool showAppOnTop) +{ + m_emitSignals = false; + m_showAppOnTopAction->setChecked(showAppOnTop); + m_emitSignals = true; +} + +void QmlJsInspectorToolBar::createActions() +{ + Core::Context context(Debugger::Constants::C_QMLDEBUGGER); + Core::ICore *core = Core::ICore::instance(); + Core::ActionManager *am = core->actionManager(); + + m_fromQmlAction = + new QAction(QIcon(QLatin1String(":/qml/images/from-qml-small.png")), + tr("Apply Changes on Save"), this); + m_showAppOnTopAction = + new QAction(QIcon(QLatin1String(":/qml/images/app-on-top.png")), + tr("Show application on top"), this); + m_playAction = + new QAction(m_pauseIcon, tr("Play/Pause Animations"), this); + m_selectAction = + new QAction(QIcon(QLatin1String(":/qml/images/select-small.png")), + tr("Select"), this); + m_zoomAction = + new QAction(QIcon(QLatin1String(":/qml/images/zoom-small.png")), + tr("Zoom"), this); + m_colorPickerAction = + new QAction(QIcon(QLatin1String(":/qml/images/color-picker-small.png")), + tr("Color Picker"), this); + + m_fromQmlAction->setCheckable(true); + m_fromQmlAction->setChecked(true); + m_showAppOnTopAction->setCheckable(true); + m_showAppOnTopAction->setChecked(false); + m_selectAction->setCheckable(true); + m_zoomAction->setCheckable(true); + m_colorPickerAction->setCheckable(true); + + Core::Command *command = am->registerAction(m_playAction, Constants::PLAY_ACTION, context); + command->setAttribute(Core::Command::CA_UpdateIcon); + am->registerAction(m_selectAction, Constants::SELECT_ACTION, context); + am->registerAction(m_zoomAction, Constants::ZOOM_ACTION, context); + am->registerAction(m_colorPickerAction, Constants::COLOR_PICKER_ACTION, context); + am->registerAction(m_fromQmlAction, Constants::FROM_QML_ACTION, context); + am->registerAction(m_showAppOnTopAction, Constants::SHOW_APP_ON_TOP_ACTION, context); + + m_barWidget = new Utils::StyledBar; + m_barWidget->setSingleRow(true); + m_barWidget->setProperty("topBorder", true); + + QMenu *playSpeedMenu = new QMenu(m_barWidget); + m_playSpeedMenuActions = new QActionGroup(this); + m_playSpeedMenuActions->setExclusive(true); + QAction *speedAction = playSpeedMenu->addAction(tr("1x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setChecked(true); + speedAction->setData(1.0f); + m_playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.5x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(2.0f); + m_playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.25x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(4.0f); + m_playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.125x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(8.0f); + m_playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.1x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(10.0f); + m_playSpeedMenuActions->addAction(speedAction); + + QHBoxLayout *toolBarLayout = new QHBoxLayout(m_barWidget); + toolBarLayout->setMargin(0); + toolBarLayout->setSpacing(5); + + m_operateByInstructionButton = toolButton(am->command(Debugger::Constants::OPERATE_BY_INSTRUCTION)->action()); + + // Add generic debugging controls + toolBarLayout->addWidget(toolButton(Debugger::DebuggerPlugin::visibleDebugAction())); + toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::STOP)->action())); + toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::NEXT)->action())); + toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::STEP)->action())); + toolBarLayout->addWidget(toolButton(am->command(Debugger::Constants::STEPOUT)->action())); + toolBarLayout->addWidget(m_operateByInstructionButton); + toolBarLayout->addStretch(1); + + // QML Helpers + toolBarLayout->addWidget(new Utils::StyledSeparator); + toolBarLayout->addWidget(toolButton(am->command(Constants::FROM_QML_ACTION)->action())); + toolBarLayout->addWidget(toolButton(am->command(Constants::SHOW_APP_ON_TOP_ACTION)->action())); + m_playButton = toolButton(am->command(Constants::PLAY_ACTION)->action()); + m_playButton->setMenu(playSpeedMenu); + toolBarLayout->addWidget(m_playButton); + + // Inspector + toolBarLayout->addWidget(new Utils::StyledSeparator); + toolBarLayout->addWidget(toolButton(am->command(Constants::SELECT_ACTION)->action())); + toolBarLayout->addWidget(toolButton(am->command(Constants::ZOOM_ACTION)->action())); + toolBarLayout->addWidget(toolButton(am->command(Constants::COLOR_PICKER_ACTION)->action())); + + m_colorBox = new ToolBarColorBox(m_barWidget); + m_colorBox->setMinimumSize(20, 20); + m_colorBox->setMaximumSize(20, 20); + m_colorBox->setInnerBorderColor(QColor(192, 192, 192)); + m_colorBox->setOuterBorderColor(QColor(58, 58, 58)); + toolBarLayout->addWidget(m_colorBox); + + connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml())); + connect(m_showAppOnTopAction, SIGNAL(triggered()), SLOT(showAppOnTopClick())); + connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick())); + connect(m_colorPickerAction, SIGNAL(triggered(bool)), SLOT(colorPickerTriggered(bool))); + connect(m_selectAction, SIGNAL(triggered(bool)), SLOT(selectToolTriggered(bool))); + connect(m_zoomAction, SIGNAL(triggered(bool)), SLOT(zoomToolTriggered(bool))); + + Debugger::DebuggerMainWindow *mw = Debugger::DebuggerPlugin::mainWindow(); + activeDebugLanguagesChanged(mw->activeDebugLanguages()); + connect(mw, SIGNAL(activeDebugLanguagesChanged(Debugger::DebuggerLanguages)), + this, SLOT(activeDebugLanguagesChanged(Debugger::DebuggerLanguages))); +} + +QWidget *QmlJsInspectorToolBar::widget() const +{ + return m_barWidget; +} + +void QmlJsInspectorToolBar::changeAnimationSpeed() +{ + QAction *action = static_cast(sender()); + + m_animationSpeed = action->data().toReal(); + emit animationSpeedChanged(m_animationSpeed); + + updatePlayAction(); +} + +void QmlJsInspectorToolBar::activatePlayOnClick() +{ + m_paused = !m_paused; + emit animationPausedChanged(m_paused); + updatePlayAction(); +} + +void QmlJsInspectorToolBar::updatePlayAction() +{ + m_playAction->setIcon(m_paused ? m_playIcon : m_pauseIcon); +} + +void QmlJsInspectorToolBar::colorPickerTriggered(bool checked) +{ + updateDesignModeActions(ColorPickerMode); + + if (m_designModeActive != checked) { + m_designModeActive = checked; + emit designModeSelected(checked); + } + + if (checked) + emit colorPickerSelected(); +} + +void QmlJsInspectorToolBar::selectToolTriggered(bool checked) +{ + updateDesignModeActions(SelectionToolMode); + + if (m_designModeActive != checked) { + m_designModeActive = checked; + emit designModeSelected(checked); + } + + if (checked) + emit selectToolSelected(); +} + +void QmlJsInspectorToolBar::zoomToolTriggered(bool checked) +{ + updateDesignModeActions(ZoomMode); + + if (m_designModeActive != checked) { + m_designModeActive = checked; + emit designModeSelected(checked); + } + + if (checked) + emit zoomToolSelected(); +} + +void QmlJsInspectorToolBar::showAppOnTopClick() +{ + if (m_emitSignals) + emit showAppOnTopSelected(m_showAppOnTopAction->isChecked()); +} + +void QmlJsInspectorToolBar::setSelectedColor(const QColor &color) +{ + m_colorBox->setColor(color); +} + +void QmlJsInspectorToolBar::activateFromQml() +{ + if (m_emitSignals) + emit applyChangesFromQmlFileTriggered(m_fromQmlAction->isChecked()); +} + +void QmlJsInspectorToolBar::activeDebugLanguagesChanged(Debugger::DebuggerLanguages languages) +{ + m_operateByInstructionButton->setVisible(languages & Debugger::CppLanguage); +} + +void QmlJsInspectorToolBar::updateDesignModeActions(DesignTool activeTool) +{ + m_activeTool = activeTool; + m_selectAction->setChecked(m_designModeActive && (m_activeTool == SelectionToolMode)); + m_zoomAction->setChecked(m_designModeActive && (m_activeTool == ZoomMode)); + m_colorPickerAction->setChecked(m_designModeActive && (m_activeTool == ColorPickerMode)); +} + +} // namespace Internal +} // namespace QmlJSInspector diff --git a/src/plugins/qmljsinspector/qmljsinspectortoolbar.h b/src/plugins/qmljsinspector/qmljsinspectortoolbar.h new file mode 100644 index 0000000000..30795b7540 --- /dev/null +++ b/src/plugins/qmljsinspector/qmljsinspectortoolbar.h @@ -0,0 +1,157 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#ifndef QMLJSINSPECTORTOOLBAR_H +#define QMLJSINSPECTORTOOLBAR_H + +#include + +#include +#include + +QT_BEGIN_NAMESPACE +class QAction; +class QActionGroup; +class QColor; +class QToolButton; +QT_END_NAMESPACE + +namespace Utils { +class StyledBar; +} + +namespace QmlJSInspector { + +class ToolBarColorBox; + +namespace Internal { + +class QmlJsInspectorToolBar : public QObject +{ + Q_OBJECT + +public: + enum DesignTool { + NoTool = 0, + SelectionToolMode = 1, + MarqueeSelectionToolMode = 2, + MoveToolMode = 3, + ResizeToolMode = 4, + ColorPickerMode = 5, + ZoomMode = 6 + }; + + explicit QmlJsInspectorToolBar(QObject *parent = 0); + void createActions(); + QWidget *widget() const; + +public slots: + void setEnabled(bool value); + void enable(); + void disable(); + + void activateColorPicker(); + void activateSelectTool(); + void activateZoomTool(); + + void setAnimationSpeed(qreal slowDownFactor); + void setAnimationPaused(bool paused); + + void setDesignModeBehavior(bool inDesignMode); + void setShowAppOnTop(bool showAppOnTop); + void setSelectedColor(const QColor &color); + +signals: + void applyChangesFromQmlFileTriggered(bool isChecked); + + void designModeSelected(bool); + void reloadSelected(); + void colorPickerSelected(); + void selectToolSelected(); + void zoomToolSelected(); + + void showAppOnTopSelected(bool isChecked); + + void animationSpeedChanged(qreal slowdownFactor); + void animationPausedChanged(bool paused); + +private slots: + void activatePlayOnClick(); + void colorPickerTriggered(bool checked); + void selectToolTriggered(bool checked); + void zoomToolTriggered(bool checked); + + void showAppOnTopClick(); + + void changeAnimationSpeed(); + + void activateFromQml(); + + void updatePlayAction(); + + void activeDebugLanguagesChanged(Debugger::DebuggerLanguages languages); + +private: + void updateDesignModeActions(DesignTool activeTool); + + QToolButton *m_operateByInstructionButton; + + QAction *m_fromQmlAction; + QAction *m_playAction; + QAction *m_selectAction; + QAction *m_zoomAction; + QAction *m_colorPickerAction; + + QAction *m_showAppOnTopAction; + + QActionGroup *m_playSpeedMenuActions; + + QToolButton *m_playButton; + QIcon m_playIcon; + QIcon m_pauseIcon; + + ToolBarColorBox *m_colorBox; + + bool m_emitSignals; + bool m_paused; + qreal m_animationSpeed; + + bool m_designModeActive; + DesignTool m_activeTool; + + Utils::StyledBar *m_barWidget; +}; + +} // namespace Internal +} // namespace QmlJSInspector + +#endif // QMLJSINSPECTORTOOLBAR_H -- cgit v1.2.1