forked from qt-creator/qt-creator
Show shortcuts in tooltips of ImageViewer
Change-Id: I90fa2e3bddc99cff721c30499046a11a3dd93486 Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
committed by
Daniel Teske
parent
108f7d804f
commit
7d089b35a3
82
src/plugins/imageviewer/commandbutton.cpp
Normal file
82
src/plugins/imageviewer/commandbutton.cpp
Normal file
@@ -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 <coreplugin/actionmanager/actionmanager.h>
|
||||||
|
#include <coreplugin/actionmanager/command.h>
|
||||||
|
#include <utils/proxyaction.h>
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
78
src/plugins/imageviewer/commandbutton.h
Normal file
78
src/plugins/imageviewer/commandbutton.h
Normal file
@@ -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 <QPointer>
|
||||||
|
#include <QString>
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
|
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<Core::Command> m_command;
|
||||||
|
QString m_toolTipBase;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // COMMANDBUTTON_H
|
@@ -86,6 +86,14 @@ ImageViewer::ImageViewer(QWidget *parent)
|
|||||||
// (photograph has outline - piece of paper)
|
// (photograph has outline - piece of paper)
|
||||||
updateButtonIconByTheme(d->ui_toolbar.toolButtonOutline, "emblem-photos");
|
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
|
// connections
|
||||||
connect(d->file, SIGNAL(changed()), this, SIGNAL(changed()));
|
connect(d->file, SIGNAL(changed()), this, SIGNAL(changed()));
|
||||||
|
|
||||||
@@ -272,10 +280,10 @@ void ImageViewer::setPaused(bool paused)
|
|||||||
{
|
{
|
||||||
d->imageView->setPaused(paused);
|
d->imageView->setPaused(paused);
|
||||||
if (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")));
|
d->ui_toolbar.toolButtonPlayPause->setIcon(QPixmap(QLatin1String(":/imageviewer/images/play-small.png")));
|
||||||
} else {
|
} 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")));
|
d->ui_toolbar.toolButtonPlayPause->setIcon(QPixmap(QLatin1String(":/imageviewer/images/pause-small.png")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ include(../../qtcreatorplugin.pri)
|
|||||||
include(imageviewer_dependencies.pri)
|
include(imageviewer_dependencies.pri)
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
commandbutton.h \
|
||||||
imageviewerplugin.h \
|
imageviewerplugin.h \
|
||||||
imageviewerfactory.h \
|
imageviewerfactory.h \
|
||||||
imageviewerfile.h \
|
imageviewerfile.h \
|
||||||
@@ -13,6 +14,7 @@ HEADERS += \
|
|||||||
imagevieweractionhandler.h
|
imagevieweractionhandler.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
commandbutton.cpp \
|
||||||
imageviewerplugin.cpp \
|
imageviewerplugin.cpp \
|
||||||
imageviewerfactory.cpp \
|
imageviewerfactory.cpp \
|
||||||
imageviewerfile.cpp \
|
imageviewerfile.cpp \
|
||||||
|
@@ -16,6 +16,7 @@ QtcPlugin {
|
|||||||
]
|
]
|
||||||
|
|
||||||
files: [
|
files: [
|
||||||
|
"commandbutton.h",
|
||||||
"imageviewerplugin.h",
|
"imageviewerplugin.h",
|
||||||
"imageviewerfactory.h",
|
"imageviewerfactory.h",
|
||||||
"imageviewerfile.h",
|
"imageviewerfile.h",
|
||||||
@@ -23,6 +24,7 @@ QtcPlugin {
|
|||||||
"imageview.h",
|
"imageview.h",
|
||||||
"imageviewerconstants.h",
|
"imageviewerconstants.h",
|
||||||
"imagevieweractionhandler.h",
|
"imagevieweractionhandler.h",
|
||||||
|
"commandbutton.cpp",
|
||||||
"imageviewerplugin.cpp",
|
"imageviewerplugin.cpp",
|
||||||
"imageviewerfactory.cpp",
|
"imageviewerfactory.cpp",
|
||||||
"imageviewerfile.cpp",
|
"imageviewerfile.cpp",
|
||||||
|
@@ -18,8 +18,8 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButtonBackground">
|
<widget class="CommandButton" name="toolButtonBackground">
|
||||||
<property name="toolTip">
|
<property name="toolTipBase">
|
||||||
<string>Show Background</string>
|
<string>Show Background</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@@ -35,8 +35,8 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButtonOutline">
|
<widget class="CommandButton" name="toolButtonOutline">
|
||||||
<property name="toolTip">
|
<property name="toolTipBase">
|
||||||
<string>Show Outline</string>
|
<string>Show Outline</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@@ -52,8 +52,8 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButtonFitToScreen">
|
<widget class="CommandButton" name="toolButtonFitToScreen">
|
||||||
<property name="toolTip">
|
<property name="toolTipBase">
|
||||||
<string>Fit to Screen</string>
|
<string>Fit to Screen</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@@ -66,8 +66,8 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButtonOriginalSize">
|
<widget class="CommandButton" name="toolButtonOriginalSize">
|
||||||
<property name="toolTip">
|
<property name="toolTipBase">
|
||||||
<string>Original Size</string>
|
<string>Original Size</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@@ -77,8 +77,8 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButtonZoomIn">
|
<widget class="CommandButton" name="toolButtonZoomIn">
|
||||||
<property name="toolTip">
|
<property name="toolTipBase">
|
||||||
<string>Zoom In</string>
|
<string>Zoom In</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@@ -91,8 +91,8 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButtonZoomOut">
|
<widget class="CommandButton" name="toolButtonZoomOut">
|
||||||
<property name="toolTip">
|
<property name="toolTipBase">
|
||||||
<string>Zoom Out</string>
|
<string>Zoom Out</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@@ -105,10 +105,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButtonPlayPause">
|
<widget class="CommandButton" name="toolButtonPlayPause">
|
||||||
<property name="toolTip">
|
|
||||||
<string>Pause Animation</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@@ -148,6 +145,11 @@
|
|||||||
<header>utils/styledbar.h</header>
|
<header>utils/styledbar.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>CommandButton</class>
|
||||||
|
<extends>QToolButton</extends>
|
||||||
|
<header>commandbutton.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="imageviewer.qrc"/>
|
<include location="imageviewer.qrc"/>
|
||||||
|
Reference in New Issue
Block a user