// Preferences
createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIcon(),
tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
- Qt::CTRL+Qt::Key_R, desk, false, this, SLOT( onPreferences() ) );
+ Qt::CTRL+Qt::Key_P, desk, false, this, SLOT( onPreferences() ) );
// Help menu:
resMgr->loadPixmap( "PyViewer", tr( "ICON_REPLACE" ) ),
tr( "ACT_REPLACE" ), 0, this );
action->setStatusTip( tr( "DSC_REPLACE" ) );
- action->setShortcut( QKeySequence::Replace );
+ action->setShortcuts( QList<QKeySequence>() << QKeySequence( "Ctrl+H" ) << QKeySequence( QKeySequence::Replace ) );
action->setShortcutContext( Qt::WidgetShortcut );
connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( replace() ) );
toolMgr()->registerAction( action, ReplaceId );
ProcessVoidEvent( new TEvent( section, name, value ) );
}
+/*!
+ \brief Add font setting to the application preferences.
+ \param section resources file section name
+ \param name setting name
+ \param value new setting value
+*/
+void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
+{
+ class TEvent: public SALOME_Event
+ {
+ QString mySection;
+ QString myName;
+ QFont myValue;
+ public:
+ TEvent( const QString& section, const QString& name, const QFont& value )
+ : mySection( section ), myName( name ), myValue( value ) {}
+ virtual void Execute()
+ {
+ if ( SUIT_Session::session() ) {
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ if ( !mySection.isEmpty() && !myName.isEmpty() )
+ resMgr->setValue( mySection, myName, myValue );
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent( section, name, value ) );
+}
+
/*!
\fn int SalomePyQt::integerSetting( const QString& section,
const QString& name,
/*!
\fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
const QString& name,
- const QByteArray def );
+ const QByteArray& def );
\brief Get byte array setting from the application preferences.
\param section resources file section name
\param name setting name
return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
}
+/*!
+ \fn QByteArray SalomePyQt::fontSetting( const QString& section,
+ const QString& name,
+ const QFont& def );
+ \brief Get font setting from the application preferences.
+ \param section resources file section name
+ \param name setting name
+ \param def default value which is returned if the setting is not found
+ \return setting value
+*/
+
+class TGetFontSettingEvent: public SALOME_Event
+{
+public:
+ typedef QFont TResult;
+ TResult myResult;
+ QString mySection;
+ QString myName;
+ TResult myDefault;
+ TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
+ : mySection( section ), myName( name ), myDefault( def ) {}
+ virtual void Execute()
+ {
+ if ( SUIT_Session::session() ) {
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
+ }
+ }
+};
+QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
+{
+ return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
+}
+
/*!
\brief Remove setting from the application preferences.
\param section resources file section name
static void addSetting ( const QString&, const QString&, const QString& );
static void addSetting ( const QString&, const QString&, const QColor& );
static void addSetting ( const QString&, const QString&, const QByteArray& );
+ static void addSetting ( const QString&, const QString&, const QFont& );
static int integerSetting( const QString&, const QString&, const int = 0 );
static double doubleSetting ( const QString&, const QString&, const double = 0 );
static bool boolSetting ( const QString&, const QString&, const bool = 0 );
static QString stringSetting ( const QString&, const QString&, const QString& = QString(""), const bool = true );
static QColor colorSetting ( const QString&, const QString&, const QColor& = QColor() );
static QByteArray byteArraySetting( const QString&, const QString&, const QByteArray& = QByteArray() );
+ static QFont fontSetting( const QString&, const QString&, const QFont& = QFont() );
static void removeSetting ( const QString&, const QString& );
static bool hasSetting ( const QString&, const QString& );
static QStringList parameters ( const QString& );
static void addSetting ( const QString&, const QString&, const QString& ) /ReleaseGIL/ ;
static void addSetting ( const QString&, const QString&, const QColor& ) /ReleaseGIL/ ;
static void addSetting ( const QString&, const QString&, const QByteArray& ) /ReleaseGIL/ ;
+ static void addSetting ( const QString&, const QString&, const QFont& ) /ReleaseGIL/ ;
static int integerSetting( const QString&, const QString&, const int = 0 ) /ReleaseGIL/ ;
static double doubleSetting ( const QString&, const QString&, const double = 0 ) /ReleaseGIL/ ;
static bool boolSetting ( const QString&, const QString&, const bool = false ) /ReleaseGIL/ ;
static QString stringSetting ( const QString&, const QString&, const QString& = QString(""), const bool = true ) /ReleaseGIL/ ;
static QColor colorSetting ( const QString&, const QString&, const QColor& = QColor() ) /ReleaseGIL/ ;
static QByteArray byteArraySetting( const QString&, const QString&, const QByteArray& = QByteArray() ) /ReleaseGIL/ ;
+ static QFont fontSetting( const QString&, const QString&, const QFont& = QFont() ) /ReleaseGIL/ ;
static void removeSetting ( const QString&, const QString& ) /ReleaseGIL/ ;
static bool hasSetting ( const QString&, const QString& ) /ReleaseGIL/ ;
static QStringList parameters ( const QString& ) /ReleaseGIL/ ;
//! Properties
createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIcon(),
tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
- Qt::CTRL+Qt::Key_P, desk, false, this, SLOT( onProperties() ) );
+ 0, desk, false, this, SLOT( onProperties() ) );
//! Catalog Generator
createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIcon(),
#include "PyEditor_Settings.h"
#include "PyEditor_Keywords.h"
+#include <QMenu>
#include <QPainter>
#include <QTextBlock>
}
}
+void PyEditor_Editor::contextMenuEvent( QContextMenuEvent* event )
+{
+ QMenu* menu = createStandardContextMenu();
+ emit customizeMenu( menu );
+ menu->exec( event->globalPos() );
+ delete menu;
+}
+
/*!
\brief Indent and tab text.
\param isShift flag defines reverse tab direction
class PyEditor_Keywords;
class PyEditor_Completer;
class PyEditor_PyHighlighter;
+class QMenu;
class PYEDITOR_EXPORT PyEditor_Editor : public QPlainTextEdit
{
virtual void keyPressEvent( QKeyEvent* );
virtual void resizeEvent( QResizeEvent* );
virtual void paintEvent( QPaintEvent* );
+ virtual void contextMenuEvent( QContextMenuEvent* );
PyEditor_Keywords* userKeywords() const;
PyEditor_Keywords* standardKeywords() const;
void updateLineNumberAreaWidth( int );
void updateLineNumberArea( const QRect&, int );
+Q_SIGNALS:
+ void customizeMenu( QMenu* );
+
private:
bool matchLeftParenthesis( const QTextBlock&, int, int );
bool matchRightParenthesis( const QTextBlock&, int, int );
addAction( new QAction( tr( "CASE_SENSITIVE_CHECK" ), this ) );
addAction( new QAction( tr( "WHOLE_WORDS_CHECK" ), this ) );
addAction( new QAction( tr( "REGEX_CHECK" ), this ) );
- addAction( new QAction( tr( "Find" ), this ) );
+ addAction( new QAction( QIcon( ":/images/py_find.png" ), tr( "Find" ), this ) );
addAction( new QAction( tr( "FindPrevious" ), this ) );
addAction( new QAction( tr( "FindNext" ), this ) );
- addAction( new QAction( tr( "Replace" ), this ) );
+ addAction( new QAction( QIcon( ":/images/py_replace.png" ), tr( "Replace" ), this ) );
foreach ( QAction* action, actions().mid( CaseSensitive, RegExp+1 ) )
{
}
myEditor->installEventFilter( this );
+ connect( myEditor, SIGNAL( customizeMenu( QMenu* ) ), this, SLOT( customizeMenu( QMenu* ) ) );
hide();
}
{
case Qt::Key_Escape:
if ( isVisible() )
+ {
hide();
+ return true;
+ }
break;
default:
break;
activate( Find );
}
+/*!
+ \brief Customize menu for editor.
+*/
+void PyEditor_FindTool::customizeMenu( QMenu* menu )
+{
+ menu->addSeparator();
+ menu->addAction( actions()[Find] );
+ menu->addAction( actions()[Replace] );
+}
+
/*!
\brief Slot: activate 'Replace' dialog.
*/
bindings << QKeySequence( QKeySequence::FindNext );
break;
case Replace:
- bindings << QKeySequence( QKeySequence::Replace );
bindings << QKeySequence( "Ctrl+H" );
+ bindings << QKeySequence( QKeySequence::Replace );
break;
default:
break;
class QAction;
class QLabel;
class QLineEdit;
+class QMenu;
class PYEDITOR_EXPORT PyEditor_FindTool : public QWidget
{
void replaceAll();
void update();
void activate( int );
+ void customizeMenu( QMenu* );
private:
QList<QKeySequence> shortcuts( int ) const;
{
return myEditor->toPlainText();
}
+
+/*!
+ \brief Set editor's settings.
+ \param settings Settings object.
+*/
+void PyEditor_Widget::setSettings( const PyEditor_Settings& settings )
+{
+ myEditor->setSettings( settings );
+}
+
+/*!
+ \brief Get editor's settings.
+ \return Settings object.
+*/
+const PyEditor_Settings& PyEditor_Widget::settings() const
+{
+ return myEditor->settings();
+}
#define PYEDITOR_WIDGET_H
#include "PyEditor.h"
+#include "PyEditor_Settings.h"
#include <QWidget>
PyEditor_Editor* editor();
PyEditor_FindTool* findTool();
+ void setSettings( const PyEditor_Settings& );
+ const PyEditor_Settings& settings() const;
+
bool isModified();
QString text() const;
tr( "ACT_REPLACE" ), this );
action->setToolTip( tr( "TTP_REPLACE" ) );
action->setStatusTip( tr( "DSC_REPLACE" ) );
- action->setShortcut( QKeySequence::Replace );
+ action->setShortcuts( QList<QKeySequence>() << QKeySequence( "Ctrl+H" ) << QKeySequence( QKeySequence::Replace ) );
action->setShortcutContext( Qt::WidgetShortcut );
connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( replace() ) );
myActions[ ReplaceId ] = action;
PyEditor_Editor* editor();
PyEditor_FindTool* findTool();
+ void setSettings( const PyEditor_Settings& );
+ const PyEditor_Settings& settings() const;
+
bool isModified();
QString text() const;