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 / kopalettemanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.9 KB  |  224 lines

  1. /*
  2.  *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.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, Boston, MA 02110-1301, USA.
  16.  */
  17.  
  18. #ifndef _KO_PALETTE_MANAGER_
  19. #define _KO_PALETTE_MANAGER_
  20.  
  21. #include <qobject.h>
  22. #include <qdockwindow.h>
  23. #include <qstring.h>
  24. #include <qmap.h>
  25. #include <qdict.h>
  26. #include <qvaluestack.h>
  27. #include <qwidget.h>
  28. #include <qsignalmapper.h>
  29. #include <qstringlist.h>
  30.  
  31. #include <koffice_export.h>
  32.  
  33. #include <KoView.h>
  34.  
  35. class KoPalette;
  36. class KActionMenu;
  37. class KAction;
  38. class KActionCollection;
  39. class KToggleAction;
  40.  
  41. enum enumKoDockability {
  42.     DOCK_ENABLED = 0, // It's possible to dock the dockers
  43.     DOCK_DISABLED = 1, // The dockers cannot be docked
  44.     DOCK_SMART = 2 // On small screens, don't dock, else dock, initially
  45. };
  46.  
  47. enum enumKoPaletteStyle {
  48.     PALETTE_DOCKER, // QDockWindow based docker with tabs
  49.     PALETTE_TOOLBOX // QDockWindow based docker with a QToolBox
  50. };
  51.  
  52.  
  53. namespace {
  54.     struct DockerRecord {
  55.         int position;
  56.         int x;
  57.         int y;
  58.         int w;
  59.         int h;
  60.     };
  61. }
  62.  
  63. /**
  64.  * Manages the set of dockwindow palettes and their widgets.
  65.  *
  66.  * You create one palette manager per view; then you can add widgets
  67.  * to your hearts content. Widgets are grouped into dock windows by
  68.  * palette names. To see the menu entries, add a the following line
  69.  * to your .rc file:
  70.  *
  71.  * <Action name="view_palette_action_menu"/>
  72.  *
  73.  * There are two styles: one that uses tabs and one that uses the vertical
  74.  * QToolBox style to separate and show individual widgets. By implementing
  75.  * the kopalette interface and extending the above enum, you can add
  76.  * more types.
  77.  *
  78.  * TODO:
  79.  *        - Drag & Drop
  80.  *        - Restore order of tabs in a docker
  81.  *        - Set initial position of floating dockers on first startup
  82.  *        - Restoration of the application default state
  83.  *        - Make it impossible to close a floating palette window with alt-f4
  84.  */
  85. class KOPALETTE_EXPORT KoPaletteManager : public QObject {
  86.  
  87.     Q_OBJECT
  88.  
  89.  
  90. public:
  91.  
  92.     KoPaletteManager(KoView * view, KActionCollection * ac, const char * name);
  93.     virtual ~KoPaletteManager();
  94.  
  95. public:
  96.     
  97.     /**
  98.      * Add a new tab with the given name an description to the specified palette.
  99.      * The widget's caption is used, where necessary. If there is no
  100.      * palette with this name, a new palette is created with the given palette name
  101.      * and the widget's caption.
  102.      *
  103.      * If there is already a widget with the given name, that widget will be
  104.      * unplugged (but not destroyed) and the given widget will be plugged in place.
  105.      *
  106.      * If the widget occurs in the saved configuration, it is not added to the
  107.      * specified palette, but in the place where it was left.
  108.      *
  109.      * @param widget the widget that will be inserted as a tab or entry in the palette
  110.      * @param name the name under which the palette will be stored. Not the caption -- do not i18n this.
  111.      * @param paletteName the unique name of the palette this widget will be a child of. If the palette already exists, the current widget is added to it.
  112.      * @param position the position of the widget in the palettes
  113.      * @param style docker, toolbox or slider
  114.      */
  115.     virtual void addWidget(QWidget * widget, const QString & name, const QString & paletteName, int position = -1, 
  116.                enumKoPaletteStyle style = PALETTE_DOCKER, bool shown = true);
  117.  
  118.  
  119.     /**
  120.      * Get a certain widget by name
  121.      */
  122.     virtual QWidget * widget(const QString & name);
  123.  
  124.     /**
  125.      * Show a the specified palette wherever it currently is.
  126.      */
  127.     virtual void showWidget(const QString & name);
  128.  
  129.     /**
  130.      * hide the specified widget
  131.      */
  132.     virtual void hideWidget(const QString & name);
  133.     
  134.     /**
  135.      * Remove the widget with the specified name from whichever
  136.      * palette it is currently in. If it is the last widget in
  137.      * the palette, the palette is destroyed. If the name does
  138.      * not occur, nothing is done.
  139.      */
  140.     virtual void removeWidget(const QString & name);
  141.  
  142.  
  143.     /**
  144.      * Create an empty palette in the given style. with the given name and caption. If
  145.      * the palette already exists, nothing is done.
  146.      */
  147.     virtual KoPalette * createPalette(const QString & name, const QString & caption, enumKoPaletteStyle style = PALETTE_DOCKER);
  148.  
  149.     /**
  150.      * Move the specified palette to the specified location. If there is already
  151.      * a location for the palette in the saved settings, then move it there
  152.      * instead of the specified location.
  153.      */
  154.     virtual void placePalette(const QString & name, Dock location = DockRight);
  155.  
  156.     /**
  157.      * Add a palette; this can be used to add palettes other than those in the two
  158.      * default styles.
  159.      */
  160.      virtual void addPalette(KoPalette * palette, const QString & name, Dock location = DockRight);
  161.  
  162.      /**
  163.       * Sets all palettes to the specified fixed width
  164.       */
  165.      virtual void setFixedWidth(int w);
  166.  
  167. public slots:
  168.  
  169.     void slotTogglePalette(int paletteIndex);
  170.     void slotToggleAllPalettes();
  171.     void showAllPalettes(bool shown);
  172.  
  173.     /**
  174.      * Restores the palette configuration to the default layout, i.e, the layout
  175.      * preferred by each docker.
  176.      */
  177.     virtual void slotReset();
  178.  
  179.     /**
  180.      * Reset the font for all palettes
  181.      */
  182.     virtual void slotResetFont();
  183.      
  184.  
  185. protected:
  186.  
  187.     bool eventFilter( QObject *o, QEvent *e );
  188.  
  189. private:
  190.  
  191.  
  192.     /**
  193.      * Saves the current palette configuration to the application config object.
  194.      */
  195.     virtual void save();
  196.  
  197.  
  198. private:
  199.  
  200.     KoView                  * m_view;
  201.     KActionCollection       * m_actionCollection;
  202.     KActionMenu             * m_viewActionMenu;
  203.     KToggleAction           * m_toggleShowHidePalettes;
  204.     enumKoDockability         m_dockability;
  205.     
  206.     QStringList             * m_widgetNames;
  207.  
  208.     QDict<QWidget>          * m_widgets;
  209.     QDict<KoPalette>        * m_palettes;
  210.     QValueStack<QString>   m_hiddenWidgets; // names of widgets actively hidden by hide all
  211.     QDict<KToggleAction>    * m_actions;
  212.     QSignalMapper           * m_mapper;
  213.  
  214.     QMap<QString, QString>  * m_defaultMapping; // widget to docker
  215.     QStringList               m_defaultPaletteOrder; // Order of palette creation
  216.     QStringList               m_defaultWidgetOrder; // Order of widget addition
  217.     QMap<QString, QString>  * m_currentMapping; // widget to docker
  218.  
  219.     bool m_setFixedWidth;
  220.     int m_fixedWidth;
  221. };
  222.  
  223. #endif
  224.