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

libkmahjongg

kmahjonggtilesetselector.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 "kmahjonggtilesetselector.h"
00020 
00021 #include <klocale.h>
00022 #include <kstandarddirs.h>
00023 #include <QPainter>
00024 
00025 #include "kmahjonggtileset.h"
00026 
00027 KMahjonggTilesetSelector::KMahjonggTilesetSelector( QWidget* parent, KConfigSkeleton * aconfig )
00028         : QWidget( parent )
00029 {
00030     setupUi(this);
00031     setupData(aconfig);
00032 }
00033 
00034 KMahjonggTilesetSelector::~KMahjonggTilesetSelector()
00035 {
00036      tilesetMap.clear();
00037 }
00038 
00039 void KMahjonggTilesetSelector::setupData(KConfigSkeleton * aconfig)
00040 {
00041     //Get our currently configured Tileset entry
00042     KConfig * config = aconfig->config();
00043     KConfigGroup group = config->group("General");
00044     QString initialGroup = group.readEntry("Tileset_file");
00045 
00046     //The lineEdit widget holds our tileset path, but the user does not manipulate it directly
00047     kcfg_TileSet->hide();
00048 
00049     //This will also load our resourcedir if it is not done already
00050     KMahjonggTileset tile;
00051 
00052     //Now get our tilesets into a list
00053     QStringList tilesAvailable = KGlobal::dirs()->findAllResources("kmahjonggtileset", QString("*.desktop"), KStandardDirs::Recursive);
00054 
00055     QString namestr("Name");
00056     int numvalidentries = 0;
00057     for (int i = 0; i < tilesAvailable.size(); ++i)
00058     {   
00059         KMahjonggTileset * aset = new KMahjonggTileset();
00060         QString atileset = tilesAvailable.at(i);
00061         if (aset->loadTileset(atileset)) {
00062             tilesetMap.insert(aset->authorProperty(namestr), aset);
00063             tilesetList->addItem(aset->authorProperty(namestr));
00064             //Find if this is our currently configured Tileset
00065             if (atileset==initialGroup) {
00066                 //Select current entry
00067                 tilesetList->setCurrentRow(numvalidentries);
00068                 tilesetChanged();
00069             }
00070             ++numvalidentries;
00071         } else {
00072             delete aset;
00073         }
00074     }
00075     
00076     connect(tilesetList, SIGNAL(currentItemChanged ( QListWidgetItem * , QListWidgetItem * )), this, SLOT(tilesetChanged()));
00077 }
00078 
00079 void KMahjonggTilesetSelector::tilesetChanged()
00080 {
00081     KMahjonggTileset * selTileset = tilesetMap.value(tilesetList->currentItem()->text());
00082         //Sanity checkings. Should not happen.
00083     if (!selTileset) return;
00084     if (selTileset->path()==kcfg_TileSet->text()) {
00085         return;
00086     }
00087     QString authstr("Author");
00088     QString contactstr("AuthorEmail");
00089     QString descstr("Description");
00090     kcfg_TileSet->setText(selTileset->path());
00091     tilesetAuthor->setText(selTileset->authorProperty(authstr));
00092     tilesetContact->setText(selTileset->authorProperty(contactstr));
00093     tilesetDescription->setText(selTileset->authorProperty(descstr));
00094 
00095     //Make sure SVG is loaded when graphics is selected
00096     if (!selTileset->loadGraphics()) return;
00097     //Let the tileset calculate its ideal size for the preview area, but reduce the margins a bit (pass oversized drawing area)
00098     QSize tilesize = selTileset->preferredTileSize(tilesetPreview->size()*1.3, 1, 1);
00099     selTileset->reloadTileset(tilesize);
00100     //Draw the preview
00101     QImage qiRend(tilesetPreview->size(),QImage::Format_ARGB32_Premultiplied);
00102     qiRend.fill(0);
00103     QPainter p(&qiRend);
00104     //Calculate the margins to center the tile
00105     QSize margin = tilesetPreview->size() - tilesize;
00106     //Draw unselected tile and first tileface
00107     p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->unselectedTile(1));
00108     p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->tileface(0));
00109     p.end();
00110     tilesetPreview->setPixmap(QPixmap::fromImage(qiRend));
00111 
00112 }
00113 
00114 #include "kmahjonggtilesetselector.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