• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkmahjongg

kmahjonggbackgroundselector.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2006 Mauricio Piacentini  <mauricio@tabuleiro.com>
00003 
00004     Libkmahjongg is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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     //Get our currently configured Tileset entry
00044     KConfig * config = aconfig->config();
00045     KConfigGroup group = config->group("General");
00046     QString initialGroup = group.readEntry("Background_file");
00047 
00048     //The lineEdit widget holds our bg path, but the user does not manipulate it directly
00049     kcfg_Background->hide();
00050 
00051     KMahjonggBackground bg;
00052 
00053     //Now get our tilesets into a list
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             //Find if this is our currently configured Tileset
00065             if (bgpath==initialGroup) {
00066                 //Select current entry
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         //Sanity checkings. Should not happen.
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     //Make sure SVG is loaded when graphics is selected
00096     if (!selBG->loadGraphics()) return;
00097 
00098     //Draw the preview
00099     //TODO here: add code to load and keep proportions for non-tiled content?
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"

libkmahjongg

Skip menu "libkmahjongg"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal