• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkmahjongg

  • sources
  • kde-4.14
  • kdegames
  • libkmahjongg
kmahjonggtilesetselector.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
3 
4  Libkmahjongg is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kmahjonggtilesetselector.h"
20 
21 #include <klocale.h>
22 #include <kstandarddirs.h>
23 #include <QPainter>
24 
25 #include "kmahjonggtileset.h"
26 
27 KMahjonggTilesetSelector::KMahjonggTilesetSelector( QWidget* parent, KConfigSkeleton * aconfig )
28  : QWidget( parent )
29 {
30  setupUi(this);
31  setupData(aconfig);
32 }
33 
34 KMahjonggTilesetSelector::~KMahjonggTilesetSelector()
35 {
36  tilesetMap.clear();
37 }
38 
39 void KMahjonggTilesetSelector::setupData(KConfigSkeleton * aconfig)
40 {
41  //Get our currently configured Tileset entry
42  KConfig * config = aconfig->config();
43  KConfigGroup group = config->group("General");
44  QString initialGroup = group.readEntry("Tileset_file");
45 
46  //The lineEdit widget holds our tileset path, but the user does not manipulate it directly
47  kcfg_TileSet->hide();
48 
49  //This will also load our resourcedir if it is not done already
50  KMahjonggTileset tile;
51 
52  //Now get our tilesets into a list
53  QStringList tilesAvailable = KGlobal::dirs()->findAllResources("kmahjonggtileset", QLatin1String( "*.desktop"), KStandardDirs::Recursive);
54 
55  QLatin1String namestr("Name");
56  int numvalidentries = 0;
57  for (int i = 0; i < tilesAvailable.size(); ++i)
58  {
59  KMahjonggTileset * aset = new KMahjonggTileset();
60  QString atileset = tilesAvailable.at(i);
61  if (aset->loadTileset(atileset)) {
62  tilesetMap.insert(aset->authorProperty(namestr), aset);
63  tilesetList->addItem(aset->authorProperty(namestr));
64  //Find if this is our currently configured Tileset
65  if (atileset==initialGroup) {
66  //Select current entry
67  tilesetList->setCurrentRow(numvalidentries);
68  tilesetChanged();
69  }
70  ++numvalidentries;
71  } else {
72  delete aset;
73  }
74  }
75 
76  connect(tilesetList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(tilesetChanged()));
77 }
78 
79 void KMahjonggTilesetSelector::tilesetChanged()
80 {
81  KMahjonggTileset * selTileset = tilesetMap.value(tilesetList->currentItem()->text());
82  //Sanity checkings. Should not happen.
83  if (!selTileset) return;
84  if (selTileset->path()==kcfg_TileSet->text()) {
85  return;
86  }
87  QLatin1String authstr("Author");
88  QLatin1String contactstr("AuthorEmail");
89  QLatin1String descstr("Description");
90  kcfg_TileSet->setText(selTileset->path());
91  tilesetAuthor->setText(selTileset->authorProperty(authstr));
92  tilesetContact->setText(selTileset->authorProperty(contactstr));
93  tilesetDescription->setText(selTileset->authorProperty(descstr));
94 
95  //Make sure SVG is loaded when graphics is selected
96  if (!selTileset->loadGraphics()) return;
97  //Let the tileset calculate its ideal size for the preview area, but reduce the margins a bit (pass oversized drawing area)
98  QSize tilesize = selTileset->preferredTileSize(tilesetPreview->size()*1.3, 1, 1);
99  selTileset->reloadTileset(tilesize);
100  //Draw the preview
101  QImage qiRend(tilesetPreview->size(),QImage::Format_ARGB32_Premultiplied);
102  qiRend.fill(0);
103  QPainter p(&qiRend);
104  //Calculate the margins to center the tile
105  QSize margin = tilesetPreview->size() - tilesize;
106  //Draw unselected tile and first tileface
107  p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->unselectedTile(1));
108  p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->tileface(0));
109  p.end();
110  tilesetPreview->setPixmap(QPixmap::fromImage(qiRend));
111 
112 }
113 
114 #include "kmahjonggtilesetselector.moc"
KMahjonggTileset::unselectedTile
QPixmap unselectedTile(int num)
Definition: kmahjonggtileset.cpp:359
KMahjonggTilesetSelector::~KMahjonggTilesetSelector
~KMahjonggTilesetSelector()
Definition: kmahjonggtilesetselector.cpp:34
KMahjonggTilesetSelector::setupData
void setupData(KConfigSkeleton *config)
Definition: kmahjonggtilesetselector.cpp:39
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
QSize::width
int width() const
QPainter::end
bool end()
KMahjonggTileset::preferredTileSize
QSize preferredTileSize(const QSize &boardsize, int horizontalCells, int verticalCells)
Definition: kmahjonggtileset.cpp:101
QList::at
const T & at(int i) const
QListWidgetItem
KMahjonggTilesetSelector::tilesetChanged
void tilesetChanged()
Definition: kmahjonggtilesetselector.cpp:79
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
QMap::clear
void clear()
QList::size
int size() const
KMahjonggTileset::path
QString path() const
Definition: kmahjonggtileset.cpp:172
KMahjonggTileset::tileface
QPixmap tileface(int num)
Definition: kmahjonggtileset.cpp:370
QImage::fill
void fill(uint pixelValue)
KMahjonggTileset::loadGraphics
bool loadGraphics()
Definition: kmahjonggtileset.cpp:254
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
KMahjonggTileset::reloadTileset
bool reloadTileset(const QSize &newTilesize)
Definition: kmahjonggtileset.cpp:277
QString
QStringList
QSize
KMahjonggTileset::loadTileset
bool loadTileset(const QString &tilesetPath)
Definition: kmahjonggtileset.cpp:180
QImage
KMahjonggTileset
Definition: kmahjonggtileset.h:30
KMahjonggTileset::authorProperty
QString authorProperty(const QString &key) const
Definition: kmahjonggtileset.cpp:137
QLatin1String
QSize::height
int height() const
kmahjonggtilesetselector.h
KMahjonggTilesetSelector::KMahjonggTilesetSelector
KMahjonggTilesetSelector(QWidget *parent, KConfigSkeleton *config)
Definition: kmahjonggtilesetselector.cpp:27
QMap::insert
iterator insert(const Key &key, const T &value)
KMahjonggTilesetSelector::tilesetMap
QMap< QString, KMahjonggTileset * > tilesetMap
Definition: kmahjonggtilesetselector.h:36
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
kmahjonggtileset.h
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkmahjongg

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

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal