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