From: jakub Date: Thu, 23 Dec 2010 07:26:38 +0000 (+0100) Subject: qml X-Git-Url: http://vcs.maemo.org/git/?p=mdictionary;a=commitdiff_plain;h=9e1b6e62ff6f4b4650f585eb7a8f942f163e57f6 qml --- diff --git a/data/gui.qrc b/data/gui.qrc index bb4db8a..70533fe 100644 --- a/data/gui.qrc +++ b/data/gui.qrc @@ -15,5 +15,6 @@ button/buttonLeft.png button/buttonR.png button/go-previous.png + progressBar/background.png diff --git a/src/mdictionary/gui/MainWindow.cpp b/src/mdictionary/gui/MainWindow.cpp index 431ccf0..e5a0b61 100644 --- a/src/mdictionary/gui/MainWindow.cpp +++ b/src/mdictionary/gui/MainWindow.cpp @@ -372,16 +372,11 @@ void MainWindow::enableMenu() { } void MainWindow::showHistory(QPoint p) { - - HistoryListDialog historyDialog(backbone->history()->list(), searchBarWidget); - + HistoryListDialog historyDialog(backbone->history()->list(), this );// searchBarWidget); #ifndef Q_WS_MAEMO_5 - QPoint newPos = mapFromGlobal(p); - newPos.setY(searchBarWidget->pos().y() - - historyDialog.sizeHint().height()); - newPos.setX(width() - historyDialog.sizeHint().width()); - - historyDialog.move(newPos); + p.setX(p.x() - historyDialog.sizeHint().width() + 5); + p.setY(p.y() - historyDialog.sizeHint().height() - 80); + historyDialog.move(p); #endif if(historyDialog.exec() == QDialog::Accepted) { diff --git a/src/mdictionary/gui/SearchBarWidget.cpp b/src/mdictionary/gui/SearchBarWidget.cpp index 0726d76..81795d5 100644 --- a/src/mdictionary/gui/SearchBarWidget.cpp +++ b/src/mdictionary/gui/SearchBarWidget.cpp @@ -33,8 +33,16 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { + qDebug()<<"test1"; #ifndef Q_WS_MAEMO_5 this->setMaximumHeight(50); + busyTimer=new QTimer; + + progressBar = new QDeclarativeView(); + progressBar->setSource(QUrl("src/mdictionary/qml/ProgressBar.qml")); + progressBar->setResizeMode(QDeclarativeView::SizeRootObjectToView); + progressBar->setAlignment(Qt::AlignCenter); + progressBar->hide(); view= new QDeclarativeView(); view->setSource(QUrl("src/mdictionary/qml/SearchBarWidget.qml")); @@ -43,10 +51,12 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { view->show(); mainLayout = new QVBoxLayout; + mainLayout->addWidget(progressBar); mainLayout->addWidget(view); setLayout(mainLayout); QGraphicsObject *rootObject = view->rootObject(); + QGraphicsObject *rootObject2 = progressBar->rootObject(); connect(rootObject, SIGNAL(searchButtonClicked(QString)), this, SLOT(searchButtonClicked(QString))); @@ -55,7 +65,16 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { connect(rootObject, SIGNAL(historyPrevToolButtonClicked()), this, SIGNAL(historyPrev())); connect(rootObject, SIGNAL(historyShowToolButtonClicked()), - this, SIGNAL(historyShow())); + this, SLOT(showHistoryButtonClicked())); + + connect(this, SIGNAL(progresSetMax(QVariant)), + rootObject2, SLOT(setMax(QVariant))); + connect(this, SIGNAL(progresSetMin(QVariant)), + rootObject2, SLOT(setMin(QVariant))); + connect(this, SIGNAL(progresSetValue(QVariant)), + rootObject2, SLOT(setValue(QVariant))); + connect(this, SIGNAL(progresSetValue2(QVariant)), + rootObject2, SLOT(setValue2(QVariant))); connect(this, SIGNAL(setEnableHistoryNext(QVariant)), rootObject, SLOT(setEnableHistoryNext(QVariant))); @@ -70,13 +89,19 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { connect(this, SIGNAL(setLineEditEnables(QVariant)), rootObject, SLOT(setEnableLineEdit(QVariant))); + connect(busyTimer, SIGNAL(timeout()), + this, SLOT(updateBusyTimer())); + emit setEnableHistoryNext(false); emit setEnableHistoryShow(false); emit setEnableHistoryPrev(false); completerModel = new QStringListModel(this); - connect(&delayTimer, SIGNAL(timeout()), - this, SLOT(delaySearchTimeout())); + // connect(&delayTimer, SIGNAL(timeout()), + // this, SLOT(delaySearchTimeout())); + + view->setFocus(); + #else initializeUI(); connect(searchPushButton, SIGNAL(clicked()), @@ -108,6 +133,7 @@ SearchBarWidget::~SearchBarWidget() { } QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) { + qDebug()<<"test2"; QPixmap p = original.pixmap(64); if(rotation != 0) { @@ -144,12 +170,16 @@ QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) { } void SearchBarWidget::setFocus() { -#ifdef Q_WS_MAEMO_5 + qDebug()<<"test3"; +#ifndef Q_WS_MAEMO_5 + view->setFocus(); +#else searchWordLineEdit->setFocus(); #endif } void SearchBarWidget::initializeUI() { + qDebug()<<"test4"; #ifdef Q_WS_MAEMO_5 setMaximumHeight(150); @@ -256,6 +286,7 @@ void SearchBarWidget::initializeUI() { } void SearchBarWidget::searchButtonClicked(QString text) { + qDebug()<<"test5"; if(busy) Q_EMIT stopSearching(); else @@ -263,6 +294,7 @@ void SearchBarWidget::searchButtonClicked(QString text) { } void SearchBarWidget::searchPushButtonClicked() { + qDebug()<<"test6"; #ifdef Q_WS_MAEMO_5 if(busy) { Q_EMIT stopSearching(); @@ -274,6 +306,7 @@ void SearchBarWidget::searchPushButtonClicked() { } void SearchBarWidget::search(QString word) { + qDebug()<<"test7"; qDebug()<insertRow(completerModel->rowCount()); @@ -290,6 +323,7 @@ void SearchBarWidget::search(QString word) { } void SearchBarWidget::searchDelay(QString word) { + qDebug()<<"test8"; if(!busy && !word.isEmpty()) { #ifndef Q_WS_MAEMO_5 emit setLineEditText(word); @@ -305,6 +339,7 @@ void SearchBarWidget::searchDelay(QString word) { } void SearchBarWidget::delaySearchTimeout() { + qDebug()<<"test9"; delayTimer.stop(); if(!busy) { Q_EMIT searchForTranslations(delayString); @@ -312,9 +347,11 @@ void SearchBarWidget::delaySearchTimeout() { } void SearchBarWidget::setEnabled(bool enabled) { + qDebug()<<"test10"; #ifndef Q_WS_MAEMO_5 emit setLineEditEnables(enabled); if(!enabled) { + qDebug()<<"tu???"; emit setEnableHistoryNext(false); emit setEnableHistoryShow(false); emit setEnableHistoryPrev(false); @@ -330,11 +367,19 @@ void SearchBarWidget::setEnabled(bool enabled) { } void SearchBarWidget::setBusy() { + qDebug()<<"test11"; if(busy) return; #ifndef Q_WS_MAEMO_5 + busyTimer->start(500); emit setButtonText(tr("Stop")); -// searchingProgressBar->show(); + this->setMaximumHeight(88); + progressBar->show(); + emit progresSetMax(100); + emit progresSetMin(0); + emit progresSetValue(-1); + emit progresSetValue2(100); + progressMax=true; #else searchingProgressBar->show(); searchPushButton->setText(tr("Stop")); @@ -344,10 +389,27 @@ void SearchBarWidget::setBusy() { busy = true; } +void SearchBarWidget::updateBusyTimer(){ + // qDebug()<<"test12"; + if(progressMax==true){ + emit progresSetValue2(0); + progressMax=false; + } + else{ + emit progresSetValue2(100); + progressMax=true; + } + busyTimer->start(500); +} + void SearchBarWidget::setIdle() { + qDebug()<<"test13"; if(!busy) return; #ifndef Q_WS_MAEMO_5 -// searchingProgressBar->hide(); + progressBar->hide(); + busyTimer->stop(); + emit progresSetValue2(0); + this->setMaximumHeight(50); emit setButtonText(tr("Search")); #else searchingProgressBar->hide(); @@ -360,6 +422,7 @@ void SearchBarWidget::setIdle() { void SearchBarWidget::clearSearchWordToolButtonClicked() { + qDebug()<<"test14"; #ifdef Q_WS_MAEMO_5 searchWordLineEdit->clear(); #endif @@ -368,6 +431,7 @@ void SearchBarWidget::clearSearchWordToolButtonClicked() { void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) { + qDebug()<<"test15"; if(!busy) { #ifndef Q_WS_MAEMO_5 emit setEnableHistoryNext(next); @@ -382,11 +446,13 @@ void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) { } void SearchBarWidget::showHistoryButtonClicked() { + qDebug()<<"test16"; #ifndef Q_WS_MAEMO_5 QPoint p=view->pos(); // = historyShowToolButton->pos(); - p.setY(p.y()); - emit historyShow(mapToGlobal(p)); - #else + p=mapToGlobal(p); + p.setX(p.x()+view->width()); + emit historyShow(p); +#else emit historyShow(); #endif } diff --git a/src/mdictionary/gui/SearchBarWidget.h b/src/mdictionary/gui/SearchBarWidget.h index 52a8e65..427eb53 100644 --- a/src/mdictionary/gui/SearchBarWidget.h +++ b/src/mdictionary/gui/SearchBarWidget.h @@ -56,6 +56,10 @@ Q_SIGNALS: void setButtonText(QVariant text); void setLineEditText(QVariant text); void setLineEditEnables(QVariant enabled); + void progresSetMax(QVariant); + void progresSetMin(QVariant); + void progresSetValue(QVariant); + void progresSetValue2(QVariant); //! Requests to search for a list of words matching a word passed as //! a parameter @@ -82,6 +86,8 @@ Q_SIGNALS: public Q_SLOTS: + void updateBusyTimer(); + void searchButtonClicked(QString text); //! Enables or disables search word line edit and history buttons @@ -147,6 +153,9 @@ private: QVBoxLayout* mainLayout; QDeclarativeView *view; + QDeclarativeView *progressBar; + QTimer *busyTimer; + bool progressMax; QLineEdit* searchWordLineEdit; QCompleter* lineEditCompleter; diff --git a/src/mdictionary/qml/Button.qml b/src/mdictionary/qml/Button.qml index 748ba3c..a21cf2f 100644 --- a/src/mdictionary/qml/Button.qml +++ b/src/mdictionary/qml/Button.qml @@ -43,6 +43,7 @@ BorderImage { height: parent.height anchors.left: parent.left source: "qrc:/button/buttonLeft.png" + fillMode:Image.Stretch } Image { @@ -52,6 +53,7 @@ BorderImage { height: parent.height anchors.horizontalCenter: parent.horizontalCenter source: "qrc:/button/buttonCenter.png" + fillMode:Image.Stretch } Image { @@ -61,6 +63,7 @@ BorderImage { height: parent.height anchors.right: parent.right source: "qrc:/button/buttonR.png" + fillMode:Image.Stretch } states: [ diff --git a/src/mdictionary/qml/MyTextLineEdit.qml b/src/mdictionary/qml/MyTextLineEdit.qml index 1c551a5..2514185 100644 --- a/src/mdictionary/qml/MyTextLineEdit.qml +++ b/src/mdictionary/qml/MyTextLineEdit.qml @@ -20,7 +20,7 @@ Rectangle { selectByMouse: true; font.pixelSize: rectangle1.height * .5; onCursorPositionChanged: moveCursorSelection(cursorPosition); - activeFocusOnPress: true; + focus: rectangle1.focus; Keys.onPressed: { if ((event.key == Qt.Key_Enter) || (event.key == Qt.Key_Return)) rectangle1.enterPressed(text_input1.text) diff --git a/src/mdictionary/qml/ProgressBar.qml b/src/mdictionary/qml/ProgressBar.qml index ea3ec86..a36bda2 100644 --- a/src/mdictionary/qml/ProgressBar.qml +++ b/src/mdictionary/qml/ProgressBar.qml @@ -1,48 +1,73 @@ import Qt 4.7 -Item { +Rectangle { id: progressBar property int minimum: 0 property int maximum: 100 - property int value: 0 - property alias color: gradient1.color - property alias secondColor: gradient2.color + property int value: -1 + property int value2: 50 function setMax(intiger) { maximum=intiger } function setMin(intiger) { minimum=intiger } function setValue(intiger) { value= intiger } + function setValue2(intiger) { value2= intiger } width: 250; height: 23 clip: true BorderImage { - source: "background.png" + source: "qrc:/progressBar/background.png" width: parent.width; height: parent.height border { left: 4; top: 4; right: 4; bottom: 4 } } + Rectangle { id: highlight + z: 1; + + property int widthDest: (progressBar.width * (value - minimum)) / (maximum - minimum) - 6 + property int position: (progressBar.width * (value2 - minimum)) / (maximum - minimum) - property int widthDest: ((progressbar.width * (value - minimum)) / (maximum - minimum) - 6) + width: (value>-1) ? (highlight.widthDest) : (90) + anchors.leftMargin: (value>-1) ? (0) : (highlight.position) - width: highlight.widthDest - Behavior on width { SmoothedAnimation { velocity: 1200 } } + Behavior on width { + SmoothedAnimation { + velocity: 1200 + } + } + + Behavior on anchors.leftMargin { + SequentialAnimation{ + loops: Animation.Infinite + SmoothedAnimation { velocity: 450; to: progressBar.width - 96} + SmoothedAnimation { velocity: 450; to: 0 } + } + } - anchors { left: parent.left; top: parent.top; bottom: parent.bottom; margins: 3 } radius: 1 + anchors.top: parent.top + anchors.left: parent.left + + anchors.bottom: parent.bottom + anchors.margins: 3 + gradient: Gradient { - GradientStop { id: gradient1; position: 0.0 } - GradientStop { id: gradient2; position: 1.0 } + GradientStop {color:"#0510a0"; position: 0.0 } + GradientStop {color:"#6b98f7"; position: 1.0 } } } Text { - anchors { right: highlight.right; rightMargin: 6; verticalCenter: parent.verticalCenter } + z: 1; + anchors.right: highlight.right + anchors.rightMargin: (value>-1) ? 6 : 35; + anchors.verticalCenter: parent.verticalCenter color: "white" font.bold: true - text: Math.floor((value - minimum) / (maximum - minimum) * 100) + '%' + text: (value>-1) ? (Math.floor((value - minimum) / (maximum - minimum) * 100) + '%') : ("???"); } } diff --git a/src/mdictionary/qml/SearchBarWidget.qml b/src/mdictionary/qml/SearchBarWidget.qml index 8bd574e..d72e71c 100644 --- a/src/mdictionary/qml/SearchBarWidget.qml +++ b/src/mdictionary/qml/SearchBarWidget.qml @@ -13,6 +13,7 @@ Rectangle { function setEnableHistoryShow(Boolean) { historyShowToolButton.enabled = Boolean } function setEnableLineEdit(Boolean) { enableLineEdit = Boolean } function setLineEditText(string) { inputSearchText.setText(string) } + function clear() { inputSearchText.setText("") } signal searchButtonClicked(string text); signal historyNextToolButtonClicked; @@ -26,6 +27,7 @@ Rectangle { anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter onEnterPressed: searchBarWidget.searchButtonClicked(text); + focus: searchBarWidget.focus IconButton { id: clearButton; width: inputSearchText.height-6; @@ -35,6 +37,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter enabled: true; pathToIcon: "qrc:/button/go-previous.png"; + onClicked: clear(); } }