1 // File: QtxWorkstack.cxx
2 // Author: Sergey TELKOV
4 #include "QtxWorkstack.h"
11 #include <qsplitter.h>
12 #include <qpopupmenu.h>
13 #include <qobjectlist.h>
14 #include <qpushbutton.h>
15 #include <qwidgetstack.h>
16 #include <qapplication.h>
19 Class: QtxWorkstack [Public]
23 QtxWorkstack::QtxWorkstack( QWidget* parent )
28 QVBoxLayout* base = new QVBoxLayout( this );
29 mySplit = new QSplitter( this );
30 mySplit->setChildrenCollapsible( false );
31 base->addWidget( mySplit );
34 QtxWorkstack::~QtxWorkstack()
38 QWidgetList QtxWorkstack::windowList() const
40 QPtrList<QtxWorkstackArea> lst;
41 areas( mySplit, lst, true );
44 for ( QPtrListIterator<QtxWorkstackArea> it( lst ); it.current(); ++it )
46 QWidgetList wids = it.current()->widgetList();
47 for ( QWidgetListIt itr( wids ); itr.current(); ++itr )
48 widList.append( itr.current() );
54 QWidgetList QtxWorkstack::splitWindowList() const
56 return myArea ? myArea->widgetList() : QWidgetList();
59 QWidget* QtxWorkstack::activeWindow() const
64 void QtxWorkstack::split( const int o )
66 QtxWorkstackArea* area = activeArea();
70 if ( area->widgetList().count() < 2 )
73 QWidget* curWid = area->activeWidget();
77 QSplitter* s = splitter( area );
78 QPtrList<QtxWorkstackArea> areaList;
81 QPtrList<QSplitter> splitList;
82 splitters( s, splitList );
85 if ( areaList.count() + splitList.count() < 2 || s->orientation() == o )
89 trg = wrapSplitter( area );
94 trg->setOrientation( (Orientation)o );
96 QtxWorkstackArea* newArea = createArea( 0 );
97 insertWidget( newArea, trg, area );
99 area->removeWidget( curWid );
100 newArea->insertWidget( curWid );
106 void QtxWorkstack::splitVertical()
108 split( Qt::Vertical );
111 void QtxWorkstack::splitHorizontal()
113 split( Qt::Horizontal );
116 QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area )
121 QSplitter* pSplit = splitter( area );
125 bool upd = pSplit->isUpdatesEnabled();
126 pSplit->setUpdatesEnabled( false );
128 QIntList szList = pSplit->sizes();
130 QSplitter* wrap = new QSplitter( 0 );
131 wrap->setChildrenCollapsible( false );
132 insertWidget( wrap, pSplit, area );
133 area->reparent( wrap, QPoint( 0, 0 ), true );
135 pSplit->setSizes( szList );
137 pSplit->setUpdatesEnabled( upd );
142 void QtxWorkstack::insertWidget( QWidget* wid, QWidget* pWid, QWidget* after )
147 QWidgetList moveList;
148 const QObjectList* lst = pWid->children();
152 for ( QObjectListIt it( *lst ); it.current(); ++it )
154 if ( found && ( it.current()->inherits( "QSplitter" ) ||
155 it.current()->inherits( "QtxWorkstackArea" ) ) )
156 moveList.append( (QWidget*)it.current() );
157 if ( it.current() == after )
162 QMap<QWidget*, bool> map;
163 for ( QWidgetListIt it( moveList ); it.current(); ++it )
165 map.insert( it.current(), it.current()->isVisibleTo( it.current()->parentWidget() ) );
166 it.current()->reparent( 0, QPoint( 0, 0 ), false );
169 wid->reparent( pWid, QPoint( 0, 0 ), true );
171 for ( QWidgetListIt itr( moveList ); itr.current(); ++itr )
172 itr.current()->reparent( pWid, QPoint( 0, 0 ), map.contains( itr.current() ) ? map[itr.current()] : false );
175 void QtxWorkstack::onPopupActivated( int id )
182 case SplitHorizontal:
186 if ( activeWindow() )
187 activeWindow()->close();
192 void QtxWorkstack::onDestroyed( QObject* obj )
194 QtxWorkstackArea* area = (QtxWorkstackArea*)obj;
196 if ( area == myArea )
201 QtxWorkstackArea* cur = neighbourArea( area );
206 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
209 void QtxWorkstack::onWindowActivated( QWidget* wid )
211 const QObject* obj = sender();
212 if ( !obj->inherits( "QtxWorkstackArea" ) )
215 setActiveArea( (QtxWorkstackArea*)obj );
218 void QtxWorkstack::onDeactivated( QtxWorkstackArea* area )
220 if ( myArea != area )
223 QPtrList<QtxWorkstackArea> lst;
224 areas( mySplit, lst, true );
226 int idx = lst.find( area );
230 QtxWorkstackArea* newArea = neighbourArea( area );
234 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
237 void QtxWorkstack::onContextMenuRequested( QPoint p )
242 QWidgetList lst = activeArea()->widgetList();
246 QPopupMenu* pm = new QPopupMenu();
247 connect( pm, SIGNAL( activated( int ) ), this, SLOT( onPopupActivated( int ) ) );
249 if ( lst.count() > 1 )
251 pm->insertItem( tr( "Split vertically" ), SplitVertical );
252 pm->insertItem( tr( "Split horizontally" ), SplitHorizontal );
253 pm->insertSeparator();
255 pm->insertItem( tr( "Close" ), Close );
262 void QtxWorkstack::childEvent( QChildEvent* e )
264 if ( e->inserted() && e->child()->isWidgetType() )
266 QWidget* w = (QWidget*)e->child();
267 if ( w && w != mySplit )
269 targetArea()->insertWidget( w );
273 QWidget::childEvent( e );
276 void QtxWorkstack::customEvent( QCustomEvent* e )
281 QSplitter* QtxWorkstack::splitter( QtxWorkstackArea* area ) const
286 QSplitter* split = 0;
288 QWidget* wid = area->parentWidget();
289 if ( wid && wid->inherits( "QSplitter" ) )
290 split = (QSplitter*)wid;
295 void QtxWorkstack::splitters( QSplitter* split, QPtrList<QSplitter>& splitList, const bool rec ) const
300 const QObjectList* objs = split->children();
303 for ( QObjectListIt it( *objs ); it.current(); ++it )
306 splitters( (QSplitter*)it.current(), splitList, rec );
307 if ( it.current()->inherits( "QSplitter" ) )
308 splitList.append( (QSplitter*)it.current() );
313 void QtxWorkstack::areas( QSplitter* split, QPtrList<QtxWorkstackArea>& areaList, const bool rec ) const
318 const QObjectList* objs = split->children();
321 for ( QObjectListIt it( *objs ); it.current(); ++it )
323 if ( it.current()->inherits( "QtxWorkstackArea" ) )
324 areaList.append( (QtxWorkstackArea*)it.current() );
325 else if ( rec && it.current()->inherits( "QSplitter" ) )
326 areas( (QSplitter*)it.current(), areaList, rec );
331 QtxWorkstackArea* QtxWorkstack::activeArea() const
336 QtxWorkstackArea* QtxWorkstack::targetArea()
338 QtxWorkstackArea* area = activeArea();
340 area = currentArea();
343 QPtrList<QtxWorkstackArea> lst;
344 areas( mySplit, lst );
345 if ( !lst.isEmpty() )
350 area = createArea( mySplit );
355 QtxWorkstackArea* QtxWorkstack::currentArea() const
357 QtxWorkstackArea* area = 0;
358 QWidget* wid = focusWidget();
359 while ( wid && !area )
361 if ( wid->inherits( "QtxWorkstackArea" ) )
362 area = (QtxWorkstackArea*)wid;
363 wid = wid->parentWidget();
369 QtxWorkstackArea* QtxWorkstack::createArea( QWidget* parent ) const
371 QtxWorkstackArea* area = new QtxWorkstackArea( parent );
373 connect( area, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
374 connect( area, SIGNAL( activated( QWidget* ) ), this, SLOT( onWindowActivated( QWidget* ) ) );
375 connect( area, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onContextMenuRequested( QPoint ) ) );
376 connect( area, SIGNAL( deactivated( QtxWorkstackArea* ) ), this, SLOT( onDeactivated( QtxWorkstackArea* ) ) );
381 void QtxWorkstack::setActiveArea( QtxWorkstackArea* area )
383 QWidget* oldCur = myWin;
385 QtxWorkstackArea* oldArea = myArea;
389 if ( myArea != oldArea )
392 oldArea->updateActiveState();
394 myArea->updateActiveState();
398 myWin = myArea->activeWidget();
400 if ( myWin && oldCur != myWin )
401 emit windowActivated( myWin );
404 QtxWorkstackArea* QtxWorkstack::neighbourArea( QtxWorkstackArea* area ) const
406 QPtrList<QtxWorkstackArea> lst;
407 areas( mySplit, lst, true );
408 int pos = lst.find( area );
412 QtxWorkstackArea* na = 0;
413 for ( int i = pos - 1; i >= 0 && !na; i-- )
415 if ( !lst.at( i )->isEmpty() )
419 for ( int j = pos + 1; j < (int)lst.count() && !na; j++ )
421 if ( !lst.at( j )->isEmpty() )
427 QtxWorkstackArea* QtxWorkstack::areaAt( const QPoint& p ) const
429 QtxWorkstackArea* area = 0;
430 QPtrList<QtxWorkstackArea> lst;
431 areas( mySplit, lst, true );
432 for ( QPtrListIterator<QtxWorkstackArea> it( lst ); it.current() && !area; ++it )
434 QtxWorkstackArea* cur = it.current();
435 QRect r = cur->geometry();
436 if ( cur->parentWidget() )
437 r = QRect( cur->parentWidget()->mapToGlobal( r.topLeft() ), r.size() );
438 if ( r.contains( p ) )
444 void QtxWorkstack::updateState()
446 updateState( mySplit );
449 void QtxWorkstack::updateState( QSplitter* split )
451 QPtrList<QSplitter> recList;
452 splitters( split, recList, false );
453 for ( QPtrListIterator<QSplitter> itr( recList ); itr.current(); ++itr )
454 updateState( itr.current() );
456 QPtrList<QSplitter> splitList;
457 splitters( split, splitList, false );
459 QPtrList<QtxWorkstackArea> areaList;
460 areas( split, areaList, false );
463 for ( QPtrListIterator<QtxWorkstackArea> it( areaList ); it.current(); ++it )
465 if ( it.current()->isEmpty() )
466 it.current()->hide();
469 it.current()->show();
474 if ( split == mySplit )
477 if ( areaList.isEmpty() && splitList.isEmpty() )
486 Class: QtxWorkstackArea [Internal]
490 QtxWorkstackArea::QtxWorkstackArea( QWidget* parent )
493 QVBoxLayout* base = new QVBoxLayout( this );
495 QHBox* top = new QHBox( this );
496 base->addWidget( top );
498 myBar = new QtxWorkstackTabBar( top );
500 QPushButton* close = new QPushButton( top );
501 close->setPixmap( style().stylePixmap( QStyle::SP_TitleBarCloseButton ) );
502 close->setAutoDefault( true );
503 close->setFlat( true );
506 top->setStretchFactor( myBar, 1 );
508 myStack = new QWidgetStack( this );
510 base->addWidget( myStack, 1 );
512 connect( myClose, SIGNAL( clicked() ), this, SLOT( onClose() ) );
513 connect( myBar, SIGNAL( selected( int ) ), this, SLOT( onSelected( int ) ) );
514 connect( myBar, SIGNAL( dragActiveTab() ), this, SLOT( onDragActiveTab() ) );
515 connect( myBar, SIGNAL( contextMenuRequested( QPoint ) ), this, SIGNAL( contextMenuRequested( QPoint ) ) );
521 qApp->installEventFilter( this );
524 QtxWorkstackArea::~QtxWorkstackArea()
526 qApp->removeEventFilter( this );
529 bool QtxWorkstackArea::isEmpty() const
532 for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !res; ++it )
537 void QtxWorkstackArea::insertWidget( QWidget* wid, const int idx )
542 int pos = myList.find( wid );
543 if ( pos != -1 && ( pos == idx || ( idx < 0 && pos == (int)myList.count() - 1 ) ) )
546 myList.removeRef( wid );
547 pos = idx < 0 ? myList.count() : idx;
548 myList.insert( QMIN( pos, (int)myList.count() ), wid );
549 if ( !myInfo.contains( wid ) )
551 QtxWorkstackChild* child = new QtxWorkstackChild( wid, myStack );
552 myChild.insert( wid, child );
553 myInfo.insert( wid, WidgetInfo() );
554 myInfo[wid].id = generateId();
555 myInfo[wid].vis = wid->isVisibleTo( wid->parentWidget() );
557 connect( child, SIGNAL( destroyed( QObject* ) ), this, SLOT( onChildDestroyed( QObject* ) ) );
558 connect( child, SIGNAL( shown( QtxWorkstackChild* ) ), this, SLOT( onChildShown( QtxWorkstackChild* ) ) );
559 connect( child, SIGNAL( hided( QtxWorkstackChild* ) ), this, SLOT( onChildHided( QtxWorkstackChild* ) ) );
560 connect( child, SIGNAL( activated( QtxWorkstackChild* ) ), this, SLOT( onChildActivated( QtxWorkstackChild* ) ) );
561 connect( child, SIGNAL( captionChanged( QtxWorkstackChild* ) ), this, SLOT( onChildCaptionChanged( QtxWorkstackChild* ) ) );
566 setWidgetActive( wid );
569 void QtxWorkstackArea::removeWidget( QWidget* wid )
571 if ( !myList.contains( wid ) )
574 if ( myBar->tab( widgetId( wid ) ) )
575 myBar->removeTab( myBar->tab( widgetId( wid ) ) );
576 myStack->removeWidget( child( wid ) );
578 myList.remove( wid );
579 myInfo.remove( wid );
580 myChild.remove( wid );
584 if ( myList.isEmpty() )
590 QWidgetList QtxWorkstackArea::widgetList() const
593 for ( QWidgetListIt it( myList ); it.current(); ++it )
595 if ( widgetVisibility( it.current() ) )
596 lst.append( it.current() );
601 QWidget* QtxWorkstackArea::activeWidget() const
603 return widget( myBar->currentTab() );
606 void QtxWorkstackArea::setActiveWidget( QWidget* wid )
608 myBar->setCurrentTab( widgetId( wid ) );
611 bool QtxWorkstackArea::contains( QWidget* wid ) const
613 return myList.contains( wid );
616 void QtxWorkstackArea::show()
618 QMap<QWidget*, bool> map;
619 for ( QWidgetListIt it( myList ); it.current(); ++it )
621 map.insert( it.current(), isBlocked( it.current() ) );
622 setBlocked( it.current(), true );
627 for ( QWidgetListIt itr( myList ); itr.current(); ++itr )
628 setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false );
631 void QtxWorkstackArea::hide()
633 QMap<QWidget*, bool> map;
634 for ( QWidgetListIt it( myList ); it.current(); ++it )
636 map.insert( it.current(), isBlocked( it.current() ) );
637 setBlocked( it.current(), true );
642 for ( QWidgetListIt itr( myList ); itr.current(); ++itr )
643 setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false );
646 bool QtxWorkstackArea::isActive() const
648 QtxWorkstack* ws = workstack();
652 return ws->activeArea() == this;
655 void QtxWorkstackArea::updateActiveState()
657 myBar->setActive( isActive() );
660 QtxWorkstack* QtxWorkstackArea::workstack() const
662 QtxWorkstack* ws = 0;
663 QWidget* wid = parentWidget();
666 if ( wid->inherits( "QtxWorkstack" ) )
667 ws = (QtxWorkstack*)wid;
668 wid = wid->parentWidget();
673 bool QtxWorkstackArea::eventFilter( QObject* o, QEvent* e )
675 if ( o->isWidgetType() )
677 QWidget* wid = (QWidget*)o;
678 if ( e->type() == QEvent::FocusIn || e->type() == QEvent::MouseButtonPress )
681 while ( !ok && wid && wid != myClose )
684 wid = wid->parentWidget();
687 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)( e->type() == QEvent::FocusIn ? ActivateEvent : FocusEvent ) ) );
693 QRect QtxWorkstackArea::floatRect() const
695 QRect r = myStack->geometry();
696 return QRect( mapToGlobal( r.topLeft() ), mapToGlobal( r.bottomRight() ) );
699 QRect QtxWorkstackArea::floatTab( const int idx ) const
701 return myBar->tabRect( idx );
704 int QtxWorkstackArea::tabAt( const QPoint& p ) const
707 for ( int i = 0; i < myBar->count() && idx == -1; i++ )
709 QRect r = myBar->tabRect( i );
710 if ( r.isValid() && r.contains( p ) )
716 void QtxWorkstackArea::customEvent( QCustomEvent* e )
721 emit activated( activeWidget() );
724 if ( activeWidget() )
725 activeWidget()->setFocus();
728 removeWidget( (QWidget*)e->data() );
733 void QtxWorkstackArea::focusInEvent( QFocusEvent* e )
735 QWidget::focusInEvent( e );
737 emit activated( activeWidget() );
740 void QtxWorkstackArea::mousePressEvent( QMouseEvent* e )
742 QWidget::mousePressEvent( e );
744 emit activated( activeWidget() );
747 void QtxWorkstackArea::onClose()
749 QWidget* wid = activeWidget();
754 void QtxWorkstackArea::onSelected( int id )
758 emit activated( activeWidget() );
761 void QtxWorkstackArea::onDragActiveTab()
763 QtxWorkstackChild* c = child( activeWidget() );
767 new QtxWorkstackDrag( workstack(), c );
770 void QtxWorkstackArea::onChildDestroyed( QObject* obj )
772 QtxWorkstackChild* child = (QtxWorkstackChild*)obj;
773 myStack->removeWidget( child );
776 for ( ChildMap::ConstIterator it = myChild.begin(); it != myChild.end() && !wid; ++it )
778 if ( it.data() == child )
782 myChild.remove( wid );
784 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)RemoveEvent, wid ) );
787 void QtxWorkstackArea::onChildShown( QtxWorkstackChild* c )
789 setWidgetShown( c->widget(), true );
792 void QtxWorkstackArea::onChildHided( QtxWorkstackChild* c )
794 setWidgetShown( c->widget(), false );
797 void QtxWorkstackArea::onChildActivated( QtxWorkstackChild* c )
799 setWidgetActive( c->widget() );
802 void QtxWorkstackArea::onChildCaptionChanged( QtxWorkstackChild* c )
804 updateTab( c->widget() );
807 void QtxWorkstackArea::updateCurrent()
809 QMap<QWidget*, bool> map;
810 for ( QWidgetListIt it( myList ); it.current(); ++it )
812 map.insert( it.current(), isBlocked( it.current() ) );
813 setBlocked( it.current(), true );
816 myStack->raiseWidget( myBar->currentTab() );
818 for ( QWidgetListIt itr( myList ); itr.current(); ++itr )
819 setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false );
822 void QtxWorkstackArea::updateTab( QWidget* wid )
824 QTab* tab = myBar->tab( widgetId( wid ) );
830 icoSet = QIconSet( *wid->icon() );
832 tab->setIconSet( icoSet );
833 tab->setText( wid->caption() );
836 QWidget* QtxWorkstackArea::widget( const int id ) const
839 for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !wid; ++it )
841 if ( it.data().id == id )
847 int QtxWorkstackArea::widgetId( QWidget* wid ) const
850 if ( myInfo.contains( wid ) )
855 bool QtxWorkstackArea::widgetVisibility( QWidget* wid ) const
858 if ( myInfo.contains( wid ) )
859 res = myInfo[wid].vis;
863 void QtxWorkstackArea::setWidgetActive( QWidget* wid )
865 int id = widgetId( wid );
869 myBar->setCurrentTab( id );
872 void QtxWorkstackArea::setWidgetShown( QWidget* wid, const bool on )
874 if ( isBlocked( wid ) || !myInfo.contains( wid ) || myInfo[wid].vis == on )
877 myInfo[wid].vis = on;
881 void QtxWorkstackArea::updateState()
883 bool updBar = myBar->isUpdatesEnabled();
884 bool updStk = myStack->isUpdatesEnabled();
885 myBar->setUpdatesEnabled( false );
886 myStack->setUpdatesEnabled( false );
888 bool block = myBar->signalsBlocked();
889 myBar->blockSignals( true );
891 QWidget* prev = activeWidget();
894 for ( QWidgetListIt it( myList ); it.current(); ++it )
896 QWidget* wid = it.current();
897 int id = widgetId( wid );
902 bool vis = widgetVisibility( wid );
904 if ( myBar->tab( id ) && ( !vis || myBar->indexOf( id ) != idx ) )
905 myBar->removeTab( myBar->tab( id ) );
907 if ( !myBar->tab( id ) && vis )
909 QTab* tab = new QTab( wid->caption() );
910 myBar->insertTab( tab, idx );
911 tab->setIdentifier( id );
916 bool block = isBlocked( wid );
917 setBlocked( wid, true );
919 QtxWorkstackChild* cont = child( wid );
922 myStack->removeWidget( cont );
923 else if ( !myStack->widget( id ) )
924 myStack->addWidget( cont, id );
929 setBlocked( wid, block );
932 int curId = widgetId( prev );
933 if ( !myBar->tab( curId ) )
936 int pos = myList.find( prev );
937 for ( int i = pos - 1; i >= 0 && !wid; i-- )
939 if ( widgetVisibility( myList.at( i ) ) )
940 wid = myList.at( i );
943 for ( int j = pos + 1; j < (int)myList.count() && !wid; j++ )
945 if ( widgetVisibility( myList.at( j ) ) )
946 wid = myList.at( j );
950 curId = widgetId( wid );
953 myBar->setCurrentTab( curId );
955 myBar->blockSignals( block );
959 myBar->setUpdatesEnabled( updBar );
960 myStack->setUpdatesEnabled( updStk );
966 QResizeEvent re( myBar->size(), myBar->size() );
967 QApplication::sendEvent( myBar, &re );
972 emit deactivated( this );
977 if ( prev != activeWidget() )
978 emit activated( activeWidget() );
982 int QtxWorkstackArea::generateId() const
986 for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end(); ++it )
987 map.insert( it.data().id, 0 );
990 while ( map.contains( id ) )
996 bool QtxWorkstackArea::isBlocked( QWidget* wid ) const
998 return myBlock.contains( wid );
1001 void QtxWorkstackArea::setBlocked( QWidget* wid, const bool on )
1004 myBlock.insert( wid, 0 );
1006 myBlock.remove( wid );
1009 QtxWorkstackChild* QtxWorkstackArea::child( QWidget* wid ) const
1011 QtxWorkstackChild* res = 0;
1012 if ( myChild.contains( wid ) )
1018 Class: QtxWorkstackChild [Internal]
1022 QtxWorkstackChild::QtxWorkstackChild( QWidget* wid, QWidget* parent )
1026 myWidget->reparent( this, QPoint( 0, 0 ), myWidget->isVisibleTo( myWidget->parentWidget() ) );
1027 myWidget->installEventFilter( this );
1029 connect( myWidget, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
1032 QtxWorkstackChild::~QtxWorkstackChild()
1034 qApp->removeEventFilter( this );
1039 widget()->removeEventFilter( this );
1040 widget()->reparent( 0, QPoint( 0, 0 ), false );
1041 disconnect( widget(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
1044 QWidget* QtxWorkstackChild::widget() const
1049 bool QtxWorkstackChild::eventFilter( QObject* o, QEvent* e )
1051 if ( o->isWidgetType() )
1053 if ( e->type() == QEvent::CaptionChange || e->type() == QEvent::IconChange )
1054 emit captionChanged( this );
1056 if ( !e->spontaneous() && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) )
1059 if ( !e->spontaneous() && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) )
1062 if ( e->type() == QEvent::FocusIn )
1063 emit activated( this );
1065 return QHBox::eventFilter( o, e );
1068 void QtxWorkstackChild::onDestroyed( QObject* obj )
1070 if ( obj != widget() )
1077 void QtxWorkstackChild::childEvent( QChildEvent* e )
1079 if ( e->type() == QEvent::ChildRemoved && e->child() == widget() )
1084 QHBox::childEvent( e );
1088 Class: QtxWorkstackTabBar [Internal]
1092 QtxWorkstackTabBar::QtxWorkstackTabBar( QWidget* parent )
1093 : QTabBar( parent ),
1098 QtxWorkstackTabBar::~QtxWorkstackTabBar()
1102 void QtxWorkstackTabBar::setActive( const bool on )
1104 QFont aFont = font();
1105 aFont.setUnderline( on );
1111 QRect QtxWorkstackTabBar::tabRect( const int idx ) const
1114 QTab* t = tabAt( idx );
1118 r.setLeft( QMAX( r.left(), 0 ) );
1120 int x1 = tabAt( 0 )->rect().left();
1121 int x2 = tabAt( count() - 1 )->rect().right();
1124 if ( QABS( x2 - x1 ) > width() )
1125 bw = 2 * style().pixelMetric( QStyle::PM_TabBarScrollButtonWidth, this );
1127 int limit = width() - bw;
1128 r.setRight( QMIN( r.right(), limit ) );
1130 r = QRect( mapToGlobal( r.topLeft() ), r.size() );
1135 void QtxWorkstackTabBar::mouseMoveEvent( QMouseEvent* e )
1137 if ( myId != -1 && !tab( myId )->rect().contains( e->pos() ) )
1140 emit dragActiveTab();
1143 QTabBar::mouseMoveEvent( e );
1146 void QtxWorkstackTabBar::mousePressEvent( QMouseEvent* e )
1148 QTabBar::mousePressEvent( e );
1150 if ( e->button() == LeftButton )
1151 myId = currentTab();
1154 void QtxWorkstackTabBar::mouseReleaseEvent( QMouseEvent* e )
1156 QTabBar::mouseReleaseEvent( e );
1160 if ( e->button() == RightButton )
1161 emit contextMenuRequested( e->globalPos() );
1164 void QtxWorkstackTabBar::contextMenuEvent( QContextMenuEvent* e )
1166 if ( e->reason() != QContextMenuEvent::Mouse )
1167 emit contextMenuRequested( e->globalPos() );
1170 void QtxWorkstackTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const
1172 if ( currentTab() != t->identifier() )
1174 QFont fnt = p->font();
1175 fnt.setUnderline( false );
1178 QTabBar::paintLabel( p, br, t, has_focus );
1182 Class: QtxWorkstackDrag [Internal]
1186 QtxWorkstackDrag::QtxWorkstackDrag( QtxWorkstack* ws, QtxWorkstackChild* child )
1194 qApp->installEventFilter( this );
1197 QtxWorkstackDrag::~QtxWorkstackDrag()
1199 qApp->removeEventFilter( this );
1204 bool QtxWorkstackDrag::eventFilter( QObject*, QEvent* e )
1206 switch ( e->type() )
1208 case QEvent::MouseMove:
1209 updateTarget( ((QMouseEvent*)e)->globalPos() );
1211 case QEvent::MouseButtonRelease:
1223 void QtxWorkstackDrag::updateTarget( const QPoint& p )
1226 QtxWorkstackArea* area = detectTarget( p, tab );
1227 setTarget( area, tab );
1230 QtxWorkstackArea* QtxWorkstackDrag::detectTarget( const QPoint& p, int& tab ) const
1235 QtxWorkstackArea* area = myWS->areaAt( p );
1237 tab = area->tabAt( p );
1241 void QtxWorkstackDrag::setTarget( QtxWorkstackArea* area, const int tab )
1243 if ( !area || ( myArea == area && tab == myTab ) )
1258 void QtxWorkstackDrag::dropWidget()
1261 myArea->insertWidget( myChild->widget(), myTab );
1264 void QtxWorkstackDrag::drawRect()
1266 if ( !myPainter || !myArea )
1269 QRect r = myArea->floatRect();
1270 int m = myPainter->pen().width();
1272 r.setTop( r.top() + m + 2 );
1273 r.setLeft( r.left() + m + 2 );
1274 r.setRight( r.right() - m - 2 );
1275 r.setBottom( r.bottom() - m - 2 );
1277 myPainter->drawRect( r );
1279 QRect tr = myArea->floatTab( myTab );
1280 tr.setTop( tr.top() + m );
1281 tr.setLeft( tr.left() + m );
1282 tr.setRight( tr.right() - m );
1283 tr.setBottom( tr.bottom() - m );
1285 myPainter->drawRect( tr );
1288 void QtxWorkstackDrag::endDrawRect()
1294 void QtxWorkstackDrag::startDrawRect()
1299 int scr = QApplication::desktop()->screenNumber( (QWidget*)this );
1300 QWidget* paint_on = QApplication::desktop()->screen( scr );
1302 myPainter = new QPainter( paint_on, true );
1303 myPainter->setPen( QPen( gray, 3 ) );
1304 myPainter->setRasterOp( XorROP );