From 7cc04115db6f9fa2d79d02d32cff38e4ecd8c52b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 15 Oct 2009 17:09:38 +1000 Subject: Some improvements to loader --- examples/declarative/loader/Browser.qml | 58 ++++++++++++++++++---------- examples/declarative/loader/loader.pro | 9 +++++ examples/declarative/loader/main.cpp | 42 +++++++++++++++----- src/declarative/extra/qmlfolderlistmodel.cpp | 9 +++++ src/declarative/extra/qmlfolderlistmodel.h | 3 ++ 5 files changed, 90 insertions(+), 31 deletions(-) diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index 5f972f1..9eedd4e 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -2,13 +2,14 @@ import Qt 4.6 Rectangle { id: root + property bool keyPressed: false width: parent.width height: parent.height - color: palette.base + color: palette.window FolderListModel { id: folders nameFilters: [ "*.qml" ] -// folder: "E:" + folder: "E:" } SystemPalette { id: palette; colorGroup: Qt.Active } @@ -25,7 +26,7 @@ Rectangle { } } width: root.width - height: 32 + height: 48 color: "transparent" Rectangle { id: highlight; visible: false @@ -36,15 +37,15 @@ Rectangle { } } Item { - width: 32; height: 32 + width: 46; height: 46 Image { source: "images/fileopen.png"; anchors.centerIn: parent; visible: folders.isFolder(index)} } Text { id: nameText anchors.fill: parent; verticalAlignment: "AlignVCenter" - text: fileName; anchors.leftMargin: 32 - font.pointSize: 10 - color: palette.windowText + text: fileName; anchors.leftMargin: 48 + font.pixelSize: 32 + color: wrapper.isCurrentItem ? palette.highlightedText : palette.text } MouseRegion { id: mouseRegion @@ -62,13 +63,6 @@ Rectangle { } } - Script { - function up(path) { - var pos = path.toString().lastIndexOf("/"); - return path.toString().substring(0, pos); - } - } - ListView { id: view anchors.top: titleBar.bottom @@ -77,37 +71,59 @@ Rectangle { anchors.bottom: parent.bottom model: folders delegate: folderDelegate - highlight: Rectangle { color: "#FFFBAF" } + highlight: Rectangle { color: palette.highlight; visible: root.keyPressed } clip: true focus: true + pressDelay: 100 + Keys.onPressed: { - if (event.key == Qt.Key_Return || event.key == Qt.Key_Select) { + root.keyPressed = true; + if (event.key == Qt.Key_Return || event.key == Qt.Key_Select || event.key == Qt.Key_Right) { view.currentItem.launch(); event.accepted = true; } } + Keys.onLeftPressed: folders.folder = up(folders.folder) } Rectangle { id: titleBar width: parent.width - height: 32 - color: palette.button; border.color: palette.mid + height: 48 + color: palette.lighter(palette.window); border.color: palette.mid Rectangle { id: upButton - width: 30 + width: 48 height: titleBar.height border.color: palette.mid; color: "transparent" - MouseRegion { anchors.fill: parent; onClicked: folders.folder = up(folders.folder) } + + Script { + function up(path) { + var pos = path.toString().lastIndexOf("/"); + return path.toString().substring(0, pos); + } + } + Image { anchors.centerIn: parent; source: "images/up.png" } + MouseRegion { id: upRegion; anchors.fill: parent + onClicked: if (folders.parentFolder != "") folders.folder = folders.parentFolder + } + states: [ + State { + name: "pressed" + when: upRegion.pressed + PropertyChanges { target: upButton; color: palette.highlightedText } + } + ] } Text { anchors.left: upButton.right; anchors.right: parent.right; height: parent.height anchors.leftMargin: 4; anchors.rightMargin: 4 - text: folders.folder; color: palette.buttonText + text: folders.folder; color: palette.text elide: "ElideLeft"; horizontalAlignment: "AlignRight"; verticalAlignment: "AlignVCenter" + font.pixelSize: 32 } } } diff --git a/examples/declarative/loader/loader.pro b/examples/declarative/loader/loader.pro index 089eaff..9b03b8f 100644 --- a/examples/declarative/loader/loader.pro +++ b/examples/declarative/loader/loader.pro @@ -7,3 +7,12 @@ target.path = $$[QT_INSTALL_EXAMPLES]/declarative/loader sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS loader.pro sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/loader INSTALLS += target sources + +symbian { +# TARGET.UID3 = + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.EPOCHEAPSIZE = 100000 20000000 + HEADERS += $$QT_SOURCE_TREE/examples/network/ftp/sym_iap_util.h + LIBS += -lesock -lconnmon -linsock + TARGET.CAPABILITY = NetworkServices +} diff --git a/examples/declarative/loader/main.cpp b/examples/declarative/loader/main.cpp index fbae5f1..0993814 100644 --- a/examples/declarative/loader/main.cpp +++ b/examples/declarative/loader/main.cpp @@ -15,6 +15,15 @@ #include #include #include +#include + +#if defined (Q_OS_SYMBIAN) +#define SYMBIAN_NETWORK_INIT +#endif + +#if defined (SYMBIAN_NETWORK_INIT) +#include "sym_iap_util.h" +#endif QmlView *canvas = 0; @@ -30,13 +39,11 @@ public: setLayout(layout); #ifdef Q_OS_SYMBIAN QAction *closeAction = new QAction("Close", this); - closeAction->setSoftKeyRole(QAction::BackSoftKey); + closeAction->setSoftKeyRole(QAction::NegativeSoftKey); connect(closeAction, SIGNAL(triggered()), this, SLOT(close())); - - QList softKeys; - softKeys.append(closeAction); - setSoftKeys(softKeys); + addAction(closeAction); #endif + connect(logText, SIGNAL(textChanged()), this, SIGNAL(textChanged())); } void append(const QString &text) { @@ -50,6 +57,9 @@ public: return logger; } +signals: + void textChanged(); + private: QPlainTextEdit *logText; }; @@ -112,7 +122,7 @@ public: } } - canvas->setUrl(fileName); + canvas->setUrl(url); canvas->execute(); } @@ -124,8 +134,9 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow() : QMainWindow() {} - + MainWindow() : QMainWindow() + { + } public slots: void toggleFullScreen() @@ -149,6 +160,13 @@ public slots: Logger::instance()->show(); #endif } + + void enableNetwork() + { +#if defined(SYMBIAN_NETWORK_INIT) + qt_SetDefaultIap(); +#endif + } }; class ConfiguredNetworkAccessManager : public QNetworkAccessManager { @@ -185,8 +203,6 @@ int main(int argc, char *argv[]) canvas->setFocusPolicy(Qt::StrongFocus); canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager); - mw->setCentralWidget(canvas); - QMenuBar *mb = mw->menuBar(); QAction *showLogAction = new QAction("View Log...", mw); mb->addAction(showLogAction); @@ -194,6 +210,11 @@ int main(int argc, char *argv[]) QAction *toggleFSAction = new QAction("Fullscreen", mw); mb->addAction(toggleFSAction); QObject::connect(toggleFSAction, SIGNAL(triggered()), mw, SLOT(toggleFullScreen())); +#if defined(SYMBIAN_NETWORK_INIT) + QAction *enableNetworkAction = new QAction("Enable Network", mw); + mb->addAction(enableNetworkAction); + QObject::connect(enableNetworkAction, SIGNAL(triggered()), mw, SLOT(enableNetwork())); +#endif QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("qmlLauncher", launcher); @@ -205,6 +226,7 @@ int main(int argc, char *argv[]) mw->show(); #endif canvas->execute(); + mw->setCentralWidget(canvas); return app.exec(); } diff --git a/src/declarative/extra/qmlfolderlistmodel.cpp b/src/declarative/extra/qmlfolderlistmodel.cpp index bdea03f..4a7c2f1 100644 --- a/src/declarative/extra/qmlfolderlistmodel.cpp +++ b/src/declarative/extra/qmlfolderlistmodel.cpp @@ -195,6 +195,15 @@ void QmlFolderListModel::setFolder(const QString &folder) } } +QString QmlFolderListModel::parentFolder() const +{ + Q_D(const QmlFolderListModel); + int pos = d->folder.lastIndexOf('/'); + if (pos == -1) + return QString(); + return d->folder.left(pos); +} + /*! \qmlproperty list FolderListModel::nameFilters diff --git a/src/declarative/extra/qmlfolderlistmodel.h b/src/declarative/extra/qmlfolderlistmodel.h index 24a3ac6..6bb1c4b 100644 --- a/src/declarative/extra/qmlfolderlistmodel.h +++ b/src/declarative/extra/qmlfolderlistmodel.h @@ -61,6 +61,7 @@ class Q_DECLARATIVE_EXPORT QmlFolderListModel : public QListModelInterface, publ Q_INTERFACES(QmlParserStatus) Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QString parentFolder READ parentFolder NOTIFY folderChanged) Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) @@ -77,6 +78,8 @@ public: QString folder() const; void setFolder(const QString &folder); + QString parentFolder() const; + QStringList nameFilters() const; void setNameFilters(const QStringList &filters); -- cgit v0.12