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

granatier

  • sources
  • kde-4.14
  • kdegames
  • granatier
  • src
  • config
playerselectoritem.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Mathias Kraus <k.hias@gmx.de>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "playerselectoritem.h"
19 #include "playersettings.h"
20 
21 #include <QtGui/QLabel>
22 #include <QtGui/QVBoxLayout>
23 #include <QtGui/QHBoxLayout>
24 #include <QtGui/QGridLayout>
25 #include <QtGui/QSpacerItem>
26 #include <QtGui/QCheckBox>
27 
28 #include <KDE/KLineEdit>
29 #include <KDE/KKeySequenceWidget>
30 #include <KDE/KLocalizedString>
31 
32 
33 PlayerSelectorItem::PlayerSelectorItem(const QString& playerId, PlayerSettings* playerSettings, QWidget* parent) : QWidget(parent), m_playerId(playerId), m_playerSettings(playerSettings)
34 {
35  m_selectCheckBox = new QCheckBox;
36  m_selectCheckBox->setChecked(m_playerSettings->enabled(playerId));
37  m_playerName = new KLineEdit(m_playerSettings->playerName(playerId));
38  m_playerName->setFixedWidth(200);
39  m_playerPreviewPixmap = new QPixmap(QSize(64, 64));
40  m_playerPreviewPixmapAlphaChannel = new QPixmap(QSize(64, 64));
41  m_playerPreviewPixmapLabel = new QLabel;
42  m_playerAuthor = new QLabel;
43 
44  QHBoxLayout* mainLayout = new QHBoxLayout(this);
45  mainLayout->setMargin(6);
46 
47  QGridLayout* gridLayoutPlayer = new QGridLayout();
48  gridLayoutPlayer->setMargin(0);
49 
50  QVBoxLayout* verticalLayoutKeySequence = new QVBoxLayout();
51  verticalLayoutKeySequence->setMargin(0);
52 
53  mainLayout->addLayout(gridLayoutPlayer);
54  mainLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
55  mainLayout->addLayout(verticalLayoutKeySequence);
56  mainLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
57 
58  gridLayoutPlayer->addWidget(m_selectCheckBox, 0, 0);
59  gridLayoutPlayer->addWidget(m_playerName, 0, 1, 1, 3);
60  gridLayoutPlayer->addWidget(m_playerPreviewPixmapLabel, 1, 1, 2, 1);
61  gridLayoutPlayer->addWidget(m_playerAuthor, 2, 2);//, 1, 1, Qt::AlignBottom);
62 
63  QGridLayout* gridLayoutKeySequence = new QGridLayout();
64  gridLayoutKeySequence->setMargin(0);
65 
66  verticalLayoutKeySequence->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
67  verticalLayoutKeySequence->addLayout(gridLayoutKeySequence);
68  verticalLayoutKeySequence->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
69 
70  m_moveLeft = new KKeySequenceWidget(this);
71  m_moveLeft->setMultiKeyShortcutsAllowed(false);
72  m_moveLeft->setModifierlessAllowed(true);
73  m_moveLeft->setClearButtonShown(false);
74  m_moveLeft->setKeySequence(m_playerSettings->keyLeft(playerId));
75  m_labelMoveLeft = new QLabel(i18nc("Label for the key sequence to move the player.", "Left:"));
76  gridLayoutKeySequence->addWidget(m_labelMoveLeft, 1, 1, Qt::AlignRight);
77  gridLayoutKeySequence->addWidget(m_moveLeft, 1, 2);
78 
79  m_moveUp = new KKeySequenceWidget(this);
80  m_moveUp->setMultiKeyShortcutsAllowed(false);
81  m_moveUp->setModifierlessAllowed(true);
82  m_moveUp->setClearButtonShown(false);
83  m_moveUp->setKeySequence(m_playerSettings->keyUp(playerId));
84  m_labelMoveUp = new QLabel(i18nc("Label for the key sequence to move the player.", "Up:"));
85  gridLayoutKeySequence->addWidget(m_labelMoveUp, 0, 3, Qt::AlignRight);
86  gridLayoutKeySequence->addWidget(m_moveUp, 0, 4);
87 
88  m_moveRight = new KKeySequenceWidget(this);
89  m_moveRight->setMultiKeyShortcutsAllowed(false);
90  m_moveRight->setModifierlessAllowed(true);
91  m_moveRight->setClearButtonShown(false);
92  m_moveRight->setKeySequence(m_playerSettings->keyRight(playerId));
93  m_labelMoveRight = new QLabel(i18nc("Label for the key sequence to move the player.", "Right:"));
94  gridLayoutKeySequence->addWidget(m_labelMoveRight, 1, 5, Qt::AlignRight);
95  gridLayoutKeySequence->addWidget(m_moveRight, 1, 6);
96 
97  m_moveDown = new KKeySequenceWidget(this);
98  m_moveDown->setMultiKeyShortcutsAllowed(false);
99  m_moveDown->setModifierlessAllowed(true);
100  m_moveDown->setClearButtonShown(false);
101  m_moveDown->setKeySequence(m_playerSettings->keyDown(playerId));
102  m_labelMoveDown = new QLabel(i18nc("Label for the key sequence to move the player.", "Down:"));
103  gridLayoutKeySequence->addWidget(m_labelMoveDown, 2, 3, Qt::AlignRight);
104  gridLayoutKeySequence->addWidget(m_moveDown, 2, 4);
105 
106  m_dropBomb = new KKeySequenceWidget(this);
107  m_dropBomb->setMultiKeyShortcutsAllowed(false);
108  m_dropBomb->setModifierlessAllowed(true);
109  m_dropBomb->setClearButtonShown(false);
110  m_dropBomb->setKeySequence(m_playerSettings->keyPutBomb(playerId));
111  m_labelDropBomb = new QLabel(i18nc("Label for the key sequence to move the player.", "Bomb:"));
112  gridLayoutKeySequence->addWidget(m_labelDropBomb, 1, 3, Qt::AlignRight);
113  gridLayoutKeySequence->addWidget(m_dropBomb, 1, 4);
114 
115  selectionChanged(m_selectCheckBox->isChecked());
116  connect(m_selectCheckBox, SIGNAL(toggled(bool)), this, SLOT(selectionChanged(bool)));
117  connect(m_selectCheckBox, SIGNAL(toggled(bool)), this, SLOT(settingsChanged()));
118  connect(m_playerName, SIGNAL(textEdited(QString)), this, SLOT(settingsChanged()));
119  connect(m_moveLeft, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(settingsChanged()));
120  connect(m_moveUp, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(settingsChanged()));
121  connect(m_moveRight, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(settingsChanged()));
122  connect(m_moveDown, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(settingsChanged()));
123  connect(m_dropBomb, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(settingsChanged()));
124 }
125 
126 PlayerSelectorItem::~PlayerSelectorItem()
127 {
128  delete m_selectCheckBox;
129 
130  delete m_playerName;
131  delete m_playerPreviewPixmap;
132  delete m_playerPreviewPixmapAlphaChannel;;
133  delete m_playerPreviewPixmapLabel;
134  delete m_playerAuthor;
135 
136  delete m_moveLeft;
137  delete m_moveUp;
138  delete m_moveRight;
139  delete m_moveDown;
140  delete m_dropBomb;
141 
142  delete m_labelMoveLeft;
143  delete m_labelMoveUp;
144  delete m_labelMoveRight;
145  delete m_labelMoveDown;
146  delete m_labelDropBomb;
147 }
148 
149 void PlayerSelectorItem::setPlayerPreviewPixmap(const QPixmap& pixmap)
150 {
151  delete m_playerPreviewPixmap;
152  m_playerPreviewPixmap = new QPixmap(pixmap);
153 
154  QPixmap tempPixmap(*m_playerPreviewPixmap);
155  tempPixmap.setAlphaChannel(*m_playerPreviewPixmapAlphaChannel);
156  m_playerPreviewPixmapLabel->setPixmap(tempPixmap);
157 }
158 
159 void PlayerSelectorItem::setPlayerAuthor(const QString& name, const QString& mail)
160 {
161  QString mailString;
162  if(!mail.isEmpty())
163  {
164  mailString = "<br />" + mail;
165  }
166  m_playerAuthor->setText("<i>" + i18nc("Author attribution, e.g. \"by Jack\"", "by %1", name) + "</i>" + mailString);
167 }
168 
169 void PlayerSelectorItem::selectionChanged(bool selectionState)
170 {
171  m_playerName->setEnabled(selectionState);
172  m_playerAuthor->setEnabled(selectionState);
173 
174  if(selectionState == true)
175  {
176  m_playerPreviewPixmapAlphaChannel->fill(QColor(255, 255, 255, 255));
177  }
178  else
179  {
180  m_playerPreviewPixmapAlphaChannel->fill(QColor(64, 64, 64, 255));
181  }
182  QPixmap tempPixmap(*m_playerPreviewPixmap);
183  tempPixmap.setAlphaChannel(*m_playerPreviewPixmapAlphaChannel);
184  m_playerPreviewPixmapLabel->setPixmap(tempPixmap);
185 
186  m_moveLeft->setEnabled(selectionState);
187  m_moveUp->setEnabled(selectionState);
188  m_moveRight->setEnabled(selectionState);
189  m_moveDown->setEnabled(selectionState);
190  m_dropBomb->setEnabled(selectionState);
191 
192  m_labelMoveLeft->setEnabled(selectionState);
193  m_labelMoveUp->setEnabled(selectionState);
194  m_labelMoveRight->setEnabled(selectionState);
195  m_labelMoveDown->setEnabled(selectionState);
196  m_labelDropBomb->setEnabled(selectionState);
197 }
198 
199 void PlayerSelectorItem::settingsChanged()
200 {
201  m_playerSettings->setEnabled(m_playerId, m_selectCheckBox->isChecked());
202  m_playerSettings->setPlayerName(m_playerId, m_playerName->text());
203  m_playerSettings->setKeyLeft(m_playerId, m_moveLeft->keySequence());
204  m_playerSettings->setKeyUp(m_playerId, m_moveUp->keySequence());
205  m_playerSettings->setKeyRight(m_playerId, m_moveRight->keySequence());
206  m_playerSettings->setKeyDown(m_playerId, m_moveDown->keySequence());
207  m_playerSettings->setKeyPutBomb(m_playerId, m_dropBomb->keySequence());
208 }
QSpacerItem
PlayerSelectorItem::~PlayerSelectorItem
~PlayerSelectorItem()
Definition: playerselectoritem.cpp:126
QWidget
QPixmap::fill
void fill(const QColor &color)
QBoxLayout::addSpacerItem
void addSpacerItem(QSpacerItem *spacerItem)
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
PlayerSettings::keyUp
const QKeySequence keyUp(const QString &strPlayerID) const
Definition: playersettings.cpp:149
QLabel::setPixmap
void setPixmap(const QPixmap &)
PlayerSelectorItem::setPlayerAuthor
void setPlayerAuthor(const QString &name, const QString &mail)
Definition: playerselectoritem.cpp:159
QHBoxLayout
PlayerSettings::playerName
const QString playerName(const QString &strPlayerID) const
Definition: playersettings.cpp:129
PlayerSettings::setKeyLeft
void setKeyLeft(const QString &strPlayerID, const QKeySequence &key)
Definition: playersettings.cpp:307
PlayerSettings::keyRight
const QKeySequence keyRight(const QString &strPlayerID) const
Definition: playersettings.cpp:154
PlayerSelectorItem::setPlayerPreviewPixmap
void setPlayerPreviewPixmap(const QPixmap &pixmap)
Definition: playerselectoritem.cpp:149
QGridLayout
PlayerSettings::enabled
bool enabled(const QString &strPlayerID) const
Definition: playersettings.cpp:144
PlayerSettings::keyDown
const QKeySequence keyDown(const QString &strPlayerID) const
Definition: playersettings.cpp:159
PlayerSettings::setKeyDown
void setKeyDown(const QString &strPlayerID, const QKeySequence &key)
Definition: playersettings.cpp:298
PlayerSettings::keyPutBomb
const QKeySequence keyPutBomb(const QString &strPlayerID) const
Definition: playersettings.cpp:169
QWidget::setEnabled
void setEnabled(bool)
QCheckBox
QString::isEmpty
bool isEmpty() const
PlayerSelectorItem::PlayerSelectorItem
PlayerSelectorItem(const QString &playerId, PlayerSettings *playerSettings, QWidget *parent=0)
Definition: playerselectoritem.cpp:33
QVBoxLayout
PlayerSettings
Definition: playersettings.h:27
PlayerSettings::setKeyPutBomb
void setKeyPutBomb(const QString &strPlayerID, const QKeySequence &key)
Definition: playersettings.cpp:316
QLabel::setText
void setText(const QString &)
QString
QColor
QLayout::setMargin
void setMargin(int margin)
QPixmap
playersettings.h
QSize
PlayerSettings::setKeyUp
void setKeyUp(const QString &strPlayerID, const QKeySequence &key)
Definition: playersettings.cpp:280
QAbstractButton::setChecked
void setChecked(bool)
PlayerSettings::setKeyRight
void setKeyRight(const QString &strPlayerID, const QKeySequence &key)
Definition: playersettings.cpp:289
QKeySequence
QPixmap::setAlphaChannel
void setAlphaChannel(const QPixmap &alphaChannel)
PlayerSettings::keyLeft
const QKeySequence keyLeft(const QString &strPlayerID) const
Definition: playersettings.cpp:164
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
PlayerSettings::setEnabled
void setEnabled(const QString &strPlayerID, const bool enabled)
Definition: playersettings.cpp:271
playerselectoritem.h
PlayerSettings::setPlayerName
void setPlayerName(const QString &strPlayerID, const QString &strName)
Definition: playersettings.cpp:262
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

granatier

Skip menu "granatier"
  • Main Page
  • Namespace List
  • Namespace Members
  • 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