~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.2.15 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080717202539-6n7dtirbkoo7qvhd
Tags: 2:0.9.4-1
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

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-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
12
 * Copyright (C) 2006-2008 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
33
33
// KDE includes.
34
34
 
35
35
#include <kapplication.h>
36
 
#include <kconfig.h>
37
36
#include <kiconeffect.h>
38
37
#include <kapplication.h>
39
38
#include <kstandarddirs.h>
42
41
// Local includes.
43
42
 
44
43
#include "dpopupmenu.h"
45
 
#include "dpopupmenu.moc"
46
44
 
47
45
namespace Digikam
48
46
{
49
47
 
50
 
QImage DPopupMenu::_dpopupmenu_sidePixmap_;
51
 
QColor DPopupMenu::_dpopupmenu_sidePixmapColor_;
 
48
static QImage s_dpopupmenu_sidePixmap;
 
49
static QColor s_dpopupmenu_sidePixmapColor;
52
50
 
53
 
DPopupMenu::DPopupMenu( QWidget* parent, const char* name )
54
 
          : KPopupMenu( parent, name )
 
51
DPopupMenu::DPopupMenu(QWidget* parent, const char* name)
 
52
          : KPopupMenu(parent, name)
55
53
{
56
54
    // Must be initialized so that we know the size on first invocation
57
 
    if ( _dpopupmenu_sidePixmap_.isNull() )
 
55
    if ( s_dpopupmenu_sidePixmap.isNull() )
58
56
        generateSidePixmap();
59
57
}
60
58
 
 
59
DPopupMenu::~DPopupMenu()
 
60
{
 
61
}
 
62
 
61
63
void DPopupMenu::generateSidePixmap()
62
64
{
63
65
    const QColor newColor = calcPixmapColor();
64
66
 
65
 
    if ( newColor != _dpopupmenu_sidePixmapColor_ ) 
 
67
    if ( newColor != s_dpopupmenu_sidePixmapColor ) 
66
68
    {
67
 
        _dpopupmenu_sidePixmapColor_ = newColor;
 
69
        s_dpopupmenu_sidePixmapColor = newColor;
68
70
 
69
71
        if (KApplication::kApplication()->aboutData()->appName() == QString("digikam"))
70
 
            _dpopupmenu_sidePixmap_.load( locate( "data","digikam/data/menusidepixmap.png" ) );
 
72
            s_dpopupmenu_sidePixmap.load( locate( "data","digikam/data/menusidepixmap.png" ) );
71
73
        else
72
 
            _dpopupmenu_sidePixmap_.load( locate( "data","showfoto/menusidepixmap.png" ) );
73
 
    
74
 
        KIconEffect::colorize( _dpopupmenu_sidePixmap_, newColor, 1.0 );
 
74
            s_dpopupmenu_sidePixmap.load( locate( "data","showfoto/menusidepixmap.png" ) );
 
75
 
 
76
        KIconEffect::colorize(s_dpopupmenu_sidePixmap, newColor, 1.0);
75
77
    }
76
78
}
77
79
 
 
80
int DPopupMenu::sidePixmapWidth() const
 
81
{
 
82
    return s_dpopupmenu_sidePixmap.width();
 
83
}
 
84
 
78
85
QRect DPopupMenu::sideImageRect() const
79
86
{
80
 
    return QStyle::visualRect( QRect( frameWidth(), frameWidth(), 
81
 
                                      _dpopupmenu_sidePixmap_.width(),
82
 
                                      height() - 2*frameWidth() ), this );
 
87
    return QStyle::visualRect(QRect(frameWidth(), frameWidth(),
 
88
                                    s_dpopupmenu_sidePixmap.width(),
 
89
                                    height() - 2*frameWidth()),
 
90
                              this);
83
91
}
84
92
 
85
93
QColor DPopupMenu::calcPixmapColor()
86
94
{
87
 
    KConfig *config = KGlobal::config();
88
 
    config->setGroup("WM");
89
 
    QColor color = QApplication::palette().active().highlight();
90
 
//     QColor activeTitle = QApplication::palette().active().background();
91
 
//     QColor inactiveTitle = QApplication::palette().inactive().background();
92
 
    QColor activeTitle = config->readColorEntry("activeBackground", &color);
93
 
    QColor inactiveTitle = config->readColorEntry("inactiveBackground", &color);
 
95
    QColor color;
 
96
    QColor activeTitle   = QApplication::palette().active().background();
 
97
    QColor inactiveTitle = QApplication::palette().inactive().background();
94
98
 
95
99
    // figure out which color is most suitable for recoloring to
96
100
    int h1, s1, v1, h2, s2, v2, h3, s3, v3;
127
131
 
128
132
void DPopupMenu::setMinimumSize(const QSize & s)
129
133
{
130
 
    KPopupMenu::setMinimumSize(s.width() + _dpopupmenu_sidePixmap_.width(), s.height());
 
134
    KPopupMenu::setMinimumSize(s.width() + s_dpopupmenu_sidePixmap.width(), s.height());
131
135
}
132
136
 
133
137
void DPopupMenu::setMaximumSize(const QSize & s)
134
138
{
135
 
    KPopupMenu::setMaximumSize(s.width() + _dpopupmenu_sidePixmap_.width(), s.height());
 
139
    KPopupMenu::setMaximumSize(s.width() + s_dpopupmenu_sidePixmap.width(), s.height());
136
140
}
137
141
 
138
142
void DPopupMenu::setMinimumSize(int w, int h)
139
143
{
140
 
    KPopupMenu::setMinimumSize(w + _dpopupmenu_sidePixmap_.width(), h);
 
144
    KPopupMenu::setMinimumSize(w + s_dpopupmenu_sidePixmap.width(), h);
141
145
}
142
146
 
143
147
void DPopupMenu::setMaximumSize(int w, int h)
144
148
{
145
 
  KPopupMenu::setMaximumSize(w + _dpopupmenu_sidePixmap_.width(), h);
 
149
  KPopupMenu::setMaximumSize(w + s_dpopupmenu_sidePixmap.width(), h);
146
150
}
147
151
 
148
152
void DPopupMenu::resizeEvent(QResizeEvent * e)
149
153
{
150
 
    KPopupMenu::resizeEvent( e );
 
154
    KPopupMenu::resizeEvent(e);
151
155
 
152
 
    setFrameRect( QStyle::visualRect( QRect( _dpopupmenu_sidePixmap_.width(), 0,
153
 
                                      width() - _dpopupmenu_sidePixmap_.width(), 
154
 
                                      height() ), this ) );
 
156
    setFrameRect(QStyle::visualRect(QRect(s_dpopupmenu_sidePixmap.width(), 0,
 
157
                                          width() - s_dpopupmenu_sidePixmap.width(), height()), 
 
158
                 this ) );
155
159
}
156
160
 
157
161
//Workaround Qt3.3.x sizing bug, by ensuring we're always wide enough.
158
 
void DPopupMenu::resize( int width, int height )
 
162
void DPopupMenu::resize(int width, int height)
159
163
{
160
164
    width = kMax(width, maximumSize().width());
161
165
    KPopupMenu::resize(width, height);
162
166
}
163
167
 
164
 
void DPopupMenu::paintEvent( QPaintEvent* e )
 
168
void DPopupMenu::paintEvent(QPaintEvent* e)
165
169
{
166
170
    generateSidePixmap();
167
171
 
168
172
    QPainter p( this );
169
173
 
170
174
    QRect r = sideImageRect();
171
 
    r.setTop( r.bottom() - _dpopupmenu_sidePixmap_.height() );
 
175
    r.setTop(r.bottom()-s_dpopupmenu_sidePixmap.height()+1);
172
176
    if ( r.intersects( e->rect() ) )
173
177
    {
174
 
        QRect drawRect = r.intersect( e->rect() ).intersect( sideImageRect() );
175
 
        QRect pixRect = drawRect;
176
 
        pixRect.moveBy( -r.left(), -r.top() );
177
 
        p.drawImage( drawRect.topLeft(), _dpopupmenu_sidePixmap_, pixRect );
 
178
        QRect drawRect = r.intersect(e->rect()).intersect(sideImageRect());
 
179
        QRect pixRect  = drawRect;
 
180
        pixRect.moveBy(-r.left(), -r.top());
 
181
        p.drawImage(drawRect.topLeft(), s_dpopupmenu_sidePixmap, pixRect);
178
182
    }
179
183
 
180
 
    p.setClipRegion( e->region() );
181
 
 
182
 
    //NOTE The order is important here. drawContents() must be called before drawPrimitive(),
183
 
    //     otherwise we get rendering glitches.
184
 
 
185
 
    drawContents( &p );
186
 
 
187
 
    style().drawPrimitive( QStyle::PE_PanelPopup, &p,
188
 
                           QRect( 0, 0, width(), height() ),
189
 
                           colorGroup(), QStyle::Style_Default,
190
 
                           QStyleOption( frameWidth(), 0 ) );
 
184
    p.setClipRegion(e->region());
 
185
 
 
186
    //NOTE: The order is important here. drawContents() must be called before drawPrimitive(),
 
187
    //      otherwise we get rendering glitches.
 
188
 
 
189
    drawContents(&p);
 
190
 
 
191
    style().drawPrimitive(QStyle::PE_PanelPopup, &p,
 
192
                          QRect(0, 0, width(), height()),
 
193
                          colorGroup(), QStyle::Style_Default,
 
194
                          QStyleOption( frameWidth(), 0));
191
195
}
192
196
 
193
197
}  // namespace Digikam
194