*/
QtxWorkspaceAction::QtxWorkspaceAction( QtxWorkspace* ws, QObject* parent )
: QtxActionSet( parent ),
- myWorkspace( ws )
+ myWorkspace( ws ),
+ myWindowsFlag( true )
{
insertAction( new QtxAction( tr( "Arranges the windows as overlapping tiles" ),
tr( "Cascade" ), 0, this ), Cascade );
action( Tile )->setVisible( flags & Tile );
action( VTile )->setVisible( flags & VTile );
action( HTile )->setVisible( flags & HTile );
- action( Windows )->setVisible( flags & Windows );
+ myWindowsFlag = flags & Windows;
}
/*!
ret = ret | ( action( Tile )->isVisible() ? Tile : 0 );
ret = ret | ( action( VTile )->isVisible() ? VTile : 0 );
ret = ret | ( action( HTile )->isVisible() ? HTile : 0 );
- ret = ret | ( action( Windows )->isVisible() ? Windows : 0 );
+ ret = ret | ( myWindowsFlag ? Windows : 0 );
return ret;
}
Activates correposponding child window.
*/
-void QtxWorkspaceAction::onItemActivated( int idx )
+void QtxWorkspaceAction::activateItem( const int idx )
{
QtxWorkspace* ws = workspace();
if ( !ws )
return;
QWidgetList wList = ws->windowList();
- if ( idx < 0 || idx >= (int)wList.count() )
- return;
-
- wList.at( idx )->setFocus();
+ if ( idx >= 0 && idx < (int)wList.count() )
+ wList.at( idx )->setFocus();
}
/*!
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();
- }
- }
+ activateItem( id - Windows - 1 );
}
QtxWorkspace* workspace() const;
- void setMenuActions( const int );
int menuActions() const;
+ void setMenuActions( const int );
QIcon icon( const int ) const;
QString text( const int ) const;
void tileHorizontal();
private slots:
- void onTriggered( int );
void onAboutToShow();
- void onItemActivated( int );
+ void onTriggered( int );
protected:
virtual void addedTo( QWidget* );
private:
void updateContent();
void updateWindows();
+ void activateItem( const int );
private:
QtxWorkspace* myWorkspace;
+ bool myWindowsFlag;
};
#ifdef WIN32
#include "QtxWorkstack.h"
-#include <qpopupmenu.h>
-#include <qwidgetlist.h>
+#include <QMenu>
+#include <QWidgetList>
/*!
- Constructor
+ \class QtxWorkstackAction
+ \brief Implements actions group for menu Windows with standard operations, like
+ "Split vertical", "Split horizontal", etc.
*/
-QtxWorkstackAction::QtxWorkstackAction( QtxWorkstack* ws, QObject* parent, const char* name )
-: QtxAction( tr( "Controls windows into workstack" ), tr( "Workstack management" ), 0, parent, name ),
-myFlags( Standard ),
-myWorkstack( ws )
+
+/*!
+ \brief Constructor.
+ \param ws workstack
+ \param parent parent object (owner of the action)
+*/
+QtxWorkstackAction::QtxWorkstackAction( QtxWorkstack* ws, QObject* parent )
+: QtxActionSet( parent ),
+ myWorkstack( ws ),
+ myWindowsFlag( true )
{
- myItem.insert( VSplit, new QtxAction( tr( "Split the active window on two vertical parts" ),
- tr( "Split vertically" ), 0, this, 0, false ) );
- myItem.insert( HSplit, new QtxAction( tr( "Split the active window on two horizontal parts" ),
- tr( "Split horizontally" ), 0, this, 0, false ) );
+ insertAction( new QtxAction( tr( "Split the active window on two vertical parts" ),
+ tr( "Split vertically" ), 0, this ), SplitVertical );
+ insertAction( new QtxAction( tr( "Split the active window on two horizontal parts" ),
+ tr( "Split horizontally" ), 0, this ), SplitHorizontal );
- connect( myItem[VSplit], SIGNAL( activated() ), ws, SLOT( splitVertical() ) );
- connect( myItem[HSplit], SIGNAL( activated() ), ws, SLOT( splitHorizontal() ) );
+ connect( this, SIGNAL( triggered( int ) ), this, SLOT( onTriggered( int ) ) );
+
+ setMenuActions( Standard );
}
/*!
- Destructor
+ \brief Destructor.
*/
QtxWorkstackAction::~QtxWorkstackAction()
{
}
/*!
- \return corresponding workstack
+ \brief Get workstack.
+ \return parent workstack
*/
QtxWorkstack* QtxWorkstackAction::workstack() const
{
}
/*!
- \return set of action flags
-*/
-int QtxWorkstackAction::items() const
-{
- return myFlags;
-}
+ \brief Set actions to be visible in the menu.
+
+ Actions, which IDs are set in \a flags parameter, will be shown in the
+ menu bar. Other actions will not be shown.
-/*!
- Sets action flags
- \param flags - new set of flags
+ \param flags ORed together actions flags
*/
-void QtxWorkstackAction::setItems( const int flags )
+void QtxWorkstackAction::setMenuActions( const int flags )
{
- if ( !flags || flags == myFlags || !( flags & Split ) )
- return;
-
- myFlags = flags;
+ action( SplitVertical )->setVisible( flags & SplitVertical );
+ action( SplitHorizontal )->setVisible( flags & SplitHorizontal );
+ myWindowsFlag = flags & Windows;
}
/*!
- \return true if action contains all flags
- \param flags - new set of flags
+ \brief Get menu actions which are currently visible in the menu bar.
+ \return ORed together actions flags
+ \sa setMenuActions()
*/
-bool QtxWorkstackAction::hasItems( const int flags ) const
+int QtxWorkstackAction::menuActions() const
{
- return ( myFlags & flags ) == flags;
+ int ret = 0;
+ ret = ret | ( action( SplitVertical )->isVisible() ? SplitVertical : 0 );
+ ret = ret | ( action( SplitHorizontal )->isVisible() ? SplitHorizontal : 0 );
+ ret = ret | ( myWindowsFlag ? Windows : 0 );
+ return ret;
}
/*!
- \return accelerator of item
- \param id - item id
+ \brief Get keyboard accelerator for the specified action.
+ \param id menu action ID
+ \return keyboard accelerator of menu item or 0 if there is no such action
*/
int QtxWorkstackAction::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;
}
/*!
- \return icons of item
- \param id - item id
+ \brief Get icon for the specified action.
+
+ If \a id is invalid, null icon is returned.
+
+ \param id menu action ID
+ \return menu item icon
*/
-QIconSet QtxWorkstackAction::iconSet( const int id ) const
+QIcon QtxWorkstackAction::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;
}
/*!
- \return menu text of item
- \param id - item id
+ \brief Get menu item text for the specified action.
+ \param id menu action ID
+ \return menu item text or null QString if there is no such action
*/
-QString QtxWorkstackAction::menuText( const int id ) const
+QString QtxWorkstackAction::text( const int id ) const
{
QString txt;
- if ( myItem.contains( id ) )
- txt = myItem[id]->menuText();
+ if ( action( id ) )
+ txt = action( id )->text();
return txt;
}
/*!
- \return status tip of item
- \param id - item id
+ \brief Get status bar tip for the specified action.
+ \param id menu action ID
+ \return status bar tip menu item or null QString if there is no such action
*/
QString QtxWorkstackAction::statusTip( const int id ) const
{
QString txt;
- if ( myItem.contains( id ) )
- txt = myItem[id]->statusTip();
+ if ( action( id ) )
+ txt = action( id )->statusTip();
return txt;
}
/*!
- Changes accelerator of item
- \param id - item id
- \param a - new accelerator
+ \brief Set keyboard accelerator for the specified action.
+ \param id menu action ID
+ \param a new keyboard accelerator
*/
void QtxWorkstackAction::setAccel( const int id, const int a )
{
- if ( myItem.contains( id ) )
- myItem[id]->setAccel( a );
+ if ( action( id ) )
+ action( id )->setShortcut( a );
}
/*!
- Changes icons of item
- \param id - item id
- \param ico - new icons
+ \brief Set menu item icon for the specified action.
+ \param id menu action ID
+ \param ico new menu item icon
*/
-void QtxWorkstackAction::setIconSet( const int id, const QIconSet& ico )
+void QtxWorkstackAction::setIcon( const int id, const QIcon& icon )
{
- if ( myItem.contains( id ) )
- myItem[id]->setIconSet( ico );
+ if ( action( id ) )
+ action( id )->setIcon( icon );
}
/*!
- Changes menu text of item
- \param id - item id
- \param txt - new menu text
+ \brief Set menu item text for the specified action.
+ \param id menu action ID
+ \param txt new menu item text
*/
-void QtxWorkstackAction::setMenuText( const int id, const QString& txt )
+void QtxWorkstackAction::setText( const int id, const QString& txt )
{
- if ( myItem.contains( id ) )
- myItem[id]->setMenuText( txt );
+ if ( action( id ) )
+ action( id )->setText( txt );
}
/*!
- Changes status tip of item
- \param id - item id
- \param txt - new status tip
+ \brief Set menu item status bar tip for the specified action.
+ \param id menu action ID
+ \param txt new menu item status bar tip
*/
void QtxWorkstackAction::setStatusTip( const int id, const QString& txt )
{
- if ( myItem.contains( id ) )
- myItem[id]->setStatusTip( txt );
-}
-
-/*!
- Adds action to widget
- \param wid - widget
-*/
-bool QtxWorkstackAction::addTo( QWidget* wid )
-{
- return addTo( wid, -1 );
-}
-
-/*!
- Adds action to widget
- \param wid - widget
- \param idx - position
-*/
-bool QtxWorkstackAction::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 QtxWorkstackAction::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 );
}
/*!
- Performs action
- \param type - action type
+ \brief Process action activated by the user.
+ \param type action ID
*/
void QtxWorkstackAction::perform( const int type )
{
switch ( type )
{
- case VSplit:
- workstack()->splitVertical();
+ case SplitVertical:
+ splitVertical();
break;
- case HSplit:
- workstack()->splitHorizontal();
+ case SplitHorizontal:
+ splitHorizontal();
break;
}
}
/*!
- SLOT: called just before the popup menu is displayed, updates popup
+ \brief Split the window area in the workstack in the vertical direction.
*/
-void QtxWorkstackAction::onAboutToShow()
+void QtxWorkstackAction::splitVertical()
{
- const QObject* obj = sender();
- if ( !obj || !obj->inherits( "QPopupMenu" ) )
- return;
-
QtxWorkstack* ws = workstack();
- if ( ws && myItem.contains( VSplit ) )
- myItem[VSplit]->setAccel( ws->accel( QtxWorkstack::SplitVertical ) );
- if ( ws && myItem.contains( HSplit ) )
- myItem[HSplit]->setAccel( ws->accel( QtxWorkstack::SplitHorizontal ) );
-
- updatePopup( (QPopupMenu*)obj );
+ if ( ws )
+ ws->splitVertical();
}
/*!
- SLOT: called when popup menu is destroyed, removes it from menu
+ \brief Split the window area in the workstack in the horizontal direction.
*/
-void QtxWorkstackAction::onPopupDestroyed( QObject* obj )
+void QtxWorkstackAction::splitHorizontal()
{
- myMenu.remove( (QPopupMenu*)obj );
+ QtxWorkstack* ws = workstack();
+ if ( ws )
+ ws->splitHorizontal();
}
/*!
- Updates popup
- \param pm - popup menu
+ \brief Called when action is added to the menu bar.
+ \param w menu bar widget this action is being added to
*/
-void QtxWorkstackAction::checkPopup( QPopupMenu* pm )
+void QtxWorkstackAction::addedTo( QWidget* w )
{
- 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::addedTo( w );
- if ( !updList.isEmpty() )
- myMenu.insert( pm, updList );
- else
- {
- disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
- disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) );
- }
+ QMenu* pm = ::qobject_cast<QMenu*>( w );
+ if ( pm )
+ connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
}
/*!
- Clears and refills popup and updates state of actions
- \param pm - popup menu
+ \brief Called when action is removed from the menu bar.
+ \param w menu bar widget this action is being removed from
*/
-void QtxWorkstackAction::updatePopup( QPopupMenu* pm )
+void QtxWorkstackAction::removedFrom( QWidget* w )
{
- if ( !myMenu.contains( pm ) )
- return;
-
- fillPopup( pm, clearPopup( pm ) );
+ QtxActionSet::removedFrom( w );
- int count = workstack() ? workstack()->splitWindowList().count() : 0;
- myItem[VSplit]->setEnabled( count > 1 );
- myItem[HSplit]->setEnabled( count > 1 );
+ QMenu* pm = ::qobject_cast<QMenu*>( w );
+ if ( pm )
+ disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
}
/*!
- Clears popup
- \param pm - popup menu
+ \brief Update all menu action state.
*/
-int QtxWorkstackAction::clearPopup( QPopupMenu* pm )
+void QtxWorkstackAction::updateContent()
{
- 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 );
+ bool count = workstack() ? workstack()->splitWindowList().count() > 1 : 0;
+ action( SplitVertical )->setEnabled( count );
+ action( SplitHorizontal )->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
+ \brief Update actions which refer to the opened child windows.
*/
-void QtxWorkstackAction::fillPopup( QPopupMenu* pm, const int idx )
+void QtxWorkstackAction::updateWindows()
{
- if ( !pm )
+ QtxWorkstack* ws = workstack();
+ if ( !ws )
return;
- int index = idx < 0 ? pm->count() : QMIN( (int)pm->count(), idx );
+ QList<QAction*> lst = actions();
+ for ( QList<QAction*>::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( SplitVertical )->isVisible() || action( SplitHorizontal )->isVisible();
- for ( ItemMap::ConstIterator mit = myItem.begin(); mit != myItem.end(); ++mit )
+ QList<QAction*> items;
+ QMap<QAction*, int> map;
+ if ( menuActions() & Windows )
{
- if ( !hasItems( mit.key() ) )
- continue;
-
- mit.data()->addTo( pm, index );
- lst.append( pm->idAt( index++ ) );
+ 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 );
+ }
+
+ if ( base && !items.isEmpty() )
+ {
+ QAction* sep = new QtxAction( this );
+ sep->setSeparator( true );
+ items.prepend( sep );
+ map.insert( sep, Windows );
+ }
}
- QtxWorkstack* ws = workstack();
- if ( !ws || !hasItems( Windows ) )
- return;
+ if ( !items.isEmpty() )
+ insertActions( items );
- QWidgetList wList = ws->windowList();
- if ( wList.isEmpty() )
- return;
+ for ( QMap<QAction*, int>::const_iterator itr = map.begin(); itr != map.end(); ++itr )
+ setActionId( itr.key(), itr.value() );
+}
- lst.append( pm->insertSeparator( index++ ) );
+/*!
+ \brief Called when parent menu is about to show.
- 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 );
- }
+ Updates all menu items.
+*/
+void QtxWorkstackAction::onAboutToShow()
+{
+ QMenu* pm = ::qobject_cast<QMenu*>( sender() );
+ if ( pm )
+ updateContent();
}
/*!
- SLOT: called when popup item corresponding to window is activated, activates window
+ \brief Called when menu item corresponding to some child window is activated.
+
+ Activates correposponding child window.
*/
-void QtxWorkstackAction::onItemActivated( int idx )
+void QtxWorkstackAction::activateItem( const int idx )
{
QtxWorkstack* ws = workstack();
if ( !ws )
return;
QWidgetList wList = ws->windowList();
- if ( idx < 0 || idx >= (int)wList.count() )
- return;
+ if ( idx >= 0 && idx < (int)wList.count() )
+ wList.at( idx )->setFocus();
+}
- wList.at( idx )->setFocus();
+/*!
+ \brief Called when menu item is activated by the user.
+
+ Perform the corresponding action.
+*/
+void QtxWorkstackAction::onTriggered( int id )
+{
+ if ( id < Windows )
+ perform( id );
+ else
+ activateItem( id - Windows - 1 );
}
#ifndef QTXWORKSTACKACTION_H
#define QTXWORKSTACKACTION_H
-#include "QtxAction.h"
+#include "QtxActionSet.h"
class QtxWorkstack;
#pragma warning( disable:4251 )
#endif
-class QTX_EXPORT QtxWorkstackAction : public QtxAction
+class QTX_EXPORT QtxWorkstackAction : public QtxActionSet
{
Q_OBJECT
public:
- enum { VSplit = 0x0001,
- HSplit = 0x0002,
- Windows = 0x0010,
- Split = VSplit | HSplit,
- Standard = Split | Windows };
+ enum { SplitVertical = 0x0001,
+ SplitHorizontal = 0x0002,
+ Windows = 0x0010,
+ Split = SplitVertical | SplitHorizontal,
+ Standard = Split | Windows };
-public:
- QtxWorkstackAction( QtxWorkstack*, QObject* = 0, const char* = 0 );
+ QtxWorkstackAction( QtxWorkstack*, QObject* = 0 );
virtual ~QtxWorkstackAction();
QtxWorkstack* workstack() const;
- int items() const;
- void setItems( const int );
- bool hasItems( const int ) const;
+ int menuActions() const;
+ void setMenuActions( const int );
+ QIcon icon( const int ) const;
+ QString text( const int ) const;
int accel( const int ) const;
- QIconSet iconSet( const int ) const;
- QString menuText( 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 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 );
private slots:
void onAboutToShow();
- void onItemActivated( int );
- void onPopupDestroyed( QObject* );
-
-private:
- void checkPopup( QPopupMenu* );
- void updatePopup( QPopupMenu* );
+ void onTriggered( int );
- int clearPopup( QPopupMenu* );
- void fillPopup( QPopupMenu*, const int );
+protected:
+ virtual void addedTo( QWidget* );
+ virtual void removedFrom( QWidget* );
private:
- typedef QMap<QPopupMenu*, QIntList> MenuMap;
- typedef QMap<int, QtxAction*> ItemMap;
+ void updateContent();
+ void updateWindows();
+ void splitVertical();
+ void splitHorizontal();
+ void activateItem( const int );
private:
- MenuMap myMenu;
- ItemMap myItem;
- int myFlags;
QtxWorkstack* myWorkstack;
+ bool myWindowsFlag;
};
#ifdef WIN32
#include "STD_MDIDesktop.h"
-#include "STD_CloseDlg.h"
-
#include <SUIT_Tools.h>
+#include <SUIT_Study.h>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
-#include <SUIT_Study.h>
-//#include <SUIT_ViewModel.h>
-#include <SUIT_ViewManager.h>
-//#include <SUIT_Operation.h>
#include <SUIT_MessageBox.h>
+#include <SUIT_ViewManager.h>
#include <SUIT_ResourceMgr.h>
#include <QtxDockAction.h>
#include <QtxActionToolMgr.h>
#include <QMenu>
+#include <QStatusBar>
+#include <QCloseEvent>
#include <QFileDialog>
#include <QApplication>
-#include <QCloseEvent>
-#include <QStatusBar>
-
-#include <iostream>
/*!Create and return new instance of STD_Application*/
extern "C" STD_EXPORT SUIT_Application* createApplication()
beforeCloseDoc( study );
if ( study )
- study->closeDocument(myClosePermanently);
+ study->closeDocument();
+// TODO: myClosePermanently move to SalomeApp
+// study->closeDocument( myClosePermanently );
clearViewManagers();
for ( int i = 0; i < apps.count(); i++ )
aNbStudies += apps.at( i )->getNbStudies();
- // STV: aNbStudies - number of currently existing studies (exclude currently closed)
- // STV: aNbStudies should be compared with 0.
if ( aNbStudies )
{
savePreferences();
*/
bool STD_Application::isPossibleToClose()
{
- myClosePermanently = true; //SRN: BugID: IPAL9021
+// TODO: myClosePermanently move to SalomeApp
+// myClosePermanently = true;
if ( activeStudy() )
{
activeStudy()->abortAllOperations();
if ( activeStudy()->isModified() )
{
QString sName = activeStudy()->studyName().trimmed();
- QString msg = sName.isEmpty() ? tr( "INF_DOC_MODIFIED" ) : tr ( "INF_DOCUMENT_MODIFIED" ).arg( sName );
+ return closeAction( closeChoice( sName ) );
+ }
+ }
+ return true;
+}
- //SRN: BugID: IPAL9021: Begin
- STD_CloseDlg dlg(desktop());
- switch( dlg.exec() )
- {
- case 1:
- if ( activeStudy()->isSaved() )
- onSaveDoc();
- else if ( !onSaveAsDoc() )
- return false;
- break;
- case 2:
- break;
- case 3:
+int STD_Application::closeChoice( const QString& docName )
+{
+ int answer = SUIT_MessageBox::question( desktop(), tr( "CLOSE_STUDY" ), tr( "CLOSE_QUESTION" ).arg( docName ),
+ SUIT_MessageBox::Save | SUIT_MessageBox::Discard | SUIT_MessageBox::Cancel,
+ SUIT_MessageBox::Save );
+
+ int res = CloseCancel;
+ if ( answer == SUIT_MessageBox::Save )
+ res = CloseSave;
+ else if ( answer == SUIT_MessageBox::Discard )
+ res = CloseDiscard;
+
+ return res;
+}
+
+bool STD_Application::closeAction( const int choice )
+{
+ bool res = true;
+ switch( choice )
+ {
+ case CloseSave:
+ if ( activeStudy()->isSaved() )
+ onSaveDoc();
+ else if ( !onSaveAsDoc() )
+ res = false;
+ break;
+ case CloseDiscard:
+ break;
+/*
+ case 3:
myClosePermanently = false;
break;
- case 4:
- default:
- return false;
- }
- //SRN: BugID: IPAL9021: End
- }
+*/
+ case CloseCancel:
+ default:
+ res = false;
}
- return true;
+
+ return res;
}
/*!Save document if all ok, else error message.*/
{
putInfo( "" );
// displaying a message box as SUIT_Validator in case file can't be written (the most frequent case)
- SUIT_MessageBox::error1( desktop(),
- tr( "ERR_ERROR" ),
- tr( "ERR_PERMISSION_DENIED" ).arg( activeStudy()->studyName() ),
- tr( "BUT_OK" ) );
+ SUIT_MessageBox::critical( desktop(), tr( "ERR_ERROR" ),
+ tr( "ERR_PERMISSION_DENIED" ).arg( activeStudy()->studyName() ) );
}
else
putInfo( tr( "INF_DOC_SAVED" ).arg( "" ) );
QApplication::restoreOverrideCursor();
if ( !isOk )
- SUIT_MessageBox::error1( desktop(), tr( "ERROR" ),
- tr( "INF_DOC_SAVING_FAILS" ).arg( aName ),
- tr( "BUT_OK" ) );
+ SUIT_MessageBox::critical( desktop(), tr( "ERROR" ), tr( "INF_DOC_SAVING_FAILS" ).arg( aName ) );
}
studySaved( activeStudy() );
{
int aAnswer = 1;
if ( exitConfirmation() )
- aAnswer = SUIT_MessageBox::info2( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ),
- tr( "BUT_OK" ), tr( "BUT_CANCEL" ), 1, 2, 2 );
- if ( aAnswer == 1 )
+ aAnswer = SUIT_MessageBox::question( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ),
+ SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, SUIT_MessageBox::Cancel );
+ if ( aAnswer == SUIT_MessageBox::Ok )
SUIT_Session::session()->closeSession();
}
/*!Call SUIT_MessageBox::info1(...) with about information.*/
void STD_Application::onHelpAbout()
{
- SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" );
+ SUIT_MessageBox::information( desktop(), tr( "About" ), tr( "ABOUT_INFO" ) );
}
/*!Create empty study. \n
if ( QFileInfo( aName ).exists() )
{
- int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TIT_FILE_SAVEAS" ),
- tr( "MSG_FILE_EXISTS" ).arg( aName ),
- tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 );
- if ( aAnswer == 3 )
+ int aAnswer = SUIT_MessageBox::question( desktop(), tr( "TIT_FILE_SAVEAS" ),
+ tr( "MSG_FILE_EXISTS" ).arg( aName ),
+ SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel, SUIT_MessageBox::Yes );
+ if ( aAnswer == SUIT_MessageBox::Cancel )
{ // cancelled
aName = QString::null;
isOk = true;
}
- else if ( aAnswer == 2 ) // not save to this file
+ else if ( aAnswer == SUIT_MessageBox::No ) // not save to this file
anOldPath = aName; // not to return to the same initial dir at each "while" step
else // overwrite the existing file
isOk = true;
ViewWindowsId, ViewToolBarsId, ViewStatusBarId, NewWindowId,
EditCutId, EditCopyId, EditPasteId, HelpAboutId, UserID };
+ enum { CloseSave, CloseDiscard, CloseCancel };
+
public:
STD_Application();
virtual ~STD_Application();
virtual QString getFileFilter() const { return QString::null; }
virtual QString getFileName( bool open, const QString& initial, const QString& filters,
- const QString& caption, QWidget* parent );
+ const QString& caption, QWidget* parent );
QString getDirectory( const QString& initial, const QString& caption, QWidget* parent );
virtual void start();
virtual void setActiveViewManager( SUIT_ViewManager* );
+ virtual bool closeAction( const int );
+ virtual int closeChoice( const QString& );
+
private:
ViewManagerList myViewMgrs;
SUIT_ViewManager* myActiveViewMgr;
private:
bool myExitConfirm;
bool myEditEnabled;
- bool myClosePermanently;
+// bool myClosePermanently; TODO: Move into SalomeApp_Application
};
#if defined WIN32
#include <SUIT_ResourceMgr.h>
#include <QtxWorkstack.h>
-//#include <QtxActionMenuMgr.h>
-//#include <QtxWorkstackAction.h>
+#include <QtxActionMenuMgr.h>
+#include <QtxWorkstackAction.h>
#include <QFrame>
#include <QVBoxLayout>
/*!Constructor.Create new instances of QVBox and QtxWorkstack.*/
STD_TabDesktop::STD_TabDesktop()
: SUIT_Desktop(),
-myWorkstack( 0 )//,
-//myWorkstackAction( 0 )
+myWorkstack( 0 ),
+myWorkstackAction( 0 )
{
QFrame* base = new QFrame( this );
base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
createActions();
}
-/*!Destructor.*/
+/*!
+ Destructor.
+*/
STD_TabDesktop::~STD_TabDesktop()
{
}
-/*!\retval SUIT_ViewWindow - return const active window.*/
+/*!
+ \retval SUIT_ViewWindow - return const active window.
+*/
SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
{
SUIT_ViewWindow* wnd = 0;
return wnd;
}
-/*!\retval QPtrList<SUIT_ViewWindow> - return const active window list.*/
+/*!
+ \retval QPtrList<SUIT_ViewWindow> - return const active window list.
+*/
QList<SUIT_ViewWindow*> STD_TabDesktop::windows() const
{
QList<SUIT_ViewWindow*> winList;
return winList;
}
-/*! insert new widget into desktop.*/
+/*!
+ Insert new widget into desktop.
+*/
void STD_TabDesktop::addWindow( QWidget* w )
{
if ( !w || !workstack() )
workstack()->addWindow( w );
}
-/*!Call method perform for operation \a type.*/
-void STD_TabDesktop::windowOperation( const int /*type*/ )
+/*!
+ Call method perform for operation \a type.
+*/
+void STD_TabDesktop::windowOperation( const int type )
{
-// myWorkstackAction->perform( operationFlag( type ) );
+ myWorkstackAction->perform( operationFlag( type ) );
}
-/*!Sets window operations by \a first ... parameters.*/
+/*!
+ Sets window operations by \a first ... parameters.
+*/
void STD_TabDesktop::setWindowOperations( const int first, ... )
{
va_list ints;
setWindowOperations( typeList );
}
-/*!Sets window operations by variable \a opList - operation list.*/
+/*!
+ Sets window operations by variable \a opList - operation list.
+*/
void STD_TabDesktop::setWindowOperations( const QList<int>& opList )
{
int flags = 0;
// myWorkstackAction->setItems( flags );
}
-/*!\retval QtxWorkstack pointer - QT work stack.*/
+/*!
+ \retval QtxWorkstack pointer - Qt work stack.
+*/
QtxWorkstack* STD_TabDesktop::workstack() const
{
return myWorkstack;
}
-/*!Emit window activated.*/
+/*!
+ Emit window activated.
+*/
void STD_TabDesktop::onWindowActivated( QWidget* w )
{
if ( w && w->inherits( "SUIT_ViewWindow" ) )
emit windowActivated( (SUIT_ViewWindow*)w );
}
-/*!Create actions for window.*/
+/*!
+ Create actions for window.
+*/
void STD_TabDesktop::createActions()
{
-/*
if ( myWorkstackAction )
return;
myWorkstackAction = new QtxWorkstackAction( workstack(), this );
- myWorkstackAction->setItems( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
+ myWorkstackAction->setMenuActions( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
// Split Horizontal
- myWorkstackAction->setIconSet( QtxWorkstackAction::HSplit,
- resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
- myWorkstackAction->setMenuText( QtxWorkstackAction::HSplit, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
- myWorkstackAction->setStatusTip( QtxWorkstackAction::HSplit, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
+ myWorkstackAction->setIcon( QtxWorkstackAction::SplitHorizontal,
+ resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
+ myWorkstackAction->setText( QtxWorkstackAction::SplitHorizontal, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
+ myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitHorizontal, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
// Split Vertical
- myWorkstackAction->setIconSet( QtxWorkstackAction::VSplit,
- resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
- myWorkstackAction->setMenuText( QtxWorkstackAction::VSplit, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
- myWorkstackAction->setStatusTip( QtxWorkstackAction::VSplit, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
+ myWorkstackAction->setIcon( QtxWorkstackAction::SplitVertical,
+ resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
+ myWorkstackAction->setText( QtxWorkstackAction::SplitVertical, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
+ myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitVertical, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
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( myWorkstackAction, winMenuId, -1 );
mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
-*/
}
-/*!Convert STD_TabDesktop enumerations to QtxWorkstackAction*/
-int STD_TabDesktop::operationFlag( const int /*type*/ ) const
+/*!
+ Convert STD_TabDesktop enumerations to QtxWorkstackAction
+*/
+int STD_TabDesktop::operationFlag( const int type ) const
{
int res = 0;
-/*
switch ( type )
{
- case VSplit:
- res = QtxWorkstackAction::VSplit;
+ case SplitVertical:
+ res = QtxWorkstackAction::SplitVertical;
break;
- case HSplit:
- res = QtxWorkstackAction::HSplit;
+ case SplitHorizontal:
+ res = QtxWorkstackAction::SplitHorizontal;
break;
}
-*/
+
return res;
}
#include <SUIT_Desktop.h>
class QtxWorkstack;
-//class QtxWorkstackAction;
+class QtxWorkstackAction;
#if defined WIN32
#pragma warning( disable: 4251 )
Q_OBJECT
public:
- enum { MenuWindowId = 6 };
- enum { VSplit, HSplit };
+ enum { SplitVertical, SplitHorizontal };
public:
STD_TabDesktop();
private:
QtxWorkstack* myWorkstack;
-// QtxWorkstackAction* myWorkstackAction;
+ QtxWorkstackAction* myWorkstackAction;
};
#if defined WIN32
<translation>You are trying to save this document under an unknown type
( %1 )</translation>
</message>
- <message>
- <source>CLOSE_DLG_UNLOAD</source>
- <translation>&Unload</translation>
- </message>
<message>
<source>TOT_DESK_NEWWINDOW</source>
<translation>Create new Window</translation>
<source>ERR_DESK_NOAPP</source>
<translation>No applications registered</translation>
</message>
- <message>
- <source>CLOSE_DLG_CLOSE</source>
- <translation>C&lose w/o saving</translation>
- </message>
<message>
<source>INF_DESK_DOC_CREATE</source>
<translation>Create a new document</translation>
<translation>Load Study</translation>
</message>
<message>
- <source>CLOSE_DLG_CAPTION</source>
- <translation>Close active study</translation>
+ <source>CLOSE_STUDY</source>
+ <translation>Close study</translation>
</message>
<message>
<source>PRP_DESK_HELP_SEARCH</source>
<source>INF_CANCELLED</source>
<translation>Cancelled</translation>
</message>
- <message>
- <source>CLOSE_DLG_SAVE_CLOSE</source>
- <translation>&Save&&Close</translation>
- </message>
<message>
<source>PRP_DESK_WINDOW_VSPLIT</source>
<translation>Splits the active window on two vertical parts</translation>
<translation>Open document</translation>
</message>
<message>
- <source>CLOSE_DLG_DESCRIPTION</source>
- <translation>Do you want to close or only unload the study</translation>
+ <source>CLOSE_QUESTION</source>
+ <translation>Document %1 modified. Do you want to save or discard the modification and close the document?</translation>
</message>
<message>
<source>PRP_DESK_FILE_EXIT</source>
while ( QApplication::overrideCursor() )
QApplication::restoreOverrideCursor();
- SUIT_MessageBox::error1( 0, title, msg, "OK" );
+ SUIT_MessageBox::critical( 0, title, msg );
}
if ( !QDir(aPath).exists() )
{
aPath = QDir::homePath();
- SUIT_MessageBox::error1(this,
- tr("ERR_ERROR"),
- tr("ERR_DIR_NOT_EXIST").arg(dirPath),
- tr("BUT_OK"));
+ SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "ERR_DIR_NOT_EXIST" ).arg( dirPath ) );
}
else
- processPath(aPath);
+ processPath( aPath );
}
/*!
Called when user presses "Add" button - adds current directory to quick directory
/*! returns false if can't open file */
bool SUIT_FileValidator::canOpen( const QString& file )
{
- if ( !QFile::exists( file ) ) {
- SUIT_MessageBox::error1( myParent,
- QObject::tr( "ERR_ERROR" ),
- QObject::tr( "ERR_FILE_NOT_EXIST" ).arg( file ),
- QObject::tr( "BUT_OK" ) );
+ if ( !QFile::exists( file ) )
+ {
+ SUIT_MessageBox::critical( myParent, QObject::tr( "ERR_ERROR" ),
+ QObject::tr( "ERR_FILE_NOT_EXIST" ).arg( file ) );
return false;
- }
- if ( !QFileInfo( file ).isReadable() ) {
- SUIT_MessageBox::error1( myParent,
- QObject::tr( "ERR_ERROR" ),
- QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
- QObject::tr( "BUT_OK" ) );
+ }
+ if ( !QFileInfo( file ).isReadable() )
+ {
+ SUIT_MessageBox::critical( myParent, QObject::tr( "ERR_ERROR" ),
+ QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ) );
return false;
}
return true;
/*! returns false if can't save file */
bool SUIT_FileValidator::canSave( const QString& file )
{
- if ( QFile::exists( file ) ) {
+ if ( QFile::exists( file ) )
+ {
// if file exists - raise warning...
- if ( SUIT_MessageBox::warn2( myParent,
- QObject::tr( "WRN_WARNING" ),
- QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( file ),
- QObject::tr( "BUT_YES" ),
- QObject::tr( "BUT_NO" ),
- SUIT_YES,
- SUIT_NO,
- SUIT_NO ) == SUIT_NO ) {
+ if ( SUIT_MessageBox::question( myParent, QObject::tr( "WRN_WARNING" ),
+ QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( file ),
+ SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+ SUIT_MessageBox::No ) != SUIT_MessageBox::Yes )
+ {
return false;
}
// ... and if user wants to overwrite file, check it for writeability
- if ( !QFileInfo( file ).isWritable() ) {
- SUIT_MessageBox::error1( myParent,
- QObject::tr( "ERR_ERROR" ),
- QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
- QObject::tr( "BUT_OK" ) );
+ if ( !QFileInfo( file ).isWritable() )
+ {
+ SUIT_MessageBox::critical( myParent, QObject::tr( "ERR_ERROR" ),
+ QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ) );
return false;
}
}
QFile qf( file );
if ( !qf.open( QFile::WriteOnly ) )
{
- SUIT_MessageBox::error1( myParent, QObject::tr( "ERR_ERROR" ),
- QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
- QObject::tr( "BUT_OK" ) );
+ SUIT_MessageBox::critical( myParent, QObject::tr( "ERR_ERROR" ),
+ QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ) );
return false;
}
else
#include "SUIT_OverrideCursor.h"
#include <QMessageBox>
+#include <QPushButton>
#include <QApplication>
/*!
- Shows info message box with one button [ static ]
+ Constructor
*/
-int SUIT_MessageBox::info1( QWidget* parent, const QString& caption,
- const QString& text, const QString& textButton0 )
+SUIT_MessageBox::SUIT_MessageBox( QWidget* parent )
+: QMessageBox( parent )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
- int ret = QMessageBox::information( parent, caption, text, textButton0,
- QString::null, QString::null, 0, 0 );
- QApplication::processEvents();
- return ret;
}
/*!
- Shows warning message box with one button [ static ]
+ Constructor
*/
-int SUIT_MessageBox::warn1( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0 )
+SUIT_MessageBox::SUIT_MessageBox( Icon icon, const QString& title, const QString& text,
+ StandardButtons buttons, QWidget* parent, Qt::WindowFlags f )
+: QMessageBox( icon, title, text, buttons, parent, f )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
- int ret = QMessageBox::warning( parent, caption, text, textButton0,
- QString::null, QString::null, 0, 0 );
- QApplication::processEvents();
- return ret;
}
/*!
- Shows error message box with one button [ static ]
+ Destructor
*/
-int SUIT_MessageBox::error1( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0 )
+SUIT_MessageBox::~SUIT_MessageBox()
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
- int ret = QMessageBox::critical( parent, caption, text, textButton0,
- QString::null, QString::null, 0, 0 );
- QApplication::processEvents();
- return ret;
}
/*!
- Shows question message box with one button [ static ]
+ Returns the text of the specified button
*/
-int SUIT_MessageBox::question1( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0 )
+QString SUIT_MessageBox::buttonText( StandardButton btn ) const
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
- int ret = QMessageBox::question( parent, caption, text, textButton0,
- QString::null, QString::null, 0, 0 );
- QApplication::processEvents();
- return ret;
+ QString res;
+ QAbstractButton* b = button( btn );
+ if ( b )
+ res = b->text();
+ return res;
}
/*!
- Shows info message box with two buttons.
- Returns id of the pressed button or -1 if escaped [ static ]
+ Set the text of the specified button
*/
-int SUIT_MessageBox::info2( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- int idButton0, int idButton1, int idDefault )
+void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else
- idDefault = 0;
-
- int ret = QMessageBox::information( parent, caption, text, textButton0,
- textButton1, QString::null, idDefault );
- QApplication::processEvents();
- return ( ret == 0 ? idButton0 : idButton1 );
+ QAbstractButton* b = button( btn );
+ if ( b )
+ b->setText( text );
}
/*!
- Shows warning message box with two buttons.
- Returns id of the pressed button or -1 if escaped [ static ]
+ Shows critical message box with specified standard buttons. [ static ]
*/
-int SUIT_MessageBox::warn2( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- int idButton0, int idButton1, int idDefault )
+SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
-
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else
- idDefault = 0;
-
- int ret = QMessageBox::warning( parent, caption, text, textButton0,
- textButton1, QString::null, idDefault );
- QApplication::processEvents();
- return ( ret == 0 ? idButton0 : idButton1 );
+ return QMessageBox::critical( parent, title, text, buttons, defaultButton );
}
/*!
- Shows error message box with two buttons
- Returns id of the pressed button or -1 if escaped [ static ]
+ Shows information message box with specified standard buttons. [ static ]
*/
-int SUIT_MessageBox::error2( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- int idButton0, int idButton1, int idDefault )
+SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
-
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else
- idDefault = 0;
-
- int ret = QMessageBox::critical( parent, caption, text, textButton0,
- textButton1, QString::null, idDefault );
- QApplication::processEvents();
- return ( ret == 0 ? idButton0 : idButton1 );
+ return QMessageBox::information( parent, title, text, buttons, defaultButton );
}
/*!
- Shows question message box with two buttons
- Returns id of the pressed button or -1 if escaped [ static ]
+ Shows question message box with specified standard buttons. [ static ]
*/
-int SUIT_MessageBox::question2( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- int idButton0, int idButton1, int idDefault )
+SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
-
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else
- idDefault = 0;
-
- int ret = QMessageBox::question( parent, caption, text, textButton0,
- textButton1, QString::null, idDefault );
- QApplication::processEvents();
- return ( ret == 0 ? idButton0 : idButton1 );
+ return QMessageBox::question( parent, title, text,buttons, defaultButton );
}
/*!
- Shows info message box with three buttons.
- Returns id of the pressed button or -1 if escaped [ static ]
+ Shows warning message box with specified standard buttons. [ static ]
*/
-int SUIT_MessageBox::info3( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- const QString& textButton2,
- int idButton0, int idButton1,
- int idButton2, int idDefault )
+SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
+ SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
-
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else if ( idDefault == idButton2 )
- idDefault = 2;
- else
- idDefault = 0;
-
- int ret = QMessageBox::information( parent, caption, text, textButton0,
- textButton1, textButton2, idDefault );
- QApplication::processEvents();
- switch ( ret )
- {
- case 0:
- return idButton0;
- case 1:
- return idButton1;
- case 2:
- return idButton2;
- }
- return -1;
+ return QMessageBox::warning( parent, title, text, buttons, defaultButton );
}
/*!
- Shows warning message box with three buttons.
- Returns id of the pressed button or -1 if escaped [ static ]
+ Shows critical message box. Some buttons can be renamed. Variable number of arguments
+ should be specified starting from \param btn as pairs of StandardButton and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
*/
-int SUIT_MessageBox::warn3( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- const QString& textButton2,
- int idButton0, int idButton1,
- int idButton2, int idDefault )
+SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title,
+ const QString& text, StandardButtons buttons,
+ StandardButton defaultButton, StandardButton btn, ... )
{
- SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
-
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else if ( idDefault == idButton2 )
- idDefault = 2;
- else
- idDefault = 0;
-
- int ret = QMessageBox::warning( parent, caption, text, textButton0,
- textButton1, textButton2, idDefault );
- QApplication::processEvents();
- switch ( ret )
- {
- case 0:
- return idButton0;
- case 1:
- return idButton1;
- case 2:
- return idButton2;
- }
- return -1;
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Critical, parent, title, text,
+ buttons, defaultButton, messageMap( btn, args ) );
}
/*!
- Shows error message box with three buttons.
- Returns id of the pressed button or -1 if escaped [ static ]
+ Shows information message box. Some buttons can be renamed. Variable number of arguments
+ should be specified starting from \param btn as pairs of StandardButton and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
*/
-int SUIT_MessageBox::error3( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- const QString& textButton2,
- int idButton0, int idButton1,
- int idButton2, int idDefault )
+SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title,
+ const QString& text,
+ SUIT_MessageBox::StandardButtons buttons,
+ SUIT_MessageBox::StandardButton defaultButton,
+ SUIT_MessageBox::StandardButton btn, ... )
{
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Information, parent, title, text,
+ buttons, defaultButton, messageMap( btn, args ) );
+}
+
+/*!
+ Shows question message box. Some buttons can be renamed. Variable number of arguments
+ should be specified starting from \param btn as pairs of StandardButton and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
+*/
+SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title,
+ const QString& text, StandardButtons buttons,
+ StandardButton defaultButton, StandardButton btn, ... )
+{
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Question, parent, title, text,
+ buttons, defaultButton, messageMap( btn, args ) );
+}
+
+/*!
+ Shows warning message box. Some buttons can be renamed. Variable number of arguments
+ should be specified starting from \param btn as pairs of StandardButton and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
+*/
+SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title,
+ const QString& text, StandardButtons buttons,
+ StandardButton defaultButton, StandardButton btn, ... )
+{
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Warning, parent, title, text,
+ buttons, defaultButton, messageMap( btn, args ) );
+}
+
+/*!
+ Shows critical message box with user specified buttons. Each button decribed by two
+ parameters: int - button id and QString - button text. First button specified by \param btn0
+ and \param txt0, following buttons specified as variable number of arguments which
+ should be started from \param btn as pairs of int and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
+*/
+int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int btn0, QString txt0, int btn, ... )
+{
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Critical, parent, title, text,
+ defaultButton, messageList( btn0, txt0, btn, args ) );
+}
+
+/*!
+ Shows information message box with user specified buttons. Each button decribed by two
+ parameters: int - button id and QString - button text. First button specified by \param btn0
+ and \param txt0, following buttons specified as variable number of arguments which
+ should be started from \param btn as pairs of int and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
+*/
+int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int btn0, QString txt0, int btn, ... )
+{
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Information, parent, title, text,
+ defaultButton, messageList( btn0, txt0, btn, args ) );
+}
+
+/*!
+ Shows question message box with user specified buttons. Each button decribed by two
+ parameters: int - button id and QString - button text. First button specified by \param btn0
+ and \param txt0, following buttons specified as variable number of arguments which
+ should be started from \param btn as pairs of int and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
+*/
+int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int btn0, QString txt0, int btn, ... )
+{
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Question, parent, title, text,
+ defaultButton, messageList( btn0, txt0, btn, args ) );
+}
+
+/*!
+ Shows warning message box with user specified buttons. Each button decribed by two
+ parameters: int - button id and QString - button text. First button specified by \param btn0
+ and \param txt0, following buttons specified as variable number of arguments which
+ should be started from \param btn as pairs of int and QString.
+ After the last pair 0 (zero) value should be specified. [ static ]
+*/
+int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int btn0, QString txt0, int btn, ... )
+{
+ va_list args;
+ va_start( args, btn );
+ return messageBox( SUIT_MessageBox::Warning, parent, title, text,
+ defaultButton, messageList( btn0, txt0, btn, args ) );
+}
+
+/*!
+ Shows critical message box with user specified buttons. Each button decribed by button text.
+ Variable number of arguments should be started from \param txt. After the last text 0 (zero)
+ value should be specified. [ static ]
+*/
+int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, char* txt, ... )
+{
+ va_list args;
+ va_start( args, txt );
+ return messageBox( SUIT_MessageBox::Critical, parent, title, text,
+ 0, messageList( txt, args ) );
+}
+
+/*!
+ Shows information message box with user specified buttons. Each button decribed by button text.
+ Variable number of arguments should be started from \param txt. After the last text 0 (zero)
+ value should be specified. [ static ]
+*/
+int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, char* txt, ... )
+{
+ va_list args;
+ va_start( args, txt );
+ return messageBox( SUIT_MessageBox::Information, parent, title, text,
+ 0, messageList( txt, args ) );
+}
+
+/*!
+ Shows question message box with user specified buttons. Each button decribed by button text.
+ Variable number of arguments should be started from \param txt. After the last text 0 (zero)
+ value should be specified. [ static ]
+*/
+int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, char* txt, ... )
+{
+ va_list args;
+ va_start( args, txt );
+ return messageBox( SUIT_MessageBox::Question, parent, title, text,
+ 0, messageList( txt, args ) );
+}
+
+/*!
+ Shows warning message box with user specified buttons. Each button decribed by button text.
+ Variable number of arguments should be started from \param txt. After the last text 0 (zero)
+ value should be specified. [ static ]
+*/
+int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, char* txt, ... )
+{
+ va_list args;
+ va_start( args, txt );
+ return messageBox( SUIT_MessageBox::Warning, parent, title, text,
+ 0, messageList( txt, args ) );
+}
+
+SUIT_MessageBox::StandardButton SUIT_MessageBox::messageBox( SUIT_MessageBox::Icon icon, QWidget* parent,
+ const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton,
+ const ButtonMap& map )
+{
+ SUIT_MessageBox msgBox( icon, title, text, buttons, parent );
+ for ( ButtonMap::const_iterator it = map.begin(); it != map.end(); ++it )
+ msgBox.setButtonText( it.key(), it.value() );
+
+ if ( defaultButton != NoButton )
+ msgBox.setDefaultButton( ::qobject_cast<QPushButton*>( msgBox.button( defaultButton ) ) );
+
SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
-
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else if ( idDefault == idButton2 )
- idDefault = 2;
+
+ StandardButton res = NoButton;
+ if ( msgBox.exec() == -1 )
+ res = QMessageBox::Cancel;
else
- idDefault = 0;
-
- int ret = QMessageBox::critical( parent, caption, text, textButton0,
- textButton1, textButton2, idDefault );
+ res = msgBox.standardButton( msgBox.clickedButton() );
+
QApplication::processEvents();
- switch ( ret )
- {
- case 0:
- return idButton0;
- case 1:
- return idButton1;
- case 2:
- return idButton2;
- }
- return -1;
+
+ return res;
}
-/*!
- Shows question message box with three buttons.
- Returns id of the pressed button or -1 if escaped [ static ]
-*/
-int SUIT_MessageBox::question3( QWidget* parent,
- const QString& caption,
- const QString& text,
- const QString& textButton0,
- const QString& textButton1,
- const QString& textButton2,
- int idButton0, int idButton1,
- int idButton2, int idDefault )
+int SUIT_MessageBox::messageBox( Icon icon, QWidget* parent, const QString& title, const QString& text,
+ const int defaultButton, const ButtonList& lst )
{
+ SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
+
+ QMap<QAbstractButton*, int> map;
+ for ( ButtonList::const_iterator it = lst.begin(); it != lst.end(); ++it )
+ {
+ int btn = (*it).first;
+ QString txt = (*it).second;
+ ButtonRole role = InvalidRole;
+
+ if ( btn == defaultButton )
+ role = AcceptRole;
+
+ QPushButton* pb = msgBox.addButton( txt, role );
+ map.insert( pb, btn );
+
+ if ( btn == defaultButton )
+ msgBox.setDefaultButton( pb );
+ }
+
SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
-
- if ( idDefault == idButton0 )
- idDefault = 0;
- else if ( idDefault == idButton1 )
- idDefault = 1;
- else if ( idDefault == idButton2 )
- idDefault = 2;
+
+ int res = NoButton;
+ if ( msgBox.exec() == -1 )
+ res = Cancel;
else
- idDefault = 0;
-
- int ret = QMessageBox::question( parent, caption, text, textButton0,
- textButton1, textButton2, idDefault );
+ res = map[msgBox.clickedButton()];
+
QApplication::processEvents();
- switch ( ret )
- {
- case 0:
- return idButton0;
- case 1:
- return idButton1;
- case 2:
- return idButton2;
- }
- return -1;
+
+ return res;
+}
+
+SUIT_MessageBox::ButtonMap SUIT_MessageBox::messageMap( StandardButton btn, va_list& args )
+{
+ ButtonMap map;
+ StandardButton cur = btn;
+ while ( !cur )
+ {
+ QString name = va_arg( args, QString );
+ map.insert( cur, name );
+ cur = va_arg( args, StandardButton );
+ }
+
+ va_end( args );
+
+ return map;
+}
+
+SUIT_MessageBox::ButtonList SUIT_MessageBox::messageList( int btn0, QString txt0, int btn, va_list& args )
+{
+ ButtonList lst;
+ lst.append( QPair<int, QString>( btn0, txt0 ) );
+ int cur = btn;
+ while ( !cur )
+ {
+ QString name = va_arg( args, QString );
+ lst.append( QPair<int, QString>( cur, name ) );
+ cur = va_arg( args, int );
+ }
+
+ va_end( args );
+
+ return lst;
+}
+
+SUIT_MessageBox::ButtonList SUIT_MessageBox::messageList( char* txt, va_list& args )
+{
+ int i = 0;
+ ButtonList lst;
+ char* cur = txt;
+ while ( cur )
+ {
+ lst.append( QPair<int, QString>( i++, cur ) );
+ cur = va_arg( args, char* );
+ }
+
+ va_end( args );
+
+ return lst;
}
#include "SUIT.h"
-class QWidget;
-class QString;
+#include <QMap>
+#include <QList>
+#include <QMessageBox>
-#define SUIT_OK 1
-#define SUIT_CANCEL 2
-#define SUIT_YES 3
-#define SUIT_NO 4
-#define SUIT_HELP 5
+#include <stdarg.h>
/*!
\class SUIT_MessageBox
\brief Message dialog box for SUIT-based application
*/
-class SUIT_EXPORT SUIT_MessageBox
+class SUIT_EXPORT SUIT_MessageBox : public QMessageBox
{
public:
-
- /** @name One button message boxes.*/
- //@{
- static int info1 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0 );
- static int warn1 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0 );
- static int error1 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0 );
- static int question1 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0 );
- //@}
+ SUIT_MessageBox( QWidget* = 0 );
+ SUIT_MessageBox( Icon, const QString&, const QString&, StandardButtons buttons = NoButton,
+ QWidget* = 0, Qt::WindowFlags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint );
+ ~SUIT_MessageBox();
- /** @name Two buttons message boxes.*/
- //@{
- static int info2 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- int idButton0, int idButton1, int idDefault );
- static int warn2 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- int idButton0, int idButton1, int idDefault );
- static int error2 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- int idButton0, int idButton1, int idDefault );
- static int question2 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- int idButton0, int idButton1, int idDefault );
- //@}
+ QString buttonText( StandardButton ) const;
+ void setButtonText( StandardButton, const QString& );
- /** @name Three buttons message boxes.*/
- //@{
- static int info3 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- const QString& textButton2, int idButton0, int idButton1,
- int idButton2, int idDefault );
- static int warn3 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- const QString& textButton2, int idButton0, int idButton1,
- int idButton2, int idDefault );
- static int error3 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- const QString& textButton2, int idButton0, int idButton1,
- int idButton2, int idDefault );
- static int question3 ( QWidget* parent, const QString& caption, const QString& text,
- const QString& textButton0, const QString& textButton1,
- const QString& textButton2, int idButton0, int idButton1,
- int idButton2, int idDefault );
- //@}
+ static StandardButton critical( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons = Ok, StandardButton defaultButton = NoButton );
+ static StandardButton information( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons = Ok, StandardButton defaultButton = NoButton );
+ static StandardButton question( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons = Ok, StandardButton defaultButton = NoButton );
+ static StandardButton warning( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons = Ok, StandardButton defaultButton = NoButton );
+
+ static StandardButton critical( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton, StandardButton, ... );
+ static StandardButton information( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton, StandardButton, ... );
+ static StandardButton question( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton, StandardButton, ... );
+ static StandardButton warning( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton, StandardButton, ... );
+
+ static int critical( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int, QString, int, ... );
+ static int information( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int, QString, int, ... );
+ static int question( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int, QString, int, ... );
+ static int warning( QWidget* parent, const QString& title, const QString& text,
+ int defaultButton, int, QString, int, ... );
+
+ static int critical( QWidget* parent, const QString& title, const QString& text, char*, ... );
+ static int information( QWidget* parent, const QString& title, const QString& text, char*, ... );
+ static int question( QWidget* parent, const QString& title, const QString& text, char*, ... );
+ static int warning( QWidget* parent, const QString& title, const QString& text, char*, ... );
+
+private:
+ typedef QMap<StandardButton, QString> ButtonMap;
+ typedef QList< QPair<int, QString> > ButtonList;
+
+private:
+ static StandardButton messageBox( Icon icon, QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton, const ButtonMap& );
+
+ static int messageBox( Icon icon, QWidget* parent, const QString& title, const QString& text,
+ const int defaultButton, const ButtonList& );
+
+ static ButtonMap messageMap( StandardButton, va_list& );
+ static ButtonList messageList( int, QString, int, va_list& );
+ static ButtonList messageList( char*, va_list& );
};
#endif
if ( !libHandle )
{
- SUIT_MessageBox::warn1( 0, tr( "Error" ),
- tr( "Can not load application library \"%1\": %2").arg( lib ).arg( lastError() ), tr( "Ok" ) );
+ SUIT_MessageBox::warning( 0, tr( "Error" ),
+ tr( "Can not load application library \"%1\": %2").arg( lib ).arg( lastError() ) );
return 0;
}
if ( !crtInst )
{
- SUIT_MessageBox::warn1( 0, tr( "Error" ),
- tr( "Can not find function \"%1\": %2" ).arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+ SUIT_MessageBox::warning( 0, tr( "Error" ),
+ tr( "Can not find function \"%1\": %2" ).arg( APP_CREATE_NAME ).arg( lastError() ) );
return 0;
}
SUIT_Application* anApp = crtInst();
if ( !anApp )
{
- SUIT_MessageBox::warn1( 0, tr( "Error" ), tr( "Can not create application \"%1\": %2").arg( appName ).arg( lastError() ), tr( "Ok" ) );
+ SUIT_MessageBox::warning( 0, tr( "Error" ), tr( "Can not create application \"%1\": %2").arg( appName ).arg( lastError() ) );
return 0;
}
if ( toCheck )
{
- while( SUIT_Operation* anOp = blockingOperation( theOp ) )
+ while ( SUIT_Operation* anOp = blockingOperation( theOp ) )
{
- int anAnsw = SUIT_MessageBox::warn2( application()->desktop(),
- tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
- tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 );
+ int anAnsw = SUIT_MessageBox::question( application()->desktop(),
+ tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
+ SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, SUIT_MessageBox::Ok,
+ SUIT_MessageBox::Ok, tr( "CONTINUE" ), 0 );
if ( anAnsw == 1 )
return false;
bOk = true; // cancelled
}
if ( !bOk )
- SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
+ SUIT_MessageBox::critical( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ) );
return true;
}