diff options
Diffstat (limited to 'examples')
29 files changed, 96 insertions, 93 deletions
diff --git a/examples/declarative/declarative.pro b/examples/declarative/declarative.pro index 5fc1cf0..00d3c05 100644 --- a/examples/declarative/declarative.pro +++ b/examples/declarative/declarative.pro @@ -6,7 +6,7 @@ SUBDIRS = \ imageprovider \ objectlistmodel \ plugins \ - widgets + proxywidgets # These examples contain no C++ and can simply be copied sources.files = \ diff --git a/examples/declarative/imageprovider/imageprovider.pro b/examples/declarative/imageprovider/imageprovider.pro index 86dbcca..945a301 100644 --- a/examples/declarative/imageprovider/imageprovider.pro +++ b/examples/declarative/imageprovider/imageprovider.pro @@ -18,4 +18,8 @@ ImageProviderCore_sources.files = \ ImageProviderCore/qmldir ImageProviderCore_sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovider/ImageProviderCore +symbian:{ + TARGET.EPOCALLOWDLLDATA=1 +} + INSTALLS = sources ImageProviderCore_sources target diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp index 741f68a..fb51b0c 100644 --- a/examples/declarative/plugins/plugin.cpp +++ b/examples/declarative/plugins/plugin.cpp @@ -46,7 +46,7 @@ #include <qbasictimer.h> #include <qapplication.h> -// Implements a "Time" class with hour and minute properties +// Implements a "TimeModel" class with hour and minute properties // that change on-the-minute yet efficiently sleep the rest // of the time. @@ -97,14 +97,14 @@ private: QBasicTimer timer; }; -class Time : public QObject +class TimeModel : public QObject { Q_OBJECT Q_PROPERTY(int hour READ hour NOTIFY timeChanged) Q_PROPERTY(int minute READ minute NOTIFY timeChanged) public: - Time(QObject *parent=0) : QObject(parent) + TimeModel(QObject *parent=0) : QObject(parent) { if (++instances == 1) { if (!timer) @@ -114,7 +114,7 @@ public: } } - ~Time() + ~TimeModel() { if (--instances == 0) { timer->stop(); @@ -133,12 +133,8 @@ private: static int instances; }; -int Time::instances=0; -MinuteTimer *Time::timer=0; - - -QML_DECLARE_TYPE(Time); - +int TimeModel::instances=0; +MinuteTimer *TimeModel::timer=0; class QExampleQmlPlugin : public QDeclarativeExtensionPlugin { @@ -147,7 +143,7 @@ public: void registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample")); - qmlRegisterType<Time>(uri, 1, 0, "Time"); + qmlRegisterType<TimeModel>(uri, 1, 0, "Time"); } }; diff --git a/examples/declarative/plugins/plugins.pro b/examples/declarative/plugins/plugins.pro index 877a5ce..c409d39 100644 --- a/examples/declarative/plugins/plugins.pro +++ b/examples/declarative/plugins/plugins.pro @@ -8,7 +8,7 @@ VERSION = 1.0.0 SOURCES += plugin.cpp qdeclarativesources.files += \ - com/nokia/TimeExample/qdeclarativedir \ + com/nokia/TimeExample/qmldir \ com/nokia/TimeExample/center.png \ com/nokia/TimeExample/clock.png \ com/nokia/TimeExample/Clock.qml \ @@ -22,6 +22,11 @@ sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins target.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins/com/nokia/TimeExample +symbian:{ + TARGET.EPOCALLOWDLLDATA=1 +} + + INSTALLS += qdeclarativesources sources target symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/declarative/proxywidgets/ProxyWidgets/qmldir b/examples/declarative/proxywidgets/ProxyWidgets/qmldir new file mode 100644 index 0000000..e55267c --- /dev/null +++ b/examples/declarative/proxywidgets/ProxyWidgets/qmldir @@ -0,0 +1 @@ +plugin proxywidgetsplugin diff --git a/examples/declarative/widgets/README b/examples/declarative/proxywidgets/README index f85a1e8..f50fa22 100644 --- a/examples/declarative/widgets/README +++ b/examples/declarative/proxywidgets/README @@ -1,4 +1,4 @@ To run: make install - qml mywidgets.qml + qml proxywidgets.qml diff --git a/examples/declarative/widgets/mywidgets.cpp b/examples/declarative/proxywidgets/proxywidgets.cpp index e17240d..47d0cb9 100644 --- a/examples/declarative/widgets/mywidgets.cpp +++ b/examples/declarative/proxywidgets/proxywidgets.cpp @@ -82,7 +82,7 @@ private: QPushButton *widget; }; -class MyWidgetsPlugin : public QDeclarativeExtensionPlugin +class ProxyWidgetsPlugin : public QDeclarativeExtensionPlugin { Q_OBJECT public: @@ -92,8 +92,8 @@ public: } }; -#include "mywidgets.moc" +#include "proxywidgets.moc" QML_DECLARE_TYPE(MyPushButton) -Q_EXPORT_PLUGIN2(mywidgetsplugin, MyWidgetsPlugin); +Q_EXPORT_PLUGIN2(proxywidgetsplugin, ProxyWidgetsPlugin); diff --git a/examples/declarative/widgets/widgets.pro b/examples/declarative/proxywidgets/proxywidgets.pro index 258edb1..eb85191 100644 --- a/examples/declarative/widgets/widgets.pro +++ b/examples/declarative/proxywidgets/proxywidgets.pro @@ -1,13 +1,13 @@ TEMPLATE = lib -DESTDIR = MyWidgets -TARGET = mywidgetsplugin +DESTDIR = ProxyWidgets +TARGET = proxywidgetsplugin CONFIG += qt plugin QT += declarative VERSION = 1.0.0 -SOURCES += mywidgets.cpp +SOURCES += proxywidgets.cpp -sources.files += mywidgets.pro mywidgets.cpp mywidgets.qml +sources.files += proxywidgets.pro proxywidgets.cpp proxywidgets.qml sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins @@ -17,3 +17,6 @@ INSTALLS += sources target symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +symbian:{ + TARGET.EPOCALLOWDLLDATA = 1 +}
\ No newline at end of file diff --git a/examples/declarative/widgets/mywidgets.qml b/examples/declarative/proxywidgets/proxywidgets.qml index b1efed4..023de71 100644 --- a/examples/declarative/widgets/mywidgets.qml +++ b/examples/declarative/proxywidgets/proxywidgets.qml @@ -1,5 +1,5 @@ import Qt 4.6 -import "MyWidgets" 1.0 +import "ProxyWidgets" 1.0 Rectangle { id: window diff --git a/examples/declarative/tutorials/helloworld/Cell.qml b/examples/declarative/tutorials/helloworld/Cell.qml index de4f3bb..9249ffe 100644 --- a/examples/declarative/tutorials/helloworld/Cell.qml +++ b/examples/declarative/tutorials/helloworld/Cell.qml @@ -5,10 +5,10 @@ import Qt 4.6 Item { id: container //![4] - property alias color: rectangle.color + property alias cellColor: rectangle.color //![4] //![5] - signal clicked(color color) + signal clicked(color cellColor) //![5] width: 40; height: 25 @@ -25,7 +25,7 @@ Item { //![3] MouseArea { anchors.fill: parent - onClicked: container.clicked(container.color) + onClicked: container.clicked(container.cellColor) } //![3] } diff --git a/examples/declarative/tutorials/helloworld/tutorial2.qml b/examples/declarative/tutorials/helloworld/tutorial2.qml index 99889d7..38447e2 100644 --- a/examples/declarative/tutorials/helloworld/tutorial2.qml +++ b/examples/declarative/tutorials/helloworld/tutorial2.qml @@ -15,17 +15,17 @@ Rectangle { Grid { id: colorPicker - anchors.bottom: page.bottom + x: 4; anchors.bottom: page.bottom; anchors.bottomMargin: 4 rows: 2; columns: 3; spacing: 3 //![1] - Cell { color: "red"; onClicked: helloText.color = color } + Cell { cellColor: "red"; onClicked: helloText.color = cellColor } //![1] - Cell { color: "green"; onClicked: helloText.color = color } - Cell { color: "blue"; onClicked: helloText.color = color } - Cell { color: "yellow"; onClicked: helloText.color = color } - Cell { color: "steelblue"; onClicked: helloText.color = color } - Cell { color: "black"; onClicked: helloText.color = color } + Cell { cellColor: "green"; onClicked: helloText.color = cellColor } + Cell { cellColor: "blue"; onClicked: helloText.color = cellColor } + Cell { cellColor: "yellow"; onClicked: helloText.color = cellColor } + Cell { cellColor: "steelblue"; onClicked: helloText.color = cellColor } + Cell { cellColor: "black"; onClicked: helloText.color = cellColor } } } //![0] diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index b8a4f77..d851c49 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -11,15 +11,14 @@ Rectangle { text: "Hello world!" font.pointSize: 24; font.bold: true y: 30; anchors.horizontalCenter: page.horizontalCenter - transformOrigin: Item.Center //![1] - MouseArea { id: mouseRegion; anchors.fill: parent } + MouseArea { id: mouseArea; anchors.fill: parent } //![1] //![2] states: State { - name: "down"; when: mouseRegion.pressed == true + name: "down"; when: mouseArea.pressed == true PropertyChanges { target: helloText; y: 160; rotation: 180; color: "red" } } //![2] @@ -37,15 +36,15 @@ Rectangle { Grid { id: colorPicker - anchors.bottom: page.bottom + x: 4; anchors.bottom: page.bottom; anchors.bottomMargin: 4 rows: 2; columns: 3; spacing: 3 - Cell { color: "red"; onClicked: helloText.color = color } - Cell { color: "green"; onClicked: helloText.color = color } - Cell { color: "blue"; onClicked: helloText.color = color } - Cell { color: "yellow"; onClicked: helloText.color = color } - Cell { color: "steelblue"; onClicked: helloText.color = color } - Cell { color: "black"; onClicked: helloText.color = color } + Cell { cellColor: "red"; onClicked: helloText.color = cellColor } + Cell { cellColor: "green"; onClicked: helloText.color = cellColor } + Cell { cellColor: "blue"; onClicked: helloText.color = cellColor } + Cell { cellColor: "yellow"; onClicked: helloText.color = cellColor } + Cell { cellColor: "steelblue"; onClicked: helloText.color = cellColor } + Cell { cellColor: "black"; onClicked: helloText.color = cellColor } } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml index 2e31ff8..5e28da7 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml @@ -14,11 +14,11 @@ Rectangle { gradient: Gradient { GradientStop { id: topGrad; position: 0.0 - color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } + color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame1/samegame.qml b/examples/declarative/tutorials/samegame/samegame1/samegame.qml index 5ed30c9..006b926 100644 --- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml @@ -24,7 +24,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: console.log("Implement me!"); + id: btnA; text: "New Game"; onClicked: console.log("Starting a new game..."); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 6629302..a7853d4 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -13,11 +13,11 @@ Rectangle { gradient: Gradient { GradientStop { id: topGrad; position: 0.0 - color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } + color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index 2c02c61..0ec3a8b 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -15,6 +15,12 @@ function index(xIdx,yIdx) { function initBoard() { + //Delete old blocks + for(var i = 0; i<maxIndex; i++){ + if(board[i] != null) + board[i].destroy(); + } + //Calculate board size maxX = Math.floor(background.width/tileSize); maxY = Math.floor(background.height/tileSize); diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml index 7e0bc0c..89d8035 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml @@ -1,13 +1,13 @@ import Qt 4.6 +//![2] +import "samegame.js" as SameGame +//![2] Rectangle { id: screen width: 490; height: 720 SystemPalette { id: activePalette } -//![2] - Script { source: "samegame.js" } -//![2] Item { width: parent.width; anchors.top: parent.top; anchors.bottom: toolbar.top @@ -27,7 +27,7 @@ Rectangle { //![1] Button { - id: btnA; text: "New Game"; onClicked: initBoard(); + id: btnA; text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml index 6629302..a7853d4 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml @@ -13,11 +13,11 @@ Rectangle { gradient: Gradient { GradientStop { id: topGrad; position: 0.0 - color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } + color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml index 36178ec..966f85a 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml @@ -18,6 +18,6 @@ Rectangle { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } + MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index 38efb3b..33449fa 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -14,12 +14,6 @@ function index(xIdx,yIdx) { function initBoard() { - for(var i = 0; i<maxIndex; i++){ - //Delete old blocks - if(board[i] != null) - board[i].destroy(); - } - //Calculate board size maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize); maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize); diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml index 168bf9b..db25e24 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml @@ -1,12 +1,12 @@ //![0] import Qt 4.6 +import "samegame.js" as SameGame Rectangle { id: screen width: 490; height: 720 SystemPalette { id: activePalette } - Script { source: "samegame.js" } Item { width: parent.width; anchors.top: parent.top; anchors.bottom: toolbar.top @@ -28,8 +28,7 @@ Rectangle { height: parent.height - (parent.height % tileSize); MouseArea { - id: gameMR - anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); + anchors.fill: parent; onClicked: SameGame.handleClick(mouse.x,mouse.y); } } //![1] @@ -46,7 +45,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: initBoard(); + id: btnA; text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml index a6ef62c..e50aae0 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml @@ -9,7 +9,7 @@ Item { id:block property int targetX: 0 property int targetY: 0 - SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } + SpringFollow on x { source: targetX; spring: 2; damping: 0.2; enabled: spawned } SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } //![1] diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml index 6629302..a7853d4 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml @@ -13,11 +13,11 @@ Rectangle { gradient: Gradient { GradientStop { id: topGrad; position: 0.0 - color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } + color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml index 831c03b..fc83e39 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -17,5 +17,5 @@ Rectangle { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } + MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); } } diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index c2e8018..090496d 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -1,5 +1,6 @@ import Qt 4.6 import "content" +import "content/samegame.js" as SameGame Rectangle { id: screen @@ -21,20 +22,19 @@ Rectangle { property int score: 0 property int tileSize: 40 - Script { source: "content/samegame.js" } - z: 20; anchors.centerIn: parent width: parent.width - (parent.width % getTileSize()); height: parent.height - (parent.height % getTileSize()); MouseArea { - id: gameMR - anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); + anchors.fill: parent; onClicked: SameGame.handleClick(mouse.x,mouse.y); } } } Dialog { id: dialog; anchors.centerIn: parent; z: 21 } + + //![0] Dialog { id: scoreName; anchors.centerIn: parent; z: 22; Text { @@ -54,6 +54,7 @@ Rectangle { anchors.left: spacer.right } } + //![0] Rectangle { id: toolBar @@ -62,7 +63,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: {initBoard();} + id: btnA; text: "New Game"; onClicked: {SameGame.initBoard();} anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/widgets/MyWidgets/qmldir b/examples/declarative/widgets/MyWidgets/qmldir deleted file mode 100644 index dc1d10e..0000000 --- a/examples/declarative/widgets/MyWidgets/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin mywidgetsplugin diff --git a/examples/graphicsview/weatheranchorlayout/main.cpp b/examples/graphicsview/weatheranchorlayout/main.cpp index aa06476..391fdd8 100644 --- a/examples/graphicsview/weatheranchorlayout/main.cpp +++ b/examples/graphicsview/weatheranchorlayout/main.cpp @@ -97,6 +97,8 @@ protected: case Qt::MaximumSize: sh = QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); break; + default: + break; } return sh; } @@ -167,15 +169,6 @@ private: }; -static QGraphicsProxyWidget *createItem(const QString &name = "Unnamed") -{ - QGraphicsProxyWidget *w = new QGraphicsProxyWidget; - w->setWidget(new QPushButton(name)); - w->setData(0, name); - w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - return w; -} - int main(int argc, char **argv) { Q_INIT_RESOURCE(weatheranchorlayout); diff --git a/examples/script/qstetrix/tetrixboard.cpp b/examples/script/qstetrix/tetrixboard.cpp index 7d44c4c..f35740d 100644 --- a/examples/script/qstetrix/tetrixboard.cpp +++ b/examples/script/qstetrix/tetrixboard.cpp @@ -54,7 +54,12 @@ TetrixBoard::TetrixBoard(QWidget *parent) void TetrixBoard::setNextPieceLabel(QWidget *label) { - nextPieceLabel = qobject_cast<QLabel*>(label); + nextPieceLbl = qobject_cast<QLabel*>(label); +} + +QLabel *TetrixBoard::nextPieceLabel() const +{ + return nextPieceLbl; } QObject *TetrixBoard::getTimer() @@ -82,16 +87,16 @@ void TetrixBoard::keyPressEvent(QKeyEvent *event) void TetrixBoard::showNextPiece(int width, int height) { - if (!nextPieceLabel) + if (!nextPieceLabel()) return; QPixmap pixmap(width * squareWidth(), height * squareHeight()); QPainter painter(&pixmap); - painter.fillRect(pixmap.rect(), nextPieceLabel->palette().background()); + painter.fillRect(pixmap.rect(), nextPieceLabel()->palette().background()); emit paintNextPieceRequested(&painter); - nextPieceLabel->setPixmap(pixmap); + nextPieceLabel()->setPixmap(pixmap); } void TetrixBoard::drawPauseScreen(QPainter *painter) diff --git a/examples/script/qstetrix/tetrixboard.h b/examples/script/qstetrix/tetrixboard.h index 7a04317..781ec39 100644 --- a/examples/script/qstetrix/tetrixboard.h +++ b/examples/script/qstetrix/tetrixboard.h @@ -45,21 +45,19 @@ #include <QTimer> #include <QFrame> #include <QPointer> - -QT_BEGIN_NAMESPACE -class QLabel; -QT_END_NAMESPACE +#include <QLabel> class TetrixBoard : public QFrame { Q_OBJECT Q_PROPERTY(QObject* timer READ getTimer) - Q_PROPERTY(QWidget* nextPieceLabel WRITE setNextPieceLabel) + Q_PROPERTY(QWidget* nextPieceLabel READ nextPieceLabel WRITE setNextPieceLabel) public: TetrixBoard(QWidget *parent = 0); void setNextPieceLabel(QWidget *label); + QLabel *nextPieceLabel() const; void setBoardWidth(int width); void setBoardHeight(int height); QSize minimumSizeHint() const; @@ -95,7 +93,7 @@ private: int squareHeight() { return contentsRect().height() / BoardHeight; } QTimer *timer; - QPointer<QLabel> nextPieceLabel; + QPointer<QLabel> nextPieceLbl; QImage image; }; |