diff --git a/src/plugins/imageviewer/commandbutton.cpp b/src/plugins/imageviewer/commandbutton.cpp new file mode 100644 index 00000000000..3e0413c2973 --- /dev/null +++ b/src/plugins/imageviewer/commandbutton.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (c) 2012 Konstantin Tokarev. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of Qt Creator. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "commandbutton.h" + +#include +#include +#include + +using namespace ImageViewer; +using namespace Internal; + +CommandButton::CommandButton(QWidget *parent) + : QToolButton(parent) + , m_command(0) +{ +} + +void CommandButton::setCommandId(Core::Id id) +{ + if (m_command) + disconnect(m_command, SIGNAL(keySequenceChanged()), this, SLOT(updateToolTip())); + + m_command = Core::ActionManager::command(id); + updateToolTip(); + connect(m_command, SIGNAL(keySequenceChanged()), this, SLOT(updateToolTip())); +} + +QString CommandButton::toolTipBase() const +{ + return m_toolTipBase; +} + +void CommandButton::setToolTipBase(const QString &toolTipBase) +{ + m_toolTipBase = toolTipBase; + updateToolTip(); +} + +void CommandButton::updateToolTip() +{ + if (m_command) + setToolTip(Utils::ProxyAction::stringWithAppendedShortcut(m_toolTipBase, + m_command->keySequence())); +} diff --git a/src/plugins/imageviewer/commandbutton.h b/src/plugins/imageviewer/commandbutton.h new file mode 100644 index 00000000000..d9e4b37408f --- /dev/null +++ b/src/plugins/imageviewer/commandbutton.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (c) 2012 Konstantin Tokarev. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of Qt Creator. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef COMMANDBUTTON_H +#define COMMANDBUTTON_H + +#include +#include +#include + +namespace Core { +class Command; +class Id; +} + +namespace ImageViewer { +namespace Internal { + +class CommandButton : public QToolButton +{ + Q_OBJECT + Q_PROPERTY(QString toolTipBase READ toolTipBase WRITE setToolTipBase) +public: + explicit CommandButton(QWidget *parent = 0); + void setCommandId(Core::Id id); + QString toolTipBase() const; + void setToolTipBase(const QString &toolTipBase); + +private slots: + void updateToolTip(); + +private: + QPointer m_command; + QString m_toolTipBase; +}; + +} +} + +#endif // COMMANDBUTTON_H diff --git a/src/plugins/imageviewer/imageviewer.cpp b/src/plugins/imageviewer/imageviewer.cpp index 48d61dafc65..92ae3e32d9a 100644 --- a/src/plugins/imageviewer/imageviewer.cpp +++ b/src/plugins/imageviewer/imageviewer.cpp @@ -86,6 +86,14 @@ ImageViewer::ImageViewer(QWidget *parent) // (photograph has outline - piece of paper) updateButtonIconByTheme(d->ui_toolbar.toolButtonOutline, "emblem-photos"); + d->ui_toolbar.toolButtonZoomIn->setCommandId(Constants::ACTION_ZOOM_IN); + d->ui_toolbar.toolButtonZoomOut->setCommandId(Constants::ACTION_ZOOM_OUT); + d->ui_toolbar.toolButtonOriginalSize->setCommandId(Constants::ACTION_ORIGINAL_SIZE); + d->ui_toolbar.toolButtonFitToScreen->setCommandId(Constants::ACTION_FIT_TO_SCREEN); + d->ui_toolbar.toolButtonBackground->setCommandId(Constants::ACTION_BACKGROUND); + d->ui_toolbar.toolButtonOutline->setCommandId(Constants::ACTION_OUTLINE); + d->ui_toolbar.toolButtonPlayPause->setCommandId(Constants::ACTION_TOGGLE_ANIMATION); + // connections connect(d->file, SIGNAL(changed()), this, SIGNAL(changed())); @@ -272,10 +280,10 @@ void ImageViewer::setPaused(bool paused) { d->imageView->setPaused(paused); if (paused) { - d->ui_toolbar.toolButtonPlayPause->setToolTip(tr("Play Animation")); + d->ui_toolbar.toolButtonPlayPause->setToolTipBase(tr("Play Animation")); d->ui_toolbar.toolButtonPlayPause->setIcon(QPixmap(QLatin1String(":/imageviewer/images/play-small.png"))); } else { - d->ui_toolbar.toolButtonPlayPause->setToolTip(tr("Pause Animation")); + d->ui_toolbar.toolButtonPlayPause->setToolTipBase(tr("Pause Animation")); d->ui_toolbar.toolButtonPlayPause->setIcon(QPixmap(QLatin1String(":/imageviewer/images/pause-small.png"))); } } diff --git a/src/plugins/imageviewer/imageviewer.pro b/src/plugins/imageviewer/imageviewer.pro index 1b9005d7863..c82884dbe39 100644 --- a/src/plugins/imageviewer/imageviewer.pro +++ b/src/plugins/imageviewer/imageviewer.pro @@ -4,6 +4,7 @@ include(../../qtcreatorplugin.pri) include(imageviewer_dependencies.pri) HEADERS += \ + commandbutton.h \ imageviewerplugin.h \ imageviewerfactory.h \ imageviewerfile.h \ @@ -13,6 +14,7 @@ HEADERS += \ imagevieweractionhandler.h SOURCES += \ + commandbutton.cpp \ imageviewerplugin.cpp \ imageviewerfactory.cpp \ imageviewerfile.cpp \ diff --git a/src/plugins/imageviewer/imageviewer.qbs b/src/plugins/imageviewer/imageviewer.qbs index a40c0686f6f..47bedb47210 100644 --- a/src/plugins/imageviewer/imageviewer.qbs +++ b/src/plugins/imageviewer/imageviewer.qbs @@ -16,6 +16,7 @@ QtcPlugin { ] files: [ + "commandbutton.h", "imageviewerplugin.h", "imageviewerfactory.h", "imageviewerfile.h", @@ -23,6 +24,7 @@ QtcPlugin { "imageview.h", "imageviewerconstants.h", "imagevieweractionhandler.h", + "commandbutton.cpp", "imageviewerplugin.cpp", "imageviewerfactory.cpp", "imageviewerfile.cpp", diff --git a/src/plugins/imageviewer/imageviewertoolbar.ui b/src/plugins/imageviewer/imageviewertoolbar.ui index 6b78452fae6..c07f0dcbd65 100644 --- a/src/plugins/imageviewer/imageviewertoolbar.ui +++ b/src/plugins/imageviewer/imageviewertoolbar.ui @@ -18,8 +18,8 @@ 0 - - + + Show Background @@ -35,8 +35,8 @@ - - + + Show Outline @@ -52,8 +52,8 @@ - - + + Fit to Screen @@ -66,8 +66,8 @@ - - + + Original Size @@ -77,8 +77,8 @@ - - + + Zoom In @@ -91,8 +91,8 @@ - - + + Zoom Out @@ -105,10 +105,7 @@ - - - Pause Animation - + @@ -148,6 +145,11 @@
utils/styledbar.h
1 + + CommandButton + QToolButton +
commandbutton.h
+