X-Git-Url: http://git.maemo.org/git/?p=impuzzle;a=blobdiff_plain;f=src%2Fsettingsdialog.cpp;h=019ca4871d0be1cc1d7497e58cb5eeb28beb69a2;hp=6507153e1214c87029eb59e9fca64024b2d9a8ab;hb=6ccd3c118b19d854dfa0fe9396cdf8885b52994a;hpb=3fffc1c138902d3bebc6c27c9354436541e29383 diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 6507153..019ca48 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -1,3 +1,21 @@ +/* + Image Puzzle - A set your pieces straight game + Copyright (C) 2009 Timo Härkönen + + 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 3 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 "settingsdialog.h" #include "settings.h" #include "defines.h" @@ -35,6 +53,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : imageCombo_ = new QComboBox; imageCombo_->addItems(items); + imageCombo_->setCurrentIndex(1); selectedImageLabel_ = new QLabel(tr("n/a")); @@ -48,7 +67,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : setLayout(mainLayout_); connect(easyButton_, SIGNAL(toggled(bool)), this, SLOT(difficultySelectionChanged(bool))); - connect(imageCombo_, SIGNAL(currentIndexChanged(QString)), this, SLOT(imageSelectionChanged(QString))); + //connect(imageCombo_, SIGNAL(currentIndexChanged(QString)), this, SLOT(imageSelectionChanged(QString))); + connect(imageCombo_, SIGNAL(activated(QString)), this, SLOT(imageSelectionChanged(QString))); } int SettingsDialog::exec() @@ -77,6 +97,7 @@ void SettingsDialog::imageSelectionChanged(const QString &txt) qDebug() << "Random image selected"; // Get random image from ~/MyDocs/.images/ + //TODO: images from other directories QStringList filters; filters << "*.jpg" << "*.png" << "*.xpm"; @@ -85,16 +106,24 @@ void SettingsDialog::imageSelectionChanged(const QString &txt) QStringList pics = dir.entryList(filters, QDir::Files | QDir::NoSymLinks); - qDebug() << QString("pics list contains %1 entries").arg(pics.count()); + //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(!pics.isEmpty()) { + QString path = QDir::homePath() + QLatin1String("/MyDocs/.images/") + pics.at(qrand() % pics.count()); + Settings::instance()->setImage(QPixmap(path)); + Settings::instance()->setImagePath(path); + } + else { + Settings::instance()->setImage(QPixmap(":/images/default.jpg")); + Settings::instance()->setImagePath("default"); + } if(selectedImageLabel_->isVisible()) { selectedImageLabel_->setVisible(false); } } else if(txt == SELECT_IMAGE_TXT) { - qDebug() << "Select image... selected"; + //qDebug() << "Select image... selected"; // Open file selection dialog QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), @@ -102,6 +131,7 @@ void SettingsDialog::imageSelectionChanged(const QString &txt) tr("Images (*.png *.xpm *.jpg)")); Settings::instance()->setImage(QPixmap(fileName)); + Settings::instance()->setImagePath(fileName); selectedImageLabel_->setText(fileName); @@ -110,9 +140,10 @@ void SettingsDialog::imageSelectionChanged(const QString &txt) } } else { - qDebug() << "Default image selected"; + //qDebug() << "Default image selected"; Settings::instance()->setImage(0); + Settings::instance()->setImagePath("default"); if(selectedImageLabel_->isVisible()) { selectedImageLabel_->setVisible(false);