2010-06-18 11:02:48 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-06-18 11:02:48 +02:00
|
|
|
** Copyright (c) 2010 Denis Mingulov.
|
|
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-06-18 11:02:48 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-06-18 11:02:48 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-06-18 11:02:48 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "imageviewer.h"
|
|
|
|
|
#include "imageviewerfile.h"
|
2010-06-18 11:02:50 +02:00
|
|
|
#include "imagevieweractionhandler.h"
|
2010-06-18 11:02:48 +02:00
|
|
|
#include "imageviewerconstants.h"
|
|
|
|
|
#include "imageview.h"
|
|
|
|
|
#include "ui_imageviewertoolbar.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-06-18 11:02:50 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2010-06-18 11:02:48 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2010-06-18 11:02:48 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMap>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QtDebug>
|
2010-06-18 11:02:48 +02:00
|
|
|
|
|
|
|
|
namespace ImageViewer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
struct ImageViewerPrivate
|
|
|
|
|
{
|
|
|
|
|
QString displayName;
|
|
|
|
|
ImageViewerFile *file;
|
|
|
|
|
ImageView *imageView;
|
|
|
|
|
QWidget *toolbar;
|
|
|
|
|
Ui::ImageViewerToolbar ui_toolbar;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ImageViewer::ImageViewer(QWidget *parent)
|
|
|
|
|
: IEditor(parent),
|
2011-09-02 12:16:56 +02:00
|
|
|
d(new ImageViewerPrivate)
|
2010-06-18 11:02:48 +02:00
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->file = new ImageViewerFile(this);
|
|
|
|
|
d->imageView = new ImageView();
|
2010-06-18 11:02:48 +02:00
|
|
|
|
2011-04-13 13:00:30 +02:00
|
|
|
setContext(Core::Context(Constants::IMAGEVIEWER_ID));
|
2011-09-02 12:16:56 +02:00
|
|
|
setWidget(d->imageView);
|
2011-04-13 13:00:30 +02:00
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
// toolbar
|
2011-09-02 12:16:56 +02:00
|
|
|
d->toolbar = new QWidget();
|
|
|
|
|
d->ui_toolbar.setupUi(d->toolbar);
|
2010-06-18 11:02:48 +02:00
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
// icons update - try to use system theme
|
2011-09-02 12:16:56 +02:00
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonZoomIn, "zoom-in");
|
|
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonZoomOut, "zoom-out");
|
|
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonOriginalSize, "zoom-original");
|
|
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonFitToScreen, "zoom-fit-best");
|
2010-06-18 11:02:48 +02:00
|
|
|
// a display - something is on the background
|
2011-09-02 12:16:56 +02:00
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonBackground, "video-display");
|
2010-06-18 11:02:48 +02:00
|
|
|
// "emblem to specify the directory where the user stores photographs"
|
|
|
|
|
// (photograph has outline - piece of paper)
|
2011-09-02 12:16:56 +02:00
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonOutline, "emblem-photos");
|
2010-06-18 11:02:48 +02:00
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
// connections
|
2011-09-02 12:16:56 +02:00
|
|
|
connect(d->file, SIGNAL(changed()), this, SIGNAL(changed()));
|
|
|
|
|
|
|
|
|
|
connect(d->ui_toolbar.toolButtonZoomIn, SIGNAL(clicked()),
|
|
|
|
|
d->imageView, SLOT(zoomIn()));
|
|
|
|
|
connect(d->ui_toolbar.toolButtonZoomOut, SIGNAL(clicked()),
|
|
|
|
|
d->imageView, SLOT(zoomOut()));
|
|
|
|
|
connect(d->ui_toolbar.toolButtonFitToScreen, SIGNAL(clicked()),
|
|
|
|
|
d->imageView, SLOT(fitToScreen()));
|
|
|
|
|
connect(d->ui_toolbar.toolButtonOriginalSize, SIGNAL(clicked()),
|
|
|
|
|
d->imageView, SLOT(resetToOriginalSize()));
|
|
|
|
|
connect(d->ui_toolbar.toolButtonBackground, SIGNAL(toggled(bool)),
|
|
|
|
|
d->imageView, SLOT(setViewBackground(bool)));
|
|
|
|
|
connect(d->ui_toolbar.toolButtonOutline, SIGNAL(toggled(bool)),
|
|
|
|
|
d->imageView, SLOT(setViewOutline(bool)));
|
2012-05-10 15:14:21 +04:00
|
|
|
connect(d->ui_toolbar.toolButtonPlayPause, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(playToggled()));
|
|
|
|
|
connect(d->imageView, SIGNAL(imageSizeChanged(QSize)),
|
|
|
|
|
this, SLOT(imageSizeUpdated(QSize)));
|
2011-09-02 12:16:56 +02:00
|
|
|
connect(d->imageView, SIGNAL(scaleFactorChanged(qreal)),
|
2010-06-18 11:02:48 +02:00
|
|
|
this, SLOT(scaleFactorUpdate(qreal)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageViewer::~ImageViewer()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
delete d->imageView;
|
|
|
|
|
delete d->toolbar;
|
2011-09-16 15:00:41 +02:00
|
|
|
delete d;
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ImageViewer::createNew(const QString &contents)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(contents)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-10 20:43:03 +02:00
|
|
|
bool ImageViewer::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
2010-06-18 11:02:48 +02:00
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
if (!d->imageView->openFile(realFileName)) {
|
2012-03-05 14:35:17 +01:00
|
|
|
*errorString = tr("Cannot open image file %1.").arg(QDir::toNativeSeparators(realFileName));
|
2010-06-18 11:02:48 +02:00
|
|
|
return false;
|
2011-04-04 15:24:13 +02:00
|
|
|
}
|
2010-06-18 11:02:48 +02:00
|
|
|
setDisplayName(QFileInfo(fileName).fileName());
|
2011-09-02 12:16:56 +02:00
|
|
|
d->file->setFileName(fileName);
|
2012-05-10 15:14:21 +04:00
|
|
|
d->ui_toolbar.toolButtonPlayPause->setVisible(d->imageView->isAnimated());
|
|
|
|
|
setPaused(!d->imageView->isAnimated());
|
2010-06-18 11:02:48 +02:00
|
|
|
// d_ptr->file->setMimeType
|
|
|
|
|
emit changed();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *ImageViewer::document()
|
2010-06-18 11:02:48 +02:00
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
return d->file;
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-10 11:36:51 +01:00
|
|
|
Core::Id ImageViewer::id() const
|
2010-06-18 11:02:48 +02:00
|
|
|
{
|
2011-11-10 11:36:51 +01:00
|
|
|
return Core::Id(Constants::IMAGEVIEWER_ID);
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ImageViewer::displayName() const
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
return d->displayName;
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::setDisplayName(const QString &title)
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->displayName = title;
|
2010-06-18 11:02:48 +02:00
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ImageViewer::duplicateSupported() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IEditor *ImageViewer::duplicate(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray ImageViewer::saveState() const
|
|
|
|
|
{
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ImageViewer::restoreState(const QByteArray &state)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(state);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ImageViewer::currentLine() const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ImageViewer::currentColumn() const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ImageViewer::isTemporary() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *ImageViewer::toolBar()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
return d->toolbar;
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-10 15:14:21 +04:00
|
|
|
void ImageViewer::imageSizeUpdated(const QSize &size)
|
|
|
|
|
{
|
|
|
|
|
QString imageSizeText;
|
|
|
|
|
if (size.isValid())
|
|
|
|
|
imageSizeText = QString::fromLatin1("%1x%2").arg(size.width()).arg(size.height());
|
|
|
|
|
d->ui_toolbar.labelImageSize->setText(imageSizeText);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
void ImageViewer::scaleFactorUpdate(qreal factor)
|
|
|
|
|
{
|
2010-09-10 10:51:43 +02:00
|
|
|
const QString info = QString::number(factor * 100, 'f', 2) + QLatin1Char('%');
|
2011-09-02 12:16:56 +02:00
|
|
|
d->ui_toolbar.labelInfo->setText(info);
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
bool ImageViewer::updateButtonIconByTheme(QAbstractButton *button, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(button, return false);
|
|
|
|
|
QTC_ASSERT(!name.isEmpty(), return false);
|
|
|
|
|
|
|
|
|
|
if (QIcon::hasThemeIcon(name)) {
|
|
|
|
|
button->setIcon(QIcon::fromTheme(name));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 11:02:50 +02:00
|
|
|
void ImageViewer::switchViewBackground()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->ui_toolbar.toolButtonBackground->click();
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::switchViewOutline()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->ui_toolbar.toolButtonOutline->click();
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::zoomIn()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->ui_toolbar.toolButtonZoomIn->click();
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::zoomOut()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->ui_toolbar.toolButtonZoomOut->click();
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::resetToOriginalSize()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->ui_toolbar.toolButtonOriginalSize->click();
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::fitToScreen()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
d->ui_toolbar.toolButtonFitToScreen->click();
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-10 15:14:21 +04:00
|
|
|
void ImageViewer::togglePlay()
|
|
|
|
|
{
|
|
|
|
|
d->ui_toolbar.toolButtonPlayPause->click();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::playToggled()
|
|
|
|
|
{
|
|
|
|
|
bool paused = d->imageView->isPaused();
|
|
|
|
|
setPaused(!paused);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::setPaused(bool paused)
|
|
|
|
|
{
|
|
|
|
|
d->imageView->setPaused(paused);
|
|
|
|
|
if (paused) {
|
|
|
|
|
d->ui_toolbar.toolButtonPlayPause->setToolTip(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->setIcon(QPixmap(QLatin1String(":/imageviewer/images/pause-small.png")));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ImageViewer
|