From: akl Date: Mon, 13 Apr 2015 16:52:15 +0000 (+0400) Subject: Correction of PyEditor preferences dialog box: X-Git-Tag: V7_6_0b1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a97dd3b3b19d262c63d86e0c38fc0d8f4154ac14;p=modules%2Fgui.git Correction of PyEditor preferences dialog box: 1) Use QtxFontEdit widget to manage script font; 2) Documentation page was created; 3) 'Help' toolbar button was removed; 4) 'Help' button was added into 'Preferences' dialog instead of 'Apply' one. --- diff --git a/doc/salome/gui/images/pref_salome_pythonviewer.png b/doc/salome/gui/images/pref_salome_pythonviewer.png new file mode 100644 index 000000000..0fa2b6bc4 Binary files /dev/null and b/doc/salome/gui/images/pref_salome_pythonviewer.png differ diff --git a/doc/salome/gui/images/python_copy.png b/doc/salome/gui/images/python_copy.png new file mode 100644 index 000000000..e14d435f9 Binary files /dev/null and b/doc/salome/gui/images/python_copy.png differ diff --git a/doc/salome/gui/images/python_cut.png b/doc/salome/gui/images/python_cut.png new file mode 100644 index 000000000..c534b8a09 Binary files /dev/null and b/doc/salome/gui/images/python_cut.png differ diff --git a/doc/salome/gui/images/python_delete.png b/doc/salome/gui/images/python_delete.png new file mode 100644 index 000000000..e11738a36 Binary files /dev/null and b/doc/salome/gui/images/python_delete.png differ diff --git a/doc/salome/gui/images/python_new.png b/doc/salome/gui/images/python_new.png new file mode 100644 index 000000000..7e8f49cdb Binary files /dev/null and b/doc/salome/gui/images/python_new.png differ diff --git a/doc/salome/gui/images/python_open.png b/doc/salome/gui/images/python_open.png new file mode 100644 index 000000000..29519d888 Binary files /dev/null and b/doc/salome/gui/images/python_open.png differ diff --git a/doc/salome/gui/images/python_paste.png b/doc/salome/gui/images/python_paste.png new file mode 100644 index 000000000..195c337f6 Binary files /dev/null and b/doc/salome/gui/images/python_paste.png differ diff --git a/doc/salome/gui/images/python_preferences.png b/doc/salome/gui/images/python_preferences.png new file mode 100644 index 000000000..ee92cac37 Binary files /dev/null and b/doc/salome/gui/images/python_preferences.png differ diff --git a/doc/salome/gui/images/python_redo.png b/doc/salome/gui/images/python_redo.png new file mode 100644 index 000000000..f9379dc65 Binary files /dev/null and b/doc/salome/gui/images/python_redo.png differ diff --git a/doc/salome/gui/images/python_save.png b/doc/salome/gui/images/python_save.png new file mode 100644 index 000000000..3fdb05060 Binary files /dev/null and b/doc/salome/gui/images/python_save.png differ diff --git a/doc/salome/gui/images/python_saveas.png b/doc/salome/gui/images/python_saveas.png new file mode 100644 index 000000000..8226ca31c Binary files /dev/null and b/doc/salome/gui/images/python_saveas.png differ diff --git a/doc/salome/gui/images/python_selectall.png b/doc/salome/gui/images/python_selectall.png new file mode 100644 index 000000000..b764715f8 Binary files /dev/null and b/doc/salome/gui/images/python_selectall.png differ diff --git a/doc/salome/gui/images/python_undo.png b/doc/salome/gui/images/python_undo.png new file mode 100644 index 000000000..73e78c7a7 Binary files /dev/null and b/doc/salome/gui/images/python_undo.png differ diff --git a/doc/salome/gui/images/python_view_preferences.png b/doc/salome/gui/images/python_view_preferences.png new file mode 100644 index 000000000..61fb31758 Binary files /dev/null and b/doc/salome/gui/images/python_view_preferences.png differ diff --git a/doc/salome/gui/images/pythonviewer_toolbar.png b/doc/salome/gui/images/pythonviewer_toolbar.png new file mode 100644 index 000000000..e98b3174e Binary files /dev/null and b/doc/salome/gui/images/pythonviewer_toolbar.png differ diff --git a/doc/salome/gui/input/python_viewer.doc b/doc/salome/gui/input/python_viewer.doc new file mode 100644 index 000000000..0be892324 --- /dev/null +++ b/doc/salome/gui/input/python_viewer.doc @@ -0,0 +1,94 @@ +/*! + +\page python_viewer_page Python viewer + +The functionalities of Python viewer are available via its Viewer +Toolbar. + +\image html pythonviewer_toolbar.png +
+ +\image html python_new.png + +New - clears viewer in order to create a new script. If viewer was modified, you will be asked to close it before removing. +
+ +\image html python_open.png +Open - allows to open an existing script by browsing for it in a standard Open File dialog box, choosing the required .py file and clicking Open button. If there is already opened script, you will be asked to close it before opening new one. +
+ +\image html python_save.png + +Save - saves the current script. + +\note If the script hasn't been previously saved, Save will call the standard Save File dialog box where you can enter the name for your script and save it. + +
+ +\image html python_saveas.png + +Save As... - allows to save the current script with a new name. Input a new name for the script in the standard Save file as dialog box and click Save button. +
+ +\image html python_undo.png + +Undo - undo the last user's action in Python viewer. +
+ +\image html python_redo.png + +Redo - redo the previously user's action in Python viewer. +
+ +\image html python_cut.png + +Cut - save the selected text into clipboard and remove it from the viewer. +
+ +\image html python_copy.png + +Copy - save the selected text into clipboard. +
+ +\image html python_paste.png + +Paste - restore the saved text from clipboard. +
+ +\image html python_delete.png + +Delete - remove the selected text. +
+ +\image html python_selectall.png + +Select All - select whole the text. +
+ +\image html python_preferences.png + +Preferences - provides an access to the preferences dialog box, that allows to specify advanced parameters for the Python Viewer. + +\anchor custom_python_preferences +\image html python_view_preferences.png + +The following options are available: + +- Font settings allows setting font variant and it's size. + +- Display settings specifies the script representation in the viewer: + + - Enable current line highlight switches on a background coloring of current line. + - Enable text wrapping allows lines wrapping at the view border of the editor. + + - Center cursor on scroll scrolls the script vertically to make the cursor visible at the center of the viewer. + + - Display line numbers area will make a panel displaying the line numbers of the script visible in the left border of the editor. + +- Tab settings allows to display tab indentation as a set of desirable number of white spaces. + +- Vertical edge settings manages drawing of vertical line at the specified column of the viewer. + +- Save settings as default will store the applied Python viewer settings in the SALOME preferences .xml file and restore it in the current and next SALOME sessions. + +*/ diff --git a/doc/salome/gui/input/setting_preferences.doc b/doc/salome/gui/input/setting_preferences.doc index 08df5be33..57971c758 100644 --- a/doc/salome/gui/input/setting_preferences.doc +++ b/doc/salome/gui/input/setting_preferences.doc @@ -236,7 +236,29 @@ selected object in the viewer. - Highlighted legend font color - this submenu allows to select the color of the font of the selected legend item. -

Directories Preferences

+\anchor default_python_preferences +

Python Viewer Preferences

+ +\image html pref_salome_pythonviewer.png + +\note The following settings are default and will be applied for a new created Python viewers only. Customization of already opened viewers can be done using local \ref custom_python_preferences "Preferences dialog box" that is called by click on corresponding icon of \ref python_viewer_page "Python viewer toolbar". + +- Font settings allows setting font variant, size and style. + +- Display settings specifies the script representation in the viewer: + + - Enable current line highlight switches on a background coloring of current line. + - Enable text wrapping allows lines wrapping at the view border of the editor. + + - Center cursor on scroll scrolls the script vertically to make the cursor visible at the center of the viewer. + + - Display line numbers area will make a panel displaying the line numbers of the script visible in the left border of the editor. + +- Tab settings allows to display tab indentation as a set of desirable number of white spaces. + +- Vertical edge settings manages drawing of vertical line at the specified column of the viewer. + +

Directories Preferences

\image html pref_salome_directories.png diff --git a/doc/salome/gui/input/viewers_chapter.doc b/doc/salome/gui/input/viewers_chapter.doc index 17eadb87d..83a566a55 100644 --- a/doc/salome/gui/input/viewers_chapter.doc +++ b/doc/salome/gui/input/viewers_chapter.doc @@ -32,6 +32,7 @@ directly, but can be used in custom modules for 2D visualization purposes. developed on the basis of Qt QGraphicsView scene. This viewer is used in SALOME YACS module for visualization of computation schemes. +- \subpage python_viewer_page allows a user to create/edit Python scripts. */ diff --git a/src/PyEditor/PyEditor_SettingsDlg.cxx b/src/PyEditor/PyEditor_SettingsDlg.cxx index 9b685be09..83f0e381e 100644 --- a/src/PyEditor/PyEditor_SettingsDlg.cxx +++ b/src/PyEditor/PyEditor_SettingsDlg.cxx @@ -26,14 +26,12 @@ #include "PyEditor_Settings.h" #include -#include -#include -#include #include #include +#include #include #include - +#include /*! \class PyEditor_SettingsDlg @@ -55,21 +53,8 @@ PyEditor_SettingsDlg::PyEditor_SettingsDlg( PyEditor_Editor* theEditor, QWidget* // . Font settings QGroupBox* aFontSetBox = new QGroupBox( tr( "GR_FONT_SET" ) ); QHBoxLayout* aFontSetLayout = new QHBoxLayout( aFontSetBox ); - QLabel* aFontFamilyLabel = new QLabel( tr( "LBL_FONT_FAM" ) ); - w_FontFamily = new QFontComboBox; - w_FontFamily->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); - QLabel* aFontSizeLabel = new QLabel( tr( "LBL_FONT_SIZE" ) ); - w_FontSize = new QComboBox; - w_FontSize->setInsertPolicy( QComboBox::NoInsert ); - w_FontSize->setValidator( new QIntValidator( 1, 250, w_FontSize ) ); - w_FontSize->setEditable( true ); - w_FontSize->setMinimumContentsLength( 3 ); - aFontSetLayout->addWidget( aFontFamilyLabel ); - aFontSetLayout->addWidget( w_FontFamily ); - aFontSetLayout->addWidget( aFontSizeLabel ); - aFontSetLayout->addWidget( w_FontSize ); - /*connect( w_FontFamily, SIGNAL( currentFontChanged( const QFont& ) ), - this, SLOT( onFontChanged( const QFont& ) ) );*/ + w_FontWidget = new QtxFontEdit( QtxFontEdit::Family|QtxFontEdit::Size|QtxFontEdit::UserSize, this ); + aFontSetLayout->addWidget( w_FontWidget ); // . Font settings // . Display settings @@ -137,97 +122,25 @@ PyEditor_SettingsDlg::PyEditor_SettingsDlg( PyEditor_Editor* theEditor, QWidget* aMainLayout->addWidget( w_DefaultCheck ); aMainLayout->addStretch( 1 ); + myOkBtn = new QPushButton( tr( "BUT_OK" ), this ); + myOkBtn->setAutoDefault( TRUE ); + myOkBtn->setDefault( TRUE ); + myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this ); + myCancelBtn->setAutoDefault( TRUE ); + myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this ); + myHelpBtn->setAutoDefault( TRUE ); QHBoxLayout* aButtonLayout = new QHBoxLayout; - w_ButtonBox = new QDialogButtonBox( Qt::Horizontal ); - w_ButtonBox->setStandardButtons( QDialogButtonBox::Ok - | QDialogButtonBox::Cancel - | QDialogButtonBox::Apply ); - aButtonLayout->addWidget( w_ButtonBox, 1, Qt::AlignRight ); + aButtonLayout->addWidget( myOkBtn ); + aButtonLayout->addStretch(); + aButtonLayout->addWidget( myCancelBtn ); + aButtonLayout->addWidget( myHelpBtn ); aMainLayout->addLayout( aButtonLayout ); - connect( w_ButtonBox, SIGNAL( clicked( QAbstractButton* ) ), - this, SLOT( onClick( QAbstractButton* ) ) ); - - settingsToGui(); - - onFontChanged( currentFont() ); -} - -/*! - \brief Set currently selected font. - \param fnt current font - \sa currentFont() -*/ -void PyEditor_SettingsDlg::setCurrentFont( const QFont& fnt ) -{ - w_FontFamily->blockSignals( true ); - w_FontSize->blockSignals( true ); + connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + connect( myHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); - setFontFamily( fnt.family() ); - setFontSize( fnt.pointSize() ); - - w_FontFamily->blockSignals( false ); - w_FontSize->blockSignals( false ); -} - -/*! - \brief Get currently selected font. - \return current font - \sa setCurrentFont() -*/ -QFont PyEditor_SettingsDlg::currentFont() const -{ - return QFont( fontFamily(), fontSize() ); -} - -/*! - \brief Set font size. - \param s size value - \sa fontSize() -*/ -void PyEditor_SettingsDlg::setFontSize( const int s ) -{ - if ( s <= 0 ) - return; - - int idx = w_FontSize->findText( QString::number( s ) ); - if ( idx != -1 ) - w_FontSize->setCurrentIndex( idx ); - else if ( w_FontSize->isEditable() ) - w_FontSize->setEditText( QString::number( s ) ); -} - -/*! - \brief Get font size. - \return size value - \sa setFontSize() -*/ -int PyEditor_SettingsDlg::fontSize() const -{ - bool ok; - int pSize = w_FontSize->currentText().toInt( &ok ); - return ok ? pSize : 0; -} - -/*! - \brief Set font family name. - \param theFamily new font family name - \sa fontFamily() -*/ -void PyEditor_SettingsDlg::setFontFamily( const QString& theFamily ) -{ - w_FontFamily->setCurrentFont( QFont( theFamily ) ); - onFontChanged( w_FontFamily->currentFont() ); -} - -/*! - \brief Get font family name. - \return font family name - \sa setFontFamily() -*/ -QString PyEditor_SettingsDlg::fontFamily() const -{ - return w_FontFamily->currentFont().family(); + settingsToGui(); } /*! @@ -239,30 +152,6 @@ bool PyEditor_SettingsDlg::isSetAsDefault() return w_DefaultCheck->isChecked(); } -/*! - SLOT: Perform dialog actions - \param theButton button -*/ -void PyEditor_SettingsDlg::onClick( QAbstractButton* theButton ) -{ - QDialogButtonBox::ButtonRole aButtonRole = w_ButtonBox->buttonRole( theButton ); - if ( aButtonRole == QDialogButtonBox::AcceptRole ) - { - settingsFromGui(); - setSettings(); - accept(); - } - else if ( aButtonRole == QDialogButtonBox::ApplyRole ) - { - settingsFromGui(); - setSettings(); - } - else if ( aButtonRole == QDialogButtonBox::RejectRole ) - { - reject(); - } -} - /*! SLOT: Changes the widget visibility depending on the set theState flag. \param theState flag of visibility @@ -273,29 +162,6 @@ void PyEditor_SettingsDlg::onVerticalEdgeChecked( bool theState ) w_NumberColumns->setEnabled( theState ); } -/*! - \brief Called when current font is changed. - \param theFont (not used) -*/ -void PyEditor_SettingsDlg::onFontChanged( const QFont& /*theFont*/ ) -{ - bool blocked = w_FontSize->signalsBlocked(); - w_FontSize->blockSignals( true ); - - int s = fontSize(); - w_FontSize->clear(); - - QList szList = QFontDatabase().pointSizes( fontFamily() ); - QStringList sizes; - for ( QList::const_iterator it = szList.begin(); it != szList.end(); ++it ) - sizes.append( QString::number( *it ) ); - w_FontSize->addItems( sizes ); - - setFontSize( s ); - - w_FontSize->blockSignals( blocked ); -} - /*! \brief Sets settings from preferences dialog. */ @@ -309,7 +175,7 @@ void PyEditor_SettingsDlg::settingsFromGui() my_Editor->settings()->p_TabSize = w_TabSize->value(); my_Editor->settings()->p_VerticalEdge = w_VerticalEdge->isChecked(); my_Editor->settings()->p_NumberColumns = w_NumberColumns->value(); - my_Editor->settings()->p_Font = currentFont(); + my_Editor->settings()->p_Font = w_FontWidget->currentFont(); } /*! @@ -325,7 +191,8 @@ void PyEditor_SettingsDlg::settingsToGui() w_TabSize->setValue( my_Editor->settings()->p_TabSize ); w_VerticalEdge->setChecked( my_Editor->settings()->p_VerticalEdge ); w_NumberColumns->setValue( my_Editor->settings()->p_NumberColumns ); - setCurrentFont( my_Editor->settings()->p_Font ); + w_FontWidget->setCurrentFont( my_Editor->settings()->p_Font ); + w_FontWidget->setSizes(); onVerticalEdgeChecked( my_Editor->settings()->p_VerticalEdge ); } @@ -341,3 +208,21 @@ void PyEditor_SettingsDlg::setSettings() my_Editor->updateStatement(); } + +/*! + Slot, called when user clicks "OK" button +*/ +void PyEditor_SettingsDlg::onOk() +{ + settingsFromGui(); + setSettings(); + accept(); +} + +/*! + Slot, called when user clicks "Help" button. +*/ +void PyEditor_SettingsDlg::onHelp() +{ + emit onHelpClicked(); +} diff --git a/src/PyEditor/PyEditor_SettingsDlg.h b/src/PyEditor/PyEditor_SettingsDlg.h index 971f1e9e5..05f1bb083 100644 --- a/src/PyEditor/PyEditor_SettingsDlg.h +++ b/src/PyEditor/PyEditor_SettingsDlg.h @@ -27,38 +27,28 @@ #include "PyEditor.h" class PyEditor_Editor; -class QAbstractButton; class QCheckBox; -class QComboBox; -class QDialogButtonBox; -class QFontComboBox; class QLabel; +class QPushButton; class QSpinBox; +class QtxFontEdit; class PYEDITOR_EXPORT PyEditor_SettingsDlg : public QDialog { Q_OBJECT public: - explicit PyEditor_SettingsDlg( PyEditor_Editor*, QWidget* = 0 ); - - void setCurrentFont( const QFont& ); - QFont currentFont() const; - - void setFontSize( const int ); - int fontSize() const; - - void setFontFamily( const QString& ); - QString fontFamily() const; + PyEditor_SettingsDlg( PyEditor_Editor*, QWidget* = 0 ); bool isSetAsDefault(); -public Q_SLOTS: - void onClick( QAbstractButton* ); - private Q_SLOTS: void onVerticalEdgeChecked( bool ); - void onFontChanged( const QFont& ); + void onOk(); + void onHelp(); + +Q_SIGNALS: + void onHelpClicked(); private: void settingsToGui(); @@ -77,12 +67,13 @@ private: QSpinBox* w_NumberColumns; QLabel* lbl_NumColumns; - QFontComboBox* w_FontFamily; - QComboBox* w_FontSize; + QtxFontEdit* w_FontWidget; QCheckBox* w_DefaultCheck; - QDialogButtonBox* w_ButtonBox; + QPushButton* myOkBtn; + QPushButton* myCancelBtn; + QPushButton* myHelpBtn; PyEditor_Editor* my_Editor; }; diff --git a/src/PyViewer/PyViewer_ViewWindow.cxx b/src/PyViewer/PyViewer_ViewWindow.cxx index 8b8bab816..3fcdb0f63 100644 --- a/src/PyViewer/PyViewer_ViewWindow.cxx +++ b/src/PyViewer/PyViewer_ViewWindow.cxx @@ -256,7 +256,7 @@ void PyViewer_ViewWindow::createActions() tr( "MNU_PY_BROWSER" ), 0, this ); anAction->setStatusTip( tr( "DSC_PY_BROWSER" ) ); connect( anAction, SIGNAL( triggered() ), this, SLOT( onBrowser() ) ); - aMgr->registerAction( anAction, BrowserId ); + //aMgr->registerAction( anAction, BrowserId ); // 4.2. Create multi-action for help operations /*QtxMultiAction* aHelpAction = new QtxMultiAction( this ); @@ -365,8 +365,11 @@ bool PyViewer_ViewWindow::onSaveAs() */ void PyViewer_ViewWindow::onPreferences() { - PyEditor_SettingsDlg aPage( my_TextEditor, this ); - aPage.exec(); + PyEditor_SettingsDlg* aPage = new PyEditor_SettingsDlg( my_TextEditor, this ); + connect( aPage, SIGNAL( onHelpClicked() ), + this, SLOT( onHelp() ) ); + aPage->exec(); + delete aPage; } /*! @@ -487,3 +490,15 @@ void PyViewer_ViewWindow::onBrowser() parameters << QString( "--file=%1" ).arg( appDir.filePath( "pyeditor.html" ) ); QProcess::startDetached( "HelpBrowser", parameters ); } + +/*! + Slot, called when user clicks "Help" button in "Preferences" dialog box. +*/ +void PyViewer_ViewWindow::onHelp() +{ +#ifndef NO_SUIT + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if ( app ) + app->onHelpContextModule( "GUI", "python_viewer_page.html", "custom_python_preferences" ); +#endif +} diff --git a/src/PyViewer/PyViewer_ViewWindow.h b/src/PyViewer/PyViewer_ViewWindow.h index 3c3f27cc2..81c5604e2 100644 --- a/src/PyViewer/PyViewer_ViewWindow.h +++ b/src/PyViewer/PyViewer_ViewWindow.h @@ -57,6 +57,7 @@ private Q_SLOTS: bool onSaveAs(); void onPreferences(); void onBrowser(); + void onHelp(); private: void loadFile( const QString& );