From 7184c41453c64f177f337b173f4ca82afead731d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 27 May 2010 19:16:08 +1000 Subject: Rename QDeclarativeDebugTiming -> QDeclarativeDebugTrace --- src/declarative/debugger/debugger.pri | 4 +- .../debugger/qdeclarativedebugtiming.cpp | 95 ------------------ .../debugger/qdeclarativedebugtiming_p.h | 96 ------------------ .../debugger/qdeclarativedebugtrace.cpp | 110 +++++++++++++++++++++ .../debugger/qdeclarativedebugtrace_p.h | 101 +++++++++++++++++++ src/declarative/qml/qdeclarativecomponent.cpp | 7 +- src/declarative/util/qdeclarativeview.cpp | 18 ++-- 7 files changed, 226 insertions(+), 205 deletions(-) delete mode 100644 src/declarative/debugger/qdeclarativedebugtiming.cpp delete mode 100644 src/declarative/debugger/qdeclarativedebugtiming_p.h create mode 100644 src/declarative/debugger/qdeclarativedebugtrace.cpp create mode 100644 src/declarative/debugger/qdeclarativedebugtrace_p.h diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 6777868..33d0843 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -6,7 +6,7 @@ SOURCES += \ $$PWD/qdeclarativedebugservice.cpp \ $$PWD/qdeclarativedebugclient.cpp \ $$PWD/qdeclarativedebug.cpp \ - $$PWD/qdeclarativedebugtiming.cpp + $$PWD/qdeclarativedebugtrace.cpp HEADERS += \ $$PWD/qdeclarativedebuggerstatus_p.h \ @@ -14,4 +14,4 @@ HEADERS += \ $$PWD/qdeclarativedebugservice_p.h \ $$PWD/qdeclarativedebugclient_p.h \ $$PWD/qdeclarativedebug_p.h \ - $$PWD/qdeclarativedebugtiming_p.h + $$PWD/qdeclarativedebugtrace_p.h diff --git a/src/declarative/debugger/qdeclarativedebugtiming.cpp b/src/declarative/debugger/qdeclarativedebugtiming.cpp deleted file mode 100644 index 5b93852..0000000 --- a/src/declarative/debugger/qdeclarativedebugtiming.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** 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$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativedebugtiming_p.h" - -#include - -Q_GLOBAL_STATIC(QDeclarativeDebugTiming, timerInstance); - -QDeclarativeDebugTiming::QDeclarativeDebugTiming() -: QDeclarativeDebugService(QLatin1String("CanvasFrameRate")) -{ - m_timer.start(); -} - -void QDeclarativeDebugTiming::addEvent(EventType t) -{ - if (QDeclarativeDebugService::isDebuggingEnabled()) - timerInstance()->addEventImpl(t); -} - -void QDeclarativeDebugTiming::startRange(RangeType t) -{ - if (QDeclarativeDebugService::isDebuggingEnabled()) - timerInstance()->startRangeImpl(t); -} - -void QDeclarativeDebugTiming::endRange(RangeType t) -{ - if (QDeclarativeDebugService::isDebuggingEnabled()) - timerInstance()->endRangeImpl(t); -} - -void QDeclarativeDebugTiming::addEventImpl(EventType event) -{ - QByteArray data; - QDataStream ds(&data, QIODevice::WriteOnly); - ds << m_timer.elapsed() << (int)Event << (int)event; - sendMessage(data); -} - -void QDeclarativeDebugTiming::startRangeImpl(RangeType range) -{ - QByteArray data; - QDataStream ds(&data, QIODevice::WriteOnly); - ds << m_timer.elapsed() << (int)RangeStart << (int)range; - sendMessage(data); -} - -void QDeclarativeDebugTiming::endRangeImpl(RangeType range) -{ - QByteArray data; - QDataStream ds(&data, QIODevice::WriteOnly); - ds << m_timer.elapsed() << (int)RangeEnd << (int)range; - sendMessage(data); -} - diff --git a/src/declarative/debugger/qdeclarativedebugtiming_p.h b/src/declarative/debugger/qdeclarativedebugtiming_p.h deleted file mode 100644 index d9ed67c..0000000 --- a/src/declarative/debugger/qdeclarativedebugtiming_p.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** 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$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEDEBUGTIMING_P_H -#define QDECLARATIVEDEBUGTIMING_P_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QDeclarativeDebugTiming : public QDeclarativeDebugService -{ -public: - enum EventType { - FramePaint, - Mouse, - Key, - - MaximumEventType - }; - - enum Message { - Event, - RangeStart, - RangeEnd, - - MaximumMessage - }; - - enum RangeType { - Painting, - Compiling, - Creating, - - MaximumRangeType - }; - - static void addEvent(EventType); - static void startRange(RangeType); - static void endRange(RangeType); - - QDeclarativeDebugTiming(); -private: - void addEventImpl(EventType); - void startRangeImpl(RangeType); - void endRangeImpl(RangeType); - QElapsedTimer m_timer; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECLARATIVEDEBUGTIMING_P_H - diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp new file mode 100644 index 0000000..5e6d5e7 --- /dev/null +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativedebugtrace_p.h" + +#include +#include + +Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance); + +QDeclarativeDebugTrace::QDeclarativeDebugTrace() +: QDeclarativeDebugService(QLatin1String("CanvasFrameRate")) +{ + m_timer.start(); +} + +void QDeclarativeDebugTrace::addEvent(EventType t) +{ + if (QDeclarativeDebugService::isDebuggingEnabled()) + traceInstance()->addEventImpl(t); +} + +void QDeclarativeDebugTrace::startRange(RangeType t) +{ + if (QDeclarativeDebugService::isDebuggingEnabled()) + traceInstance()->startRangeImpl(t); +} + +void QDeclarativeDebugTrace::rangeData(RangeType t, const QUrl &url) +{ + if (QDeclarativeDebugService::isDebuggingEnabled()) + traceInstance()->rangeDataImpl(t, url); +} + +void QDeclarativeDebugTrace::endRange(RangeType t) +{ + if (QDeclarativeDebugService::isDebuggingEnabled()) + traceInstance()->endRangeImpl(t); +} + +void QDeclarativeDebugTrace::addEventImpl(EventType event) +{ + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << m_timer.elapsed() << (int)Event << (int)event; + sendMessage(data); +} + +void QDeclarativeDebugTrace::startRangeImpl(RangeType range) +{ + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << m_timer.elapsed() << (int)RangeStart << (int)range; + sendMessage(data); +} + +void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QUrl &u) +{ + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << m_timer.elapsed() << (int)RangeData << (int)range << (QString)u.toString(); + sendMessage(data); +} + +void QDeclarativeDebugTrace::endRangeImpl(RangeType range) +{ + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << m_timer.elapsed() << (int)RangeEnd << (int)range; + sendMessage(data); +} + diff --git a/src/declarative/debugger/qdeclarativedebugtrace_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h new file mode 100644 index 0000000..5ba49a8 --- /dev/null +++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEDEBUGTRACE_P_H +#define QDECLARATIVEDEBUGTRACE_P_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QUrl; +class QDeclarativeDebugTrace : public QDeclarativeDebugService +{ +public: + enum EventType { + FramePaint, + Mouse, + Key, + + MaximumEventType + }; + + enum Message { + Event, + RangeStart, + RangeData, + RangeEnd, + + MaximumMessage + }; + + enum RangeType { + Painting, + Compiling, + Creating, + + MaximumRangeType + }; + + static void addEvent(EventType); + + static void startRange(RangeType); + static void rangeData(RangeType, const QUrl &); + static void endRange(RangeType); + + QDeclarativeDebugTrace(); +private: + void addEventImpl(EventType); + void startRangeImpl(RangeType); + void rangeDataImpl(RangeType, const QUrl &); + void endRangeImpl(RangeType); + QElapsedTimer m_timer; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEDEBUGTRACE_P_H + diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 2dc2d2d..9847079 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -53,7 +53,7 @@ #include "private/qdeclarativebinding_p_p.h" #include "private/qdeclarativeglobal_p.h" #include "private/qdeclarativescriptparser_p.h" -#include "private/qdeclarativedebugtiming_p.h" +#include "private/qdeclarativedebugtrace_p.h" #include #include @@ -696,7 +696,8 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons bool isRoot = !ep->inBeginCreate; if (isRoot) - QDeclarativeDebugTiming::startRange(QDeclarativeDebugTiming::Creating); + QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::Creating); + QDeclarativeDebugTrace::rangeData(QDeclarativeDebugTrace::Creating, cc->url); QDeclarativeContextData *ctxt = new QDeclarativeContextData; ctxt->isInternal = true; @@ -867,7 +868,7 @@ void QDeclarativeComponentPrivate::completeCreate() QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); complete(ep, &state); - QDeclarativeDebugTiming::endRange(QDeclarativeDebugTiming::Creating); + QDeclarativeDebugTrace::endRange(QDeclarativeDebugTrace::Creating); } } diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index d2dab76..6059ad6 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include @@ -93,35 +93,35 @@ QDeclarativeScene::QDeclarativeScene() void QDeclarativeScene::keyPressEvent(QKeyEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Key); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Key); QGraphicsScene::keyPressEvent(e); } void QDeclarativeScene::keyReleaseEvent(QKeyEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Key); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Key); QGraphicsScene::keyReleaseEvent(e); } void QDeclarativeScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Mouse); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); QGraphicsScene::mouseMoveEvent(e); } void QDeclarativeScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Mouse); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); QGraphicsScene::mousePressEvent(e); } void QDeclarativeScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::Mouse); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); QGraphicsScene::mouseReleaseEvent(e); } @@ -675,8 +675,8 @@ void QDeclarativeView::paintEvent(QPaintEvent *event) { Q_D(QDeclarativeView); - QDeclarativeDebugTiming::addEvent(QDeclarativeDebugTiming::FramePaint); - QDeclarativeDebugTiming::startRange(QDeclarativeDebugTiming::Painting); + QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::FramePaint); + QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::Painting); int time = 0; if (frameRateDebug()) @@ -684,7 +684,7 @@ void QDeclarativeView::paintEvent(QPaintEvent *event) QGraphicsView::paintEvent(event); - QDeclarativeDebugTiming::endRange(QDeclarativeDebugTiming::Painting); + QDeclarativeDebugTrace::endRange(QDeclarativeDebugTrace::Painting); if (frameRateDebug()) qDebug() << "paintEvent:" << d->frameTimer.elapsed() << "time since last frame:" << time; -- cgit v0.12 From bc1d00de820abc0697e51315d8231cadbce9f9dd Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 28 May 2010 11:20:38 +1000 Subject: Rename example layoutItem -> layoutitem and improve docs --- doc/src/examples/qml-examples.qdoc | 8 +-- .../qgraphicslayouts/layoutItem/layoutItem.pro | 8 --- .../qgraphicslayouts/layoutItem/layoutItem.qml | 57 ----------------- .../layoutItem/layoutItem.qmlproject | 16 ----- .../qgraphicslayouts/layoutItem/layoutItem.qrc | 5 -- .../qgraphicslayouts/layoutItem/main.cpp | 74 ---------------------- .../qgraphicslayouts/layoutitem/layoutitem.pro | 8 +++ .../qgraphicslayouts/layoutitem/layoutitem.qml | 57 +++++++++++++++++ .../layoutitem/layoutitem.qmlproject | 16 +++++ .../qgraphicslayouts/layoutitem/layoutitem.qrc | 5 ++ .../qgraphicslayouts/layoutitem/main.cpp | 74 ++++++++++++++++++++++ .../graphicsitems/qdeclarativelayoutitem.cpp | 11 ++-- 12 files changed, 170 insertions(+), 169 deletions(-) delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.pro create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qml create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qmlproject create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qrc create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index 56ba1c7..9f69bbf 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -117,10 +117,10 @@ like QGraphicsLayoutItem, QGraphicsLinearLayout and QGraphicsGridLayout into QML. */ /*! - \title Layout Item - \example declarative/cppextensions/qgraphicslayouts/layoutItem + \title LayoutItem + \example declarative/cppextensions/qgraphicslayouts/layoutitem - This example show how to integrate QML into an existing + This example show how to use the LayoutItem element to integrate QML items into an existing \l{Graphics View Framework}{Graphics View}-based application. */ /*! @@ -132,7 +132,7 @@ \list \o \l{declarative/cppextensions/qgraphicslayouts/graphicsLayouts}{Graphics Layouts} - \o \l{declarative/cppextensions/qgraphicslayouts/layoutItem}{Layout Item} + \o \l{declarative/cppextensions/qgraphicslayouts/layoutitem}{LayoutItem} \endlist */ diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro deleted file mode 100644 index c85a400..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro +++ /dev/null @@ -1,8 +0,0 @@ -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . -QT += declarative - -SOURCES += main.cpp -RESOURCES += layoutItem.qrc diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml deleted file mode 100644 index 6f377c5..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** 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:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 - -LayoutItem { //Sized by the layout - id: resizable - - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - - Rectangle { color: "yellow"; anchors.fill: parent } - - Rectangle { - width: 100; height: 100 - anchors.top: parent.top; anchors.right: parent.right - color: "green" - } -} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc deleted file mode 100644 index deb0fba..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - layoutItem.qml - - diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp deleted file mode 100644 index ef927d1..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -/* This example demonstrates using a LayoutItem to let QML snippets integrate - nicely with existing QGraphicsView applications designed with GraphicsLayouts -*/ -int main(int argc, char* argv[]) -{ - QApplication app(argc, argv); - - //Set up a graphics scene with a QGraphicsWidget and Layout - QGraphicsView view; - QGraphicsScene scene; - QGraphicsWidget *widget = new QGraphicsWidget(); - QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(); - widget->setLayout(layout); - scene.addItem(widget); - view.setScene(&scene); - - //Add the QML snippet into the layout - QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl(":layoutItem.qml")); - QGraphicsLayoutItem* obj = qobject_cast(c.create()); - layout->addItem(obj); - - widget->setGeometry(QRectF(0,0, 400,400)); - view.show(); - return app.exec(); -} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.pro b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.pro new file mode 100644 index 0000000..77c6b2a --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +SOURCES += main.cpp +RESOURCES += layoutitem.qrc diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qml b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qml new file mode 100644 index 0000000..6f377c5 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 + +LayoutItem { //Sized by the layout + id: resizable + + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + + Rectangle { color: "yellow"; anchors.fill: parent } + + Rectangle { + width: 100; height: 100 + anchors.top: parent.top; anchors.right: parent.right + color: "green" + } +} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ " ../exampleplugin " ] +} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qrc b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qrc new file mode 100644 index 0000000..2e52578 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/layoutitem.qrc @@ -0,0 +1,5 @@ + + + layoutitem.qml + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp new file mode 100644 index 0000000..ef927d1 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/* This example demonstrates using a LayoutItem to let QML snippets integrate + nicely with existing QGraphicsView applications designed with GraphicsLayouts +*/ +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + //Set up a graphics scene with a QGraphicsWidget and Layout + QGraphicsView view; + QGraphicsScene scene; + QGraphicsWidget *widget = new QGraphicsWidget(); + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(); + widget->setLayout(layout); + scene.addItem(widget); + view.setScene(&scene); + + //Add the QML snippet into the layout + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl(":layoutItem.qml")); + QGraphicsLayoutItem* obj = qobject_cast(c.create()); + layout->addItem(obj); + + widget->setGeometry(QRectF(0,0, 400,400)); + view.show(); + return app.exec(); +} diff --git a/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp b/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp index c8ecbb6..4add66d 100644 --- a/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp @@ -50,20 +50,21 @@ QT_BEGIN_NAMESPACE /*! \qmlclass LayoutItem QDeclarativeLayoutItem \since 4.7 - \brief The LayoutItem element allows you to place your declarative UI elements inside a classical Qt layout. + \brief The LayoutItem element allows declarative UI elements to be placed inside Qt's Graphics View layouts. - LayoutItem is a variant of Item with a couple of additional properties. These properties provide the size hints - needed for items to work in conjunction with Qt Layouts. The Qt Layout will resize the LayoutItem as appropriate, + LayoutItem is a variant of \l Item with additional size hint properties. These properties provide the size hints + necessary for items to work in conjunction with Qt \l{Graphics View Framework}{Graphics View} layout classes + such as QGraphicsLinearLayout and QGraphicsGridLayout. The Qt layout mechanisms will resize the LayoutItem as appropriate, taking its size hints into account, and you can propagate this to the other elements in your UI via anchors and bindings. - This is a QGraphicsLayoutItem subclass, and the properties merely expose the QGraphicsLayoutItem functionality to QML. + This is a QGraphicsLayoutItem subclass, and its properties merely expose the QGraphicsLayoutItem functionality to QML. See the QGraphicsLayoutItem documentation for further details. */ /*! \internal \class QDeclarativeLayoutItem - \brief The QDeclarativeLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. + \brief The QDeclarativeLayoutItem class allows you to place your QML UI elements inside Qt's Graphics View layouts. */ -- cgit v0.12 From b64f49b7c97aa905cde93a943f56eca20475678e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 28 May 2010 17:24:32 +1000 Subject: Split graphicsLayouts example into qgraphicslinearlayout and qgraphicsgridlayout and clean up --- doc/src/examples/qml-examples.qdoc | 26 +- .../graphicsLayouts/graphicsLayouts.pro | 13 - .../graphicsLayouts/graphicsLayouts.qmlproject | 16 - .../graphicsLayouts/graphicslayouts.cpp | 365 --------------------- .../graphicsLayouts/graphicslayouts.qml | 117 ------- .../graphicsLayouts/graphicslayouts.qrc | 5 - .../graphicsLayouts/graphicslayouts_p.h | 302 ----------------- .../qgraphicslayouts/graphicsLayouts/main.cpp | 59 ---- .../qgraphicsgridlayout/.main.cpp.swo | Bin 0 -> 12288 bytes .../qgraphicsgridlayout/gridlayout.cpp | 180 ++++++++++ .../qgraphicsgridlayout/gridlayout.h | 215 ++++++++++++ .../qgraphicsgridlayout/gridlayout.qrc | 6 + .../qgraphicslayouts/qgraphicsgridlayout/main.cpp | 63 ++++ .../qgraphicsgridlayout/qgraphicsgridlayout.pro | 15 + .../qgraphicsgridlayout/qgraphicsgridlayout.qml | 98 ++++++ .../qgraphicslinearlayout/linearlayout.cpp | 167 ++++++++++ .../qgraphicslinearlayout/linearlayout.h | 150 +++++++++ .../qgraphicslinearlayout/linearlayout.qrc | 6 + .../qgraphicslinearlayout/main.cpp | 64 ++++ .../qgraphicslinearlayout.pro | 15 + .../qgraphicslinearlayout.qml | 68 ++++ 21 files changed, 1065 insertions(+), 885 deletions(-) delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index 9f69bbf..035628e 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -110,13 +110,6 @@ */ /*! - \title Graphics Layouts - \example declarative/cppextensions/qgraphicslayouts/graphicsLayouts - - This example show how to integrate Qt \l{Graphics View Framework}{Graphics View} components - like QGraphicsLayoutItem, QGraphicsLinearLayout and QGraphicsGridLayout into QML. -*/ -/*! \title LayoutItem \example declarative/cppextensions/qgraphicslayouts/layoutitem @@ -124,6 +117,22 @@ \l{Graphics View Framework}{Graphics View}-based application. */ /*! + \title QGraphicsGridLayout + \example declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout + + This example shows how to use QGraphicsGridLayout to lay out QML items. This is + useful if you need to integrate Qt \l{Graphics View Framework}{Graphics View} layouts with + QML. +*/ +/*! + \title QGraphicsLinearLayout + \example declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout + + This example shows how to use QGraphicsLinearLayout to lay out QML items. This is + useful if you need to integrate Qt \l{Graphics View Framework}{Graphics View} layouts with + QML. +*/ +/*! \page declarative-cppextensions-qgraphicslayouts.html \title C++ Extensions: QGraphicsLayouts @@ -131,8 +140,9 @@ layout components with QML: \list - \o \l{declarative/cppextensions/qgraphicslayouts/graphicsLayouts}{Graphics Layouts} \o \l{declarative/cppextensions/qgraphicslayouts/layoutitem}{LayoutItem} + \o \l{declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout}{QGraphicsGridLayout} + \o \l{declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout}{QGraphicsLinearLayout} \endlist */ diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro deleted file mode 100644 index e5d91b2..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = app -TARGET = graphicslayouts -QT += declarative - -SOURCES += \ - graphicslayouts.cpp \ - main.cpp - -HEADERS += \ - graphicslayouts_p.h - -RESOURCES += \ - graphicslayouts.qrc diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp deleted file mode 100644 index 40e286d..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/**************************************************************************** -** -** 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:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "graphicslayouts_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -LinearLayoutAttached::LinearLayoutAttached(QObject *parent) -: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter), _spacing(0) -{ -} - -void LinearLayoutAttached::setStretchFactor(int f) -{ - if (_stretch == f) - return; - - _stretch = f; - emit stretchChanged(reinterpret_cast(parent()), _stretch); -} - -void LinearLayoutAttached::setSpacing(int s) -{ - if (_spacing == s) - return; - - _spacing = s; - emit spacingChanged(reinterpret_cast(parent()), _spacing); -} - -void LinearLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast(parent()), _alignment); -} - -QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) - : QObject(parent) -{ -} - -QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const -{ -Q_UNUSED(which); -Q_UNUSED(constraint); -return QSizeF(); -} - - -QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() -{ -} - -void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) -{ -insertItem(index, item); - -//connect attached properties -if (LinearLayoutAttached *obj = attachedProperties.value(item)) { - setStretchFactor(item, obj->stretchFactor()); - setAlignment(item, obj->alignment()); - updateSpacing(item, obj->spacing()); - QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), - this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); - QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), - this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); - QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), - this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); - //### need to disconnect when widget is removed? -} -} - -//### is there a better way to do this? -void QGraphicsLinearLayoutObject::clearChildren() -{ -for (int i = 0; i < count(); ++i) - removeAt(i); -} - -qreal QGraphicsLinearLayoutObject::contentsMargin() const -{ - qreal a,b,c,d; - getContentsMargins(&a, &b, &c, &d); - if(a==b && a==c && a==d) - return a; - return -1; -} - -void QGraphicsLinearLayoutObject::setContentsMargin(qreal m) -{ - setContentsMargins(m,m,m,m); -} - -void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) -{ -QGraphicsLinearLayout::setStretchFactor(item, stretch); -} - -void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) -{ - for(int i=0; i < count(); i++){ - if(itemAt(i) == item){ //I do not see the reverse function, which is why we must loop over all items - QGraphicsLinearLayout::setItemSpacing(i, spacing); - return; - } - } -} - -void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsLinearLayout::setAlignment(item, alignment); -} - -QHash QGraphicsLinearLayoutObject::attachedProperties; -LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -LinearLayoutAttached *rv = new LinearLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -////////////////////////////////////////////////////////////////////////////////////////////////////// -// QGraphicsGridLayout-related classes -////////////////////////////////////////////////////////////////////////////////////////////////////// -GridLayoutAttached::GridLayoutAttached(QObject *parent) -: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1), _rowstretch(-1), - _colstretch(-1), _rowspacing(-1), _colspacing(-1), _rowprefheight(-1), _rowmaxheight(-1), _rowminheight(-1), - _rowfixheight(-1), _colprefwidth(-1), _colmaxwidth(-1), _colminwidth(-1), _colfixwidth(-1) -{ -} - -void GridLayoutAttached::setRow(int r) -{ - if (_row == r) - return; - - _row = r; - //emit rowChanged(reinterpret_cast(parent()), _row); -} - -void GridLayoutAttached::setColumn(int c) -{ - if (_column == c) - return; - - _column = c; - //emit columnChanged(reinterpret_cast(parent()), _column); -} - -void GridLayoutAttached::setRowSpan(int rs) -{ - if (_rowspan == rs) - return; - - _rowspan = rs; - //emit rowSpanChanged(reinterpret_cast(parent()), _rowSpan); -} - -void GridLayoutAttached::setColumnSpan(int cs) -{ - if (_colspan == cs) - return; - - _colspan = cs; - //emit columnSpanChanged(reinterpret_cast(parent()), _columnSpan); -} - -void GridLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast(parent()), _alignment); -} - -void GridLayoutAttached::setRowStretchFactor(int f) -{ - _rowstretch = f; -} - -void GridLayoutAttached::setColumnStretchFactor(int f) -{ - _colstretch = f; -} - -void GridLayoutAttached::setRowSpacing(int s) -{ - _rowspacing = s; -} - -void GridLayoutAttached::setColumnSpacing(int s) -{ - _colspacing = s; -} - - -QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() -{ -} - -void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) -{ -//use attached properties -if (QObject *obj = attachedProperties.value(qobject_cast(wid))) { - int row = static_cast(obj)->row(); - int column = static_cast(obj)->column(); - int rowSpan = static_cast(obj)->rowSpan(); - int columnSpan = static_cast(obj)->columnSpan(); - if (row == -1 || column == -1) { - qWarning() << "Must set row and column for an item in a grid layout"; - return; - } - addItem(wid, row, column, rowSpan, columnSpan); -} -} - -void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) -{ -//use attached properties -if (GridLayoutAttached *obj = attachedProperties.value(item)) { - int row = obj->row(); - int column = obj->column(); - int rowSpan = obj->rowSpan(); - int columnSpan = obj->columnSpan(); - Qt::Alignment alignment = obj->alignment(); - if (row == -1 || column == -1) { - qWarning() << "Must set row and column for an item in a grid layout"; - return; - } - if(obj->rowSpacing() != -1) - setRowSpacing(row, obj->rowSpacing()); - if(obj->columnSpacing() != -1) - setColumnSpacing(column, obj->columnSpacing()); - if(obj->rowStretchFactor() != -1) - setRowStretchFactor(row, obj->rowStretchFactor()); - if(obj->columnStretchFactor() != -1) - setColumnStretchFactor(column, obj->columnStretchFactor()); - if(obj->rowPreferredHeight() != -1) - setRowPreferredHeight(row, obj->rowPreferredHeight()); - if(obj->rowMaximumHeight() != -1) - setRowMaximumHeight(row, obj->rowMaximumHeight()); - if(obj->rowMinimumHeight() != -1) - setRowMinimumHeight(row, obj->rowMinimumHeight()); - if(obj->rowFixedHeight() != -1) - setRowFixedHeight(row, obj->rowFixedHeight()); - if(obj->columnPreferredWidth() != -1) - setColumnPreferredWidth(row, obj->columnPreferredWidth()); - if(obj->columnMaximumWidth() != -1) - setColumnMaximumWidth(row, obj->columnMaximumWidth()); - if(obj->columnMinimumWidth() != -1) - setColumnMinimumWidth(row, obj->columnMinimumWidth()); - if(obj->columnFixedWidth() != -1) - setColumnFixedWidth(row, obj->columnFixedWidth()); - addItem(item, row, column, rowSpan, columnSpan); - if (alignment != -1) - setAlignment(item,alignment); - QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), - this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); - //### need to disconnect when widget is removed? -} -} - -//### is there a better way to do this? -void QGraphicsGridLayoutObject::clearChildren() -{ -for (int i = 0; i < count(); ++i) - removeAt(i); -} - -qreal QGraphicsGridLayoutObject::spacing() const -{ -if (verticalSpacing() == horizontalSpacing()) - return verticalSpacing(); -return -1; //### -} - -qreal QGraphicsGridLayoutObject::contentsMargin() const -{ - qreal a,b,c,d; - getContentsMargins(&a, &b, &c, &d); - if(a==b && a==c && a==d) - return a; - return -1; -} - -void QGraphicsGridLayoutObject::setContentsMargin(qreal m) -{ - setContentsMargins(m,m,m,m); -} - - -void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsGridLayout::setAlignment(item, alignment); -} - -QHash QGraphicsGridLayoutObject::attachedProperties; -GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -GridLayoutAttached *rv = new GridLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -QT_END_NAMESPACE diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml deleted file mode 100644 index 586f7f9..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** 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:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 -import GraphicsLayouts 4.7 - -Item { - id: resizable - - width: 800 - height: 400 - - QGraphicsWidget { - size.width: parent.width/2 - size.height: parent.height - - layout: QGraphicsLinearLayout { - LayoutItem { - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { color: "yellow"; anchors.fill: parent } - } - LayoutItem { - minimumSize: "100x100" - maximumSize: "400x400" - preferredSize: "200x200" - Rectangle { color: "green"; anchors.fill: parent } - } - } - } - QGraphicsWidget { - x: parent.width/2 - size.width: parent.width/2 - size.height: parent.height - - layout: QGraphicsGridLayout { - LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 0 - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { color: "red"; anchors.fill: parent } - } - LayoutItem { - QGraphicsGridLayout.row: 1 - QGraphicsGridLayout.column: 0 - minimumSize: "100x100" - maximumSize: "200x200" - preferredSize: "100x100" - Rectangle { color: "orange"; anchors.fill: parent } - } - LayoutItem { - QGraphicsGridLayout.row: 2 - QGraphicsGridLayout.column: 0 - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "200x200" - Rectangle { color: "yellow"; anchors.fill: parent } - } - LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "200x200" - preferredSize: "200x200" - Rectangle { color: "green"; anchors.fill: parent } - } - LayoutItem { - QGraphicsGridLayout.row: 1 - QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "400x400" - preferredSize: "200x200" - Rectangle { color: "blue"; anchors.fill: parent } - } - } - } -} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc deleted file mode 100644 index a199f8d..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - graphicslayouts.qml - - diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h deleted file mode 100644 index 7aa98df..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h +++ /dev/null @@ -1,302 +0,0 @@ -/**************************************************************************** -** -** 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:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GRAPHICSLAYOUTS_H -#define GRAPHICSLAYOUTS_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) -public: - QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); - - virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; -}; - -class LinearLayoutAttached; -class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsLinearLayoutObject(QObject * = 0); - ~QGraphicsLinearLayoutObject(); - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - static LinearLayoutAttached *qmlAttachedProperties(QObject *); - - qreal contentsMargin() const; - void setContentsMargin(qreal); - -private Q_SLOTS: - void updateStretch(QGraphicsLayoutItem*,int); - void updateSpacing(QGraphicsLayoutItem*,int); - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class LinearLayoutAttached; - void clearChildren(); - void insertLayoutItem(int, QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->insertLayoutItem(-1, item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); - } -}; - -class GridLayoutAttached; -class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) - Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) - Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsGridLayoutObject(QObject * = 0); - ~QGraphicsGridLayoutObject(); - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - qreal spacing() const; - qreal contentsMargin() const; - void setContentsMargin(qreal); - - static GridLayoutAttached *qmlAttachedProperties(QObject *); - -private Q_SLOTS: - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class GraphicsLayoutAttached; - void addWidget(QGraphicsWidget *); - void clearChildren(); - void addLayoutItem(QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->addLayoutItem(item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); - } -}; - -class LinearLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) -public: - LinearLayoutAttached(QObject *parent); - - int stretchFactor() const { return _stretch; } - void setStretchFactor(int f); - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - int spacing() const { return _spacing; } - void setSpacing(int s); - -Q_SIGNALS: - void stretchChanged(QGraphicsLayoutItem*,int); - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - void spacingChanged(QGraphicsLayoutItem*,int); - -private: - int _stretch; - Qt::Alignment _alignment; - int _spacing; -}; - -class GridLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int row READ row WRITE setRow) - Q_PROPERTY(int column READ column WRITE setColumn) - Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) - Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) - Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor) - Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) - Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight) - Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight) - Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight) - Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight) - Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth) - Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth) - Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth) - Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth) - -public: - GridLayoutAttached(QObject *parent); - - int row() const { return _row; } - void setRow(int r); - - int column() const { return _column; } - void setColumn(int c); - - int rowSpan() const { return _rowspan; } - void setRowSpan(int rs); - - int columnSpan() const { return _colspan; } - void setColumnSpan(int cs); - - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - - int rowStretchFactor() const { return _rowstretch; } - void setRowStretchFactor(int f); - int columnStretchFactor() const { return _colstretch; } - void setColumnStretchFactor(int f); - - int rowSpacing() const { return _rowspacing; } - void setRowSpacing(int s); - int columnSpacing() const { return _colspacing; } - void setColumnSpacing(int s); - - int rowPreferredHeight() const { return _rowprefheight; } - void setRowPreferredHeight(int s) { _rowprefheight = s; } - - int rowMaximumHeight() const { return _rowmaxheight; } - void setRowMaximumHeight(int s) { _rowmaxheight = s; } - - int rowMinimumHeight() const { return _rowminheight; } - void setRowMinimumHeight(int s) { _rowminheight = s; } - - int rowFixedHeight() const { return _rowfixheight; } - void setRowFixedHeight(int s) { _rowfixheight = s; } - - int columnPreferredWidth() const { return _colprefwidth; } - void setColumnPreferredWidth(int s) { _colprefwidth = s; } - - int columnMaximumWidth() const { return _colmaxwidth; } - void setColumnMaximumWidth(int s) { _colmaxwidth = s; } - - int columnMinimumWidth() const { return _colminwidth; } - void setColumnMinimumWidth(int s) { _colminwidth = s; } - - int columnFixedWidth() const { return _colfixwidth; } - void setColumnFixedWidth(int s) { _colfixwidth = s; } - -Q_SIGNALS: - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - -private: - int _row; - int _column; - int _rowspan; - int _colspan; - Qt::Alignment _alignment; - int _rowstretch; - int _colstretch; - int _rowspacing; - int _colspacing; - int _rowprefheight; - int _rowmaxheight; - int _rowminheight; - int _rowfixheight; - int _colprefwidth; - int _colmaxwidth; - int _colminwidth; - int _colfixwidth; -}; - -QT_END_NAMESPACE - -QML_DECLARE_INTERFACE(QGraphicsLayoutItem) -QML_DECLARE_INTERFACE(QGraphicsLayout) -QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) -QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QGraphicsGridLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif // GRAPHICSLAYOUTS_H diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp deleted file mode 100644 index b0a15fc..0000000 --- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include "graphicslayouts_p.h" -#include - -int main(int argc, char* argv[]) -{ - QApplication app(argc, argv); - QDeclarativeView view; - qmlRegisterInterface("QGraphicsLayoutItem"); - qmlRegisterInterface("QGraphicsLayout"); - qmlRegisterType("GraphicsLayouts",4,7,"QGraphicsLinearLayoutStretchItem"); - qmlRegisterType("GraphicsLayouts",4,7,"QGraphicsLinearLayout"); - qmlRegisterType("GraphicsLayouts",4,7,"QGraphicsGridLayout"); - view.setSource(QUrl(":graphicslayouts.qml")); - view.show(); - return app.exec(); -}; - diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo new file mode 100644 index 0000000..c742274 Binary files /dev/null and b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo differ diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp new file mode 100644 index 0000000..728c225 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gridlayout.h" + +#include +#include + +GridLayoutAttached::GridLayoutAttached(QObject *parent) +: QObject(parent), m_row(-1), m_column(-1), m_rowspan(1), m_colspan(1), m_alignment(-1), m_rowStretch(-1), + m_colStretch(-1), m_rowSpacing(-1), m_colSpacing(-1), m_rowPrefHeight(-1), m_rowMaxHeight(-1), m_rowMinHeight(-1), + m_rowFixHeight(-1), m_colPrefwidth(-1), m_colMaxwidth(-1), m_colMinwidth(-1), m_colFixwidth(-1) +{ +} + +void GridLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (m_alignment != a) { + m_alignment = a; + emit alignmentChanged(reinterpret_cast(parent()), m_alignment); + } +} + +QHash QGraphicsGridLayoutObject::attachedProperties; + +QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() +{ +} + +void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *widget) +{ + //use attached properties + if (QObject *obj = attachedProperties.value(qobject_cast(widget))) { + int row = static_cast(obj)->row(); + int column = static_cast(obj)->column(); + int rowSpan = static_cast(obj)->rowSpan(); + int columnSpan = static_cast(obj)->columnSpan(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + addItem(widget, row, column, rowSpan, columnSpan); + } +} + +void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) +{ + //use attached properties + if (GridLayoutAttached *obj = attachedProperties.value(item)) { + int row = obj->row(); + int column = obj->column(); + int rowSpan = obj->rowSpan(); + int columnSpan = obj->columnSpan(); + Qt::Alignment alignment = obj->alignment(); + + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + + if (obj->rowSpacing() != -1) + setRowSpacing(row, obj->rowSpacing()); + if (obj->columnSpacing() != -1) + setColumnSpacing(column, obj->columnSpacing()); + if (obj->rowStretchFactor() != -1) + setRowStretchFactor(row, obj->rowStretchFactor()); + if (obj->columnStretchFactor() != -1) + setColumnStretchFactor(column, obj->columnStretchFactor()); + if (obj->rowPreferredHeight() != -1) + setRowPreferredHeight(row, obj->rowPreferredHeight()); + if (obj->rowMaximumHeight() != -1) + setRowMaximumHeight(row, obj->rowMaximumHeight()); + if (obj->rowMinimumHeight() != -1) + setRowMinimumHeight(row, obj->rowMinimumHeight()); + if (obj->rowFixedHeight() != -1) + setRowFixedHeight(row, obj->rowFixedHeight()); + if (obj->columnPreferredWidth() != -1) + setColumnPreferredWidth(row, obj->columnPreferredWidth()); + if (obj->columnMaximumWidth() != -1) + setColumnMaximumWidth(row, obj->columnMaximumWidth()); + if (obj->columnMinimumWidth() != -1) + setColumnMinimumWidth(row, obj->columnMinimumWidth()); + if (obj->columnFixedWidth() != -1) + setColumnFixedWidth(row, obj->columnFixedWidth()); + + addItem(item, row, column, rowSpan, columnSpan); + + if (alignment != -1) + setAlignment(item, alignment); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*, Qt::Alignment))); + //### need to disconnect when widget is removed? Re-implement removeAt()? + } +} + +void QGraphicsGridLayoutObject::clearChildren() +{ + //### do I need to delete the removed items? And/or removed them from attachedProperties? + while (count() > 0) + removeAt(count()-1); +} + +qreal QGraphicsGridLayoutObject::spacing() const +{ + if (verticalSpacing() == horizontalSpacing()) + return verticalSpacing(); + return -1; //### +} + +qreal QGraphicsGridLayoutObject::contentsMargin() const +{ + qreal a, b, c, d; + getContentsMargins(&a, &b, &c, &d); + if (a == b && a == c && a == d) + return a; + return -1; +} + +void QGraphicsGridLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m, m, m, m); +} + +void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ + QGraphicsGridLayout::setAlignment(item, alignment); +} + +GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +{ + // ### This is not allowed - you must attach to any object + if (!qobject_cast(obj)) + return 0; + GridLayoutAttached *rv = new GridLayoutAttached(obj); + attachedProperties.insert(qobject_cast(obj), rv); + return rv; +} + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h new file mode 100644 index 0000000..04f0148 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h @@ -0,0 +1,215 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRIDLAYOUT_H +#define GRIDLAYOUT_H + +#include + +#include +#include + +class GridLayoutAttached; +class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) + Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) + Q_CLASSINFO("DefaultProperty", "children") + +public: + QGraphicsGridLayoutObject(QObject * = 0); + ~QGraphicsGridLayoutObject(); + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + qreal spacing() const; + qreal contentsMargin() const; + void setContentsMargin(qreal); + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private slots: + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class GraphicsLayoutAttached; + + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->addLayoutItem(item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } + + static QHash attachedProperties; +}; + + +class GridLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int row READ row WRITE setRow) + Q_PROPERTY(int column READ column WRITE setColumn) + + Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) + Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) + + Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor) + Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor) + Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) + Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) + + Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight) + Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight) + Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight) + Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight) + + Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth) + Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth) + Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth) + Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth) + +public: + GridLayoutAttached(QObject *parent); + + int row() const { return m_row; } + void setRow(int r) { m_row = r; } + + int column() const { return m_column; } + void setColumn(int c) { m_column = c; } + + int rowSpan() const { return m_rowspan; } + void setRowSpan(int rs) { m_rowspan = rs; } + + int columnSpan() const { return m_colspan; } + void setColumnSpan(int cs) { m_colspan = cs; } + + Qt::Alignment alignment() const { return m_alignment; } + void setAlignment(Qt::Alignment a); + + int rowStretchFactor() const { return m_rowStretch; } + void setRowStretchFactor(int f) { m_rowStretch = f; } + int columnStretchFactor() const { return m_colStretch; } + void setColumnStretchFactor(int f) { m_colStretch = f; } + + int rowSpacing() const { return m_rowSpacing; } + void setRowSpacing(int s) { m_rowSpacing = s; } + int columnSpacing() const { return m_colSpacing; } + void setColumnSpacing(int s) { m_colSpacing = s; } + + int rowPreferredHeight() const { return m_rowPrefHeight; } + void setRowPreferredHeight(int s) { m_rowPrefHeight = s; } + + int rowMaximumHeight() const { return m_rowMaxHeight; } + void setRowMaximumHeight(int s) { m_rowMaxHeight = s; } + + int rowMinimumHeight() const { return m_rowMinHeight; } + void setRowMinimumHeight(int s) { m_rowMinHeight = s; } + + int rowFixedHeight() const { return m_rowFixHeight; } + void setRowFixedHeight(int s) { m_rowFixHeight = s; } + + int columnPreferredWidth() const { return m_colPrefwidth; } + void setColumnPreferredWidth(int s) { m_colPrefwidth = s; } + + int columnMaximumWidth() const { return m_colMaxwidth; } + void setColumnMaximumWidth(int s) { m_colMaxwidth = s; } + + int columnMinimumWidth() const { return m_colMinwidth; } + void setColumnMinimumWidth(int s) { m_colMinwidth = s; } + + int columnFixedWidth() const { return m_colFixwidth; } + void setColumnFixedWidth(int s) { m_colFixwidth = s; } + +signals: + void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment); + +private: + int m_row; + int m_column; + + int m_rowspan; + int m_colspan; + Qt::Alignment m_alignment; + + int m_rowStretch; + int m_colStretch; + int m_rowSpacing; + int m_colSpacing; + + int m_rowPrefHeight; + int m_rowMaxHeight; + int m_rowMinHeight; + int m_rowFixHeight; + + int m_colPrefwidth; + int m_colMaxwidth; + int m_colMinwidth; + int m_colFixwidth; +}; + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(QGraphicsGridLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +#endif + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc new file mode 100644 index 0000000..bdf8312 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc @@ -0,0 +1,6 @@ + + + qgraphicsgridlayout.qml + + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp new file mode 100644 index 0000000..7585b23 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gridlayout.h" + +#include +#include + +#include + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + qmlRegisterInterface("QGraphicsLayoutItem"); + qmlRegisterInterface("QGraphicsLayout"); + qmlRegisterType("GridLayouts",4,7,"QGraphicsGridLayout"); + + QDeclarativeView view; + view.setSource(QUrl(":qgraphicsgridlayout.qml")); + view.show(); + + return app.exec(); +}; + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro new file mode 100644 index 0000000..ae6373d --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = qgraphicsgridlayout +QT += declarative + +SOURCES += \ + gridlayout.cpp \ + main.cpp + +HEADERS += \ + gridlayout.h + +RESOURCES += \ + gridlayout.qrc + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml new file mode 100644 index 0000000..c3edf1d --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +import GridLayouts 4.7 + +Item { + width: 400 + height: 400 + + QGraphicsWidget { + size.width: parent.width + size.height: parent.height + + layout: QGraphicsGridLayout { + objectName: "layout" + LayoutItem { + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 0 + QGraphicsGridLayout.alignment: Qt.AlignLeft + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "red"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "200x200" + preferredSize: "100x100" + Rectangle { color: "orange"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 2 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "200x200" + Rectangle { color: "yellow"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 1 + minimumSize: "100x100" + maximumSize: "200x200" + preferredSize: "200x200" + Rectangle { color: "green"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.column: 1 + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "200x200" + Rectangle { color: "blue"; anchors.fill: parent } + } + } + } +} + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp new file mode 100644 index 0000000..5cd35cb --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "linearlayout.h" + +#include +#include + +LinearLayoutAttached::LinearLayoutAttached(QObject *parent) +: QObject(parent), m_stretch(1), m_alignment(Qt::AlignCenter), m_spacing(0) +{ +} + +void LinearLayoutAttached::setStretchFactor(int f) +{ + if (m_stretch != f) { + m_stretch = f; + emit stretchChanged(reinterpret_cast(parent()), m_stretch); + } +} + +void LinearLayoutAttached::setSpacing(int s) +{ + if (m_spacing != s) { + m_spacing = s; + emit spacingChanged(reinterpret_cast(parent()), m_spacing); + } +} + +void LinearLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (m_alignment != a) { + m_alignment = a; + emit alignmentChanged(reinterpret_cast(parent()), m_alignment); + } +} + +QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) + : QObject(parent) +{ +} + +QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + Q_UNUSED(which); + Q_UNUSED(constraint); + return QSizeF(); +} + + +QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() +{ +} + +void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) +{ + insertItem(index, item); + + //connect attached properties + if (LinearLayoutAttached *obj = attachedProperties.value(item)) { + setStretchFactor(item, obj->stretchFactor()); + setAlignment(item, obj->alignment()); + updateSpacing(item, obj->spacing()); + QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); + QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); + //### need to disconnect when widget is removed? + } +} + +void QGraphicsLinearLayoutObject::clearChildren() +{ + while (count() > 0) + removeAt(count()-1); +} + +qreal QGraphicsLinearLayoutObject::contentsMargin() const +{ + qreal a, b, c, d; + getContentsMargins(&a, &b, &c, &d); + if (a == b && a == c && a == d) + return a; + return -1; +} + +void QGraphicsLinearLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m, m, m, m); +} + +void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +{ + QGraphicsLinearLayout::setStretchFactor(item, stretch); +} + +void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) +{ + for (int i=0; i < count(); i++){ + if (itemAt(i) == item) { + QGraphicsLinearLayout::setItemSpacing(i, spacing); + return; + } + } +} + +void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ + QGraphicsLinearLayout::setAlignment(item, alignment); +} + +QHash QGraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +{ + // ### This is not allowed - you must attach to any object + if (!qobject_cast(obj)) + return 0; + LinearLayoutAttached *rv = new LinearLayoutAttached(obj); + attachedProperties.insert(qobject_cast(obj), rv); + return rv; +} + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h new file mode 100644 index 0000000..392f3f8 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LINEARLAYOUT_H +#define LINEARLAYOUT_H + +#include + +#include +#include + +class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) +public: + QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); + + virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; +}; + + +class LinearLayoutAttached; +class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsLinearLayoutObject(QObject * = 0); + ~QGraphicsLinearLayoutObject(); + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + + qreal contentsMargin() const; + void setContentsMargin(qreal); + +private slots: + void updateStretch(QGraphicsLayoutItem*,int); + void updateSpacing(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } + + static QHash attachedProperties; +}; + + +class LinearLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) + +public: + LinearLayoutAttached(QObject *parent); + + int stretchFactor() const { return m_stretch; } + void setStretchFactor(int f); + Qt::Alignment alignment() const { return m_alignment; } + void setAlignment(Qt::Alignment a); + int spacing() const { return m_spacing; } + void setSpacing(int s); + +signals: + void stretchChanged(QGraphicsLayoutItem*, int); + void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment); + void spacingChanged(QGraphicsLayoutItem*, int); + +private: + int m_stretch; + Qt::Alignment m_alignment; + int m_spacing; +}; + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) +QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +#endif + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc new file mode 100644 index 0000000..93a3533 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc @@ -0,0 +1,6 @@ + + + qgraphicslinearlayout.qml + + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp new file mode 100644 index 0000000..c76e403 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "linearlayout.h" + +#include +#include + +#include + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + qmlRegisterInterface("QGraphicsLayoutItem"); + qmlRegisterInterface("QGraphicsLayout"); + qmlRegisterType("LinearLayouts",4,7,"QGraphicsLinearLayoutStretchItem"); + qmlRegisterType("LinearLayouts",4,7,"QGraphicsLinearLayout"); + + QDeclarativeView view; + view.setSource(QUrl(":qgraphicslinearlayout.qml")); + view.show(); + + return app.exec(); +}; + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro new file mode 100644 index 0000000..79eb6ff --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = qgraphicslinearlayout +QT += declarative + +SOURCES += \ + linearlayout.cpp \ + main.cpp + +HEADERS += \ + linearlayout.h + +RESOURCES += \ + linearlayout.qrc + + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml new file mode 100644 index 0000000..da77921 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +import LinearLayouts 4.7 + +Item { + width: 400 + height: 400 + + QGraphicsWidget { + size.width: parent.width + size.height: parent.height + + layout: QGraphicsLinearLayout { + LayoutItem { + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "yellow"; anchors.fill: parent } + } + LayoutItem { + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "200x200" + Rectangle { color: "green"; anchors.fill: parent } + } + } + } +} + -- cgit v0.12 From 10dba5b02c6226bce186c0308d40fdedb4ecd9b8 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 31 May 2010 11:42:36 +1000 Subject: Implement removeAt() for layout classes to clean up item removal. Also clean up qmlAttachedProperties() implementation and improve QML example --- .../qgraphicsgridlayout/.main.cpp.swo | Bin 12288 -> 12288 bytes .../qgraphicsgridlayout/gridlayout.cpp | 22 ++++++++----- .../qgraphicsgridlayout/gridlayout.h | 2 ++ .../qgraphicsgridlayout/qgraphicsgridlayout.qml | 34 +++++++++++---------- .../qgraphicslayouts/qgraphicslayouts.pro | 5 +-- .../qgraphicslinearlayout/linearlayout.cpp | 22 ++++++++----- .../qgraphicslinearlayout/linearlayout.h | 6 ++-- .../qgraphicslinearlayout.qml | 15 +++++++-- 8 files changed, 70 insertions(+), 36 deletions(-) diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo index c742274..cbd3b3e 100644 Binary files a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo and b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo differ diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp index 728c225..1792696 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp @@ -131,13 +131,23 @@ void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) setAlignment(item, alignment); QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment)), this, SLOT(updateAlignment(QGraphicsLayoutItem*, Qt::Alignment))); - //### need to disconnect when widget is removed? Re-implement removeAt()? } } +void QGraphicsGridLayoutObject::removeAt(int index) +{ + QGraphicsLayoutItem *item = itemAt(index); + if (item) { + GridLayoutAttached *obj = attachedProperties.value(item); + obj->disconnect(this); + attachedProperties.remove(item); + } + QGraphicsGridLayout::removeAt(index); +} + void QGraphicsGridLayoutObject::clearChildren() { - //### do I need to delete the removed items? And/or removed them from attachedProperties? + // do not delete the removed items; they will be deleted by the QML engine while (count() > 0) removeAt(count()-1); } @@ -146,7 +156,7 @@ qreal QGraphicsGridLayoutObject::spacing() const { if (verticalSpacing() == horizontalSpacing()) return verticalSpacing(); - return -1; //### + return -1; } qreal QGraphicsGridLayoutObject::contentsMargin() const @@ -170,11 +180,9 @@ void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::A GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) { - // ### This is not allowed - you must attach to any object - if (!qobject_cast(obj)) - return 0; GridLayoutAttached *rv = new GridLayoutAttached(obj); - attachedProperties.insert(qobject_cast(obj), rv); + if (qobject_cast(obj)) + attachedProperties.insert(qobject_cast(obj), rv); return rv; } diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h index 04f0148..cb8d9b7 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h @@ -69,6 +69,8 @@ public: qreal contentsMargin() const; void setContentsMargin(qreal); + void removeAt(int index); + static GridLayoutAttached *qmlAttachedProperties(QObject *); private slots: diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml index c3edf1d..5cb011f 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml @@ -49,46 +49,48 @@ Item { size.width: parent.width size.height: parent.height + /* + Below we create a grid layout using the GraphicsGridLayout item + (defined by the GraphicsGridLayoutObject class in gridlayout.h). + + The row, column etc. are set through attached properties on + GraphicsGridLayout, using the properties defined in the + GridLayoutAttached class (also defined in gridlayout.h). + */ + layout: QGraphicsGridLayout { - objectName: "layout" LayoutItem { QGraphicsGridLayout.row: 0 QGraphicsGridLayout.column: 0 - QGraphicsGridLayout.alignment: Qt.AlignLeft minimumSize: "100x100" maximumSize: "300x300" - preferredSize: "100x100" + preferredSize: "200x200" Rectangle { color: "red"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 1 - QGraphicsGridLayout.column: 0 + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 1 minimumSize: "100x100" maximumSize: "200x200" - preferredSize: "100x100" + preferredSize: "200x200" Rectangle { color: "orange"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 2 + QGraphicsGridLayout.row: 1 QGraphicsGridLayout.column: 0 + QGraphicsGridLayout.columnSpan: 2 minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "200x200" Rectangle { color: "yellow"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "200x200" + QGraphicsGridLayout.row: 2 + QGraphicsGridLayout.column: 0 preferredSize: "200x200" Rectangle { color: "green"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.row: 2 QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "400x400" preferredSize: "200x200" Rectangle { color: "blue"; anchors.fill: parent } } diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro index d92a6f4..672120a 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs SUBDIRS += \ - graphicsLayouts \ - layoutItem + layoutitem \ + qgraphicsgridlayout \ + qgraphicslinearlayout diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp index 5cd35cb..080b6ce 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp @@ -44,7 +44,7 @@ #include LinearLayoutAttached::LinearLayoutAttached(QObject *parent) -: QObject(parent), m_stretch(1), m_alignment(Qt::AlignCenter), m_spacing(0) +: QObject(parent), m_stretch(1), m_alignment(Qt::AlignTop), m_spacing(0) { } @@ -98,7 +98,6 @@ void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutIte { insertItem(index, item); - //connect attached properties if (LinearLayoutAttached *obj = attachedProperties.value(item)) { setStretchFactor(item, obj->stretchFactor()); setAlignment(item, obj->alignment()); @@ -109,12 +108,23 @@ void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutIte this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); - //### need to disconnect when widget is removed? } } +void QGraphicsLinearLayoutObject::removeAt(int index) +{ + QGraphicsLayoutItem *item = itemAt(index); + if (item) { + LinearLayoutAttached *obj = attachedProperties.value(item); + obj->disconnect(this); + attachedProperties.remove(item); + } + QGraphicsLinearLayout::removeAt(index); +} + void QGraphicsLinearLayoutObject::clearChildren() { + // do not delete the removed items; they will be deleted by the QML engine while (count() > 0) removeAt(count()-1); } @@ -156,11 +166,9 @@ void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt: QHash QGraphicsLinearLayoutObject::attachedProperties; LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) { - // ### This is not allowed - you must attach to any object - if (!qobject_cast(obj)) - return 0; LinearLayoutAttached *rv = new LinearLayoutAttached(obj); - attachedProperties.insert(qobject_cast(obj), rv); + if (qobject_cast(obj)) + attachedProperties.insert(qobject_cast(obj), rv); return rv; } diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h index 392f3f8..e6daf4d 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h @@ -74,11 +74,13 @@ public: QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - static LinearLayoutAttached *qmlAttachedProperties(QObject *); - qreal contentsMargin() const; void setContentsMargin(qreal); + void removeAt(int index); + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + private slots: void updateStretch(QGraphicsLayoutItem*,int); void updateSpacing(QGraphicsLayoutItem*,int); diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml index da77921..72cdeb6 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml @@ -49,17 +49,28 @@ Item { size.width: parent.width size.height: parent.height + /* + Below we create a linear layout using the GraphicsLinearLayout item + (defined by the GraphicsLinearLayoutObject class in linearlayout.h). + + The first LayoutItem uses 'GraphicsLinearLayout.spacing' to set the + item's spacing: this is an attached property, set using the + properties defined in the LinearLayoutAttached class (also defined + in linearlayout.h). + */ + layout: QGraphicsLinearLayout { LayoutItem { + QGraphicsLinearLayout.spacing: 50 minimumSize: "100x100" - maximumSize: "300x300" + maximumSize: "200x200" preferredSize: "100x100" Rectangle { color: "yellow"; anchors.fill: parent } } LayoutItem { minimumSize: "100x100" maximumSize: "400x400" - preferredSize: "200x200" + preferredSize: "300x300" Rectangle { color: "green"; anchors.fill: parent } } } -- cgit v0.12 From 33bf5e9941d4c1c257d22280cd0e8fb64382c782 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 31 May 2010 11:45:39 +1000 Subject: File shouldn't be in repository --- .../qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo deleted file mode 100644 index cbd3b3e..0000000 Binary files a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo and /dev/null differ -- cgit v0.12 From 1e60f5fb1c1ad9289247ef3bc47a94434b27dbea Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 31 May 2010 11:50:46 +1000 Subject: Rename QGraphics...Layout classes/QML items to Graphics...Layout to make it clear they are custom classes/items (not built-in) --- .../qgraphicsgridlayout/gridlayout.cpp | 24 +++++++++---------- .../qgraphicsgridlayout/gridlayout.h | 18 +++++++------- .../qgraphicslayouts/qgraphicsgridlayout/main.cpp | 2 +- .../qgraphicsgridlayout/qgraphicsgridlayout.qml | 24 +++++++++---------- .../qgraphicslinearlayout/linearlayout.cpp | 28 +++++++++++----------- .../qgraphicslinearlayout/linearlayout.h | 24 +++++++++---------- .../qgraphicslinearlayout/main.cpp | 4 ++-- .../qgraphicslinearlayout.qml | 4 ++-- 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp index 1792696..b52305e 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp @@ -58,18 +58,18 @@ void GridLayoutAttached::setAlignment(Qt::Alignment a) } } -QHash QGraphicsGridLayoutObject::attachedProperties; +QHash GraphicsGridLayoutObject::attachedProperties; -QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) +GraphicsGridLayoutObject::GraphicsGridLayoutObject(QObject *parent) : QObject(parent) { } -QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() +GraphicsGridLayoutObject::~GraphicsGridLayoutObject() { } -void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *widget) +void GraphicsGridLayoutObject::addWidget(QGraphicsWidget *widget) { //use attached properties if (QObject *obj = attachedProperties.value(qobject_cast(widget))) { @@ -85,7 +85,7 @@ void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *widget) } } -void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) +void GraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) { //use attached properties if (GridLayoutAttached *obj = attachedProperties.value(item)) { @@ -134,7 +134,7 @@ void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) } } -void QGraphicsGridLayoutObject::removeAt(int index) +void GraphicsGridLayoutObject::removeAt(int index) { QGraphicsLayoutItem *item = itemAt(index); if (item) { @@ -145,21 +145,21 @@ void QGraphicsGridLayoutObject::removeAt(int index) QGraphicsGridLayout::removeAt(index); } -void QGraphicsGridLayoutObject::clearChildren() +void GraphicsGridLayoutObject::clearChildren() { // do not delete the removed items; they will be deleted by the QML engine while (count() > 0) removeAt(count()-1); } -qreal QGraphicsGridLayoutObject::spacing() const +qreal GraphicsGridLayoutObject::spacing() const { if (verticalSpacing() == horizontalSpacing()) return verticalSpacing(); return -1; } -qreal QGraphicsGridLayoutObject::contentsMargin() const +qreal GraphicsGridLayoutObject::contentsMargin() const { qreal a, b, c, d; getContentsMargins(&a, &b, &c, &d); @@ -168,17 +168,17 @@ qreal QGraphicsGridLayoutObject::contentsMargin() const return -1; } -void QGraphicsGridLayoutObject::setContentsMargin(qreal m) +void GraphicsGridLayoutObject::setContentsMargin(qreal m) { setContentsMargins(m, m, m, m); } -void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +void GraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) { QGraphicsGridLayout::setAlignment(item, alignment); } -GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +GridLayoutAttached *GraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) { GridLayoutAttached *rv = new GridLayoutAttached(obj); if (qobject_cast(obj)) diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h index cb8d9b7..ca2cedc 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h @@ -47,7 +47,7 @@ #include class GridLayoutAttached; -class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +class GraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout { Q_OBJECT Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) @@ -60,8 +60,8 @@ class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout Q_CLASSINFO("DefaultProperty", "children") public: - QGraphicsGridLayoutObject(QObject * = 0); - ~QGraphicsGridLayoutObject(); + GraphicsGridLayoutObject(QObject * = 0); + ~GraphicsGridLayoutObject(); QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } @@ -84,19 +84,19 @@ private: void addLayoutItem(QGraphicsLayoutItem *); static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->addLayoutItem(item); + static_cast(prop->object)->addLayoutItem(item); } static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); + static_cast(prop->object)->clearChildren(); } static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); + return static_cast(prop->object)->count(); } static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); + return static_cast(prop->object)->itemAt(index); } static QHash attachedProperties; @@ -210,8 +210,8 @@ private: QML_DECLARE_INTERFACE(QGraphicsLayoutItem) QML_DECLARE_INTERFACE(QGraphicsLayout) -QML_DECLARE_TYPE(QGraphicsGridLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(GraphicsGridLayoutObject) +QML_DECLARE_TYPEINFO(GraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) #endif diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp index 7585b23..6525cb3 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) qmlRegisterInterface("QGraphicsLayoutItem"); qmlRegisterInterface("QGraphicsLayout"); - qmlRegisterType("GridLayouts",4,7,"QGraphicsGridLayout"); + qmlRegisterType("GridLayouts", 4, 7, "GraphicsGridLayout"); QDeclarativeView view; view.setSource(QUrl(":qgraphicsgridlayout.qml")); diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml index 5cb011f..50026f1 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml @@ -58,39 +58,39 @@ Item { GridLayoutAttached class (also defined in gridlayout.h). */ - layout: QGraphicsGridLayout { + layout: GraphicsGridLayout { LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 0 + GraphicsGridLayout.row: 0 + GraphicsGridLayout.column: 0 minimumSize: "100x100" maximumSize: "300x300" preferredSize: "200x200" Rectangle { color: "red"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 1 + GraphicsGridLayout.row: 0 + GraphicsGridLayout.column: 1 minimumSize: "100x100" maximumSize: "200x200" preferredSize: "200x200" Rectangle { color: "orange"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 1 - QGraphicsGridLayout.column: 0 - QGraphicsGridLayout.columnSpan: 2 + GraphicsGridLayout.row: 1 + GraphicsGridLayout.column: 0 + GraphicsGridLayout.columnSpan: 2 minimumSize: "100x100" Rectangle { color: "yellow"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 2 - QGraphicsGridLayout.column: 0 + GraphicsGridLayout.row: 2 + GraphicsGridLayout.column: 0 preferredSize: "200x200" Rectangle { color: "green"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 2 - QGraphicsGridLayout.column: 1 + GraphicsGridLayout.row: 2 + GraphicsGridLayout.column: 1 preferredSize: "200x200" Rectangle { color: "blue"; anchors.fill: parent } } diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp index 080b6ce..d0e9783 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp @@ -72,12 +72,12 @@ void LinearLayoutAttached::setAlignment(Qt::Alignment a) } } -QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) +GraphicsLinearLayoutStretchItemObject::GraphicsLinearLayoutStretchItemObject(QObject *parent) : QObject(parent) { } -QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +QSizeF GraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { Q_UNUSED(which); Q_UNUSED(constraint); @@ -85,16 +85,16 @@ QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, cons } -QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) +GraphicsLinearLayoutObject::GraphicsLinearLayoutObject(QObject *parent) : QObject(parent) { } -QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() +GraphicsLinearLayoutObject::~GraphicsLinearLayoutObject() { } -void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) +void GraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) { insertItem(index, item); @@ -111,7 +111,7 @@ void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutIte } } -void QGraphicsLinearLayoutObject::removeAt(int index) +void GraphicsLinearLayoutObject::removeAt(int index) { QGraphicsLayoutItem *item = itemAt(index); if (item) { @@ -122,14 +122,14 @@ void QGraphicsLinearLayoutObject::removeAt(int index) QGraphicsLinearLayout::removeAt(index); } -void QGraphicsLinearLayoutObject::clearChildren() +void GraphicsLinearLayoutObject::clearChildren() { // do not delete the removed items; they will be deleted by the QML engine while (count() > 0) removeAt(count()-1); } -qreal QGraphicsLinearLayoutObject::contentsMargin() const +qreal GraphicsLinearLayoutObject::contentsMargin() const { qreal a, b, c, d; getContentsMargins(&a, &b, &c, &d); @@ -138,17 +138,17 @@ qreal QGraphicsLinearLayoutObject::contentsMargin() const return -1; } -void QGraphicsLinearLayoutObject::setContentsMargin(qreal m) +void GraphicsLinearLayoutObject::setContentsMargin(qreal m) { setContentsMargins(m, m, m, m); } -void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +void GraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) { QGraphicsLinearLayout::setStretchFactor(item, stretch); } -void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) +void GraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) { for (int i=0; i < count(); i++){ if (itemAt(i) == item) { @@ -158,13 +158,13 @@ void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int s } } -void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +void GraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) { QGraphicsLinearLayout::setAlignment(item, alignment); } -QHash QGraphicsLinearLayoutObject::attachedProperties; -LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +QHash GraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *GraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) { LinearLayoutAttached *rv = new LinearLayoutAttached(obj); if (qobject_cast(obj)) diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h index e6daf4d..d9391ca 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h @@ -46,19 +46,19 @@ #include #include -class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem +class GraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem { Q_OBJECT Q_INTERFACES(QGraphicsLayoutItem) public: - QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); + GraphicsLinearLayoutStretchItemObject(QObject *parent = 0); virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; }; class LinearLayoutAttached; -class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout +class GraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout { Q_OBJECT Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) @@ -69,8 +69,8 @@ class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) Q_CLASSINFO("DefaultProperty", "children") public: - QGraphicsLinearLayoutObject(QObject * = 0); - ~QGraphicsLinearLayoutObject(); + GraphicsLinearLayoutObject(QObject * = 0); + ~GraphicsLinearLayoutObject(); QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } @@ -93,19 +93,19 @@ private: void insertLayoutItem(int, QGraphicsLayoutItem *); static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->insertLayoutItem(-1, item); + static_cast(prop->object)->insertLayoutItem(-1, item); } static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); + static_cast(prop->object)->clearChildren(); } static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); + return static_cast(prop->object)->count(); } static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); + return static_cast(prop->object)->itemAt(index); } static QHash attachedProperties; @@ -143,9 +143,9 @@ private: QML_DECLARE_INTERFACE(QGraphicsLayoutItem) QML_DECLARE_INTERFACE(QGraphicsLayout) -QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) -QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(GraphicsLinearLayoutStretchItemObject) +QML_DECLARE_TYPE(GraphicsLinearLayoutObject) +QML_DECLARE_TYPEINFO(GraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) #endif diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp index c76e403..f8d08c2 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp @@ -51,8 +51,8 @@ int main(int argc, char* argv[]) qmlRegisterInterface("QGraphicsLayoutItem"); qmlRegisterInterface("QGraphicsLayout"); - qmlRegisterType("LinearLayouts",4,7,"QGraphicsLinearLayoutStretchItem"); - qmlRegisterType("LinearLayouts",4,7,"QGraphicsLinearLayout"); + qmlRegisterType("LinearLayouts", 4, 7, "GraphicsLinearLayoutStretchItem"); + qmlRegisterType("LinearLayouts", 4, 7, "GraphicsLinearLayout"); QDeclarativeView view; view.setSource(QUrl(":qgraphicslinearlayout.qml")); diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml index 72cdeb6..9a0bd55 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml @@ -59,9 +59,9 @@ Item { in linearlayout.h). */ - layout: QGraphicsLinearLayout { + layout: GraphicsLinearLayout { LayoutItem { - QGraphicsLinearLayout.spacing: 50 + GraphicsLinearLayout.spacing: 50 minimumSize: "100x100" maximumSize: "200x200" preferredSize: "100x100" -- cgit v0.12 From 57d25d03f0a53be4cca6d20dcce0e5f2f9eecc45 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 31 May 2010 13:37:23 +1000 Subject: Fix example --- examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp index ef927d1..20a83e7 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutitem/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) //Add the QML snippet into the layout QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl(":layoutItem.qml")); + QDeclarativeComponent c(&engine, QUrl(":layoutitem.qml")); QGraphicsLayoutItem* obj = qobject_cast(c.create()); layout->addItem(obj); -- cgit v0.12 From 51aed62ef08f1ffacce71d44612abe46b8344923 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 31 May 2010 13:35:48 +1000 Subject: Add notifier for PathPercent.value --- src/declarative/graphicsitems/qdeclarativepath.cpp | 5 ++++- src/declarative/graphicsitems/qdeclarativepath_p.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 2d08c7c..141a938 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -867,6 +867,9 @@ qreal QDeclarativePathPercent::value() const void QDeclarativePathPercent::setValue(qreal value) { - _value = value; + if (_value != value) { + _value = value; + emit changed(); + } } QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index 17a2ea3..dad43e6 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -175,7 +175,7 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativePathPercent : public QDeclarativePathElement { Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) public: QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {} -- cgit v0.12