2010-06-18 11:02:48 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 Denis Mingulov.
|
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2010-06-18 11:02:48 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-06-18 11:02:48 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-06-18 11:02:48 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <utils/fileutils.h>
|
2010-06-18 11:02:48 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2015-10-19 12:55:13 +02:00
|
|
|
#include <utils/themehelper.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>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2010-06-18 11:02:48 +02:00
|
|
|
|
|
|
|
|
namespace ImageViewer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
struct ImageViewerPrivate
|
|
|
|
|
{
|
|
|
|
|
QString displayName;
|
2015-05-29 13:23:52 +02:00
|
|
|
QSharedPointer<ImageViewerFile> file;
|
2010-06-18 11:02:48 +02:00
|
|
|
ImageView *imageView;
|
|
|
|
|
QWidget *toolbar;
|
|
|
|
|
Ui::ImageViewerToolbar ui_toolbar;
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-29 13:23:52 +02:00
|
|
|
/*!
|
|
|
|
|
Tries to change the \a button icon to the icon specified by \a name
|
|
|
|
|
from the current theme. Returns \c true if icon is updated, \c false
|
|
|
|
|
otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static bool 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:48 +02:00
|
|
|
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
|
|
|
{
|
2015-05-29 13:23:52 +02:00
|
|
|
d->file.reset(new ImageViewerFile);
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageViewer::ImageViewer(const QSharedPointer<ImageViewerFile> &document, QWidget *parent)
|
|
|
|
|
: IEditor(parent),
|
|
|
|
|
d(new ImageViewerPrivate)
|
|
|
|
|
{
|
|
|
|
|
d->file = document;
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewer::ctor()
|
|
|
|
|
{
|
|
|
|
|
d->imageView = new ImageView(d->file.data());
|
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);
|
2015-05-29 13:23:52 +02:00
|
|
|
setDuplicateSupported(true);
|
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);
|
2015-10-19 12:55:13 +02:00
|
|
|
d->ui_toolbar.toolButtonZoomIn->setIcon(Utils::ThemeHelper::themedIcon(
|
|
|
|
|
QLatin1String(Core::Constants::ICON_PLUS)));
|
|
|
|
|
d->ui_toolbar.toolButtonZoomOut->setIcon(Utils::ThemeHelper::themedIcon(
|
|
|
|
|
QLatin1String(Core::Constants::ICON_MINUS)));
|
|
|
|
|
d->ui_toolbar.toolButtonFitToScreen->setIcon(Utils::ThemeHelper::themedIcon(
|
|
|
|
|
QLatin1String(Core::Constants::ICON_ZOOM)));
|
2010-06-18 11:02:48 +02:00
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
// icons update - try to use system theme
|
2012-11-26 20:43:53 +02:00
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonZoomIn, QLatin1String("zoom-in"));
|
|
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonZoomOut, QLatin1String("zoom-out"));
|
|
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonOriginalSize, QLatin1String("zoom-original"));
|
|
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonFitToScreen, QLatin1String("zoom-fit-best"));
|
2010-06-18 11:02:48 +02:00
|
|
|
// a display - something is on the background
|
2012-11-26 20:43:53 +02:00
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonBackground, QLatin1String("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)
|
2012-11-26 20:43:53 +02:00
|
|
|
updateButtonIconByTheme(d->ui_toolbar.toolButtonOutline, QLatin1String("emblem-photos"));
|
2010-06-18 11:02:48 +02:00
|
|
|
|
2012-06-25 20:39:09 +04:00
|
|
|
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);
|
|
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
// connections
|
2015-09-21 16:19:04 +02:00
|
|
|
connect(d->ui_toolbar.toolButtonZoomIn, &QAbstractButton::clicked,
|
|
|
|
|
d->imageView, &ImageView::zoomIn);
|
|
|
|
|
connect(d->ui_toolbar.toolButtonZoomOut, &QAbstractButton::clicked,
|
|
|
|
|
d->imageView, &ImageView::zoomOut);
|
|
|
|
|
connect(d->ui_toolbar.toolButtonFitToScreen, &QAbstractButton::clicked,
|
|
|
|
|
d->imageView, &ImageView::fitToScreen);
|
|
|
|
|
connect(d->ui_toolbar.toolButtonOriginalSize, &QAbstractButton::clicked,
|
|
|
|
|
d->imageView, &ImageView::resetToOriginalSize);
|
|
|
|
|
connect(d->ui_toolbar.toolButtonBackground, &QAbstractButton::toggled,
|
|
|
|
|
d->imageView, &ImageView::setViewBackground);
|
|
|
|
|
connect(d->ui_toolbar.toolButtonOutline, &QAbstractButton::toggled,
|
|
|
|
|
d->imageView, &ImageView::setViewOutline);
|
2015-01-29 14:32:36 +01:00
|
|
|
connect(d->ui_toolbar.toolButtonPlayPause, &Core::CommandButton::clicked,
|
|
|
|
|
this, &ImageViewer::playToggled);
|
2015-05-29 13:23:52 +02:00
|
|
|
connect(d->file.data(), &ImageViewerFile::imageSizeChanged,
|
|
|
|
|
this, &ImageViewer::imageSizeUpdated);
|
2015-06-02 17:14:48 +02:00
|
|
|
connect(d->file.data(), &ImageViewerFile::openFinished,
|
|
|
|
|
d->imageView, &ImageView::createScene);
|
2015-05-29 13:23:52 +02:00
|
|
|
connect(d->file.data(), &ImageViewerFile::aboutToReload,
|
|
|
|
|
d->imageView, &ImageView::reset);
|
|
|
|
|
connect(d->file.data(), &ImageViewerFile::reloadFinished,
|
|
|
|
|
d->imageView, &ImageView::createScene);
|
|
|
|
|
connect(d->file.data(), &ImageViewerFile::isPausedChanged,
|
|
|
|
|
this, &ImageViewer::updatePauseAction);
|
2015-09-21 16:19:04 +02:00
|
|
|
connect(d->imageView, &ImageView::scaleFactorChanged,
|
|
|
|
|
this, &ImageViewer::scaleFactorUpdate);
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *ImageViewer::document()
|
2010-06-18 11:02:48 +02:00
|
|
|
{
|
2015-05-29 13:23:52 +02:00
|
|
|
return d->file.data();
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *ImageViewer::toolBar()
|
|
|
|
|
{
|
2011-09-02 12:16:56 +02:00
|
|
|
return d->toolbar;
|
2010-06-18 11:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 13:23:52 +02:00
|
|
|
Core::IEditor *ImageViewer::duplicate()
|
|
|
|
|
{
|
|
|
|
|
auto other = new ImageViewer(d->file);
|
|
|
|
|
other->d->imageView->createScene();
|
|
|
|
|
return other;
|
|
|
|
|
}
|
|
|
|
|
|
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: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()
|
|
|
|
|
{
|
2015-05-29 13:23:52 +02:00
|
|
|
d->file->setPaused(!d->file->isPaused());
|
2012-05-10 15:14:21 +04:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 13:23:52 +02:00
|
|
|
void ImageViewer::updatePauseAction()
|
2012-05-10 15:14:21 +04:00
|
|
|
{
|
2015-05-29 13:23:52 +02:00
|
|
|
bool isMovie = d->file->type() == ImageViewerFile::TypeMovie;
|
|
|
|
|
d->ui_toolbar.toolButtonPlayPause->setVisible(isMovie);
|
|
|
|
|
if (isMovie) {
|
|
|
|
|
if (d->file->isPaused()) {
|
|
|
|
|
d->ui_toolbar.toolButtonPlayPause->setToolTipBase(tr("Play Animation"));
|
|
|
|
|
d->ui_toolbar.toolButtonPlayPause->setIcon(QPixmap(QLatin1String(":/imageviewer/images/play-small.png")));
|
|
|
|
|
} else {
|
|
|
|
|
d->ui_toolbar.toolButtonPlayPause->setToolTipBase(tr("Pause Animation"));
|
|
|
|
|
d->ui_toolbar.toolButtonPlayPause->setIcon(QPixmap(QLatin1String(":/imageviewer/images/pause-small.png")));
|
|
|
|
|
}
|
2012-05-10 15:14:21 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 11:02:48 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ImageViewer
|