Using user specified or random image
authortimoph <timop.harkonen@gmail.com>
Sun, 3 Jan 2010 08:34:57 +0000 (08:34 +0000)
committertimoph <timop.harkonen@gmail.com>
Sun, 3 Jan 2010 08:34:57 +0000 (08:34 +0000)
git-svn-id: file:///svnroot/impuzzle/trunk@9 e6bec12f-0854-4cc4-ad26-6875f1509f77

debian/changelog
src/defines.h
src/settingsdialog.cpp
src/settingsdialog.h

index 3bbd7bd..149fe01 100644 (file)
@@ -1,8 +1,11 @@
 impuzzle (0.2-1maemo0) unstable; urgency=low
 
+  * Implements: User specified image used in puzzle
+  * Implements: Random image used in puzzle
+  * Implements: Difficulty settings
   * Fixes: All pieces movable after shuffle
 
- -- Timo Härkönen <timop.harkonen@gmail.com>  Sat, 2 Jan 2010 17:26:12 +0200
+ -- Timo Härkönen <timop.harkonen@gmail.com>  Sun, 3 Jan 2010 10:32:42 +0200
 
 impuzzle (0.1-1maemo1) unstable; urgency=low
 
index e977a23..066cffb 100644 (file)
 
 #define IMAGE_HEIGHT 400
 
-#define GAME_VERSION = "0.1"
+#define GAME_VERSION = "0.2"
 
 #define EASY_PIECE_COUNT 12
 #define HARD_PIECE_COUNT 20
 
+#define DEFAULT_IMAGE_TXT "Default image"
+#define RANDOM_IMAGE_TXT "Random image"
+#define SELECT_IMAGE_TXT "Select image..."
+
 #endif // DEFINES_H
index 0c2b751..985dfb6 100644 (file)
@@ -7,6 +7,12 @@
 #include <QGroupBox>
 #include <QVBoxLayout>
 #include <QHBoxLayout>
+#include <QComboBox>
+#include <QFileDialog>
+#include <QDir>
+#include <QLabel>
+
+#include <QDebug>
 
 SettingsDialog::SettingsDialog(QWidget *parent) :
         QDialog(parent)
@@ -24,12 +30,25 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
     buttonGroup_ = new QGroupBox(tr("Difficulty"));
     buttonGroup_->setLayout(buttonLayout_);
 
+    QStringList items;
+    items << DEFAULT_IMAGE_TXT << RANDOM_IMAGE_TXT << SELECT_IMAGE_TXT;
+
+    imageCombo_ = new QComboBox;
+    imageCombo_->addItems(items);
+
+    selectedImageLabel_ = new QLabel(tr("n/a"));
+
     mainLayout_ = new QVBoxLayout;
     mainLayout_->addWidget(buttonGroup_);
+    mainLayout_->addWidget(imageCombo_);
+    mainLayout_->addWidget(selectedImageLabel_);
+
+    selectedImageLabel_->setVisible(false);
 
     setLayout(mainLayout_);
 
     connect(easyButton_, SIGNAL(toggled(bool)), this, SLOT(difficultySelectionChanged(bool)));
+    connect(imageCombo_, SIGNAL(currentIndexChanged(QString)), this, SLOT(imageSelectionChanged(QString)));
 }
 
 void SettingsDialog::difficultySelectionChanged(bool value)
@@ -41,3 +60,52 @@ void SettingsDialog::difficultySelectionChanged(bool value)
         Settings::instance()->setPieceCount(HARD_PIECE_COUNT);
     }
 }
+
+void SettingsDialog::imageSelectionChanged(const QString &txt)
+{
+    if(txt == RANDOM_IMAGE_TXT) {
+        qDebug() << "Random image selected";
+
+        // Get random image from ~/MyDocs/.images/
+        QStringList filters;
+        filters << "*.jpg" << "*.png" << "*.xpm";
+
+        QDir dir(QDir::homePath() + QLatin1String("/MyDocs/.images"));
+        //dir.setNameFilters(filters);
+
+        QStringList pics = dir.entryList(filters, QDir::Files | QDir::NoSymLinks);
+
+        qDebug() << QString("pics list contains %1 entries").arg(pics.count());
+
+        Settings::instance()->setImage(QPixmap(QDir::homePath() + QLatin1String("/MyDocs/.images/") + pics.at(qrand() % pics.count())));
+
+        if(selectedImageLabel_->isVisible()) {
+            selectedImageLabel_->setVisible(false);
+        }
+    }
+    else if(txt == SELECT_IMAGE_TXT) {
+        qDebug() << "Select image... selected";
+
+        // Open file selection dialog
+        QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
+                                                        QDir::homePath() + QLatin1String("/MyDocs/.images"),
+                                                         tr("Images (*.png *.xpm *.jpg)"));
+
+        Settings::instance()->setImage(QPixmap(fileName));
+
+        selectedImageLabel_->setText(fileName);
+
+        if(!selectedImageLabel_->isVisible() && !fileName.isEmpty()) {
+            selectedImageLabel_->setVisible(true);
+        }
+    }
+    else {
+        qDebug() << "Default image selected";
+
+        Settings::instance()->setImage(0);
+
+        if(selectedImageLabel_->isVisible()) {
+            selectedImageLabel_->setVisible(false);
+        }
+    }
+}
index 53feb67..6d2babc 100644 (file)
@@ -7,6 +7,8 @@ class QVBoxLayout;
 class QGroupBox;
 class QRadioButton;
 class QHBoxLayout;
+class QComboBox;
+class QLabel;
 
 class SettingsDialog : public QDialog
 {
@@ -17,6 +19,7 @@ public:
 
 private slots:
     void difficultySelectionChanged(bool value);
+    void imageSelectionChanged(const QString &txt);
 
 private:
     QVBoxLayout *mainLayout_;
@@ -26,5 +29,9 @@ private:
     QRadioButton *hardButton_;
 
     QGroupBox *buttonGroup_;
+
+    QComboBox *imageCombo_;
+
+    QLabel *selectedImageLabel_;
 };
 #endif