#include <XGUI_MenuGroupPanel.h>
#include <XGUI_MainWindow.h>
#include <XGUI_Command.h>
+#include <XGUI_Preferences.h>
+
+#include <SUIT_ResourceMgr.h>
#include <QLayout>
#include <QTabWidget>
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
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()
+{
+}
#include <QApplication>
#include <QDialogButtonBox>
+
+const QString XGUI_Preferences::VIEWER_SECTION = "Viewer";
+const QString XGUI_Preferences::MENU_SECTION = "Menu";
+
+
SUIT_ResourceMgr* XGUI_Preferences::myResourceMgr = 0;
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;
}
//**********************************************************
//**********************************************************
XGUI_PreferencesDlg::XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent)
- : QDialog(theParent)
+ : QDialog(theParent), myIsChanged(false)
{
setWindowTitle( tr("Edit preferences") );
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()
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") <<
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 );
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<QVariant> 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);
+ }
+}
#define XGUI_Preferences_H
#include "XGUI.h"
+
+#include <SUIT_PreferenceMgr.h>
#include <QDialog>
class SUIT_ResourceMgr;
-class SUIT_PreferenceMgr;
class QWidget;
+// Pair of values: section name, value name
+typedef QPair<QString, QString> XGUI_Pref;
+typedef QList<XGUI_Pref> 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();
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;
};