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"
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
),
80 setAttribute(Qt::WA_NoSystemBackground
, true);
83 WebButton::~WebButton()
88 void WebButton::reset(unsigned long changed
)
90 if (changed
&DecorationReset
|| changed
&ManualReset
|| changed
&SizeChange
|| changed
&StateChange
) {
93 setBitmap(close_bits
);
99 setBitmap(iconify_bits
);
102 setBitmap( isChecked() ? unmaximize_bits
: maximize_bits
);
104 case OnAllDesktopsButton
:
105 setBitmap( isChecked() ? unsticky_bits
: sticky_bits
);
108 setBitmap( isChecked() ? shade_on_bits
: shade_off_bits
);
111 setBitmap( isChecked() ? above_on_bits
: above_off_bits
);
114 setBitmap( isChecked() ? below_on_bits
: below_off_bits
);
117 setBitmap(menu_bits
);
129 WebButton::enterEvent(QEvent
* e
)
133 QAbstractButton::enterEvent(e
);
137 WebButton::leaveEvent(QEvent
* e
)
141 QAbstractButton::leaveEvent(e
);
144 void WebButton::paintEvent(QPaintEvent
*)
151 WebButton::drawButton(QPainter
*p
)
156 highlightPen
= QPen( palette().color( QPalette::Light
));
161 highlightPen
= QPen( palette().color( QPalette::Highlight
));
163 highlightPen
= QPen(Qt::NoPen
);
166 p
->fillRect(rect(), palette().color( QPalette::Background
) );
169 if (0 == mapToParent(rect().topLeft() ).x() )
171 else if (deco_
->width()-1 == mapToParent(rect().topRight() ).x() )
181 p
->setPen(Qt::black
);
183 p
->drawLine(0, 0, width(), 0);
184 p
->drawLine(0, 1, 0, height() - 1);
195 p
->setBrush(Qt::NoBrush
);
196 p
->setPen(highlightPen
);
199 p
->setClipRegion(QRegion(rect()) - QRect(0, 0, 6, 6));
201 p
->drawRect(2, 2, width() - 4, height() - 4);
204 p
->setClipRect(rect());
218 p
->setPen(Qt::black
);
219 p
->drawLine(0, 0, width(), 0);
220 p
->drawLine(width() - 1, 1, width() - 1, height() - 1);
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);
231 p
->setBrush(Qt::NoBrush
);
232 p
->setPen(highlightPen
);
235 p
->setClipRegion(QRegion(rect()) - QRect(width() - 6, 0, 6, 6));
237 p
->drawRect(2, 2, width() - 4, height() - 4);
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);
255 p
->setPen(Qt::black
);
256 p
->drawLine(0, 0, width(), 0);
260 p
->setBrush(Qt::NoBrush
);
261 p
->setPen(highlightPen
);
263 p
->drawRect(2, 2, width() - 4, height() - 4);
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_
);
283 WebButton::setBitmap(const unsigned char *bitmap
)
286 bitmap_
= QBitmap::fromData( QSize(8, 8), bitmap
);
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;