From: jakub Date: Fri, 18 Feb 2011 14:28:01 +0000 (+0100) Subject: bi change + completer in line edit X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=cd6d19c3e9a71f2e19d13beaf119554905803a12;p=mdictionary bi change + completer in line edit --- diff --git a/data/button/buttonCenterDisabled.png b/data/button/buttonCenterDisabled.png index 2621381..58203c0 100644 Binary files a/data/button/buttonCenterDisabled.png and b/data/button/buttonCenterDisabled.png differ diff --git a/data/button/buttonCenterPushed.png b/data/button/buttonCenterPushed.png index 58203c0..2621381 100644 Binary files a/data/button/buttonCenterPushed.png and b/data/button/buttonCenterPushed.png differ diff --git a/data/button/buttonLeftDisabled.png b/data/button/buttonLeftDisabled.png index ef89fb8..976abd6 100644 Binary files a/data/button/buttonLeftDisabled.png and b/data/button/buttonLeftDisabled.png differ diff --git a/data/button/buttonLeftPushed.png b/data/button/buttonLeftPushed.png index 976abd6..ef89fb8 100644 Binary files a/data/button/buttonLeftPushed.png and b/data/button/buttonLeftPushed.png differ diff --git a/data/button/buttonRightDisabled.png b/data/button/buttonRightDisabled.png index db3fc2b..30206c5 100644 Binary files a/data/button/buttonRightDisabled.png and b/data/button/buttonRightDisabled.png differ diff --git a/data/button/buttonRightPushed.png b/data/button/buttonRightPushed.png index 30206c5..db3fc2b 100644 Binary files a/data/button/buttonRightPushed.png and b/data/button/buttonRightPushed.png differ diff --git a/data/button/checkboxCheckedDis.png b/data/button/checkboxCheckedDis.png new file mode 100644 index 0000000..33472af Binary files /dev/null and b/data/button/checkboxCheckedDis.png differ diff --git a/data/button/checkboxDis.png b/data/button/checkboxDis.png new file mode 100644 index 0000000..a5b8e5c Binary files /dev/null and b/data/button/checkboxDis.png differ diff --git a/data/button/down_enable.png b/data/button/down_enable.png index 8cae783..0bbb98b 100644 Binary files a/data/button/down_enable.png and b/data/button/down_enable.png differ diff --git a/data/button/down_enable2.png b/data/button/down_enable2.png new file mode 100644 index 0000000..44d756a Binary files /dev/null and b/data/button/down_enable2.png differ diff --git a/data/button/up_enable.png b/data/button/up_enable.png index a82da53..63db5dd 100644 Binary files a/data/button/up_enable.png and b/data/button/up_enable.png differ diff --git a/data/button/up_enable2.png b/data/button/up_enable2.png new file mode 100644 index 0000000..0f8a4f4 Binary files /dev/null and b/data/button/up_enable2.png differ diff --git a/data/gui.qrc b/data/gui.qrc index 7ee2d8f..2890e96 100644 --- a/data/gui.qrc +++ b/data/gui.qrc @@ -30,5 +30,7 @@ button/up_enable.png button/down_enable.png button/revert.png + button/checkboxCheckedDis.png + button/checkboxDis.png diff --git a/src/include/ComboBoxModel.cpp b/src/include/ComboBoxModel.cpp index 56e5dfe..56963e1 100644 --- a/src/include/ComboBoxModel.cpp +++ b/src/include/ComboBoxModel.cpp @@ -34,7 +34,6 @@ ComboBoxModel::ComboBoxModel(QList contents, QObject *parent) : roles[ContentRole] = "content"; roles[NumberRole] = "number"; setRoleNames(roles); - setContents(contents); } diff --git a/src/mdictionary/gui/SearchBarWidget.cpp b/src/mdictionary/gui/SearchBarWidget.cpp index 9dc1450..338b87a 100644 --- a/src/mdictionary/gui/SearchBarWidget.cpp +++ b/src/mdictionary/gui/SearchBarWidget.cpp @@ -33,7 +33,13 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { - qDebug()<<"test1"; + + completerModel = new QStringList; + lineEditCompleter = new QCompleter(this); + lineEditCompleter->setModel(new QStringListModel(*completerModel)); + lineEditCompleter->setCaseSensitivity(Qt::CaseInsensitive); + lineEditCompleter->setCompletionMode(QCompleter::InlineCompletion); + #ifndef Q_WS_MAEMO_5 this->setMaximumHeight(50); busyTimer=new QTimer; @@ -45,6 +51,8 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { progressBar->hide(); view= new QDeclarativeView(); + ctxt = view->rootContext(); + view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/SearchBarWidget.qml")); view->setResizeMode(QDeclarativeView::SizeRootObjectToView); view->setAlignment(Qt::AlignCenter); @@ -66,6 +74,12 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { this, SIGNAL(historyPrev())); connect(rootObject, SIGNAL(historyShowToolButtonClicked()), this, SLOT(showHistoryButtonClicked())); + connect(rootObject, SIGNAL(textChange(QString)), + this, SLOT(textChange(QString))); + connect(rootObject, SIGNAL(nextCompleter()), + this, SLOT(nextCompleter())); + connect(rootObject, SIGNAL(prevCompleter()), + this, SLOT(prevCompleter())); connect(this, SIGNAL(progresSetMax(QVariant)), rootObject2, SLOT(setMax(QVariant))); @@ -89,6 +103,9 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { connect(this, SIGNAL(setLineEditEnables(QVariant)), rootObject, SLOT(setEnableLineEdit(QVariant))); + connect(this, SIGNAL(setCompleterText(QVariant)), + rootObject, SLOT(setCompleterText(QVariant))); + connect(busyTimer, SIGNAL(timeout()), this, SLOT(updateBusyTimer())); @@ -96,7 +113,6 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { emit setEnableHistoryShow(false); emit setEnableHistoryPrev(false); - completerModel = new QStringListModel(this); connect(&delayTimer, SIGNAL(timeout()), this, SLOT(delaySearchTimeout())); @@ -119,7 +135,6 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { connect(&delayTimer, SIGNAL(timeout()), this, SLOT(delaySearchTimeout())); - searchWordLineEdit->setFocus(); #endif @@ -132,6 +147,71 @@ SearchBarWidget::~SearchBarWidget() { } +void SearchBarWidget::textChange(QString text){ + QLineEdit line; + QString toSend=""; + QString tempString; + actualString=text; + completerActualList.clear(); + + line.setCompleter(lineEditCompleter); + line.completer()->setCompletionPrefix(text); + for (int i = 0; lineEditCompleter->setCurrentRow(i); i++) + completerActualList.append(lineEditCompleter->currentCompletion()); + + completerActualList.sort(); + if(completerActualList.contains(preferedCompliter)){ + tempString = preferedCompliter; + toSend = tempString.remove(0,text.size()); + emit setCompleterText(toSend); + } + else if(completerActualList.size()>0 && text.size()>0){ + toSend = completerActualList.at(0); + preferedCompliter= toSend; + toSend=toSend.remove(0,text.size()); + if(toSend.size()>0) + emit setCompleterText(toSend); + else if(completerActualList.size()>1){ + toSend = completerActualList.at(1); + preferedCompliter= toSend; + toSend=toSend.remove(0,text.size()); + emit setCompleterText(toSend); + } + } + else{ + preferedCompliter=""; + emit setCompleterText(toSend); + } +} + +void SearchBarWidget::prevCompleter(){ + QString tempString; + if(!preferedCompliter.isEmpty()){ + int index = completerActualList.indexOf(preferedCompliter); + qDebug()<<"index"<index+1){ + preferedCompliter = completerActualList.at(index+1); + tempString=preferedCompliter; + QString toSend = tempString.remove(0,actualString.size()); + emit setCompleterText(toSend); + } + } +} + +void SearchBarWidget::nextCompleter(){ + QString tempString; + if(!preferedCompliter.isEmpty()){ + int index = completerActualList.indexOf(preferedCompliter); + if(index>0){ + preferedCompliter = completerActualList.at(index-1); + tempString=preferedCompliter; + QString toSend = tempString.remove(0,actualString.size()); + emit setCompleterText(toSend); + } + } +} + + QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) { qDebug()<<"test2"; QPixmap p = original.pixmap(64); @@ -192,12 +272,6 @@ void SearchBarWidget::initializeUI() { searchWordLineEdit = new QLineEdit; searchWordLineEdit->setMinimumWidth(250); - completerModel = new QStringListModel(this); - - lineEditCompleter = new QCompleter(searchWordLineEdit); - lineEditCompleter->setModel(completerModel); - lineEditCompleter->setCaseSensitivity(Qt::CaseInsensitive); - lineEditCompleter->setCompletionMode(QCompleter::InlineCompletion); searchWordLineEdit->setCompleter(lineEditCompleter); #ifndef Q_WS_MAEMO_5 @@ -306,13 +380,14 @@ void SearchBarWidget::searchPushButtonClicked() { } void SearchBarWidget::search(QString word) { - qDebug()<<"test7"; - qDebug()<insertRow(completerModel->rowCount()); - QModelIndex index=completerModel->index(completerModel->rowCount() -1); - completerModel->setData(index, word); - + while(word.lastIndexOf(" ")==word.size()-1 && word.size()>0) + word=word.remove(word.size()-1,1); + if(!completerModel->contains(word)) + completerModel->append(word); + QAbstractItemModel *temp=lineEditCompleter->model(); + lineEditCompleter->setModel(new QStringListModel(*completerModel)); + delete temp; #ifndef Q_WS_MAEMO_5 emit setLineEditText(word); #else diff --git a/src/mdictionary/gui/SearchBarWidget.h b/src/mdictionary/gui/SearchBarWidget.h index 427eb53..0e84bee 100644 --- a/src/mdictionary/gui/SearchBarWidget.h +++ b/src/mdictionary/gui/SearchBarWidget.h @@ -60,6 +60,7 @@ Q_SIGNALS: void progresSetMin(QVariant); void progresSetValue(QVariant); void progresSetValue2(QVariant); + void setCompleterText(QVariant); //! Requests to search for a list of words matching a word passed as //! a parameter @@ -148,6 +149,11 @@ private Q_SLOTS: //! shows history void showHistoryButtonClicked(); + void textChange(QString text); + + void nextCompleter(); + + void prevCompleter(); private: @@ -156,10 +162,14 @@ private: QDeclarativeView *progressBar; QTimer *busyTimer; bool progressMax; + QDeclarativeContext *ctxt; + QStringList* completerModel; + QCompleter* lineEditCompleter; + QString preferedCompliter; + QString actualString; + QStringList completerActualList; QLineEdit* searchWordLineEdit; - QCompleter* lineEditCompleter; - QStringListModel* completerModel; QToolButton* clearSearchWordToolButton; QPushButton* searchPushButton; QToolButton* historyPrevToolButton; diff --git a/src/mdictionary/qml/AboutWidget.qml b/src/mdictionary/qml/AboutWidget.qml index a600d1b..92c6d07 100644 --- a/src/mdictionary/qml/AboutWidget.qml +++ b/src/mdictionary/qml/AboutWidget.qml @@ -52,13 +52,4 @@ Rectangle { anchors.horizontalCenterOffset: 0 onLinkActivated: linkClicked(link); } - - /* MySpinBox { - id: test01 - y:20; - x:20; - width: 40 - height: 20; - } - */ } diff --git a/src/mdictionary/qml/Button.qml b/src/mdictionary/qml/Button.qml index 831e007..dd94a40 100644 --- a/src/mdictionary/qml/Button.qml +++ b/src/mdictionary/qml/Button.qml @@ -3,8 +3,14 @@ import Qt 4.7 BorderImage { id: button property alias textInButton: buttonText.text - signal clicked - opacity: 1 + property bool checkable: false + property bool checked: false + + height: 20; + width: 60; + + signal clicked; + signal changeCheck; function setText(string) { textInButton = qsTr(string); } function press() { mouseArea.pressed } @@ -17,13 +23,19 @@ BorderImage { height: parent.height; onClicked: { button.clicked(); + if(checkable){ + button.checked=!button.checked; + button.changeCheck(); + } } } Text { z:1 id: buttonText + width: parent.width; anchors.centerIn: parent; + horizontalAlignment: Text.AlignHCenter font.pixelSize: parent.height * .5 elide: Text.ElideRight; style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true @@ -31,7 +43,7 @@ BorderImage { Image { id: image1 - width: (35*parent.height)/107 +1 + width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 //(35*parent.height)/107 +1 height: parent.height anchors.left: parent.left source: "qrc:/button/buttonLeft.png" @@ -54,7 +66,7 @@ BorderImage { Image { id: image2 smooth: true - width: (35*parent.height)/107 +1 + width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1//(35*parent.height)/107 +1 height: parent.height anchors.right: parent.right source: "qrc:/button/buttonR.png" @@ -64,7 +76,7 @@ BorderImage { states: [ State { name: "pressed"; - when: (mouseArea.pressed == true && button.enabled == true); + when: ((button.enabled) && (mouseArea.pressed || (button.checkable && button.checked) ) ) PropertyChanges { target: image1; source: "qrc:/button/buttonLeftPushed.png" } PropertyChanges { target: image3; source: "qrc:/button/buttonCenterPushed.png" } diff --git a/src/mdictionary/qml/Checkbox.qml b/src/mdictionary/qml/Checkbox.qml index 3ef0fc3..7e96512 100644 --- a/src/mdictionary/qml/Checkbox.qml +++ b/src/mdictionary/qml/Checkbox.qml @@ -29,6 +29,8 @@ Image { property bool selected property string pathToCheckedImage: "qrc:/button/checkboxChecked.png" property string pathToUncheckedImage: "qrc:/button/checkbox.png" + property string pathToCheckedDicImage: "qrc:/button/checkboxCheckedDis.png" + property string pathToUncheckedDicImage: "qrc:/button/checkboxDis.png" signal changed height: { var aspectRatio = sourceSize.height / sourceSize.width @@ -38,24 +40,38 @@ Image { smooth: true states: [ State { - name: "checked"; - when: (checkbox.selected == true); + name: "checkeEn"; + when: (checkbox.selected && checkbox.enabled); PropertyChanges { target: checkbox; source: pathToCheckedImage } }, State { - name: "unchecked"; - when: (checkbox.selected == false); + name: "uncheckeEn"; + when: ( !checkbox.selected && checkbox.enabled); PropertyChanges { target: checkbox; source: pathToUncheckedImage } + }, + State { + name: "checkeDi"; + when: (checkbox.selected && !checkbox.enabled); + + PropertyChanges { target: checkbox; source: pathToCheckedDicImage } + }, + State { + name: "uncheckeDi"; + when: ( !checkbox.selected && !checkbox.enabled); + + PropertyChanges { target: checkbox; source: pathToUncheckedDicImage } } ] MouseArea{ id: area anchors.fill: parent onClicked: { - checkbox.selected = !checkbox.selected - changed() + if(checkbox.enabled){ + checkbox.selected = !checkbox.selected + changed() + } } } } diff --git a/src/mdictionary/qml/ComboBox.qml b/src/mdictionary/qml/ComboBox.qml index b863e3c..b20aa0f 100644 --- a/src/mdictionary/qml/ComboBox.qml +++ b/src/mdictionary/qml/ComboBox.qml @@ -12,7 +12,9 @@ Rectangle { property int expandedHeight property int basicHeight property string startValue - height: basicHeight + height: 20 + + property variant parentField : rectangle1 function show(Boolean){ expanded = Boolean @@ -77,9 +79,7 @@ Rectangle { ElementsListView{ id: list1 - width: parent.width visible: false - z: 0 property string selected: rectangle1.startValue function selectedValue(nr, value) { @@ -88,10 +88,13 @@ Rectangle { rectangle1.show(false) } - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - highlightResizeSpeed: 1000 + anchors.rightMargin: 5 + anchors.leftMargin: 5 + anchors.bottomMargin: 10 + anchors.topMargin: 10 + anchors.fill: parent + highlightResizeSpeed: 1000 delegate: Component{ id: list1Delegate Item { @@ -118,6 +121,7 @@ Rectangle { id: contentText anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: 5 + elide: Text.ElideRight; text: content } } @@ -142,10 +146,11 @@ Rectangle { when: (rectangle1.expanded == true && rectangle1.disabled == false) PropertyChanges { target: list1; z: 10; visible: true } PropertyChanges { target: text1; z: 10; visible: false } - PropertyChanges { target: rectangle1; border.width: 0} + PropertyChanges { target: rectangle1; border.width: 1} PropertyChanges { target: rectangle1; height: rectangle1.expandedHeight} PropertyChanges { target: imageDown; height: 0.5 * rectangle1.basicHeight} PropertyChanges { target: shadeDisable; visible: false; z: -1} + PropertyChanges { target: rectangle1; anchors.fill: parentField} }, State { name: "disabled"; diff --git a/src/mdictionary/qml/GoogleDialog.qml b/src/mdictionary/qml/GoogleDialog.qml index 13e9526..d27cec6 100644 --- a/src/mdictionary/qml/GoogleDialog.qml +++ b/src/mdictionary/qml/GoogleDialog.qml @@ -26,12 +26,185 @@ Rectangle{ signal saveButtonClicked(string langFrom, string langTo); + + id:rectangle1 height: infoLabel.height + fromLabel.height + toLabel.height + saveButton.height + 50 width: 200 + color : myPalette.window; - id:rectangle1 + SystemPalette { + id: myPalette; + colorGroup:SystemPalette.Active + } + + Item { + id: comboField + anchors.bottomMargin: 6 + anchors.rightMargin: 0 + anchors.left: fromLabel.right + anchors.right: revertButton.left + anchors.bottom: saveButton.top + anchors.top: parent.top + anchors.leftMargin: 2 + z:2; + } + + 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 + } + + + 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: ") + anchors.topMargin: 3 + 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.right: revertButton.left + anchors.rightMargin: 5 + anchors.left: fromLabel.right + anchors.leftMargin: 10 + anchors.verticalCenter: fromLabel.verticalCenter + + parentField: comboField + expanded: false + basicHeight: fromLabel.height + onExpandedChanged: { + if(expanded==true) + z=2; + else + z=0; + } + } + + ComboBox{ + id: comboTo + model: comboBoxModel + anchors.right: revertButton.left + anchors.rightMargin: 5 + anchors.left: fromLabel.right + anchors.leftMargin: 10 + anchors.verticalCenter: toLabel.verticalCenter + + parentField: comboField; + expanded: false + basicHeight: fromLabel.height + + onExpandedChanged: { + if(expanded==true) + z=2; + else + z=0; + } + } + + IconButton{ + id: revertButton + width: height + height: fromLabel.height + anchors.top: fromLabel.bottom + anchors.topMargin: -8 + anchors.right: parent.right + pathToIcon: "qrc:/button/revert.png" + onClicked: { rectangle1.revertLang() } + } + + Button { + id: saveButton + height: 30 + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.left: parent.left + onClicked: { + rectangle1.saveButtonClicked(comboFrom.value, comboTo.value); + } + } + + MouseArea { + id: mouse_area1 + anchors.fill: parent + z:-1 + onClicked: { + comboTo.expanded=false; + comboFrom.expanded=false; + } + } + + + + 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") } + } + ] +} + + +/* +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); + + + id:rectangle1 + height: infoLabel.height + fromLabel.height + toLabel.height + saveButton.height + 50 + width: 200 SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } color : myPalette.window; @@ -72,6 +245,8 @@ Rectangle{ } ComboBox{ + //parentField: rectangle1 + id: comboFrom model: comboBoxModel anchors.left: parent.left @@ -96,6 +271,7 @@ Rectangle{ } ComboBox{ + //parentField: rectangle1; id: comboTo model: comboBoxModel anchors.left: parent.left @@ -155,4 +331,5 @@ Rectangle{ } ] } +*/ diff --git a/src/mdictionary/qml/MySpinBox.qml b/src/mdictionary/qml/MySpinBox.qml index 9f0d47c..54fe47d 100644 --- a/src/mdictionary/qml/MySpinBox.qml +++ b/src/mdictionary/qml/MySpinBox.qml @@ -7,16 +7,22 @@ Rectangle { property int maxValue:500; property int minValue:0; property alias value:text_input1.text + property bool isTextInMinValue:true; + property string textInMinValue:"inf"; + property int singleStep: 2; signal valueChange(int intiger); 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(isTextInMinValue && textInMinValue==string) + value=minValue; + else + for (var i=string.length-1;i>=0;i--){ + value+=(string.charCodeAt(i)-48)*pow10; + pow10= pow10*10; + } if(value>maxValue) return maxValue; if(valuemaxValue)?(maxValue):(stringToInt(text_input1.text)+1); + text_input1.text=((stringToInt(text_input1.text)+singleStep)>maxValue)?(maxValue):(stringToInt(text_input1.text)+singleStep); else running=false; } @@ -62,8 +73,11 @@ Rectangle { running: false; repeat: true onTriggered:{ - if(mouseAreaDown.pressedButtons==Qt.LeftButton) - text_input1.text=((stringToInt(text_input1.text)-1)maxValue)?(maxValue):(stringToInt(text_input1.text)+1); + onClicked: text_input1.text=((stringToInt(text_input1.text)+singleStep)>maxValue)?(maxValue):(stringToInt(text_input1.text)+singleStep); onPressAndHold:{ timerUp.restart; timerUp.running=true; @@ -124,19 +138,15 @@ Rectangle { height: rectangle1.height/2; anchors.right: parent.right anchors.bottom: parent.bottom - onClicked: text_input1.text=((stringToInt(text_input1.text)-1)0) + text_input1.text=text_input1.text+completerItemText.text.charAt(0); + } + + function addAllChars(){ + text_input1.text=text_input1.text+completerItemText.text; + completerItemText.text=""; + } TextInput { id: text_input1 @@ -19,11 +36,57 @@ Rectangle { anchors.centerIn: parent selectByMouse: true; font.pixelSize: rectangle1.height * .5; - onCursorPositionChanged: moveCursorSelection(cursorPosition); + onCursorPositionChanged: { + moveCursorSelection(cursorPosition); + if(cursorPosition==text.length && useCompleter) + completerItem.visible=true; + else + completerItem.visible=false; + } focus: rectangle1.focus; + Keys.priority : Keys.AfterItem Keys.onPressed: { - if ((event.key == Qt.Key_Enter) || (event.key == Qt.Key_Return)) + if ((event.key == Qt.Key_Enter) || (event.key == Qt.Key_Return)){ rectangle1.enterPressed(text_input1.text) + completerItem.visible=false; + } + if(useCompleter){ + if (event.key == Qt.Key_Up) + rectangle1.nextCompleter(); + if (event.key == Qt.Key_Down) + rectangle1.prevCompleter(); + if ((event.key == Qt.Key_Right) && (cursorPosition==text.length)) + addOneChar(); + if(Qt.ControlModifier){ + if (event.key == Qt.Key_Space){ + if(completerItem.visible=false) + completerItem.visible=true + else + addAllChars() + } + } + if(event.key == Qt.Key_Escape) + completerItem.visible=false; + } + } + onTextChanged: rectangle1.textChange(text); + } + + + Rectangle { + id: completerItem + x: text_input1.x + text_input1.positionToRectangle(text_input1.cursorPosition).x +1 + y: text_input1.y + width: completerItemText.paintedWidth; + visible: false; + height: text_input1.height + color: (completerItemText.text.length>0)?"#5e71fb":"#FFFFFF" + opacity: 0.5 + Text { + id: completerItemText + anchors.fill: parent + text:"" + font.pixelSize: text_input1.font.pixelSize; } } diff --git a/src/mdictionary/qml/SearchBarWidget.qml b/src/mdictionary/qml/SearchBarWidget.qml index 689480d..2210de8 100644 --- a/src/mdictionary/qml/SearchBarWidget.qml +++ b/src/mdictionary/qml/SearchBarWidget.qml @@ -12,13 +12,19 @@ Rectangle { function setEnableHistoryNext(Boolean) { historyNextToolButton.enabled = Boolean } function setEnableHistoryShow(Boolean) { historyShowToolButton.enabled = Boolean } function setEnableLineEdit(Boolean) { enableLineEdit = Boolean } - function setLineEditText(string) { inputSearchText.setText(string) } function clear() { inputSearchText.setText("") } + function setLineEditText(string) { inputSearchText.setText(string) } + function setCompleterText(string) { inputSearchText.setCompleter(string) } + signal searchButtonClicked(string text); signal historyNextToolButtonClicked; signal historyShowToolButtonClicked; signal historyPrevToolButtonClicked; + signal textChange(string text); + + signal nextCompleter(); + signal prevCompleter(); MyTextLineEdit{ id: inputSearchText @@ -28,6 +34,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter onEnterPressed: searchBarWidget.searchButtonClicked(text); focus: searchBarWidget.focus + useCompleter: true; IconButton { id: clearButton; width: inputSearchText.height-6; @@ -39,6 +46,9 @@ Rectangle { pathToIcon: "qrc:/button/go-clear.png"; onClicked: clear(); } + onTextChange: searchBarWidget.textChange(text) + onNextCompleter: searchBarWidget.nextCompleter(); + onPrevCompleter: searchBarWidget.prevCompleter(); } Item { @@ -56,7 +66,10 @@ Rectangle { anchors.right: historyPrevToolButton.left anchors.verticalCenter: parent.verticalCenter textInButton: qsTr("Search") - onClicked: searchBarWidget.searchButtonClicked(inputSearchText.textInLineEdit); + onClicked:{ + searchBarWidget.searchButtonClicked(inputSearchText.textInLineEdit); + inputSearchText.hideCompleter(); + } } IconButton { diff --git a/src/mdictionary/qml/SettingsWidget.qml b/src/mdictionary/qml/SettingsWidget.qml index 74d3a9f..b51f788 100644 --- a/src/mdictionary/qml/SettingsWidget.qml +++ b/src/mdictionary/qml/SettingsWidget.qml @@ -149,6 +149,6 @@ Rectangle { anchors.right: parent.right anchors.rightMargin: 5 textInButton: qsTr("Save") - onClicked: rectangle1.saveButtonClicked(); + //onClicked: rectangle1.saveButtonClicked(); } } diff --git a/src/mdictionary/qml/TableWidget.qml b/src/mdictionary/qml/TableWidget.qml index c07d8a5..5957c85 100644 --- a/src/mdictionary/qml/TableWidget.qml +++ b/src/mdictionary/qml/TableWidget.qml @@ -10,160 +10,273 @@ Rectangle { anchors.fill: parent signal dictLink(string link); + signal fromChange(string value); + signal toChange(string value) - ScrollBar2 { - id: horizontalScrollBar1 - z:2; - width: parent.width-12; - windowHeight: parent.height - anchors.left: parent.left - orientation: Qt.Horizontal - position: 100 + + function setFromStartValues(startFrom, startTo, startFromIndex, startToIndex){ + comboFrom.setStartValue(startFrom, startFromIndex) + comboTo.setStartValue(startTo, startToIndex) + } + + function setToStartValues(startFrom, startTo, startFromIndex, startToIndex){ + comboFrom.setStartValue(startFrom, startFromIndex) + comboTo.setStartValue(startTo, startToIndex) } - ScrollBar2 { - id: horizontalScrollBar2 - z:2; - width: parent.width-12; - windowHeight: parent.height - anchors.left: horizontalScrollBar1.left - anchors.leftMargin: horizontalScrollBar1.position - orientation: Qt.Horizontal - position: 100 + + MouseArea { + id: mouse_area1 + anchors.fill: parent + z:-1 + onClicked: { + comboTo.expanded=false; + comboFrom.expanded=false; + } } - ScrollBar2 { - id: horizontalScrollBar3 - z:2; - width: parent.width-12; - windowHeight: parent.height - anchors.left: horizontalScrollBar2.left - anchors.leftMargin: horizontalScrollBar2.position - orientation: Qt.Horizontal - position: 100 + + ComboBox { + id: comboFrom + model: fromModell + anchors.right: comboFromField.right + anchors.left: comboFromField.left + parentField: comboFromField + expanded: false + height: 20 + basicHeight:20 + index: 1 + onExpandedChanged: { + if(expanded==true){ + z=2; + mouse_area1.z=1; + } + else{ + z=0; + mouse_area1.z=-1; + } + } + onValueSelected: rectangle1.fromChange(value) } - ElementsListView{ - id: dictList - width: rectangle1.width + ComboBox { + id: comboTo + model: fromModell + anchors.right: comboToField.right + anchors.left: comboToField.left + parentField: comboToField + expanded: false + height: 20 + basicHeight:20 + index: 1 + onExpandedChanged: { + if(expanded==true){ + z=2; + mouse_area1.z=1; + } + else{ + z=0; + mouse_area1.z=-1; + } + } + onValueSelected: rectangle1.toChange(value) + } + + Item { + id: comboFromField + width: 120 + anchors.left: fromLabel.right + anchors.leftMargin: 5 + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 anchors.top: parent.top + } + + Item { + id: comboToField + width: 120 + anchors.left: toLabel.right + anchors.leftMargin: 5 anchors.bottom: parent.bottom - highlightResizeSpeed: 1000 - - header: Component{ - id: dictListHeader - Item { - width: rectangle1.width - height: 20 - Row { - anchors.fill: parent - Rectangle { - id: fromRecHeader - width: horizontalScrollBar1.position - height: parent.height - radius: 1 - gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } + anchors.bottomMargin: 10 + anchors.top: parent.top + } - Text { - id: fromTextHeader - text: qsTr("From"); - elide: Text.ElideRight - font.pixelSize: 12 - anchors.centerIn: parent + Text { + id: fromLabel + text: qsTr("From: "); + anchors.top: parent.top + anchors.topMargin: 3 + font.pixelSize: 12 + } + + Text { + id: toLabel + text: qsTr("To: "); + anchors.left: comboFrom.right + anchors.leftMargin: 15 + anchors.verticalCenterOffset: 0 + anchors.verticalCenter: fromLabel.verticalCenter + font.pixelSize: 12 + } + + Item { + id: item1 + anchors.topMargin: 30 + anchors.fill: parent + ScrollBar2 { + id: horizontalScrollBar1 + z:2; + width: parent.width-12; + windowHeight: parent.height + anchors.left: parent.left + orientation: Qt.Horizontal + position: 100 + } + ScrollBar2 { + id: horizontalScrollBar2 + z:2; + width: parent.width-12; + windowHeight: parent.height + anchors.left: horizontalScrollBar1.left + anchors.leftMargin: horizontalScrollBar1.position + orientation: Qt.Horizontal + position: 100 + } + ScrollBar2 { + id: horizontalScrollBar3 + z:2; + width: parent.width-12; + windowHeight: parent.height + anchors.left: horizontalScrollBar2.left + anchors.leftMargin: horizontalScrollBar2.position + orientation: Qt.Horizontal + position: 100 + } + + ElementsListView{ + id: dictList + width: rectangle1.width + anchors.topMargin: 0 + anchors.top: parent.top + anchors.bottom: parent.bottom + highlightResizeSpeed: 1000 + + header: Component{ + id: dictListHeader + Item { + width: rectangle1.width + height: 20 + Row { + anchors.fill: parent + Rectangle { + id: fromRecHeader + width: horizontalScrollBar1.position + height: parent.height + radius: 1 + gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } + + Text { + id: fromTextHeader + text: qsTr("From"); + elide: Text.ElideRight + font.pixelSize: 12 + anchors.centerIn: parent + } } - } - Rectangle { - id: toRecHeader - width: horizontalScrollBar2.position - height: parent.height - radius: 1 - gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } + Rectangle { + id: toRecHeader + width: horizontalScrollBar2.position + height: parent.height + radius: 1 + gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } - Text { - id: toTextHeader - text: qsTr("To"); - elide: Text.ElideRight - font.pixelSize: 12 - anchors.centerIn: parent + Text { + id: toTextHeader + text: qsTr("To"); + elide: Text.ElideRight + font.pixelSize: 12 + anchors.centerIn: parent + } } - } - Rectangle { - id: nameRecHeader - width: horizontalScrollBar3.position - height: parent.height - radius: 1 - gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } + Rectangle { + id: nameRecHeader + width: horizontalScrollBar3.position + height: parent.height + radius: 1 + gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } - Text { - id: nameTextHeader - text: qsTr("Title"); - elide: Text.ElideRight - font.pixelSize: 12 - anchors.centerIn: parent + Text { + id: nameTextHeader + text: qsTr("Title"); + elide: Text.ElideRight + font.pixelSize: 12 + anchors.centerIn: parent + } } - } - Rectangle { - id: sizeRecHeader - width: 100; - height: parent.height - radius: 1 - gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } + Rectangle { + id: sizeRecHeader + width: 100; + height: parent.height + radius: 1 + gradient: Gradient { GradientStop { position: 0.3; color: "#a0cbec" } GradientStop { position: 0.99; color: "#35a0f1" } } - Text { - id: sizeTextHeader - text: qsTr("Size"); - elide: Text.ElideRight - font.pixelSize: 12 - anchors.centerIn: parent + Text { + id: sizeTextHeader + text: qsTr("Size"); + elide: Text.ElideRight + font.pixelSize: 12 + anchors.centerIn: parent + } } } } } - } - delegate: Component{ - id: dictListDelegate - Item { - width: rectangle1.width - height:nameText.height - MouseArea{ - anchors.fill: parent - onClicked: { - dictList.currentIndex = index - } - onDoubleClicked: { - rectangle1.dictLink(link) - } - } - Row { - anchors.fill: parent - Text { - id: fromText - text: " "+from+" "; - width: horizontalScrollBar1.position - elide: Text.ElideRight + delegate: Component{ + id: dictListDelegate + Item { + width: rectangle1.width + height:nameText.height + MouseArea{ + anchors.fill: parent + onClicked: { + dictList.currentIndex = index + } + onDoubleClicked: { + rectangle1.dictLink(link) + } } + Row { + anchors.fill: parent + Text { + id: fromText + text: " "+from+" "; + width: horizontalScrollBar1.position + elide: Text.ElideRight + } - Text { - id: toText - text: " "+to+" "; - width: horizontalScrollBar2.position - elide: Text.ElideRight - } + Text { + id: toText + text: " "+to+" "; + width: horizontalScrollBar2.position + elide: Text.ElideRight + } - Text { - id: nameText - text: " "+name+" "; - width: horizontalScrollBar3.position - elide: Text.ElideRight - } - Text { - id: sizeText - text: " "+size+" "; - width: 100 - elide: Text.ElideRight + Text { + id: nameText + text: " "+name+" "; + width: horizontalScrollBar3.position + elide: Text.ElideRight + } + Text { + id: sizeText + text: " "+size+" "; + width: 100 + elide: Text.ElideRight + } } } } + model: dictModel } - model: dictModel } } diff --git a/src/mdictionary/qml/WordListWidget.qml b/src/mdictionary/qml/WordListWidget.qml index 07cf206..288cbaf 100644 --- a/src/mdictionary/qml/WordListWidget.qml +++ b/src/mdictionary/qml/WordListWidget.qml @@ -91,7 +91,8 @@ Rectangle { pathToUncheckedImage: UncheckedPath anchors.right: parent.right anchors.rightMargin: 5 - + pathToCheckedDicImage: CheckedPath + pathToUncheckedDicImage: UncheckedPath anchors.verticalCenter: parent.verticalCenter onChanged: rectangle1.changeWordState(number, selected) visible: { diff --git a/src/plugins/xdxf/XdxfDictSelectDialog.cpp b/src/plugins/xdxf/XdxfDictSelectDialog.cpp index d1575e4..42c1ca8 100644 --- a/src/plugins/xdxf/XdxfDictSelectDialog.cpp +++ b/src/plugins/xdxf/XdxfDictSelectDialog.cpp @@ -32,9 +32,7 @@ XdxfDictSelectDialog::XdxfDictSelectDialog(QList dicts, QWidget *parent) : QDialog(parent) { - setWindowTitle(tr("Select dictionary")); - //here removing already added dictionary for (int i = 0; i < dicts.size(); i++){ if(QFile::exists(QDir::homePath() + "/.mdictionary/" + dicts[i].title() + ".xdxf")){ @@ -46,11 +44,37 @@ XdxfDictSelectDialog::XdxfDictSelectDialog(QList dicts, #ifndef Q_WS_MAEMO_5 model2 = new DictsListModel(dicts, this); proxyModel2 = new DictsProxyListModel; - proxyModel2->setSourceModel(model2); - proxyModel2->setTo("Polish"); + proxyModel2->setSourceModel(model2);; view= new QDeclarativeView(); QDeclarativeContext* ctxt=view->rootContext(); ctxt->setContextProperty("dictModel", proxyModel2); + + QSet languagesFrom; + for(int i=0; i < model2->rowCount(QModelIndex()); i++) + languagesFrom.insert(model2->data(model2->index(i, 0),DictsListModel::FromRole).toString()); + languagesFrom.remove(QString()); + QStringList langFromList = languagesFrom.toList(); + qSort(langFromList); + QList langListFrom; + langListFrom.append(tr("Any")); + foreach(QString lang,langFromList) + langListFrom.append(lang); + fromModel = new ComboBoxModel(langListFrom); + ctxt->setContextProperty("fromModell", fromModel); + + QSet languagesTo; + for(int i=0; i < model2->rowCount(QModelIndex()); i++) + languagesTo.insert(model2->data(model2->index(i, 0),DictsListModel::ToRole).toString()); + languagesTo.remove(QString()); + QStringList langToList = languagesTo.toList(); + qSort(langToList); + QList langListTo; + langListTo.append(tr("Any")); + foreach(QString lang,langToList) + langListTo.append(lang); + toModel = new ComboBoxModel(langListTo); + ctxt->setContextProperty("toModell", toModel); + view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/TableWidget.qml")); view->setResizeMode(QDeclarativeView::SizeRootObjectToView); view->setAlignment(Qt::AlignCenter); @@ -58,12 +82,16 @@ XdxfDictSelectDialog::XdxfDictSelectDialog(QList dicts, mainLayout = new QVBoxLayout; mainLayout->addWidget(view); this->setLayout(mainLayout); - proxyModel2->setTo("English"); QGraphicsObject *rootObject = view->rootObject(); connect(rootObject,SIGNAL(dictLink(QString)), this,SLOT(itemClicked(QString))); + connect(rootObject,SIGNAL(fromChange(QString)), + this,SLOT(fromChange(QString))); + connect(rootObject,SIGNAL(toChange(QString)), + this,SLOT(toChange(QString))); + #else layout = new QVBoxLayout; @@ -135,6 +163,19 @@ XdxfDictSelectDialog::XdxfDictSelectDialog(QList dicts, #endif } +void XdxfDictSelectDialog::toChange(QString lang){ + if(lang!=tr("Any")) + proxyModel2->setTo(lang); + else + proxyModel2->setTo(""); +} + +void XdxfDictSelectDialog::fromChange(QString lang){ + if(lang!=tr("Any")) + proxyModel2->setFrom(lang); + else + proxyModel2->setFrom(""); +} void XdxfDictSelectDialog::initializeDicts() { //scan of all languages of dictionaries, using QSet to get only distinct languages @@ -202,7 +243,9 @@ void XdxfDictSelectDialog::itemClicked(QString link) { } void XdxfDictSelectDialog::itemClicked(QModelIndex index) { -#ifdef Q_WS_MAEMO_5 +#ifndef Q_WS_MAEMO_5 + index; +#else _link = index.model()->data(index, Qt::UserRole).toString(); accept(); #endif diff --git a/src/plugins/xdxf/XdxfDictSelectDialog.h b/src/plugins/xdxf/XdxfDictSelectDialog.h index cbf0d04..fad43b5 100644 --- a/src/plugins/xdxf/XdxfDictSelectDialog.h +++ b/src/plugins/xdxf/XdxfDictSelectDialog.h @@ -35,12 +35,14 @@ #include #include #include +#include #include "DownloadDict.h" #include "DictsListModel.h" #include "DictsModel.h" #include "DictsProxyModel.h" #include "DictsProxyListModel.h" +#include "../../include/ComboBoxModel.h" /*! @@ -77,11 +79,16 @@ private Q_SLOTS: void itemClicked(QString link); + void toChange(QString lang); + void fromChange(QString lang); + private: QVBoxLayout* mainLayout; QDeclarativeView *view; DictsListModel* model2; DictsProxyListModel *proxyModel2; + ComboBoxModel *fromModel; + ComboBoxModel *toModel; QTreeView* treeView; DictsModel* model; diff --git a/src/plugins/xdxf/xdxf.pro b/src/plugins/xdxf/xdxf.pro index d285b44..1c52b1d 100644 --- a/src/plugins/xdxf/xdxf.pro +++ b/src/plugins/xdxf/xdxf.pro @@ -29,7 +29,8 @@ SOURCES += xdxfplugin.cpp \ XdxfDictDownloadProgressDialog.cpp \ DictsModel.cpp \ HttpDownloader.cpp \ - DictsListModel.cpp + DictsListModel.cpp \ + ../../include/ComboBoxModel.cpp HEADERS += xdxfplugin.h \ TranslationXdxf.h \ @@ -38,6 +39,7 @@ HEADERS += xdxfplugin.h \ ../../include/translation.h \ ../../include/settings.h \ ../../include/CommonDictInterface.h \ + ../../include/ComboBoxModel.h \ XdxfCachingDialog.h \ XdxfDialog.h \ XdxfDictDownloader.h \