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

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2000 Daniel M. Duley <mosfet@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 version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef _KPOPUP_H
  19. #define _KPOPUP_H "$Id: kpopupmenu.h 465272 2005-09-29 09:47:40Z mueller $"
  20.  
  21. #define INCLUDE_MENUITEM_DEF
  22.  
  23. #include <qpopupmenu.h>
  24. #include <kpixmapeffect.h>
  25. #include <kpixmap.h>
  26. #include <kdelibs_export.h>
  27. /**
  28.  * @short KPopupMenu title widget.
  29.  *
  30.  * Title widget for use in KPopupMenu.
  31.  *
  32.  * You usually don't have to create this manually since
  33.  * KPopupMenu::insertTitle will do it for you, but it is allowed if
  34.  * you wish to customize it's look.
  35.  *
  36.  * @author Daniel M. Duley <mosfet@kde.org>
  37.  */
  38. class KDEUI_EXPORT KPopupTitle : public QWidget
  39. {
  40.     Q_OBJECT
  41.  
  42. public:
  43.     /**
  44.      * Constructs a title widget with the user specified gradient, pixmap,
  45.      * and colors.
  46.      */
  47.     KPopupTitle(QWidget *parent=0, const char *name=0);
  48.     /**
  49.      * @deprecated
  50.      * Constructs a title widget with the specified gradient and colors.
  51.      */
  52.     KPopupTitle(KPixmapEffect::GradientType gradient, const QColor &color,
  53.                 const QColor &textColor, QWidget *parent=0,
  54.                 const char *name=0) KDE_DEPRECATED;
  55.     /**
  56.      * @deprecated
  57.      * Constructs a title widget with the specified pixmap and colors.
  58.      */
  59.     KPopupTitle(const KPixmap &background, const QColor &color,
  60.                 const QColor &textColor, QWidget *parent=0,
  61.                 const char *name=0) KDE_DEPRECATED;
  62.     /**
  63.      * Sets the title string and optional icon for the title widget.
  64.      *
  65.      * You will want to call this before inserting into a menu.
  66.      */
  67.     void setTitle(const QString &text, const QPixmap *icon=0);
  68.     /**
  69.      * Returns the current title.
  70.      */
  71.     QString title() const { return titleStr; }
  72.     /**
  73.      * Returns the current icon.
  74.      */
  75.     QPixmap icon() const { return miniicon; }
  76.  
  77.     QSize sizeHint() const;
  78.  
  79. public slots:
  80.     /// @since 3.1
  81.     void setText( const QString &text );
  82.     /// @since 3.1
  83.     void setIcon( const QPixmap &pix );
  84.  
  85. protected:
  86.     void calcSize();
  87.     void paintEvent(QPaintEvent *ev);
  88.  
  89.     // Remove in KDE4
  90.     KPixmapEffect::GradientType grType;
  91.     QString titleStr;
  92.     // Remove in KDE4
  93.     KPixmap fill;
  94.     QPixmap miniicon;
  95.     QColor fgColor, bgColor, grHigh, grLow;
  96.     bool useGradient;
  97.  
  98. protected:
  99.     virtual void virtual_hook( int id, void* data );
  100. private:
  101.     class KPopupTitlePrivate;
  102.     KPopupTitlePrivate *d;
  103. };
  104.  
  105. /**
  106.  * @short A menu with title items.
  107.  *
  108.  * KPopupMenu is a class for menus with standard title items and keyboard
  109.  * accessibility for popups with many options and/or varying options. It acts
  110.  * identically to QPopupMenu, with the addition of insertTitle(),
  111.  * changeTitle(), setKeyboardShortcutsEnabled() and
  112.  * setKeyboardShortcutsExecute() methods.
  113.  *
  114.  * The titles support a text string, an icon, plus user defined gradients,
  115.  * colors, and background pixmaps.
  116.  *
  117.  * The keyboard search algorithm is incremental with additional underlining
  118.  * for user feedback.
  119.  *
  120.  * @author Daniel M. Duley <mosfet@kde.org>
  121.  * @author Hamish Rodda <rodda@kde.org>
  122.  */
  123. class KDEUI_EXPORT KPopupMenu : public QPopupMenu {
  124.     Q_OBJECT
  125. public:
  126.     /**
  127.      * Constructs a KPopupMenu.
  128.      */
  129.     KPopupMenu(QWidget *parent=0, const char *name=0);
  130.  
  131.     /**
  132.      * Destructs the object
  133.      */
  134.     ~KPopupMenu();
  135.  
  136.     /**
  137.      * Inserts a title item with no icon.
  138.      */
  139.     int insertTitle(const QString &text, int id=-1, int index=-1);
  140.     /**
  141.      * Inserts a title item with the given icon and title.
  142.      */
  143.     int insertTitle(const QPixmap &icon, const QString &text, int id=-1,
  144.                     int index=-1);
  145.     /**
  146.      * Changes the title of the item at the specified id. If a icon was
  147.      * previously set it is cleared.
  148.      */
  149.     void changeTitle(int id, const QString &text);
  150.     /**
  151.      * Changes the title and icon of the title item at the specified id.
  152.      */
  153.     void changeTitle(int id, const QPixmap &icon, const QString &text);
  154.     /**
  155.      * Returns the title of the title item at the specified id. The default
  156.      * id of -1 is for backwards compatibility only, you should always specify
  157.      * the id.
  158.      */
  159.     QString title(int id=-1) const;
  160.     /**
  161.      * Returns the icon of the title item at the specified id.
  162.      */
  163.     QPixmap titlePixmap(int id) const;
  164.  
  165.     /**
  166.      * Enables keyboard navigation by searching for the entered key sequence.
  167.      * Also underlines the currently selected item, providing feedback on the search.
  168.      *
  169.      * Defaults to off.
  170.      *
  171.      * WARNING: calls to text() of currently keyboard-selected items will
  172.      * contain additional ampersand characters.
  173.      *
  174.      * WARNING: though pre-existing keyboard shortcuts will not interfere with the
  175.      * operation of this feature, they may be confusing to the user as the existing
  176.      * shortcuts will not work.
  177.      * @since 3.1
  178.      */
  179.     void setKeyboardShortcutsEnabled(bool enable);
  180.  
  181.     /**
  182.      * Enables execution of the menu item once it is uniquely specified.
  183.      * Defaults to off.
  184.      * @since 3.1
  185.      */
  186.     void setKeyboardShortcutsExecute(bool enable);
  187.  
  188.     /**
  189.      * @deprecated
  190.      * Obsolete method provided for backwards compatibility only. Use the
  191.      * normal constructor and insertTitle instead.
  192.      */
  193.     KPopupMenu(const QString &title, QWidget *parent=0, const char *name=0) KDE_DEPRECATED;
  194.  
  195.     /**
  196.      * @deprecated
  197.      * Obsolete method provided for backwards compatibility only. Use
  198.      * insertTitle and changeTitle instead.
  199.      */
  200.     void setTitle(const QString &title) KDE_DEPRECATED;
  201.  
  202.     /**
  203.      * Returns the context menu associated with this menu
  204.      * @since 3.2
  205.      */
  206.     QPopupMenu* contextMenu();
  207.  
  208.     /**
  209.      * Returns the context menu associated with this menu
  210.      * @since 3.2
  211.      */
  212.     const QPopupMenu* contextMenu() const;
  213.  
  214.     /**
  215.      * Hides the context menu if shown
  216.      * @since 3.2
  217.      */
  218.     void hideContextMenu();
  219.  
  220.     /**
  221.      * Returns the KPopupMenu associated with the current context menu
  222.      * @since 3.2
  223.      */
  224.     static KPopupMenu* contextMenuFocus();
  225.  
  226.     /**
  227.      * returns the ID of the menuitem associated with the current context menu
  228.      * @since 3.2
  229.      */
  230.     static int contextMenuFocusItem();
  231.  
  232.     /**
  233.      * Reimplemented for internal purposes
  234.      * @since 3.4
  235.      */
  236.     virtual void activateItemAt(int index);
  237.     /**
  238.      * Return the state of the mouse button and keyboard modifiers
  239.      * when the last menuitem was activated.
  240.      * @since 3.4
  241.      */
  242.     Qt::ButtonState state() const;
  243.  
  244. signals:
  245.     /**
  246.      * connect to this signal to be notified when a context menu is about to be shown
  247.      * @param menu The menu that the context menu is about to be shown for
  248.      * @param menuItem The menu item that the context menu is currently on
  249.      * @param ctxMenu The context menu itself
  250.      * @since 3.2
  251.      */
  252.     void aboutToShowContextMenu(KPopupMenu* menu, int menuItem, QPopupMenu* ctxMenu);
  253.  
  254. protected:
  255.     virtual void closeEvent(QCloseEvent *);
  256.     virtual void keyPressEvent(QKeyEvent* e);
  257.     /// @since 3.4
  258.     virtual void mouseReleaseEvent(QMouseEvent* e);
  259.     virtual void mousePressEvent(QMouseEvent* e);
  260.     virtual bool focusNextPrevChild( bool next );
  261.     virtual void contextMenuEvent(QContextMenuEvent *e);
  262.     virtual void hideEvent(QHideEvent*);
  263.  
  264.     virtual void virtual_hook( int id, void* data );
  265.  
  266. protected slots:
  267.     /// @since 3.1
  268.     QString underlineText(const QString& text, uint length);
  269.     /// @since 3.1
  270.     void resetKeyboardVars(bool noMatches = false);
  271.     void itemHighlighted(int whichItem);
  272.     void showCtxMenu(QPoint pos);
  273.     void ctxMenuHiding();
  274.     void ctxMenuHideShowingMenu();
  275.  
  276. private:
  277.     class KPopupMenuPrivate;
  278.     KPopupMenuPrivate *d;
  279. };
  280.  
  281. #endif
  282.