00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include <qcursor.h>
00023
#include <qpainter.h>
00024
#include <qtooltip.h>
00025
#include <qapplication.h>
00026
00027
#include "WebButton.h"
00028
#include "Web.h"
00029
00030
namespace Web {
00031
00032 WebButton::WebButton(QWidget * parent,
const QString& tip, WebClient* deco)
00033 : QButton (parent, 0, 0),
00034 mouseOver_ (false),
00035 mouseDown_ (false),
00036 position_ (Mid),
00037 shape_ (false),
00038 deco_ (deco)
00039 {
00040 setTipText(tip);
00041 setCursor(ArrowCursor);
00042 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
00043 setBackgroundMode(NoBackground);
00044 }
00045
00046 WebButton::~WebButton()
00047 {
00048
00049 }
00050
00051
void
00052 WebButton::setShape(
bool b)
00053 {
00054 shape_ = b;
00055 repaint();
00056 }
00057
00058
void
00059 WebButton::mousePressEvent(QMouseEvent * e)
00060 {
00061 mouseDown_ =
true;
00062 repaint();
00063 QButton::mousePressEvent(e);
00064 }
00065
00066
void
00067 WebButton::mouseReleaseEvent(QMouseEvent * e)
00068 {
00069 mouseDown_ =
false;
00070 repaint();
00071
00072 KDecorationFactory* f = deco_->factory();
00073
if (rect().contains(e->pos()))
00074 {
00075 clickEvent(e->button());
00076 }
00077
if( !f->exists( deco_ ))
00078
return;
00079 QButton::mouseReleaseEvent(e);
00080 }
00081
00082
void
00083 WebButton::enterEvent(QEvent * e)
00084 {
00085 mouseOver_ =
true;
00086 repaint();
00087 QButton::enterEvent(e);
00088 }
00089
00090
void
00091 WebButton::leaveEvent(QEvent * e)
00092 {
00093 mouseOver_ =
false;
00094 repaint();
00095 QButton::leaveEvent(e);
00096 }
00097
00098
void
00099 WebButton::paintEvent(QPaintEvent *)
00100 {
00101 QPen highlightPen;
00102
00103
if (mouseDown_)
00104 highlightPen = QPen(colorGroup().light());
00105
00106
else
00107 {
00108
if (mouseOver_)
00109 highlightPen = QPen(colorGroup().highlight());
00110
else
00111 highlightPen = QPen(NoPen);
00112 }
00113
00114 QPainter p(
this);
00115
00116 p.fillRect(rect(), colorGroup().background());
00117
switch ( position_ )
00118 {
00119
case Left:
00120 {
00121
00122
00123 p.setPen(Qt::black);
00124
00125 p.drawLine(0, 0, width(), 0);
00126 p.drawLine(0, 1, 0, height() - 1);
00127
if (shape_)
00128 {
00129 p.drawPoint(3, 1);
00130 p.drawPoint(4, 1);
00131 p.drawPoint(2, 2);
00132 p.drawPoint(1, 3);
00133 p.drawPoint(1, 4);
00134 }
00135
00136
00137 p.setBrush(NoBrush);
00138 p.setPen(highlightPen);
00139
00140
if (shape_)
00141 p.setClipRegion(QRegion(rect()) - QRect(0, 0, 6, 6));
00142
00143 p.drawRect(2, 2, width() - 4, height() - 4);
00144
if (shape_)
00145 {
00146 p.setClipRect(rect());
00147 p.drawPoint(4, 3);
00148 p.drawPoint(5, 3);
00149 p.drawPoint(3, 4);
00150 p.drawPoint(3, 5);
00151 }
00152 }
00153
00154
break;
00155
00156
case Right:
00157 {
00158
00159
00160 p.setPen(Qt::black);
00161 p.drawLine(0, 0, width(), 0);
00162 p.drawLine(width() - 1, 1, width() - 1, height() - 1);
00163
if (shape_)
00164 {
00165 p.drawPoint(width() - 5, 1);
00166 p.drawPoint(width() - 4, 1);
00167 p.drawPoint(width() - 3, 2);
00168 p.drawPoint(width() - 2, 3);
00169 p.drawPoint(width() - 2, 4);
00170 }
00171
00172
00173 p.setBrush(NoBrush);
00174 p.setPen(highlightPen);
00175
00176
if (shape_)
00177 p.setClipRegion(QRegion(rect()) - QRect(width() - 6, 0, 6, 6));
00178
00179 p.drawRect(2, 2, width() - 4, height() - 4);
00180
if (shape_)
00181 {
00182 p.setClipRect(rect());
00183 p.drawPoint(width() - 5, 3);
00184 p.drawPoint(width() - 6, 3);
00185 p.drawPoint(width() - 4, 4);
00186 p.drawPoint(width() - 4, 5);
00187 }
00188 }
00189
00190
break;
00191
00192
case Mid:
00193
default:
00194 {
00195
00196
00197 p.setPen(Qt::black);
00198 p.drawLine(0, 0, width(), 0);
00199
00200
00201
00202 p.setBrush(NoBrush);
00203 p.setPen(highlightPen);
00204
00205 p.drawRect(2, 2, width() - 4, height() - 4);
00206 }
00207
00208
break;
00209 }
00210
00211
00212
00213 QPoint center(rect().center());
00214
00215
int bwby2(bitmap_.width() / 2);
00216
int bhby2(bitmap_.height() / 2);
00217
00218 p.setBrush(NoBrush);
00219 p.setPen(Qt::black);
00220
00221 p.drawPixmap(center.x() - bwby2 + 1, center.y() - bhby2 + 1, bitmap_);
00222 }
00223
00224 QSize
00225 WebButton::sizeHint()
const
00226
{
00227
return QSize(16, 16);
00228 }
00229
00230 QSize
00231 WebButton::minimumSizeHint()
const
00232
{
00233
return QSize(14, 14);
00234 }
00235
00236
void
00237 WebButton::setBitmap(
const QBitmap & b)
00238 {
00239 bitmap_ = b;
00240 repaint();
00241 }
00242
00243
void
00244 WebButton::setPosition(Position p)
00245 {
00246
if ( QApplication::reverseLayout() )
00247 {
00248
if ( p == Left )
00249 position_ = Right;
00250
else if ( p == Right )
00251 position_ = Left;
00252 }
00253
else
00254 position_ = p;
00255 repaint();
00256 }
00257
00258
void
00259 WebButton::resizeEvent(QResizeEvent *)
00260 {
00261 repaint();
00262 }
00263
00264
void
00265 WebButton::setTipText(
const QString &tip) {
00266
if(
KDecoration::options()->
showTooltips()) {
00267 QToolTip::remove(
this );
00268 QToolTip::add(
this, tip );
00269 }
00270 }
00271
00272 }
00273
00274
#include "WebButton.moc"
00275