From: stv Date: Mon, 21 May 2007 07:49:12 +0000 (+0000) Subject: no message X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f5c187008e2261ce1a1f102e95736b59aa5a18d1;p=modules%2Fgui.git no message --- diff --git a/src/Qtx/QtxActionSet.cxx b/src/Qtx/QtxActionSet.cxx new file mode 100644 index 000000000..764e0db49 --- /dev/null +++ b/src/Qtx/QtxActionSet.cxx @@ -0,0 +1,235 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxActionSet.cxx +// Author: Sergey TELKOV + +#include "QtxActionSet.h" + +#include +#include + +/*! + Constructor +*/ +QtxActionSet::QtxActionSet( QObject* parent ) +: QtxAction( parent ) +{ + connect( this, SIGNAL( changed() ), this, SLOT( onChanged() ) ); + + setVisible( false ); + + update(); +} + +/*! + Destructor +*/ +QtxActionSet::~QtxActionSet() +{ +} + +QList QtxActionSet::actions() const +{ + return mySet; +} + +void QtxActionSet::setActions( const QList& lst ) +{ + for ( ActionList::iterator it = mySet.begin(); it != mySet.end(); ++it ) + { + if ( !lst.contains( *it ) ) + delete *it; + } + + mySet.clear(); + + insertActions( lst ); +} + +void QtxActionSet::insertActions( const QList& lst, const int index ) +{ + int idx = qMin( index < 0 ? mySet.count() : index, mySet.count() ); + + for ( QList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + { + QAction* a = *it; + int ident = generateId(); + + a->setParent( this ); + mySet.insert( idx++, a ); + a->setData( ident ); + + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onActionTriggered( bool ) ) ); + } + + update(); +} + +int QtxActionSet::insertAction( QAction* a, const int id, const int index ) +{ + if ( !a ) + return -1; + + int ident = id < 0 ? generateId() : id; + int idx = qMin( index < 0 ? mySet.count() : index, mySet.count() ); + + a->setParent( this ); + mySet.insert( idx, a ); + a->setData( ident ); + + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onActionTriggered( bool ) ) ); + + update(); + + return ident; +} + +int QtxActionSet::insertAction( const QString& txt, const int id, const int index ) +{ + return insertAction( new QtxAction( txt, txt, 0, this ), id, index ); +} + +int QtxActionSet::insertAction( const QString& txt, const QIcon& ico, const int id, const int index ) +{ + return insertAction( new QtxAction( txt, ico, txt, 0, this ), id, index ); +} + +void QtxActionSet::removeAction( QAction* a ) +{ + if ( !mySet.contains( a ) ) + return; + + mySet.removeAll( a ); + delete a; +} + +void QtxActionSet::removeAction( const int id ) +{ + removeAction( action( id ) ); +} + +void QtxActionSet::clear() +{ + qDeleteAll( mySet ); + mySet.clear(); + + update(); +} + +void QtxActionSet::onChanged() +{ + if ( !isVisible() ) + return; + + bool block = signalsBlocked(); + blockSignals( true ); + setVisible( false ); + blockSignals( block ); +} + +void QtxActionSet::onActionTriggered( bool ) +{ + QAction* a = ::qobject_cast( sender() ); + if ( !a ) + return; + + int id = actionId( a ); + if ( id != -1 ) + emit triggered( id ); + emit triggered( a ); +} + +void QtxActionSet::addedTo( QWidget* w ) +{ + QtxAction::addedTo( w ); + + update( w ); +} + +void QtxActionSet::removedFrom( QWidget* w ) +{ + QtxAction::removedFrom( w ); + + update( w ); +} + +QAction* QtxActionSet::action( int id ) const +{ + QAction* a = 0; + for ( ActionList::const_iterator it = mySet.begin(); it != mySet.end() && !a; ++it ) + { + if ( actionId( *it ) == id ) + a = *it; + } + return a; +} + +int QtxActionSet::actionId( QAction* a ) const +{ + int id = -1; + if ( a && a->data().canConvert( QVariant::Int ) ) + id = a->data().toInt(); + return id; +} + +void QtxActionSet::setActionId( QAction* a, const int id ) +{ + if ( !a || id == -1 ) + return; + + a->setData( id ); +} + +int QtxActionSet::generateId() const +{ + QMap map; + for ( ActionList::const_iterator it = mySet.begin(); it != mySet.end(); ++it ) + map.insert( (*it)->data().toInt(), 0 ); + + int id = -2; + while ( map.contains( id ) ) + id--; + + return id; +} + +void QtxActionSet::update() +{ + QList lst = associatedWidgets(); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + update( *it ); +} + +void QtxActionSet::update( QWidget* w ) +{ + if ( !w ) + return; + + for ( ActionList::iterator it = mySet.begin(); it != mySet.end(); ++it ) + w->removeAction( *it ); + + if ( !associatedWidgets().contains( w ) ) + return; + + for ( int i = 0; i < mySet.count(); i++ ) + { + QAction* a = mySet.at( i ); + w->insertAction( this, a ); + } +} diff --git a/src/Qtx/QtxActionSet.h b/src/Qtx/QtxActionSet.h new file mode 100644 index 000000000..8f8d11421 --- /dev/null +++ b/src/Qtx/QtxActionSet.h @@ -0,0 +1,88 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxActionSet.h +// Author: Sergey TELKOV + +#ifndef QTXACTIONSET_H +#define QTXACTIONSET_H + +#include "QtxAction.h" + +#include +#include + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +class QTX_EXPORT QtxActionSet : public QtxAction +{ + Q_OBJECT + +public: + QtxActionSet( QObject* = 0 ); + virtual ~QtxActionSet(); + + QList actions() const; + void setActions( const QList& ); + + void insertActions( const QList&, const int = -1 ); + + int insertAction( QAction*, const int id = -1, const int = -1 ); + int insertAction( const QString&, const int id = -1, const int = -1 ); + int insertAction( const QString&, const QIcon&, const int id = -1, const int = -1 ); + + void removeAction( QAction* ); + void removeAction( const int ); + + void clear(); + +signals: + void triggered( int ); + void triggered( QAction* ); + +private slots: + void onChanged(); + void onActionTriggered( bool = false ); + +protected: + virtual void addedTo( QWidget* ); + virtual void removedFrom( QWidget* ); + + QAction* action( int ) const; + int actionId( QAction* ) const; + void setActionId( QAction*, const int ); + +private: + void update(); + void update( QWidget* ); + int generateId() const; + +private: + typedef QList ActionList; + +private: + ActionList mySet; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/Qtx/QtxLogoMgr.cxx b/src/Qtx/QtxLogoMgr.cxx index 47a8d5628..9f1617d5f 100644 --- a/src/Qtx/QtxLogoMgr.cxx +++ b/src/Qtx/QtxLogoMgr.cxx @@ -153,12 +153,12 @@ void QtxLogoMgr::LogoBox::updateContents() base->setMargin( 0 ); base->setSpacing( 3 ); - if ( myCornWid ) - base->addWidget( myCornWid ); - for ( QList::const_iterator it = myLabels.begin(); it != myLabels.end(); ++it ) base->addWidget( *it ); + if ( myCornWid ) + base->addWidget( myCornWid ); + QApplication::sendPostedEvents(); } diff --git a/src/Qtx/QtxWorkspaceAction.cxx b/src/Qtx/QtxWorkspaceAction.cxx index f06c5c2a4..7a163d590 100644 --- a/src/Qtx/QtxWorkspaceAction.cxx +++ b/src/Qtx/QtxWorkspaceAction.cxx @@ -21,31 +21,32 @@ #include "QtxWorkspaceAction.h" -#include -#include -#include +#include "QtxWorkspace.h" + +#include +#include +#include /*! Constructor */ -QtxWorkspaceAction::QtxWorkspaceAction( QWorkspace* ws, QObject* parent, const char* name ) -: QtxAction( tr( "Controls windows into workspace" ), tr( "Workspace management" ), 0, parent, name ), -myFlags( Standard ), +QtxWorkspaceAction::QtxWorkspaceAction( QtxWorkspace* ws, QObject* parent ) +: QtxActionSet( parent ), +myFlags( 0 ), myWorkspace( ws ) { - myItem.insert( Cascade, new QtxAction( tr( "Arranges the windows as overlapping tiles" ), - tr( "Cascade" ), 0, this, 0, false ) ); - myItem.insert( Tile, new QtxAction( tr( "Arranges the windows as nonoverlapping tiles" ), - tr( "Tile" ), 0, this, 0, false ) ); - myItem.insert( HTile, new QtxAction( tr( "Arranges the windows as nonoverlapping horizontal tiles" ), - tr( "Tile horizontally" ), 0, this, 0, false ) ); - myItem.insert( VTile, new QtxAction( tr( "Arranges the windows as nonoverlapping vertical tiles" ), - tr( "Tile vertically" ), 0, this, 0, false ) ); - - connect( myItem[Tile], SIGNAL( activated() ), this, SLOT( tile() ) ); - connect( myItem[Cascade], SIGNAL( activated() ), this, SLOT( cascade() ) ); - connect( myItem[HTile], SIGNAL( activated() ), this, SLOT( tileVertical() ) ); - connect( myItem[VTile], SIGNAL( activated() ), this, SLOT( tileHorizontal() ) ); + insertAction( new QtxAction( tr( "Arranges the windows as overlapping tiles" ), + tr( "Cascade" ), 0, this ), Cascade ); + insertAction( new QtxAction( tr( "Arranges the windows as nonoverlapping tiles" ), + tr( "Tile" ), 0, this ), Tile ); + insertAction( new QtxAction( tr( "Arranges the windows as nonoverlapping horizontal tiles" ), + tr( "Tile horizontally" ), 0, this ), HTile ); + insertAction( new QtxAction( tr( "Arranges the windows as nonoverlapping vertical tiles" ), + tr( "Tile vertically" ), 0, this ), VTile ); + + connect( this, SIGNAL( triggered( int ) ), this, SLOT( onTriggered( int ) ) ); + + setItems( Standard ); } /*! @@ -58,7 +59,7 @@ QtxWorkspaceAction::~QtxWorkspaceAction() /*! \return corresponding workspace */ -QWorkspace* QtxWorkspaceAction::workspace() const +QtxWorkspace* QtxWorkspaceAction::workspace() const { return myWorkspace; } @@ -77,10 +78,18 @@ int QtxWorkspaceAction::items() const */ void QtxWorkspaceAction::setItems( const int flags ) { - if ( !flags || flags == myFlags || !( flags & Operations ) ) + if ( flags == myFlags ) return; myFlags = flags; + + uint f = Windows; + while ( f ) + { + if ( action( f ) ) + action( f )->setVisible( myFlags & f ); + f = f >> 1; + } } /*! @@ -99,8 +108,8 @@ bool QtxWorkspaceAction::hasItems( const int flags ) const int QtxWorkspaceAction::accel( const int id ) const { int a = 0; - if ( myItem.contains( id ) ) - a = myItem[id]->accel(); + if ( action( id ) ) + a = action( id )->shortcut(); return a; } @@ -108,11 +117,11 @@ int QtxWorkspaceAction::accel( const int id ) const \return icons of item \param id - item id */ -QIconSet QtxWorkspaceAction::iconSet( const int id ) const +QIcon QtxWorkspaceAction::icon( const int id ) const { - QIconSet ico; - if ( myItem.contains( id ) ) - ico = myItem[id]->iconSet(); + QIcon ico; + if ( action( id ) ) + ico = action( id )->icon(); return ico; } @@ -120,11 +129,11 @@ QIconSet QtxWorkspaceAction::iconSet( const int id ) const \return menu text of item \param id - item id */ -QString QtxWorkspaceAction::menuText( const int id ) const +QString QtxWorkspaceAction::text( const int id ) const { QString txt; - if ( myItem.contains( id ) ) - txt = myItem[id]->menuText(); + if ( action( id ) ) + txt = action( id )->text(); return txt; } @@ -135,8 +144,8 @@ QString QtxWorkspaceAction::menuText( const int id ) const QString QtxWorkspaceAction::statusTip( const int id ) const { QString txt; - if ( myItem.contains( id ) ) - txt = myItem[id]->statusTip(); + if ( action( id ) ) + txt = action( id )->statusTip(); return txt; } @@ -147,8 +156,8 @@ QString QtxWorkspaceAction::statusTip( const int id ) const */ void QtxWorkspaceAction::setAccel( const int id, const int a ) { - if ( myItem.contains( id ) ) - myItem[id]->setAccel( a ); + if ( action( id ) ) + action( id )->setShortcut( a ); } /*! @@ -156,10 +165,10 @@ void QtxWorkspaceAction::setAccel( const int id, const int a ) \param id - item id \param ico - new icons */ -void QtxWorkspaceAction::setIconSet( const int id, const QIconSet& ico ) +void QtxWorkspaceAction::setIcon( const int id, const QIcon& ico ) { - if ( myItem.contains( id ) ) - myItem[id]->setIconSet( ico ); + if ( action( id ) ) + action( id )->setIcon( ico ); } /*! @@ -167,10 +176,10 @@ void QtxWorkspaceAction::setIconSet( const int id, const QIconSet& ico ) \param id - item id \param txt - new menu text */ -void QtxWorkspaceAction::setMenuText( const int id, const QString& txt ) +void QtxWorkspaceAction::setText( const int id, const QString& txt ) { - if ( myItem.contains( id ) ) - myItem[id]->setMenuText( txt ); + if ( action( id ) ) + action( id )->setText( txt ); } /*! @@ -180,65 +189,8 @@ void QtxWorkspaceAction::setMenuText( const int id, const QString& txt ) */ void QtxWorkspaceAction::setStatusTip( const int id, const QString& txt ) { - if ( myItem.contains( id ) ) - myItem[id]->setStatusTip( txt ); -} - -/*! - Adds action to widget - \param wid - widget -*/ -bool QtxWorkspaceAction::addTo( QWidget* wid ) -{ - return addTo( wid, -1 ); -} - -/*! - Adds action to widget - \param wid - widget - \param idx - position -*/ -bool QtxWorkspaceAction::addTo( QWidget* wid, const int idx ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - checkPopup( pm ); - - if ( myMenu.contains( pm ) ) - return false; - - myMenu.insert( pm, QIntList() ); - fillPopup( pm, idx ); - - connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - - return true; -} - -/*! - Removes action from widget - \param wid - widget -*/ -bool QtxWorkspaceAction::removeFrom( QWidget* wid ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - if ( !myMenu.contains( pm ) ) - return false; - - clearPopup( pm ); - - disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - - myMenu.remove( pm ); - - return true; + if ( action( id ) ) + action( id )->setStatusTip( txt ); } /*! @@ -269,11 +221,9 @@ void QtxWorkspaceAction::perform( const int type ) */ void QtxWorkspaceAction::tile() { - QWorkspace* ws = workspace(); - if ( !ws ) - return; - - ws->tile(); + QtxWorkspace* ws = workspace(); + if ( ws ) + ws->tile(); } /*! @@ -281,7 +231,7 @@ void QtxWorkspaceAction::tile() */ void QtxWorkspaceAction::cascade() { - QWorkspace* ws = workspace(); + QtxWorkspace* ws = workspace(); if ( !ws ) return; @@ -291,8 +241,8 @@ void QtxWorkspaceAction::cascade() int h = ws->height(); QWidgetList winList = ws->windowList(); - for ( QWidgetListIt it( winList ); it.current(); ++it ) - it.current()->resize( int( w * 0.8 ), int( h * 0.8 ) ); + for ( QWidgetList::iterator it = winList.begin(); it != winList.end(); ++it ) + (*it)->resize( int( w * 0.8 ), int( h * 0.8 ) ); } /*! @@ -300,42 +250,9 @@ void QtxWorkspaceAction::cascade() */ void QtxWorkspaceAction::tileVertical() { - QWorkspace* wrkSpace = workspace(); - if ( !wrkSpace ) - return; - - QWidgetList winList = wrkSpace->windowList(); - if ( winList.isEmpty() ) - return; - - int count = 0; - for ( QWidgetListIt itr( winList ); itr.current(); ++itr ) - if ( !itr.current()->testWState( WState_Minimized ) ) - count++; - - if ( !count ) - return; - - int y = 0; - - int heightForEach = wrkSpace->height() / count; - for ( QWidgetListIt it( winList ); it.current(); ++it ) - { - QWidget* win = it.current(); - if ( win->testWState( WState_Minimized ) ) - continue; - - if ( win->testWState( WState_Maximized ) ) - { - win->hide(); - win->showNormal(); - } - int prefH = win->minimumHeight() + win->parentWidget()->baseSize().height(); - int actualH = QMAX( heightForEach, prefH ); - - win->parentWidget()->setGeometry( 0, y, wrkSpace->width(), actualH ); - y += actualH; - } + QtxWorkspace* ws = workspace(); + if ( ws ) + ws->tileVertical(); } /*! @@ -343,174 +260,96 @@ void QtxWorkspaceAction::tileVertical() */ void QtxWorkspaceAction::tileHorizontal() { - QWorkspace* wrkSpace = workspace(); - if ( !wrkSpace ) - return; - - QWidgetList winList = wrkSpace->windowList(); - if ( winList.isEmpty() ) - return; - - int count = 0; - for ( QWidgetListIt itr( winList ); itr.current(); ++itr ) - if ( !itr.current()->testWState( WState_Minimized ) ) - count++; - - if ( !count ) - return; - - int x = 0; - int widthForEach = wrkSpace->width() / count; - for ( QWidgetListIt it( winList ); it.current(); ++it ) - { - QWidget* win = it.current(); - if ( win->testWState( WState_Minimized ) ) - continue; - - if ( win->testWState( WState_Maximized ) ) - { - win->hide(); - win->showNormal(); - } - int prefW = win->minimumWidth(); - int actualW = QMAX( widthForEach, prefW ); - - win->parentWidget()->setGeometry( x, 0, actualW, wrkSpace->height() ); - x += actualW; - } + QtxWorkspace* ws = workspace(); + if ( ws ) + ws->tileHorizontal(); } -/*! - SLOT: called just before the popup menu is displayed, updates popup -*/ -void QtxWorkspaceAction::onAboutToShow() +void QtxWorkspaceAction::addedTo( QWidget* w ) { - const QObject* obj = sender(); - if ( !obj || !obj->inherits( "QPopupMenu" ) ) - return; + QtxActionSet::addedTo( w ); - updatePopup( (QPopupMenu*)obj ); + QMenu* pm = ::qobject_cast( w ); + if ( pm ) + connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); } -/*! - SLOT: called when popup menu is destroyed, removes it from menu -*/ -void QtxWorkspaceAction::onPopupDestroyed( QObject* obj ) +void QtxWorkspaceAction::removedFrom( QWidget* w ) { - myMenu.remove( (QPopupMenu*)obj ); -} - -/*! - Updates popup - \param pm - popup menu -*/ -void QtxWorkspaceAction::checkPopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return; - - QIntList updList; - for ( QIntList::const_iterator it = myMenu[pm].begin(); it != myMenu[pm].end(); ++it ) - { - if ( pm->indexOf( *it ) != -1 ) - updList.append( *it ); - } - - myMenu.remove( pm ); + QtxActionSet::removedFrom( w ); - if ( !updList.isEmpty() ) - myMenu.insert( pm, updList ); - else - { + QMenu* pm = ::qobject_cast( w ); + if ( pm ) disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - } } /*! - Clears and refills popup and updates state of actions - \param pm - popup menu + Refills actions and updates thier state. */ -void QtxWorkspaceAction::updatePopup( QPopupMenu* pm ) +void QtxWorkspaceAction::updateContent() { - if ( !myMenu.contains( pm ) ) - return; - - fillPopup( pm, clearPopup( pm ) ); - bool count = workspace() ? workspace()->windowList().count() : 0; - myItem[Cascade]->setEnabled( count ); - myItem[Tile]->setEnabled( count ); - myItem[HTile]->setEnabled( count ); - myItem[VTile]->setEnabled( count ); -} - -/*! - Clears popup - \param pm - popup menu -*/ -int QtxWorkspaceAction::clearPopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return -1; - - int idx = -1; - const QIntList& lst = myMenu[pm]; - for ( QIntList::const_iterator it = lst.begin(); it != lst.end() && idx == -1; ++it ) - idx = pm->indexOf( *it ); + action( Cascade )->setEnabled( count ); + action( Tile )->setEnabled( count ); + action( HTile )->setEnabled( count ); + action( VTile )->setEnabled( count ); - for ( ItemMap::ConstIterator mit = myItem.begin(); mit != myItem.end(); ++mit ) - mit.data()->removeFrom( pm ); - - for ( QIntList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) - pm->removeItem( *itr ); - - return idx; + updateWindows(); } -/*! - Fills popup with items - \param pm - popup menu - \param idx - position -*/ -void QtxWorkspaceAction::fillPopup( QPopupMenu* pm, const int idx ) +void QtxWorkspaceAction::updateWindows() { - if ( !pm ) + QtxWorkspace* ws = workspace(); + if ( !ws ) return; - int index = idx < 0 ? pm->count() : QMIN( (int)pm->count(), idx ); + QList lst = actions(); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + { + int id = actionId( *it ); + if ( id >= Windows ) + removeAction( *it ); + } - myMenu.insert( pm, QIntList() ); - QIntList& lst = myMenu[pm]; + bool base = action( Cascade )->isVisible() || action( Tile )->isVisible() || + action( HTile )->isVisible() || action( VTile )->isVisible(); - for ( ItemMap::ConstIterator mit = myItem.begin(); mit != myItem.end(); ++mit ) + QList items; + QMap map; + if ( hasItems( Windows ) ) { - if ( !hasItems( mit.key() ) ) - continue; + int index = 1; + QWidgetList wList = ws->windowList(); + for ( QWidgetList::iterator it = wList.begin(); it != wList.end(); ++it, index++ ) + { + QWidget* wid = *it; + QAction* a = new QtxAction( wid->windowTitle(), wid->windowTitle(), 0, this, true ); + a->setChecked( wid == ws->activeWindow() ); + items.append( a ); + map.insert( a, Windows + index ); + } - mit.data()->addTo( pm, index ); - lst.append( pm->idAt( index++ ) ); + if ( base && !items.isEmpty() ) + { + QAction* sep = new QtxAction( this ); + sep->setSeparator( true ); + items.prepend( sep ); + map.insert( sep, Windows ); + } } - QWorkspace* ws = workspace(); - if ( !ws || !hasItems( Windows ) ) - return; - - QWidgetList wList = ws->windowList(); - if ( wList.isEmpty() ) - return; + if ( !items.isEmpty() ) + insertActions( items ); - lst.append( pm->insertSeparator( index++ ) ); + for ( QMap::const_iterator itr = map.begin(); itr != map.end(); ++itr ) + setActionId( itr.key(), itr.value() ); +} - int param = 0; - pm->setCheckable( true ); - for ( QWidgetListIt it( wList ); it.current(); ++it ) - { - int id = pm->insertItem( it.current()->caption(), this, SLOT( onItemActivated( int ) ), 0, -1, index++ ); - pm->setItemParameter( id, param++ ); - pm->setItemChecked( id, it.current() == ws->activeWindow() ); - lst.append( id ); - } +void QtxWorkspaceAction::onAboutToShow() +{ + QMenu* pm = ::qobject_cast( sender() ); + if ( pm ) + updateContent(); } /*! @@ -518,7 +357,7 @@ void QtxWorkspaceAction::fillPopup( QPopupMenu* pm, const int idx ) */ void QtxWorkspaceAction::onItemActivated( int idx ) { - QWorkspace* ws = workspace(); + QtxWorkspace* ws = workspace(); if ( !ws ) return; @@ -528,3 +367,21 @@ void QtxWorkspaceAction::onItemActivated( int idx ) wList.at( idx )->setFocus(); } + +void QtxWorkspaceAction::onTriggered( int id ) +{ + if ( id < Windows ) + perform( id ); + else + { + int idx = id - Windows - 1; + + QtxWorkspace* ws = workspace(); + if ( ws ) + { + QWidgetList wList = ws->windowList(); + if ( idx >= 0 && idx < (int)wList.count() ) + wList.at( idx )->setFocus(); + } + } +} diff --git a/src/Qtx/QtxWorkspaceAction.h b/src/Qtx/QtxWorkspaceAction.h index 2dfee9cdb..1b3c92a7c 100644 --- a/src/Qtx/QtxWorkspaceAction.h +++ b/src/Qtx/QtxWorkspaceAction.h @@ -22,15 +22,16 @@ #ifndef QTXWORKSPACEACTION_H #define QTXWORKSPACEACTION_H -#include "QtxAction.h" +#include "QtxActionSet.h" -class QWorkspace; +class QMenu; +class QtxWorkspace; #ifdef WIN32 #pragma warning( disable:4251 ) #endif -class QTX_EXPORT QtxWorkspaceAction : public QtxAction +class QTX_EXPORT QtxWorkspaceAction : public QtxActionSet { Q_OBJECT @@ -45,58 +46,49 @@ public: All = Standard | HTile | VTile }; public: - QtxWorkspaceAction( QWorkspace*, QObject* = 0, const char* = 0 ); + QtxWorkspaceAction( QtxWorkspace*, QObject* = 0 ); virtual ~QtxWorkspaceAction(); - QWorkspace* workspace() const; + QtxWorkspace* workspace() const; - int items() const; - void setItems( const int ); - bool hasItems( const int ) const; + int items() const; + void setItems( const int ); + bool hasItems( const int ) const; - int accel( const int ) const; - QIconSet iconSet( const int ) const; - QString menuText( const int ) const; - QString statusTip( const int ) const; + QIcon icon( const int ) const; + QString text( const int ) const; + int accel( const int ) const; + QString statusTip( const int ) const; - void setAccel( const int, const int ); - void setIconSet( const int, const QIconSet& ); - void setMenuText( const int, const QString& ); - void setStatusTip( const int, const QString& ); + void setAccel( const int, const int ); + void setIcon( const int, const QIcon& ); + void setText( const int, const QString& ); + void setStatusTip( const int, const QString& ); - virtual bool addTo( QWidget* ); - virtual bool addTo( QWidget*, const int ); - virtual bool removeFrom( QWidget* ); - - void perform( const int ); + void perform( const int ); public slots: - void tile(); - void cascade(); - void tileVertical(); - void tileHorizontal(); + void tile(); + void cascade(); + void tileVertical(); + void tileHorizontal(); private slots: - void onAboutToShow(); - void onItemActivated( int ); - void onPopupDestroyed( QObject* ); - -private: - void checkPopup( QPopupMenu* ); - void updatePopup( QPopupMenu* ); + void onTriggered( int ); + void onAboutToShow(); + void onItemActivated( int ); - int clearPopup( QPopupMenu* ); - void fillPopup( QPopupMenu*, const int ); +protected: + virtual void addedTo( QWidget* ); + virtual void removedFrom( QWidget* ); private: - typedef QMap MenuMap; - typedef QMap ItemMap; + void updateContent(); + void updateWindows(); private: - MenuMap myMenu; - ItemMap myItem; - int myFlags; - QWorkspace* myWorkspace; + int myFlags; + QtxWorkspace* myWorkspace; }; #ifdef WIN32 diff --git a/src/STD/STD_MDIDesktop.cxx b/src/STD/STD_MDIDesktop.cxx index 039833bb0..5eb434840 100755 --- a/src/STD/STD_MDIDesktop.cxx +++ b/src/STD/STD_MDIDesktop.cxx @@ -23,8 +23,8 @@ #include #include -//#include -//#include +#include +#include #include #include @@ -36,8 +36,8 @@ */ STD_MDIDesktop::STD_MDIDesktop() : SUIT_Desktop(), -myWorkspace( 0 )//, -//myWorkspaceAction( 0 ) +myWorkspace( 0 ), +myWorkspaceAction( 0 ) { QFrame* base = new QFrame( this ); QVBoxLayout* main = new QVBoxLayout( base ); @@ -106,9 +106,9 @@ void STD_MDIDesktop::addWindow( QWidget* w ) } /*!Call method perform for operation \a type.*/ -void STD_MDIDesktop::windowOperation( const int /*type*/ ) +void STD_MDIDesktop::windowOperation( const int type ) { - //myWorkspaceAction->perform( operationFlag( type ) ); + myWorkspaceAction->perform( operationFlag( type ) ); } /*!Sets window operations by \a first ... parameters.*/ @@ -137,7 +137,7 @@ void STD_MDIDesktop::setWindowOperations( const QList& opList ) for ( QList::const_iterator it = opList.begin(); it != opList.end(); ++it ) flags = flags | operationFlag( *it ); -// myWorkspaceAction->setItems( flags ); + myWorkspaceAction->setItems( flags ); } /*! @@ -162,7 +162,6 @@ void STD_MDIDesktop::onWindowActivated( QWidget* w ) */ void STD_MDIDesktop::createActions() { -/* if ( myWorkspaceAction ) return; @@ -177,45 +176,42 @@ void STD_MDIDesktop::createActions() QtxWorkspaceAction::Windows ); // Cascade - myWorkspaceAction->setIconSet( QtxWorkspaceAction::Cascade, - resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_CASCADE" ) ) ); - myWorkspaceAction->setMenuText( QtxWorkspaceAction::Cascade, tr( "MEN_DESK_WINDOW_CASCADE" ) ); + myWorkspaceAction->setIcon( QtxWorkspaceAction::Cascade, + resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_CASCADE" ) ) ); + myWorkspaceAction->setText( QtxWorkspaceAction::Cascade, tr( "MEN_DESK_WINDOW_CASCADE" ) ); myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Cascade, tr( "PRP_DESK_WINDOW_CASCADE" ) ); // Tile - myWorkspaceAction->setIconSet( QtxWorkspaceAction::Tile, - resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_TILE" ) ) ); - myWorkspaceAction->setMenuText( QtxWorkspaceAction::Tile, tr( "MEN_DESK_WINDOW_TILE" ) ); + myWorkspaceAction->setIcon( QtxWorkspaceAction::Tile, + resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_TILE" ) ) ); + myWorkspaceAction->setText( QtxWorkspaceAction::Tile, tr( "MEN_DESK_WINDOW_TILE" ) ); myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Tile, tr( "PRP_DESK_WINDOW_TILE" ) ); // Tile Horizontal - myWorkspaceAction->setIconSet( QtxWorkspaceAction::HTile, - resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HTILE" ) ) ); - myWorkspaceAction->setMenuText( QtxWorkspaceAction::HTile, tr( "MEN_DESK_WINDOW_HTILE" ) ); + myWorkspaceAction->setIcon( QtxWorkspaceAction::HTile, + resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HTILE" ) ) ); + myWorkspaceAction->setText( QtxWorkspaceAction::HTile, tr( "MEN_DESK_WINDOW_HTILE" ) ); myWorkspaceAction->setStatusTip( QtxWorkspaceAction::HTile, tr( "PRP_DESK_WINDOW_HTILE" ) ); // Tile Vertical - myWorkspaceAction->setIconSet( QtxWorkspaceAction::VTile, - resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VTILE" ) ) ); - myWorkspaceAction->setMenuText( QtxWorkspaceAction::VTile, tr( "MEN_DESK_WINDOW_VTILE" ) ); + myWorkspaceAction->setIcon( QtxWorkspaceAction::VTile, + resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VTILE" ) ) ); + myWorkspaceAction->setText( QtxWorkspaceAction::VTile, tr( "MEN_DESK_WINDOW_VTILE" ) ); myWorkspaceAction->setStatusTip( QtxWorkspaceAction::VTile, tr( "PRP_DESK_WINDOW_VTILE" ) ); - QtxActionMenuMgr* mMgr = menuMgr(); if ( !mMgr ) return; - int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100, MenuWindowId ); + int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 ); mMgr->insert( myWorkspaceAction, winMenuId, -1 ); mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 ); -*/ } /*!Convert STD_MDIDesktop enumerations to QtxWorkspaceAction.*/ -int STD_MDIDesktop::operationFlag( const int /*type*/ ) const +int STD_MDIDesktop::operationFlag( const int type ) const { int res = 0; -/* switch ( type ) { case Cascade: @@ -231,6 +227,5 @@ int STD_MDIDesktop::operationFlag( const int /*type*/ ) const res = QtxWorkspaceAction::VTile; break; } -*/ return res; } diff --git a/src/STD/STD_MDIDesktop.h b/src/STD/STD_MDIDesktop.h index 22caa0cae..a3506a468 100755 --- a/src/STD/STD_MDIDesktop.h +++ b/src/STD/STD_MDIDesktop.h @@ -24,7 +24,7 @@ #include class QtxWorkspace; -//class QtxWorkspaceAction; +class QtxWorkspaceAction; #if defined WIN32 #pragma warning( disable: 4251 ) @@ -35,7 +35,6 @@ class STD_EXPORT STD_MDIDesktop: public SUIT_Desktop Q_OBJECT public: - enum { MenuWindowId = 6 }; enum { Cascade, Tile, HTile, VTile }; public: @@ -64,7 +63,7 @@ private: private: QtxWorkspace* myWorkspace; -// QtxWorkspaceAction* myWorkspaceAction; + QtxWorkspaceAction* myWorkspaceAction; }; #if defined WIN32