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

kmahjongg

  • sources
  • kde-4.14
  • kdegames
  • kmahjongg
kmahjongglayoutselector.cpp
Go to the documentation of this file.
1 /*
2  KMahjonggLayoutSelector
3  Part of kmahjongg, the classic mahjongg game for KDE
4 
5  Copyright (C) 2007 Mauricio Piacentini <mauricio@tabuleiro.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21 */
22 
23 #include "kmahjongglayoutselector.h"
24 
25 #include "boardwidget.h"
26 #include "prefs.h"
27 
28 #include <klocale.h>
29 #include <kstandarddirs.h>
30 #include <QPainter>
31 
32 #include "kmahjongglayout.h"
33 
34 KMahjonggLayoutSelector::KMahjonggLayoutSelector( QWidget* parent, KConfigSkeleton * aconfig )
35  : QWidget( parent )
36 {
37  setupUi(this);
38  bw = new BoardWidget( layoutPreview );
39  bw->resize(layoutPreview->size());
40  setupData(aconfig);
41 }
42 
43 void KMahjonggLayoutSelector::setupData(KConfigSkeleton * aconfig)
44 {
45  //Get our currently configured Layout entry
46  KConfig * config = aconfig->config();
47  KConfigGroup group = config->group("General");
48  QString initialGroup = group.readEntry("Layout_file");
49 
50  //The lineEdit widget holds our tileset path, but the user does not manipulate it directly
51  kcfg_Layout->hide();
52 
53  //No new stuff yet
54  getNewButton->hide();
55 
56  //This will also load our resourcedir if it is not done already
57  KMahjonggLayout tile;
58 
59  //Now get our tilesets into a list
60  QStringList tilesAvailable = KGlobal::dirs()->findAllResources("kmahjongglayout", QString("*.desktop"), KStandardDirs::Recursive);
61  tilesAvailable.sort();
62  QString namestr("Name");
63  int numvalidentries = 0;
64  for (int i = 0; i < tilesAvailable.size(); ++i)
65  {
66  KMahjonggLayout * aset = new KMahjonggLayout();
67  QString atileset = tilesAvailable.at(i);
68  if (aset->load(atileset)) {
69  layoutMap.insert(aset->authorProperty(namestr), aset);
70  layoutList->addItem(aset->authorProperty(namestr));
71  //Find if this is our currently configured Tileset
72  if (atileset==initialGroup) {
73  //Select current entry
74  layoutList->setCurrentRow(numvalidentries);
75  layoutChanged();
76  }
77  ++numvalidentries;
78  } else {
79  delete aset;
80  }
81  }
82 
83  connect(layoutList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(layoutChanged()));
84 }
85 
86 void KMahjonggLayoutSelector::layoutChanged()
87 {
88  KMahjonggLayout * selLayout = layoutMap.value(layoutList->currentItem()->text());
89  //Sanity checkings. Should not happen.
90  if (!selLayout) return;
91  if (selLayout->path()==kcfg_Layout->text()) {
92  return;
93  }
94  QString authstr("Author");
95  QString contactstr("AuthorEmail");
96  QString descstr("Description");
97  kcfg_Layout->setText(selLayout->path());
98  layoutAuthor->setText(selLayout->authorProperty(authstr));
99  layoutContact->setText(selLayout->authorProperty(contactstr));
100  layoutDescription->setText(selLayout->authorProperty(descstr));
101 
102  //If settings for tiles/background have been applied, update our preview
103  if (bw->theTiles.path()!=Prefs::tileSet())
104  bw->loadTileset(Prefs::tileSet());
105  if (bw->theBackground.path()!=Prefs::background())
106  bw->loadBackground(Prefs::background());
107 
108  //Now load the boardLayout temporarily
109  bw->loadBoardLayout(selLayout->path());
110  bw->calculateNewGame();
111 
112  /* //Let the tileset calculate its ideal size for the preview area, but reduce the margins a bit (pass oversized drawing area)
113  QSize tilesize = selTileset->preferredTileSize(tilesetPreview->size()*1.3, 1, 1);
114  selTileset->reloadTileset(tilesize);
115  //Draw the preview
116  QImage qiRend(tilesetPreview->size(),QImage::Format_ARGB32_Premultiplied);
117  qiRend.fill(0);
118  QPainter p(&qiRend);
119  //Calculate the margins to center the tile
120  QSize margin = tilesetPreview->size() - tilesize;
121  //Draw unselected tile and first tileface
122  p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->unselectedTile(1));
123  p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->tileface(0));
124  tilesetPreview->setPixmap(QPixmap::fromImage(qiRend));*/
125 }
126 
127 void KMahjonggLayoutSelector::useRandomLayoutToggled(bool active) {
128  widgetNoRandom->setEnabled(!active);
129 }
130 
131 #include "kmahjongglayoutselector.moc"
KMahjonggLayoutSelector::useRandomLayoutToggled
void useRandomLayoutToggled(bool)
Definition: kmahjongglayoutselector.cpp:127
KMahjonggLayout
Definition: kmahjongglayout.h:28
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
KMahjonggLayoutSelector::layoutMap
QMap< QString, KMahjonggLayout * > layoutMap
Definition: kmahjongglayoutselector.h:41
QList::at
const T & at(int i) const
KMahjonggLayout::load
bool load(const QString &file)
Definition: kmahjongglayout.cpp:76
BoardWidget::calculateNewGame
void calculateNewGame(int num=-1)
Method Description.
Definition: boardwidget.cpp:717
QListWidgetItem
prefs.h
KConfigSkeleton
BoardWidget::theBackground
KMahjonggBackground theBackground
Definition: boardwidget.h:130
QList::size
int size() const
KMahjonggLayoutSelector::setupData
void setupData(KConfigSkeleton *config)
Definition: kmahjongglayoutselector.cpp:43
BoardWidget::loadBackground
bool loadBackground(const QString &, bool bShowError=true)
Slot Description.
Definition: boardwidget.cpp:1048
KMahjonggLayout::path
QString path() const
Definition: kmahjongglayout.cpp:123
boardwidget.h
QString
KMahjonggLayout::authorProperty
QString authorProperty(const QString &key) const
Definition: kmahjongglayout.cpp:127
QStringList
Prefs::tileSet
static QString tileSet()
Get The tile-set to use.
Definition: prefs.h:30
BoardWidget::loadBoardLayout
bool loadBoardLayout(const QString &)
Slot Description.
Definition: boardwidget.cpp:1098
QStringList::sort
void sort()
QMap::insert
iterator insert(const Key &key, const T &value)
Prefs::background
static QString background()
Get The background to use.
Definition: prefs.h:49
kmahjongglayoutselector.h
KMahjonggLayoutSelector::KMahjonggLayoutSelector
KMahjonggLayoutSelector(QWidget *parent, KConfigSkeleton *config)
Definition: kmahjongglayoutselector.cpp:34
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
BoardWidget::loadTileset
bool loadTileset(const QString &)
Slot Description.
Definition: boardwidget.cpp:1078
BoardWidget::theTiles
KMahjonggTileset theTiles
Definition: boardwidget.h:129
kmahjongglayout.h
KMahjonggLayoutSelector::layoutChanged
void layoutChanged()
Definition: kmahjongglayoutselector.cpp:86
QMap::value
const T value(const Key &key) const
BoardWidget
Where all the funn happens.
Definition: boardwidget.h:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmahjongg

Skip menu "kmahjongg"
  • 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