~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to core/utilities/imageeditor/editor/actioncategorizedview.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

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        : 2006-01-20
 
7
 * Description : action categorized view
 
8
 *
 
9
 * Copyright (C) 2006-2012 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 "actioncategorizedview.h"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <QString>
 
29
#include <QPropertyAnimation>
 
30
#include <QScrollBar>
 
31
#include <QSignalMapper>
 
32
 
 
33
// KDE includes
 
34
 
 
35
#include <kdebug.h>
 
36
#include <kdeversion.h>
 
37
#include <kcategorydrawer.h>
 
38
 
 
39
namespace Digikam
 
40
{
 
41
 
 
42
ActionCategorizedView::ActionCategorizedView(QWidget* const parent)
 
43
    : KCategorizedView(parent)
 
44
{
 
45
    m_horizontalScrollAnimation = new QPropertyAnimation(horizontalScrollBar(), "value", this);
 
46
    m_verticalScrollAnimation   = new QPropertyAnimation(verticalScrollBar(),   "value", this);
 
47
}
 
48
 
 
49
ActionCategorizedView::~ActionCategorizedView()
 
50
{
 
51
}
 
52
 
 
53
void ActionCategorizedView::setupIconMode()
 
54
{
 
55
    setViewMode(QListView::IconMode);
 
56
    setMovement(QListView::Static);
 
57
#if KDE_IS_VERSION(4,5,0)
 
58
    setCategoryDrawer(new KCategoryDrawerV3(this)); // deprecated, but needed for KDE 4.4 compatibility
 
59
#else
 
60
    setCategoryDrawer(new KCategoryDrawerV2);       // deprecated, but needed for KDE 4.4 compatibility
 
61
#endif
 
62
    setSelectionMode(QAbstractItemView::SingleSelection);
 
63
 
 
64
    setMouseTracking(true);
 
65
    viewport()->setAttribute(Qt::WA_Hover);
 
66
 
 
67
    setFrameShape(QFrame::NoFrame);
 
68
}
 
69
 
 
70
void ActionCategorizedView::adjustGridSize()
 
71
{
 
72
    // Find a suitable grid size. The delegate's size hint does never word-wrap.
 
73
    // To keep a suitable width, we want to word wrap.
 
74
    setWordWrap(true);
 
75
    int maxSize = viewOptions().decorationSize.width() * 4;
 
76
    QFontMetrics fm(viewOptions().font);
 
77
    QSize grid;
 
78
 
 
79
    for (int i = 0; i < model()->rowCount(); ++i)
 
80
    {
 
81
        const QModelIndex index = model()->index(i, 0);
 
82
        const QSize size        = sizeHintForIndex(index);
 
83
 
 
84
        if (size.width() > maxSize)
 
85
        {
 
86
            QString text        = index.data(Qt::DisplayRole).toString();
 
87
            QRect unwrappedRect = fm.boundingRect(QRect(0, 0, size.width(), size.height()), Qt::AlignLeft, text);
 
88
            QRect wrappedRect   = fm.boundingRect(QRect(0, 0, maxSize, maxSize), Qt::AlignLeft | Qt::TextWordWrap, text);
 
89
            grid                = grid.expandedTo(QSize(maxSize, size.height() + wrappedRect.height() - unwrappedRect.height()));
 
90
        }
 
91
        else
 
92
        {
 
93
            grid = grid.expandedTo(size);
 
94
        }
 
95
    }
 
96
 
 
97
    //grid += QSize(KDialog::spacingHint(), KDialog::spacingHint());
 
98
    setGridSize(grid);
 
99
}
 
100
 
 
101
int ActionCategorizedView::autoScrollDuration(float relativeDifference, QPropertyAnimation* animation)
 
102
{
 
103
    const int minimumTime       = 1000;
 
104
    const int maxPixelPerSecond = 1000;
 
105
 
 
106
    int pixelToScroll           = qAbs(animation->startValue().toInt() - animation->endValue().toInt());
 
107
    int factor                  = qMax(1.0f, relativeDifference * 100); // in [1;15]
 
108
 
 
109
    int duration                = 1000 * pixelToScroll / maxPixelPerSecond;
 
110
    duration                    *= factor;
 
111
 
 
112
    return qMax(minimumTime, duration);
 
113
}
 
114
 
 
115
void ActionCategorizedView::autoScroll(float relativePos, QScrollBar* scrollBar, QPropertyAnimation* animation)
 
116
{
 
117
 
 
118
    if (scrollBar->minimum() != scrollBar->maximum())
 
119
    {
 
120
        const float lowerPart = 0.15F;
 
121
        const float upperPart = 0.85F;
 
122
 
 
123
        if (relativePos > upperPart && scrollBar->value() !=  scrollBar->maximum())
 
124
        {
 
125
            animation->stop();
 
126
            animation->setStartValue(scrollBar->value());
 
127
            animation->setEndValue(scrollBar->maximum());
 
128
            animation->setDuration(autoScrollDuration(1 - relativePos, animation));
 
129
            animation->start();
 
130
        }
 
131
        else if (relativePos < lowerPart && scrollBar->value() !=  scrollBar->minimum())
 
132
        {
 
133
            animation->stop();
 
134
            animation->setStartValue(scrollBar->value());
 
135
            animation->setEndValue(scrollBar->minimum());
 
136
            animation->setDuration(autoScrollDuration(relativePos, animation));
 
137
            animation->start();
 
138
        }
 
139
        else
 
140
        {
 
141
            animation->stop();
 
142
        }
 
143
    }
 
144
}
 
145
 
 
146
void ActionCategorizedView::mouseMoveEvent(QMouseEvent* e)
 
147
{
 
148
    KCategorizedView::mouseMoveEvent(e);
 
149
    autoScroll(float(e->pos().x()) / viewport()->width(),  horizontalScrollBar(), m_horizontalScrollAnimation);
 
150
    autoScroll(float(e->pos().y()) / viewport()->height(), verticalScrollBar(),   m_verticalScrollAnimation);
 
151
}
 
152
 
 
153
void ActionCategorizedView::leaveEvent(QEvent* e)
 
154
{
 
155
    KCategorizedView::leaveEvent(e);
 
156
    m_horizontalScrollAnimation->stop();
 
157
    m_verticalScrollAnimation->stop();
 
158
}
 
159
 
 
160
}  // namespace Digikam