--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file ComboBoxModel.cpp
+ \brief Contains data for ComboBox QML component
+
+ \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
+#include "ComboBoxModel.h"
+
+ComboBoxModel::ComboBoxModel(QList<QString> contents, QObject *parent) :
+ QAbstractListModel(parent)
+{
+ QHash<int, QByteArray> roles;
+ roles[ContentRole] = "content";
+ roles[NumberRole] = "number";
+ setRoleNames(roles);
+
+ setContents(contents);
+}
+
+int ComboBoxModel::rowCount(const QModelIndex &parent) const
+{
+ return _contents.count();
+}
+
+QVariant ComboBoxModel::data(const QModelIndex &index, int role) const
+{
+ if (index.row() < 0 || index.row() > _contents.count())
+ return QVariant();
+
+ QString item = _contents[index.row()];
+ if (role == ContentRole)
+ return item;
+ if (role == NumberRole)
+ return index.row();
+ return QVariant();
+}
+
+QString ComboBoxModel::selectedItem()
+{
+ return _selectedItem;
+}
+
+int ComboBoxModel::selectedIndex()
+{
+ return _selectedIndex;
+}
+
+void ComboBoxModel::setSelectedItem(QString item)
+{
+ _selectedItem = item;
+}
+
+void ComboBoxModel::setSelectedIndex(int index)
+{
+ _selectedIndex = index;
+}
+
+void ComboBoxModel::setContents(QList<QString> contents)
+{
+ foreach (QString item, contents)
+ {
+ addItem(item);
+ }
+}
+
+void ComboBoxModel::addItem(QString item)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ _contents << item;
+ endInsertRows();
+}
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file ComboBoxModel.h
+ \brief Contains data for ComboBox QML component
+
+ \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
+
+#ifndef COMBOBOXMODEL_H
+#define COMBOBOXMODEL_H
+
+#include <QAbstractListModel>
+#include <QList>
+#include <QHash>
+
+/*!
+ Contains a list of string values.
+ Data source for qml ComboBox
+*/
+class ComboBoxModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum ComboBoxRoles
+ {
+ ContentRole = Qt::UserRole + 1,
+ NumberRole
+ };
+
+ //! Constructor
+ /*!
+ \param contents list of elements for ComboBox
+ \param parent parent of this class.
+ */
+ explicit ComboBoxModel(QList<QString> contents, QObject *parent = 0);
+
+ int rowCount(const QModelIndex & parent = QModelIndex()) const;
+
+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+
+ QString selectedItem();
+ int selectedIndex();
+ void setSelectedItem(QString item);
+ void setSelectedIndex(int index);
+
+private:
+ void setContents(QList<QString> contents);
+ void addItem(QString item);
+ QList<QString> _contents;
+ QString _selectedItem;
+ int _selectedIndex;
+
+};
+
+#endif // COMBOBOXMODEL_H
gui/DictTypeModel.cpp \
gui/DictManagerModel.cpp \
gui/HistoryListModel.cpp \
- gui/WordListModel.cpp
+ gui/WordListModel.cpp \
+ ../include/ComboBoxModel.cpp
HEADERS += gui/MainWindow.h \
backbone/ConfigGenerator.h \
gui/DictManagerModel.h \
gui/DictManagerWidget.h \
gui/HistoryListModel.h \
- gui/WordListModel.h
+ gui/WordListModel.h \
+ ../include/ComboBoxModel.h
RESOURCES += ../../data/gui.qrc
id: rectangle1
radius: 10
border.color: "#000666";
-// property int maxValue:500;
-// property int minValue:0;
property alias value:text1.text
+ property alias index: list1.currentIndex
+ property alias model: list1.model
property bool expanded: false
+ property bool disabled: false
+ property int expandedHeight
+ property int basicHeight
+ property string startValue
+ height: basicHeight
function show(Boolean){
- //mozna jeszcze to w tle ukrywać
expanded = Boolean
}
- signal valueSelected(string selected); //?
-
-// function stringToInt(string){
-// var value=0;
-// var pow10=1;
-// for (var i=string.length-1;i>=0;i--){
-// value+=(string.charCodeAt(i)-48)*pow10;
-// pow10= pow10*10;
-// }
-// if(value>maxValue)
-// return maxValue;
-// if(value<minValue)
-// return minValue;
-// return value;
-// }
+ function setStartValue(val, idx){
+ startValue = val
+ list1.currentIndex = idx
+ }
+
+ signal valueSelected(string selected);
Text {
id: text1
- x: 1
width: rectangle1.width-15
height: rectangle1.height*0.6;
text: list1.selected
anchors.centerIn: parent
font.pixelSize: rectangle1.height * .5;
- onTextChanged: {} //stub, tu reakcja na zmianę wyboru z listy
+ onTextChanged: { rectangle1.valueSelected(text) }
}
-// TextInput {
-// id: text_input1
-// x: 1
-// width: rectangle1.width-15
-// height: rectangle1.height*0.6;
-// text: "123"
-// anchors.centerIn: parent
-// validator: IntValidator{bottom: minValue; top: maxValue;}
-// transformOrigin: Item.Left
-// selectByMouse: true;
-// font.pixelSize: rectangle1.height * .5;
-// onCursorPositionChanged: moveCursorSelection(cursorPosition);
-// onTextChanged: rectangle1.valueChange(stringToInt(text_input1.text));
-// onFocusChanged: {
-// if(focus==false)
-// text=stringToInt(text);
-// }
-// }
-
Rectangle {
id: shadeDisable
width: parent.width;
anchors.centerIn: parent;
radius: parent.radius
color: "grey";
- opacity: 0
- }
-
- Image {
- id: imageUp
- z:4;
- width: 11;
- height: 6;
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.rightMargin: 2
- anchors.topMargin: 2
- source: "qrc:/button/up_enable.png";
+ opacity: 0.5
}
Image {
id: imageDown
z:4;
width: 11;
- height: 6;
+ height: 0.5 * rectangle1.height;
+ anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
- anchors.rightMargin: 2
- anchors.bottomMargin: 2
+ anchors.topMargin: 4
+ anchors.rightMargin: 6
+ anchors.bottomMargin: 4
source: "qrc:/button/down_enable.png";
}
width: parent.width
visible: false
z: 0
- property string selected: startValue//inicjowane z cpp
+ property string selected: rectangle1.startValue
function selectedValue(nr, value) {
currentIndex = nr
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
highlightResizeSpeed: 1000
- model: comboBoxModel
delegate: Component{
id: list1Delegate
states: [
State {
name: "basic";
- when: rectangle1.expanded = false
+ when: (rectangle1.expanded == false && rectangle1.disabled == false)
PropertyChanges { target: list1; z: 0; visible: false }
- PropertyChanges {target: listMouseArea; z: 1 }
+ PropertyChanges { target: text1; z: 0; visible: true }
+ PropertyChanges { target: rectangle1; border.width: 1}
+ PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
+ PropertyChanges { target: imageDown; visible: true}
+ PropertyChanges { target: shadeDisable; visible: false; z:-1}
},
State {
name: "expanded"
- when: rectangle1.expanded = true
+ when: (rectangle1.expanded == true && rectangle1.disabled == false)
PropertyChanges { target: list1; z: 10; visible: true }
- PropertyChanges {target: listMouseArea; z: 11 }
+ PropertyChanges { target: text1; z: 10; visible: false }
+ PropertyChanges { target: rectangle1; border.width: 0}
+ PropertyChanges { target: rectangle1; height: rectangle1.expandedHeight}
+ PropertyChanges { target: imageDown; visible: false}
+ PropertyChanges { target: shadeDisable; visible: false; z: -1}
+ },
+ State {
+ name: "disabled";
+ when: rectangle1.disabled == true
+ PropertyChanges { target: list1; z: 0; visible: false }
+ PropertyChanges { target: text1; z: 0; visible: true }
+ PropertyChanges { target: rectangle1; border.width: 1}
+ PropertyChanges { target: rectangle1; expanded: false}
+ PropertyChanges { target: rectangle1; height: rectangle1.basicHeight}
+ PropertyChanges { target: imageDown; visible: true}
+ PropertyChanges { target: shadeDisable; visible: true; z:10}
}
]
--- /dev/null
+import Qt 4.7
+
+Rectangle{
+ property bool newPlugin:false;
+
+ function setInfo(string){
+ infoLabel.text = string;
+ }
+ function setStartValues(startFrom, startTo, startFromIndex, startToIndex){
+ comboFrom.setStartValue(startFrom, startFromIndex)
+ comboTo.setStartValue(startTo, startToIndex)
+ }
+ function revertLang(){
+ var tmpidx = comboFrom.index
+ comboFrom.index = comboTo.index
+ comboTo.index = tmpidx
+
+ var tmpval = comboFrom.value
+ comboFrom.value = comboTo.value
+ comboTo.value = tmpval
+ }
+
+ function setNew(bool){
+ newPlugin=bool;
+ }
+
+ signal saveButtonClicked(string langFrom, string langTo);
+
+ height: infoLabel.height + fromLabel.height + toLabel.height + saveButton.height + 50
+ width: 200
+
+ id:rectangle1
+
+
+
+ SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
+ color : myPalette.window;
+
+
+ Text {
+ id: infoLabel
+ height: paintedHeight+5;
+ anchors.right: parent.right
+ anchors.left: parent.left
+ anchors.top: parent.top
+ wrapMode: Text.Wrap;
+ transformOrigin: Item.Left
+ font.pixelSize: 12
+ z: 15
+ }
+
+ Text {
+ id: fromLabel
+ text: qsTr("From: ")
+ height: paintedHeight+5;
+ anchors.top: infoLabel.bottom
+ anchors.left: parent.left
+ wrapMode: Text.Wrap;
+ transformOrigin: Item.Left
+ font.pixelSize: 12
+ }
+
+ Text {
+ id: toLabel
+ text: qsTr("To: ")
+ height: paintedHeight+5;
+ anchors.top: fromLabel.bottom
+ anchors.left: parent.left
+ wrapMode: Text.Wrap;
+ transformOrigin: Item.Left
+ font.pixelSize: 12
+ }
+
+ ComboBox{
+ id: comboFrom
+ model: comboBoxModel
+ anchors.left: parent.left
+ anchors.leftMargin: {
+ if (fromLabel.width < 30 && toLabel.width < 30){
+ return 30
+ }
+ else if (fromLabel.width > toLabel.width){
+ return fromLabel.width + 10
+ }
+ else {
+ return toLabel.width + 10
+ }
+ }
+
+ anchors.top: infoLabel.bottom
+ anchors.right: revertButton.left
+ anchors.rightMargin: 10
+ expanded: false
+ basicHeight: fromLabel.height
+ expandedHeight: parent.height - comboFrom.x - saveButton.height -20
+ }
+
+ ComboBox{
+ id: comboTo
+ model: comboBoxModel
+ anchors.left: parent.left
+ anchors.leftMargin: {
+ if (fromLabel.width < 30 && toLabel.width < 30){
+ return 30
+ }
+ else if (fromLabel.width > toLabel.width){
+ return fromLabel.width + 10
+ }
+ else {
+ return toLabel.width + 10
+ }
+ }
+
+ anchors.right: revertButton.left
+ anchors.rightMargin: 10
+ anchors.top: comboFrom.bottom
+ expanded: false
+ basicHeight: fromLabel.height
+ expandedHeight: parent.height - comboTo.x - saveButton.height - 20 - fromLabel.height
+ }
+
+ IconButton{
+ id: revertButton
+ width: height
+ height: fromLabel.height
+ anchors.top: fromLabel.top
+ anchors.topMargin: fromLabel.height /2
+ anchors.right: parent.right
+// pathToIcon: //gimp again, ech
+ pathToIcon: "qrc:/button/up_enable.png"; //temp
+ onClicked: { rectangle1.revertLang() }
+ }
+
+ Button {
+ id: saveButton
+ height: 30
+ z: 1
+ anchors.bottom: parent.bottom
+ anchors.right: parent.right
+ anchors.left: parent.left
+ onClicked: {
+ rectangle1.saveButtonClicked(comboFrom.value, comboTo.value);
+ }
+ }
+
+ states: [
+ State {
+ name: "new"
+ when: newPlugin==true
+ PropertyChanges { target: saveButton; textInButton: qsTr("Add") }
+ },
+ State {
+ name: "edit"
+ when: newPlugin==false
+ PropertyChanges { target: saveButton; textInButton: qsTr("Save settings") }
+ }
+ ]
+}
+
this->plugin = plugin;
this->type = type;
_settings = 0;
+ _actualLangFrom = 0;
+ _actualLangTo = 0;
if(plugin) {
_langTo=GooglePlugin::languages.key(
_langFrom=GooglePlugin::languages.key("en");
}
- initializeUI();
-
+#ifdef Q_WS_MAEMO_5
connect(confirmButton, SIGNAL(clicked()),
this, SLOT(accept()));
connect(changeLangButton, SIGNAL(clicked()),
this, SLOT(changeLangButtonClicked()));
+#else
+
+ int i=0,j=0;
+ int actualLangTo=0;
+ int actualLangFrom=0;
+
+ QList<QString> langList;
+ foreach(QString langs, GooglePlugin::languages.keys()){
+ if(langs==_langTo)
+ actualLangTo=j;
+ if(langs==_langFrom)
+ actualLangFrom=i;
+ if(langs!="Detect langlage"){
+ langList.append(langs);
+ j++;
+ }
+ i++;
+ }
+
+ _actualLangFrom = actualLangFrom;
+ _actualLangTo = actualLangTo;
+ model = new ComboBoxModel(langList);
+
+ view= new QDeclarativeView();
+ ctxt = view->rootContext();
+ ctxt->setContextProperty("comboBoxModel", &(*model));
+ view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/GoogleDialog.qml"));
+ view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+ //view->setAlignment(Qt::AlignCenter);
+ view->show();
+
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(view);
+ setLayout(mainLayout);
+ view->setWindowTitle(tr("Google Settings"));
+
+ QGraphicsObject *rootObject = view->rootObject();
+
+ connect(rootObject, SIGNAL(saveButtonClicked(QString, QString)),
+ this, SLOT(saveButtonClicked(QString,QString)));
+
+ connect(this, SIGNAL(setInfo(QVariant)),
+ rootObject, SLOT(setInfo(QVariant)));
+ connect(this,SIGNAL(setNew(QVariant)),
+ rootObject, SLOT(setNew(QVariant)));
+ connect(this,SIGNAL(setStartValues(QVariant,QVariant,QVariant,QVariant)),
+ rootObject, SLOT(setStartValues(QVariant, QVariant, QVariant, QVariant)));
+
+#endif
+
+ initializeUI();
}
void GoogleDialog::initializeUI() {
+#ifndef Q_WS_MAEMO_5
+
+ setWindowTitle(tr("Google Plugin Settings"));
+ if (type != New){
+ emit setNew(false);
+ QString info=tr("Plugin: ") + plugin->type().toUpper() +"\n" +
+ tr("From: ") + _langFrom + "\n" +
+ tr("To: ") + _langTo;
+ emit setInfo(info);
+ }
+ else{
+ emit setNew(true);
+ }
+ emit setStartValues(_langFrom, _langTo, _actualLangFrom, _actualLangTo);
+
+// setMinimumSize(sizeHint());
+
+
+#else
+
int i=0,j=0;
int actualLangTo=0;
int actualLangFrom=0;
setModal(true);
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
+#endif
}
}
}
-
+#ifdef Q_WS_MAEMO_5
void GoogleDialog::accept() {
saveSettings();
QDialog::accept();
GooglePlugin::languages.value(_langFrom));
}
+#else
+void GoogleDialog::saveButtonClicked(QString langFrom, QString langTo){
+ saveSettings(langFrom, langTo);
+ QDialog::accept();
+}
+
+void GoogleDialog::saveSettings(QString langFrom, QString langTo){
+ _settings = new Settings;
+ _langFrom = langFrom;
+ _langTo = langTo;
+ if(plugin) {
+ foreach(QString key, plugin->settings()->keys())
+ _settings->setValue(key, plugin->settings()->value(key));
+ }
+
+ _settings->setValue("lang_to",
+ GooglePlugin::languages.value(langTo));
+ _settings->setValue("lang_from",
+ GooglePlugin::languages.value(langFrom));
+}
+#endif
Settings* GoogleDialog::getSettings() {
return _settings;
#include <QDialog>
#include "../../include/settings.h"
+#include "../../include/ComboBoxModel.h"
#include <QtGui>
+
+
#include <QDeclarativeView>
+#include <QDeclarativeContext>
+#include <QList>
#include "GooglePlugin.h"
//! requests to show notification
void notify(Notify::NotifyType, QString);
+#ifndef Q_WS_MAEMO_5
+ void setInfo(QVariant info);
+ void setNew(QVariant text);
+ void setStartValues(QVariant from, QVariant to, QVariant fromIndex, QVariant toIndex);
+#endif
+
public Q_SLOTS:
+#ifdef Q_Ws_MAEMO_5
//! reimplemented accept method, to save new settings
void accept();
+#endif
private Q_SLOTS:
//! assigns the language chosen from a list(langFromComboBox) to _langFrom
//! handles the "swap languages" button
void changeLangButtonClicked();
+
+#ifndef Q_Ws_MAEMO_5
+ void saveButtonClicked(QString langFrom, QString langTo);
+#endif
+
private:
- QVBoxLayout* mainLayout;
- QDeclarativeView *view;
void initializeUI();
//! saves new settings after acceptance of dialog
+#ifdef Q_Ws_MAEMO_5
void saveSettings();
+#else
+ void saveSettings(QString langFrom, QString langTo);
+
+ ComboBoxModel* model;
+ QVBoxLayout* mainLayout;
+ QDeclarativeView *view;
+ QDeclarativeContext* ctxt;
+#endif
+
+ int lastHeight;
QLabel* infoLabel;
QLabel* langFromLabel;
QHBoxLayout* changeLangLayout;
QString _langFrom;
QString _langTo;
+ int _actualLangTo;
+ int _actualLangFrom;
Settings* _settings;
GooglePlugin* plugin;
GooglePlugin.cpp \
TranslationGoogle.cpp \
GoogleDictDialog.cpp \
- GoogleDialog.cpp
+ GoogleDialog.cpp \
+ ../../include/ComboBoxModel.cpp
HEADERS += \
GooglePlugin.h \
../../include/translation.h \
../../include/settings.h \
../../include/CommonDictInterface.h \
+ ../../include/ComboBoxModel.h \
TranslationGoogle.h \
GoogleDictDialog.h \
GoogleDialog.h
}
check.commands = echo 'No check here'
QMAKE_EXTRA_TARGETS += check
+
+OTHER_FILES += \
+ ../../mdictionary/qml/GoogleDialog.qml