From: vsv Date: Tue, 12 Aug 2014 14:57:56 +0000 (+0400) Subject: Editing preferences added X-Git-Tag: V_0.4.4~109^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0452ad37317a81b20f0d0c0a5136aaae10774ad5;p=modules%2Fshaper.git Editing preferences added --- diff --git a/src/XGUI/NewGeom.xml b/src/XGUI/NewGeom.xml index 0f76d8321..1b1bd2a0b 100644 --- a/src/XGUI/NewGeom.xml +++ b/src/XGUI/NewGeom.xml @@ -2,7 +2,12 @@ -->
- + -
+ +
+ + + +
diff --git a/src/XGUI/XGUI_MainMenu.cpp b/src/XGUI/XGUI_MainMenu.cpp index a16076e54..4e64c9e6e 100644 --- a/src/XGUI/XGUI_MainMenu.cpp +++ b/src/XGUI/XGUI_MainMenu.cpp @@ -3,6 +3,9 @@ #include #include #include +#include + +#include #include #include @@ -129,9 +132,9 @@ QList XGUI_MainMenu::workbenches() const int XGUI_MainMenu::menuItemSize() const { - //TODO(sbh, vsv): get this value from the preferences - static const ItemSize DEFAULT_ITEM_SIZE = Medium; - return (int) DEFAULT_ITEM_SIZE; + int DEFAULT_ITEM_SIZE = XGUI_Preferences::resourceMgr()->integerValue( + XGUI_Preferences::MENU_SECTION, "item_size"); + return DEFAULT_ITEM_SIZE; } int XGUI_MainMenu::menuHeight() const @@ -144,7 +147,11 @@ int XGUI_MainMenu::menuHeight() const int XGUI_MainMenu::menuItemRowsCount() const { - //TODO(sbh, vsv): get this value from the preferences - static const int DEFAULT_ITEM_ROWS_COUNT = 3; + int DEFAULT_ITEM_ROWS_COUNT = XGUI_Preferences::resourceMgr()->integerValue( + XGUI_Preferences::MENU_SECTION, "rows_number"); return DEFAULT_ITEM_ROWS_COUNT; } + +void XGUI_MainMenu::updateFromResources() +{ +} diff --git a/src/XGUI/XGUI_MainMenu.h b/src/XGUI/XGUI_MainMenu.h index 3be908792..b583bf02c 100644 --- a/src/XGUI/XGUI_MainMenu.h +++ b/src/XGUI/XGUI_MainMenu.h @@ -28,11 +28,11 @@ class XGUI_EXPORT XGUI_MainMenu: public QWidget //! Size of menu item //TODO(sbh, vsv): Move to the settings - enum ItemSize { - Small = 20, - Medium = 25, - Large = 30 - }; + //enum ItemSize { + // Small = 20, + // Medium = 25, + // Large = 30 + //}; public: XGUI_MainMenu(XGUI_MainWindow *parent); @@ -69,6 +69,8 @@ public: int menuItemRowsCount() const; int menuHeight() const; + void updateFromResources(); + private: XGUI_MainWindow* myDesktop; QTabWidget* myMenuTabs; diff --git a/src/XGUI/XGUI_Preferences.cpp b/src/XGUI/XGUI_Preferences.cpp index 06d7fbf15..14fea9f98 100644 --- a/src/XGUI/XGUI_Preferences.cpp +++ b/src/XGUI/XGUI_Preferences.cpp @@ -12,6 +12,11 @@ #include #include + +const QString XGUI_Preferences::VIEWER_SECTION = "Viewer"; +const QString XGUI_Preferences::MENU_SECTION = "Menu"; + + SUIT_ResourceMgr* XGUI_Preferences::myResourceMgr = 0; @@ -24,10 +29,16 @@ SUIT_ResourceMgr* XGUI_Preferences::resourceMgr() return myResourceMgr; } -void XGUI_Preferences::editPreferences() +bool XGUI_Preferences::editPreferences(XGUI_Prefs& theModified) { XGUI_PreferencesDlg aDlg(resourceMgr(), QApplication::activeWindow()); aDlg.exec(); + if (aDlg.isChanged()) { + aDlg.modified(theModified); + resourceMgr()->save(); + return true; + } + return false; } @@ -36,7 +47,7 @@ void XGUI_Preferences::editPreferences() //********************************************************** //********************************************************** XGUI_PreferencesDlg::XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent) - : QDialog(theParent) + : QDialog(theParent), myIsChanged(false) { setWindowTitle( tr("Edit preferences") ); @@ -44,21 +55,21 @@ XGUI_PreferencesDlg::XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* main->setMargin( 5 ); main->setSpacing( 5 ); - myPreferences = new SUIT_PreferenceMgr(theResurces, this); + myPreferences = new XGUI_PreferencesMgr(theResurces, this); main->addWidget( myPreferences ); setFocusProxy( myPreferences ); myPreferences->setFrameStyle( QFrame::Box | QFrame::Sunken ); - //myPreferences->show(); QDialogButtonBox* aBtnBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); main->addWidget(aBtnBox); connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept())); connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject())); + createEditors(); myPreferences->retrieve(); - createEditors(); + setMinimumSize(800, 200); } XGUI_PreferencesDlg::~XGUI_PreferencesDlg() @@ -67,10 +78,16 @@ XGUI_PreferencesDlg::~XGUI_PreferencesDlg() void XGUI_PreferencesDlg::createEditors() { - int aLFpage = myPreferences->addItem("Look&Feel"); + int aLFpage = myPreferences->addItem("Desktop"); myPreferences->setItemIcon(aLFpage, QIcon(":pictures/view_prefs.png")); - int viewTab = myPreferences->addItem( tr("Viewer"), aLFpage ); + createMenuPage(aLFpage); + createViewerPage(aLFpage); +} + +void XGUI_PreferencesDlg::createViewerPage(int thePageId) +{ + int viewTab = myPreferences->addItem( tr("Viewer"), thePageId ); QStringList gradList; gradList << tr("Horizontal gradient") << tr("Vertical gradient") << @@ -87,7 +104,8 @@ void XGUI_PreferencesDlg::createEditors() QString aImgFiles("Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)"); int bgId = myPreferences->addItem( tr("Viewer 3d" ), bgGroup, - SUIT_PreferenceMgr::Background, "Viewer", "background" ); + SUIT_PreferenceMgr::Background, + XGUI_Preferences::VIEWER_SECTION, "background" ); myPreferences->setItemProperty( "gradient_names", gradList, bgId ); myPreferences->setItemProperty( "gradient_ids", idList, bgId ); myPreferences->setItemProperty( "texture_enabled", true, bgId ); @@ -96,10 +114,61 @@ void XGUI_PreferencesDlg::createEditors() myPreferences->setItemProperty( "texture_stretch_enabled", true, bgId ); myPreferences->setItemProperty( "custom_enabled", false, bgId ); myPreferences->setItemProperty( "image_formats", aImgFiles, bgId ); +} +void XGUI_PreferencesDlg::createMenuPage(int thePageId) +{ + int aMenuTab = myPreferences->addItem(tr("Main menu"), thePageId ); + + int aSizeGroup = myPreferences->addItem(tr("Size"), aMenuTab ); + myPreferences->setItemProperty( "columns", 2, aSizeGroup ); + + int aItemSizeItem = myPreferences->addItem( tr( "Item size" ), + aSizeGroup, + SUIT_PreferenceMgr::Selector, + XGUI_Preferences::MENU_SECTION, + "item_size" ); + QStringList aValuesList; + QList anIndicesList; + aValuesList << tr("Small") << tr("Medium") << tr("Large"); + anIndicesList << 20 << 25 << 30; + myPreferences->setItemProperty( "strings", aValuesList, aItemSizeItem ); + myPreferences->setItemProperty( "indexes", anIndicesList, aItemSizeItem ); + + int aRowsNb = myPreferences->addItem( tr( "Number of rows" ), + aSizeGroup, + SUIT_PreferenceMgr::IntSpin, + XGUI_Preferences::MENU_SECTION, + "rows_number" ); + myPreferences->setItemProperty( "min", 1, aRowsNb ); + myPreferences->setItemProperty( "max", 10, aRowsNb ); } +void XGUI_PreferencesDlg::accept() +{ + myPreferences->store(); + myIsChanged = true; + QDialog::accept(); +} +void XGUI_PreferencesDlg::modified(XGUI_Prefs& theModified) const +{ + theModified = myPreferences->modified(); +} +//********************************************************** +//********************************************************** +//********************************************************** +void XGUI_PreferencesMgr::changedResources( const ResourceMap& theMap) +{ + myModified.clear(); + ResourceMap::ConstIterator it; + QString sec, param; + for (it = theMap.begin(); it != theMap.end(); ++it ) { + XGUI_Pref aPref; + it.key()->resource( aPref.first, aPref.second ); + myModified.append(aPref); + } +} diff --git a/src/XGUI/XGUI_Preferences.h b/src/XGUI/XGUI_Preferences.h index 5453ec5a9..90150c67f 100644 --- a/src/XGUI/XGUI_Preferences.h +++ b/src/XGUI/XGUI_Preferences.h @@ -6,17 +6,27 @@ #define XGUI_Preferences_H #include "XGUI.h" + +#include #include class SUIT_ResourceMgr; -class SUIT_PreferenceMgr; class QWidget; +// Pair of values: section name, value name +typedef QPair XGUI_Pref; +typedef QList XGUI_Prefs; + + +//*********************************************************************** +/// Class for manipulation with preferences in the application class XGUI_EXPORT XGUI_Preferences { public: + static const QString VIEWER_SECTION; + static const QString MENU_SECTION; - static void editPreferences(); + static bool editPreferences(XGUI_Prefs& theModified); static SUIT_ResourceMgr* resourceMgr(); @@ -24,18 +34,50 @@ private: static SUIT_ResourceMgr* myResourceMgr; }; +//*********************************************************************** +/// Manager of preferences +class XGUI_EXPORT XGUI_PreferencesMgr : public SUIT_PreferenceMgr +{ + Q_OBJECT +public: + XGUI_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent) + :SUIT_PreferenceMgr(theResource, theParent) {} + + virtual ~XGUI_PreferencesMgr() {} + + XGUI_Prefs modified() const { return myModified; } + +protected: + virtual void changedResources( const ResourceMap& theMap); -class XGUI_PreferencesDlg: public QDialog +private: + XGUI_Prefs myModified; +}; + + +//*********************************************************************** +/// Dialog box for preferences editing +class XGUI_EXPORT XGUI_PreferencesDlg: public QDialog { Q_OBJECT public: XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0); virtual ~XGUI_PreferencesDlg(); + bool isChanged() const { return myIsChanged; } + + void modified(XGUI_Prefs& theModified) const; + +public slots: + virtual void accept(); + private: void createEditors(); - - SUIT_PreferenceMgr* myPreferences; + void createViewerPage(int thePageId); + void createMenuPage(int thePageId); + + XGUI_PreferencesMgr* myPreferences; + bool myIsChanged; }; diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 4f445729b..e605d2a07 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -198,6 +198,17 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) return aWnd; } +void XGUI_Viewer::updateFromResources() +{ + Qtx::BackgroundData aBk = XGUI_Preferences::resourceMgr()->backgroundValue("Viewer", "background"); + foreach (QMdiSubWindow* aWnd, myViews) { + XGUI_ViewWindow* aView = dynamic_cast(aWnd->widget()); + if (aView) + aView->setBackground(aBk); + } +} + + XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const { if (myActiveView) diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 8c2f13c9c..218fd26d0 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -128,6 +128,7 @@ public: //! Add action to the viewer void addAction(QAction* theAction) { myActions.append(theAction); } + void updateFromResources(); static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper, Qt::KeyboardModifiers theState, Qt::MouseButtons theButton); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b25db3e10..f6c41a9f4 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -668,7 +668,21 @@ void XGUI_Workshop::onRedo() //****************************************************** void XGUI_Workshop::onPreferences() { - XGUI_Preferences::editPreferences(); + XGUI_Prefs aModif; + XGUI_Preferences::editPreferences(aModif); + if (aModif.size() > 0) { + QString aSection; + foreach (XGUI_Pref aPref, aModif) { + aSection = aPref.first; + if (aSection == XGUI_Preferences::VIEWER_SECTION) { + if (!isSalomeMode()) + myMainWindow->viewer()->updateFromResources(); + } else if (aSection == XGUI_Preferences::MENU_SECTION) { + if (!isSalomeMode()) + myMainWindow->menuObject()->updateFromResources(); + } + } + } } //******************************************************