lib

tktoolbarbutton.h

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000 theKompany.com
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 #ifndef TKTOOLBARBUTTON_H
00021 #define TKTOOLBARBUTTON_H
00022 
00023 #include <tkaction.h>
00024 
00025 #include <qpixmap.h>
00026 #include <qtoolbutton.h>
00027 #include <kglobal.h>
00028 
00029 class KToolBar;
00030 class KInstance;
00031 class QPopupMenu;
00032 class QPainter;
00033 
00034 class TKToolBarButton : public QToolButton
00035 { Q_OBJECT
00036 public:
00037   TKToolBarButton(const QString& icon, const QString& txt,
00038                      QWidget* parent = 0, const char *name=0L,
00039                      KInstance *_instance = KGlobal::instance());
00040 
00041   TKToolBarButton(const QPixmap&, const QString&, QWidget* parent=0, const char* name=0);
00042   ~TKToolBarButton();
00043 
00044   void setIconMode(TK::IconMode);
00045   void setRaised(bool);
00046   void setAutoRaised(bool);
00047 
00053   void setEnabled(bool enable = true);
00054 
00063   virtual void setPixmap(const QPixmap &pixmap);
00064 
00076   virtual void setPixmap(const QPixmap &pixmap, bool generate);
00077 
00084   virtual void setDefaultPixmap(const QPixmap& pixmap);
00085 
00092   virtual void setDisabledPixmap(const QPixmap& pixmap);
00093 
00100   virtual void setText(const QString &text);
00101   QString text();
00102 
00111   virtual void setIcon(const QString &icon);
00112 
00119   virtual void setDefaultIcon(const QString& icon);
00120 
00127   virtual void setDisabledIcon(const QString& icon);
00128 
00134   void on(bool flag = true);
00135 
00139   void toggle();
00140 
00148   void setToggle(bool toggle = true);
00149 
00153   QPopupMenu *popup();
00154 
00162   void setPopup (QPopupMenu *p);
00163 
00178   void setDelayedPopup(QPopupMenu *p, bool toggle = false);
00179 
00180   QPixmap getActivePixmap() const;
00181 
00182   virtual QSize sizeHint() const;
00183   virtual QSize minimumSizeHint() const;
00184 
00185 signals:
00186   void buttonClicked();
00187   void buttonPressed();
00188   void buttonReleased();
00189   void buttonToggled();
00190 
00191 public slots:
00192   void modeChange();
00193 
00194 protected:
00195   void paletteChange(const QPalette &);
00196   void leaveEvent(QEvent *e);
00197   void enterEvent(QEvent *e);
00198   void drawButton(QPainter *p);
00199   bool eventFilter (QObject *o, QEvent *e);
00200   void showMenu();
00201 
00202   void makeDefaultPixmap();
00203   void makeDisabledPixmap();
00204   bool arrowPressed( const QPoint& pos ) {
00205     int x = pos.x();
00206     int y = pos.y();
00207     return (x > width() - 12 && x <= width() && y > 0 && y < height());
00208   }
00209 
00210 private:
00211   QPixmap defaultPixmap;
00212   QPixmap activePixmap;
00213   QPixmap disabledPixmap;
00214   virtual void setIcon(const QPixmap &p) { QButton::setIcon(p); }
00215   class TKToolBarButtonPrivate;
00216   TKToolBarButtonPrivate *d;
00217 
00218 
00219 protected slots:
00220   void slotClicked();
00221   void slotPressed();
00222   void slotReleased();
00223   void slotToggled();
00224   void slotDelayTimeout();
00225 };
00226 
00227 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys