[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kmines/viranch/qtquick] src: Port to QtQuick support in libkdegames
From:       Viranch Mehta <viranch.mehta () gmail ! com>
Date:       2013-03-28 12:13:00
Message-ID: 20130328121300.46544A604F () git ! kde ! org
[Download RAW message or body]

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/highscore  )
 
 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 <QGraphicsObject>
-#include <KGameRenderer>
 #include <KStandardDirs>
 
-CanvasWidget::CanvasWidget(KGameRenderer *renderer, QWidget *parent) :
-    KgDeclarativeView(renderer, parent)
+CanvasWidget::CanvasWidget(QWidget *parent) :
+    KgDeclarativeView(parent)
 {
     QString path = 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 <KgDeclarativeView>
 
 class CanvasWidget : public KgDeclarativeView
 {
     Q_OBJECT
 public:
-    CanvasWidget(KGameRenderer *renderer, QWidget *parent=0);
+    CanvasWidget(QWidget *parent=0);
     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_LIBRARY})
-
-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 <viranch.mehta@gmail.com>
-  
-    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 <http://www.gnu.org/licenses/>.
-*/
-
-#include "canvasitem.h"
-
-#include <QPainter>
-
-//static
-KGameRenderer *CanvasItem::m_renderer = 0;
-
-void CanvasItem::setRenderer(KGameRenderer *renderer)
-{
-    m_renderer = 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() != 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 = m_renderer->boundsOnSprite(spriteKey()).size().toSize();
-        setImplicitWidth(size.width());
-        setImplicitHeight(size.height());
-    }
-}
-
-void CanvasItem::receivePixmap(const QPixmap& pixmap)
-{
-    m_pixmap = pixmap;
-    update();
-}
-
-void CanvasItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, \
                QWidget *widget)
-{
-    Q_UNUSED(option); Q_UNUSED(widget);
-
-    QSize size = boundingSize();
-    if (renderSize() != 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/canvasitem.h deleted file mode 100644
index c9ca674..0000000
--- a/src/declarativeimports/canvasitem.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-    Copyright 2012 Viranch Mehta <viranch.mehta@gmail.com>
-  
-    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 <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef CANVASITEM_H
-#define CANVASITEM_H
-
-#include <QDeclarativeItem>
-#include <KGameRenderer>
-#include <KGameRendererClient>
-
-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 = 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=0);
-
-signals:
-    void spriteKeyChanged();
-
-private:
-    static KGameRenderer *m_renderer;
-    QPixmap m_pixmap;
-
-    QSize boundingSize();
-
-};
-
-#endif
diff --git a/src/declarativeimports/corebindingsplugin.cpp \
b/src/declarativeimports/corebindingsplugin.cpp deleted file mode 100644
index 6c8a527..0000000
--- a/src/declarativeimports/corebindingsplugin.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-    Copyright 2012 Viranch Mehta <viranch.mehta@gmail.com>
-  
-    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 <http://www.gnu.org/licenses/>.
-*/
-
-#include "corebindingsplugin.h"
-
-#include "canvasitem.h"
-
-#include <QDeclarativeContext>
-#include <KGameRenderer>
-
-void CoreBindingsPlugin::initializeEngine(QDeclarativeEngine *engine, const char \
                *uri)
-{
-    QObject *property = \
                engine->rootContext()->contextProperty("renderer").value<QObject*>();
-    KGameRenderer *renderer = (KGameRenderer*) property;
-    CanvasItem::setRenderer(renderer);
-}
-
-void CoreBindingsPlugin::registerTypes(const char *uri)
-{
-    Q_ASSERT(uri == QLatin1String("org.kde.games.core"));
-
-    qmlRegisterType<CanvasItem>(uri, 0, 1, "CanvasItem");
-}
-
-#include "corebindingsplugin.moc"
diff --git a/src/declarativeimports/corebindingsplugin.h \
b/src/declarativeimports/corebindingsplugin.h deleted file mode 100644
index 8dc9c52..0000000
--- a/src/declarativeimports/corebindingsplugin.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-    Copyright 2012 Viranch Mehta <viranch.mehta@gmail.com>
-  
-    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 <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef COREBINDINGSPLUGIN_H
-#define COREBINDINGSPLUGIN_H
-
-#include <QDeclarativeEngine>
-#include <QDeclarativeExtensionPlugin>
-
-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 <viranch.mehta@gmail.com>
-  
-    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 <http://www.gnu.org/licenses/>.
-*/
-
-#include "kgdeclarativeview.h"
-
-#include <QDeclarativeEngine>
-#include <QDeclarativeContext>
-
-#include <kdeclarative.h>
-#include <KGameRenderer>
-
-KgDeclarativeView::KgDeclarativeView(KGameRenderer *renderer, QWidget *parent) :
-    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 constructing \
                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(onMinesCountChanged(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 = new KConfigDialog( this, QLatin1String( "settings" ), \
                Settings::self() );
     dialog->addPage( new GeneralOptsConfig( dialog ), i18n("General"), \
                QLatin1String( "games-config-options" ));
-    dialog->addPage( new KgThemeSelector( m_renderer.themeProvider() ), i18n( \
"Theme" ), QLatin1String( "games-config-theme" )); +    dialog->addPage( new \
KgThemeSelector( m_provider ), i18n( "Theme" ), QLatin1String( "games-config-theme" \
                ));
     dialog->addPage( new CustomGameConfig( dialog ), i18n("Custom Game"), \
                QLatin1String( "games-config-custom" ));
     connect( dialog, SIGNAL(settingsChanged(QString)), m_canvas, \
SLOT(updateUseQuestionMarks()) );  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 <KXmlGuiWindow>
-#include <KGameRenderer>
 
 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 <http://www.gnu.org/licenses/>.
 */
 
-#ifndef KGDECLARATIVEVIEW_H
-#define KGDECLARATIVEVIEW_H
+import QtQuick 1.1
+import org.kde.games.core 0.1 as KgCore
 
-#include <QDeclarativeView>
-
-class KGameRenderer;
-
-class KgDeclarativeView : public QDeclarativeView
-{
-    Q_OBJECT
-public:
-    KgDeclarativeView(KGameRenderer *renderer=0, QWidget *parent=0);
-    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!="" ? 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 = mines;
     }
 
-    KgCore.CanvasItem {
+    CanvasItem {
         id: background
         spriteKey: "mainWidget"
         anchors.fill: parent


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic