1 // File: QtxWorkstack.cxx
2 // Author: Sergey TELKOV
4 #include "QtxWorkstack.h"
13 #include <qsplitter.h>
14 #include <qpopupmenu.h>
15 #include <qobjectlist.h>
16 #include <qpushbutton.h>
17 #include <qwidgetstack.h>
18 #include <qapplication.h>
19 #include <qinputdialog.h>
22 Class: QtxWorkstack [Public]
26 QtxWorkstack::QtxWorkstack( QWidget* parent )
32 myActionsMap.insert( SplitVertical, new QAction( tr( "Split vertically" ), 0, this ) );
33 myActionsMap.insert( SplitHorizontal, new QAction( tr( "Split horizontally" ), 0, this ) );
34 myActionsMap.insert( Close, new QAction( tr( "Close" ), 0, this ) );
35 myActionsMap.insert( Rename, new QAction( tr( "Rename" ), 0, this ) );
37 connect( myActionsMap[SplitVertical], SIGNAL( activated() ), this, SLOT( splitVertical() ) );
38 connect( myActionsMap[SplitHorizontal], SIGNAL( activated() ), this, SLOT( splitHorizontal() ) );
39 connect( myActionsMap[Close], SIGNAL( activated() ), this, SLOT( onCloseWindow() ) );
40 connect( myActionsMap[Rename], SIGNAL( activated() ), this, SLOT( onRename() ) );
42 QVBoxLayout* base = new QVBoxLayout( this );
43 mySplit = new QSplitter( this );
44 mySplit->setChildrenCollapsible( false );
45 base->addWidget( mySplit );
48 QtxWorkstack::~QtxWorkstack()
52 QWidgetList QtxWorkstack::windowList() const
54 QPtrList<QtxWorkstackArea> lst;
55 areas( mySplit, lst, true );
58 for ( QPtrListIterator<QtxWorkstackArea> it( lst ); it.current(); ++it )
60 QWidgetList wids = it.current()->widgetList();
61 for ( QWidgetListIt itr( wids ); itr.current(); ++itr )
62 widList.append( itr.current() );
68 QWidgetList QtxWorkstack::splitWindowList() const
70 return myArea ? myArea->widgetList() : QWidgetList();
73 QWidget* QtxWorkstack::activeWindow() const
78 void QtxWorkstack::split( const int o )
80 QtxWorkstackArea* area = activeArea();
84 if ( area->widgetList().count() < 2 )
87 QWidget* curWid = area->activeWidget();
91 QSplitter* s = splitter( area );
92 QPtrList<QtxWorkstackArea> areaList;
95 QPtrList<QSplitter> splitList;
96 splitters( s, splitList );
99 if ( areaList.count() + splitList.count() < 2 || s->orientation() == o )
103 trg = wrapSplitter( area );
108 trg->setOrientation( (Orientation)o );
110 QtxWorkstackArea* newArea = createArea( 0 );
111 insertWidget( newArea, trg, area );
113 area->removeWidget( curWid );
114 newArea->insertWidget( curWid );
116 distributeSpace( trg );
123 * \brief Split workarea of the given widget on two parts.
124 * \param wid - widget, belonging to this workstack
125 * \param o - orientation of splitting (Qt::Horizontal or Qt::Vertical)
126 * \param type - type of splitting, see <VAR>SplitType</VAR> enumeration
128 void QtxWorkstack::Split (QWidget* wid, const Qt::Orientation o, const SplitType type)
132 // find area of the given widget
133 QtxWorkstackArea* area = NULL;
134 QPtrList<QtxWorkstackArea> allAreas;
135 areas(mySplit, allAreas, true);
137 QPtrListIterator<QtxWorkstackArea> it (allAreas);
138 for (; it.current() && !area; ++it) {
139 if (it.current()->contains(wid))
144 QWidgetList wids = area->widgetList();
145 if (wids.count() < 2)
148 QSplitter* s = splitter(area);
149 QPtrList<QtxWorkstackArea> areaList;
152 QPtrList<QSplitter> splitList;
153 splitters(s, splitList);
156 if (areaList.count() + splitList.count() < 2 || s->orientation() == o)
159 if (!trg) trg = wrapSplitter(area);
162 trg->setOrientation(o);
164 QtxWorkstackArea* newArea = createArea(0);
165 insertWidget(newArea, trg, area);
170 QWidgetListIt itr (wids);
171 for (; itr.current(); ++itr)
173 QWidget* wid_i = itr.current();
175 area->removeWidget(wid_i);
176 newArea->insertWidget(wid_i);
183 QWidgetListIt itr (wids);
184 for (; itr.current() && itr.current() != wid; ++itr) {
186 for (; itr.current(); ++itr) {
187 area->removeWidget(itr.current());
188 newArea->insertWidget(itr.current());
193 area->removeWidget(wid);
194 newArea->insertWidget(wid);
198 distributeSpace(trg);
202 * \brief Put given widget on top of its workarea
203 * \param wid - widget, belonging to this workstack
206 void QtxWorkstack::OnTop (QWidget* wid)
211 // find area of the given widget
212 QtxWorkstackArea* area = 0;
213 QPtrList<QtxWorkstackArea> allAreas;
214 areas( mySplit, allAreas, true );
215 for ( QPtrListIterator<QtxWorkstackArea> it( allAreas ); it.current() && !area; ++it )
217 if ( it.current()->contains( wid ) )
222 area->setActiveWidget( wid );
227 * \brief Move widget(s) from source workarea into target workarea
228 * or just reorder widgets inside one workarea.
229 * \param wid1 - widget from target workarea
230 * \param wid2 - widget from source workarea
231 * \param all - if this parameter is TRUE, all widgets from source workarea will
232 * be moved into the target one, else only the \a wid2 will be moved
234 * Move \a wid2 in target workarea. Put it right after \a wid1.
235 * If value of boolean argument is TRUE, all widgets from source workarea
236 * will be moved together with \a wid2, source workarea will be deleted.
237 * If \a wid1 and \a wid2 belongs to one workarea, simple reordering will take place.
239 void QtxWorkstack::Attract ( QWidget* wid1, QWidget* wid2, const bool all )
241 if ( !wid1 || !wid2 )
244 // find area of the widgets
245 QtxWorkstackArea *area1 = NULL, *area2 = NULL;
246 QPtrList<QtxWorkstackArea> allAreas;
247 areas(mySplit, allAreas, true);
248 QPtrListIterator<QtxWorkstackArea> it (allAreas);
249 for (; it.current() && !(area1 && area2); ++it) {
250 if (it.current()->contains(wid1))
251 area1 = it.current();
252 if (it.current()->contains(wid2))
253 area2 = it.current();
255 if (!area1 || !area2) return;
257 QWidget* curWid = area1->activeWidget();
260 if (area1 == area2) {
262 // Set wid1 at first position, wid2 at second
263 area1->insertWidget(wid1);
264 area1->insertWidget(wid2, 1);
266 // Set wid2 right after wid1
267 area1->removeWidget(wid2);
269 QWidgetList wids1 = area1->widgetList();
270 QWidgetListIt itr1 (wids1);
271 for (; itr1.current() && itr1.current() != wid1; ++itr1, ++wid1_ind);
272 area1->insertWidget(wid2, wid1_ind + 1);
276 QWidgetList wids1 = area1->widgetList();
277 QWidgetListIt itr1 (wids1);
278 for (; itr1.current() && itr1.current() != wid1; ++itr1, ++wid1_ind);
281 // Set wid2 right after wid1, other widgets from area2 right after wid2
282 QWidgetList wids2 = area2->widgetList();
283 QWidgetListIt itr2 (wids2);
284 for (int ind = wid1_ind + 1; itr2.current(); ++itr2, ++ind)
286 area2->removeWidget(itr2.current());
287 if (itr2.current() == wid2) {
288 area1->insertWidget(itr2.current(), wid1_ind + 1);
290 area1->insertWidget(itr2.current(), ind);
294 // Set wid2 right after wid1
295 area2->removeWidget(wid2);
296 area1->insertWidget(wid2, wid1_ind + 1);
300 area1->setActiveWidget( curWid );
303 static void setSizes (QIntList& szList, const int item_ind,
304 const int new_near, const int new_this, const int new_farr)
306 // set size to all items before an item # <item_ind>
308 QIntList::iterator its = szList.begin();
309 for (; its != szList.end() && cur_pos < item_ind; ++its, ++cur_pos) {
312 if (its == szList.end()) return;
313 // set size to item # <item_ind>
316 // set size to all items after an item # <item_ind>
317 for (; its != szList.end(); ++its) {
323 * \brief Set position of the widget relatively its splitter.
324 * \param wid - widget to set position of
325 * \param pos - position relatively splitter. Value in range [0..1].
327 * Orientation of positioning will correspond to the splitter orientation.
329 void QtxWorkstack::SetRelativePositionInSplitter( QWidget* wid, const double position )
331 if ( position < 0.0 || 1.0 < position)
337 // find area of the given widget
338 QtxWorkstackArea* area = NULL;
339 QPtrList<QtxWorkstackArea> allAreas;
340 areas(mySplit, allAreas, true);
341 for ( QPtrListIterator<QtxWorkstackArea> it( allAreas );
342 it.current() && !area;
345 if (it.current()->contains(wid))
352 QSplitter* split = splitter( area );
356 // find index of the area in its splitter
358 bool isFound = false;
359 const QObjectList* was = split->children();
360 for (QObjectListIt ito (*was); ito.current() && !isFound; ++ito, ++item_ind)
362 if (ito.current() == area)
365 if (!isFound || item_ind == 0)
368 QIntList szList = split->sizes();
369 int splitter_size = (split->orientation() == Horizontal ?
370 split->width() : split->height());
371 int nb = szList.count();
373 int new_prev = int(splitter_size * position / item_ind);
374 int new_next = int(splitter_size * (1.0 - position) / (nb - item_ind));
375 setSizes (szList, item_ind, new_prev, new_next, new_next);
376 split->setSizes(szList);
380 * \brief Set position of the widget relatively the entire workstack.
381 * \param wid - widget to set position of
382 * \param o - orientation of positioning (Qt::Horizontal or Qt::Vertical).
383 * If o = Qt::Horizontal, horizontal position of \a wid will be changed.
384 * If o = Qt::Vertical, vertical position of \a wid will be changed.
385 * \param pos - position relatively workstack. Value in range [0..1].
387 void QtxWorkstack::SetRelativePosition( QWidget* wid, const Qt::Orientation o,
388 const double position )
390 if ( position < 0.0 || 1.0 < position )
396 int splitter_size = o == Horizontal ? mySplit->width() : mySplit->height();
397 int need_pos = int( position * splitter_size );
398 int splitter_pos = 0;
400 if ( setPosition( wid, mySplit, o, need_pos, splitter_pos ) != 0 )
402 // impossible to set required position
407 * \brief Sets the action's accelerator key to accel.
408 * \param id - the key of the action in the actions map.
409 * \param accel - action's accelerator key.
411 void QtxWorkstack::setAccel( const int id, const int accel )
413 if ( !myActionsMap.contains( id ) )
416 myActionsMap[id]->setAccel( accel );
420 * \brief Returns the action's accelerator key.
421 * \param id - the key of the action in the actions map.
422 * \retval int - action's accelerator key.
424 int QtxWorkstack::accel( const int id ) const
427 if ( myActionsMap.contains( id ) )
428 res = myActionsMap[id]->accel();
432 static int positionSimple (QIntList& szList, const int nb, const int splitter_size,
433 const int item_ind, const int item_rel_pos,
434 const int need_pos, const int splitter_pos)
436 if (item_ind == 0) { // cannot move in this splitter
437 return (need_pos - splitter_pos);
442 int new_this = szList[item_ind];
445 bool isToCheck = false;
447 if (need_pos < splitter_pos) {
448 // Set size of all previous workareas to zero <--
449 if (item_ind == nb - 1) {
450 // item iz last in the splitter, it will occupy all the splitter
451 new_this = splitter_size;
453 // recompute size of next items in splitter
454 new_next = (splitter_size - new_this) / (nb - item_ind - 1);
456 delta = need_pos - splitter_pos;
458 } else if (need_pos > (splitter_pos + splitter_size)) {
459 // Set size of all next workareas to zero -->
460 // recompute size of previous items in splitter
462 new_prev = (splitter_size - new_this) / item_ind;
463 delta = need_pos - (splitter_pos + splitter_size - new_this);
465 } else { // required position lays inside this splitter
466 // Move workarea inside splitter into required position <->
467 int new_item_rel_pos = need_pos - splitter_pos;
468 new_prev = new_item_rel_pos / item_ind;
469 if (need_pos < (splitter_pos + item_rel_pos)) {
470 // Make previous workareas smaller, next - bigger
471 // No problem to keep old size of the widget
473 // Make previous workareas bigger, next - smaller
474 if (new_this > splitter_size - new_item_rel_pos) {
475 new_this = splitter_size - new_item_rel_pos;
477 // jfa to do: in this case fixed size of next widgets could prevent right resizing
480 if (item_ind == nb - 1) {
481 new_this = splitter_size - new_item_rel_pos;
483 new_next = (splitter_size - new_item_rel_pos - new_this) / (nb - item_ind - 1);
488 setSizes (szList, item_ind, new_prev, new_this, new_next);
493 * \brief Set position of given widget.
494 * \param wid - widget to be moved
495 * \param split - currently processed splitter (goes from more common
496 * to more particular splitter in recursion calls)
497 * \param o - orientation of positioning
498 * \param need_pos - required position of the given widget in pixels
499 * (from top/left side of workstack area)
500 * \param splitter_pos - position of the splitter \a split
501 * (from top/left side of workstack area)
502 * \retval int - returns difference between a required and a distinguished position.
504 * Internal method. Recursively calls itself.
505 * Is called from <VAR>SetRelativePosition</VAR> public method.
507 int QtxWorkstack::setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
508 const int need_pos, const int splitter_pos )
510 if ( !wid || !split )
511 return need_pos - splitter_pos;
513 // Find corresponding sub-splitter.
514 // Find also index of appropriate item in current splitter.
515 int cur_ind = 0, item_ind = 0;
516 bool isBottom = false, isFound = false;
517 QSplitter* sub_split = NULL;
518 const QObjectList* objs = split->children();
521 for (QObjectListIt it (*objs); it.current() && !isFound; ++it)
523 if (it.current()->inherits( "QtxWorkstackArea")) {
524 if (((QtxWorkstackArea*)it.current())->contains(wid)) {
530 } else if (it.current()->inherits("QSplitter")) {
531 QPtrList<QtxWorkstackArea> areaList;
532 areas((QSplitter*)it.current(), areaList, true);
533 for (QPtrListIterator<QtxWorkstackArea> ita (areaList);
534 ita.current() && !isFound;
537 if (ita.current()->contains(wid)) {
540 sub_split = (QSplitter*)it.current();
548 return (need_pos - splitter_pos);
550 if (split->orientation() == o) {
551 // Find coordinates of near and far sides of the appropriate item relatively current splitter
552 int splitter_size = (o == Horizontal ? split->width() : split->height());
553 QIntList szList = split->sizes();
554 int nb = szList.count();
555 int item_rel_pos = 0; // position of near side of item relatively this splitter
556 for (int i = 0; i < item_ind; i++) {
557 item_rel_pos += szList[i];
559 int item_size = szList[item_ind]; // size of item
560 int item_pos = splitter_pos + item_rel_pos;
562 // Resize splitter items to complete the conditions
564 // I. Bottom of splitters stack reached
566 int delta = positionSimple(szList, nb, splitter_size, item_ind, item_rel_pos, need_pos, splitter_pos);
567 split->setSizes(szList);
568 // Recompute delta, as some windows can reject given size
569 int new_item_rel_pos = 0;
570 QIntList szList1 = split->sizes();
571 for (int i = 0; i < item_ind; i++) {
572 new_item_rel_pos += szList1[i];
574 delta = need_pos - (splitter_pos + new_item_rel_pos);
578 // II. Bottom of splitters stack is not yet reached
580 if (item_ind == 0) { // cannot move in this splitter
581 // Process in sub-splitter
582 return setPosition(wid, sub_split, o, need_pos, splitter_pos);
586 int new_this = szList[item_ind];
589 if (need_pos < splitter_pos) {
590 // Set size of all previous workareas to zero <--
591 if (item_ind == nb - 1) {
592 new_this = splitter_size;
594 new_next = (splitter_size - new_this) / (nb - item_ind - 1);
596 setSizes (szList, item_ind, new_prev, new_this, new_next);
597 split->setSizes(szList);
598 // Recompute splitter_pos, as some windows can reject given size
599 int new_item_rel_pos = 0;
600 QIntList szList1 = split->sizes();
601 for (int i = 0; i < item_ind; i++) {
602 new_item_rel_pos += szList1[i];
604 // Process in sub-splitter
605 return setPosition(wid, sub_split, o, need_pos, splitter_pos + new_item_rel_pos);
606 } else if (need_pos > (splitter_pos + splitter_size)) {
607 // Set size of all next workareas to zero -->
608 new_prev = (splitter_size - new_this) / item_ind;
609 setSizes (szList, item_ind, new_prev, new_this, new_next);
610 split->setSizes(szList);
611 // Recompute splitter_pos, as some windows can reject given size
612 int new_item_rel_pos = 0;
613 QIntList szList1 = split->sizes();
614 for (int i = 0; i < item_ind; i++) {
615 new_item_rel_pos += szList1[i];
617 // Process in sub-splitter
618 return setPosition(wid, sub_split, o, need_pos, splitter_pos + new_item_rel_pos);
620 // Set appropriate size of all previous/next items <->
621 int new_item_rel_pos = item_rel_pos;
622 if (need_pos < item_pos || (item_pos + item_size) < need_pos) {
623 // Move item inside splitter into required position <->
624 int new_this = szList[item_ind];
626 new_item_rel_pos = need_pos - splitter_pos;
627 if ((item_pos + item_size) < need_pos) {
628 //new_item_rel_pos = need_pos - (item_pos + item_size);
629 new_item_rel_pos = item_rel_pos + (need_pos - (item_pos + item_size));
631 int new_prev = new_item_rel_pos / item_ind;
632 if (need_pos < (splitter_pos + item_rel_pos)) {
633 // Make previous workareas smaller, next - bigger
634 // No problem to keep old size of the widget
636 // Make previous workareas bigger, next - smaller
637 if (new_this > splitter_size - new_item_rel_pos) {
638 new_this = splitter_size - new_item_rel_pos;
641 if (item_ind == nb - 1) {
642 new_this = splitter_size - new_item_rel_pos;
644 new_next = (splitter_size - new_item_rel_pos - new_this) / (nb - item_ind - 1);
646 setSizes (szList, item_ind, new_prev, new_this, new_next);
647 split->setSizes(szList);
648 // Recompute new_item_rel_pos, as some windows can reject given size
649 new_item_rel_pos = 0;
650 QIntList szList1 = split->sizes();
651 for (int i = 0; i < item_ind; i++) {
652 new_item_rel_pos += szList1[i];
657 // Process in sub-splitter
658 int add_pos = setPosition(wid, sub_split, o, need_pos, splitter_pos + new_item_rel_pos);
662 // this can be if corresponding workarea is first in sub-splitter
663 // or sub-splitter has another orientation
665 // Resize ones again to reach precize position <->
666 int need_pos_1 = splitter_pos + new_item_rel_pos + add_pos;
668 // Move workarea inside splitter into required position <->
669 int delta_1 = positionSimple(szList, nb, splitter_size, item_ind,
670 new_item_rel_pos, need_pos_1, splitter_pos);
671 split->setSizes(szList);
672 // Recompute new_item_rel_pos, as some windows can reject given size
673 new_item_rel_pos = 0;
674 QIntList szList1 = split->sizes();
675 for (int i = 0; i < item_ind; i++) {
676 new_item_rel_pos += szList1[i];
678 delta_1 = need_pos_1 - (splitter_pos + new_item_rel_pos);
683 return setPosition(wid, sub_split, o, need_pos, splitter_pos);
689 void QtxWorkstack::distributeSpace( QSplitter* split ) const
694 QIntList szList = split->sizes();
695 int size = ( split->orientation() == Horizontal ?
696 split->width() : split->height() ) / szList.count();
697 for ( QIntList::iterator it = szList.begin(); it != szList.end(); ++it )
699 split->setSizes( szList );
702 void QtxWorkstack::splitVertical()
704 split( Qt::Horizontal );
707 void QtxWorkstack::splitHorizontal()
709 split( Qt::Vertical );
712 void QtxWorkstack::onRename()
718 QString newName = QInputDialog::getText( tr( "Rename" ), tr( "Enter new name:" ), QLineEdit::Normal,
719 myWorkWin->caption(), &ok, topLevelWidget() );
720 if ( ok && !newName.isEmpty() )
721 myWorkWin->setCaption( newName );
724 QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area )
729 QSplitter* pSplit = splitter( area );
733 bool upd = pSplit->isUpdatesEnabled();
734 pSplit->setUpdatesEnabled( false );
736 QIntList szList = pSplit->sizes();
738 QSplitter* wrap = new QSplitter( 0 );
739 #if defined QT_VERSION && QT_VERSION >= 0x30200
740 wrap->setChildrenCollapsible( false );
742 insertWidget( wrap, pSplit, area );
743 area->reparent( wrap, QPoint( 0, 0 ), true );
745 pSplit->setSizes( szList );
747 pSplit->setUpdatesEnabled( upd );
752 void QtxWorkstack::insertWidget( QWidget* wid, QWidget* pWid, QWidget* after )
757 QWidgetList moveList;
758 const QObjectList* lst = pWid->children();
762 for ( QObjectListIt it( *lst ); it.current(); ++it )
764 if ( found && ( it.current()->inherits( "QSplitter" ) ||
765 it.current()->inherits( "QtxWorkstackArea" ) ) )
766 moveList.append( (QWidget*)it.current() );
767 if ( it.current() == after )
772 QMap<QWidget*, bool> map;
773 for ( QWidgetListIt it( moveList ); it.current(); ++it )
775 map.insert( it.current(), it.current()->isVisibleTo( it.current()->parentWidget() ) );
776 it.current()->reparent( 0, QPoint( 0, 0 ), false );
779 wid->reparent( pWid, QPoint( 0, 0 ), true );
781 for ( QWidgetListIt itr( moveList ); itr.current(); ++itr )
782 itr.current()->reparent( pWid, QPoint( 0, 0 ), map.contains( itr.current() ) ? map[itr.current()] : false );
786 * \brief Closes the active window.
788 void QtxWorkstack::onCloseWindow()
792 else if( activeWindow() )
793 activeWindow()->close();
796 void QtxWorkstack::onDestroyed( QObject* obj )
798 QtxWorkstackArea* area = (QtxWorkstackArea*)obj;
800 if ( area == myArea )
805 QtxWorkstackArea* cur = neighbourArea( area );
810 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
813 void QtxWorkstack::onWindowActivated( QWidget* wid )
815 const QObject* obj = sender();
816 if ( !obj->inherits( "QtxWorkstackArea" ) )
819 setActiveArea( (QtxWorkstackArea*)obj );
822 void QtxWorkstack::onDeactivated( QtxWorkstackArea* area )
824 if ( myArea != area )
827 QPtrList<QtxWorkstackArea> lst;
828 areas( mySplit, lst, true );
830 int idx = lst.find( area );
837 QtxWorkstackArea* newArea = neighbourArea( area );
838 if ( newArea && newArea->activeWidget() )
839 newArea->activeWidget()->setFocus();
841 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
844 void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p )
849 QWidgetList lst = activeArea()->widgetList();
855 QPopupMenu* pm = new QPopupMenu();
857 if ( lst.count() > 1 )
859 myActionsMap[SplitVertical]->addTo( pm );
860 myActionsMap[SplitHorizontal]->addTo( pm );
861 pm->insertSeparator();
866 myActionsMap[Close]->addTo( pm );
867 myActionsMap[Rename]->addTo( pm );
878 void QtxWorkstack::childEvent( QChildEvent* e )
880 if ( e->inserted() && e->child()->isWidgetType() )
882 QWidget* w = (QWidget*)e->child();
883 if ( w && w != mySplit )
885 targetArea()->insertWidget( w );
889 QWidget::childEvent( e );
892 void QtxWorkstack::customEvent( QCustomEvent* e )
897 QSplitter* QtxWorkstack::splitter( QtxWorkstackArea* area ) const
902 QSplitter* split = 0;
904 QWidget* wid = area->parentWidget();
905 if ( wid && wid->inherits( "QSplitter" ) )
906 split = (QSplitter*)wid;
911 void QtxWorkstack::splitters( QSplitter* split, QPtrList<QSplitter>& splitList, const bool rec ) const
916 const QObjectList* objs = split->children();
919 for ( QObjectListIt it( *objs ); it.current(); ++it )
922 splitters( (QSplitter*)it.current(), splitList, rec );
923 if ( it.current()->inherits( "QSplitter" ) )
924 splitList.append( (QSplitter*)it.current() );
929 void QtxWorkstack::areas( QSplitter* split, QPtrList<QtxWorkstackArea>& areaList, const bool rec ) const
934 const QObjectList* objs = split->children();
937 for ( QObjectListIt it( *objs ); it.current(); ++it )
939 if ( it.current()->inherits( "QtxWorkstackArea" ) )
940 areaList.append( (QtxWorkstackArea*)it.current() );
941 else if ( rec && it.current()->inherits( "QSplitter" ) )
942 areas( (QSplitter*)it.current(), areaList, rec );
947 QtxWorkstackArea* QtxWorkstack::activeArea() const
952 QtxWorkstackArea* QtxWorkstack::targetArea()
954 QtxWorkstackArea* area = activeArea();
956 area = currentArea();
959 QPtrList<QtxWorkstackArea> lst;
960 areas( mySplit, lst );
961 if ( !lst.isEmpty() )
966 area = createArea( mySplit );
971 QtxWorkstackArea* QtxWorkstack::currentArea() const
973 QtxWorkstackArea* area = 0;
974 QWidget* wid = focusWidget();
975 while ( wid && !area )
977 if ( wid->inherits( "QtxWorkstackArea" ) )
978 area = (QtxWorkstackArea*)wid;
979 wid = wid->parentWidget();
985 QtxWorkstackArea* QtxWorkstack::createArea( QWidget* parent ) const
987 QtxWorkstackArea* area = new QtxWorkstackArea( parent );
989 connect( area, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
990 connect( area, SIGNAL( activated( QWidget* ) ), this, SLOT( onWindowActivated( QWidget* ) ) );
991 connect( area, SIGNAL( contextMenuRequested( QWidget*, QPoint ) ),
992 this, SLOT( onContextMenuRequested( QWidget*, QPoint ) ) );
993 connect( area, SIGNAL( deactivated( QtxWorkstackArea* ) ), this, SLOT( onDeactivated( QtxWorkstackArea* ) ) );
998 void QtxWorkstack::setActiveArea( QtxWorkstackArea* area )
1000 QWidget* oldCur = myWin;
1002 QtxWorkstackArea* oldArea = myArea;
1006 if ( myArea != oldArea )
1009 oldArea->updateActiveState();
1011 myArea->updateActiveState();
1015 myWin = myArea->activeWidget();
1017 if ( myWin && oldCur != myWin )
1018 emit windowActivated( myWin );
1021 QtxWorkstackArea* QtxWorkstack::neighbourArea( QtxWorkstackArea* area ) const
1023 QPtrList<QtxWorkstackArea> lst;
1024 areas( mySplit, lst, true );
1025 int pos = lst.find( area );
1029 QtxWorkstackArea* na = 0;
1030 for ( int i = pos - 1; i >= 0 && !na; i-- )
1032 if ( !lst.at( i )->isEmpty() )
1036 for ( int j = pos + 1; j < (int)lst.count() && !na; j++ )
1038 if ( !lst.at( j )->isEmpty() )
1044 QtxWorkstackArea* QtxWorkstack::areaAt( const QPoint& p ) const
1046 QtxWorkstackArea* area = 0;
1047 QPtrList<QtxWorkstackArea> lst;
1048 areas( mySplit, lst, true );
1049 for ( QPtrListIterator<QtxWorkstackArea> it( lst ); it.current() && !area; ++it )
1051 QtxWorkstackArea* cur = it.current();
1052 QRect r = cur->geometry();
1053 if ( cur->parentWidget() )
1054 r = QRect( cur->parentWidget()->mapToGlobal( r.topLeft() ), r.size() );
1055 if ( r.contains( p ) )
1061 void QtxWorkstack::updateState()
1063 updateState( mySplit );
1066 void QtxWorkstack::updateState( QSplitter* split )
1068 QPtrList<QSplitter> recList;
1069 splitters( split, recList, false );
1070 for ( QPtrListIterator<QSplitter> itr( recList ); itr.current(); ++itr )
1071 updateState( itr.current() );
1073 QPtrList<QSplitter> splitList;
1074 splitters( split, splitList, false );
1076 QPtrList<QtxWorkstackArea> areaList;
1077 areas( split, areaList, false );
1080 for ( QPtrListIterator<QtxWorkstackArea> it( areaList ); it.current(); ++it )
1082 if ( it.current()->isEmpty() )
1083 it.current()->hide();
1086 it.current()->show();
1091 if ( split == mySplit )
1094 for ( QPtrListIterator<QSplitter> iter( splitList ); iter.current() && !vis; ++iter )
1095 vis = iter.current()->isVisibleTo( iter.current()->parentWidget() );
1097 if ( areaList.isEmpty() && splitList.isEmpty() )
1106 Class: QtxWorkstackArea [Internal]
1110 QtxWorkstackArea::QtxWorkstackArea( QWidget* parent )
1113 QVBoxLayout* base = new QVBoxLayout( this );
1115 QHBox* top = new QHBox( this );
1116 base->addWidget( top );
1118 myBar = new QtxWorkstackTabBar( top );
1120 QPushButton* close = new QPushButton( top );
1121 close->setPixmap( style().stylePixmap( QStyle::SP_TitleBarCloseButton ) );
1122 close->setAutoDefault( true );
1123 close->setFlat( true );
1126 top->setStretchFactor( myBar, 1 );
1128 myStack = new QWidgetStack( this );
1130 base->addWidget( myStack, 1 );
1132 connect( myClose, SIGNAL( clicked() ), this, SLOT( onClose() ) );
1133 connect( myBar, SIGNAL( selected( int ) ), this, SLOT( onSelected( int ) ) );
1134 connect( myBar, SIGNAL( dragActiveTab() ), this, SLOT( onDragActiveTab() ) );
1135 connect( myBar, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onContextMenuRequested( QPoint ) ) );
1139 updateActiveState();
1141 qApp->installEventFilter( this );
1144 QtxWorkstackArea::~QtxWorkstackArea()
1146 qApp->removeEventFilter( this );
1149 bool QtxWorkstackArea::isEmpty() const
1152 for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !res; ++it )
1153 res = it.data().vis;
1157 void QtxWorkstackArea::insertWidget( QWidget* wid, const int idx )
1162 int pos = myList.find( wid );
1163 if ( pos != -1 && ( pos == idx || ( idx < 0 && pos == (int)myList.count() - 1 ) ) )
1166 myList.removeRef( wid );
1167 pos = idx < 0 ? myList.count() : idx;
1168 myList.insert( QMIN( pos, (int)myList.count() ), wid );
1169 if ( !myInfo.contains( wid ) )
1171 QtxWorkstackChild* child = new QtxWorkstackChild( wid, myStack );
1172 myChild.insert( wid, child );
1173 myInfo.insert( wid, WidgetInfo() );
1174 myInfo[wid].id = generateId();
1175 myInfo[wid].vis = wid->isVisibleTo( wid->parentWidget() );
1177 connect( child, SIGNAL( destroyed( QObject* ) ), this, SLOT( onChildDestroyed( QObject* ) ) );
1178 connect( wid, SIGNAL( destroyed() ), this, SLOT( onWidgetDestroyed() ) );
1179 connect( child, SIGNAL( shown( QtxWorkstackChild* ) ), this, SLOT( onChildShown( QtxWorkstackChild* ) ) );
1180 connect( child, SIGNAL( hided( QtxWorkstackChild* ) ), this, SLOT( onChildHided( QtxWorkstackChild* ) ) );
1181 connect( child, SIGNAL( activated( QtxWorkstackChild* ) ), this, SLOT( onChildActivated( QtxWorkstackChild* ) ) );
1182 connect( child, SIGNAL( captionChanged( QtxWorkstackChild* ) ), this, SLOT( onChildCaptionChanged( QtxWorkstackChild* ) ) );
1187 setWidgetActive( wid );
1190 void QtxWorkstackArea::onContextMenuRequested( QPoint p )
1192 const QtxWorkstackTabBar* bar = ::qt_cast<const QtxWorkstackTabBar*>( sender() );
1197 QTab* tab = myBar->tabAt( tabAt( p ) );
1199 wid = widget( tab->identifier() );
1201 emit contextMenuRequested( wid, p );
1204 void QtxWorkstackArea::onWidgetDestroyed()
1207 removeWidget( (QWidget*)sender(), false );
1210 void QtxWorkstackArea::removeWidget( QWidget* wid, const bool del )
1212 if ( !myList.contains( wid ) )
1215 if ( myBar->tab( widgetId( wid ) ) )
1216 myBar->removeTab( myBar->tab( widgetId( wid ) ) );
1217 myStack->removeWidget( child( wid ) );
1219 myList.remove( wid );
1220 myInfo.remove( wid );
1221 myChild.remove( wid );
1225 delete child( wid );
1226 if( myList.isEmpty() )
1235 QWidgetList QtxWorkstackArea::widgetList() const
1238 for ( QWidgetListIt it( myList ); it.current(); ++it )
1240 if ( widgetVisibility( it.current() ) )
1241 lst.append( it.current() );
1246 QWidget* QtxWorkstackArea::activeWidget() const
1248 return widget( myBar->currentTab() );
1251 void QtxWorkstackArea::setActiveWidget( QWidget* wid )
1253 myBar->setCurrentTab( widgetId( wid ) );
1256 bool QtxWorkstackArea::contains( QWidget* wid ) const
1258 return myList.contains( wid );
1261 void QtxWorkstackArea::show()
1263 QMap<QWidget*, bool> map;
1264 for ( QWidgetListIt it( myList ); it.current(); ++it )
1266 map.insert( it.current(), isBlocked( it.current() ) );
1267 setBlocked( it.current(), true );
1272 for ( QWidgetListIt itr( myList ); itr.current(); ++itr )
1273 setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false );
1276 void QtxWorkstackArea::hide()
1278 QMap<QWidget*, bool> map;
1279 for ( QWidgetListIt it( myList ); it.current(); ++it )
1281 map.insert( it.current(), isBlocked( it.current() ) );
1282 setBlocked( it.current(), true );
1287 for ( QWidgetListIt itr( myList ); itr.current(); ++itr )
1288 setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false );
1291 bool QtxWorkstackArea::isActive() const
1293 QtxWorkstack* ws = workstack();
1297 return ws->activeArea() == this;
1300 void QtxWorkstackArea::updateActiveState()
1302 myBar->setActive( isActive() );
1305 QtxWorkstack* QtxWorkstackArea::workstack() const
1307 QtxWorkstack* ws = 0;
1308 QWidget* wid = parentWidget();
1309 while ( wid && !ws )
1311 if ( wid->inherits( "QtxWorkstack" ) )
1312 ws = (QtxWorkstack*)wid;
1313 wid = wid->parentWidget();
1318 bool QtxWorkstackArea::eventFilter( QObject* o, QEvent* e )
1320 if ( o->isWidgetType() )
1322 QWidget* wid = (QWidget*)o;
1323 if ( e->type() == QEvent::FocusIn || e->type() == QEvent::MouseButtonPress )
1326 while ( !ok && wid && wid != myClose )
1329 wid = wid->parentWidget();
1332 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)( e->type() == QEvent::FocusIn ? ActivateWidget : FocusWidget ) ) );
1338 QRect QtxWorkstackArea::floatRect() const
1340 QRect r = myStack->geometry();
1341 return QRect( mapToGlobal( r.topLeft() ), mapToGlobal( r.bottomRight() ) );
1344 QRect QtxWorkstackArea::floatTab( const int idx ) const
1346 return myBar->tabRect( idx );
1349 int QtxWorkstackArea::tabAt( const QPoint& p ) const
1352 for ( int i = 0; i < myBar->count() && idx == -1; i++ )
1354 QRect r = myBar->tabRect( i );
1355 if ( r.isValid() && r.contains( p ) )
1361 void QtxWorkstackArea::customEvent( QCustomEvent* e )
1363 switch ( e->type() )
1365 case ActivateWidget:
1366 emit activated( activeWidget() );
1369 if ( activeWidget() && !activeWidget()->focusWidget() )
1370 activeWidget()->setFocus();
1373 removeWidget( (QWidget*)e->data() );
1378 void QtxWorkstackArea::focusInEvent( QFocusEvent* e )
1380 QWidget::focusInEvent( e );
1382 emit activated( activeWidget() );
1385 void QtxWorkstackArea::mousePressEvent( QMouseEvent* e )
1387 QWidget::mousePressEvent( e );
1389 emit activated( activeWidget() );
1392 void QtxWorkstackArea::onClose()
1394 QWidget* wid = activeWidget();
1399 void QtxWorkstackArea::onSelected( int id )
1403 emit activated( activeWidget() );
1406 void QtxWorkstackArea::onDragActiveTab()
1408 QtxWorkstackChild* c = child( activeWidget() );
1412 new QtxWorkstackDrag( workstack(), c );
1415 void QtxWorkstackArea::onChildDestroyed( QObject* obj )
1417 QtxWorkstackChild* child = (QtxWorkstackChild*)obj;
1418 myStack->removeWidget( child );
1421 for ( ChildMap::ConstIterator it = myChild.begin(); it != myChild.end() && !wid; ++it )
1423 if ( it.data() == child )
1427 myChild.remove( wid );
1429 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)RemoveWidget, wid ) );
1432 void QtxWorkstackArea::onChildShown( QtxWorkstackChild* c )
1434 setWidgetShown( c->widget(), true );
1437 void QtxWorkstackArea::onChildHided( QtxWorkstackChild* c )
1439 setWidgetShown( c->widget(), false );
1442 void QtxWorkstackArea::onChildActivated( QtxWorkstackChild* c )
1444 setWidgetActive( c->widget() );
1447 void QtxWorkstackArea::onChildCaptionChanged( QtxWorkstackChild* c )
1449 updateTab( c->widget() );
1452 void QtxWorkstackArea::updateCurrent()
1454 QMap<QWidget*, bool> map;
1455 for ( QWidgetListIt it( myList ); it.current(); ++it )
1457 map.insert( it.current(), isBlocked( it.current() ) );
1458 setBlocked( it.current(), true );
1461 myStack->raiseWidget( myBar->currentTab() );
1463 for ( QWidgetListIt itr( myList ); itr.current(); ++itr )
1464 setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false );
1467 void QtxWorkstackArea::updateTab( QWidget* wid )
1469 QTab* tab = myBar->tab( widgetId( wid ) );
1476 QPixmap pix = *wid->icon();
1477 pix.convertFromImage( pix.convertToImage().smoothScale( pix.width(), 16, QImage::ScaleMin ) );
1478 icoSet = QIconSet( pix );
1481 tab->setIconSet( icoSet );
1482 tab->setText( wid->caption() );
1485 QWidget* QtxWorkstackArea::widget( const int id ) const
1488 for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !wid; ++it )
1490 if ( it.data().id == id )
1496 int QtxWorkstackArea::widgetId( QWidget* wid ) const
1499 if ( myInfo.contains( wid ) )
1500 id = myInfo[wid].id;
1504 bool QtxWorkstackArea::widgetVisibility( QWidget* wid ) const
1507 if ( myInfo.contains( wid ) )
1508 res = myInfo[wid].vis;
1512 void QtxWorkstackArea::setWidgetActive( QWidget* wid )
1514 int id = widgetId( wid );
1518 myBar->setCurrentTab( id );
1521 void QtxWorkstackArea::setWidgetShown( QWidget* wid, const bool on )
1523 if ( isBlocked( wid ) || !myInfo.contains( wid ) || myInfo[wid].vis == on )
1526 myInfo[wid].vis = on;
1530 void QtxWorkstackArea::updateState()
1532 bool updBar = myBar->isUpdatesEnabled();
1533 bool updStk = myStack->isUpdatesEnabled();
1534 myBar->setUpdatesEnabled( false );
1535 myStack->setUpdatesEnabled( false );
1537 bool block = myBar->signalsBlocked();
1538 myBar->blockSignals( true );
1540 QWidget* prev = activeWidget();
1543 for ( QWidgetListIt it( myList ); it.current(); ++it )
1545 QWidget* wid = it.current();
1546 int id = widgetId( wid );
1551 bool vis = widgetVisibility( wid );
1553 if ( myBar->tab( id ) && ( !vis || myBar->indexOf( id ) != idx ) )
1554 myBar->removeTab( myBar->tab( id ) );
1556 if ( !myBar->tab( id ) && vis )
1558 QTab* tab = new QTab( wid->caption() );
1559 myBar->insertTab( tab, idx );
1560 tab->setIdentifier( id );
1565 bool block = isBlocked( wid );
1566 setBlocked( wid, true );
1568 QtxWorkstackChild* cont = child( wid );
1571 myStack->removeWidget( cont );
1572 else if ( !myStack->widget( id ) )
1573 myStack->addWidget( cont, id );
1578 setBlocked( wid, block );
1581 int curId = widgetId( prev );
1582 if ( !myBar->tab( curId ) )
1585 int pos = myList.find( prev );
1586 for ( int i = pos - 1; i >= 0 && !wid; i-- )
1588 if ( widgetVisibility( myList.at( i ) ) )
1589 wid = myList.at( i );
1592 for ( int j = pos + 1; j < (int)myList.count() && !wid; j++ )
1594 if ( widgetVisibility( myList.at( j ) ) )
1595 wid = myList.at( j );
1599 curId = widgetId( wid );
1602 myBar->setCurrentTab( curId );
1604 myBar->blockSignals( block );
1608 myBar->setUpdatesEnabled( updBar );
1609 myStack->setUpdatesEnabled( updStk );
1615 QResizeEvent re( myBar->size(), myBar->size() );
1616 QApplication::sendEvent( myBar, &re );
1621 emit deactivated( this );
1626 if ( prev != activeWidget() )
1627 emit activated( activeWidget() );
1631 int QtxWorkstackArea::generateId() const
1635 for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end(); ++it )
1636 map.insert( it.data().id, 0 );
1639 while ( map.contains( id ) )
1645 bool QtxWorkstackArea::isBlocked( QWidget* wid ) const
1647 return myBlock.contains( wid );
1650 void QtxWorkstackArea::setBlocked( QWidget* wid, const bool on )
1653 myBlock.insert( wid, 0 );
1655 myBlock.remove( wid );
1658 QtxWorkstackChild* QtxWorkstackArea::child( QWidget* wid ) const
1660 QtxWorkstackChild* res = 0;
1661 if ( myChild.contains( wid ) )
1667 Class: QtxWorkstackChild [Internal]
1671 QtxWorkstackChild::QtxWorkstackChild( QWidget* wid, QWidget* parent )
1675 myWidget->reparent( this, QPoint( 0, 0 ), myWidget->isVisibleTo( myWidget->parentWidget() ) );
1676 myWidget->installEventFilter( this );
1678 connect( myWidget, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
1681 QtxWorkstackChild::~QtxWorkstackChild()
1683 qApp->removeEventFilter( this );
1688 widget()->removeEventFilter( this );
1689 widget()->reparent( 0, QPoint( 0, 0 ), false );
1690 disconnect( widget(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
1693 QWidget* QtxWorkstackChild::widget() const
1698 bool QtxWorkstackChild::eventFilter( QObject* o, QEvent* e )
1700 if ( o->isWidgetType() )
1702 if ( e->type() == QEvent::CaptionChange || e->type() == QEvent::IconChange )
1703 emit captionChanged( this );
1705 if ( !e->spontaneous() && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) )
1708 if ( !e->spontaneous() && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) )
1711 if ( e->type() == QEvent::FocusIn )
1712 emit activated( this );
1714 return QHBox::eventFilter( o, e );
1717 void QtxWorkstackChild::onDestroyed( QObject* obj )
1719 if ( obj != widget() )
1726 void QtxWorkstackChild::childEvent( QChildEvent* e )
1728 if ( e->type() == QEvent::ChildRemoved && e->child() == widget() )
1733 QHBox::childEvent( e );
1737 Class: QtxWorkstackTabBar [Internal]
1741 QtxWorkstackTabBar::QtxWorkstackTabBar( QWidget* parent )
1742 : QTabBar( parent ),
1747 QtxWorkstackTabBar::~QtxWorkstackTabBar()
1751 void QtxWorkstackTabBar::setActive( const bool on )
1753 QFont aFont = font();
1754 aFont.setUnderline( on );
1760 QRect QtxWorkstackTabBar::tabRect( const int idx ) const
1763 QTab* t = tabAt( idx );
1767 r.setLeft( QMAX( r.left(), 0 ) );
1769 int x1 = tabAt( 0 )->rect().left();
1770 int x2 = tabAt( count() - 1 )->rect().right();
1773 if ( QABS( x2 - x1 ) > width() )
1774 #if defined QT_VERSION && QT_VERSION >= 0x30300
1775 bw = 2 * style().pixelMetric( QStyle::PM_TabBarScrollButtonWidth, this );
1780 int limit = width() - bw;
1781 r.setRight( QMIN( r.right(), limit ) );
1783 r = QRect( mapToGlobal( r.topLeft() ), r.size() );
1788 void QtxWorkstackTabBar::mouseMoveEvent( QMouseEvent* e )
1790 if ( myId != -1 && !tab( myId )->rect().contains( e->pos() ) )
1793 emit dragActiveTab();
1796 QTabBar::mouseMoveEvent( e );
1799 void QtxWorkstackTabBar::mousePressEvent( QMouseEvent* e )
1801 QTabBar::mousePressEvent( e );
1803 if ( e->button() == LeftButton )
1804 myId = currentTab();
1807 void QtxWorkstackTabBar::mouseReleaseEvent( QMouseEvent* e )
1809 QTabBar::mouseReleaseEvent( e );
1813 if ( e->button() == RightButton )
1814 emit contextMenuRequested( e->globalPos() );
1817 void QtxWorkstackTabBar::contextMenuEvent( QContextMenuEvent* e )
1819 if ( e->reason() != QContextMenuEvent::Mouse )
1820 emit contextMenuRequested( e->globalPos() );
1823 void QtxWorkstackTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const
1825 if ( currentTab() != t->identifier() )
1827 QFont fnt = p->font();
1828 fnt.setUnderline( false );
1831 QTabBar::paintLabel( p, br, t, has_focus );
1835 Class: QtxWorkstackDrag [Internal]
1839 QtxWorkstackDrag::QtxWorkstackDrag( QtxWorkstack* ws, QtxWorkstackChild* child )
1847 qApp->installEventFilter( this );
1850 QtxWorkstackDrag::~QtxWorkstackDrag()
1852 qApp->removeEventFilter( this );
1857 bool QtxWorkstackDrag::eventFilter( QObject*, QEvent* e )
1859 switch ( e->type() )
1861 case QEvent::MouseMove:
1862 updateTarget( ((QMouseEvent*)e)->globalPos() );
1864 case QEvent::MouseButtonRelease:
1876 void QtxWorkstackDrag::updateTarget( const QPoint& p )
1879 QtxWorkstackArea* area = detectTarget( p, tab );
1880 setTarget( area, tab );
1883 QtxWorkstackArea* QtxWorkstackDrag::detectTarget( const QPoint& p, int& tab ) const
1888 QtxWorkstackArea* area = myWS->areaAt( p );
1890 tab = area->tabAt( p );
1894 void QtxWorkstackDrag::setTarget( QtxWorkstackArea* area, const int tab )
1896 if ( !area || ( myArea == area && tab == myTab ) )
1911 void QtxWorkstackDrag::dropWidget()
1914 myArea->insertWidget( myChild->widget(), myTab );
1917 void QtxWorkstackDrag::drawRect()
1919 if ( !myPainter || !myArea )
1922 QRect r = myArea->floatRect();
1923 int m = myPainter->pen().width();
1925 r.setTop( r.top() + m + 2 );
1926 r.setLeft( r.left() + m + 2 );
1927 r.setRight( r.right() - m - 2 );
1928 r.setBottom( r.bottom() - m - 2 );
1930 myPainter->drawRect( r );
1932 QRect tr = myArea->floatTab( myTab );
1933 tr.setTop( tr.top() + m );
1934 tr.setLeft( tr.left() + m );
1935 tr.setRight( tr.right() - m );
1936 tr.setBottom( tr.bottom() - m );
1938 myPainter->drawRect( tr );
1941 void QtxWorkstackDrag::endDrawRect()
1947 void QtxWorkstackDrag::startDrawRect()
1952 int scr = QApplication::desktop()->screenNumber( (QWidget*)this );
1953 QWidget* paint_on = QApplication::desktop()->screen( scr );
1955 myPainter = new QPainter( paint_on, true );
1956 myPainter->setPen( QPen( gray, 3 ) );
1957 myPainter->setRasterOp( XorROP );