From: nds Date: Mon, 6 Oct 2008 09:46:16 +0000 (+0000) Subject: Merging with the BR_V5_DEV branch. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=32c7c27106fbe53f1389f945565870c4549f1fc5;p=modules%2Fgui.git Merging with the BR_V5_DEV branch. --- diff --git a/src/Qtx/QtxTreeView.cxx b/src/Qtx/QtxTreeView.cxx index bd07c1206..c57192b03 100644 --- a/src/Qtx/QtxTreeView.cxx +++ b/src/Qtx/QtxTreeView.cxx @@ -42,13 +42,12 @@ public: bool sortMenuEnabled() const; void addMenuAction( QAction* ); - protected: void contextMenuEvent( QContextMenuEvent* ); private: typedef QMap ActionsMap; - bool myEnableSortMenu; + bool myEnableSortMenu; ActionsMap myActions; }; @@ -307,6 +306,26 @@ void QtxTreeView::addHeaderMenuAction( QAction* action ) h->addMenuAction( action ); } +/*! + \brief Resizes the given column in order to enclose its contents. + The size will be changed only if it is smaller than the size of + contents. + \param column number of column +*/ +void QtxTreeView::resizeColumnToEncloseContents( int column ) +{ + if (column < 0 || column >= header()->count()) + return; + + int contentsSizeHint = sizeHintForColumn(column); + int headerSizeHint = header()->isHidden() ? 0 : header()->sectionSizeHint(column); + int sizeHint = qMax(contentsSizeHint, headerSizeHint); + + int currentSize = columnWidth( column ); + if (currentSize < sizeHint) + setColumnWidth( column, sizeHint ); +} + /* \brief Called when the header section is clicked. \param column header column index @@ -345,6 +364,18 @@ void QtxTreeView::drawRow( const QModelIndex& index ) emit drawedRow( index ); } +/*! + \brief Called when rows are about to be removed. + \param parent model index + \param start first row to remove + \param end last row to remove +*/ +void QtxTreeView::rowsAboutToBeRemoved( const QModelIndex& parent, int start, int end ) +{ + setCurrentIndex( QModelIndex() ); + QTreeView::rowsAboutToBeRemoved( parent, start, end ); +} + /*! \brief Expand/collapse the specified item (recursively). \param index model index diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h index 8106afcb8..dfa3a5268 100644 --- a/src/Qtx/QtxTreeView.h +++ b/src/Qtx/QtxTreeView.h @@ -53,8 +53,11 @@ public: void addHeaderMenuAction( QAction* ); + void resizeColumnToEncloseContents( int ); + protected slots: void onHeaderClicked( int ); + void rowsAboutToBeRemoved( const QModelIndex&, int, int ); void selectionChanged( const QItemSelection&, const QItemSelection& ); protected: diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 27e8cdd0a..9a5794f29 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -23,22 +23,20 @@ #include "QtxAction.h" -#include #include -#include -#include #include +#include #include +#include #include +#include +#include #include #include +#include #include #include #include -#include -#include - -#define DARK_COLOR_LIGHT 250 /*! \class QtxWorkstackArea::WidgetEvent @@ -1495,6 +1493,13 @@ QtxWorkstack::QtxWorkstack( QWidget* parent ) connect( myActionsMap[Close], SIGNAL( triggered( bool ) ), this, SLOT( onCloseWindow() ) ); connect( myActionsMap[Rename], SIGNAL( triggered( bool ) ), this, SLOT( onRename() ) ); + // Action shortcut will work when action added in any widget. + for ( QMap::iterator it = myActionsMap.begin(); it != myActionsMap.end(); ++it ) + { + addAction( it.value() ); + it.value()->setShortcutContext( Qt::ApplicationShortcut ); + } + QVBoxLayout* base = new QVBoxLayout( this ); base->setMargin( 0 ); @@ -1511,13 +1516,25 @@ QtxWorkstack::~QtxWorkstack() } /*! - \brief Get all child widgets in all workareas. - \return list of widgets in all workareas + \brief Get list of all widgets in all areas or in specified area which given + widget belongs to + \param wid widget specifying area if it is equal to null when widgets of all + areas are retuned + \return list of widgets */ -QWidgetList QtxWorkstack::windowList() const +QWidgetList QtxWorkstack::windowList( QWidget* wid ) const { QList lst; - areas( mySplit, lst, true ); + if ( !wid ) + { + areas( mySplit, lst, true ); + } + else + { + QtxWorkstackArea* area = wgArea( wid ); + if ( area ) + lst.append( area ); + } QWidgetList widList; for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) @@ -2783,7 +2800,7 @@ void QtxWorkstack::splitterInfo( QSplitter* split, QString& info ) const if ( !split ) return; - const QObjectList& objs = split->children(); + /*const QObjectList& objs = */split->children(); // VSR: is it needed ??? QString sizesStr; QList sizes = split->sizes(); @@ -3114,3 +3131,95 @@ QtxWorkstack& QtxWorkstack::operator>>( QString& outParameters ) \brief Emitted when the workstack's child widget \w is activated. \param w widget being activated */ + +/*! + \brief Gets area containing given widget + \param wid widget + \return pointer to QtxWorkstackArea* object +*/ +QtxWorkstackArea* QtxWorkstack::wgArea( QWidget* wid ) const +{ + QtxWorkstackArea* resArea = 0; + + QList areaList; + areas( mySplit, areaList, true ); + + QList::ConstIterator it; + for ( it = areaList.begin(); it != areaList.end() && !resArea; ++it ) + { + if ( (*it)->contains( wid ) ) + resArea = *it; + } + + return resArea; +} + +/*! + \brief Moves the first widget to the same area which the second widget belongs to + \param wid widget to be moved + \param wid_to widget specified the destination area + \param before specifies whether the first widget has to be moved before or after + the second widget + \return TRUE if operation is completed successfully, FALSE otherwise +*/ +bool QtxWorkstack::move( QWidget* wid, QWidget* wid_to, const bool before ) +{ + if ( wid && wid_to ) + { + QtxWorkstackArea* area_src = wgArea( wid ); + QtxWorkstackArea* area_to = wgArea( wid_to ); + if ( area_src && area_to ) + { + // find index of the second widget + QWidgetList wgList = area_to->widgetList(); + QWidgetList::ConstIterator it; + int idx = 0; + for ( it = wgList.begin(); it != wgList.begin(); ++it, idx++ ) + { + if ( *it == wid_to ) + break; + } + + if ( idx < wgList.count() ) // paranoidal check + { + if ( !before ) + idx++; + area_src->removeWidget( wid, true ); + area_to->insertWidget( wid, idx ); + return true; + } + } + } + return false; +} + +/*! + \brief Group all windows in one area + \return TRUE if operation is completed successfully, FALSE otherwise +*/ +void QtxWorkstack::stack() +{ + QWidgetList wgList = windowList(); + if ( !wgList.count() ) + return; // nothing to do + + QtxWorkstackArea* area_to = 0; + QWidgetList::ConstIterator it; + for ( it = wgList.begin(); it != wgList.end(); ++it ) + { + QtxWorkstackArea* area_src = 0; + if ( !area_to ) + { + area_to = wgArea( *it ); + area_src = area_to; + } + else + area_src = wgArea( *it ); + + if ( area_src != area_to ) + { + area_src->removeWidget( *it, true ); + area_to->insertWidget( *it, -1 ); + } + } +} diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index 22425c869..21d1b5f30 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -71,7 +71,7 @@ public: QtxWorkstack( QWidget* = 0 ); virtual ~QtxWorkstack(); - QWidgetList windowList() const; + QWidgetList windowList( QWidget* = 0 ) const; QWidgetList splitWindowList() const; QWidget* activeWindow() const; @@ -86,6 +86,8 @@ public: int menuActions() const; void split( const int ); + bool move( QWidget* wid, QWidget* wid_to, const bool before ); + void stack(); QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 ); @@ -125,6 +127,7 @@ private: void insertWidget( QWidget*, QWidget*, QWidget* ); QtxWorkstackArea* areaAt( const QPoint& ) const; + QtxWorkstackArea* wgArea( QWidget* ) const; QtxWorkstackArea* targetArea(); QtxWorkstackArea* activeArea() const;