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

List:       kde-commits
Subject:    [pairs/new_qml2] src: Simplify games selection code
From:       Aleix Pol <aleixpol () kde ! org>
Date:       2011-12-01 0:40:09
Message-ID: 20111201004009.6E6E4A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 3e639844f0c4b00405f01736a0ba730d46037c24 by Aleix Pol.
Committed on 01/12/2011 at 01:35.
Pushed by apol into branch 'new_qml2'.

Simplify games selection code

M  +0    -1    src/qml/Main.qml
M  +12   -26   src/qml/OptionsPage.qml
M  +8    -24   src/themesmodel.cpp
M  +1    -2    src/themesmodel.h

http://commits.kde.org/pairs/3e639844f0c4b00405f01736a0ba730d46037c24

diff --git a/src/qml/Main.qml b/src/qml/Main.qml
index dba12d4..47850f1 100644
--- a/src/qml/Main.qml
+++ b/src/qml/Main.qml
@@ -1,5 +1,4 @@
 import QtQuick 1.0
-import '.'
 
 Rectangle
 {
diff --git a/src/qml/OptionsPage.qml b/src/qml/OptionsPage.qml
index a134618..de87f3c 100644
--- a/src/qml/OptionsPage.qml
+++ b/src/qml/OptionsPage.qml
@@ -8,8 +8,6 @@ Rectangle {
     color: 'green'
     signal gameStarted;
     
-    onGameTypeChanged: themesModel.refresh(gameType, gameLanguage)
-    
     Row {
         anchors.margins: 30
         anchors.fill: parent
@@ -49,36 +47,24 @@ Rectangle {
                     onClicked: gameType = 'word'
                 }
             }
-            GridView {
-                width: 400
+            
+            Flow {
                 id: themesView
                 height: parent.height
-                model: themesModel
+                width: parent.width
                 
-                MouseArea {
-                    anchors.fill: parent
+                Repeater {
+                    model: themesModel
                     
-                    onClicked: {
-                        var idx=themesView.indexAt(mouse.x, mouse.y)
-                        gameStarted()
-                        fgame.newGame(idx, gameLanguage, gameType)
-                    }
-                }
-                
-                delegate: Column {
-                    Image {
+                    delegate: Button {
+                        visible: themesModel.isPertinent(index, gameType, \
gameLanguage)  source: "image://theme/"+display+"/"+decoration
-                        fillMode: Image.PreserveAspectFit
-                        width: 100
-                        height: 100
-                    }
-                    
-                    Text {
-                        width: 100
-                        wrapMode: Text.WordWrap
-                        font.pixelSize: 20
-                        horizontalAlignment: Text.AlignHCenter
                         text: display
+                        
+                        onClicked: {
+                            gameStarted()
+                            fgame.newGame(index, gameLanguage, gameType)
+                        }
                     }
                 }
             }
diff --git a/src/themesmodel.cpp b/src/themesmodel.cpp
index 52e4486..3f5438b 100644
--- a/src/themesmodel.cpp
+++ b/src/themesmodel.cpp
@@ -26,6 +26,11 @@
 
 ThemesModel::ThemesModel(QObject* parent): QStandardItemModel(parent)
 {
+    QHash<int, QByteArray> names=QStandardItemModel::roleNames();
+    names.insert(PairsTheme::CardTypeRole, "type");
+    names.insert(PairsTheme::LanguagesRole, "languages");
+    setRoleNames(names);
+    
     qsrand(QTime::currentTime().elapsed());
     
     QStringList themesdirs=KGlobal::dirs()->findDirs("appdata", "themes");
@@ -36,25 +41,6 @@ ThemesModel::ThemesModel(QObject* parent): \
QStandardItemModel(parent)  QMetaObject::invokeMethod(this, "reload", \
Qt::QueuedConnection);  }
 
-void ThemesModel::refresh(const QString &type, const QString &lang)
-{
-    emit layoutAboutToBeChanged();
-    clear();
-    const QStringList themes = KGlobal::dirs()->findAllResources("appdata", \
                QLatin1String( "themes/*.pairs.*" ));
-
-    Q_FOREACH(const QString& themePath, themes) {
-        PairsTheme* theme = new PairsTheme(themePath);
-
-        if(!theme->isCorrect() || !theme->isPertinent(type, lang)) {
-            qWarning() << "uncorrect theme:" << themePath << theme->error();
-            delete theme;
-        } else {
-            appendRow(theme);
-        }
-    }
-    changePersistentIndex(index(0,0), index(rowCount(),columnCount()));
-    emit layoutChanged();
-}
 void ThemesModel::reload()
 {
     clear();
@@ -89,12 +75,10 @@ QVariant ThemesModel::info(int row, const QByteArray& role)
     return QStandardItemModel::data(index(row, 0), roles.key(role));
 }
 
-QHash< int, QByteArray> ThemesModel::roleNames() const
+bool ThemesModel::isPertinent(int row, const QString& type, const QString& lang)
 {
-    QHash<int, QByteArray> names=QStandardItemModel::roleNames();
-    names.insert(PairsTheme::CardTypeRole, "type");
-    names.insert(PairsTheme::LanguagesRole, "languages");
-    return names;
+    PairsTheme* theme=static_cast<PairsTheme*>(item(row, 0));
+    return theme->isPertinent(type, lang);
 }
 
 QString ThemesModel::randomThemesImage() const
diff --git a/src/themesmodel.h b/src/themesmodel.h
index 0eb5f80..a449cda 100644
--- a/src/themesmodel.h
+++ b/src/themesmodel.h
@@ -29,13 +29,12 @@ class ThemesModel : public QStandardItemModel
         explicit ThemesModel(QObject* parent = 0);
 
         PairsTheme* themeForName(const QString& title) const;
-        QHash< int, QByteArray > roleNames() const;
         bool exists(const QString& icon);
         QByteArray themeData(const QString& path) const;
         
     public slots:
         QVariant info(int row, const QByteArray& role);
-        void refresh(const QString &type, const QString &lang);
+        bool isPertinent(int row, const QString &type,const QString &lang);
         
         /** @returns a random image from any theme */
         QString randomThemesImage() const;


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

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