From: jakub Date: Thu, 13 Jan 2011 14:21:45 +0000 (+0100) Subject: xdxfDialog in qml X-Git-Url: http://vcs.maemo.org/git/?p=mdictionary;a=commitdiff_plain;h=695a29e13c1b432ae8ec369fcab200c5e21e4739 xdxfDialog in qml --- diff --git a/mdictionary.pri b/mdictionary.pri index 5b4b2ea..c48f80d 100644 --- a/mdictionary.pri +++ b/mdictionary.pri @@ -30,3 +30,5 @@ DEFINES += MDICTIONARY_PLUGINS_DIR=\\\"$$PLUGINS_DIR\\\" system(echo "ENABLED_SRC = $$ENABLED_SRC" >src/src.pri) system(echo "ENABLED_PLUGINS = $$ENABLED_PLUGINS" >src/plugins/plugins.pri) + +OTHER_FILES += diff --git a/src/mdictionary/gui/SettingsWidget.cpp b/src/mdictionary/gui/SettingsWidget.cpp index b8b3c4d..4c37017 100644 --- a/src/mdictionary/gui/SettingsWidget.cpp +++ b/src/mdictionary/gui/SettingsWidget.cpp @@ -32,7 +32,6 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) : QDialog(parent) { guiInterface = parent; #ifndef Q_WS_MAEMO_5 - view= new QDeclarativeView(); view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/SettingsWidget.qml")); view->setResizeMode(QDeclarativeView::SizeRootObjectToView); diff --git a/src/mdictionary/qml/XdxfDialog.qml b/src/mdictionary/qml/XdxfDialog.qml new file mode 100644 index 0000000..567c455 --- /dev/null +++ b/src/mdictionary/qml/XdxfDialog.qml @@ -0,0 +1,220 @@ +import Qt 4.7 + +Rectangle{ + id:rectangle1 + width: 220 + height: textPlugin.height + textFrom.height + textTo.height + textDescription.height + textInfo.height +90 + + property bool newPlugin:false; + + SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } + color : myPalette.window; + + function setPlugin(string){ + textPlugin.text = qsTr("Plugin") + ": " + string; + } + function setFrom(string){ + textFrom.text = qsTr("From") + ": " + string; + } + function setTo(string){ + textTo.text = qsTr("To") + ": " + string; + } + function setDescription(string){ + textDescription.text = qsTr("Description") + ": " + string; + } + function setInfo(string){ + textInfo.text = string; + } + function setButtonText(string){ + saveButton.textInButton=string; + } + function setCheckedOptimalize(bool){ + optimalizeCheckbox.selected=bool; + } + function setCheckedStrip(bool){ + stripCheckbox.selected=bool; + } + function setNew(bool){ + newPlugin=bool; + } + function setPath(string){ + console.log("new path"); + textPath.text=string; + } + + + signal saveButtonClicked(); + signal downloadButtonClicked(); + signal browseButtonClicked(); + signal optimalizeCheckboxChanged(bool Boolean); + signal stripCheckboxChanged(bool Boolean); + + Text { + id: textPlugin + width: rectangle1.width + height: paintedHeight+5; + text: "Plugin: " + wrapMode: Text.Wrap; + transformOrigin: Item.Left + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: 12 + } + + Text { + id: textFrom + width:rectangle1.width + height: paintedHeight+5; + text: "From: " + wrapMode: Text.Wrap; + anchors.top: textPlugin.bottom + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: 12 + } + + Text { + id: textTo + width: rectangle1.width + height: paintedHeight+5; + text: "To: " + wrapMode: Text.Wrap; + anchors.top: textFrom.bottom + transformOrigin: Item.Left + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: 12 + } + + Text { + id: textDescription + width: rectangle1.width + height: paintedHeight+5; + text: "Description: " + wrapMode: Text.Wrap; + anchors.top: textTo.bottom + transformOrigin: Item.Left + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: 12 + } + + Text { + id: textInfo + width: rectangle1.width + height: paintedHeight+5; + text: ": " + wrapMode: Text.Wrap; + anchors.top: textDescription.bottom + transformOrigin: Item.Left + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: 12 + } + + Checkbox { + id: optimalizeCheckbox + width: 20 + height: 20 + anchors.left: parent.left + anchors.leftMargin: 5 + anchors.top: textInfo.bottom + onChanged: rectangle1.optimalizeCheckboxChanged(selected); + } + + Checkbox { + id: stripCheckbox + width: 20 + height: 20 + anchors.top: optimalizeCheckbox.bottom + anchors.topMargin: 5 + anchors.horizontalCenter: optimalizeCheckbox.horizontalCenter + onChanged: rectangle1.stripCheckboxChanged(selected); + } + + Text { + id: textOptimalize + width: 80 + height: 20 + text: qsTr("Optimize") + anchors.left: optimalizeCheckbox.right + anchors.leftMargin: 5 + anchors.verticalCenterOffset: 3 + anchors.verticalCenter: optimalizeCheckbox.verticalCenter + font.pixelSize: 12 + } + + Text { + id: textStrip + width: 80 + height: 20 + text: qsTr("Strip accents") + anchors.verticalCenterOffset: 3 + anchors.verticalCenter: stripCheckbox.verticalCenter + anchors.horizontalCenter: textOptimalize.horizontalCenter + font.pixelSize: 12 + } + + Button { + id: saveButton + height: 30 + textInButton: qsTr("Save") + anchors.top: stripCheckbox.bottom + anchors.topMargin: 10 + anchors.right: parent.right + anchors.left: parent.left + onClicked: rectangle1.saveButtonClicked(); + } + + Text { + id: textPath + height: paintedHeight+5; + text: qsTr("Dictionary file: not selected") + wrapMode: Text.Wrap; + anchors.top: parent.top + anchors.topMargin: 10 + anchors.right: browseButton.left + anchors.rightMargin: 0 + anchors.left: parent.left + anchors.leftMargin: 0 + font.pixelSize: 12 + opacity: 0 + } + + Button { + id: browseButton + width: 80; + height: 25; + textInButton: qsTr("Browse"); + anchors.top: parent.top + anchors.topMargin: 10 + anchors.right: parent.right + anchors.rightMargin: 10 + opacity: 0 + onClicked: rectangle1.browseButtonClicked(); + } + + Button { + id: downloadButton + width: 80; + height: 25; + textInButton: qsTr("Download"); + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.top: browseButton.bottom + anchors.topMargin: 10 + opacity: 0 + onClicked: rectangle1.downloadButtonClicked(); + } + + states: [ + State { + name: "Stan1" + when: newPlugin==true + PropertyChanges { target: textPlugin; opacity: 0} + PropertyChanges { target: textFrom; opacity: 0} + PropertyChanges { target: textTo; opacity: 0} + PropertyChanges { target: textDescription; opacity: 0} + PropertyChanges { target: textInfo; opacity: 0} + + PropertyChanges { target: textPath; opacity: 1} + PropertyChanges { target: browseButton; opacity: 1 } + PropertyChanges { target: downloadButton; opacity: 1} + } + ] +} diff --git a/src/plugins/xdxf/XdxfDialog.cpp b/src/plugins/xdxf/XdxfDialog.cpp index c0d8bac..32abb55 100644 --- a/src/plugins/xdxf/XdxfDialog.cpp +++ b/src/plugins/xdxf/XdxfDialog.cpp @@ -32,14 +32,63 @@ XdxfDialog::XdxfDialog(XdxfPlugin *plugin, XdxfDialogType type, QWidget *parent) : QDialog(parent) { + this->plugin = plugin; this->type = type; +#ifndef Q_WS_MAEMO_5 + + view= new QDeclarativeView(); + view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/XdxfDialog.qml")); + view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + view->setAlignment(Qt::AlignCenter); + view->show(); + + mainLayout = new QVBoxLayout; + mainLayout->addWidget(view); + setLayout(mainLayout); + view->setWindowTitle(tr("Xdxf Settings")); + + QGraphicsObject *rootObject = view->rootObject(); + + connect(this, SIGNAL(setPlugin(QVariant)), + rootObject, SLOT(setPlugin(QVariant))); + connect(this, SIGNAL(setFrom(QVariant)), + rootObject, SLOT(setFrom(QVariant))); + connect(this, SIGNAL(setTo(QVariant)), + rootObject, SLOT(setTo(QVariant))); + connect(this, SIGNAL(setDescription(QVariant)), + rootObject, SLOT(setDescription(QVariant))); + connect(this, SIGNAL(setInfo(QVariant)), + rootObject, SLOT(setInfo(QVariant))); + connect(this, SIGNAL(setCheckedOptimalize(QVariant)), + rootObject, SLOT(setCheckedOptimalize(QVariant))); + connect(this, SIGNAL(setCheckedStrip(QVariant)), + rootObject, SLOT(setCheckedStrip(QVariant))); + connect(this,SIGNAL(setButtonText(QVariant)), + rootObject, SLOT(setButtonText(QVariant))); + connect(this,SIGNAL(setNew(QVariant)), + rootObject, SLOT(setNew(QVariant))); + connect(this,SIGNAL(setPath(QVariant)), + rootObject, SLOT(setPath(QVariant))); + + connect(rootObject, SIGNAL(saveButtonClicked()), + this, SLOT(accept())); + connect(rootObject, SIGNAL(downloadButtonClicked()), + this, SLOT(downloadFile())); + connect(rootObject, SIGNAL(browseButtonClicked()), + this, SLOT(selectFile())); + + connect(rootObject, SIGNAL(optimalizeCheckboxChanged(bool)), + this, SLOT(setGenerateCache(bool))); + connect(rootObject, SIGNAL(stripCheckboxChanged(bool)), + this, SLOT(setAccents(bool))); + +#else + cacheToolTip = tr("Optimize for quicker searches (may take some time)"); accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)"); - initializeUI(); - connect(cacheCheckBox, SIGNAL(toggled(bool)), this, SLOT(setGenerateCache(bool))); connect(accentsCheckBox, SIGNAL(toggled(bool)), @@ -60,20 +109,64 @@ XdxfDialog::XdxfDialog(XdxfPlugin *plugin, connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)), this, SLOT(fileDownloaded(QString))); } - connect(confirmButton, SIGNAL(clicked()), this, SLOT(accept())); -} - +#endif -void XdxfDialog::fileDownloaded(QString) { - infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile())); - _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile(); - updateGeometry(); + initializeUI(); } void XdxfDialog::initializeUI() { +#ifndef Q_WS_MAEMO_5 + + if(type != New){ + emit setNew(false); + emit setPlugin(plugin->type().toUpper()); + emit setFrom(plugin->langFrom()); + emit setTo(plugin->langTo()); + emit setDescription(plugin->name()); + emit setInfo(plugin->infoNote()); + } + else{ + emit setNew(true); + connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)), + this, SLOT(fileDownloaded(QString))); + } + + if(!plugin) { + emit setCheckedOptimalize(true); + emit setCheckedStrip(true); +// accentsCheckBox->setEnabled(false); + _generateCache = true; + _accents = true; + _dictionaryFilePath = ""; + } + else if(plugin && plugin->settings()->value("cached") == "true") { + emit setCheckedOptimalize(true); + emit setCheckedStrip(true); +// accentsCheckBox->setEnabled(false); + _generateCache = true; + _accents = true; + } + else { + emit setCheckedOptimalize(false); + _generateCache = false; + if(plugin->settings()->value("strip_accents") == "true") { + emit setCheckedStrip(true); + _accents = true; + } + else { + emit setCheckedStrip(false); + _accents = false; + } + } + if(type == New) + emit setButtonText("Add"); + else + emit setButtonText("Save settings"); + +#else mainVerticalLayout = new QVBoxLayout; widget = new QWidget; widget->setLayout(mainVerticalLayout); @@ -201,17 +294,29 @@ void XdxfDialog::initializeUI() { scrollArea->setLineWidth(0); scrollArea->setMidLineWidth(0); scrollArea->setFrameStyle(QFrame::NoFrame); +#endif } void XdxfDialog::setAccents(bool accents) { + qDebug()<<"setAcents"<setEnabled(!generate); +#else if(generate) { _lastAccents = _accents; accentsCheckBox->setChecked(true); @@ -219,6 +324,7 @@ void XdxfDialog::setGenerateCache(bool generate) { else accentsCheckBox->setChecked(_lastAccents); accentsCheckBox->setEnabled(!generate); +#endif } @@ -230,15 +336,32 @@ void XdxfDialog::selectFile() { NULL, NULL); if (!fileName.isEmpty()) { - infoLabel->setText(tr("Dictionary file: %1").arg(fileName)); _dictionaryFilePath = fileName; - updateGeometry(); + #ifndef Q_WS_MAEMO_5 + emit setPath(tr("Dictionary file: %1").arg(fileName)); + #else + infoLabel->setText(tr("Dictionary file: %1").arg(fileName)); + updateGeometry(); + #endif } } +void XdxfDialog::fileDownloaded(QString) { +#ifndef Q_WS_MAEMO_5 + qDebug()<<"fileDownloaded"; + emit setPath(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile())); + _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile(); +#else + infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile())); + _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile(); + updateGeometry(); +#endif +} + + void XdxfDialog::downloadFile() { - XdxfPlugin::dictDownloader.download(this); + XdxfPlugin::dictDownloader.download(this); } @@ -250,7 +373,6 @@ void XdxfDialog::saveSettings() { } else _settings->setValue("path", _dictionaryFilePath); - if(_generateCache) _settings->setValue("generateCache", "true"); else diff --git a/src/plugins/xdxf/XdxfDialog.h b/src/plugins/xdxf/XdxfDialog.h index 8e031f6..2f1a053 100644 --- a/src/plugins/xdxf/XdxfDialog.h +++ b/src/plugins/xdxf/XdxfDialog.h @@ -32,6 +32,7 @@ #include #include "../../include/settings.h" #include +#include #include "xdxfplugin.h" @@ -82,6 +83,17 @@ Q_SIGNALS: //! Requests to show notification void notify(Notify::NotifyType, QString); + void setPlugin(QVariant name); + void setFrom(QVariant lang); + void setTo(QVariant lang); + void setDescription(QVariant descript); + void setInfo(QVariant info); + void setCheckedOptimalize(QVariant boolean); + void setCheckedStrip(QVariant boolean); + void setButtonText(QVariant text); + void setNew(QVariant text); + void setPath(QVariant path); + public Q_SLOTS: /*! Reimplemented accept method, to check if all necessary fields in @@ -91,6 +103,7 @@ public Q_SLOTS: void accept(); private Q_SLOTS: + //! displays dialog to browse and select file void selectFile(); @@ -115,6 +128,9 @@ private Q_SLOTS: private: + QVBoxLayout* mainLayout; + QDeclarativeView *view; + void initializeUI(); //! saves new settings after acceptance of dialog diff --git a/src/plugins/xdxf/xdxf.pro b/src/plugins/xdxf/xdxf.pro index 79bf8c8..f91a16a 100644 --- a/src/plugins/xdxf/xdxf.pro +++ b/src/plugins/xdxf/xdxf.pro @@ -4,7 +4,9 @@ QT = core \ gui \ xml \ sql \ - network + network\ + declarative + maemo5 { LIBS += -lbz2 \ } @@ -44,15 +46,36 @@ HEADERS += xdxfplugin.h \ RESOURCES += xdxf.qrc TRANSLATIONS += pl_PL.ts \ en_US.ts -unix { - INSTALLS += dicts \ - plugin-icon +OTHER_FILES += \ + ../../mdictionary/qml/XdxfDialog.qml + + +unix { dicts.path = $$PLUGINS_DIR dicts.files += ../../../data/dicts/eng-us.xdxf dicts.files += ../../../data/dicts/eng-thai.xdxf plugin-icon.path = $$DATA_DIR plugin-icon.files += xdxf.png + + meego { + qmls.path = $$DATA_DIR/qml + qmls.files += ../../mdictionary/qml/XdxfDialog.qml + } + else:maemo5 { + qmls.path = $$DATA_DIR/qml + qmls.files += ../../mdictionary/qml/XdxfDialog.qml + } + else { + qmls.path = $$DATA_DIR/qml + qmls.files += ../../mdictionary/qml/XdxfDialog.qml + } + + INSTALLS += dicts \ + plugin-icon\ + qmls } check.commands = echo \ 'No check here' QMAKE_EXTRA_TARGETS += check + +