ktabzoombutton.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qpainter.h>
00013 #include <qsizepolicy.h>
00014 #include <qstyle.h>
00015
00016
00017 #include "ktabzoombutton.h"
00018
00019
00020 class KTabZoomButtonPrivate
00021 {
00022 public:
00023
00024 KTabZoomPosition::Position m_position;
00025
00026 };
00027
00028
00029 KTabZoomButton::KTabZoomButton(const QString &text, QWidget *parent, KTabZoomPosition::Position pos, const char *name)
00030 : QPushButton(text, parent, name)
00031 {
00032 d = new KTabZoomButtonPrivate;
00033
00034 d->m_position = pos;
00035
00036 setFlat(true);
00037 setToggleButton(true);
00038
00039 setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00040 }
00041
00042
00043 KTabZoomButton::~KTabZoomButton()
00044 {
00045 delete d;
00046 }
00047
00048
00049 void KTabZoomButton::drawButton(QPainter *p)
00050 {
00051 int w = fontMetrics().width(text()) + 2*fontMetrics().width('m');
00052 int h = fontMetrics().height()+2;
00053
00054 QPixmap pixmap(w, h);
00055 QPainter painter(&pixmap);
00056
00057 pixmap.fill(eraseColor());
00058
00059 QStyle::SFlags flags = QStyle::Style_Default;
00060 if (isEnabled())
00061 flags |= QStyle::Style_Enabled;
00062 if (isDown())
00063 flags |= QStyle::Style_Down;
00064 if (isOn())
00065 flags |= QStyle::Style_On;
00066 if (! isFlat() && ! isDown())
00067 flags |= QStyle::Style_Raised;
00068
00069 style().drawControl(QStyle::CE_PushButton, &painter, this, QRect(0,0,w,h), colorGroup(), flags);
00070 style().drawControl(QStyle::CE_PushButtonLabel, &painter, this, QRect(0,0,w,h), colorGroup(), flags);
00071
00072 if (hasFocus())
00073 style().drawPrimitive(QStyle::PE_FocusRect, &painter, QRect(1,1,w-2,h-2), colorGroup(), flags);
00074
00075 switch (d->m_position)
00076 {
00077 case KTabZoomPosition::Top:
00078 case KTabZoomPosition::Bottom:
00079 p->drawPixmap(0,0, pixmap);
00080 break;
00081
00082 case KTabZoomPosition::Left:
00083 p->rotate(-90);
00084 p->drawPixmap(-height(), 0, pixmap);
00085 break;
00086
00087 case KTabZoomPosition::Right:
00088 p->rotate(90);
00089 p->drawPixmap(0,-width(), pixmap);
00090 break;
00091 }
00092 }
00093
00094
00095 void KTabZoomButton::drawButtonLabel(QPainter *p)
00096 {
00097 drawButton(p);
00098 }
00099
00100
00101 QSize KTabZoomButton::sizeHint () const
00102 {
00103 int w = fontMetrics().width(text()) + 2*fontMetrics().width('m');
00104
00105 if (d->m_position == KTabZoomPosition::Top || d->m_position == KTabZoomPosition::Bottom)
00106 return QSize(w, fontMetrics().height()+2);
00107
00108 return QSize(fontMetrics().height()+2, w);
00109 }
00110
00111 #include "ktabzoombutton.moc"
This file is part of the documentation for KDevelop Version 3.1.2.