From kde-commits Thu Mar 28 12:13:00 2013 From: Viranch Mehta Date: Thu, 28 Mar 2013 12:13:00 +0000 To: kde-commits Subject: [kmines/viranch/qtquick] src: Port to QtQuick support in libkdegames Message-Id: <20130328121300.46544A604F () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=136447276401912 Git commit 508324afa818e8b4f5304ab1905ca43251e73218 by Viranch Mehta. Committed on 28/03/2013 at 13:13. Pushed by viranch into branch 'viranch/qtquick'. Port to QtQuick support in libkdegames M +0 -1 src/CMakeLists.txt M +2 -3 src/canvaswidget.cpp M +2 -4 src/canvaswidget.h D +0 -22 src/declarativeimports/CMakeLists.txt D +0 -87 src/declarativeimports/canvasitem.cpp D +0 -56 src/declarativeimports/canvasitem.h D +0 -39 src/declarativeimports/corebindingsplugin.cpp D +0 -35 src/declarativeimports/corebindingsplugin.h D +0 -1 src/declarativeimports/qmldir D +0 -49 src/kgdeclarativeview.cpp M +4 -3 src/mainwindow.cpp M +2 -2 src/mainwindow.h R +5 -16 src/qml/CanvasItem.qml [from: src/kgdeclarativeview.h - 068%= similarity] M +4 -4 src/qml/CellItem.qml M +0 -1 src/qml/MineField.qml M +1 -2 src/qml/main.qml http://commits.kde.org/kmines/508324afa818e8b4f5304ab1905ca43251e73218 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d2cd1c2..ec30663 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,6 @@ include_directories( ${CMAKE_SOURCE_DIR}/libkdegames/highsc= ore ) = set(kmines_SRCS mainwindow.cpp - kgdeclarativeview.cpp canvaswidget.cpp main.cpp ) = diff --git a/src/canvaswidget.cpp b/src/canvaswidget.cpp index 98e9ea5..288325c 100644 --- a/src/canvaswidget.cpp +++ b/src/canvaswidget.cpp @@ -19,11 +19,10 @@ #include "settings.h" = #include -#include #include = -CanvasWidget::CanvasWidget(KGameRenderer *renderer, QWidget *parent) : - KgDeclarativeView(renderer, parent) +CanvasWidget::CanvasWidget(QWidget *parent) : + KgDeclarativeView(parent) { QString path =3D KStandardDirs::locate("appdata", "qml/main.qml"); setSource(QUrl::fromLocalFile(path)); diff --git a/src/canvaswidget.h b/src/canvaswidget.h index 130fc0b..ed54a76 100644 --- a/src/canvaswidget.h +++ b/src/canvaswidget.h @@ -18,15 +18,13 @@ #ifndef CANVASWIDGET_H #define CANVASWIDGET_H = -#include "kgdeclarativeview.h" - -class KGameRenderer; +#include = class CanvasWidget : public KgDeclarativeView { Q_OBJECT public: - CanvasWidget(KGameRenderer *renderer, QWidget *parent=3D0); + CanvasWidget(QWidget *parent=3D0); void setGamePaused(bool paused); void startNewGame(int rows, int cols, int numMines); = diff --git a/src/declarativeimports/CMakeLists.txt b/src/declarativeimports= /CMakeLists.txt deleted file mode 100644 index 8a62978..0000000 --- a/src/declarativeimports/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -project(corebindings) - -include_directories( ${CMAKE_SOURCE_DIR}/libkdegames ) - -set(corebindings_SRCS - corebindingsplugin.cpp - canvasitem.cpp - ) - -INCLUDE_DIRECTORIES( - ${CMAKE_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${KDE4_INCLUDES} -) - -qt4_automoc(${corebindings_SRCS}) - -add_library(corebindingsplugin SHARED ${corebindings_SRCS}) -target_link_libraries(corebindingsplugin kdegames ${QT_QTDECLARATIVE_LIBRA= RY}) - -install(TARGETS corebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/= kde/games/core) -install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/games/core) diff --git a/src/declarativeimports/canvasitem.cpp b/src/declarativeimports= /canvasitem.cpp deleted file mode 100644 index 427b1e5..0000000 --- a/src/declarativeimports/canvasitem.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright 2012 Viranch Mehta - = - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - = - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - = - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "canvasitem.h" - -#include - -//static -KGameRenderer *CanvasItem::m_renderer =3D 0; - -void CanvasItem::setRenderer(KGameRenderer *renderer) -{ - m_renderer =3D renderer; -} - -CanvasItem::CanvasItem(QDeclarativeItem *parent) : - QDeclarativeItem(parent), - KGameRendererClient(m_renderer, QString()) -{ - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QSize CanvasItem::boundingSize() -{ - return boundingRect().toRect().size(); -} - -void CanvasItem::setSpriteKey(const QString &key) -{ - if (spriteKey() !=3D key) { - KGameRendererClient::setSpriteKey(key); - setRenderSize(boundingRect().toRect().size()); - emit spriteKeyChanged(); - } -} - -bool CanvasItem::isValid() const -{ - return (m_renderer && m_renderer->spriteExists(spriteKey())); -} - -void CanvasItem::setImplicitSize() -{ - if (isValid()) { - QSize size =3D m_renderer->boundsOnSprite(spriteKey()).size().toSi= ze(); - setImplicitWidth(size.width()); - setImplicitHeight(size.height()); - } -} - -void CanvasItem::receivePixmap(const QPixmap& pixmap) -{ - m_pixmap =3D pixmap; - update(); -} - -void CanvasItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *= option, QWidget *widget) -{ - Q_UNUSED(option); Q_UNUSED(widget); - - QSize size =3D boundingSize(); - if (renderSize() !=3D size) { - setRenderSize(size); - return; - } - - if (!m_pixmap.isNull()) { - setImplicitSize(); - painter->drawPixmap(boundingRect().toRect(), m_pixmap); - } -} - -#include "canvasitem.moc" diff --git a/src/declarativeimports/canvasitem.h b/src/declarativeimports/c= anvasitem.h deleted file mode 100644 index c9ca674..0000000 --- a/src/declarativeimports/canvasitem.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright 2012 Viranch Mehta - = - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - = - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - = - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef CANVASITEM_H -#define CANVASITEM_H - -#include -#include -#include - -class CanvasItem : public QDeclarativeItem, KGameRendererClient -{ - Q_OBJECT - Q_PROPERTY(QString spriteKey READ spriteKey WRITE setSpriteKey NOTIFY = spriteKeyChanged) - Q_PROPERTY(bool valid READ isValid) - -public: - CanvasItem(QDeclarativeItem *parent =3D 0); - - static void setRenderer(KGameRenderer*); - - void setSpriteKey(const QString &spriteKey); - - bool isValid() const; - - void setImplicitSize(); - - void receivePixmap(const QPixmap& pixmap); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, = QWidget *widget=3D0); - -signals: - void spriteKeyChanged(); - -private: - static KGameRenderer *m_renderer; - QPixmap m_pixmap; - - QSize boundingSize(); - -}; - -#endif diff --git a/src/declarativeimports/corebindingsplugin.cpp b/src/declarativ= eimports/corebindingsplugin.cpp deleted file mode 100644 index 6c8a527..0000000 --- a/src/declarativeimports/corebindingsplugin.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright 2012 Viranch Mehta - = - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - = - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - = - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "corebindingsplugin.h" - -#include "canvasitem.h" - -#include -#include - -void CoreBindingsPlugin::initializeEngine(QDeclarativeEngine *engine, cons= t char *uri) -{ - QObject *property =3D engine->rootContext()->contextProperty("renderer= ").value(); - KGameRenderer *renderer =3D (KGameRenderer*) property; - CanvasItem::setRenderer(renderer); -} - -void CoreBindingsPlugin::registerTypes(const char *uri) -{ - Q_ASSERT(uri =3D=3D QLatin1String("org.kde.games.core")); - - qmlRegisterType(uri, 0, 1, "CanvasItem"); -} - -#include "corebindingsplugin.moc" diff --git a/src/declarativeimports/corebindingsplugin.h b/src/declarativei= mports/corebindingsplugin.h deleted file mode 100644 index 8dc9c52..0000000 --- a/src/declarativeimports/corebindingsplugin.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2012 Viranch Mehta - = - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - = - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - = - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef COREBINDINGSPLUGIN_H -#define COREBINDINGSPLUGIN_H - -#include -#include - -class CoreBindingsPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT - -public: - void initializeEngine(QDeclarativeEngine *engine, const char *uri); - void registerTypes(const char *uri); -}; - -Q_EXPORT_PLUGIN2(corebindingsplugin, CoreBindingsPlugin) - -#endif // COREBINDINGSPLUGIN_H diff --git a/src/declarativeimports/qmldir b/src/declarativeimports/qmldir deleted file mode 100644 index 3f32798..0000000 --- a/src/declarativeimports/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin corebindingsplugin diff --git a/src/kgdeclarativeview.cpp b/src/kgdeclarativeview.cpp deleted file mode 100644 index 2fea038..0000000 --- a/src/kgdeclarativeview.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright 2012 Viranch Mehta - = - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - = - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - = - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "kgdeclarativeview.h" - -#include -#include - -#include -#include - -KgDeclarativeView::KgDeclarativeView(KGameRenderer *renderer, QWidget *par= ent) : - QDeclarativeView(parent) -{ - KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(engine()); - kdeclarative.initialize(); - - // binds things like i18n and icons - kdeclarative.setupBindings(); - - // bind our theme renderer so QML components can make use of it for co= nstructing KGameRenderer - setupRenderer(renderer); - - setResizeMode(QDeclarativeView::SizeRootObjectToView); -} - -void KgDeclarativeView::setupRenderer(KGameRenderer *renderer) -{ - if (renderer) { - engine()->rootContext()->setContextProperty("renderer", (QObject*)= renderer); - } -} - -#include "kgdeclarativeview.moc" diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cadb390..50a6409 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -93,9 +93,10 @@ private: */ = KMinesMainWindow::KMinesMainWindow() : - m_renderer(provider()), - m_canvas(new CanvasWidget(&m_renderer, this)) + m_provider(provider()), + m_canvas(new CanvasWidget(this)) { + m_provider->setDeclarativeEngine("themeProvider", m_canvas->engine()); connect(m_canvas, SIGNAL(minesCountChanged(int,int)), SLOT(onMinesCoun= tChanged(int,int))); connect(m_canvas, SIGNAL(gameOver(bool)), SLOT(onGameOver(bool))); connect(m_canvas, SIGNAL(firstClickDone()), SLOT(onFirstClick())); @@ -234,7 +235,7 @@ void KMinesMainWindow::configureSettings() return; KConfigDialog *dialog =3D new KConfigDialog( this, QLatin1String( "set= tings" ), Settings::self() ); dialog->addPage( new GeneralOptsConfig( dialog ), i18n("General"), QLa= tin1String( "games-config-options" )); - dialog->addPage( new KgThemeSelector( m_renderer.themeProvider() ), i1= 8n( "Theme" ), QLatin1String( "games-config-theme" )); + dialog->addPage( new KgThemeSelector( m_provider ), i18n( "Theme" ), Q= Latin1String( "games-config-theme" )); dialog->addPage( new CustomGameConfig( dialog ), i18n("Custom Game"), = QLatin1String( "games-config-custom" )); connect( dialog, SIGNAL(settingsChanged(QString)), m_canvas, SLOT(upda= teUseQuestionMarks()) ); dialog->setHelp(QString(),QLatin1String( "kmines" )); diff --git a/src/mainwindow.h b/src/mainwindow.h index 30c09c9..62e4ea6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -19,12 +19,12 @@ #define MAINWINDOW_H = #include -#include = class KMinesScene; class KMinesView; class KGameClock; class KToggleAction; +class KgThemeProvider; class CanvasWidget; = class KMinesMainWindow : public KXmlGuiWindow @@ -47,7 +47,7 @@ private: KMinesView* m_view; KGameClock* m_gameClock; KToggleAction* m_actionPause; - KGameRenderer m_renderer; + KgThemeProvider* m_provider; CanvasWidget* m_canvas; }; #endif diff --git a/src/kgdeclarativeview.h b/src/qml/CanvasItem.qml similarity index 68% rename from src/kgdeclarativeview.h rename to src/qml/CanvasItem.qml index 39999fd..31d5f18 100644 --- a/src/kgdeclarativeview.h +++ b/src/qml/CanvasItem.qml @@ -15,20 +15,9 @@ along with this program. If not, see . */ = -#ifndef KGDECLARATIVEVIEW_H -#define KGDECLARATIVEVIEW_H +import QtQuick 1.1 +import org.kde.games.core 0.1 as KgCore = -#include - -class KGameRenderer; - -class KgDeclarativeView : public QDeclarativeView -{ - Q_OBJECT -public: - KgDeclarativeView(KGameRenderer *renderer=3D0, QWidget *parent=3D0); - void setupRenderer(KGameRenderer *renderer); - -}; - -#endif //KGDECLARATIVEVIEW_H +KgCore.KgItem { + provider: themeProvider +} diff --git a/src/qml/CellItem.qml b/src/qml/CellItem.qml index 33dd028..2a5985c 100644 --- a/src/qml/CellItem.qml +++ b/src/qml/CellItem.qml @@ -18,7 +18,7 @@ import QtQuick 1.1 import org.kde.games.core 0.1 as KgCore = -KgCore.CanvasItem { +CanvasItem { id: cell spriteKey: border!=3D"" ? border : exploded ? "explosion" : (pressed |= | revealed ? "cell_down" : "cell_up") = @@ -67,19 +67,19 @@ KgCore.CanvasItem { } } = - KgCore.CanvasItem { + CanvasItem { anchors.fill: parent visible: (parent.hasMine||flagged) && revealed spriteKey: "mine" } = - KgCore.CanvasItem { + CanvasItem { anchors.fill: parent spriteKey: revealed && error ? "error" : ["", "flag", "question"][= cellState] visible: cellState>0 } = - KgCore.CanvasItem { + CanvasItem { anchors.fill: parent visible: digit>0 && revealed && !error spriteKey: "arabic" + ["One", "Two", "Three", "Four", "Five", "Six= ", "Seven", "Eight"][digit-1] diff --git a/src/qml/MineField.qml b/src/qml/MineField.qml index 74e7efe..5092247 100644 --- a/src/qml/MineField.qml +++ b/src/qml/MineField.qml @@ -16,7 +16,6 @@ */ = import QtQuick 1.1 -import org.kde.games.core 0.1 as KgCore = Item { id: container diff --git a/src/qml/main.qml b/src/qml/main.qml index 10ef6fa..707c3ab 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -16,7 +16,6 @@ */ = import QtQuick 1.1 -import org.kde.games.core 0.1 as KgCore import "logic.js" as Logic = Item { @@ -38,7 +37,7 @@ Item { field.mines =3D mines; } = - KgCore.CanvasItem { + CanvasItem { id: background spriteKey: "mainWidget" anchors.fill: parent