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

« back to all changes in this revision

Viewing changes to libs/widgets/common/dzoombar.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 digiKam project
4
 
 * http://www.digikam.org
5
 
 *
6
 
 * Date        : 2007-04-15
7
 
 * Description : a zoom bar used in status bar.
8
 
 *
9
 
 * Copyright (C) 2007-2010 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 "dzoombar.moc"
25
 
 
26
 
// C++ includes
27
 
 
28
 
#include <cmath>
29
 
 
30
 
// Qt includes
31
 
 
32
 
#include <QAction>
33
 
#include <QLayout>
34
 
#include <QSlider>
35
 
#include <QTimer>
36
 
#include <QToolButton>
37
 
#include <QList>
38
 
 
39
 
// KDE includes
40
 
 
41
 
#include <klocale.h>
42
 
#include <kvbox.h>
43
 
#include <kcombobox.h>
44
 
#include <kglobal.h>
45
 
#include <kdebug.h>
46
 
 
47
 
// Local includes
48
 
 
49
 
#include "dcursortracker.h"
50
 
#include "thumbnailsize.h"
51
 
 
52
 
namespace Digikam
53
 
{
54
 
 
55
 
class DZoomBarPriv
56
 
{
57
 
 
58
 
public:
59
 
 
60
 
    DZoomBarPriv()
61
 
    {
62
 
        zoomToFitButton = 0;
63
 
        zoomTo100Button = 0;
64
 
        zoomTracker     = 0;
65
 
        zoomMinusButton = 0;
66
 
        zoomPlusButton  = 0;
67
 
        zoomSlider      = 0;
68
 
        zoomTimer       = 0;
69
 
        zoomCombo       = 0;
70
 
    }
71
 
 
72
 
    QToolButton* zoomToFitButton;
73
 
    QToolButton* zoomTo100Button;
74
 
    QToolButton* zoomPlusButton;
75
 
    QToolButton* zoomMinusButton;
76
 
 
77
 
    QTimer*      zoomTimer;
78
 
 
79
 
    QSlider*     zoomSlider;
80
 
 
81
 
    KComboBox*   zoomCombo;
82
 
 
83
 
    DTipTracker* zoomTracker;
84
 
};
85
 
 
86
 
DZoomBar::DZoomBar(QWidget* parent)
87
 
    : KHBox(parent), d(new DZoomBarPriv)
88
 
{
89
 
    setAttribute(Qt::WA_DeleteOnClose);
90
 
    setFocusPolicy(Qt::NoFocus);
91
 
 
92
 
    d->zoomToFitButton = new QToolButton(this);
93
 
    d->zoomToFitButton->setAutoRaise(true);
94
 
    d->zoomToFitButton->setFocusPolicy(Qt::NoFocus);
95
 
 
96
 
    d->zoomTo100Button = new QToolButton(this);
97
 
    d->zoomTo100Button->setAutoRaise(true);
98
 
    d->zoomTo100Button->setFocusPolicy(Qt::NoFocus);
99
 
 
100
 
    d->zoomMinusButton = new QToolButton(this);
101
 
    d->zoomMinusButton->setAutoRaise(true);
102
 
    d->zoomMinusButton->setFocusPolicy(Qt::NoFocus);
103
 
 
104
 
    d->zoomSlider  = new QSlider(Qt::Horizontal, this);
105
 
    d->zoomTracker = new DTipTracker(QString(""), d->zoomSlider);
106
 
    d->zoomSlider->setRange(ThumbnailSize::Small, ThumbnailSize::Huge);
107
 
    d->zoomSlider->setSingleStep(ThumbnailSize::Step);
108
 
    d->zoomSlider->setValue(ThumbnailSize::Medium);
109
 
    d->zoomSlider->setFixedWidth(120);
110
 
    d->zoomSlider->setFocusPolicy(Qt::NoFocus);
111
 
    d->zoomSlider->setInvertedControls(true);       // See B.K.O #161087
112
 
 
113
 
    d->zoomPlusButton = new QToolButton(this);
114
 
    d->zoomPlusButton->setAutoRaise(true);
115
 
    d->zoomPlusButton->setFocusPolicy(Qt::NoFocus);
116
 
 
117
 
    d->zoomCombo = new KComboBox(true, this);
118
 
    d->zoomCombo->setDuplicatesEnabled(false);
119
 
    d->zoomCombo->setFocusPolicy(Qt::ClickFocus);
120
 
    d->zoomCombo->setInsertPolicy(QComboBox::NoInsert);
121
 
 
122
 
    QList<double> zoomLevels;
123
 
    zoomLevels << 10.0;
124
 
    zoomLevels << 25.0;
125
 
    zoomLevels << 50.0;
126
 
    zoomLevels << 75.0;
127
 
    zoomLevels << 100.0;
128
 
    zoomLevels << 150.0;
129
 
    zoomLevels << 200.0;
130
 
    zoomLevels << 300.0;
131
 
    zoomLevels << 450.0;
132
 
    zoomLevels << 600.0;
133
 
    zoomLevels << 800.0;
134
 
    zoomLevels << 1200.0;
135
 
 
136
 
    foreach (const double zoom, zoomLevels)
137
 
    {
138
 
        d->zoomCombo->addItem(QString("%1%").arg((int)zoom), QVariant(zoom));
139
 
    }
140
 
 
141
 
    layout()->setMargin(0);
142
 
    layout()->setSpacing(0);
143
 
 
144
 
    // -------------------------------------------------------------
145
 
 
146
 
    connect(d->zoomSlider, SIGNAL(valueChanged(int)),
147
 
            this, SIGNAL(signalZoomSliderChanged(int)));
148
 
 
149
 
    connect(d->zoomSlider, SIGNAL(valueChanged(int)),
150
 
            this, SLOT(slotZoomSliderChanged(int)));
151
 
 
152
 
    connect(d->zoomSlider, SIGNAL(sliderReleased()),
153
 
            this, SLOT(slotZoomSliderReleased()));
154
 
 
155
 
    connect(d->zoomCombo, SIGNAL(activated(int)),
156
 
            this, SLOT(slotZoomSelected(int)));
157
 
 
158
 
    connect(d->zoomCombo, SIGNAL(returnPressed(const QString&)),
159
 
            this, SLOT(slotZoomTextChanged(const QString&)));
160
 
 
161
 
    // -------------------------------------------------------------
162
 
 
163
 
    setBarMode(PreviewZoomCtrl);
164
 
}
165
 
 
166
 
DZoomBar::~DZoomBar()
167
 
{
168
 
    delete d->zoomTimer;
169
 
    delete d;
170
 
}
171
 
 
172
 
void DZoomBar::setZoomToFitAction(QAction* action)
173
 
{
174
 
    d->zoomToFitButton->setDefaultAction(action);
175
 
}
176
 
 
177
 
void DZoomBar::setZoomTo100Action(QAction* action)
178
 
{
179
 
    d->zoomTo100Button->setDefaultAction(action);
180
 
}
181
 
 
182
 
void DZoomBar::setZoomPlusAction(QAction* action)
183
 
{
184
 
    d->zoomPlusButton->setDefaultAction(action);
185
 
}
186
 
 
187
 
void DZoomBar::setZoomMinusAction(QAction* action)
188
 
{
189
 
    d->zoomMinusButton->setDefaultAction(action);
190
 
}
191
 
 
192
 
void DZoomBar::slotZoomSliderChanged(int)
193
 
{
194
 
    if (d->zoomTimer)
195
 
    {
196
 
        d->zoomTimer->stop();
197
 
        delete d->zoomTimer;
198
 
    }
199
 
 
200
 
    d->zoomTimer = new QTimer( this );
201
 
    connect(d->zoomTimer, SIGNAL(timeout()),
202
 
            this, SLOT(slotDelayedZoomSliderChanged()) );
203
 
    d->zoomTimer->setSingleShot(true);
204
 
    d->zoomTimer->start(300);
205
 
}
206
 
 
207
 
void DZoomBar::slotDelayedZoomSliderChanged()
208
 
{
209
 
    emit signalDelayedZoomSliderChanged(d->zoomSlider->value());
210
 
}
211
 
 
212
 
void DZoomBar::slotZoomSliderReleased()
213
 
{
214
 
    emit signalZoomSliderReleased(d->zoomSlider->value());
215
 
}
216
 
 
217
 
void DZoomBar::setZoom(double zoom, double zmin, double zmax)
218
 
{
219
 
    int size = sizeFromZoom(zoom, zmin, zmax);
220
 
 
221
 
    d->zoomSlider->blockSignals(true);
222
 
    d->zoomSlider->setValue(size);
223
 
    d->zoomSlider->blockSignals(false);
224
 
 
225
 
    QString ztxt = QString::number(lround(zoom*100.0)) + QString("%");
226
 
    d->zoomCombo->blockSignals(true);
227
 
    d->zoomCombo->setCurrentIndex(-1);
228
 
    d->zoomCombo->setEditText(ztxt);
229
 
    d->zoomCombo->blockSignals(false);
230
 
}
231
 
 
232
 
void DZoomBar::setThumbsSize(int size)
233
 
{
234
 
    d->zoomSlider->blockSignals(true);
235
 
    d->zoomSlider->setValue(size);
236
 
    d->zoomSlider->blockSignals(false);
237
 
 
238
 
    d->zoomTracker->setText(i18n("Size: %1", size));
239
 
    triggerZoomTrackerToolTip();
240
 
}
241
 
 
242
 
int DZoomBar::sizeFromZoom(double zoom, double zmin, double zmax)
243
 
{
244
 
    double h = (double)ThumbnailSize::Huge;
245
 
    double s = (double)ThumbnailSize::Small;
246
 
    double zoomN = log(zoom)/log(2);
247
 
    double zminN = log(zmin)/log(2);
248
 
    double zmaxN = log(zmax)/log(2);
249
 
    double zval = (zoomN-zminN)/(zmaxN-zminN);
250
 
    return (int)(zval*(h - s) + s);
251
 
}
252
 
 
253
 
double DZoomBar::zoomFromSize(int size, double zmin, double zmax)
254
 
{
255
 
    double h = (double)ThumbnailSize::Huge;
256
 
    double s = (double)ThumbnailSize::Small;
257
 
    double zminN = log(zmin)/log(2);
258
 
    double zmaxN = log(zmax)/log(2);
259
 
    double zval = (size - s)/(h - s);
260
 
    return pow(2, zval*(zmaxN-zminN) + zminN);
261
 
}
262
 
 
263
 
void DZoomBar::triggerZoomTrackerToolTip()
264
 
{
265
 
    d->zoomTracker->triggerAutoShow();
266
 
}
267
 
 
268
 
void DZoomBar::slotUpdateTrackerPos()
269
 
{
270
 
    d->zoomTracker->refresh();
271
 
}
272
 
 
273
 
void DZoomBar::slotZoomSelected(int index)
274
 
{
275
 
    bool ok     = false;
276
 
    double zoom = d->zoomCombo->itemData(index).toDouble(&ok) / 100.0;
277
 
 
278
 
    if (ok && zoom > 0.0)
279
 
    {
280
 
        emit signalZoomValueEdited(zoom);
281
 
    }
282
 
}
283
 
 
284
 
void DZoomBar::slotZoomTextChanged(const QString& txt)
285
 
{
286
 
    bool ok     = false;
287
 
    double zoom = KGlobal::locale()->readNumber(txt, &ok) / 100.0;
288
 
 
289
 
    if (ok && zoom > 0.0)
290
 
    {
291
 
        emit signalZoomValueEdited(zoom);
292
 
    }
293
 
}
294
 
 
295
 
void DZoomBar::setBarMode(BarMode mode)
296
 
{
297
 
    QAction* zfitAction = d->zoomToFitButton->defaultAction();
298
 
    QAction* z100Action = d->zoomTo100Button->defaultAction();
299
 
 
300
 
    switch (mode)
301
 
    {
302
 
        case PreviewZoomCtrl:
303
 
        {
304
 
            d->zoomToFitButton->show();
305
 
 
306
 
            if (zfitAction)
307
 
            {
308
 
                zfitAction->setEnabled(true);
309
 
            }
310
 
 
311
 
            d->zoomTo100Button->show();
312
 
 
313
 
            if (z100Action)
314
 
            {
315
 
                z100Action->setEnabled(true);
316
 
            }
317
 
 
318
 
            d->zoomCombo->show();
319
 
            d->zoomCombo->setEnabled(true);
320
 
            d->zoomTracker->setEnable(false);
321
 
            break;
322
 
        }
323
 
        case ThumbsSizeCtrl:
324
 
        {
325
 
            d->zoomToFitButton->show();
326
 
 
327
 
            if (zfitAction)
328
 
            {
329
 
                zfitAction->setEnabled(false);
330
 
            }
331
 
 
332
 
            d->zoomTo100Button->show();
333
 
 
334
 
            if (z100Action)
335
 
            {
336
 
                z100Action->setEnabled(false);
337
 
            }
338
 
 
339
 
            d->zoomCombo->show();
340
 
            d->zoomCombo->setEnabled(false);
341
 
            d->zoomTracker->setEnable(true);
342
 
            break;
343
 
        }
344
 
        default:   // NoPreviewZoomCtrl
345
 
        {
346
 
            d->zoomToFitButton->hide();
347
 
            d->zoomTo100Button->hide();
348
 
            d->zoomCombo->hide();
349
 
            d->zoomTracker->setEnable(true);
350
 
            break;
351
 
        }
352
 
    }
353
 
}
354
 
 
355
 
}  // namespace Digikam