~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/common/libkipiplugins/widgets/previewimage.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of kipi-plugins project
 
4
 * http://www.kipi-plugins.org
 
5
 *
 
6
 * Date        : 2009-12-13
 
7
 * Description : a widget to preview image effect.
 
8
 *
 
9
 * Copyright (C) 2009-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
11
 * This program is free software; you can redistribute it
 
12
 * and/or modify it under the terms of the GNU General
 
13
 * Public License as published by the Free Software Foundation;
 
14
 * either version 2, or (at your option)
 
15
 * any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "previewimage.moc"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <QAction>
 
29
#include <QLabel>
 
30
#include <QTimer>
 
31
#include <QImage>
 
32
#include <QPaintEvent>
 
33
#include <QPainter>
 
34
#include <QPixmap>
 
35
#include <QGraphicsPixmapItem>
 
36
#include <QGraphicsScene>
 
37
#include <QWheelEvent>
 
38
#include <QScrollBar>
 
39
#include <QToolBar>
 
40
 
 
41
// KDE includes
 
42
 
 
43
#include <klocale.h>
 
44
#include <kiconloader.h>
 
45
#include <kicon.h>
 
46
#include <kvbox.h>
 
47
 
 
48
namespace KIPIPlugins
 
49
{
 
50
 
 
51
class PreviewImage::PreviewImagePriv
 
52
{
 
53
 
 
54
public:
 
55
 
 
56
    PreviewImagePriv()
 
57
    {
 
58
        pixmapItem     = 0;
 
59
        scene          = 0;
 
60
        zoomInAction   = 0;
 
61
        zoomOutAction  = 0;
 
62
        zoom2FitAction = 0;
 
63
        toolBar        = 0;
 
64
    }
 
65
 
 
66
    int                  lastdx;
 
67
    int                  lastdy;
 
68
 
 
69
    QGraphicsScene*      scene;
 
70
    QGraphicsPixmapItem* pixmapItem;
 
71
 
 
72
    QAction*             zoomInAction;
 
73
    QAction*             zoomOutAction;
 
74
    QAction*             zoom2FitAction;
 
75
 
 
76
    QToolBar*            toolBar;
 
77
};
 
78
 
 
79
PreviewImage::PreviewImage(QWidget* parent)
 
80
            : QGraphicsView(parent), d(new PreviewImagePriv)
 
81
{
 
82
    setAttribute(Qt::WA_DeleteOnClose);
 
83
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
84
    setMouseTracking(true);
 
85
    setCacheMode(QGraphicsView::CacheBackground);
 
86
 
 
87
    d->scene      = new QGraphicsScene;
 
88
    d->pixmapItem = new QGraphicsPixmapItem;
 
89
 
 
90
    d->scene->addItem(d->pixmapItem);
 
91
    setScene(d->scene);
 
92
 
 
93
    // create context menu
 
94
 
 
95
    d->zoomInAction = new QAction(KIcon("zoom-in"), i18n("Zoom In"), this);
 
96
    d->zoomInAction->setToolTip(i18n("Zoom In"));
 
97
    d->zoomInAction->setShortcut(Qt::Key_Plus);
 
98
    connect(d->zoomInAction, SIGNAL(triggered()),
 
99
            this, SLOT(slotZoomIn()));
 
100
 
 
101
    d->zoomOutAction = new QAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
 
102
    d->zoomOutAction->setToolTip(i18n("Zoom Out"));
 
103
    d->zoomOutAction->setShortcut(Qt::Key_Minus);
 
104
    connect(d->zoomOutAction, SIGNAL(triggered()),
 
105
            this, SLOT(slotZoomOut()));
 
106
 
 
107
    d->zoom2FitAction = new QAction(KIcon("zoom-fit-best"), i18n("Zoom to Fit"), this);
 
108
    d->zoom2FitAction->setToolTip(i18n("Zoom to Fit"));
 
109
    d->zoom2FitAction->setShortcut(Qt::Key_Asterisk);
 
110
    connect(d->zoom2FitAction, SIGNAL(triggered()),
 
111
            this, SLOT(slotZoom2Fit()));
 
112
 
 
113
    addAction(d->zoomInAction);
 
114
    addAction(d->zoomOutAction);
 
115
    addAction(d->zoom2FitAction);
 
116
    setContextMenuPolicy(Qt::ActionsContextMenu);
 
117
 
 
118
    // Create ToolBar
 
119
 
 
120
    d->toolBar = new QToolBar(this);
 
121
    d->toolBar->addAction(d->zoomInAction);
 
122
    d->toolBar->addAction(d->zoomOutAction);
 
123
    d->toolBar->addAction(d->zoom2FitAction);
 
124
    d->toolBar->hide();
 
125
    d->toolBar->installEventFilter(this);
 
126
 
 
127
    horizontalScrollBar()->installEventFilter(this);
 
128
    verticalScrollBar()->installEventFilter(this);
 
129
}
 
130
 
 
131
PreviewImage::~PreviewImage()
 
132
{
 
133
    delete d;
 
134
}
 
135
 
 
136
bool PreviewImage::setImage(const QImage& img) const
 
137
{
 
138
    if (!img.isNull())
 
139
    {
 
140
        d->pixmapItem->setPixmap(QPixmap::fromImage(img));
 
141
        d->pixmapItem->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
 
142
        d->scene->setSceneRect(0, 0, img.width(), img.height());
 
143
        return true;
 
144
    }
 
145
 
 
146
    return false;
 
147
}
 
148
 
 
149
bool PreviewImage::load(const QString& file) const
 
150
{
 
151
    QImage image(file);
 
152
    return setImage(image);
 
153
}
 
154
 
 
155
void PreviewImage::slotZoomIn()
 
156
{
 
157
    scale(1.5, 1.5);
 
158
    d->zoom2FitAction->setDisabled(false);
 
159
}
 
160
 
 
161
void PreviewImage::slotZoomOut()
 
162
{
 
163
    scale(1.0 / 1.5, 1.0 / 1.5);
 
164
    d->zoom2FitAction->setDisabled(false);
 
165
}
 
166
 
 
167
void PreviewImage::slotZoom2Fit()
 
168
{
 
169
    fitInView(d->pixmapItem->boundingRect(), Qt::KeepAspectRatio);
 
170
    d->zoom2FitAction->setDisabled(true);
 
171
}
 
172
 
 
173
void PreviewImage::wheelEvent(QWheelEvent *e)
 
174
{
 
175
    if(e->modifiers() == Qt::ControlModifier)
 
176
    {
 
177
        if(e->delta() > 0)
 
178
        {
 
179
            slotZoomIn();
 
180
        }
 
181
        else
 
182
        {
 
183
            slotZoomOut();
 
184
        }
 
185
    }
 
186
    else
 
187
    {
 
188
        QGraphicsView::wheelEvent(e);
 
189
    }
 
190
}
 
191
 
 
192
void PreviewImage::mousePressEvent(QMouseEvent* e)
 
193
{
 
194
    if (e->button() == Qt::LeftButton)
 
195
    {
 
196
        d->lastdx = e->x();
 
197
        d->lastdy = e->y();
 
198
        setCursor(Qt::ClosedHandCursor);
 
199
    }
 
200
}
 
201
 
 
202
void PreviewImage::mouseReleaseEvent(QMouseEvent* e)
 
203
{
 
204
    if (e->button() == Qt::LeftButton)
 
205
        unsetCursor();
 
206
}
 
207
 
 
208
void PreviewImage::mouseMoveEvent(QMouseEvent* e)
 
209
{
 
210
    if (e->buttons() & Qt::LeftButton)
 
211
    {
 
212
        int dx    = e->x() - d->lastdx;
 
213
        int dy    = e->y() - d->lastdy;
 
214
        verticalScrollBar()->setValue(verticalScrollBar()->value() - dy);
 
215
        horizontalScrollBar()->setValue(horizontalScrollBar()->value() - dx);
 
216
        d->lastdx = e->x();
 
217
        d->lastdy = e->y();
 
218
    }
 
219
    else
 
220
    {
 
221
        if (verticalScrollBar()->isVisible() || horizontalScrollBar()->isVisible())
 
222
            setCursor(Qt::OpenHandCursor);
 
223
    }
 
224
}
 
225
 
 
226
void PreviewImage::enterEvent(QEvent*)
 
227
{
 
228
    d->toolBar->show();
 
229
}
 
230
 
 
231
void PreviewImage::leaveEvent(QEvent*)
 
232
{
 
233
    d->toolBar->hide();
 
234
}
 
235
 
 
236
bool PreviewImage::eventFilter(QObject *obj, QEvent *ev)
 
237
{
 
238
    if ( obj == d->toolBar )
 
239
    {
 
240
        if ( ev->type() == QEvent::Enter)
 
241
            setCursor(Qt::ArrowCursor);
 
242
        else if ( ev->type() == QEvent::Leave)
 
243
            unsetCursor();
 
244
 
 
245
        return false;
 
246
    }
 
247
    else if ( obj == verticalScrollBar() && verticalScrollBar()->isVisible())
 
248
    {
 
249
        if ( ev->type() == QEvent::Enter)
 
250
            setCursor(Qt::ArrowCursor);
 
251
        else if ( ev->type() == QEvent::Leave)
 
252
            unsetCursor();
 
253
 
 
254
        return false;
 
255
    }
 
256
    else if ( obj == horizontalScrollBar() && horizontalScrollBar()->isVisible())
 
257
    {
 
258
        if ( ev->type() == QEvent::Enter)
 
259
            setCursor(Qt::ArrowCursor);
 
260
        else if ( ev->type() == QEvent::Leave)
 
261
            unsetCursor();
 
262
 
 
263
        return false;
 
264
    }
 
265
 
 
266
    return QGraphicsView::eventFilter(obj, ev);
 
267
}
 
268
 
 
269
} // namespace KIPIPlugins