home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ktoolbarbutton.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  9.3 KB  |  331 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
  3.               (C) 1997, 1998 Sven Radej (radej@kde.org)
  4.               (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
  5.               (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
  6.               (C) 2000 Kurt Granroth (granroth@kde.org)
  7.  
  8.     This library is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU Library General Public
  10.     License version 2 as published by the Free Software Foundation.
  11.  
  12.     This library is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     Library General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU Library General Public License
  18.     along with this library; see the file COPYING.LIB.  If not, write to
  19.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20.     Boston, MA 02110-1301, USA.
  21. */
  22.  
  23. #ifndef _KTOOLBARBUTTON_H
  24. #define _KTOOLBARBUTTON_H
  25.  
  26. #include <qpixmap.h>
  27. #include <qtoolbutton.h>
  28. #include <qintdict.h>
  29. #include <qstring.h>
  30. #include <kglobal.h>
  31.  
  32. class KToolBar;
  33. class KToolBarButtonPrivate;
  34. class KInstance;
  35. class QEvent;
  36. class QPopupMenu;
  37. class QPainter;
  38.  
  39. /**
  40.  * A toolbar button. This is used internally by KToolBar, use the
  41.  * KToolBar methods instead.
  42.  * @internal
  43.  */
  44. class KDEUI_EXPORT KToolBarButton : public QToolButton
  45. {
  46.   Q_OBJECT
  47.  
  48. public:
  49.   /**
  50.    * Construct a button with an icon loaded by the button itself.
  51.    * This will trust the button to load the correct icon with the
  52.    * correct size.
  53.    *
  54.    * @param icon   Name of icon to load (may be absolute or relative)
  55.    * @param id     Id of this button
  56.    * @param parent This button's parent
  57.    * @param name   This button's internal name
  58.    * @param txt    This button's text (in a tooltip or otherwise)
  59.    * @param _instance the instance to use for this button
  60.    */
  61.   KToolBarButton(const QString& icon, int id, QWidget *parent,
  62.                  const char *name=0L, const QString &txt=QString::null,
  63.                  KInstance *_instance = KGlobal::instance());
  64.  
  65.   /**
  66.    * Construct a button with an existing pixmap.  It is not
  67.    * recommended that you use this as the internal icon loading code
  68.    * will almost always get it "right".
  69.    *
  70.    * @param pixmap Name of icon to load (may be absolute or relative)
  71.    * @param id     Id of this button
  72.    * @param parent This button's parent
  73.    * @param name   This button's internal name
  74.    * @param txt    This button's text (in a tooltip or otherwise)
  75.    */
  76.   KToolBarButton(const QPixmap& pixmap, int id, QWidget *parent,
  77.                  const char *name=0L, const QString &txt=QString::null);
  78.  
  79.   /**
  80.    * Construct a separator button
  81.    *
  82.    * @param parent This button's parent
  83.    * @param name   This button's internal name
  84.    */
  85.   KToolBarButton(QWidget *parent=0L, const char *name=0L);
  86.  
  87.   /**
  88.    * Standard destructor
  89.    */
  90.   ~KToolBarButton();
  91.  
  92. #ifndef KDE_NO_COMPAT
  93.   /**
  94.    * @deprecated
  95.    * Set the pixmap directly for this button.  This pixmap should be
  96.    * the active one... the dimmed and disabled pixmaps are constructed
  97.    * based on this one.  However, don't use this function unless you
  98.    * are positive that you don't want to use setIcon.
  99.    *
  100.    * @param pixmap The active pixmap
  101.    */
  102.   // this one is from QButton, so #ifdef-ing it out doesn't break BC
  103.   virtual void setPixmap(const QPixmap &pixmap) KDE_DEPRECATED;
  104.  
  105.   /**
  106.    * @deprecated
  107.    * Force the button to use this pixmap as the default one rather
  108.    * then generating it using effects.
  109.    *
  110.    * @param pixmap The pixmap to use as the default (normal) one
  111.    */
  112.   void setDefaultPixmap(const QPixmap& pixmap) KDE_DEPRECATED;
  113.  
  114.   /**
  115.    * @deprecated
  116.    * Force the button to use this pixmap when disabled one rather then
  117.    * generating it using effects.
  118.    *
  119.    * @param pixmap The pixmap to use when disabled
  120.    */
  121.   void setDisabledPixmap(const QPixmap& pixmap) KDE_DEPRECATED;
  122. #endif
  123.  
  124.   /**
  125.    * Set the text for this button.  The text will be either used as a
  126.    * tooltip (IconOnly) or will be along side the icon
  127.    *
  128.    * @param text The button (or tooltip) text
  129.    */
  130.   virtual void setText(const QString &text);
  131.  
  132.   /**
  133.    * Set the icon for this button. The icon will be loaded internally
  134.    * with the correct size. This function is preferred over setIconSet
  135.    *
  136.    * @param icon The name of the icon
  137.    */
  138.   virtual void setIcon(const QString &icon);
  139.  
  140.   /// @since 3.1
  141.   virtual void setIcon( const QPixmap &pixmap )
  142.   { QToolButton::setIcon( pixmap ); }
  143.  
  144.   /**
  145.    * Set the pixmaps for this toolbar button from a QIconSet.
  146.    * If you call this you don't need to call any of the other methods
  147.    * that set icons or pixmaps.
  148.    * @param iconset  The iconset to use
  149.    */
  150.   virtual void setIconSet( const QIconSet &iconset );
  151.  
  152. #ifndef KDE_NO_COMPAT
  153.   /**
  154.    * @deprecated
  155.    * Set the active icon for this button.  The pixmap itself is loaded
  156.    * internally based on the icon size...  .. the disabled and default
  157.    * pixmaps, however will only be constructed if generate is
  158.    * true.  This function is preferred over setPixmap
  159.    *
  160.    * @param icon     The name of the active icon
  161.    * @param generate If true, then the other icons are automagically
  162.    *                 generated from this one
  163.    */
  164.   KDE_DEPRECATED void setIcon(const QString &icon, bool generate ) { Q_UNUSED(generate); setIcon( icon ); }
  165.  
  166.   /**
  167.    * @deprecated
  168.    * Force the button to use this icon as the default one rather
  169.    * then generating it using effects.
  170.    *
  171.    * @param icon The icon to use as the default (normal) one
  172.    */
  173.   void setDefaultIcon(const QString& icon) KDE_DEPRECATED;
  174.  
  175.   /**
  176.    * @deprecated
  177.    * Force the button to use this icon when disabled one rather then
  178.    * generating it using effects.
  179.    *
  180.    * @param icon The icon to use when disabled
  181.    */
  182.   void setDisabledIcon(const QString& icon) KDE_DEPRECATED;
  183. #endif
  184.  
  185.   /**
  186.    * Turn this button on or off
  187.    *
  188.    * @param flag true or false
  189.    */
  190.   void on(bool flag = true);
  191.  
  192.   /**
  193.    * Toggle this button
  194.    */
  195.   void toggle();
  196.  
  197.   /**
  198.    * Turn this button into a toggle button or disable the toggle
  199.    * aspects of it.  This does not toggle the button itself.
  200.    * Use toggle() for that.
  201.    *
  202.    * @param toggle true or false
  203.    */
  204.   void setToggle(bool toggle = true);
  205.  
  206.   /**
  207.    * Return a pointer to this button's popup menu (if it exists)
  208.    */
  209.   QPopupMenu *popup();
  210.  
  211.   /**
  212.    * Returns the button's id.
  213.    * @since 3.2
  214.    */
  215.   int id() const;
  216.  
  217.   /**
  218.    * Give this button a popup menu.  There will not be a delay when
  219.    * you press the button.  Use setDelayedPopup if you want that
  220.    * behavior.
  221.    *
  222.    * @param p The new popup menu
  223.    * @param unused Has no effect - ignore it.
  224.    */
  225.   void setPopup (QPopupMenu *p, bool unused = false);
  226.  
  227.   /**
  228.    * Gives this button a delayed popup menu.
  229.    *
  230.    * This function allows you to add a delayed popup menu to the button.
  231.    * The popup menu is then only displayed when the button is pressed and
  232.    * held down for about half a second.
  233.    *
  234.    * @param p the new popup menu
  235.    * @param unused Has no effect - ignore it.
  236.    */
  237.   void setDelayedPopup(QPopupMenu *p, bool unused = false);
  238.  
  239.   /**
  240.    * Turn this button into a radio button
  241.    *
  242.    * @param f true or false
  243.    */
  244.   void setRadio(bool f = true);
  245.  
  246.   /**
  247.    * Toolbar buttons naturally will assume the global styles
  248.    * concerning icons, icons sizes, etc.  You can use this function to
  249.    * explicitly turn this off, if you like.
  250.    *
  251.    * @param no_style Will disable styles if true
  252.    */
  253.   void setNoStyle(bool no_style = true);
  254.  
  255. signals:
  256.   /**
  257.    * Emitted when the toolbar button is clicked (with LMB or MMB)
  258.    */
  259.   void clicked(int);
  260.   /**
  261.    * Emitted when the toolbar button is clicked (with any mouse button)
  262.    * @param state makes it possible to find out which button was pressed,
  263.    * and whether any keyboard modifiers were held.
  264.    * @since 3.4
  265.    */
  266.   void buttonClicked(int, Qt::ButtonState state);
  267.   void doubleClicked(int);
  268.   void pressed(int);
  269.   void released(int);
  270.   void toggled(int);
  271.   void highlighted(int, bool);
  272.  
  273. public slots:
  274.   /**
  275.    * This slot should be called whenever the toolbar mode has
  276.    * potentially changed.  This includes such events as text changing,
  277.    * orientation changing, etc.
  278.    */
  279.    void modeChange();
  280.    virtual void setTextLabel(const QString&, bool tipToo);
  281.  
  282. protected:
  283.   bool event(QEvent *e);
  284.   void paletteChange(const QPalette &);
  285.   void leaveEvent(QEvent *e);
  286.   void enterEvent(QEvent *e);
  287.   void drawButton(QPainter *p);
  288.   bool eventFilter (QObject *o, QEvent *e);
  289.   /// @since 3.4
  290.   void mousePressEvent( QMouseEvent * );
  291.   /// @since 3.4
  292.   void mouseReleaseEvent( QMouseEvent * );
  293.   void showMenu();
  294.   QSize sizeHint() const;
  295.   QSize minimumSizeHint() const;
  296.   QSize minimumSize() const;
  297.  
  298.   /// @since 3.1
  299.   bool isRaised() const;
  300.   /// @since 3.1
  301.   bool isActive() const;
  302.   /// @since 3.1
  303.   int iconTextMode() const;
  304.  
  305. protected slots:
  306.   void slotClicked();
  307.   void slotPressed();
  308.   void slotReleased();
  309.   void slotToggled();
  310.   void slotDelayTimeout();
  311.  
  312. protected:
  313.   virtual void virtual_hook( int id, void* data );
  314. private:
  315.   KToolBarButtonPrivate *d;
  316. };
  317.  
  318. /**
  319. * List of KToolBarButton objects.
  320. * @internal
  321. * @version $Id: ktoolbarbutton.h 465272 2005-09-29 09:47:40Z mueller $
  322. */
  323. class KDEUI_EXPORT KToolBarButtonList : public QIntDict<KToolBarButton>
  324. {
  325. public:
  326.    KToolBarButtonList();
  327.    ~KToolBarButtonList() {}
  328. };
  329.  
  330. #endif
  331.