*/
QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
const QString& menu, const QString& tip, const int key,
- QObject* parent, const bool toggle, QObject* reciever, const char* member )
+ QObject* parent, const bool toggle, QObject* reciever,
+ const char* member, const QString& shortcutAction )
{
- QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle );
+ QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction );
a->setStatusTip( tip );
if ( reciever && member )
bool unregisterAction( QAction* );
QAction* createAction( const int, const QString&, const QIcon&, const QString&,
const QString&, const int, QObject* = 0,
- const bool = false, QObject* = 0, const char* = 0 );
+ const bool = false, QObject* = 0, const char* = 0, const QString& = QString() );
private:
CAM_Application* myApp; //!< parent application object
#include <SUIT_Study.h>
#include <SUIT_FileDlg.h>
#include <SUIT_ResourceMgr.h>
+#include <SUIT_ShortcutMgr.h>
#include <SUIT_Tools.h>
#include <SUIT_Accel.h>
#include <SUIT_MessageBox.h>
if ( desktop() )
resourceMgr()->setValue( "desktop", "geometry", desktop()->storeGeometry() );
resourceMgr()->save();
+
+ // Update shortcuts
+ shortcutMgr()->updateShortcuts();
}
delete prefDlg;
pref->addPreference( tr( "PREF_RESIZE_ON_EXPAND_ITEM" ), objSetGroup, LightApp_Preferences::Bool,
"ObjectBrowser", "resize_on_expand_item" );
+ // Shortcuts preferences
+ int shortcutTab = pref->addPreference( tr( "PREF_TAB_SHORTCUTS" ), salomeCat );
+ int shortcutGroup = pref->addPreference( tr( "PREF_GROUP_SHORTCUTS" ), shortcutTab );
+ pref->addPreference( tr( "" ), shortcutGroup,
+ LightApp_Preferences::ShortcutTree, "shortcuts" );
+
// MRU preferences
int mruGroup = pref->addPreference( tr( "PREF_GROUP_MRU" ), genTab, LightApp_Preferences::Auto, "MRU", "show_mru" );
pref->setItemProperty( "columns", 4, mruGroup );
#include <SUIT_Operation.h>
#include <SUIT_ViewManager.h>
#include <SUIT_ResourceMgr.h>
+#include <SUIT_ShortcutMgr.h>
#include <SUIT_Desktop.h>
#include <SUIT_TreeModel.h>
if ( mySwitchOp == 0 )
mySwitchOp = new LightApp_SwitchOp( this );
+ // Enable Display and Erase actions
+ action(myDisplay)->setEnabled(true);
+ action(myErase)->setEnabled(true);
+
+ application()->shortcutMgr()->setSectionEnabled( moduleName() );
+
/* BUG 0020498 : The Entry column is always shown at module activation
The registration of column is moved into LightApp_Application
anIt.value()->abort();
}
+ // Disable Display and Erase action
+ action(myDisplay)->setEnabled(false);
+ action(myErase)->setEnabled(false);
+
+ application()->shortcutMgr()->setSectionEnabled( moduleName(), false );
+
/* BUG 0020498 : The Entry column is always shown at module activation
QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
LightApp_DataModel* m = dynamic_cast<LightApp_DataModel*>( dataModel() );
QAction
*disp = createAction( -1, tr( "TOP_SHOW" ), p, tr( "MEN_SHOW" ), tr( "STB_SHOW" ),
- 0, d, false, this, SLOT( onShowHide() ) ),
+ 0, d, false, this, SLOT( onShowHide() ), QString("General:Show object(s)") ),
*erase = createAction( -1, tr( "TOP_HIDE" ), p, tr( "MEN_HIDE" ), tr( "STB_HIDE" ),
- 0, d, false, this, SLOT( onShowHide() ) ),
+ 0, d, false, this, SLOT( onShowHide() ) , QString("General:Hide object(s)") ),
*dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ),
0, d, false, this, SLOT( onShowHide() ) ),
*eraseAll = createAction( -1, tr( "TOP_ERASE_ALL" ), p, tr( "MEN_ERASE_ALL" ), tr( "STB_ERASE_ALL" ),
<parameter name="User's Guide" value="${KERNEL_ROOT_DIR}/share/doc/salome/gui/KERNEL/index.html"/>
<parameter name="Developer's Guide" value="${KERNEL_ROOT_DIR}/share/doc/salome/tui/KERNEL/index.html"/>
</section>
+ <!--Salome shortcut settings-->
+ <section name="shortcuts_settings">
+ <parameter name="general_sections" value="General;Viewers"/>
+ </section>
+ <section name="shortcuts:General">
+ <parameter name="Show object(s)" value="Ctrl+S"/>
+ <parameter name="Hide object(s)" value="Ctrl+H" />
+ </section>
+ <section name="shortcuts:Viewers">
+ <parameter name="Front view" value="Ctrl+Alt+F"/>
+ <parameter name="Back view" value="Ctrl+Alt+B"/>
+ <parameter name="Top view" value="Ctrl+Alt+T"/>
+ <parameter name="Bottom view" value="Ctrl+Alt+B"/>
+ <parameter name="Left view" value="Ctrl+Alt+L"/>
+ <parameter name="Right view" value="Ctrl+Alt+R"/>
+ <parameter name="Reset view" value="Ctrl+Alt+E"/>
+ </section>
+ <section name="shortcuts:Geometry">
+ <parameter name="Increase number of isolines" value="Meta+I"/>
+ <parameter name="Decrease number of isolines" value="Ctrl+Alt+G"/>
+ <parameter name="Increase transparency" value="Ctrl+Alt+T"/>
+ <parameter name="Decrease transparency" value="Alt+T"/>
+ </section>
</document>
<source>PREFERENCES_NOT_SUPPORTED</source>
<translation>Preferences for module "%1" not supported</translation>
</message>
+ <message>
+ <source>PREF_TAB_SHORTCUTS</source>
+ <translation>Shortcuts</translation>
+ </message>
+ <message>
+ <source>PREF_GROUP_SHORTCUTS</source>
+ <translation>Shortcuts settings</translation>
+ </message>
</context>
<context>
<name>LightApp_Module</name>
// Projections
aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
- tr( "MNU_FRONT_VIEW" ), 0, this);
+ tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
+ this->addAction(aAction);
toolMgr()->registerAction( aAction, FrontId );
aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
- tr( "MNU_BACK_VIEW" ), 0, this);
+ tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
aAction->setStatusTip(tr("DSC_BACK_VIEW"));
connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
+ this->addAction(aAction);
toolMgr()->registerAction( aAction, BackId );
aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
- tr( "MNU_TOP_VIEW" ), 0, this);
+ tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
aAction->setStatusTip(tr("DSC_TOP_VIEW"));
connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
+ this->addAction(aAction);
toolMgr()->registerAction( aAction, TopId );
aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
- tr( "MNU_BOTTOM_VIEW" ), 0, this);
+ tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
+ this->addAction(aAction);
+ this->addAction(aAction);
toolMgr()->registerAction( aAction, BottomId );
-
+
aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
- tr( "MNU_LEFT_VIEW" ), 0, this);
+ tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
+ this->addAction(aAction);
toolMgr()->registerAction( aAction, LeftId );
aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
- tr( "MNU_RIGHT_VIEW" ), 0, this);
+ tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
+ this->addAction(aAction);
toolMgr()->registerAction( aAction, RightId );
// Reset
aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
- tr( "MNU_RESET_VIEW" ), 0, this);
+ tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
aAction->setStatusTip(tr("DSC_RESET_VIEW"));
connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
+ this->addAction(aAction);
toolMgr()->registerAction( aAction, ResetId );
// Clone
Creates an action owned by \a parent.
Parameter \a toggle can be used to make the action checkable.
+ Parameter \a shortcutAction can be used to assign the shortcut from
+ preferences. This parameter value corresponds to shortcut action identifier
+ in shortcut preferences.
\param parent parent object
\param toggle if \c true the action will be a toggle action
+ \param shortcutAction shortcut action identifier
*/
-QtxAction::QtxAction( QObject* parent, bool toggle )
+QtxAction::QtxAction( QObject* parent, bool toggle, const QString& shortcutAction )
: QWidgetAction( parent )
{
setCheckable( toggle );
+ setShortcutActionName(shortcutAction);
QApplication::instance()->installEventFilter( this );
}
Creates an action owned by \a parent. Parameters \a text,
\a icon, \a menuText and \a accel specify the action's attributes.
Parameter \a toggle can be used to make the action checkable.
+ Parameter \a shortcutAction can be used to assign the shortcut from
+ preferences. This parameter value corresponds to shortcut action identifier
+ in shortcut preferences.
\param text tooltip text
\param icon iconset
\param accel shortcut key sequence
\param parent parent object
\param toggle if \c true the action will be a toggle action
+ \param shortcutAction shortcut action identifier
*/
-QtxAction::QtxAction( const QString& text, const QIcon& icon,
- const QString& menuText, int accel, QObject* parent, bool toggle )
+QtxAction::QtxAction( const QString& text, const QIcon& icon, const QString& menuText,
+ int accel, QObject* parent, bool toggle, const QString& shortcutAction )
: QWidgetAction( parent )
{
setIcon( icon );
setToolTip( text );
setShortcut( accel );
setCheckable( toggle );
+ setShortcutActionName(shortcutAction);
QApplication::instance()->installEventFilter( this );
}
Creates an action owned by \a parent. Parameters \a text,
\a menuText and \a accel specify the action's attributes.
Parameter \a toggle can be used to make the action checkable.
+ Parameter \a shortcutAction can be used to assign the shortcut from
+ preferences. This parameter value corresponds to shortcut action identifier
+ in shortcut preferences.
\param text tooltip text
\param menuText menu text
\param accel shortcut key sequence
\param parent parent object
\param toggle if \c true the action is a toggle action
+ \param shortcutAction shortcut action identifier
*/
QtxAction::QtxAction( const QString& text, const QString& menuText,
- int accel, QObject* parent, bool toggle )
+ int accel, QObject* parent, bool toggle, const QString& shortcutAction )
: QWidgetAction( parent )
{
setText( menuText );
setToolTip( text );
setShortcut( accel );
setCheckable( toggle );
-
+ setShortcutActionName(shortcutAction);
+
QApplication::instance()->installEventFilter( this );
}
else
removedFrom( ae->widget() );
}
+
+/*!
+ \brief Return shortcut action name for the action.
+
+ \return shortcut action name
+ \sa setShortcutActionName()
+*/
+QString QtxAction::shortcutActionName() const
+{
+ return myShortcutActionName;
+}
+
+/*!
+ \brief Set shortcut action name to the action.
+
+ Shortcut action name is used for shortcuts customization.
+
+ \param shortcutAction shortcut action name
+ \sa shortcutActionName()
+*/
+void QtxAction::setShortcutActionName( const QString& shortcutAction )
+{
+ myShortcutActionName = shortcutAction;
+}
class ActionNotify;
public:
- QtxAction( QObject* = 0, bool = false );
- QtxAction( const QString&, const QString&, int, QObject*, bool = false );
- QtxAction( const QString&, const QIcon&, const QString&, int, QObject*, bool = false );
+ QtxAction( QObject* = 0, bool = false, const QString& = QString() );
+ QtxAction( const QString&, const QString&, int, QObject*, bool = false, const QString& = QString() );
+ QtxAction( const QString&, const QIcon&, const QString&, int, QObject*, bool = false, const QString& = QString() );
virtual ~QtxAction();
virtual bool eventFilter( QObject*, QEvent* );
+ QString shortcutActionName() const;
+ void setShortcutActionName( const QString& );
+
protected:
virtual void addedTo( QWidget* );
virtual void removedFrom( QWidget* );
virtual void customEvent( QEvent* );
+
+private:
+ QString myShortcutActionName;
};
#ifdef WIN32
const QString& param ): QtxPageNamedPrefItem( title, parent, sect, "" )
{
mySection = sect;
+
myShortcutTree = new QtxShortcutTree();
+
+ // Retrieve shortcuts common sections from resources
+ QtxResourceMgr* resMgr = resourceMgr();
+ if ( resMgr ){
+ QString generalSections = resourceMgr()->stringValue( "shortcuts_settings", "general_sections", QString() );
+ QStringList sectionsList = generalSections.split( ";", QString::SkipEmptyParts );
+ myShortcutTree->setGeneralSections( sectionsList );
+ }
+
setControl( myShortcutTree );
}
#include <QToolButton>
#include <QLineEdit>
#include <QTableWidgetItem>
+#include <QMessageBox>
#include <QKeyEvent>
#include <QKeySequence>
if ( keyEvent->key() == Qt::Key_Delete || keyEvent->key() == Qt::Key_Backspace )
currentItem()->setText( 1, "" );
if ( text != "" ) {
- currentItem()->setText( 1, text );
+ if ( text.endsWith( "+" ) || checkUniqueness( currentItem(), text ) )
+ currentItem()->setText( 1, text );
}
return true;
}
if ( event->type() == QEvent::KeyRelease ) {
if ( currentItem()->text( 1 ).endsWith( "+" ) )
- currentItem()->setText( 1, myPrevBindings[ currentItem()->parent()->text( 0 ) ][ currentItem()->text( 0 ) ] );
+ currentItem()->setText( 1, myPrevBindings[ currentItem()->parent()->text( 0 ) ][ currentItem()->text( 0 ) ] );
else myPrevBindings[ currentItem()->parent()->text( 0 ) ][ currentItem()->text( 0 ) ] = currentItem()->text( 1 );
return true;
prev->setText( 1, myPrevBindings[ prev->parent()->text( 0 ) ][ prev->text( 0 ) ] );
}
-
/*!
\brief Set key bindings to the tree
\param title the name of top-level item
void QtxShortcutTree::setBindings( const QString& title, const ShortcutMap& theShortcutMap )
{
QTreeWidgetItem* item= new QTreeWidgetItem();
+ QFont font = item->font(0);
+ font.setBold(true);
+
if ( findItems( title, Qt::MatchFixedString ).isEmpty() ) {
item->setText( 0, title );
+ item->setFont( 0, font );
addTopLevelItem( item );
item->setFlags( Qt::ItemIsEnabled );
} else {
{
ShortcutMap* aMap = new ShortcutMap();
QTreeWidgetItem* item = findItems( sec, Qt::MatchFixedString ).first();
- QList< QTreeWidgetItem* > childLst = item->takeChildren();
+ int nbChildren = item->childCount();
- for( int i = 0; i < childLst.size(); i++ )
- aMap->insert( childLst.at(i)->text( 0 ), childLst.at(i)->text(1) );
+ for( int i = 0; i < nbChildren; i++ ) {
+ QTreeWidgetItem* child = item->child(i);
+ aMap->insert( child->text( 0 ), child->text( 1 ) );
+ }
return aMap;
}
void QtxShortcutTree::focusOutEvent ( QFocusEvent* event )
{
QWidget::focusOutEvent( event );
- if ( currentItem()->isSelected() )
+ if ( currentItem() && currentItem()->isSelected() )
currentItem()->setText( 1, myPrevBindings[ currentItem()->parent()->text( 0 ) ][ currentItem()->text( 0 ) ] );
}
+
+/*!
+ \brief Set the list of shortcuts general sections.
+
+ Key combinations in general sections should not intersect
+ with any other key combinations.
+
+ \param sectionsList list of common section names
+*/
+void QtxShortcutTree::setGeneralSections( const QStringList& sectionsList )
+{
+ myGeneralSections = sectionsList;
+}
+
+/*!
+ \brief Check uniqueness of the shortcut.
+ \param item current item of the shortcut tree
+ \param shortcut shortcut appointed for the current item
+ \return \c true if the given shortcut is allowed
+*/
+bool QtxShortcutTree::checkUniqueness( QTreeWidgetItem* item, const QString& shortcut )
+{
+ // List of sections to check shortcut intersections
+ QStringList sectionsList;
+
+ // Current section
+ QString currentSection = currentItem()->parent()->text( 0 );
+
+ // If the current section is general
+ if ( myGeneralSections.contains(currentSection) ) {
+ sectionsList = sections();
+ int currentSectionIndex = sectionsList.indexOf(currentSection);
+ sectionsList.move( currentSectionIndex, 0);
+ }
+ else {
+ sectionsList = myGeneralSections;
+ sectionsList.prepend(currentSection);
+ }
+
+ // Iterate on sections
+ QStringList::const_iterator it;
+ for( it = sectionsList.constBegin(); it != sectionsList.constEnd(); ++it ) {
+ QString section = *it;
+
+ // Iterate on actual section
+ QTreeWidgetItem* sectionRoot = findItems( section, Qt::MatchFixedString ).first();
+ int nbChildren = sectionRoot->childCount();
+
+ for( int i = 0; i < nbChildren; i++ ) {
+ QTreeWidgetItem* child = sectionRoot->child(i);
+
+ if ( (child != item) && (shortcut == child->text( 1 )) ) {
+ bool res = QMessageBox::warning( parentWidget(), tr("Warning"),
+ tr("The \"%1\" shortcut has already used by the \"%2\" action.\n")
+ .arg(shortcut, section + ":" + child->text( 0 ) ) +
+ tr("Do you want to reassign it from that action to the current one?"),
+ QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes;
+ if (res)
+ child->setText( 1, "" );
+ return res;
+ }
+ }
+ }
+
+ return true;
+}
void setBindings( const QString&, const ShortcutMap& );
ShortcutMap* bindings( const QString& ) const;
QStringList sections() const;
+ void setGeneralSections( const QStringList& );
protected:
virtual bool eventFilter( QObject*, QEvent* );
virtual void focusOutEvent( QFocusEvent* );
+ virtual bool checkUniqueness( QTreeWidgetItem*, const QString& );
private slots:
void onCurrentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* );
private:
QMap< QString, ShortcutMap > myPrevBindings;
+ QStringList myGeneralSections;
};
#endif // QTXSHORTCUTEDIT_H
SUIT_TreeModel.h \
SUIT_ViewManager.h \
SUIT_ViewModel.h \
- SUIT_ViewWindow.h
+ SUIT_ViewWindow.h \
+ SUIT_ShortcutMgr.h
dist_libsuit_la_SOURCES = \
SUIT_Accel.cxx \
SUIT_TreeModel.cxx \
SUIT_ViewManager.cxx \
SUIT_ViewModel.cxx \
- SUIT_ViewWindow.cxx
+ SUIT_ViewWindow.cxx \
+ SUIT_ShortcutMgr.cxx
MOC_FILES = \
SUIT_Accel_moc.cxx \
SUIT_TreeModel_moc.cxx \
SUIT_ViewManager_moc.cxx \
SUIT_ViewModel_moc.cxx \
- SUIT_ViewWindow_moc.cxx
+ SUIT_ViewWindow_moc.cxx \
+ SUIT_ShortcutMgr_moc.cxx
nodist_libsuit_la_SOURCES = $(MOC_FILES)
#include "SUIT_Session.h"
#include "SUIT_Desktop.h"
#include "SUIT_ResourceMgr.h"
+#include "SUIT_ShortcutMgr.h"
#include <QTimer>
#include <QLabel>
#include <QtxActionMenuMgr.h>
#include <QtxActionToolMgr.h>
+
/*!
\class StatusLabel
\brief Status bar customization label. Used to workaroubd desktop resizing bug.
{
if ( desktop() )
desktop()->show();
+
+ // Initialize shortcut manager
+ SUIT_ShortcutMgr::Init();
}
/*!
return SUIT_Session::session()->resourceMgr();
}
+/*!
+ \brief Get access to shortcut manager.
+ \return global shortcut manager
+*/
+SUIT_ShortcutMgr* SUIT_Application::shortcutMgr() const
+{
+ return SUIT_ShortcutMgr::getShortcutMgr();
+}
+
#define DEFAULT_MESSAGE_DELAY 3000
/*!
*/
QAction* SUIT_Application::createAction( const int id, const QString& text, const QIcon& icon,
const QString& menu, const QString& tip, const int key,
- QObject* parent, const bool toggle, QObject* reciever, const char* member )
+ QObject* parent, const bool toggle, QObject* reciever,
+ const char* member, const QString& shortcutAction )
{
- QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle );
+ QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction );
a->setStatusTip( tip );
if ( reciever && member )
class SUIT_Desktop;
class SUIT_ViewModel;
class SUIT_ResourceMgr;
+class SUIT_ShortcutMgr;
class SUIT_Study;
#ifdef WIN32
SUIT_ResourceMgr* resourceMgr() const;
+ SUIT_ShortcutMgr* shortcutMgr() const;
+
//! Puts the message to the status bar
void putInfo ( const QString&, const int = 0 );
int registerAction( const int, QAction* );
QAction* createAction( const int, const QString&, const QIcon&, const QString&,
const QString&, const int, QObject* = 0,
- const bool = false, QObject* = 0, const char* = 0 );
+ const bool = false, QObject* = 0, const char* = 0,
+ const QString& = QString() );
protected slots:
virtual void onDesktopActivated();
SUIT_Study* myStudy;
SUIT_Desktop* myDesktop;
QMap<int, QAction*> myActionMap;
+ SUIT_ShortcutMgr* myShortcutMgr;
QLabel* myStatusLabel;
};
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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
+//
+
+#include "SUIT_ShortcutMgr.h"
+
+#include "SUIT_Session.h"
+#include "SUIT_ResourceMgr.h"
+
+#include <QtxAction.h>
+
+#include <QApplication>
+#include <QActionEvent>
+
+SUIT_ShortcutMgr* SUIT_ShortcutMgr::myShortcutMgr = NULL;
+
+/*!
+ \brief Constructor
+*/
+SUIT_ShortcutMgr::SUIT_ShortcutMgr()
+: QObject()
+{
+ qApp->installEventFilter( this );
+}
+
+/*!
+ \brief Destructor
+*/
+SUIT_ShortcutMgr::~SUIT_ShortcutMgr()
+{
+ qApp->removeEventFilter( this );
+}
+
+/*!
+ \brief Create new instance of shortcut manager.
+*/
+void SUIT_ShortcutMgr::Init()
+{
+ if( myShortcutMgr==NULL )
+ myShortcutMgr = new SUIT_ShortcutMgr();
+}
+
+/*!
+ \brief Return shortcut manager.
+*/
+SUIT_ShortcutMgr* SUIT_ShortcutMgr::getShortcutMgr()
+{
+ Init();
+
+ return myShortcutMgr;
+}
+
+/*!
+ \brief Custom event filter for qapplication .
+
+ Redefined from QObject::eventFilter();
+*/
+bool SUIT_ShortcutMgr::eventFilter( QObject* o, QEvent* e )
+{
+ if ( e->type() == QEvent::ActionAdded ) {
+ QActionEvent* anActionEvent = (QActionEvent*)e;
+ if (anActionEvent) {
+ QtxAction* anAction = qobject_cast<QtxAction*>( anActionEvent->action() );
+ if ( anAction )
+ processAction( anAction );
+ }
+ }
+
+ return QObject::eventFilter( o, e );
+}
+
+/*!
+ \brief Return key sequence for shortcut action name.
+ \param actionName name of shortcut action in preferences
+ \return key sequence defined in preferences or empty sequence
+*/
+QKeySequence SUIT_ShortcutMgr::getShortcutByActionName( const QString& actionName ) const
+{
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+
+ QString section = actionName.section( resMgr->sectionsToken(), 0, 0 );
+ section.prepend( QString("shortcuts") + resMgr->sectionsToken() );
+ QString parameter = actionName.section( resMgr->sectionsToken(), 1, 1 );
+
+ QString shortcutValue;
+ bool hasValue = resMgr->value( section, parameter, shortcutValue, false );
+
+ if ( !hasValue )
+ return QKeySequence();
+
+ return QKeySequence::fromString( shortcutValue );
+}
+
+/*!
+ \brief Set shortcut to the given action if the shortcut is defined.
+ \param action action to process
+ */
+void SUIT_ShortcutMgr::processAction( QtxAction* action )
+{
+ QString shortcutActionName = action->shortcutActionName();
+
+ if ( !shortcutActionName.isEmpty() ) {
+ // Add action to the actions map
+ QList<QtxAction*> actions = myShortcutActions.values( shortcutActionName );
+ if ( !actions.contains(action) )
+ myShortcutActions.insertMulti( shortcutActionName, action );
+
+ QKeySequence keySeq = getShortcutByActionName( shortcutActionName );
+ action->setShortcut( keySeq );
+ }
+}
+
+/*!
+ \brief Enable/disable a shortcuts section.
+
+ Enables or disables actions which belong to the given shortcuts section.
+ Only actions which have an active desktop as a parent widget
+ are taken into account.
+
+ \param section shorcuts section
+ \param on if \c true - action will be enabled, otherwise - disabled
+*/
+void SUIT_ShortcutMgr::setSectionEnabled( const QString& section, const bool on )
+{
+ QMap<QString, QtxAction*>::ConstIterator it;
+ for ( it = myShortcutActions.constBegin(); it != myShortcutActions.constEnd(); ++it ) {
+ QtxAction* action = it.value();
+ QString shortcutActionName = action->shortcutActionName();
+ QString actionSection = shortcutActionName.section( ":", 0, 0 );
+ if ( actionSection == section ) {
+ // Check if the action parent widget equals to the active desktop
+ SUIT_Application* app = SUIT_Session::session()->activeApplication();
+ if ( !app )
+ return;
+ if ( action->parentWidget() == (QWidget*)app->desktop() )
+ action->setEnabled( on );
+ }
+ }
+}
+
+/*!
+ \brief Update shortcuts from preferences.
+*/
+void SUIT_ShortcutMgr::updateShortcuts()
+{
+ QMap<QString, QtxAction*>::ConstIterator it;
+ for ( it = myShortcutActions.constBegin(); it != myShortcutActions.constEnd(); ++it ) {
+ QtxAction* action = it.value();
+ QKeySequence keySeq = getShortcutByActionName( action->shortcutActionName() );
+ action->setShortcut( keySeq );
+ }
+}
--- /dev/null
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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
+//
+
+#ifndef SUIT_SHORTCUTMGR_H
+#define SUIT_SHORTCUTMGR_H
+
+#include "SUIT.h"
+
+#include <QObject>
+#include <QMap>
+
+class QtxAction;
+
+class QKeySequence;
+
+#if defined WIN32
+#pragma warning( disable: 4251 )
+#endif
+
+/*!
+ \class SUIT_ShortcutMgr
+ \brief Class which manages shortcuts customization.
+*/
+class SUIT_EXPORT SUIT_ShortcutMgr: public QObject
+{
+public:
+ static void Init();
+ static SUIT_ShortcutMgr* getShortcutMgr();
+
+ void setSectionEnabled( const QString&, const bool = true );
+ void updateShortcuts();
+
+protected:
+ SUIT_ShortcutMgr();
+ virtual ~SUIT_ShortcutMgr();
+
+private:
+ virtual bool eventFilter( QObject* o, QEvent* e );
+
+ void processAction( QtxAction* );
+ QKeySequence getShortcutByActionName( const QString& ) const;
+
+private:
+ static SUIT_ShortcutMgr* myShortcutMgr;
+ QMap<QString, QtxAction*> myShortcutActions;
+};
+
+#if defined WIN32
+#pragma warning( default: 4251 )
+#endif
+
+#endif
// Projections
anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
- tr( "MNU_FRONT_VIEW" ), 0, this);
+ tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
+ this->addAction(anAction);
mgr->registerAction( anAction, FrontId );
anAction = new QtxAction(tr("MNU_BACK_VIEW"),
theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
- tr( "MNU_BACK_VIEW" ), 0, this);
+ tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
anAction->setStatusTip(tr("DSC_BACK_VIEW"));
connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
+ this->addAction(anAction);
mgr->registerAction( anAction, BackId );
anAction = new QtxAction(tr("MNU_TOP_VIEW"),
theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
- tr( "MNU_TOP_VIEW" ), 0, this);
+ tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
anAction->setStatusTip(tr("DSC_TOP_VIEW"));
connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
+ this->addAction(anAction);
mgr->registerAction( anAction, TopId );
anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
- tr( "MNU_BOTTOM_VIEW" ), 0, this);
+ tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
+ this->addAction(anAction);
mgr->registerAction( anAction, BottomId );
anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
- tr( "MNU_LEFT_VIEW" ), 0, this);
+ tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
+ this->addAction(anAction);
mgr->registerAction( anAction, LeftId );
anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
- tr( "MNU_RIGHT_VIEW" ), 0, this);
+ tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
+ this->addAction(anAction);
mgr->registerAction( anAction, RightId );
// Reset
anAction = new QtxAction(tr("MNU_RESET_VIEW"),
theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
- tr( "MNU_RESET_VIEW" ), 0, this);
+ tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
anAction->setStatusTip(tr("DSC_RESET_VIEW"));
connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
+ this->addAction(anAction);
mgr->registerAction( anAction, ResetId );
// onViewTrihedron: Shows - Hides Trihedron
<parameter name="User's Guide" value="${KERNEL_ROOT_DIR}/share/doc/salome/gui/KERNEL/index.html"/>
<parameter name="Developer's Guide" value="${KERNEL_ROOT_DIR}/share/doc/salome/tui/KERNEL/index.html"/>
</section>
+ <!--Salome shortcut settings-->
+ <section name="shortcuts_settings">
+ <parameter name="general_sections" value="General;Viewers"/>
+ </section>
+ <section name="shortcuts:General">
+ <parameter name="Show object(s)" value="Ctrl+S"/>
+ <parameter name="Hide object(s)" value="Ctrl+H" />
+ </section>
+ <section name="shortcuts:Viewers">
+ <parameter name="Front view" value="Ctrl+Alt+F"/>
+ <parameter name="Back view" value="Ctrl+Alt+B"/>
+ <parameter name="Top view" value="Ctrl+Alt+T"/>
+ <parameter name="Bottom view" value="Ctrl+Alt+B"/>
+ <parameter name="Left view" value="Ctrl+Alt+L"/>
+ <parameter name="Right view" value="Ctrl+Alt+R"/>
+ <parameter name="Reset view" value="Ctrl+Alt+R"/>
+ </section>
+ <section name="shortcuts:Geometry">
+ <parameter name="Increase number of isolines" value="Meta+I"/>
+ <parameter name="Decrease number of isolines" value="Ctrl+Alt+G"/>
+ <parameter name="Increase transparency" value="Ctrl+Alt+T"/>
+ <parameter name="Decrease transparency" value="Alt+T"/>
+ </section>
</document>