Commit ef9d9953 authored by hjk's avatar hjk Committed by hjk
Browse files

ImageViewer: adjust to style guide

Change-Id: Id0f5a521199b9dc5b29fc3cb7b7bd82521bc00e6
Reviewed-on: http://codereview.qt.nokia.com/4130

Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent c34ca898
......@@ -71,7 +71,7 @@ struct ImageViewPrivate
ImageView::ImageView(QWidget *parent)
: QGraphicsView(parent),
d_ptr(new ImageViewPrivate())
d(new ImageViewPrivate())
{
setScene(new QGraphicsScene(this));
setTransformationAnchor(AnchorUnderMouse);
......@@ -123,8 +123,8 @@ bool ImageView::openFile(QString fileName)
QGraphicsScene *s = scene();
bool drawBackground = (d_ptr->backgroundItem ? d_ptr->backgroundItem->isVisible() : false);
bool drawOutline = (d_ptr->outlineItem ? d_ptr->outlineItem->isVisible() : true);
bool drawBackground = (d->backgroundItem ? d->backgroundItem->isVisible() : false);
bool drawOutline = (d->outlineItem ? d->outlineItem->isVisible() : true);
s->clear();
resetTransform();
......@@ -132,40 +132,40 @@ bool ImageView::openFile(QString fileName)
// image
#ifndef QT_NO_SVG
if (isSvg) {
d_ptr->imageItem = new QGraphicsSvgItem(fileName);
d->imageItem = new QGraphicsSvgItem(fileName);
} else
#endif
{
QPixmap pixmap(fileName);
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setTransformationMode(Qt::SmoothTransformation);
d_ptr->imageItem = pixmapItem;
d->imageItem = pixmapItem;
}
d_ptr->imageItem->setCacheMode(QGraphicsItem::NoCache);
d_ptr->imageItem->setZValue(0);
d->imageItem->setCacheMode(QGraphicsItem::NoCache);
d->imageItem->setZValue(0);
// background item
d_ptr->backgroundItem = new QGraphicsRectItem(d_ptr->imageItem->boundingRect());
d_ptr->backgroundItem->setBrush(Qt::white);
d_ptr->backgroundItem->setPen(Qt::NoPen);
d_ptr->backgroundItem->setVisible(drawBackground);
d_ptr->backgroundItem->setZValue(-1);
d->backgroundItem = new QGraphicsRectItem(d->imageItem->boundingRect());
d->backgroundItem->setBrush(Qt::white);
d->backgroundItem->setPen(Qt::NoPen);
d->backgroundItem->setVisible(drawBackground);
d->backgroundItem->setZValue(-1);
// outline
d_ptr->outlineItem = new QGraphicsRectItem(d_ptr->imageItem->boundingRect());
d->outlineItem = new QGraphicsRectItem(d->imageItem->boundingRect());
QPen outline(Qt::black, 1, Qt::DashLine);
outline.setCosmetic(true);
d_ptr->outlineItem->setPen(outline);
d_ptr->outlineItem->setBrush(Qt::NoBrush);
d_ptr->outlineItem->setVisible(drawOutline);
d_ptr->outlineItem->setZValue(1);
d->outlineItem->setPen(outline);
d->outlineItem->setBrush(Qt::NoBrush);
d->outlineItem->setVisible(drawOutline);
d->outlineItem->setZValue(1);
s->addItem(d_ptr->backgroundItem);
s->addItem(d_ptr->imageItem);
s->addItem(d_ptr->outlineItem);
s->addItem(d->backgroundItem);
s->addItem(d->imageItem);
s->addItem(d->outlineItem);
// if image size is 0x0, then it is not loaded
if (d_ptr->imageItem->boundingRect().height() == 0 && d_ptr->imageItem->boundingRect().width() == 0)
if (d->imageItem->boundingRect().height() == 0 && d->imageItem->boundingRect().width() == 0)
return false;
emitScaleFactor();
......@@ -174,18 +174,18 @@ bool ImageView::openFile(QString fileName)
void ImageView::setViewBackground(bool enable)
{
if (!d_ptr->backgroundItem)
if (!d->backgroundItem)
return;
d_ptr->backgroundItem->setVisible(enable);
d->backgroundItem->setVisible(enable);
}
void ImageView::setViewOutline(bool enable)
{
if (!d_ptr->outlineItem)
if (!d->outlineItem)
return;
d_ptr->outlineItem->setVisible(enable);
d->outlineItem->setVisible(enable);
}
void ImageView::doScale(qreal factor)
......@@ -219,7 +219,7 @@ void ImageView::resetToOriginalSize()
void ImageView::fitToScreen()
{
fitInView(d_ptr->imageItem, Qt::KeepAspectRatio);
fitInView(d->imageItem, Qt::KeepAspectRatio);
emitScaleFactor();
}
......
......@@ -83,7 +83,7 @@ protected:
void wheelEvent(QWheelEvent *event);
private:
QScopedPointer<struct ImageViewPrivate> d_ptr;
QScopedPointer<struct ImageViewPrivate> d;
};
} // namespace Internal
......
......@@ -63,52 +63,52 @@ struct ImageViewerPrivate
ImageViewer::ImageViewer(QWidget *parent)
: IEditor(parent),
d_ptr(new ImageViewerPrivate)
d(new ImageViewerPrivate)
{
d_ptr->file = new ImageViewerFile(this);
d_ptr->imageView = new ImageView();
d->file = new ImageViewerFile(this);
d->imageView = new ImageView();
setContext(Core::Context(Constants::IMAGEVIEWER_ID));
setWidget(d_ptr->imageView);
setWidget(d->imageView);
// toolbar
d_ptr->toolbar = new QWidget();
d_ptr->ui_toolbar.setupUi(d_ptr->toolbar);
d->toolbar = new QWidget();
d->ui_toolbar.setupUi(d->toolbar);
// icons update - try to use system theme
updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonZoomIn, "zoom-in");
updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonZoomOut, "zoom-out");
updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonOriginalSize, "zoom-original");
updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonFitToScreen, "zoom-fit-best");
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");
// a display - something is on the background
updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonBackground, "video-display");
updateButtonIconByTheme(d->ui_toolbar.toolButtonBackground, "video-display");
// "emblem to specify the directory where the user stores photographs"
// (photograph has outline - piece of paper)
updateButtonIconByTheme(d_ptr->ui_toolbar.toolButtonOutline, "emblem-photos");
updateButtonIconByTheme(d->ui_toolbar.toolButtonOutline, "emblem-photos");
// connections
connect(d_ptr->file, SIGNAL(changed()), this, SIGNAL(changed()));
connect(d_ptr->ui_toolbar.toolButtonZoomIn, SIGNAL(clicked()),
d_ptr->imageView, SLOT(zoomIn()));
connect(d_ptr->ui_toolbar.toolButtonZoomOut, SIGNAL(clicked()),
d_ptr->imageView, SLOT(zoomOut()));
connect(d_ptr->ui_toolbar.toolButtonFitToScreen, SIGNAL(clicked()),
d_ptr->imageView, SLOT(fitToScreen()));
connect(d_ptr->ui_toolbar.toolButtonOriginalSize, SIGNAL(clicked()),
d_ptr->imageView, SLOT(resetToOriginalSize()));
connect(d_ptr->ui_toolbar.toolButtonBackground, SIGNAL(toggled(bool)),
d_ptr->imageView, SLOT(setViewBackground(bool)));
connect(d_ptr->ui_toolbar.toolButtonOutline, SIGNAL(toggled(bool)),
d_ptr->imageView, SLOT(setViewOutline(bool)));
connect(d_ptr->imageView, SIGNAL(scaleFactorChanged(qreal)),
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)));
connect(d->imageView, SIGNAL(scaleFactorChanged(qreal)),
this, SLOT(scaleFactorUpdate(qreal)));
}
ImageViewer::~ImageViewer()
{
delete d_ptr->imageView;
delete d_ptr->toolbar;
delete d->imageView;
delete d->toolbar;
}
bool ImageViewer::createNew(const QString &contents)
......@@ -119,12 +119,12 @@ bool ImageViewer::createNew(const QString &contents)
bool ImageViewer::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
if (!d_ptr->imageView->openFile(realFileName)) {
if (!d->imageView->openFile(realFileName)) {
*errorString = tr("Cannot open image file %1").arg(QDir::toNativeSeparators(realFileName));
return false;
}
setDisplayName(QFileInfo(fileName).fileName());
d_ptr->file->setFileName(fileName);
d->file->setFileName(fileName);
// d_ptr->file->setMimeType
emit changed();
return true;
......@@ -132,7 +132,7 @@ bool ImageViewer::open(QString *errorString, const QString &fileName, const QStr
Core::IFile *ImageViewer::file()
{
return d_ptr->file;
return d->file;
}
QString ImageViewer::id() const
......@@ -142,12 +142,12 @@ QString ImageViewer::id() const
QString ImageViewer::displayName() const
{
return d_ptr->displayName;
return d->displayName;
}
void ImageViewer::setDisplayName(const QString &title)
{
d_ptr->displayName = title;
d->displayName = title;
emit changed();
}
......@@ -190,13 +190,13 @@ bool ImageViewer::isTemporary() const
QWidget *ImageViewer::toolBar()
{
return d_ptr->toolbar;
return d->toolbar;
}
void ImageViewer::scaleFactorUpdate(qreal factor)
{
const QString info = QString::number(factor * 100, 'f', 2) + QLatin1Char('%');
d_ptr->ui_toolbar.labelInfo->setText(info);
d->ui_toolbar.labelInfo->setText(info);
}
bool ImageViewer::updateButtonIconByTheme(QAbstractButton *button, const QString &name)
......@@ -214,32 +214,32 @@ bool ImageViewer::updateButtonIconByTheme(QAbstractButton *button, const QString
void ImageViewer::switchViewBackground()
{
d_ptr->ui_toolbar.toolButtonBackground->click();
d->ui_toolbar.toolButtonBackground->click();
}
void ImageViewer::switchViewOutline()
{
d_ptr->ui_toolbar.toolButtonOutline->click();
d->ui_toolbar.toolButtonOutline->click();
}
void ImageViewer::zoomIn()
{
d_ptr->ui_toolbar.toolButtonZoomIn->click();
d->ui_toolbar.toolButtonZoomIn->click();
}
void ImageViewer::zoomOut()
{
d_ptr->ui_toolbar.toolButtonZoomOut->click();
d->ui_toolbar.toolButtonZoomOut->click();
}
void ImageViewer::resetToOriginalSize()
{
d_ptr->ui_toolbar.toolButtonOriginalSize->click();
d->ui_toolbar.toolButtonOriginalSize->click();
}
void ImageViewer::fitToScreen()
{
d_ptr->ui_toolbar.toolButtonFitToScreen->click();
d->ui_toolbar.toolButtonFitToScreen->click();
}
} // namespace Internal
......
......@@ -40,8 +40,10 @@
#include <QtCore/QScopedPointer>
#include <QtCore/QStringList>
QT_FORWARD_DECLARE_CLASS(QAbstractButton)
QT_FORWARD_DECLARE_CLASS(QAction)
QT_BEGIN_NAMESPACE
class QAbstractButton;
class QAction;
QT_END_NAMESPACE
namespace ImageViewer {
namespace Internal {
......@@ -95,7 +97,7 @@ private:
bool updateButtonIconByTheme(QAbstractButton *button, const QString &name);
private:
QScopedPointer<struct ImageViewerPrivate> d_ptr;
QScopedPointer<struct ImageViewerPrivate> d;
};
} // namespace Internal
......
......@@ -70,10 +70,10 @@ struct ImageViewerActionHandlerPrivate
ImageViewerActionHandler::ImageViewerActionHandler(QObject *parent) :
QObject(parent),
d_ptr(new ImageViewerActionHandlerPrivate)
d(new ImageViewerActionHandlerPrivate)
{
d_ptr->signalMapper = new QSignalMapper(this);
connect(d_ptr->signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
d->signalMapper = new QSignalMapper(this);
connect(d->signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
}
ImageViewerActionHandler::~ImageViewerActionHandler()
......@@ -116,17 +116,17 @@ void ImageViewerActionHandler::actionTriggered(int supportedAction)
void ImageViewerActionHandler::createActions()
{
registerNewAction(ZoomIn, Constants::ACTION_ZOOM_IN, tr("Zoom In"),
d_ptr->context, QKeySequence(tr("Ctrl++")));
d->context, QKeySequence(tr("Ctrl++")));
registerNewAction(ZoomOut, Constants::ACTION_ZOOM_OUT, tr("Zoom Out"),
d_ptr->context, QKeySequence(tr("Ctrl+-")));
d->context, QKeySequence(tr("Ctrl+-")));
registerNewAction(OriginalSize, Constants::ACTION_ORIGINAL_SIZE, tr("Original Size"),
d_ptr->context, QKeySequence(tr("Ctrl+0")));
d->context, QKeySequence(tr("Ctrl+0")));
registerNewAction(FitToScreen, Constants::ACTION_FIT_TO_SCREEN, tr("Fit To Screen"),
d_ptr->context, QKeySequence(tr("Ctrl+=")));
d->context, QKeySequence(tr("Ctrl+=")));
registerNewAction(Background, Constants::ACTION_BACKGROUND, tr("Switch Background"),
d_ptr->context, QKeySequence(tr("Ctrl+[")));
d->context, QKeySequence(tr("Ctrl+[")));
registerNewAction(Outline, Constants::ACTION_OUTLINE, tr("Switch Outline"),
d_ptr->context, QKeySequence(tr("Ctrl+]")));
d->context, QKeySequence(tr("Ctrl+]")));
}
QAction *ImageViewerActionHandler::registerNewAction(int actionId, const QString &id,
......@@ -139,8 +139,8 @@ QAction *ImageViewerActionHandler::registerNewAction(int actionId, const QString
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);
connect(action, SIGNAL(triggered()), d->signalMapper, SLOT(map()));
d->signalMapper->setMapping(action, actionId);
return action;
}
......
......@@ -50,14 +50,13 @@ namespace Internal {
class ImageViewerActionHandler : public QObject
{
Q_OBJECT
public:
explicit ImageViewerActionHandler(QObject *parent = 0);
~ImageViewerActionHandler();
void createActions();
signals:
public slots:
void actionTriggered(int supportedAction);
......@@ -75,11 +74,10 @@ protected:
const Core::Context &context, const QKeySequence &key);
private:
QScopedPointer<struct ImageViewerActionHandlerPrivate> d_ptr;
QScopedPointer<struct ImageViewerActionHandlerPrivate> d;
};
} // namespace Internal
} // namespace ImageViewer
#endif // IMAGEVIEWERACTIONHANDLER_H
......@@ -37,16 +37,15 @@
namespace ImageViewer {
namespace Constants {
const char * const IMAGEVIEWER_ID = "Editors.ImageViewer";
const char * const IMAGEVIEWER_DISPLAY_NAME = QT_TRANSLATE_NOOP("OpenWith::Editors", "Image Viewer");
const char IMAGEVIEWER_ID[] = "Editors.ImageViewer";
const char 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";
const char ACTION_ZOOM_IN[] = "ImageViewer.ZoomIn";
const char ACTION_ZOOM_OUT[] = "ImageViewer.ZoomOut";
const char ACTION_ORIGINAL_SIZE[] = "ImageViewer.OriginalSize";
const char ACTION_FIT_TO_SCREEN[] = "ImageViewer.FitToScreen";
const char ACTION_BACKGROUND[] = "ImageViewer.Background";
const char ACTION_OUTLINE[] = "ImageViewer.Outline";
} // namespace Constants
} // namespace ImageViewer
......
......@@ -51,9 +51,9 @@ struct ImageViewerFactoryPrivate
ImageViewerFactory::ImageViewerFactory(QObject *parent) :
Core::IEditorFactory(parent),
d_ptr(new ImageViewerFactoryPrivate)
d(new ImageViewerFactoryPrivate)
{
d_ptr->actionHandler = new ImageViewerActionHandler(this);
d->actionHandler = new ImageViewerActionHandler(this);
QMap<QByteArray, QString> possibleMimeTypes;
possibleMimeTypes.insert("bmp", QLatin1String("image/bmp"));
......@@ -76,7 +76,7 @@ ImageViewerFactory::ImageViewerFactory(QObject *parent) :
foreach (const QByteArray &format, supportedFormats) {
const QString &value = possibleMimeTypes.value(format);
if (!value.isEmpty())
d_ptr->mimeTypes.append(value);
d->mimeTypes.append(value);
}
}
......@@ -91,7 +91,7 @@ Core::IEditor *ImageViewerFactory::createEditor(QWidget *parent)
QStringList ImageViewerFactory::mimeTypes() const
{
return d_ptr->mimeTypes;
return d->mimeTypes;
}
QString ImageViewerFactory::id() const
......@@ -111,7 +111,7 @@ Core::IFile *ImageViewerFactory::open(const QString & /*fileName*/)
void ImageViewerFactory::extensionsInitialized()
{
d_ptr->actionHandler->createActions();
d->actionHandler->createActions();
}
} // namespace Internal
......
......@@ -62,7 +62,7 @@ public:
void extensionsInitialized();
private:
QScopedPointer<struct ImageViewerFactoryPrivate> d_ptr;
QScopedPointer<struct ImageViewerFactoryPrivate> d;
};
} // namespace Internal
......
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