00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#include "karrowbutton.h"
00020
00021
#include <qstyle.h>
00022
#include <qpainter.h>
00023
00024
class KArrowButtonPrivate
00025 {
00026
public:
00027 Qt::ArrowType arrow;
00028 };
00029
00030 KArrowButton::KArrowButton(
QWidget *parent, Qt::ArrowType arrow,
00031
const char *name)
00032 :
QPushButton(parent, name)
00033 {
00034 d =
new KArrowButtonPrivate();
00035 d->arrow = arrow;
00036 }
00037
00038 KArrowButton::~KArrowButton()
00039 {
00040
delete d;
00041 }
00042
00043 QSize KArrowButton::sizeHint()
const
00044
{
00045
return QSize( 12, 12 );
00046 }
00047
00048 void KArrowButton::setArrowType(Qt::ArrowType a)
00049 {
00050
if (d->arrow != a) {
00051 d->arrow = a;
00052 repaint();
00053 }
00054 }
00055 Qt::ArrowType
KArrowButton::arrowType()
const
00056
{
00057
return d->arrow;
00058 }
00059
00060 void KArrowButton::drawButton(
QPainter *p)
00061 {
00062
const unsigned int arrowSize = 8;
00063
const unsigned int margin = 2;
00064
00065 p->
fillRect( rect(), colorGroup().brush( QColorGroup::Background ) );
00066 style().drawPrimitive( QStyle::PE_Panel, p,
QRect( 0, 0, width(), height() ),
00067 colorGroup(),
00068
isDown() ? QStyle::Style_Sunken : QStyle::Style_Default,
00069
QStyleOption( 2, 0 ) );
00070
00071
if (static_cast<unsigned int>(width()) < arrowSize + margin ||
00072 static_cast<unsigned int>(height()) < arrowSize + margin)
00073
return;
00074
00075
unsigned int x = 0, y = 0;
00076
if (d->arrow == DownArrow) {
00077 x = (width() - arrowSize) / 2;
00078 y = height() - (arrowSize + margin);
00079 }
else if (d->arrow == UpArrow) {
00080 x = (width() - arrowSize) / 2;
00081 y = margin;
00082 }
else if (d->arrow == RightArrow) {
00083 x = width() - (arrowSize + margin);
00084 y = (height() - arrowSize) / 2;
00085 }
else {
00086 x = margin;
00087 y = (height() - arrowSize) / 2;
00088 }
00089
00090
if (
isDown()) {
00091 x++;
00092 y++;
00093 }
00094
00095 QStyle::PrimitiveElement e = QStyle::PE_ArrowLeft;
00096
switch (d->arrow)
00097 {
00098
case Qt::LeftArrow: e = QStyle::PE_ArrowLeft;
break;
00099
case Qt::RightArrow: e = QStyle::PE_ArrowRight;
break;
00100
case Qt::UpArrow: e = QStyle::PE_ArrowUp;
break;
00101
case Qt::DownArrow: e = QStyle::PE_ArrowDown;
break;
00102 }
00103
int flags = QStyle::Style_Enabled;
00104
if (
isDown() )
00105 flags |= QStyle::Style_Down;
00106 style().drawPrimitive( e, p,
QRect(
QPoint( x, y ),
QSize( arrowSize, arrowSize ) ),
00107 colorGroup(), flags );
00108 }
00109
00110
void KArrowButton::virtual_hook(
int,
void* )
00111 { }
00112
00113
#include "karrowbutton.moc"