Commit 67c47887 authored by Konstantin Tokarev's avatar Konstantin Tokarev Committed by Eike Ziller
Browse files

Moved CommandButton to Core and made some improvements to it.



Added constructor taking Id, use command description if toolTipBase
is not set.

Change-Id: I56d774e9c194c6f1eb90583f4a13ed75db540ba3
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 889409f2
/**************************************************************************** /****************************************************************************
** **
** This file is part of Qt Creator
**
** Copyright (c) 2012 Konstantin Tokarev. ** Copyright (c) 2012 Konstantin Tokarev.
** **
** Contact: Nokia Corporation (qt-info@nokia.com) ** Contact: Nokia Corporation (qt-info@nokia.com)
** **
** This file is part of Qt Creator.
** **
** $QT_BEGIN_LICENSE:BSD$ ** GNU Lesser General Public License Usage
** You may use this file under the terms of the BSD license as follows: **
** 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
** **
** "Redistribution and use in source and binary forms, with or without ** Alternatively, this file may be used in accordance with the terms and
** modification, are permitted provided that the following conditions are ** conditions contained in a signed written agreement between you and Nokia.
** 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 ** If you have questions regarding the use of this file, please contact
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** Nokia at qt-info@nokia.com.
** 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 "commandbutton.h"
...@@ -44,8 +36,16 @@ ...@@ -44,8 +36,16 @@
#include <coreplugin/actionmanager/command.h> #include <coreplugin/actionmanager/command.h>
#include <utils/proxyaction.h> #include <utils/proxyaction.h>
using namespace ImageViewer; using namespace Core;
using namespace Internal;
/*!
\class Core::CommandButton
\brief A tool button associated with one of registered Command objects.
Tooltip of this button consists of toolTipBase property value and Command's
key sequence which is automatically updated when user changes it.
*/
CommandButton::CommandButton(QWidget *parent) CommandButton::CommandButton(QWidget *parent)
: QToolButton(parent) : QToolButton(parent)
...@@ -53,12 +53,23 @@ CommandButton::CommandButton(QWidget *parent) ...@@ -53,12 +53,23 @@ CommandButton::CommandButton(QWidget *parent)
{ {
} }
void CommandButton::setCommandId(Core::Id id) CommandButton::CommandButton(Id id, QWidget *parent)
: QToolButton(parent)
, m_command(0)
{
setCommandId(id);
}
void CommandButton::setCommandId(Id id)
{ {
if (m_command) if (m_command)
disconnect(m_command, SIGNAL(keySequenceChanged()), this, SLOT(updateToolTip())); disconnect(m_command, SIGNAL(keySequenceChanged()), this, SLOT(updateToolTip()));
m_command = Core::ActionManager::command(id); m_command = ActionManager::command(id);
if (m_toolTipBase.isEmpty())
m_toolTipBase = m_command->description();
updateToolTip(); updateToolTip();
connect(m_command, SIGNAL(keySequenceChanged()), this, SLOT(updateToolTip())); connect(m_command, SIGNAL(keySequenceChanged()), this, SLOT(updateToolTip()));
} }
......
/**************************************************************************** /****************************************************************************
** **
** This file is part of Qt Creator
**
** Copyright (c) 2012 Konstantin Tokarev. ** Copyright (c) 2012 Konstantin Tokarev.
** **
** Contact: Nokia Corporation (qt-info@nokia.com) ** Contact: Nokia Corporation (qt-info@nokia.com)
** **
** This file is part of Qt Creator.
** **
** $QT_BEGIN_LICENSE:BSD$ ** GNU Lesser General Public License Usage
** 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 ** This file may be used under the terms of the GNU Lesser General Public
** modification, are permitted provided that the following conditions are ** License version 2.1 as published by the Free Software Foundation and
** met: ** appearing in the file LICENSE.LGPL included in the packaging of this file.
** * Redistributions of source code must retain the above copyright ** Please review the following information to ensure the GNU Lesser General
** notice, this list of conditions and the following disclaimer. ** Public License version 2.1 requirements will be met:
** * Redistributions in binary form must reproduce the above copyright ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
** 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 ** In addition, as a special exception, Nokia gives you certain additional
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** rights. These rights are described in the Nokia Qt LGPL Exception
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
** 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$
** **
****************************************************************************/ ** 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 qt-info@nokia.com.
**
**************************************************************************/
#ifndef COMMANDBUTTON_H #ifndef COMMANDBUTTON_H
#define COMMANDBUTTON_H #define COMMANDBUTTON_H
#include <coreplugin/core_global.h>
#include <QPointer> #include <QPointer>
#include <QString> #include <QString>
#include <QToolButton> #include <QToolButton>
namespace Core { namespace Core {
class Command; class Command;
class Id; class Id;
}
namespace ImageViewer { class CORE_EXPORT CommandButton : public QToolButton
namespace Internal {
class CommandButton : public QToolButton
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString toolTipBase READ toolTipBase WRITE setToolTipBase) Q_PROPERTY(QString toolTipBase READ toolTipBase WRITE setToolTipBase)
public: public:
explicit CommandButton(QWidget *parent = 0); explicit CommandButton(QWidget *parent = 0);
void setCommandId(Core::Id id); explicit CommandButton(Id id, QWidget *parent = 0);
void setCommandId(Id id);
QString toolTipBase() const; QString toolTipBase() const;
void setToolTipBase(const QString &toolTipBase); void setToolTipBase(const QString &toolTipBase);
...@@ -72,7 +63,6 @@ private: ...@@ -72,7 +63,6 @@ private:
QString m_toolTipBase; QString m_toolTipBase;
}; };
}
} }
#endif // COMMANDBUTTON_H #endif // COMMANDBUTTON_H
...@@ -41,6 +41,7 @@ SOURCES += mainwindow.cpp \ ...@@ -41,6 +41,7 @@ SOURCES += mainwindow.cpp \
editormanager/iexternaleditor.cpp \ editormanager/iexternaleditor.cpp \
actionmanager/actionmanager.cpp \ actionmanager/actionmanager.cpp \
actionmanager/command.cpp \ actionmanager/command.cpp \
actionmanager/commandbutton.cpp \
actionmanager/actioncontainer.cpp \ actionmanager/actioncontainer.cpp \
actionmanager/commandsfile.cpp \ actionmanager/commandsfile.cpp \
dialogs/saveitemsdialog.cpp \ dialogs/saveitemsdialog.cpp \
...@@ -122,6 +123,7 @@ HEADERS += mainwindow.h \ ...@@ -122,6 +123,7 @@ HEADERS += mainwindow.h \
actionmanager/actioncontainer.h \ actionmanager/actioncontainer.h \
actionmanager/actionmanager.h \ actionmanager/actionmanager.h \
actionmanager/command.h \ actionmanager/command.h \
actionmanager/commandbutton.h \
actionmanager/actionmanager_p.h \ actionmanager/actionmanager_p.h \
actionmanager/command_p.h \ actionmanager/command_p.h \
actionmanager/actioncontainer_p.h \ actionmanager/actioncontainer_p.h \
......
...@@ -4,7 +4,6 @@ include(../../qtcreatorplugin.pri) ...@@ -4,7 +4,6 @@ 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 \
...@@ -14,7 +13,6 @@ HEADERS += \ ...@@ -14,7 +13,6 @@ HEADERS += \
imagevieweractionhandler.h imagevieweractionhandler.h
SOURCES += \ SOURCES += \
commandbutton.cpp \
imageviewerplugin.cpp \ imageviewerplugin.cpp \
imageviewerfactory.cpp \ imageviewerfactory.cpp \
imageviewerfile.cpp \ imageviewerfile.cpp \
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="CommandButton" name="toolButtonBackground"> <widget class="Core::CommandButton" name="toolButtonBackground">
<property name="toolTipBase"> <property name="toolTipBase">
<string>Show Background</string> <string>Show Background</string>
</property> </property>
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="CommandButton" name="toolButtonOutline"> <widget class="Core::CommandButton" name="toolButtonOutline">
<property name="toolTipBase"> <property name="toolTipBase">
<string>Show Outline</string> <string>Show Outline</string>
</property> </property>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="CommandButton" name="toolButtonFitToScreen"> <widget class="Core::CommandButton" name="toolButtonFitToScreen">
<property name="toolTipBase"> <property name="toolTipBase">
<string>Fit to Screen</string> <string>Fit to Screen</string>
</property> </property>
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="CommandButton" name="toolButtonOriginalSize"> <widget class="Core::CommandButton" name="toolButtonOriginalSize">
<property name="toolTipBase"> <property name="toolTipBase">
<string>Original Size</string> <string>Original Size</string>
</property> </property>
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="CommandButton" name="toolButtonZoomIn"> <widget class="Core::CommandButton" name="toolButtonZoomIn">
<property name="toolTipBase"> <property name="toolTipBase">
<string>Zoom In</string> <string>Zoom In</string>
</property> </property>
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="CommandButton" name="toolButtonZoomOut"> <widget class="Core::CommandButton" name="toolButtonZoomOut">
<property name="toolTipBase"> <property name="toolTipBase">
<string>Zoom Out</string> <string>Zoom Out</string>
</property> </property>
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="CommandButton" name="toolButtonPlayPause"> <widget class="Core::CommandButton" name="toolButtonPlayPause">
</widget> </widget>
</item> </item>
<item> <item>
...@@ -146,9 +146,9 @@ ...@@ -146,9 +146,9 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>CommandButton</class> <class>Core::CommandButton</class>
<extends>QToolButton</extends> <extends>QToolButton</extends>
<header>commandbutton.h</header> <header>coreplugin/actionmanager/commandbutton.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment