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.
25 #include <QMouseEvent>
27 #include <QPaintEvent>
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
),
43 this->setToolTip( tip
);
44 setBackgroundColor(Qt::black
);
46 setFixedSize(Static::instance()->titleHeight() - 1,
47 Static::instance()->titleHeight());
55 void Button::setAlignment(Alignment a
)
61 void Button::setActive(bool b
)
67 Button::Alignment
Button::alignment() const
72 void Button::mousePressEvent(QMouseEvent
*e
)
75 lastButton_
= e
->button();
78 QMouseEvent
me(e
->type(), e
->pos(), e
->globalPos(),
79 (e
->button()&realizeButtons_
) ? Qt::LeftButton
: Qt::NoButton
,
81 QWidget::mousePressEvent(&me
);
84 void Button::mouseReleaseEvent(QMouseEvent
*e
)
87 lastButton_
= e
->button();
89 QMouseEvent
me(e
->type(), e
->pos(), e
->globalPos(),
90 (e
->button()&realizeButtons_
) ? Qt::LeftButton
: Qt::NoButton
,
92 QWidget::mouseReleaseEvent(&me
);
95 void Button::setPixmap(const QPixmap
&p
)
97 if (QPixmap::defaultDepth() <= 8)
98 aPixmap_
= iPixmap_
= p
;
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
++)
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
++)
131 aPixmap_
.convertFromImage(aTx
);
132 iPixmap_
.convertFromImage(iTx
);
136 aPixmap_
.setMask(*p
.mask());
137 iPixmap_
.setMask(*p
.mask());
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_
);
156 // vim:ts=2:sw=2:tw=78
157 #include "Button.moc"