44
43
#include "dpopupmenu.h"
45
#include "dpopupmenu.moc"
50
QImage DPopupMenu::_dpopupmenu_sidePixmap_;
51
QColor DPopupMenu::_dpopupmenu_sidePixmapColor_;
48
static QImage s_dpopupmenu_sidePixmap;
49
static QColor s_dpopupmenu_sidePixmapColor;
53
DPopupMenu::DPopupMenu( QWidget* parent, const char* name )
54
: KPopupMenu( parent, name )
51
DPopupMenu::DPopupMenu(QWidget* parent, const char* name)
52
: KPopupMenu(parent, name)
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
DPopupMenu::~DPopupMenu()
61
63
void DPopupMenu::generateSidePixmap()
63
65
const QColor newColor = calcPixmapColor();
65
if ( newColor != _dpopupmenu_sidePixmapColor_ )
67
if ( newColor != s_dpopupmenu_sidePixmapColor )
67
_dpopupmenu_sidePixmapColor_ = newColor;
69
s_dpopupmenu_sidePixmapColor = newColor;
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" ) );
72
_dpopupmenu_sidePixmap_.load( locate( "data","showfoto/menusidepixmap.png" ) );
74
KIconEffect::colorize( _dpopupmenu_sidePixmap_, newColor, 1.0 );
74
s_dpopupmenu_sidePixmap.load( locate( "data","showfoto/menusidepixmap.png" ) );
76
KIconEffect::colorize(s_dpopupmenu_sidePixmap, newColor, 1.0);
80
int DPopupMenu::sidePixmapWidth() const
82
return s_dpopupmenu_sidePixmap.width();
78
85
QRect DPopupMenu::sideImageRect() const
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()),
85
93
QColor DPopupMenu::calcPixmapColor()
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);
96
QColor activeTitle = QApplication::palette().active().background();
97
QColor inactiveTitle = QApplication::palette().inactive().background();
95
99
// figure out which color is most suitable for recoloring to
96
100
int h1, s1, v1, h2, s2, v2, h3, s3, v3;
128
132
void DPopupMenu::setMinimumSize(const QSize & s)
130
KPopupMenu::setMinimumSize(s.width() + _dpopupmenu_sidePixmap_.width(), s.height());
134
KPopupMenu::setMinimumSize(s.width() + s_dpopupmenu_sidePixmap.width(), s.height());
133
137
void DPopupMenu::setMaximumSize(const QSize & s)
135
KPopupMenu::setMaximumSize(s.width() + _dpopupmenu_sidePixmap_.width(), s.height());
139
KPopupMenu::setMaximumSize(s.width() + s_dpopupmenu_sidePixmap.width(), s.height());
138
142
void DPopupMenu::setMinimumSize(int w, int h)
140
KPopupMenu::setMinimumSize(w + _dpopupmenu_sidePixmap_.width(), h);
144
KPopupMenu::setMinimumSize(w + s_dpopupmenu_sidePixmap.width(), h);
143
147
void DPopupMenu::setMaximumSize(int w, int h)
145
KPopupMenu::setMaximumSize(w + _dpopupmenu_sidePixmap_.width(), h);
149
KPopupMenu::setMaximumSize(w + s_dpopupmenu_sidePixmap.width(), h);
148
152
void DPopupMenu::resizeEvent(QResizeEvent * e)
150
KPopupMenu::resizeEvent( e );
154
KPopupMenu::resizeEvent(e);
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()),
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)
160
164
width = kMax(width, maximumSize().width());
161
165
KPopupMenu::resize(width, height);
164
void DPopupMenu::paintEvent( QPaintEvent* e )
168
void DPopupMenu::paintEvent(QPaintEvent* e)
166
170
generateSidePixmap();
168
172
QPainter p( this );
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() ) )
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);
180
p.setClipRegion( e->region() );
182
//NOTE The order is important here. drawContents() must be called before drawPrimitive(),
183
// otherwise we get rendering glitches.
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());
186
//NOTE: The order is important here. drawContents() must be called before drawPrimitive(),
187
// otherwise we get rendering glitches.
191
style().drawPrimitive(QStyle::PE_PanelPopup, &p,
192
QRect(0, 0, width(), height()),
193
colorGroup(), QStyle::Style_Default,
194
QStyleOption( frameWidth(), 0));
193
197
} // namespace Digikam