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 / kmdichildfrm.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  12.7 KB  |  447 lines

  1. //----------------------------------------------------------------------------
  2. //    filename             : kmdichildfrm.h
  3. //----------------------------------------------------------------------------
  4. //    Project              : KDE MDI extension
  5. //
  6. //    begin                : 07/1999       by Szymon Stefanek as part of kvirc
  7. //                                         (an IRC application)
  8. //    changes              : 09/1999       by Falk Brettschneider to create an
  9. //                           - 06/2000     stand-alone Qt extension set of
  10. //                                         classes and a Qt-based library
  11. //                           2000-2003     maintained by the KDevelop project
  12. //    patches              : */2000        Lars Beikirch (Lars.Beikirch@gmx.net)
  13. //
  14. //    copyright            : (C) 1999-2003 by Falk Brettschneider
  15. //                                         and
  16. //                                         Szymon Stefanek (stefanek@tin.it)
  17. //    email                :  falkbr@kdevelop.org (Falk Brettschneider)
  18. //----------------------------------------------------------------------------
  19. //
  20. //----------------------------------------------------------------------------
  21. //
  22. //    This program is free software; you can redistribute it and/or modify
  23. //    it under the terms of the GNU Library General Public License as
  24. //    published by the Free Software Foundation; either version 2 of the
  25. //    License, or (at your option) any later version.
  26. //
  27. //------------------------------------------------------------------------------
  28. #ifndef _KMDI_CHILD_FRM_H_
  29. #define _KMDI_CHILD_FRM_H_
  30.  
  31. #include <qptrlist.h>
  32. #include <qpixmap.h>
  33. #include <qpushbutton.h>
  34. #include <qlabel.h>
  35. #include <qdatetime.h>
  36. #include <qlayout.h>
  37.  
  38. #include <qdict.h>
  39.  
  40. #include "kmdichildfrmcaption.h"
  41.  
  42. class KMdiChildArea;
  43. class KMdiChildView;
  44. class QPopupMenu;
  45. class QToolButton;
  46.  
  47. //==============================================================================
  48. /**
  49.   * @short Internal class, only used on Win32.
  50.   * This class provides a label widget that can process mouse click events.
  51.   */
  52. class KMDI_EXPORT KMdiWin32IconButton : public QLabel
  53. {
  54.     Q_OBJECT
  55. public:
  56.     KMdiWin32IconButton( QWidget* parent, const char* name = 0 );
  57.     virtual void mousePressEvent( QMouseEvent* );
  58.  
  59. signals:
  60.     void pressed();
  61. };
  62.  
  63. //==============================================================================
  64. /* some special events, see kmdidefines.h
  65. */ 
  66. //------------------------------------------------------------------------------
  67. /**
  68.  * @short a QCustomEvent for move
  69.  * This special event will be useful, to inform view about child frame event.
  70.  */
  71. class KMDI_EXPORT KMdiChildFrmMoveEvent : public QCustomEvent
  72. {
  73. public:
  74.     KMdiChildFrmMoveEvent( QMoveEvent *e ) : QCustomEvent( QEvent::Type( QEvent::User + int( KMdi::EV_Move ) ), e ) {}
  75.  
  76. };
  77.  
  78. //------------------------------------------------------------------------------
  79. /**
  80.  * @short a QCustomEvent for begin of dragging
  81.  * This special event will be useful, to inform view about child frame event.
  82.  */
  83. class KMDI_EXPORT KMdiChildFrmDragBeginEvent : public QCustomEvent
  84. {
  85. public:
  86.     KMdiChildFrmDragBeginEvent( QMouseEvent *e ) : QCustomEvent( QEvent::Type( QEvent::User + int( KMdi::EV_DragBegin ) ), e ) {}
  87. };
  88.  
  89. //------------------------------------------------------------------------------
  90. /**
  91.  * @short a QCustomEvent for end of dragging
  92.  * This special event will be useful, to inform view about child frame event.
  93.  */
  94. class KMDI_EXPORT KMdiChildFrmDragEndEvent : public QCustomEvent
  95. {
  96. public:
  97.     KMdiChildFrmDragEndEvent( QMouseEvent *e ) : QCustomEvent( QEvent::Type( QEvent::User + int( KMdi::EV_DragEnd ) ), e ) {}
  98. };
  99.  
  100. //------------------------------------------------------------------------------
  101. /**
  102.  * @short a QCustomEvent for begin of resizing
  103.  * This special event will be useful, to inform view about child frame event.
  104.  */
  105. class KMDI_EXPORT KMdiChildFrmResizeBeginEvent : public QCustomEvent
  106. {
  107. public:
  108.     KMdiChildFrmResizeBeginEvent( QMouseEvent *e ) : QCustomEvent( QEvent::Type( QEvent::User + int( KMdi::EV_ResizeBegin ) ), e ) {}
  109. };
  110.  
  111. //------------------------------------------------------------------------------
  112. /**
  113.  * @short a QCustomEvent for end of resizing
  114.  * This special event will be useful, to inform view about child frame event.
  115.  */
  116. class KMDI_EXPORT KMdiChildFrmResizeEndEvent : public QCustomEvent
  117. {
  118. public:
  119.     KMdiChildFrmResizeEndEvent( QMouseEvent *e ) : QCustomEvent( QEvent::Type( QEvent::User + int( KMdi::EV_ResizeEnd ) ), e ) {}
  120. };
  121.  
  122.  
  123. class KMdiChildFrmPrivate;
  124. //==============================================================================
  125. /**
  126.   * @short Internal class.
  127.   * It's an MDI child frame widget. It contains a view widget and a frame caption. Usually you derive from its view.
  128.   */ 
  129. //------------------------------------------------------------------------------
  130. class KMDI_EXPORT KMdiChildFrm : public QFrame
  131. {
  132.     friend class KMdiChildArea;
  133.     friend class KMdiChildFrmCaption;
  134.  
  135.     Q_OBJECT
  136.  
  137.     // attributes
  138. public:
  139.     enum MdiWindowState { Normal, Maximized, Minimized };
  140.     //positions same in h and cpp for fast order check
  141.     KMdiChildView* m_pClient;
  142.  
  143. protected:
  144.     KMdiChildArea* m_pManager;
  145.     KMdiChildFrmCaption* m_pCaption;
  146.     KMdiWin32IconButton* m_pWinIcon;
  147.     QToolButton* m_pUnixIcon;
  148.     QToolButton* m_pMinimize;
  149.     QToolButton* m_pMaximize;
  150.     QToolButton* m_pClose;
  151.     QToolButton* m_pUndock;
  152.     MdiWindowState m_state;
  153.     QRect m_restoredRect;
  154.     int m_iResizeCorner;
  155.     int m_iLastCursorCorner;
  156.     bool m_bResizing;
  157.     bool m_bDragging;
  158.     QPixmap* m_pIconButtonPixmap;
  159.     QPixmap* m_pMinButtonPixmap;
  160.     QPixmap* m_pMaxButtonPixmap;
  161.     QPixmap* m_pRestoreButtonPixmap;
  162.     QPixmap* m_pCloseButtonPixmap;
  163.     QPixmap* m_pUndockButtonPixmap;
  164.     
  165.     /**
  166.     * Every child frame window has an temporary ID in the Window menu of the child area.
  167.     */
  168.     int m_windowMenuID;
  169.     
  170.     /**
  171.     * Imitates a system menu for child frame windows
  172.     */
  173.     QPopupMenu* m_pSystemMenu;
  174.     
  175.     QSize m_oldClientMinSize;
  176.     QSize m_oldClientMaxSize;
  177.     QLayout::ResizeMode m_oldLayoutResizeMode;
  178.     QTime m_timeMeasure;
  179.  
  180.     // methods
  181. public:
  182.     
  183.     /**
  184.      * Creates a new KMdiChildFrm class.
  185.      */
  186.     KMdiChildFrm( KMdiChildArea *parent );
  187.     
  188.     /**
  189.      * Destroys this KMdiChildFrm
  190.      * If a child is still here managed (no recreation was made) it is destroyed too.
  191.      */
  192.     ~KMdiChildFrm();
  193.     
  194.     /**
  195.      * Reparents the widget w to this KMdiChildFrm (if this is not already done)
  196.      * Installs an event filter to catch focus events.
  197.      * Resizes this mdi child in a way that the child fits perfectly in.
  198.      */
  199.     void setClient( KMdiChildView *w, bool bAutomaticResize = false );
  200.     
  201.     /**
  202.      * Reparents the client widget to 0 (desktop), moves with an offset from the original position
  203.      * Removes the event filter.
  204.      */
  205.     void unsetClient( QPoint positionOffset = QPoint( 0, 0 ) );
  206.     
  207.     /**
  208.      * Sets the window icon pointer.
  209.      */
  210.     void setIcon( const QPixmap &pxm );
  211.     
  212.     /**
  213.      * Returns the child frame icon.
  214.      */
  215.     QPixmap* icon() const;
  216.     
  217.     /**
  218.      * Enables or disables the close button
  219.      */
  220.     void enableClose( bool bEnable );
  221.     
  222.     /**
  223.      * Sets the caption of this window
  224.      */
  225.     void setCaption( const QString& text );
  226.     
  227.     /**
  228.       * Gets the caption of this mdi child.
  229.      */
  230.     const QString& caption() { return m_pCaption->m_szCaption; }
  231.     
  232.     /**
  233.      * Minimizes, Maximizes, or restores the window.
  234.      */
  235.     void setState( MdiWindowState state, bool bAnimate = true );
  236.     
  237.     /**
  238.      * Returns the current state of the window
  239.      */
  240.     inline MdiWindowState state() const { return m_state; }
  241.     
  242.     /**
  243.      * Returns the inner client area of the parent of this (which is KMdiChildArea).
  244.      */
  245.     QRect mdiAreaContentsRect() const;
  246.     
  247.     /**
  248.      * Returns the geometry that will be restored by calling restore().
  249.      */
  250.     QRect restoreGeometry() const;
  251.     
  252.     /**
  253.      * Sets the geometry that will be restored by calling restore().
  254.      */
  255.     void setRestoreGeometry( const QRect& newRestGeo );
  256.     
  257.     /**
  258.      * Forces updating the rects of the caption and so...
  259.      * It may be useful when setting the mdiCaptionFont of the MdiManager
  260.      */
  261.     void updateRects() { resizeEvent( 0 ); }
  262.     
  263.     /**
  264.      * Returns the system menu.
  265.      */
  266.     QPopupMenu* systemMenu() const;
  267.     
  268.     /**
  269.      * Returns the caption bar height 
  270.      */
  271.     inline int captionHeight() const { return m_pCaption->height(); }
  272.     
  273.     /**
  274.      * sets new raise behavior and pixmaps of the buttons depending on the current decoration style
  275.      */
  276.     void redecorateButtons();
  277.  
  278.     /**
  279.      * returns the mouse state "In Drag"
  280.      */
  281.     bool isInDrag() const { return m_bDragging; }
  282.     
  283.     /**
  284.      * returns the mouse state "In Resize"
  285.      */
  286.     bool isInResize() const { return m_bResizing; }
  287.     
  288.     /**
  289.      * Internally called from the signal focusInEventOccurs.
  290.      * It raises the MDI childframe to the top of all other MDI child frames and sets the focus on it.
  291.      */
  292.     void raiseAndActivate();
  293.  
  294.     /**
  295.      * Sets the minimum size of the widget to w by h pixels.
  296.      * It extends it's base clase method in a way that the minimum size of
  297.      * the child area will be set additionally if the view is maximized.
  298.      */
  299.     virtual void setMinimumSize ( int minw, int minh );
  300.  
  301. public slots:
  302.     
  303.     void slot_resizeViaSystemMenu();
  304.  
  305. protected:
  306.     
  307.     /**
  308.      * Reimplemented from the base class.
  309.      * Resizes the captionbar, relayouts the position of the system buttons,
  310.      * and calls resize for its embedded KMdiChildView with the proper size
  311.      */
  312.     virtual void resizeEvent( QResizeEvent * );
  313.     
  314.     /**
  315.      * Reimplemented from the base class.
  316.      * Detects if the mouse is on the edge of window and what resize cursor must be set.
  317.      * Calls KMdiChildFrm::resizeWindow if it is in m_bResizing.
  318.      */
  319.     virtual void mouseMoveEvent( QMouseEvent *e );
  320.     
  321.     /**
  322.      * Reimplemented from the base class.
  323.      * Colours the caption, raises the childfrm widget and
  324.      * turns to resize mode if it is on the edge (resize-sensitive area)
  325.      */
  326.     virtual void mousePressEvent( QMouseEvent *e );
  327.     
  328.     /**
  329.      * Reimplemented from the base class.
  330.      * Sets a normal cursor and leaves the resize mode.
  331.      */
  332.     virtual void mouseReleaseEvent( QMouseEvent * );
  333.     
  334.     /**
  335.      * Reimplemented from the base class.
  336.      * give its child view the chance to notify a childframe move... that's why it sends
  337.      * a KMdiChildMovedEvent to the embedded KMdiChildView .
  338.      */
  339.     virtual void moveEvent( QMoveEvent* me );
  340.     
  341.     /**
  342.      * Reimplemented from the base class. If not in resize mode, it sets the mouse cursor to normal appearance.
  343.      */
  344.     virtual void leaveEvent( QEvent * );
  345.     
  346.     /** 
  347.      * Reimplemented from the base class.
  348.      * In addition, the following are caught
  349.      * -the client's mousebutton press events which raises and activates the childframe
  350.      * -the client's resize event which resizes this widget as well
  351.      */
  352.     virtual bool eventFilter( QObject*, QEvent* ); 
  353.     
  354.     /**
  355.      * Calculates the new geometry from the new mouse position given as parameters
  356.      * and calls KMdiChildFrm::setGeometry
  357.      */
  358.     void resizeWindow( int resizeCorner, int x, int y );
  359.     
  360.     /**
  361.      * Override the cursor appearance depending on the widget corner given as parameter
  362.      */
  363.     void setResizeCursor( int resizeCorner );
  364.     
  365.     /**
  366.      * Changes from the resize cursor to the normal (previous) cursor
  367.      */
  368.     void unsetResizeCursor();
  369.     
  370.     /**
  371.      * That means to show a mini window showing the childframe's caption bar, only.
  372.      * It cannot be resized.
  373.      */
  374.     virtual void switchToMinimizeLayout();
  375.     
  376.     /**
  377.      * Does the actual resize. Called from various places but from resizeEvent in general.
  378.      */
  379.     void doResize();
  380.     
  381.     /**
  382.      * Does the actual resize, like doResize() but skips resize of the client if \a captionOnly is true.
  383.      * @todo: merge with doResize()
  384.      */
  385.     void doResize( bool captionOnly );
  386.  
  387. protected slots:
  388.     
  389.     /**
  390.      * Handles a click on the Maximize button
  391.      */
  392.     void maximizePressed();
  393.     
  394.     /**
  395.      * Handles a click on the Restore (Normalize) button
  396.      */
  397.     void restorePressed();
  398.     
  399.     /**
  400.      * Handles a click on the Minimize button.
  401.      */
  402.     void minimizePressed();
  403.     
  404.     /**
  405.      * Handles a click on the Close button.
  406.      */
  407.     void closePressed();
  408.     
  409.     /**
  410.      * Handles a click on the Undock (Detach) button
  411.      */
  412.     void undockPressed();
  413.     
  414.     /**
  415.      * Shows a system menu for child frame windows.
  416.      */
  417.     void showSystemMenu();
  418.  
  419. protected:
  420.  
  421.     /**
  422.      * Restore the focus policies for _all_ widgets in the view using the list given as parameter.
  423.      * Install the event filter for all direct child widgets of this. (See KMdiChildFrm::eventFilter)
  424.      */
  425.     void linkChildren( QDict<FocusPolicy>* pFocPolDict );
  426.  
  427.     /**
  428.      * Backups all focus policies of _all_ child widgets in the MDI childview since they get lost during a reparent.
  429.      * Remove all event filters for all direct child widgets of this. (See KMdiChildFrm::eventFilter)
  430.      */
  431.     QDict<QWidget::FocusPolicy>* unlinkChildren();
  432.     
  433.     /**
  434.      * Calculates the corner id for the resize cursor. The return value can be tested for:
  435.      * KMDI_RESIZE_LEFT, KMDI_RESIZE_RIGHT, KMDI_RESIZE_TOP, KMDI_RESIZE_BOTTOM
  436.      * or an OR'd variant of them for the corners.
  437.      */
  438.     int getResizeCorner( int ax, int ay );
  439.  
  440. private:
  441.     KMdiChildFrmPrivate *d;
  442. };
  443.  
  444. #endif //_KMDICHILDFRM_H_
  445.  
  446. // kate: space-indent off; replace-tabs off; tab-width 4; indent-mode csands;
  447.