| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# karrowbutton.cpp

    00001 /* This file is part of the KDE libraries
    00002          Copyright (C) 2001 Frerich Raabe <raabe@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011          Library General Public License for more details.
    00012
    00013          You should have received a copy of the GNU Library General Public License
    00014          along with this library; see the file COPYING.LIB.  If not, write to
    00015          the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016          Boston, MA 02111-1307, USA.
    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
    00056 void KArrowButton::drawButton(QPainter *p)
    00057 {
    00058         const unsigned int arrowSize = 8;
    00059         const unsigned int margin = 2;
    00060
    00061 #if QT_VERSION < 300
    00062         style().drawPanel(p, 0, 0, width(), height(), colorGroup(),
    00063                         isDown(), 2, &colorGroup().brush(QColorGroup::Background));
    00064 #else
    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 #endif
    00071
    00072         if (static_cast<unsigned int>(width()) < arrowSize + margin ||
    00073             static_cast<unsigned int>(height()) < arrowSize + margin)
    00074                 return; // don't draw arrows if we are too small
    00075
    00076         unsigned int x = 0, y = 0;
    00077         if (d->arrow == DownArrow) {
    00078                 x = (width() - arrowSize) / 2;
    00079                 y = height() - (arrowSize + margin);
    00080         } else if (d->arrow == UpArrow) {
    00081                 x = (width() - arrowSize) / 2;
    00082                 y = margin;
    00083         } else if (d->arrow == RightArrow) {
    00084                 x = width() - (arrowSize + margin);
    00085                 y = (height() - arrowSize) / 2;
    00086         } else { // arrowType == LeftArrow
    00087                 x = margin;
    00088                 y = (height() - arrowSize) / 2;
    00089         }
    00090
    00091         if (isDown()) {
    00092                 x++;
    00093                 y++;
    00094         }
    00095
    00096 #if QT_VERSION < 300
    00097         style().drawArrow(p, d->arrow, isDown(), x, y, arrowSize, arrowSize,
    00098                         colorGroup(), true);
    00099 #else
    00100         QStyle::PrimitiveElement e = QStyle::PE_ArrowLeft;
    00101         switch (d->arrow)
    00102         {
    00103                 case Qt::LeftArrow: e = QStyle::PE_ArrowLeft; break;
    00104                 case Qt::RightArrow: e = QStyle::PE_ArrowRight; break;
    00105                 case Qt::UpArrow: e = QStyle::PE_ArrowUp; break;
    00106                 case Qt::DownArrow: e = QStyle::PE_ArrowDown; break;
    00107         }
    00108         int flags = QStyle::Style_Enabled;
    00109         if ( isDown() )
    00110                 flags |= QStyle::Style_Down;
    00111         style().drawPrimitive( e, p, QRect( QPoint( x, y ), QSize( arrowSize, arrowSize ) ),
    00112                                colorGroup(), flags );
    00113 #endif
    00114 }
    00115
    00116 void KArrowButton::virtual_hook( int, void* )
    00117 { /*BASE::virtual_hook( id, data );*/ }
    00118
    00119 #include "karrowbutton.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:56:11 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001