From 4d9f2607c5de55f0f8f0f7d44ad3e25accaa01da Mon Sep 17 00:00:00 2001 From: jakub Date: Mon, 31 Jan 2011 12:31:51 +0100 Subject: [PATCH] table view --- mdictionary.pri | 2 + src/mdictionary/qml/Button.qml | 7 +- src/mdictionary/qml/IconButton.qml | 7 +- src/mdictionary/qml/ScrollBar.qml | 49 +------- src/mdictionary/qml/ScrollBar2.qml | 52 +++++++++ src/mdictionary/qml/TableWidget.qml | 169 ++++++++++++++++++++++++++++ src/mdictionary/qml/TranslationView.qml | 6 +- src/mdictionary/qml/XdxfDictDownloader.qml | 4 - src/plugins/xdxf/DownloadDict.h | 20 +++- src/plugins/xdxf/XdxfDialog.h | 3 +- src/plugins/xdxf/XdxfDictSelectDialog.cpp | 59 ++++++++-- src/plugins/xdxf/XdxfDictSelectDialog.h | 12 ++ src/plugins/xdxf/xdxf.pro | 14 ++- src/plugins/xdxf/xdxf.qrc | 1 + 14 files changed, 334 insertions(+), 71 deletions(-) create mode 100644 src/mdictionary/qml/ScrollBar2.qml create mode 100644 src/mdictionary/qml/TableWidget.qml diff --git a/mdictionary.pri b/mdictionary.pri index c48f80d..0648729 100644 --- a/mdictionary.pri +++ b/mdictionary.pri @@ -32,3 +32,5 @@ system(echo "ENABLED_SRC = $$ENABLED_SRC" >src/src.pri) system(echo "ENABLED_PLUGINS = $$ENABLED_PLUGINS" >src/plugins/plugins.pri) OTHER_FILES += + +HEADERS += diff --git a/src/mdictionary/qml/Button.qml b/src/mdictionary/qml/Button.qml index 0491e99..d10edc6 100644 --- a/src/mdictionary/qml/Button.qml +++ b/src/mdictionary/qml/Button.qml @@ -33,15 +33,18 @@ BorderImage { height: parent.height anchors.left: parent.left source: "qrc:/button/buttonLeft.png" + smooth: true fillMode:Image.Stretch } Image { id: image3 smooth: true - width: parent.width - ((70*parent.height)/107) +1; height: parent.height - anchors.horizontalCenter: parent.horizontalCenter + anchors.right: image2.left + anchors.rightMargin: -1 + anchors.left: image1.right + anchors.leftMargin: -1 source: "qrc:/button/buttonCenter.png" fillMode:Image.Stretch } diff --git a/src/mdictionary/qml/IconButton.qml b/src/mdictionary/qml/IconButton.qml index dc749a4..19d3d70 100644 --- a/src/mdictionary/qml/IconButton.qml +++ b/src/mdictionary/qml/IconButton.qml @@ -23,6 +23,7 @@ Rectangle { Image { id: image z:4; + smooth: true anchors.centerIn: parent width: iconWidth; height: iconHeight; @@ -42,9 +43,11 @@ Rectangle { id: image3 z: 1 smooth: true - width: parent.width - (70*parent.height)/107 +1 height: parent.height - anchors.horizontalCenter: parent.horizontalCenter + anchors.right: image2.left + anchors.rightMargin: -1 + anchors.left: image1.right + anchors.leftMargin: -1 source: "qrc:/button/buttonCenter.png" } diff --git a/src/mdictionary/qml/ScrollBar.qml b/src/mdictionary/qml/ScrollBar.qml index cf216d2..5fba8af 100644 --- a/src/mdictionary/qml/ScrollBar.qml +++ b/src/mdictionary/qml/ScrollBar.qml @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - import Qt 4.7 Item { @@ -56,7 +15,10 @@ Item { ny = scrollArea.visibleArea.yPosition * container.height; else ny = scrollArea.visibleArea.xPosition * container.width; - if (ny > 2) return ny; else return 2; + if (ny > 2) + return ny; + else + return 2; } function size() @@ -80,7 +42,8 @@ Item { else t = Math.ceil(container.width - 3 - ny); if (nh > t) return t; else return nh; - } else return nh + ny; + } else + return nh + ny; } //Rectangle { anchors.fill: parent; color: "Black"; opacity: 0.5 } diff --git a/src/mdictionary/qml/ScrollBar2.qml b/src/mdictionary/qml/ScrollBar2.qml new file mode 100644 index 0000000..4147362 --- /dev/null +++ b/src/mdictionary/qml/ScrollBar2.qml @@ -0,0 +1,52 @@ +import Qt 4.7 + +Item { + id: scrollBar + + // The properties that define the scrollbar's state. + // position and pageSize are in the range 0.0 - 1.0. They are relative to the + // height of the page, i.e. a pageSize of 0.5 means that you can see 50% + // of the height of the view. + // orientation can be either Qt.Vertical or Qt.Horizontal + property variant orientation : Qt.Vertical + property int windowHeight :100 + property alias position: slider.x + + signal changeCursor + + // Size the bar to the required size, depending upon the orientation. + Rectangle { + id: slider; + width: 1; + height: windowHeight; + radius: height/2 - 1 + color: "black" + opacity: 0.7 + } + + MouseArea { + property variant lastPresX; + anchors.rightMargin: 5 + anchors.leftMargin: 5 + id: mouse_area1 + anchors.fill: slider + onEntered: { + + } + + onMousePositionChanged:{ + var num=0; + if(Qt.LeftButton) { + num= slider.x+(mouseX-lastPresX); + + if(num>(scrollBar.width-slider.width)) + slider.x=scrollBar.width-slider.width + else if(num<0) + slider.x=0; + else + slider.x=num ; + } + } + onPressed: lastPresX=mouseX; + } +} diff --git a/src/mdictionary/qml/TableWidget.qml b/src/mdictionary/qml/TableWidget.qml new file mode 100644 index 0000000..c07d8a5 --- /dev/null +++ b/src/mdictionary/qml/TableWidget.qml @@ -0,0 +1,169 @@ +import Qt 4.7 + +Rectangle { + SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } + color : myPalette.window; + + id: rectangle1 + width: 400; + height: 400; + anchors.fill: parent + + signal dictLink(string link); + + 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.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" } } + + 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" } } + + 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" } } + + 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 + } + + 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 + } + } + } + } + model: dictModel + } +} diff --git a/src/mdictionary/qml/TranslationView.qml b/src/mdictionary/qml/TranslationView.qml index f161c4d..c0a546a 100644 --- a/src/mdictionary/qml/TranslationView.qml +++ b/src/mdictionary/qml/TranslationView.qml @@ -24,12 +24,14 @@ Rectangle { Item { id: headerSpace; width: parent.width; height: 1} ScrollBar { - scrollArea: webView; width: 8 + scrollArea: webView; + width: 8 anchors { right: parent.right; top: parent.bottom; bottom: parent.bottom } } ScrollBar { - scrollArea: webView; height: 8; orientation: Qt.Horizontal + scrollArea: webView; + height: 8; orientation: Qt.Horizontal anchors { right: parent.right; rightMargin: 8; left: parent.left; bottom: parent.bottom } } diff --git a/src/mdictionary/qml/XdxfDictDownloader.qml b/src/mdictionary/qml/XdxfDictDownloader.qml index 6973147..074f880 100644 --- a/src/mdictionary/qml/XdxfDictDownloader.qml +++ b/src/mdictionary/qml/XdxfDictDownloader.qml @@ -10,15 +10,12 @@ Rectangle { color : myPalette.window; function setValue(intiger){ - console.log("ala value " +intiger); progressbar1.setValue(intiger); } function setText(string){ - console.log("ala text " +string); text.text=string; } function setMaximumValue(intiger){ - console.log("ala max " +intiger); if(intiger==0){ timerUp.running=true; setValue(-1); @@ -56,7 +53,6 @@ Rectangle { anchors.right: parent.right anchors.left: parent.left onClicked: { - console.log("click"); rectangle1.cancelDownloading(); } } diff --git a/src/plugins/xdxf/DownloadDict.h b/src/plugins/xdxf/DownloadDict.h index bf50c17..c5e3d11 100644 --- a/src/plugins/xdxf/DownloadDict.h +++ b/src/plugins/xdxf/DownloadDict.h @@ -72,6 +72,14 @@ public: _link = lreg.capturedTexts().at(1); } + DownloadDict(const DownloadDict &dict) { + _from = dict.fromLang(); + _to = dict.toLang(); + _title = dict.title(); + _size = dict.size(); + _link = dict.link(); + } + //! \return dictionary source language QString fromLang() const {return _from;} @@ -92,10 +100,14 @@ public: \return 1 if this is before other */ bool operator <(DownloadDict other) const { - if(_from < other.fromLang()) return true; - if(_from > other.fromLang()) return false; - if(_to < other.toLang()) return true; - return false; + if(_from < other.fromLang()) + return true; + else if(_from > other.fromLang()) + return false; + else if(_to < other.toLang()) + return true; + else + return false; } private: diff --git a/src/plugins/xdxf/XdxfDialog.h b/src/plugins/xdxf/XdxfDialog.h index d1775da..706c949 100644 --- a/src/plugins/xdxf/XdxfDialog.h +++ b/src/plugins/xdxf/XdxfDialog.h @@ -30,12 +30,11 @@ #define XDXFDIALOG_H #include -#include "../../include/settings.h" #include #include #include "xdxfplugin.h" - +#include "../../include/settings.h" /*! This class can create dialogs for adding a new dictionary or changing settings diff --git a/src/plugins/xdxf/XdxfDictSelectDialog.cpp b/src/plugins/xdxf/XdxfDictSelectDialog.cpp index fdb7cdd..d1575e4 100644 --- a/src/plugins/xdxf/XdxfDictSelectDialog.cpp +++ b/src/plugins/xdxf/XdxfDictSelectDialog.cpp @@ -31,8 +31,41 @@ 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")){ + dicts.removeAt(i); + i--; + } + } + +#ifndef Q_WS_MAEMO_5 + model2 = new DictsListModel(dicts, this); + proxyModel2 = new DictsProxyListModel; + proxyModel2->setSourceModel(model2); + proxyModel2->setTo("Polish"); + view= new QDeclarativeView(); + QDeclarativeContext* ctxt=view->rootContext(); + ctxt->setContextProperty("dictModel", proxyModel2); + view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/TableWidget.qml")); + view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + view->setAlignment(Qt::AlignCenter); + + 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))); +#else + layout = new QVBoxLayout; setLayout(layout); @@ -53,15 +86,6 @@ XdxfDictSelectDialog::XdxfDictSelectDialog(QList dicts, checkBoxLayout->addWidget(langToLabel); checkBoxLayout->addWidget(langTo, 10); - //here removing already added dictionary - - for (int i = 0; i < dicts.size(); i++){ - if(QFile::exists(QDir::homePath() + "/.mdictionary/" + dicts[i].title() + ".xdxf")){ - dicts.removeAt(i); - i--; - } - } - model = new DictsModel(dicts, this); proxyModel = new DictsProxyModel; @@ -108,6 +132,7 @@ XdxfDictSelectDialog::XdxfDictSelectDialog(QList dicts, #endif initializeDicts(); + #endif } @@ -149,6 +174,11 @@ void XdxfDictSelectDialog::initializeDicts() { void XdxfDictSelectDialog::refreshDictList() { +#ifndef Q_WS_MAEMO_5 + + +#else + //if selected language is "Any"(index 0), from filter string is set to empty string, proxy model uses empty string as special case and don't filter by this field. if(langTo->currentIndex() == 0) proxyModel->setTo(QString()); @@ -159,10 +189,21 @@ void XdxfDictSelectDialog::refreshDictList() { proxyModel->setFrom(QString()); else proxyModel->setFrom(langFrom->currentText()); + +#endif } +void XdxfDictSelectDialog::itemClicked(QString link) { +#ifndef Q_WS_MAEMO_5 + _link = link; + accept(); +#endif +} + void XdxfDictSelectDialog::itemClicked(QModelIndex index) { +#ifdef Q_WS_MAEMO_5 _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 7ac546d..cbf0d04 100644 --- a/src/plugins/xdxf/XdxfDictSelectDialog.h +++ b/src/plugins/xdxf/XdxfDictSelectDialog.h @@ -33,9 +33,14 @@ #include #include #include +#include +#include + #include "DownloadDict.h" +#include "DictsListModel.h" #include "DictsModel.h" #include "DictsProxyModel.h" +#include "DictsProxyListModel.h" /*! @@ -70,7 +75,14 @@ private Q_SLOTS: //! accept dialog and sets download link of clicked dictionary void itemClicked(QModelIndex); + void itemClicked(QString link); + private: + QVBoxLayout* mainLayout; + QDeclarativeView *view; + DictsListModel* model2; + DictsProxyListModel *proxyModel2; + QTreeView* treeView; DictsModel* model; DictsProxyModel *proxyModel; //used by treeView to allow filtering and sorti diff --git a/src/plugins/xdxf/xdxf.pro b/src/plugins/xdxf/xdxf.pro index 929060c..d285b44 100644 --- a/src/plugins/xdxf/xdxf.pro +++ b/src/plugins/xdxf/xdxf.pro @@ -28,7 +28,8 @@ SOURCES += xdxfplugin.cpp \ XdxfDictSelectDialog.cpp \ XdxfDictDownloadProgressDialog.cpp \ DictsModel.cpp \ - HttpDownloader.cpp + HttpDownloader.cpp \ + DictsListModel.cpp HEADERS += xdxfplugin.h \ TranslationXdxf.h \ @@ -45,7 +46,9 @@ HEADERS += xdxfplugin.h \ DownloadDict.h \ DictsModel.h \ DictsProxyModel.h \ - HttpDownloader.h + HttpDownloader.h \ + DictsListModel.h \ + DictsProxyListModel.h RESOURCES += xdxf.qrc @@ -53,7 +56,9 @@ TRANSLATIONS += pl_PL.ts \ en_US.ts OTHER_FILES += ../../mdictionary/qml/XdxfDialog.qml \ - ../../mdictionary/qml/XdxfDictDownloader.qml + ../../mdictionary/qml/XdxfDictDownloader.qml \ + ../../mdictionary/qml/TableWidget.qml \ + ../../mdictionary/qml/ScrollBar2.qml unix { dicts.path = $$PLUGINS_DIR @@ -74,6 +79,9 @@ unix { qmls.path = $$DATA_DIR/qml qmls.files += ../../mdictionary/qml/XdxfDialog.qml qmls.files += ../../mdictionary/qml/XdxfDictDownloader.qml + qmls.files += ../../mdictionary/qml/TableWidget.qml + qmls.files += ../../mdictionary/qml/ScrollBar2.qml + } INSTALLS += dicts \ diff --git a/src/plugins/xdxf/xdxf.qrc b/src/plugins/xdxf/xdxf.qrc index 0642344..fa729df 100644 --- a/src/plugins/xdxf/xdxf.qrc +++ b/src/plugins/xdxf/xdxf.qrc @@ -2,5 +2,6 @@ translations/pl_PL.qm translations/en_US.qm + scrollbar.png -- 1.7.9.5