~ubuntu-branches/ubuntu/jaunty/digikam/jaunty

« back to all changes in this revision

Viewing changes to libs/widgets/common/dpopupmenu.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2009-01-21 21:55:15 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090121215515-lry0s2pdep289o3u
Tags: 2:0.10.0~rc1-0ubuntu1
* New upstream release (release candididate 1)
* rules:
  - Simplify by including standard class/kde4.mk
* control:
  - Build-Depends on quilt (default patch system of kde4.mk)
  - Bump Standards-Version to 3.8.0
  - Bump debhelper dependancy to 7
  - Add ${misc:Depends} to make lintian happy
* {digikam|showfoto}.install:
  - Update icon paths
  - Do not package oxygen and apps icons: provided by kde-icons-oxygen
* patches/01-kubuntu-fix-armel.patch:
  - Fix cut&paste bug in the patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 *
10
10
 * Copyright (C) 1996-2000 the kicker authors.
11
11
 * Copyright (C) 2005 Mark Kretschmann <markey@web.de>
12
 
 * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
12
 * Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
13
13
 *
14
14
 * This program is free software; you can redistribute it
15
15
 * and/or modify it under the terms of the GNU General
28
28
 
29
29
// Qt includes.
30
30
 
 
31
#include <QFont>
 
32
#include <QFontMetrics>
31
33
#include <QPaintEvent>
32
34
#include <QPainter>
33
35
#include <QPixmap>
41
43
#include <kapplication.h>
42
44
#include <kcomponentdata.h>
43
45
#include <kglobal.h>
 
46
#include <kglobalsettings.h>
44
47
#include <kiconeffect.h>
45
48
#include <kstandarddirs.h>
 
49
#include <kiconloader.h>
 
50
#include <kdebug.h>
 
51
 
 
52
// Local includes.
 
53
 
 
54
#include "version.h"
46
55
 
47
56
namespace Digikam
48
57
{
49
58
 
50
 
static QImage s_dpopupmenu_sidePixmap;
51
 
static QColor s_dpopupmenu_sidePixmapColor;
 
59
class DPopupMenuPriv
 
60
{
 
61
public:
 
62
 
 
63
    DPopupMenuPriv(){};
 
64
 
 
65
    int     gradientWidth;
 
66
 
 
67
    QFont   fontAppName;
 
68
    QFont   fontVersion;
 
69
};
52
70
 
53
71
DPopupMenu::DPopupMenu(QWidget* parent)
54
 
          : KMenu(parent)
 
72
          : KMenu(parent), d(new DPopupMenuPriv)
55
73
{
56
 
    // Must be initialized so that we know the size on first invocation
57
 
    if (s_dpopupmenu_sidePixmap.isNull())
58
 
        generateSidePixmap();
59
 
 
60
 
    setContentsMargins(sidePixmapWidth(), 0, 0, 0);
 
74
    d->fontAppName = KGlobalSettings::generalFont();
 
75
    d->fontVersion = KGlobalSettings::generalFont();
 
76
 
 
77
    d->fontAppName.setBold(true);
 
78
    d->fontAppName.setPixelSize(13);
 
79
    d->fontVersion.setBold(false);
 
80
    d->fontVersion.setPixelSize(11);
 
81
 
 
82
    // has to be an odd number to get the text centered
 
83
    d->gradientWidth = d->fontAppName.pixelSize() + 2;
 
84
 
 
85
    setContentsMargins(d->gradientWidth, 0, 0, 0);
61
86
}
62
87
 
63
88
DPopupMenu::~DPopupMenu()
64
89
{
65
 
}
66
 
 
67
 
int DPopupMenu::sidePixmapWidth() const
68
 
{
69
 
    return s_dpopupmenu_sidePixmap.width();
70
 
}
71
 
 
72
 
void DPopupMenu::generateSidePixmap()
73
 
{
74
 
    const QColor newColor = calcPixmapColor();
75
 
 
76
 
    if (newColor != s_dpopupmenu_sidePixmapColor)
77
 
    {
78
 
        s_dpopupmenu_sidePixmapColor = newColor;
79
 
 
80
 
        if (KGlobal::mainComponent().aboutData()->appName() == QString("digikam"))
81
 
            s_dpopupmenu_sidePixmap.load(KStandardDirs::locate("data","digikam/data/menusidepix-digikam.png"));
82
 
        else
83
 
            s_dpopupmenu_sidePixmap.load(KStandardDirs::locate("data","showfoto/data/menusidepix-showfoto.png"));
84
 
 
85
 
        KIconEffect::colorize(s_dpopupmenu_sidePixmap, newColor, 1.0);
86
 
    }
87
 
}
88
 
 
89
 
QRect DPopupMenu::sideImageRect() const
90
 
{
 
90
    delete d;
 
91
}
 
92
 
 
93
void DPopupMenu::renderSidebarGradient(QPainter *p)
 
94
{
 
95
    p->setRenderHint(QPainter::QPainter::TextAntialiasing);
 
96
    p->setPen(Qt::white);
 
97
 
91
98
    int frameWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this);
92
 
    return QStyle::visualRect(layoutDirection(), rect(),
93
 
                              QRect(frameWidth, frameWidth,
94
 
                                    s_dpopupmenu_sidePixmap.width(),
95
 
                                    height() - 2*frameWidth));
 
99
    QRect drawRect = QStyle::visualRect(layoutDirection(), rect(),
 
100
                                        QRect(frameWidth, frameWidth,
 
101
                                              d->gradientWidth, height() - 2*frameWidth));
 
102
    p->setClipRect(drawRect);
 
103
 
 
104
    // ----------------------------------------
 
105
 
 
106
    // draw gradient
 
107
    QLinearGradient linearGrad;
 
108
    linearGrad.setCoordinateMode(QGradient::ObjectBoundingMode);
 
109
    linearGrad.setStart(0.0, 0.0);
 
110
    linearGrad.setFinalStop(0.0, 1.0);
 
111
    linearGrad.setColorAt(0, QColor(255, 255, 255, 25));
 
112
    linearGrad.setColorAt(1, QColor(98, 98, 98));
 
113
 
 
114
    // FIXME: this doesn't seem to work in 0.10.x versions, so I disable it for now
 
115
//    linearGrad.setColorAt(1, calcPixmapColor());
 
116
 
 
117
    p->fillRect(drawRect, QBrush(linearGrad));
 
118
 
 
119
    // ----------------------------------------
 
120
 
 
121
    p->resetTransform();
 
122
    p->translate(drawRect.bottomLeft());
 
123
    p->rotate(-90.0);
 
124
 
 
125
    // ----------------------------------------
 
126
 
 
127
    const int    spacing = 8;
 
128
    const int    margin  = 4;
 
129
    QPixmap      appIcon;
 
130
    QString      appName;
 
131
    QFontMetrics fontMt(d->fontAppName);
 
132
    QFontMetrics fontMt2(d->fontVersion);
 
133
 
 
134
    if (KGlobal::mainComponent().aboutData()->appName() == QString("digikam"))
 
135
    {
 
136
        appIcon = SmallIcon("digikam", d->fontAppName.pixelSize());
 
137
        appName = QString("digiKam");
 
138
    }
 
139
    else
 
140
    {
 
141
        appIcon = SmallIcon("showfoto", d->fontAppName.pixelSize());
 
142
        appName = QString("showFoto");
 
143
    }
 
144
 
 
145
    QRect fontRect = QRect(appIcon.width() + spacing, 1, fontMt.width(appName), drawRect.width());
 
146
    int   shift    = fontMt.ascent() - fontMt2.ascent();
 
147
 
 
148
    // ----------------------------------------
 
149
    // draw application icon.
 
150
 
 
151
    p->drawPixmap(margin, 1, appIcon);
 
152
 
 
153
    // ----------------------------------------
 
154
    // draw app name.
 
155
 
 
156
    p->setFont(d->fontAppName);
 
157
    p->drawText(fontRect, Qt::AlignLeft|Qt::AlignVCenter, appName);
 
158
 
 
159
    // ----------------------------------------
 
160
    // draw version string.
 
161
 
 
162
    fontRect.moveLeft(fontRect.right() + spacing);
 
163
    fontRect.setY(shift);
 
164
    p->setFont(d->fontVersion);
 
165
    p->drawText(fontRect, Qt::AlignLeft|Qt::AlignVCenter, QString(digikam_version_short));
96
166
}
97
167
 
98
168
QColor DPopupMenu::calcPixmapColor()
134
204
    return color;
135
205
}
136
206
 
137
 
void DPopupMenu::setMinimumSize(const QSize & s)
 
207
void DPopupMenu::setMinimumSize(const QSize& s)
138
208
{
139
 
    KMenu::setMinimumSize(s.width() + s_dpopupmenu_sidePixmap.width(), s.height());
 
209
    KMenu::setMinimumSize(s.width() + d->gradientWidth, s.height());
140
210
}
141
211
 
142
 
void DPopupMenu::setMaximumSize(const QSize & s)
 
212
void DPopupMenu::setMaximumSize(const QSize& s)
143
213
{
144
 
    KMenu::setMaximumSize(s.width() + s_dpopupmenu_sidePixmap.width(), s.height());
 
214
    KMenu::setMaximumSize(s.width() + d->gradientWidth, s.height());
145
215
}
146
216
 
147
217
void DPopupMenu::setMinimumSize(int w, int h)
148
218
{
149
 
    KMenu::setMinimumSize(w + s_dpopupmenu_sidePixmap.width(), h);
 
219
    KMenu::setMinimumSize(w + d->gradientWidth, h);
150
220
}
151
221
 
152
222
void DPopupMenu::setMaximumSize(int w, int h)
153
223
{
154
 
    KMenu::setMaximumSize(w + s_dpopupmenu_sidePixmap.width(), h);
 
224
    KMenu::setMaximumSize(w + d->gradientWidth, h);
155
225
}
156
226
 
157
227
void DPopupMenu::paintEvent(QPaintEvent* e)
160
230
 
161
231
    {
162
232
        // scope for QPainter object
163
 
 
164
 
        generateSidePixmap();
165
 
 
166
233
        QPainter p(this);
167
 
        p.setClipRegion(e->region());
168
234
 
169
235
        QStyleOptionFrame frOpt;
170
236
        frOpt.init(this);
172
238
        frOpt.midLineWidth = 0;
173
239
        style()->drawPrimitive(QStyle::PE_FrameMenu, &frOpt, &p, this);
174
240
 
175
 
        QRect r = sideImageRect();
176
 
        r.setTop(r.bottom()-s_dpopupmenu_sidePixmap.height()+1);
177
 
        if (r.intersects( e->rect()))
178
 
        {
179
 
            QRect drawRect = r.intersect(e->rect()).intersect( sideImageRect());
180
 
            QRect pixRect  = drawRect;
181
 
            pixRect.translate(-r.left(), -r.top());
182
 
            p.drawImage(drawRect.topLeft(), s_dpopupmenu_sidePixmap, pixRect);
183
 
        }
 
241
        renderSidebarGradient(&p);
184
242
    }
185
243
}
186
244