[kde-doc-english] KDE/kdegames/kmahjongg
Christian Krippendorf
coding at christian-krippendorf.de
Thu Jan 5 13:25:48 UTC 2012
SVN commit 1271802 by krippendorf:
Random Layout
A new option in kmahjongg layout config dialog for using random layouts.
FEATURE: 241663
REVIEW: 6840
GUI:
M +23 -1 boardwidget.cpp
M +3 -0 boardwidget.h
M +68 -67 gametype.ui
M +4 -0 kmahjongg.kcfg
M +3 -0 kmahjongglayoutselector.cpp
M +1 -0 kmahjongglayoutselector.h
--- trunk/KDE/kdegames/kmahjongg/boardwidget.cpp #1271801:1271802
@@ -100,11 +100,18 @@
}
setShowMatch( Prefs::showMatchingTiles() );
+ // If the random layout is activated, we won't load a boardlayout, as it will be created
+ // randomly in calculateNewGame().
+ if (!Prefs::randomLayout()) {
if (QString::compare(Prefs::layout(), theBoardLayout.path(), Qt::CaseSensitive)!=0) {
//TODO: WARN USER HERE ABOUT DESTRUCTIVE OPERATION!!!
loadBoardLayout(Prefs::layout());
calculateNewGame();
}
+ } else {
+ calculateNewGame();
+ }
+
setDisplayedWidth();
drawBoard(true);
//Store our updated settings, some values might have been changed to defaults
@@ -644,15 +651,30 @@
}
// ---------------------------------------------------------
+
+QString BoardWidget::getRandomLayoutName() const {
+ QStringList tilesAvailable = KGlobal::dirs()->findAllResources("kmahjongglayout",
+ QString("*.desktop"), KStandardDirs::Recursive);
+
+ return tilesAvailable.at(qrand() % tilesAvailable.size());
+}
+
+// ---------------------------------------------------------
void BoardWidget::calculateNewGame( int gNumber)
{
cancelUserSelectedTiles();
stopMatchAnimation();
stopEndAnimation();
Game->initialiseRemovedTiles();
+
+ // If random layout is true, we will create a new random layout from the existing layouts.
+ if (Prefs::randomLayout()) {
+ QString layoutName = getRandomLayoutName();
+ loadBoardLayout(layoutName);
+ }
+
setStatusText( i18n("Calculating new game...") );
-
if( !loadBoard())
{
setStatusText( i18n("Error converting board information!") );
--- trunk/KDE/kdegames/kmahjongg/boardwidget.h #1271801:1271802
@@ -333,6 +333,9 @@
unsigned short cheatsUsed; /**< storage for highscore calculation */
long gameGenerationNum; /**< seed for the random number generator used for this game */
+private:
+ QString getRandomLayoutName() const;
+
public:
GameData * Game; /**< Member Description */
KMahjonggTileset theTiles; /**< Member Description @see KMahjonggTileset */
--- trunk/KDE/kdegames/kmahjongg/gametype.ui #1271801:1271802
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0" >
<class>KMahjonggLayoutSelector</class>
<widget class="QWidget" name="KMahjonggLayoutSelector" >
@@ -5,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>491</width>
- <height>412</height>
+ <width>480</width>
+ <height>461</height>
</rect>
</property>
<property name="maximumSize" >
@@ -15,24 +16,26 @@
<height>600</height>
</size>
</property>
- <layout class="QGridLayout" >
- <property name="leftMargin" >
- <number>0</number>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="kcfg_RandomLayout">
+ <property name="text">
+ <string>Random Layout</string>
</property>
- <property name="topMargin" >
- <number>0</number>
- </property>
- <property name="rightMargin" >
- <number>0</number>
- </property>
- <property name="bottomMargin" >
- <number>0</number>
- </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="widgetNoRandom" native="true">
+ <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" >
- <layout class="QHBoxLayout" >
+ <layout class="QVBoxLayout" name="layoutNoRandom">
<item>
- <layout class="QVBoxLayout" >
+ <layout class="QHBoxLayout" name="_2">
<item>
+ <layout class="QVBoxLayout" name="_3">
+ <item>
<widget class="QListWidget" name="layoutList" >
<property name="minimumSize" >
<size>
@@ -56,26 +59,17 @@
<property name="title" >
<string>Preview</string>
</property>
- <layout class="QVBoxLayout" >
+ <layout class="QVBoxLayout" name="_4">
<property name="spacing" >
<number>6</number>
</property>
- <property name="leftMargin" >
+ <property name="margin">
<number>9</number>
</property>
- <property name="topMargin" >
- <number>9</number>
- </property>
- <property name="rightMargin" >
- <number>9</number>
- </property>
- <property name="bottomMargin" >
- <number>9</number>
- </property>
<item>
<widget class="QLabel" name="layoutPreview" >
<property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -93,44 +87,26 @@
</item>
</layout>
</item>
- <item row="1" column="0" >
+ <item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Layout Details</string>
</property>
- <layout class="QHBoxLayout" >
+ <layout class="QHBoxLayout" name="_5">
<property name="spacing" >
<number>6</number>
</property>
- <property name="leftMargin" >
+ <property name="margin">
<number>9</number>
</property>
- <property name="topMargin" >
- <number>9</number>
- </property>
- <property name="rightMargin" >
- <number>9</number>
- </property>
- <property name="bottomMargin" >
- <number>9</number>
- </property>
<item>
- <layout class="QVBoxLayout" >
+ <layout class="QVBoxLayout" name="_6">
<property name="spacing" >
<number>6</number>
</property>
- <property name="leftMargin" >
+ <property name="margin">
<number>0</number>
</property>
- <property name="topMargin" >
- <number>0</number>
- </property>
- <property name="rightMargin" >
- <number>0</number>
- </property>
- <property name="bottomMargin" >
- <number>0</number>
- </property>
<item>
<widget class="QLabel" name="labelAuthor" >
<property name="text" >
@@ -164,22 +140,13 @@
</layout>
</item>
<item>
- <layout class="QVBoxLayout" >
+ <layout class="QVBoxLayout" name="_7">
<property name="spacing" >
<number>6</number>
</property>
- <property name="leftMargin" >
+ <property name="margin">
<number>0</number>
</property>
- <property name="topMargin" >
- <number>0</number>
- </property>
- <property name="rightMargin" >
- <number>0</number>
- </property>
- <property name="bottomMargin" >
- <number>0</number>
- </property>
<item>
<widget class="QLabel" name="layoutAuthor" >
<property name="text" >
@@ -208,7 +175,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeHint" >
+ <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@@ -219,7 +186,7 @@
</layout>
</widget>
</item>
- <item row="2" column="0" >
+ <item>
<widget class="KLineEdit" name="kcfg_Layout" >
<property name="enabled" >
<bool>false</bool>
@@ -232,12 +199,12 @@
</property>
</widget>
</item>
- <item row="3" column="0" >
+ <item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
- <property name="sizeHint" >
+ <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
@@ -246,7 +213,41 @@
</spacer>
</item>
</layout>
+ </item>
+ </layout>
</widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>KLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>klineedit.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
- <connections/>
+ <connections>
+ <connection>
+ <sender>kcfg_RandomLayout</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>KMahjonggLayoutSelector</receiver>
+ <slot>useRandomLayoutToggled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>226</x>
+ <y>15</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>226</x>
+ <y>209</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+ <slots>
+ <slot>useRandomLayoutToggled(bool)</slot>
+ </slots>
</ui>
--- trunk/KDE/kdegames/kmahjongg/kmahjongg.kcfg #1271801:1271802
@@ -17,6 +17,10 @@
<entry name="Angle" type="Int">
<default>0</default>
</entry>
+ <entry name="RandomLayout" type="Bool">
+ <label>Whether a random layout is choosed on startup.</label>
+ <default>false</default>
+ </entry>
<entry name="SolvableGames" type="Bool" key="Solvable_game">
<label>Whether all games should be solvable.</label>
<default>true</default>
--- trunk/KDE/kdegames/kmahjongg/kmahjongglayoutselector.cpp #1271801:1271802
@@ -122,7 +122,10 @@
p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->unselectedTile(1));
p.drawPixmap(margin.width()/2, margin.height()/2, selTileset->tileface(0));
tilesetPreview->setPixmap(QPixmap::fromImage(qiRend));*/
+}
+void KMahjonggLayoutSelector::useRandomLayoutToggled(bool active) {
+ widgetNoRandom->setEnabled(!active);
}
#include "kmahjongglayoutselector.moc"
--- trunk/KDE/kdegames/kmahjongg/kmahjongglayoutselector.h #1271801:1271802
@@ -41,6 +41,7 @@
QMap<QString, KMahjonggLayout *> layoutMap;
public slots:
void layoutChanged();
+ void useRandomLayoutToggled(bool);
private:
BoardWidget * bw;
};
More information about the kde-doc-english
mailing list