• 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
kmahjonggbackgroundselector.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 "kmahjonggbackgroundselector.h"
20 
21 #include <klocale.h>
22 #include <kstandarddirs.h>
23 #include <QPainter>
24 #include "kmahjonggbackground.h"
25 
26 KMahjonggBackgroundSelector::KMahjonggBackgroundSelector( QWidget* parent, KConfigSkeleton * aconfig )
27  : QWidget( parent )
28 {
29  setupUi(this);
30  setupData(aconfig);
31 }
32 
33 KMahjonggBackgroundSelector::~KMahjonggBackgroundSelector()
34 {
35  qDeleteAll(backgroundMap);
36 }
37 
38 void KMahjonggBackgroundSelector::setupData(KConfigSkeleton * aconfig)
39 {
40  //Get our currently configured Tileset entry
41  KConfig * config = aconfig->config();
42  KConfigGroup group = config->group("General");
43  QString initialGroup = group.readEntry("Background_file");
44 
45  //The lineEdit widget holds our bg path, but the user does not manipulate it directly
46  kcfg_Background->hide();
47 
48  KMahjonggBackground bg;
49 
50  //Now get our tilesets into a list
51  QStringList bgsAvailable = KGlobal::dirs()->findAllResources("kmahjonggbackground", QLatin1String( "*.desktop"), KStandardDirs::Recursive);
52  QLatin1String namestr("Name");
53  int numvalidentries = 0;
54  for (int i = 0; i < bgsAvailable.size(); ++i)
55  {
56  KMahjonggBackground * abg = new KMahjonggBackground();
57  QString bgpath = bgsAvailable.at(i);
58  if (abg->load(bgpath,backgroundPreview->width(),backgroundPreview->height())) {
59  backgroundMap.insert(abg->authorProperty(namestr), abg);
60  backgroundList->addItem(abg->authorProperty(namestr));
61  //Find if this is our currently configured Tileset
62  if (bgpath==initialGroup) {
63  //Select current entry
64  backgroundList->setCurrentRow(numvalidentries);
65  backgroundChanged();
66  }
67  ++numvalidentries;
68  } else {
69  delete abg;
70  }
71  }
72 
73  connect(backgroundList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(backgroundChanged()));
74 }
75 
76 void KMahjonggBackgroundSelector::backgroundChanged()
77 {
78  KMahjonggBackground * selBG = backgroundMap.value(backgroundList->currentItem()->text());
79  //Sanity checkings. Should not happen.
80  if (!selBG) return;
81  if (selBG->path()==kcfg_Background->text()) {
82  return;
83  }
84  QLatin1String authstr("Author");
85  QLatin1String contactstr("AuthorEmail");
86  QLatin1String descstr("Description");
87  kcfg_Background->setText(selBG->path());
88  backgroundAuthor->setText(selBG->authorProperty(authstr));
89  backgroundContact->setText(selBG->authorProperty(contactstr));
90  backgroundDescription->setText(selBG->authorProperty(descstr));
91 
92  if (selBG->authorProperty(QLatin1String( "Plain" )) == QLatin1String("1")) {
93  backgroundPreview->setPixmap(QPixmap());
94  return;
95  }
96 
97  //Make sure SVG is loaded when graphics is selected
98  if (!selBG->loadGraphics()) return;
99 
100  //Draw the preview
101  //TODO here: add code to load and keep proportions for non-tiled content?
102  QImage qiRend(backgroundPreview->size(),QImage::Format_ARGB32_Premultiplied);
103  qiRend.fill(0);
104  QPainter p(&qiRend);
105  p.fillRect(p.viewport(), selBG->getBackground() );
106  p.end();
107  backgroundPreview->setPixmap(QPixmap::fromImage(qiRend));
108 
109 }
110 
111 #include "kmahjonggbackgroundselector.moc"
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
QPainter::end
bool end()
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
KMahjonggBackground::getBackground
QBrush & getBackground()
Definition: kmahjonggbackground.cpp:189
KMahjonggBackground::path
QString path() const
Definition: kmahjonggbackground.cpp:202
KMahjonggBackground::loadGraphics
bool loadGraphics()
Definition: kmahjonggbackground.cpp:151
QList::at
const T & at(int i) const
QListWidgetItem
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
QList::size
int size() const
KMahjonggBackground
Definition: kmahjonggbackground.h:29
kmahjonggbackgroundselector.h
QImage::fill
void fill(uint pixelValue)
QPainter
KMahjonggBackgroundSelector::backgroundChanged
void backgroundChanged()
Definition: kmahjonggbackgroundselector.cpp:76
kmahjonggbackground.h
KMahjonggBackground::authorProperty
QString authorProperty(const QString &key) const
Definition: kmahjonggbackground.cpp:206
QString
QStringList
QPixmap
KMahjonggBackground::load
bool load(const QString &file, short width, short height)
Definition: kmahjonggbackground.cpp:92
QImage
QPainter::viewport
QRect viewport() const
KMahjonggBackgroundSelector::setupData
void setupData(KConfigSkeleton *config)
Definition: kmahjonggbackgroundselector.cpp:38
KMahjonggBackgroundSelector::KMahjonggBackgroundSelector
KMahjonggBackgroundSelector(QWidget *parent, KConfigSkeleton *config)
Definition: kmahjonggbackgroundselector.cpp:26
QLatin1String
QMap::insert
iterator insert(const Key &key, const T &value)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KMahjonggBackgroundSelector::backgroundMap
QMap< QString, KMahjonggBackground * > backgroundMap
Definition: kmahjonggbackgroundselector.h:36
KMahjonggBackgroundSelector::~KMahjonggBackgroundSelector
~KMahjonggBackgroundSelector()
Definition: kmahjonggbackgroundselector.cpp:33
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