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

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.
**
** 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:
** 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
**
** "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.
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** 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$
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
****************************************************************************/
**************************************************************************/
#include "commandbutton.h"
......@@ -44,8 +36,16 @@
#include <coreplugin/actionmanager/command.h>
#include <utils/proxyaction.h>
using namespace ImageViewer;
using namespace Internal;
using namespace Core;
/*!
\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)
: QToolButton(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)
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();
connect(m_command, SIGNAL(keySequenceChanged()), this, SLOT(updateToolTip()));
}
......
/****************************************************************************
**
** This file is part of Qt Creator
**
** 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:
** GNU Lesser General Public License Usage
**
** "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 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.
**
** 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$
** 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 qt-info@nokia.com.
**
**************************************************************************/
#ifndef COMMANDBUTTON_H
#define COMMANDBUTTON_H
#include <coreplugin/core_global.h>
#include <QPointer>
#include <QString>
#include <QToolButton>
namespace Core {
class Command;
class Id;
}
namespace ImageViewer {
namespace Internal {
class CommandButton : public QToolButton
class CORE_EXPORT CommandButton : public QToolButton
{
Q_OBJECT
Q_PROPERTY(QString toolTipBase READ toolTipBase WRITE setToolTipBase)
public:
explicit CommandButton(QWidget *parent = 0);
void setCommandId(Core::Id id);
explicit CommandButton(Id id, QWidget *parent = 0);
void setCommandId(Id id);
QString toolTipBase() const;
void setToolTipBase(const QString &toolTipBase);
......@@ -72,7 +63,6 @@ private:
QString m_toolTipBase;
};
}
}
#endif // COMMANDBUTTON_H
......@@ -41,6 +41,7 @@ SOURCES += mainwindow.cpp \
editormanager/iexternaleditor.cpp \
actionmanager/actionmanager.cpp \
actionmanager/command.cpp \
actionmanager/commandbutton.cpp \
actionmanager/actioncontainer.cpp \
actionmanager/commandsfile.cpp \
dialogs/saveitemsdialog.cpp \
......@@ -122,6 +123,7 @@ HEADERS += mainwindow.h \
actionmanager/actioncontainer.h \
actionmanager/actionmanager.h \
actionmanager/command.h \
actionmanager/commandbutton.h \
actionmanager/actionmanager_p.h \
actionmanager/command_p.h \
actionmanager/actioncontainer_p.h \
......
......@@ -4,7 +4,6 @@ include(../../qtcreatorplugin.pri)
include(imageviewer_dependencies.pri)
HEADERS += \
commandbutton.h \
imageviewerplugin.h \
imageviewerfactory.h \
imageviewerfile.h \
......@@ -14,7 +13,6 @@ HEADERS += \
imagevieweractionhandler.h
SOURCES += \
commandbutton.cpp \
imageviewerplugin.cpp \
imageviewerfactory.cpp \
imageviewerfile.cpp \
......
......@@ -18,7 +18,7 @@
<number>0</number>
</property>
<item>
<widget class="CommandButton" name="toolButtonBackground">
<widget class="Core::CommandButton" name="toolButtonBackground">
<property name="toolTipBase">
<string>Show Background</string>
</property>
......@@ -35,7 +35,7 @@
</widget>
</item>
<item>
<widget class="CommandButton" name="toolButtonOutline">
<widget class="Core::CommandButton" name="toolButtonOutline">
<property name="toolTipBase">
<string>Show Outline</string>
</property>
......@@ -52,7 +52,7 @@
</widget>
</item>
<item>
<widget class="CommandButton" name="toolButtonFitToScreen">
<widget class="Core::CommandButton" name="toolButtonFitToScreen">
<property name="toolTipBase">
<string>Fit to Screen</string>
</property>
......@@ -66,7 +66,7 @@
</widget>
</item>
<item>
<widget class="CommandButton" name="toolButtonOriginalSize">
<widget class="Core::CommandButton" name="toolButtonOriginalSize">
<property name="toolTipBase">
<string>Original Size</string>
</property>
......@@ -77,7 +77,7 @@
</widget>
</item>
<item>
<widget class="CommandButton" name="toolButtonZoomIn">
<widget class="Core::CommandButton" name="toolButtonZoomIn">
<property name="toolTipBase">
<string>Zoom In</string>
</property>
......@@ -91,7 +91,7 @@
</widget>
</item>
<item>
<widget class="CommandButton" name="toolButtonZoomOut">
<widget class="Core::CommandButton" name="toolButtonZoomOut">
<property name="toolTipBase">
<string>Zoom Out</string>
</property>
......@@ -105,7 +105,7 @@
</widget>
</item>
<item>
<widget class="CommandButton" name="toolButtonPlayPause">
<widget class="Core::CommandButton" name="toolButtonPlayPause">
</widget>
</item>
<item>
......@@ -146,9 +146,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>CommandButton</class>
<class>Core::CommandButton</class>
<extends>QToolButton</extends>
<header>commandbutton.h</header>
<header>coreplugin/actionmanager/commandbutton.h</header>
</customwidget>
</customwidgets>
<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