Fix some error
[kdeartwork.git] / kwin-styles / riscos / Button.cpp
blobcb1a900593df356b3a960e43e8c0c7ac4874378a
1 /*
2 RISC OS KWin client
4 Copyright 2000
5 Rik Hemsley <rik@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 as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include <qtooltip.h>
24 //Added by qt3to4:
25 #include <QMouseEvent>
26 #include <QPixmap>
27 #include <QPaintEvent>
28 #include "Button.h"
29 #include "Static.h"
31 namespace RiscOS
34 Button::Button(QWidget *parent, const QString& tip,
35 const Qt::ButtonState realizeButtons)
36 : QWidget(parent, "Button", 0),
37 realizeButtons_(realizeButtons),
38 lastButton_(Qt::NoButton),
39 alignment_(Qt::DockLeft),
40 down_ (false),
41 active_ (false)
43 this->setToolTip( tip);
44 setBackgroundColor(Qt::black);
46 setFixedSize(Static::instance()->titleHeight() - 1,
47 Static::instance()->titleHeight());
50 Button::~Button()
52 // Empty.
55 void Button::setAlignment(Alignment a)
57 alignment_ = a;
58 repaint();
61 void Button::setActive(bool b)
63 active_ = b;
64 repaint();
67 Button::Alignment Button::alignment() const
69 return alignment_;
72 void Button::mousePressEvent(QMouseEvent *e)
74 down_ = true;
75 lastButton_ = e->button();
76 repaint();
78 QMouseEvent me(e->type(), e->pos(), e->globalPos(),
79 (e->button()&realizeButtons_) ? Qt::LeftButton : Qt::NoButton,
80 e->state());
81 QWidget::mousePressEvent(&me);
84 void Button::mouseReleaseEvent(QMouseEvent *e)
86 down_ = false;
87 lastButton_ = e->button();
88 repaint();
89 QMouseEvent me(e->type(), e->pos(), e->globalPos(),
90 (e->button()&realizeButtons_) ? Qt::LeftButton : Qt::NoButton,
91 e->state());
92 QWidget::mouseReleaseEvent(&me);
95 void Button::setPixmap(const QPixmap &p)
97 if (QPixmap::defaultDepth() <= 8)
98 aPixmap_ = iPixmap_ = p;
99 else
101 QRgb light;
102 QRgb* data = NULL;
103 QRgb w = qRgb(255, 255, 255);
105 QImage aTx(p.convertToImage());
106 QImage iTx(aTx.copy());
108 const KDecorationOptions* options = KDecoration::options();
109 light = options->color(KDecoration::ColorButtonBg, true).light(150).rgb();
111 if (light == qRgb(0, 0, 0))
112 light = qRgb(228, 228, 228);
114 data = (QRgb *)aTx.bits();
116 for (int x = 0; x < 144; x++)
117 if (data[x] == w)
118 data[x] = light;
120 light = options->color(KDecoration::ColorButtonBg, false).light(150).rgb();
122 if (light == qRgb(0, 0, 0))
123 light = qRgb(228, 228, 228);
125 data = (QRgb *)iTx.bits();
127 for (int x = 0; x < 144; x++)
128 if (data[x] == w)
129 data[x] = light;
131 aPixmap_.convertFromImage(aTx);
132 iPixmap_.convertFromImage(iTx);
134 if (0 != p.mask())
136 aPixmap_.setMask(*p.mask());
137 iPixmap_.setMask(*p.mask());
140 repaint();
143 void Button::paintEvent(QPaintEvent *)
145 bitBlt(this, alignment_ == Left ? 1 : 0, 0,
146 &Static::instance()->buttonBase(active_, down_));
148 int i = width() / 2 - 6;
150 bitBlt(this, alignment_ == Left ? i + 1 : i,
151 i + 1, active_ ? &aPixmap_ : &iPixmap_);
154 } // End namespace
156 // vim:ts=2:sw=2:tw=78
157 #include "Button.moc"