diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-12 02:05:28 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-12 02:05:28 (GMT) |
commit | 7c0960a479a250d4c6b46d6fe094ab93564e515b (patch) | |
tree | 6d6fd1009c2239c588925fe914473197726bde14 | |
parent | 350d455677d928d5154ebf9e33328423c8aa012d (diff) | |
parent | 7a3557acf5e0a9570e7e7e033a096eef5ca87055 (diff) | |
download | Qt-7c0960a479a250d4c6b46d6fe094ab93564e515b.zip Qt-7c0960a479a250d4c6b46d6fe094ab93564e515b.tar.gz Qt-7c0960a479a250d4c6b46d6fe094ab93564e515b.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r-- | demos/declarative/flickr/flickr.qml | 4 | ||||
-rw-r--r-- | doc/src/declarative/qtdeclarative.qdoc | 1 | ||||
-rw-r--r-- | doc/src/declarative/qtprogrammers.qdoc | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.cpp | 23 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.h | 4 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit_p.h | 5 | ||||
-rw-r--r-- | src/declarative/util/qfxview.cpp | 17 | ||||
-rw-r--r-- | src/declarative/util/qfxview.h | 2 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 70 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.h | 6 |
10 files changed, 95 insertions, 42 deletions
diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml index fa3bc35..829f568 100644 --- a/demos/declarative/flickr/flickr.qml +++ b/demos/declarative/flickr/flickr.qml @@ -119,8 +119,10 @@ Item { Item { id: Background + + anchors.fill: parent - Image { source: "content/pics/background.png"; opaque: true } + Image { source: "content/pics/background.png"; opaque: true; anchors.fill: parent } GridView { id: PhotoGridView; model: FeedModel; delegate: PhotoDelegate; cacheBuffer: 100 diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index 67605dc..4fe9994 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -86,7 +86,6 @@ C++ Reference: \list - \o \l {qtprogrammers}{QML for Qt programmers} \o \l {qtbinding}{C++ Data Binding} \o \l {cppitem}{C++ Components} \endlist diff --git a/doc/src/declarative/qtprogrammers.qdoc b/doc/src/declarative/qtprogrammers.qdoc index a79c671..6777724 100644 --- a/doc/src/declarative/qtprogrammers.qdoc +++ b/doc/src/declarative/qtprogrammers.qdoc @@ -1,4 +1,7 @@ -/*! +/* + + INCOMPLETE + \page qtprogrammers.html \target qtprogrammers \title QML for Qt programmers diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 74c9b5b..35b1173 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -430,6 +430,26 @@ void QFxTextEdit::setCursorVisible(bool on) d->control->processEvent(&focusEvent, QPointF(0, 0)); } +/*! + \qmlproperty bool TextEdit::focusOnPress + + Whether the TextEdit should gain focus on a mouse press. By default this is + set to false; +*/ +bool QFxTextEdit::focusOnPress() const +{ + Q_D(const QFxTextEdit); + return d->focusOnPress; +} + +void QFxTextEdit::setFocusOnPress(bool on) +{ + Q_D(QFxTextEdit); + if (d->focusOnPress == on) + return; + d->focusOnPress = on; +} + void QFxTextEdit::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { @@ -643,6 +663,7 @@ void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) void QFxTextEdit::focusChanged(bool hasFocus) { Q_D(QFxTextEdit); + setCursorVisible(hasFocus); } /*! @@ -684,6 +705,8 @@ Handles the given mouse \a event. void QFxTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QFxTextEdit); + if (d->focusOnPress) + setFocus(true); QMouseEvent *me = sceneMouseEventToMouseEvent(event); d->control->processEvent(me, QPointF(0, 0)); event->setAccepted(me->isAccepted()); diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index 5d95cd1..0aaa17b 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -77,6 +77,7 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) + Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) Q_CLASSINFO("DefaultProperty", "text") public: @@ -127,6 +128,9 @@ public: bool isCursorVisible() const; void setCursorVisible(bool on); + bool focusOnPress() const; + void setFocusOnPress(bool on); + virtual void dump(int depth); virtual QString propertyInfo() const; diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index dd2a1bf..a9b7237 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -68,7 +68,9 @@ class QFxTextEditPrivate : public QFxPaintedItemPrivate public: QFxTextEditPrivate() - : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), dirty(false), wrap(false), richText(false), cursorVisible(false), format(QFxTextEdit::AutoText), document(0) + : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), + dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), + format(QFxTextEdit::AutoText), document(0) { } @@ -95,6 +97,7 @@ public: bool wrap; bool richText; bool cursorVisible; + bool focusOnPress; QFxTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp index 078916b..e17decf 100644 --- a/src/declarative/util/qfxview.cpp +++ b/src/declarative/util/qfxview.cpp @@ -105,6 +105,8 @@ public: QmlComponent *component; QBasicTimer resizetimer; + QSize initialSize; + void init(); }; @@ -137,6 +139,7 @@ public: QFxView::QFxView(QWidget *parent) : QSimpleCanvas(parent), d(new QFxViewPrivate(this)) { + setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); d->init(); } @@ -150,6 +153,7 @@ QFxView::QFxView(QWidget *parent) QFxView::QFxView(QSimpleCanvas::CanvasMode mode, QWidget *parent) : QSimpleCanvas(mode, parent), d(new QFxViewPrivate(this)) { + setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); d->init(); } @@ -381,10 +385,23 @@ void QFxView::timerEvent(QTimerEvent* e) if (d->root) emit sceneResized(QSize(d->root->width(),d->root->height())); d->resizetimer.stop(); + updateGeometry(); } } /*! + The size hint is the size of the root item. +*/ +QSize QFxView::sizeHint() const +{ + if (d->initialSize.width() <= 0) + d->initialSize.setWidth(d->root->width()); + if (d->initialSize.height() <= 0) + d->initialSize.setHeight(d->root->height()); + return d->initialSize; +} + +/*! Creates a \l{QmlComponent} {component} from the \a qml string, and returns it as an \l {QFxItem} {item}. If the \a parent item is provided, it becomes the new item's diff --git a/src/declarative/util/qfxview.h b/src/declarative/util/qfxview.h index f575f27..d6f786c 100644 --- a/src/declarative/util/qfxview.h +++ b/src/declarative/util/qfxview.h @@ -82,6 +82,8 @@ public: virtual QFxItem *root() const; + QSize sizeHint() const; + void dumpRoot(); static void printErrorLine(const QmlError &); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 8457972..bd52b46 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -49,27 +49,34 @@ QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, Q record_autotime = 0; record_period = 20; - int width = 240; - int height = 320; - setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_NoSystemBackground); if (!(flags & Qt::FramelessWindowHint)) - createMenuBar(); + createMenu(menuBar(),0); canvas = new QFxView(this); if(testMode != QFxTestEngine::NoTest) testEngine = new QFxTestEngine(testMode, testDir, canvas, this); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); - canvas->setFixedSize(width, height); - resize(width, height); + setCentralWidget(canvas); } -void QmlViewer::createMenuBar() +QSize QmlViewer::sizeHint() const { - QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + if (skin) + return QMainWindow::sizeHint(); + else { + QSize sh = canvas->sizeHint(); + sh.setHeight(sh.height()+menuBar()->sizeHint().height()); + return sh; + } +} + +void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) +{ + QMenu *fileMenu = flatmenu ? flatmenu : menu->addMenu(tr("&File")); QAction *openAction = new QAction(tr("&Open..."), this); openAction->setShortcut(QKeySequence("Ctrl+O")); @@ -81,13 +88,9 @@ void QmlViewer::createMenuBar() connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); fileMenu->addAction(reloadAction); - QAction *quitAction = new QAction(tr("&Quit"), this); - quitAction->setShortcut(QKeySequence("Ctrl+Q")); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - fileMenu->addSeparator(); - fileMenu->addAction(quitAction); + if (flatmenu) flatmenu->addSeparator(); - QMenu *recordMenu = menuBar()->addMenu(tr("&Recording")); + QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording")); QAction *snapshotAction = new QAction(tr("&Take Snapsot\tF3"), this); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); @@ -97,10 +100,19 @@ void QmlViewer::createMenuBar() connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection())); recordMenu->addAction(recordAction); - QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); + if (flatmenu) flatmenu->addSeparator(); + + QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help")); QAction *aboutAction = new QAction(tr("&About Qt..."), this); connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); helpMenu->addAction(aboutAction); + + QAction *quitAction = new QAction(tr("&Quit"), this); + quitAction->setShortcut(QKeySequence("Ctrl+Q")); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + fileMenu->addSeparator(); + fileMenu->addAction(quitAction); + } void QmlViewer::takeSnapShot() @@ -216,13 +228,14 @@ public: setTransform(fit); } + QMenu* menu; + private slots: void slotSkinKeyPressEvent(int code, const QString& text, bool autorep); void slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep); void slotPopupMenu(); private: - void populateContextMenu(QMenu *menu); const QSize m_screenSize; }; @@ -231,6 +244,7 @@ PreviewDeviceSkin::PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWi DeviceSkin(parameters, parent), m_screenSize(parameters.screenSize()) { + menu = new QMenu(this); connect(this, SIGNAL(skinKeyPressEvent(int,QString,bool)), this, SLOT(slotSkinKeyPressEvent(int,QString,bool))); connect(this, SIGNAL(skinKeyReleaseEvent(int,QString,bool)), @@ -265,14 +279,7 @@ void PreviewDeviceSkin::slotSkinKeyReleaseEvent(int code, const QString& text, b void PreviewDeviceSkin::slotPopupMenu() { - QMenu menu(this); - populateContextMenu(&menu); - menu.exec(QCursor::pos()); -} - -void PreviewDeviceSkin::populateContextMenu(QMenu *menu) -{ - connect(menu->addAction(tr("&Close")), SIGNAL(triggered()), parentWidget(), SLOT(close())); + menu->exec(QCursor::pos()); } void QmlViewer::setSkin(const QString& skinDirectory) @@ -283,12 +290,13 @@ void QmlViewer::setSkin(const QString& skinDirectory) delete skin; if (!err.isEmpty()) qWarning() << err; + delete menuBar(); skin = new PreviewDeviceSkin(parameters,this); - skin->setScreenSize(canvas->size()); + skin->setScreenSize(canvas->sizeHint()); canvas->setParent(skin, Qt::SubWindow); canvas->setAutoFillBackground(true); skin->setView(canvas); - delete layout(); + createMenu(0,skin->menu); canvas->show(); } @@ -318,21 +326,11 @@ void QmlViewer::setRecordPeriod(int ms) void QmlViewer::sceneResized(QSize size) { if (size.width() > 0 && size.height() > 0) { - canvas->setFixedSize(size.width(), size.height()); if (skin) skin->setScreenSize(size); - else - resize(size); } } -void QmlViewer::resizeEvent(QResizeEvent *e) -{ - QMainWindow::resizeEvent(e); - //if (!skin) - //canvas->setFixedSize(width(),height()); -} - void QmlViewer::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_0 && devicemode) diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index fc8a427..3f17912 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -31,7 +31,6 @@ Q_OBJECT public: QmlViewer(QFxTestEngine::TestMode = QFxTestEngine::NoTest, const QString &testDir = QString(), QWidget *parent=0, Qt::WindowFlags flags=0); - void createMenuBar(); void setRecordDither(const QString& s) { record_dither = s; } void setRecordPeriod(int ms); void setRecordFile(const QString&); @@ -43,6 +42,8 @@ public: void setDeviceKeys(bool); void setCacheEnabled(bool); + QSize sizeHint() const; + public slots: void sceneResized(QSize size); void openQml(const QString& fileName); @@ -55,7 +56,8 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual void timerEvent(QTimerEvent *); - virtual void resizeEvent(QResizeEvent *); + + void createMenu(QMenuBar *menu, QMenu *flatmenu); private: QString currentFileName; |