summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/imageviewer/imageviewer.cpp33
-rw-r--r--src/plugins/imageviewer/imageviewer.h10
-rw-r--r--src/plugins/imageviewer/imageviewer.pro6
-rw-r--r--src/plugins/imageviewer/imagevieweractionhandler.cpp145
-rw-r--r--src/plugins/imageviewer/imagevieweractionhandler.h78
-rw-r--r--src/plugins/imageviewer/imageviewerconstants.h8
-rw-r--r--src/plugins/imageviewer/imageviewerfactory.cpp25
-rw-r--r--src/plugins/imageviewer/imageviewerfactory.h7
-rw-r--r--src/plugins/imageviewer/imageviewerplugin.cpp14
-rw-r--r--src/plugins/imageviewer/imageviewerplugin.h2
10 files changed, 317 insertions, 11 deletions
diff --git a/src/plugins/imageviewer/imageviewer.cpp b/src/plugins/imageviewer/imageviewer.cpp
index ad6754c12c..74ee25a110 100644
--- a/src/plugins/imageviewer/imageviewer.cpp
+++ b/src/plugins/imageviewer/imageviewer.cpp
@@ -30,12 +30,15 @@
#include "imageviewer.h"
#include "imageviewerfile.h"
+#include "imagevieweractionhandler.h"
#include "imageviewerconstants.h"
#include "imageview.h"
#include "ui_imageviewertoolbar.h"
#include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h>
+#include <coreplugin/actionmanager/actionmanager.h>
+#include <coreplugin/actionmanager/command.h>
#include <utils/qtcassert.h>
#include <QtCore/QMap>
@@ -215,5 +218,35 @@ bool ImageViewer::updateButtonIconByTheme(QAbstractButton *button, const QString
return false;
}
+void ImageViewer::switchViewBackground()
+{
+ d_ptr->ui_toolbar.toolButtonBackground->click();
+}
+
+void ImageViewer::switchViewOutline()
+{
+ d_ptr->ui_toolbar.toolButtonOutline->click();
+}
+
+void ImageViewer::zoomIn()
+{
+ d_ptr->ui_toolbar.toolButtonZoomIn->click();
+}
+
+void ImageViewer::zoomOut()
+{
+ d_ptr->ui_toolbar.toolButtonZoomOut->click();
+}
+
+void ImageViewer::resetToOriginalSize()
+{
+ d_ptr->ui_toolbar.toolButtonOriginalSize->click();
+}
+
+void ImageViewer::fitToScreen()
+{
+ d_ptr->ui_toolbar.toolButtonFitToScreen->click();
+}
+
} // namespace Internal
} // namespace ImageViewer
diff --git a/src/plugins/imageviewer/imageviewer.h b/src/plugins/imageviewer/imageviewer.h
index b4426a0b3f..cb68a67e5b 100644
--- a/src/plugins/imageviewer/imageviewer.h
+++ b/src/plugins/imageviewer/imageviewer.h
@@ -38,6 +38,7 @@
#include <QtCore/QStringList>
QT_FORWARD_DECLARE_CLASS(QAbstractButton)
+QT_FORWARD_DECLARE_CLASS(QAction)
namespace ImageViewer {
namespace Internal {
@@ -77,9 +78,16 @@ public:
public slots:
void scaleFactorUpdate(qreal factor);
+ void switchViewBackground();
+ void switchViewOutline();
+ void zoomIn();
+ void zoomOut();
+ void resetToOriginalSize();
+ void fitToScreen();
+
private:
/*!
- \brief Try to change button's icon to the one from the current theme
+ \brief Try to change button's icon to the one from the current theme.
\param button Button where an icon should be changed
\param name Icon name in the in the current icon theme
\return true if icon is updated, false otherwise
diff --git a/src/plugins/imageviewer/imageviewer.pro b/src/plugins/imageviewer/imageviewer.pro
index b4465c9d08..879212095c 100644
--- a/src/plugins/imageviewer/imageviewer.pro
+++ b/src/plugins/imageviewer/imageviewer.pro
@@ -9,14 +9,16 @@ HEADERS += \
imageviewerfile.h \
imageviewer.h \
imageview.h \
- imageviewerconstants.h
+ imageviewerconstants.h \
+ imagevieweractionhandler.h
SOURCES += \
imageviewerplugin.cpp \
imageviewerfactory.cpp \
imageviewerfile.cpp \
imageviewer.cpp \
- imageview.cpp
+ imageview.cpp \
+ imagevieweractionhandler.cpp
RESOURCES += \
imageviewer.qrc
diff --git a/src/plugins/imageviewer/imagevieweractionhandler.cpp b/src/plugins/imageviewer/imagevieweractionhandler.cpp
new file mode 100644
index 0000000000..2aa15e4910
--- /dev/null
+++ b/src/plugins/imageviewer/imagevieweractionhandler.cpp
@@ -0,0 +1,145 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (c) 2010 Denis Mingulov.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "imagevieweractionhandler.h"
+#include "imageviewer.h"
+#include "imageviewerconstants.h"
+
+#include <QtCore/QList>
+#include <QtCore/QPointer>
+#include <QtCore/QSignalMapper>
+#include <QtGui/QAction>
+
+#include <coreplugin/icore.h>
+#include <coreplugin/uniqueidmanager.h>
+#include <coreplugin/actionmanager/actionmanager.h>
+#include <coreplugin/actionmanager/command.h>
+#include <coreplugin/editormanager/editormanager.h>
+
+namespace ImageViewer {
+namespace Internal {
+
+enum SupportedActions { ZoomIn = 0, ZoomOut, OriginalSize, FitToScreen, Background, Outline };
+
+struct ImageViewerActionHandlerPrivate
+{
+ QPointer<QAction> actionZoomIn;
+ QPointer<QAction> actionZoomOut;
+ QPointer<QAction> actionOriginalSize;
+ QPointer<QAction> actionFitToScreen;
+ QPointer<QAction> actionBackground;
+ QPointer<QAction> actionOutline;
+
+ QList<int> context;
+ QPointer<QSignalMapper> signalMapper;
+};
+
+ImageViewerActionHandler::ImageViewerActionHandler(QObject *parent) :
+ QObject(parent),
+ d_ptr(new ImageViewerActionHandlerPrivate)
+{
+ d_ptr->context << Core::ICore::instance()->uniqueIDManager()
+ ->uniqueIdentifier(Constants::IMAGEVIEWER_ID);
+
+ d_ptr->signalMapper = new QSignalMapper(this);
+ connect(d_ptr->signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
+}
+
+ImageViewerActionHandler::~ImageViewerActionHandler()
+{
+}
+
+void ImageViewerActionHandler::actionTriggered(int supportedAction)
+{
+ Core::EditorManager *editorManager = Core::EditorManager::instance();
+ Core::IEditor *editor = editorManager->currentEditor();
+ ImageViewer *viewer = qobject_cast<ImageViewer *>(editor);
+ if (!viewer)
+ return;
+
+ SupportedActions action = static_cast<SupportedActions>(supportedAction);
+ switch(action) {
+ case ZoomIn:
+ viewer->zoomIn();
+ break;
+ case ZoomOut:
+ viewer->zoomOut();
+ break;
+ case OriginalSize:
+ viewer->resetToOriginalSize();
+ break;
+ case FitToScreen:
+ viewer->fitToScreen();
+ break;
+ case Background:
+ viewer->switchViewBackground();
+ break;
+ case Outline:
+ viewer->switchViewOutline();
+ break;
+ default:
+ break;
+ }
+}
+
+void ImageViewerActionHandler::createActions()
+{
+ registerNewAction(ZoomIn, Constants::ACTION_ZOOM_IN, tr("Zoom In"),
+ d_ptr->context, QKeySequence(tr("Ctrl++")));
+ registerNewAction(ZoomOut, Constants::ACTION_ZOOM_OUT, tr("Zoom Out"),
+ d_ptr->context, QKeySequence(tr("Ctrl+-")));
+ registerNewAction(OriginalSize, Constants::ACTION_ORIGINAL_SIZE, tr("Original Size"),
+ d_ptr->context, QKeySequence(tr("Ctrl+0")));
+ registerNewAction(FitToScreen, Constants::ACTION_FIT_TO_SCREEN, tr("Fit To Screen"),
+ d_ptr->context, QKeySequence(tr("Ctrl+=")));
+ registerNewAction(Background, Constants::ACTION_BACKGROUND, tr("Switch background"),
+ d_ptr->context, QKeySequence(tr("Ctrl+[")));
+ registerNewAction(Outline, Constants::ACTION_OUTLINE, tr("Switch outline"),
+ d_ptr->context, QKeySequence(tr("Ctrl+]")));
+}
+
+QAction *ImageViewerActionHandler::registerNewAction(int actionId, const QString &id,
+ const QString &title, const QList<int> &context, const QKeySequence &key)
+{
+ Core::ActionManager *actionManager = Core::ICore::instance()->actionManager();
+ Core::Command *command = 0;
+
+ QAction *action = new QAction(title, this);
+ command = actionManager->registerAction(action, id, context);
+ if (command)
+ command->setDefaultKeySequence(key);
+ connect(action, SIGNAL(triggered()), d_ptr->signalMapper, SLOT(map()));
+ d_ptr->signalMapper->setMapping(action, actionId);
+
+ return action;
+}
+
+} // namespace Internal
+} // namespace ImageViewer
diff --git a/src/plugins/imageviewer/imagevieweractionhandler.h b/src/plugins/imageviewer/imagevieweractionhandler.h
new file mode 100644
index 0000000000..417e8fb79c
--- /dev/null
+++ b/src/plugins/imageviewer/imagevieweractionhandler.h
@@ -0,0 +1,78 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (c) 2010 Denis Mingulov.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef IMAGEVIEWERACTIONHANDLER_H
+#define IMAGEVIEWERACTIONHANDLER_H
+
+#include <QObject>
+#include <QtCore/QScopedPointer>
+
+QT_FORWARD_DECLARE_CLASS(QAction)
+QT_FORWARD_DECLARE_CLASS(QKeySequence)
+
+namespace ImageViewer {
+namespace Internal {
+
+class ImageViewerActionHandler : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ImageViewerActionHandler(QObject *parent = 0);
+ ~ImageViewerActionHandler();
+
+ void createActions();
+
+signals:
+
+public slots:
+ void actionTriggered(int supportedAction);
+
+protected:
+ /*!
+ \brief Create a new action and register this action in the action manager.
+ \param actionId Action's internal id
+ \param id Command id
+ \param title Action's title
+ \param context Current context
+ \param key Key sequence for the command
+ \return Created and registered action, 0 if something goes wrong
+ */
+ QAction *registerNewAction(int actionId, const QString &id, const QString &title,
+ const QList<int> &context, const QKeySequence &key);
+
+private:
+ QScopedPointer<struct ImageViewerActionHandlerPrivate> d_ptr;
+};
+
+} // namespace Internal
+} // namespace ImageViewer
+
+
+#endif // IMAGEVIEWERACTIONHANDLER_H
diff --git a/src/plugins/imageviewer/imageviewerconstants.h b/src/plugins/imageviewer/imageviewerconstants.h
index 6dc1c427ad..749bedca0a 100644
--- a/src/plugins/imageviewer/imageviewerconstants.h
+++ b/src/plugins/imageviewer/imageviewerconstants.h
@@ -37,6 +37,14 @@ namespace Constants {
const char * const IMAGEVIEWER_ID = "Editors.ImageViewer";
const char * const IMAGEVIEWER_DISPLAY_NAME = QT_TRANSLATE_NOOP("OpenWith::Editors", "Image Viewer");
+// actions
+const char * const ACTION_ZOOM_IN = "ImageViewer.ZoomIn";
+const char * const ACTION_ZOOM_OUT = "ImageViewer.ZoomOut";
+const char * const ACTION_ORIGINAL_SIZE = "ImageViewer.OriginalSize";
+const char * const ACTION_FIT_TO_SCREEN = "ImageViewer.FitToScreen";
+const char * const ACTION_BACKGROUND = "ImageViewer.Background";
+const char * const ACTION_OUTLINE = "ImageViewer.Outline";
+
} // namespace Constants
} // namespace ImageViewer
diff --git a/src/plugins/imageviewer/imageviewerfactory.cpp b/src/plugins/imageviewer/imageviewerfactory.cpp
index c87bf77807..94d5ff6c2d 100644
--- a/src/plugins/imageviewer/imageviewerfactory.cpp
+++ b/src/plugins/imageviewer/imageviewerfactory.cpp
@@ -29,6 +29,7 @@
**************************************************************************/
#include "imageviewerfactory.h"
+#include "imagevieweractionhandler.h"
#include "imageviewerconstants.h"
#include "imageviewer.h"
@@ -39,9 +40,18 @@
namespace ImageViewer {
namespace Internal {
+struct ImageViewerFactoryPrivate
+{
+ QStringList mimeTypes;
+ QPointer<ImageViewerActionHandler> actionHandler;
+};
+
ImageViewerFactory::ImageViewerFactory(QObject *parent) :
- Core::IEditorFactory(parent)
+ Core::IEditorFactory(parent),
+ d_ptr(new ImageViewerFactoryPrivate)
{
+ d_ptr->actionHandler = new ImageViewerActionHandler(this);
+
QMap<QByteArray, QString> possibleMimeTypes;
possibleMimeTypes.insert("bmp", QLatin1String("image/bmp"));
possibleMimeTypes.insert("gif", QLatin1String("image/gif"));
@@ -63,10 +73,14 @@ ImageViewerFactory::ImageViewerFactory(QObject *parent) :
foreach (const QByteArray &format, supportedFormats) {
const QString &value = possibleMimeTypes.value(format);
if (!value.isEmpty())
- m_mimeTypes.append(value);
+ d_ptr->mimeTypes.append(value);
}
}
+ImageViewerFactory::~ImageViewerFactory()
+{
+}
+
Core::IEditor *ImageViewerFactory::createEditor(QWidget *parent)
{
return new ImageViewer(parent);
@@ -74,7 +88,7 @@ Core::IEditor *ImageViewerFactory::createEditor(QWidget *parent)
QStringList ImageViewerFactory::mimeTypes() const
{
- return m_mimeTypes;
+ return d_ptr->mimeTypes;
}
QString ImageViewerFactory::id() const
@@ -92,5 +106,10 @@ Core::IFile *ImageViewerFactory::open(const QString & /*fileName*/)
return 0;
}
+void ImageViewerFactory::extensionsInitialized()
+{
+ d_ptr->actionHandler->createActions();
+}
+
} // namespace Internal
} // namespace ImageViewer
diff --git a/src/plugins/imageviewer/imageviewerfactory.h b/src/plugins/imageviewer/imageviewerfactory.h
index ff42ac012e..9c2fe3d555 100644
--- a/src/plugins/imageviewer/imageviewerfactory.h
+++ b/src/plugins/imageviewer/imageviewerfactory.h
@@ -35,7 +35,7 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/ifile.h>
-#include <QtCore/QStringList>
+#include <QtCore/QScopedPointer>
namespace ImageViewer {
namespace Internal {
@@ -45,6 +45,7 @@ class ImageViewerFactory : public Core::IEditorFactory
Q_OBJECT
public:
explicit ImageViewerFactory(QObject *parent = 0);
+ ~ImageViewerFactory();
Core::IEditor *createEditor(QWidget *parent);
@@ -55,8 +56,10 @@ public:
Core::IFile *open(const QString &fileName);
+ void extensionsInitialized();
+
private:
- QStringList m_mimeTypes;
+ QScopedPointer<struct ImageViewerFactoryPrivate> d_ptr;
};
} // namespace Internal
diff --git a/src/plugins/imageviewer/imageviewerplugin.cpp b/src/plugins/imageviewer/imageviewerplugin.cpp
index 1dbcfa3426..7d00d66867 100644
--- a/src/plugins/imageviewer/imageviewerplugin.cpp
+++ b/src/plugins/imageviewer/imageviewerplugin.cpp
@@ -42,9 +42,16 @@
namespace ImageViewer {
namespace Internal {
+///////////////////////////////// ImageViewerPluginPrivate //////////////////////////////////
+struct ImageViewerPluginPrivate
+{
+ QPointer<ImageViewerFactory> factory;
+};
+
///////////////////////////////// ImageViewerPlugin //////////////////////////////////
ImageViewerPlugin::ImageViewerPlugin()
+ : d_ptr(new ImageViewerPluginPrivate)
{
}
@@ -60,16 +67,17 @@ bool ImageViewerPlugin::initialize(const QStringList &arguments, QString *errorM
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/imageviewer/ImageViewer.mimetypes.xml"), errorMessage))
return false;
- ImageViewerFactory *factory = new ImageViewerFactory(this);
+ d_ptr->factory = new ImageViewerFactory(this);
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
- aggregate->add(factory);
+ aggregate->add(d_ptr->factory);
- addAutoReleasedObject(factory);
+ addAutoReleasedObject(d_ptr->factory);
return true;
}
void ImageViewerPlugin::extensionsInitialized()
{
+ d_ptr->factory->extensionsInitialized();
}
} // namespace Internal
diff --git a/src/plugins/imageviewer/imageviewerplugin.h b/src/plugins/imageviewer/imageviewerplugin.h
index 25707252e0..4083903e08 100644
--- a/src/plugins/imageviewer/imageviewerplugin.h
+++ b/src/plugins/imageviewer/imageviewerplugin.h
@@ -34,6 +34,7 @@
#include <extensionsystem/iplugin.h>
#include <QtCore/QtPlugin>
+#include <QtCore/QScopedPointer>
namespace ImageViewer {
@@ -52,6 +53,7 @@ public:
void extensionsInitialized();
private:
+ QScopedPointer<struct ImageViewerPluginPrivate> d_ptr;
};
} // namespace Internal