00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef QTXWORKSTACK_H
00027 #define QTXWORKSTACK_H
00028
00029 #include "Qtx.h"
00030
00031 #include <QMap>
00032 #include <QFrame>
00033 #include <QEvent>
00034 #include <QWidget>
00035 #include <QTabBar>
00036 #include <QPointer>
00037 #include <QSplitter>
00038 #include <QByteArray>
00039
00040 class QAction;
00041 class QDataStream;
00042 class QRubberBand;
00043 class QStackedWidget;
00044 class QAbstractButton;
00045
00046 class QtxWorkstackArea;
00047 class QtxWorkstackDrag;
00048 class QtxWorkstackChild;
00049 class QtxWorkstackTabBar;
00050 class QtxWorkstackSplitter;
00051
00052 #ifdef WIN32
00053 #pragma warning( disable:4251 )
00054 #endif
00055
00056 class QTX_EXPORT QtxWorkstack : public QWidget
00057 {
00058 Q_OBJECT
00059
00060 public:
00062 enum { SplitVertical = 0x01,
00063 SplitHorizontal = 0x02,
00064 Close = 0x04,
00065 Rename = 0x08,
00066 All = SplitVertical | SplitHorizontal |
00067 Close | Rename
00068 };
00069
00070 enum { VersionMarker = 0x01,
00071 SplitMarker = 0x02,
00072 AreaMarker = 0x04,
00073 WidgetMarker = 0x08
00074 };
00075
00076 enum { Horizontal = 0x01,
00077 Visible = 0x02
00078 };
00079
00081 enum SplitType
00082 {
00083 SplitStay,
00084 SplitAt,
00085 SplitMove
00086 };
00087
00088 public:
00089 QtxWorkstack( QWidget* = 0 );
00090 virtual ~QtxWorkstack();
00091
00092 QWidgetList windowList( QWidget* = 0 ) const;
00093 QWidgetList splitWindowList() const;
00094
00095 QWidget* activeWindow() const;
00096
00097 int accel( const int ) const;
00098 void setAccel( const int, const int );
00099
00100 QIcon icon( const int ) const;
00101 void setIcon( const int, const QIcon& );
00102
00103 void setMenuActions( const int );
00104 int menuActions() const;
00105
00106 void stack();
00107 void split( const int );
00108 bool move( QWidget* wid, QWidget* wid_to, const bool before );
00109
00110 QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 );
00111
00112 QByteArray saveState( int ) const;
00113 bool restoreState( const QByteArray&, int );
00114
00115 void setOpaqueResize( bool = true );
00116 bool opaqueResize() const;
00117
00118 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
00119 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
00120 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
00121 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
00122
00123 signals:
00124 void windowActivated( QWidget* );
00125
00126 public slots:
00127 void splitVertical();
00128 void splitHorizontal();
00129
00130 private slots:
00131 void onRename();
00132 void onCloseWindow();
00133 void onDestroyed( QObject* );
00134 void onWindowActivated( QWidget* );
00135 void onContextMenuRequested( QWidget*, QPoint );
00136 void onDeactivated( QtxWorkstackArea* );
00137
00138 protected:
00139 virtual void customEvent( QEvent* );
00140
00141 QAction* action( const int ) const;
00142
00143 void saveState( QDataStream& ) const;
00144 bool restoreState( QDataStream& );
00145
00146 private:
00147 QSplitter* splitter( QtxWorkstackArea* ) const;
00148 void splitters( QSplitter*, QList<QSplitter*>&, const bool = false ) const;
00149 void areas( QSplitter*, QList<QtxWorkstackArea*>&, const bool = false ) const;
00150
00151 QSplitter* wrapSplitter( QtxWorkstackArea* );
00152 void insertWidget( QWidget*, QWidget*, QWidget* );
00153
00154 QtxWorkstackArea* areaAt( const QPoint& ) const;
00155 QtxWorkstackArea* wgArea( QWidget* ) const;
00156
00157 QtxWorkstackArea* targetArea();
00158 QtxWorkstackArea* activeArea() const;
00159 QtxWorkstackArea* currentArea() const;
00160
00161 void setActiveArea( QtxWorkstackArea* );
00162 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
00163
00164 QtxWorkstackArea* createArea( QWidget* ) const;
00165
00166 void updateState();
00167 void updateState( QSplitter* );
00168
00169 void distributeSpace( QSplitter* ) const;
00170
00171 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
00172 const int need_pos, const int splitter_pos );
00173
00174 private:
00175 QPointer<QWidget> myWin;
00176 QPointer<QtxWorkstackArea> myArea;
00177 QtxWorkstackSplitter* mySplit;
00178 QPointer<QWidget> myWorkWin;
00179 QPointer<QtxWorkstackArea> myWorkArea;
00180
00181 QMap<int, QAction*> myActionsMap;
00182
00183 friend class QtxWorkstackArea;
00184 friend class QtxWorkstackDrag;
00185 friend class QtxWorkstackAction;
00186 friend class QtxWorkstackSplitter;
00187 };
00188
00189 class QtxWorkstackSplitter : public QSplitter
00190 {
00191 Q_OBJECT
00192
00193 public:
00194 QtxWorkstackSplitter( QWidget* = 0 );
00195 virtual ~QtxWorkstackSplitter();
00196
00197 QtxWorkstack* workstack() const;
00198
00199 void saveState( QDataStream& ) const;
00200 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
00201 };
00202
00203 class QtxWorkstackArea : public QFrame
00204 {
00205 Q_OBJECT
00206
00207 class WidgetEvent;
00208 class RestoreEvent;
00209
00210 public:
00211 QtxWorkstackArea( QWidget* );
00212 virtual ~QtxWorkstackArea();
00213
00214 bool isNull() const;
00215 bool isEmpty() const;
00216
00217 QtxWorkstackChild* insertWidget( QWidget*, const int = -1, Qt::WindowFlags = 0 );
00218 void removeWidget( QWidget*, const bool = true );
00219
00220 void insertChild( QtxWorkstackChild*, const int = -1 );
00221 void removeChild( QtxWorkstackChild*, const bool = true );
00222
00223 QWidget* activeWidget() const;
00224 void setActiveWidget( QWidget* );
00225
00226 bool contains( QWidget* ) const;
00227
00228 QWidgetList widgetList() const;
00229 QList<QtxWorkstackChild*> childList() const;
00230
00231 bool isActive() const;
00232 void updateActiveState();
00233
00234 QtxWorkstack* workstack() const;
00235
00236 virtual bool eventFilter( QObject*, QEvent* );
00237
00238 QRect floatRect() const;
00239 QRect floatTab( const int ) const;
00240
00241 int tabAt( const QPoint& ) const;
00242
00243 void saveState( QDataStream& ) const;
00244 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
00245
00246 signals:
00247 void activated( QWidget* );
00248 void contextMenuRequested( QWidget*, QPoint );
00249 void deactivated( QtxWorkstackArea* );
00250
00251 private slots:
00252 void onClose();
00253 void onCurrentChanged( int );
00254
00255 void onChildDestroyed( QObject* );
00256 void onChildShown( QtxWorkstackChild* );
00257 void onChildHidden( QtxWorkstackChild* );
00258 void onChildActivated( QtxWorkstackChild* );
00259 void onChildCaptionChanged( QtxWorkstackChild* );
00260
00261 void onDragActiveTab();
00262 void onContextMenuRequested( QPoint );
00263
00264 protected:
00265 virtual void customEvent( QEvent* );
00266 virtual void focusInEvent( QFocusEvent* );
00267 virtual void mousePressEvent( QMouseEvent* );
00268
00269 private:
00271 enum { ActivateWidget = QEvent::User,
00272 FocusWidget,
00273 MakeCurrent,
00274 RestoreWidget
00275 };
00276
00277 private:
00278 void updateState();
00279 void updateCurrent();
00280 void updateTab( QWidget* );
00281
00282 QWidget* widget( const int ) const;
00283 int widgetId( QWidget* ) const;
00284
00285 QtxWorkstackChild* child( QWidget* ) const;
00286 QtxWorkstackChild* child( const int ) const;
00287
00288 void setWidgetActive( QWidget* );
00289
00290 int generateId() const;
00291
00292 private:
00293 typedef QList<QtxWorkstackChild*> ChildList;
00294
00295 private:
00296 QtxWorkstackTabBar* myBar;
00297 ChildList myList;
00298 QAbstractButton* myClose;
00299 QStackedWidget* myStack;
00300 };
00301
00302 class QtxWorkstackChild : public QWidget
00303 {
00304 Q_OBJECT
00305
00306 public:
00307 QtxWorkstackChild( QWidget*, QWidget* = 0, Qt::WindowFlags = 0 );
00308 virtual ~QtxWorkstackChild();
00309
00310 QWidget* widget() const
00311 ;
00312
00313 int id() const;
00314 void setId( const int );
00315
00316 bool visibility();
00317
00318 QtxWorkstackArea* area() const;
00319
00320 virtual bool eventFilter( QObject*, QEvent* );
00321
00322 signals:
00323 void shown( QtxWorkstackChild* );
00324 void hidden( QtxWorkstackChild* );
00325 void activated( QtxWorkstackChild* );
00326 void captionChanged( QtxWorkstackChild* );
00327
00328 private slots:
00329 void onDestroyed( QObject* );
00330
00331 protected:
00332 virtual void childEvent( QChildEvent* );
00333
00334 private:
00335 int myId;
00336 QPointer<QWidget> myWidget;
00337 };
00338
00339 class QtxWorkstackTabBar : public QTabBar
00340 {
00341 Q_OBJECT
00342
00343 public:
00344 QtxWorkstackTabBar( QWidget* = 0 );
00345 virtual ~QtxWorkstackTabBar();
00346
00347 bool isActive() const;
00348 void setActive( const bool );
00349
00350 int tabId( const int ) const;
00351 int indexOf( const int ) const;
00352 void setTabId( const int, const int );
00353
00354 void updateActiveState();
00355
00356 signals:
00357 void dragActiveTab();
00358 void contextMenuRequested( QPoint );
00359
00360 private slots:
00361 void onCurrentChanged( int );
00362
00363 protected:
00364 virtual void changeEvent( QEvent* );
00365 virtual void mouseMoveEvent( QMouseEvent* );
00366 virtual void mousePressEvent( QMouseEvent* );
00367 virtual void mouseReleaseEvent( QMouseEvent* );
00368 virtual void contextMenuEvent( QContextMenuEvent* );
00369
00370 private:
00371 int myId;
00372 bool myActive;
00373 };
00374
00375 class QtxWorkstackDrag : public QObject
00376 {
00377 Q_OBJECT
00378
00379 public:
00380 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
00381 virtual ~QtxWorkstackDrag();
00382
00383 virtual bool eventFilter( QObject*, QEvent* );
00384
00385 private:
00386 void dropWidget();
00387
00388 void updateTarget( const QPoint& );
00389 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
00390 void setTarget( QtxWorkstackArea*, const int );
00391
00392 void drawRect();
00393 void endDrawRect();
00394 void startDrawRect();
00395
00396 private:
00397 QtxWorkstack* myWS;
00398 QtxWorkstackChild* myChild;
00399
00400 int myTab;
00401 QtxWorkstackArea* myArea;
00402 QRubberBand* myTabRect;
00403 QRubberBand* myAreaRect;
00404 };
00405
00406 #ifdef WIN32
00407 #pragma warning( default:4251 )
00408 #endif
00409
00410 #endif // QTXWORKSTACK_H