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 / kpushbutton.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.3 KB  |  162 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef KPUSHBUTTON_H
  21. #define KPUSHBUTTON_H
  22.  
  23. #include <qpoint.h>
  24. #include <qpushbutton.h>
  25. #include <kguiitem.h>
  26. #include <kstdguiitem.h> 
  27.  
  28. class QDragObject;
  29. /**
  30.  * This is nothing but a QPushButton with drag-support and KGuiItem support. You have to call
  31.  * setDragEnabled( true ) and override the virtual method
  32.  * dragObject() to specify the QDragObject to be used.
  33.  *
  34.  * @short A QPushButton with drag-support and KGuiItem support
  35.  * @author Carsten Pfeiffer <pfeiffer@kde.org>
  36.  */
  37. class KDEUI_EXPORT KPushButton : public QPushButton
  38. {
  39.     Q_OBJECT
  40.     Q_PROPERTY(int stdItem READ guiItm WRITE setGuiItm )
  41.     Q_PROPERTY(bool isDragEnabled READ isDragEnabled WRITE setDragEnabled)
  42.  
  43. public:
  44.  
  45.     /**
  46.      * Default constructor.
  47.      */
  48.     KPushButton( QWidget *parent, const char *name=0 );
  49.  
  50.     /**
  51.      * Constructor, that sets the button-text to @p text
  52.      */
  53.     KPushButton( const QString &text, QWidget *parent, const char *name=0);
  54.  
  55.     /**
  56.      * Constructor, that sets an icon and the button-text to @p text
  57.      */
  58.     KPushButton( const QIconSet &icon, const QString &text,
  59.              QWidget *parent, const char *name=0 );
  60.  
  61.     /**
  62.      * Constructor that takes a KGuiItem for the text, the icon, the tooltip
  63.      * and the what's this help
  64.      */
  65.     KPushButton( const KGuiItem &item, QWidget *parent, const char *name = 0 );
  66.  
  67.     /**
  68.      * Destructs the button.
  69.      */
  70.     ~KPushButton();
  71.  
  72.     /**
  73.      * Enables/disables drag-support. Default is disabled.
  74.      */
  75.     void setDragEnabled( bool enable );
  76.  
  77.     /**
  78.      * @returns if drag support is enabled or not.
  79.      */
  80.     bool isDragEnabled() const { return m_dragEnabled; }
  81.  
  82.     /**
  83.      * Sets the KGuiItem for this button.
  84.      */
  85.     void setGuiItem( const KGuiItem& item );
  86.  
  87.     /** 
  88.     * Sets the standard KGuiItem for this button.
  89.     * @since 3.4
  90.     */
  91.     void setGuiItem( KStdGuiItem::StdItem item );
  92.  
  93.     /**
  94.     * Reads the standard KGuiItem for this button. 
  95.     * @since 3.4
  96.     */
  97.     KStdGuiItem::StdItem guiItem() const;
  98.  
  99.     // Hack for Qt designer
  100.     void setGuiItm(int itm ) { setGuiItem( (KStdGuiItem::StdItem)itm );}
  101.     int guiItm() const { return (int)guiItem(); }
  102.  
  103.     /**
  104.      * Sets the Icon Set for this button. It also takes into account hte
  105.      * KGlobalSettings::showIconsOnPushButtons() setting.
  106.      */
  107.     void setIconSet( const QIconSet &iconSet );
  108.  
  109.     /**
  110.     * Sets the text of the button
  111.     */
  112.     void setText( const QString &text );
  113.  
  114. protected:
  115.     /**
  116.      * Reimplement this and return the QDragObject that should be used
  117.      * for the drag.
  118.      * Default implementation returns 0L, so that no drag is initiated.
  119.      */
  120.     virtual QDragObject * dragObject();
  121.  
  122.     /**
  123.      * Reimplemented to add drag-support
  124.      */
  125.     virtual void mousePressEvent( QMouseEvent * );
  126.     /**
  127.      * Reimplemented to add drag-support
  128.      */
  129.     virtual void mouseMoveEvent( QMouseEvent * );
  130.  
  131.     /**
  132.      * Starts a drag (dragCopy() by default) using dragObject()
  133.      */
  134.     virtual void startDrag();
  135.  
  136. private:
  137.     bool m_dragEnabled;
  138.     QPoint startPos;
  139.  
  140. private slots:
  141.     void slotSettingsChanged( int category );
  142.  
  143. private:
  144.     /**
  145.      * Internal.
  146.      * Initialize the KPushButton instance
  147.      */
  148.     void init( const KGuiItem &item );
  149.  
  150.     void readSettings();
  151.     static bool s_useIcons;
  152.  
  153. protected:
  154.     virtual void virtual_hook( int id, void* data );
  155. private:
  156.     class KPushButtonPrivate;
  157.     KPushButtonPrivate *d;
  158.  
  159. };
  160.  
  161. #endif // KPUSHBUTTON_H
  162.