libkmahjongg
kmahjonggbackgroundselector.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kmahjonggbackgroundselector.h"
00020
00021 #include <klocale.h>
00022 #include <kstandarddirs.h>
00023 #include <QPainter>
00024 #include "kmahjonggbackground.h"
00025
00026 KMahjonggBackgroundSelector::KMahjonggBackgroundSelector( QWidget* parent, KConfigSkeleton * aconfig )
00027 : QWidget( parent )
00028 {
00029 setupUi(this);
00030 setupData(aconfig);
00031 }
00032
00033 KMahjonggBackgroundSelector::~KMahjonggBackgroundSelector()
00034 {
00035 foreach(KMahjonggBackground* bg, backgroundMap) {
00036 delete bg;
00037 }
00038 backgroundMap.clear();
00039 }
00040
00041 void KMahjonggBackgroundSelector::setupData(KConfigSkeleton * aconfig)
00042 {
00043
00044 KConfig * config = aconfig->config();
00045 KConfigGroup group = config->group("General");
00046 QString initialGroup = group.readEntry("Background_file");
00047
00048
00049 kcfg_Background->hide();
00050
00051 KMahjonggBackground bg;
00052
00053
00054 QStringList bgsAvailable = KGlobal::dirs()->findAllResources("kmahjonggbackground", QString("*.desktop"), KStandardDirs::Recursive);
00055 QString namestr("Name");
00056 int numvalidentries = 0;
00057 for (int i = 0; i < bgsAvailable.size(); ++i)
00058 {
00059 KMahjonggBackground * abg = new KMahjonggBackground();
00060 QString bgpath = bgsAvailable.at(i);
00061 if (abg->load(bgpath,backgroundPreview->width(),backgroundPreview->height())) {
00062 backgroundMap.insert(abg->authorProperty(namestr), abg);
00063 backgroundList->addItem(abg->authorProperty(namestr));
00064
00065 if (bgpath==initialGroup) {
00066
00067 backgroundList->setCurrentRow(numvalidentries);
00068 backgroundChanged();
00069 }
00070 ++numvalidentries;
00071 } else {
00072 delete abg;
00073 }
00074 }
00075
00076 connect(backgroundList, SIGNAL(currentItemChanged ( QListWidgetItem * , QListWidgetItem * )), this, SLOT(backgroundChanged()));
00077 }
00078
00079 void KMahjonggBackgroundSelector::backgroundChanged()
00080 {
00081 KMahjonggBackground * selBG = backgroundMap.value(backgroundList->currentItem()->text());
00082
00083 if (!selBG) return;
00084 if (selBG->path()==kcfg_Background->text()) {
00085 return;
00086 }
00087 QString authstr("Author");
00088 QString contactstr("AuthorEmail");
00089 QString descstr("Description");
00090 kcfg_Background->setText(selBG->path());
00091 backgroundAuthor->setText(selBG->authorProperty(authstr));
00092 backgroundContact->setText(selBG->authorProperty(contactstr));
00093 backgroundDescription->setText(selBG->authorProperty(descstr));
00094
00095
00096 if (!selBG->loadGraphics()) return;
00097
00098
00099
00100 QImage qiRend(backgroundPreview->size(),QImage::Format_ARGB32_Premultiplied);
00101 qiRend.fill(0);
00102 QPainter p(&qiRend);
00103 p.fillRect(p.viewport(), selBG->getBackground() );
00104 p.end();
00105 backgroundPreview->setPixmap(QPixmap::fromImage(qiRend));
00106
00107 }
00108
00109 #include "kmahjonggbackgroundselector.moc"