add more spacing
[personal-kdebase.git] / workspace / kwin / clients / web / WebButton.cpp
blobd8365a0803141ceee0b448b2c20e867048102f50
1 /*
2 'Web' kwin client
4 Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
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., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "WebButton.h"
23 #include <QPainter>
24 //Added by qt3to4:
25 #include <QEvent>
27 #include "Web.h"
29 namespace Web {
31 static unsigned char close_bits[] = {
32 0x42, 0xe7, 0x7e, 0x3c, 0x3c, 0x7e, 0xe7, 0x42
34 static unsigned char iconify_bits[] = {
35 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x3c, 0x18, 0x00
37 static unsigned char maximize_bits[] = {
38 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00
40 static unsigned char unmaximize_bits[] = {
41 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f
43 static unsigned char sticky_bits[] = {
44 0x20, 0x70, 0xfa, 0x7e, 0x3c, 0x1c, 0x32, 0x01
46 static unsigned char unsticky_bits[] = {
47 0x1c, 0x1c, 0x1c, 0x3e, 0x7f, 0x08, 0x08, 0x08
49 static unsigned char help_bits[] = {
50 0x18, 0x18, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x3c
52 static unsigned char shade_on_bits[] = {
53 0xff, 0xff, 0x81, 0x81, 0x99, 0xbd, 0x81, 0xff
55 static unsigned char shade_off_bits[] = {
56 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
58 static unsigned char above_on_bits[] = {
59 0xff, 0x7e, 0x3c, 0x18, 0x00, 0xff, 0xff, 0x00
61 static unsigned char above_off_bits[] = {
62 0x18, 0x3c, 0x7e, 0xff, 0x00, 0xff, 0xff, 0x00
64 static unsigned char below_on_bits[] = {
65 0x00, 0xff, 0xff, 0x00, 0x18, 0x3c, 0x7e, 0xff
67 static unsigned char below_off_bits[] = {
68 0x00, 0xff, 0xff, 0x00, 0xff, 0x7e, 0x3c, 0x18
70 static unsigned char menu_bits[] = {
71 0xff, 0x81, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff
74 WebButton::WebButton(ButtonType type, WebClient *parent, bool shape)
75 : KCommonDecorationButton (type, parent),
76 mouseOver_ (false),
77 shape_ (shape),
78 deco_ (parent)
80 setAttribute(Qt::WA_NoSystemBackground, true);
83 WebButton::~WebButton()
85 // Empty.
88 void WebButton::reset(unsigned long changed)
90 if (changed&DecorationReset || changed&ManualReset || changed&SizeChange || changed&StateChange) {
91 switch (type() ) {
92 case CloseButton:
93 setBitmap(close_bits);
94 break;
95 case HelpButton:
96 setBitmap(help_bits);
97 break;
98 case MinButton:
99 setBitmap(iconify_bits);
100 break;
101 case MaxButton:
102 setBitmap( isChecked() ? unmaximize_bits : maximize_bits );
103 break;
104 case OnAllDesktopsButton:
105 setBitmap( isChecked() ? unsticky_bits : sticky_bits );
106 break;
107 case ShadeButton:
108 setBitmap( isChecked() ? shade_on_bits : shade_off_bits );
109 break;
110 case AboveButton:
111 setBitmap( isChecked() ? above_on_bits : above_off_bits );
112 break;
113 case BelowButton:
114 setBitmap( isChecked() ? below_on_bits : below_off_bits );
115 break;
116 case MenuButton:
117 setBitmap(menu_bits);
118 break;
119 default:
120 setBitmap(0);
121 break;
124 this->update();
128 void
129 WebButton::enterEvent(QEvent * e)
131 mouseOver_ = true;
132 repaint();
133 QAbstractButton::enterEvent(e);
136 void
137 WebButton::leaveEvent(QEvent * e)
139 mouseOver_ = false;
140 repaint();
141 QAbstractButton::leaveEvent(e);
144 void WebButton::paintEvent(QPaintEvent *)
146 QPainter p(this);
147 drawButton(&p);
150 void
151 WebButton::drawButton(QPainter *p)
153 QPen highlightPen;
155 if (isDown() )
156 highlightPen = QPen( palette().color( QPalette::Light ));
158 else
160 if (mouseOver_)
161 highlightPen = QPen( palette().color( QPalette::Highlight ));
162 else
163 highlightPen = QPen(Qt::NoPen);
166 p->fillRect(rect(), palette().color( QPalette::Background ) );
168 Position position_;
169 if (0 == mapToParent(rect().topLeft() ).x() )
170 position_ = Left;
171 else if (deco_->width()-1 == mapToParent(rect().topRight() ).x() )
172 position_ = Right;
173 else
174 position_ = Mid;
175 switch ( position_ )
177 case Left:
179 // Draw edge.
181 p->setPen(Qt::black);
183 p->drawLine(0, 0, width(), 0);
184 p->drawLine(0, 1, 0, height() - 1);
185 if (shape_)
187 p->drawPoint(3, 1);
188 p->drawPoint(4, 1);
189 p->drawPoint(2, 2);
190 p->drawPoint(1, 3);
191 p->drawPoint(1, 4);
193 // Draw highlight.
195 p->setBrush(Qt::NoBrush);
196 p->setPen(highlightPen);
198 if (shape_)
199 p->setClipRegion(QRegion(rect()) - QRect(0, 0, 6, 6));
201 p->drawRect(2, 2, width() - 4, height() - 4);
202 if (shape_)
204 p->setClipRect(rect());
205 p->drawPoint(4, 3);
206 p->drawPoint(5, 3);
207 p->drawPoint(3, 4);
208 p->drawPoint(3, 5);
212 break;
214 case Right:
216 // Draw edge.
218 p->setPen(Qt::black);
219 p->drawLine(0, 0, width(), 0);
220 p->drawLine(width() - 1, 1, width() - 1, height() - 1);
221 if (shape_)
223 p->drawPoint(width() - 5, 1);
224 p->drawPoint(width() - 4, 1);
225 p->drawPoint(width() - 3, 2);
226 p->drawPoint(width() - 2, 3);
227 p->drawPoint(width() - 2, 4);
229 // Draw highlight.
231 p->setBrush(Qt::NoBrush);
232 p->setPen(highlightPen);
234 if (shape_)
235 p->setClipRegion(QRegion(rect()) - QRect(width() - 6, 0, 6, 6));
237 p->drawRect(2, 2, width() - 4, height() - 4);
238 if (shape_)
240 p->setClipRect(rect());
241 p->drawPoint(width() - 5, 3);
242 p->drawPoint(width() - 6, 3);
243 p->drawPoint(width() - 4, 4);
244 p->drawPoint(width() - 4, 5);
248 break;
250 case Mid:
251 default:
253 // Draw edge.
255 p->setPen(Qt::black);
256 p->drawLine(0, 0, width(), 0);
258 // Draw highlight.
260 p->setBrush(Qt::NoBrush);
261 p->setPen(highlightPen);
263 p->drawRect(2, 2, width() - 4, height() - 4);
266 break;
269 // Draw icon.
271 QPoint center(rect().center());
273 int bwby2(bitmap_.width() / 2); // Bitmap Width BY 2
274 int bhby2(bitmap_.height() / 2); // Bitmap Height BY 2
276 p->setBrush(Qt::NoBrush);
277 p->setPen(Qt::black);
279 p->drawPixmap(center.x() - bwby2 + 1, center.y() - bhby2 + 1, bitmap_);
282 void
283 WebButton::setBitmap(const unsigned char *bitmap)
285 if (bitmap)
286 bitmap_ = QBitmap::fromData( QSize(8, 8), bitmap);
287 else
288 bitmap_ = QBitmap(8,8);
289 bitmap_.setMask(bitmap_);
294 // vim:ts=2:sw=2:tw=78:set et:
295 // kate: indent-width 2; replace-tabs on; tab-width 2; space-indent on;