From 1da27e0416f9569943ff9596005ed074cbdc573d Mon Sep 17 00:00:00 2001 From: jakub Date: Wed, 12 Jan 2011 14:06:56 +0100 Subject: [PATCH] add setingWidget Qml --- src/mdictionary/gui/SettingsWidget.cpp | 212 +++++++++++++++++++++----------- src/mdictionary/gui/SettingsWidget.h | 22 +++- src/mdictionary/qml/MySpinBox.qml | 8 +- src/mdictionary/qml/SettingsWidget.qml | 152 ++++++++++++++++------- 4 files changed, 272 insertions(+), 122 deletions(-) diff --git a/src/mdictionary/gui/SettingsWidget.cpp b/src/mdictionary/gui/SettingsWidget.cpp index ad16b4c..b8b3c4d 100644 --- a/src/mdictionary/gui/SettingsWidget.cpp +++ b/src/mdictionary/gui/SettingsWidget.cpp @@ -31,7 +31,6 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) : QDialog(parent) { guiInterface = parent; -/* #ifndef Q_WS_MAEMO_5 view= new QDeclarativeView(); @@ -40,116 +39,146 @@ guiInterface = parent; view->setAlignment(Qt::AlignCenter); view->show(); + view->setMinimumWidth(250); + view->setMaximumWidth(250); + view->setMinimumHeight(view->sizeHint().height()); + view->setMaximumHeight(view->sizeHint().height()); + mainLayout = new QVBoxLayout; mainLayout->addWidget(view); setLayout(mainLayout); + view->setWindowTitle(tr("Settings")); QGraphicsObject *rootObject = view->rootObject(); - // connect(this, SIGNAL(setUrl(QVariant)), - // rootObject, SLOT(setUrl(QVariant))); - view->setWindowTitle(tr("Settings")); + connect(this, SIGNAL(setMinHistory(QVariant)), + rootObject, SLOT(setMinHistory(QVariant))); + connect(this, SIGNAL(setValueHistory(QVariant)), + rootObject, SLOT(setValueHistory(QVariant))); + connect(this, SIGNAL(setMaxHistory(QVariant)), + rootObject, SLOT(setMaxHistory(QVariant))); + connect(this, SIGNAL(setMinSearchResult(QVariant)), + rootObject, SLOT(setMinSearchResult(QVariant))); + connect(this, SIGNAL(setValueSearchResult(QVariant)), + rootObject, SLOT(setValueSearchResult(QVariant))); + connect(this, SIGNAL(setMaxSearchResult(QVariant)), + rootObject, SLOT(setMaxSearchResult(QVariant))); + connect(this, SIGNAL(setCheckedBookmarks(QVariant)), + rootObject, SLOT(setCheckedBookmarks(QVariant))); + connect(this, SIGNAL(setCheckedDictionaries(QVariant)), + rootObject, SLOT(setCheckedDictionaries(QVariant))); + + connect(rootObject, SIGNAL(historySizeValueChanged(int)), + this, SLOT(historySizeValueChanged(int))); + connect(rootObject, SIGNAL(searchResulValueChanged(int)), + this, SLOT(searchResulValueChanged(int))); + connect(rootObject, SIGNAL(dictionariesCheckBoxChanged(bool)), + this, SLOT(dictionariesCheckBoxChanged(bool))); + connect(rootObject, SIGNAL(bookmarksCheckBoxChanged(bool)), + this, SLOT(bookmarksCheckBoxChanged(bool))); + connect(rootObject, SIGNAL(saveButtonClicked()), + this, SLOT(save())); #else -// */ setWindowTitle(tr("Settings")); - initalizeUI(); setModal(true); -//#endif +#endif + + initalizeUI(); +} + +void SettingsWidget::historySizeValueChanged(int value){ + historyValue = value; + changed(); +} + +void SettingsWidget::searchResulValueChanged(int value){ + searchResultValue=value; + changed(); +} + +void SettingsWidget::dictionariesCheckBoxChanged(bool boolean){ + dictionariesCheckBox=boolean; + changed(); +} + +void SettingsWidget::bookmarksCheckBoxChanged(bool boolean){ + bookmarksCheckBox=boolean; + changed(); } void SettingsWidget::initalizeUI() { +#ifndef Q_WS_MAEMO_5 + emit setMinHistory(1); + emit setMaxHistory(50); + emit setMinHistory(0); + emit setMaxHistory(500); + settings = 0; +#else verticalLayout = new QVBoxLayout; - setLayout(verticalLayout); - historySizeLayout = new QHBoxLayout; - historySizeSpinBox = new SpinBox; + searchResultLayout = new QHBoxLayout; + searchResultSizeSpinBox = new SpinBox; + searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks")); + searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries")); + historySizeSpinBox->setMinimum(1); historySizeSpinBox->setMaximum(50); - historySizeToolTip = tr("Limits maximum number of words saved in history"); + historySizeLayout->addWidget(historySizeSpinBox); #ifdef Q_WS_MAEMO_5 historySizeInfoToolButton = new QToolButton; historySizeInfoToolButton->setIcon(QIcon::fromTheme("general_information")); - #endif - - historySizeLayout->addWidget(historySizeSpinBox); - #ifdef Q_WS_MAEMO_5 historySizeLayout->addWidget(historySizeInfoToolButton); + searchResultSizeInfoToolButton = new QToolButton; + searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information")); #endif - - - - searchResultLayout = new QHBoxLayout; - - searchResultSizeSpinBox = new SpinBox; searchResultSizeSpinBox->setMinimum(0); searchResultSizeSpinBox->setMaximum(500); searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited")); - searchResultSizeToolTip = tr("Limits maximum number of found words, affects" " only when searching in file."); - - #ifdef Q_WS_MAEMO_5 - searchResultSizeInfoToolButton = new QToolButton; - searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information")); - #endif - searchResultLayout->addWidget(searchResultSizeSpinBox); + #ifdef Q_WS_MAEMO_5 searchResultLayout->addWidget(searchResultSizeInfoToolButton); #endif - - - - spinBoxesFormLayout = new QFormLayout; - spinBoxesFormLayout->addRow(tr("Search result size"), - searchResultLayout); - spinBoxesFormLayout->addRow(tr("History size"), - historySizeLayout); - - - + spinBoxesFormLayout->addRow(tr("Search result size"), searchResultLayout); + spinBoxesFormLayout->addRow(tr("History size"), historySizeLayout); verticalLayout->addLayout(spinBoxesFormLayout); - - checkBoxesLabel = new QLabel(tr("Search in:"),this); - searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks")); - searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries")); - verticalLayout->addSpacing(20); verticalLayout->addWidget(checkBoxesLabel); verticalLayout->addWidget(searchInDictionariesCheckBox); verticalLayout->addWidget(searchInBookmarksCheckBox); + setLayout(verticalLayout); - connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this, - SLOT(changed())); - connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this, - SLOT(changed())); - connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this, - SLOT(changed())); - connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this, - SLOT(changed())); - + connect(historySizeSpinBox, SIGNAL(valueChanged(int)), + this,SLOT(changed())); + connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), + this,SLOT(changed())); + connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), + this,SLOT(changed())); + connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), + this,SLOT(changed())); -#ifdef Q_WS_MAEMO_5 + #ifdef Q_WS_MAEMO_5 connect(searchResultSizeInfoToolButton, SIGNAL(clicked()), this, SLOT(showSearchResultSizeInfo())); - connect(historySizeInfoToolButton, SIGNAL(clicked()), this, SLOT(showHistorySizeInfo())); -#else + #else historySizeSpinBox->setToolTip(historySizeToolTip); searchResultSizeSpinBox->setToolTip(searchResultSizeToolTip); -#endif + #endif settings = 0; @@ -167,15 +196,29 @@ void SettingsWidget::initalizeUI() { setMaximumHeight(sizeHint().height()); connect(closeButton, SIGNAL(clicked()), this, SLOT(save())); #endif +#endif } void SettingsWidget::showEvent(QShowEvent *e) { -/* #ifndef Q_WS_MAEMO_5 + settings = guiInterface->settings(); + + emit setValueHistory(settings->value("history_size").toInt()); + emit setValueSearchResult(settings->value("search_limit").toInt()); + + if(settings->value("search_bookmarks") == "true") + emit setCheckedBookmarks(true); + else + emit setCheckedBookmarks(false); + + if(settings->value("search_dictionaries") == "true") + emit setCheckedDictionaries(true); + else + emit setCheckedDictionaries(false); + QDialog::showEvent(e); #else -//*/ #ifndef Q_WS_MAEMO_5 _save = false; #endif @@ -197,25 +240,47 @@ void SettingsWidget::showEvent(QShowEvent *e) { searchInDictionariesCheckBox->setChecked(true); else searchInDictionariesCheckBox->setChecked(false); - - _changed = false; QDialog::showEvent(e); -//#endif +#endif + _changed = false; } void SettingsWidget::hideEvent(QHideEvent *e) { QDialog::hideEvent(e); - #ifndef Q_WS_MAEMO_5 - if(settings && _save) { - #else - if(settings && _changed && - QMessageBox::question(this, - tr("Save"), - tr("Do you want to save changes?"), - QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) { +#ifndef Q_WS_MAEMO_5 + if(settings && _save) { + Settings* newSettings = new Settings; + newSettings->setValue("history_size",QString::number(historyValue)); + newSettings->setValue("search_limit",QString::number(searchResultValue)); + if(dictionariesCheckBox==true) + newSettings->setValue("search_dictionaries", "true"); + else + newSettings->setValue("search_dictionaries", "false"); + + if(bookmarksCheckBox==true) + newSettings->setValue("search_bookmarks", "true"); + else + newSettings->setValue("search_bookmarks", "false"); + foreach(QString key, newSettings->keys()) { + if(settings->value(key) != newSettings->value(key)) { + guiInterface->setSettings(newSettings); + break; + } + } + _changed = false; + if(settings) { + delete settings; + settings = 0; + } + } +#else + if(settings && _changed && + QMessageBox::question(this, + tr("Save"), + tr("Do you want to save changes?"), + QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) { - #endif Settings* newSettings = new Settings; newSettings->setValue("history_size", QString::number(historySizeSpinBox->value())); @@ -234,20 +299,19 @@ void SettingsWidget::hideEvent(QHideEvent *e) { newSettings->setValue("search_bookmarks", "false"); //setting new settings only if they are different than old ones - QString key; - foreach(key, newSettings->keys()) { + foreach(QString key, newSettings->keys()) { if(settings->value(key) != newSettings->value(key)) { guiInterface->setSettings(newSettings); break; } } - } if(settings) { delete settings; settings = 0; } _changed = false; +#endif } diff --git a/src/mdictionary/gui/SettingsWidget.h b/src/mdictionary/gui/SettingsWidget.h index b8d9841..d721cd9 100644 --- a/src/mdictionary/gui/SettingsWidget.h +++ b/src/mdictionary/gui/SettingsWidget.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "../../include/GUIInterface.h" #include "../../include/settings.h" @@ -57,6 +58,15 @@ public: explicit SettingsWidget(GUIInterface *parent = 0); Q_SIGNALS: + void setMinHistory(QVariant minValue); + void setMaxHistory(QVariant minValue); + void setValueHistory(QVariant value); + void setMinSearchResult(QVariant minValue); + void setMaxSearchResult(QVariant minValue); + void setValueSearchResult(QVariant value); + void setCheckedBookmarks(QVariant boolen); + void setCheckedDictionaries(QVariant boolen); + void notify(Notify::NotifyType, QString); protected: @@ -64,6 +74,11 @@ protected: void hideEvent(QHideEvent *); private Q_SLOTS: + void historySizeValueChanged(int value); + void searchResulValueChanged(int value); + void dictionariesCheckBoxChanged(bool boolean); + void bookmarksCheckBoxChanged(bool boolean); + void changed(); #ifndef Q_WS_MAEMO_5 void save(); @@ -108,9 +123,10 @@ private: QHBoxLayout* footerLayout; bool _save; #endif - - - + int historyValue; + int searchResultValue; + bool dictionariesCheckBox; + bool bookmarksCheckBox; }; #endif // SETTINGSWIDGET_H diff --git a/src/mdictionary/qml/MySpinBox.qml b/src/mdictionary/qml/MySpinBox.qml index c248bbe..9f0d47c 100644 --- a/src/mdictionary/qml/MySpinBox.qml +++ b/src/mdictionary/qml/MySpinBox.qml @@ -31,14 +31,16 @@ Rectangle { height: rectangle1.height*0.6; text: "123" anchors.centerIn: parent - validator: IntValidator{bottom: 0; top: 500;} + validator: IntValidator{bottom: minValue; top: maxValue;} transformOrigin: Item.Left selectByMouse: true; font.pixelSize: rectangle1.height * .5; onCursorPositionChanged: moveCursorSelection(cursorPosition); - //focus: rectangle1.focus; onTextChanged: rectangle1.valueChange(stringToInt(text_input1.text)); - + onFocusChanged: { + if(focus==false) + text=stringToInt(text); + } } Timer { diff --git a/src/mdictionary/qml/SettingsWidget.qml b/src/mdictionary/qml/SettingsWidget.qml index df60531..74d3a9f 100644 --- a/src/mdictionary/qml/SettingsWidget.qml +++ b/src/mdictionary/qml/SettingsWidget.qml @@ -1,86 +1,154 @@ import Qt 4.7 Rectangle { - width: 500 - height:500 + id: rectangle1 + width: 230 + height:170 + + SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } + color : myPalette.window; + + signal historySizeValueChanged(int intiger); + signal searchResulValueChanged(int intiger); + signal dictionariesCheckBoxChanged(bool Boolean); + signal bookmarksCheckBoxChanged(bool Boolean); + signal saveButtonClicked(); + + function setMinHistory(intiger){ + historySpinbox.minValue=intiger; + } + function setMaxHistory(intiger){ + historySpinbox.maxValue=intiger; + } + function setValueHistory(intiger){ + historySpinbox.value=intiger; + } + + function setMaxSearchResult(intiger){ + searchSpinbox.maxValue=intiger; + } + function setMinSearchResult(intiger){ + searchSpinbox.minValue=intiger; + } + function setValueSearchResult(intiger){ + searchSpinbox.value=intiger; + } + + function setCheckedBookmarks(bool){ + bookmarkCheckBox.selected=bool; + } + function setCheckedDictionaries(bool){ + dictionariesCheckBox.selected=bool; + } Text { - id: text1 - x: 36 - y: 11 - width: 80 - height: 20 - text: "Search result size" + id: textSearch + width: 120 + height: paintedHeight+5; + text: qsTr("Search result size") + anchors.verticalCenterOffset: 2 + anchors.left: parent.left + anchors.verticalCenter: searchSpinbox.verticalCenter font.pixelSize: 12 } Text { - id: text2 - x: 36 - y: 83 - width: 80 - height: 20 - text: "History size" + id: textHistory + width: 120 + height: paintedHeight+5; + text: qsTr("History size") + anchors.verticalCenterOffset: 2 + anchors.left: parent.left + anchors.verticalCenter: historySpinbox.verticalCenter font.pixelSize: 12 } Text { - id: text3 - x: 36 - y: 131 - width: 80 - height: 20 - text: "Search in:" + id: textSearchIn + width: 120 + height: paintedHeight+5; + text: qsTr("Search in:") + anchors.top: textHistory.bottom + anchors.topMargin: 15 + anchors.left: parent.left font.pixelSize: 12 } Text { - id: text4 - x: 94 - y: 150 - width: 80 + id: textBookmark + width: 120 height: 20 - text: "Bookmarks" + text: qsTr("Bookmarks") + anchors.verticalCenterOffset: 2 + anchors.left: bookmarkCheckBox.right + anchors.leftMargin: 10 + anchors.verticalCenter: bookmarkCheckBox.verticalCenter font.pixelSize: 12 } Text { - id: text5 - x: 94 - y: 177 - width: 80 + id: textDictionaries + width: 120 height: 20 - text: "Dictionaries" + text: qsTr("Dictionaries") + anchors.verticalCenterOffset: 2 + anchors.left: dictionariesCheckBox.right + anchors.leftMargin: 10 + anchors.verticalCenter: dictionariesCheckBox.verticalCenter font.pixelSize: 12 } MySpinBox { - id: myspinbox1 + id: searchSpinbox width: 40 height: 20; - x: 152 - y: 9 + anchors.top: parent.top + anchors.topMargin: 10 + anchors.left: textSearch.right + anchors.leftMargin: 20 + onValueChange: rectangle1.searchResulValueChanged(intiger); } MySpinBox { - id: myspinbox2 + id: historySpinbox width: 40 height: 20; - x: 152 - y: 81 + anchors.horizontalCenter: searchSpinbox.horizontalCenter + anchors.top: searchSpinbox.bottom + anchors.topMargin: 10 + onValueChange: rectangle1.historySizeValueChanged(intiger); } Checkbox { - id: checkbox1 + id: bookmarkCheckBox width: 20 - x: 36 - y: 157 + height: 20 + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.top: textSearchIn.bottom + anchors.topMargin: 0 + onChanged: rectangle1.bookmarksCheckBoxChanged(selected); } Checkbox { - id: checkbox2 + id: dictionariesCheckBox width: 20 - x: 36 - y: 177 + height: 20 + anchors.horizontalCenter: bookmarkCheckBox.horizontalCenter + anchors.top: bookmarkCheckBox.bottom + anchors.topMargin: 3 + onChanged: rectangle1.dictionariesCheckBoxChanged(selected); + } + + Button { + id: saveButton + width: 66 + height:26 + anchors.bottom: parent.bottom + anchors.bottomMargin: 5 + anchors.right: parent.right + anchors.rightMargin: 5 + textInButton: qsTr("Save") + onClicked: rectangle1.saveButtonClicked(); } } -- 1.7.9.5