2
* $Id: menupreview.cpp,v 1.3 2003/02/18 22:14:45 mueller Exp $
4
* Menu Transparency Preview Widget
5
* Copyright (C) 2002 Karol Szwed <gallium@kde.org>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public
9
* License version 2 as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; see the file COPYING. If not, write to
18
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
22
#include "menupreview.h"
28
#include <kpixmapeffect.h>
30
#include <kimageeffect.h>
31
#include <kiconloader.h>
34
MenuPreview::MenuPreview( QWidget* parent, int opacity, PreviewMode pvm )
35
: QWidget( parent, 0, WStyle_Customize | WRepaintNoErase ),
36
pixBackground(NULL), pixOverlay(NULL), pixBlended(NULL)
38
setFixedSize(150, 150);
39
setFocusPolicy( NoFocus );
42
if (opacity < 0) opacity = 0;
43
if (opacity > 100) opacity = 100;
44
menuOpacity = opacity/100.0;
46
pixBackground = new KPixmap();
47
pixOverlay = new KPixmap();
48
pixBlended = new KPixmap();
54
MenuPreview::~MenuPreview()
61
void MenuPreview::createPixmaps()
67
pixBackground->resize( w, h );
69
pixOverlay->resize( w, h );
71
pixBlended->resize( w, h );
73
QColorGroup cg = colorGroup();
74
QColor c1 = cg.background();
80
p.begin(pixBackground);
81
for(int x=0; x < pixBackground->width(); x+=5)
82
for(int y=0; y < pixBackground->height(); y+=5)
83
p.fillRect( x, y, 5, 5,
85
((y % 2) ? c2 : c1 ) : // See the grid? ;-)
86
((y % 2) ? c1 : c2 ) );
87
KIconLoader* icl = KGlobal::iconLoader();
88
QPixmap pix = icl->loadIcon("go", KIcon::Desktop, KIcon::SizeLarge, KIcon::ActiveState);
89
p.drawPixmap( (width()-2-pix.width())/2, (height()-2-pix.height())/2, pix );
93
c1 = cg.button().light(110);
94
c2 = cg.button().dark(110);
95
KPixmapEffect::gradient( *pixOverlay, c1, c2, KPixmapEffect::VerticalGradient );
99
void MenuPreview::blendPixmaps()
101
// Rebuild pixmaps, and repaint
102
if (pixBlended && pixBackground)
104
if (mode == Blend && pixOverlay) {
105
QImage src = pixOverlay->convertToImage();
106
QImage dst = pixBackground->convertToImage();
107
KImageEffect::blend(src, dst, menuOpacity);
108
pixBlended->convertFromImage( dst );
109
} else if (mode == Tint) {
110
QColor clr = colorGroup().button();
111
QImage dst = pixBackground->convertToImage();
112
KImageEffect::blend(clr, dst, menuOpacity);
113
pixBlended->convertFromImage( dst );
118
void MenuPreview::setOpacity( int opacity )
120
if (opacity < 0 || opacity > 100)
123
if ((int)(menuOpacity*100) != opacity) {
124
menuOpacity = opacity/100.0;
130
void MenuPreview::setPreviewMode( PreviewMode pvm )
139
void MenuPreview::paintEvent( QPaintEvent* /* pe */ )
141
// Paint the frame and blended pixmap
142
QColorGroup cg = colorGroup();
148
p.drawLine(0, 0, x2, 0);
149
p.drawLine(0, 0, 0, y2);
150
p.setPen(cg.light());
151
p.drawLine(1, y2, x2, y2);
152
p.drawLine(x2, 1, x2, y2);
154
if (mode == NoEffect)
155
p.fillRect(1, 1, --x2, --y2, cg.button());
156
else if (mode != NoEffect && pixBlended)
157
p.drawPixmap(1, 1, *pixBlended, 0, 0, --x2, --y2);
161
p.setPen( cg.text() );
162
p.drawText( r, AlignTop | AlignLeft, QString::number((int)(menuOpacity*100))+i18n("%") );
165
#include "menupreview.moc"
167
// vim: set noet ts=4: