[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [lskat/frameworks] src: Merge branch 'master' into frameworks
From: Martin Walch <walch.martin () web ! de>
Date: 2016-05-01 0:14:38
Message-ID: E1awf1y-0007yr-7Y () scm ! kde ! org
[Download RAW message or body]
Git commit bf9d6cecbadb5ba99721cf24e6653b10eb474209 by Martin Walch.
Committed on 30/04/2016 at 19:09.
Pushed by martinwalch into branch 'frameworks'.
Merge branch 'master' into frameworks
M +1 -2 src/CMakeLists.txt
M +40 -46 src/abstractdisplay.cpp
M +60 -53 src/abstractdisplay.h
M +8 -14 src/abstractengine.cpp
M +48 -38 src/abstractengine.h
M +7 -14 src/abstractinput.cpp
M +34 -33 src/abstractinput.h
M +605 -644 src/aiinput.cpp
M +99 -87 src/aiinput.h
M +237 -259 src/cardsprite.cpp
M +60 -73 src/config_two.cpp
M +47 -37 src/config_two.h
M +92 -104 src/deck.cpp
M +74 -59 src/deck.h
M +172 -180 src/display_intro.cpp
M +47 -39 src/display_intro.h
M +286 -309 src/display_two.cpp
M +89 -73 src/display_two.h
M +348 -370 src/engine_two.cpp
M +72 -64 src/engine_two.h
M +208 -211 src/fromlibkdegames/cardcache.cpp
M +51 -46 src/fromlibkdegames/cardcache.h
M +38 -44 src/fromlibkdegames/carddeckinfo.cpp
M +28 -39 src/fromlibkdegames/carddeckinfo_p.h
M +103 -110 src/fromlibkdegames/kcarddialog.cpp
M +53 -54 src/fromlibkdegames/kcarddialog.h
M +161 -174 src/gameview.cpp
M +49 -43 src/gameview.h
A +0 -2 src/lskat_debug.cpp [License: LGPL (v2+)]
A +1 -2 src/lskat_debug.h [License: LGPL (v2+)]
M +85 -88 src/main.cpp
M +443 -471 src/mainwindow.cpp
M +103 -86 src/mainwindow.h
M +14 -19 src/mouseinput.cpp
M +28 -23 src/mouseinput.h
M +18 -23 src/namedialogwidget.cpp
M +19 -15 src/namedialogwidget.h
M +147 -159 src/pixmapsprite.cpp
M +96 -100 src/pixmapsprite.h
M +127 -159 src/player.cpp
M +141 -108 src/player.h
M +112 -130 src/scoresprite.cpp
M +66 -58 src/scoresprite.h
M +65 -70 src/textsprite.cpp
M +152 -180 src/thememanager.cpp
http://commits.kde.org/lskat/bf9d6cecbadb5ba99721cf24e6653b10eb474209
diff --cc src/CMakeLists.txt
index fa57894,c9db784..4841cc1
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@@ -1,6 -1,7 +1,6 @@@
-include_directories( ${CMAKE_SOURCE_DIR}/libkdegames/kgame )
-
-set( lskat_SRCS
+set(lskat_SRCS
- lskat_debug.cpp
++ lskat_debug.cpp
thememanager.cpp
namedialogwidget.cpp
gameview.cpp
@@@ -49,5 -42,4 +49,4 @@@ install(TARGETS lskat ${KDE_INSTALL_TA
########### install files ###############
-install( FILES lskatui.rc DESTINATION ${DATA_INSTALL_DIR}/lskat )
+install(FILES lskatui.rc DESTINATION ${KDE_INSTALL_DATADIR}/lskat)
-
diff --cc src/abstractdisplay.cpp
index b41f07e,d8c54db..c1d5e13
--- a/src/abstractdisplay.cpp
+++ b/src/abstractdisplay.cpp
@@@ -80,23 -78,22 +77,20 @@@ void AbstractDisplay::reset(
// Create all sprites and store them for later access
void AbstractDisplay::createCardSprites()
{
- // Only create sprites once (unless explicitly reset)
- if (mCards.size() > 0) return;
-
- // Loop all cards
- for (int cardNo=0; cardNo<mDeck->cardNumber(); cardNo++)
- {
- // Create sprite with card correct card image
- Suite suite = Suite(cardNo%4);
- CardType cardtype = CardType(cardNo/4);
- CardSprite* sprite = new CardSprite(suite, cardtype, mTheme, mAdvancePeriod, \
mScene);
- // Display sprite
- sprite->hide();
-
- // Store sprite
- mCards[cardNo] = sprite;
- }// next
+ // Only create sprites once (unless explicitly reset)
+ if (mCards.size() > 0) return;
+
+ // Loop all cards
+ for (int cardNo = 0; cardNo < mDeck->cardNumber(); cardNo++)
+ {
+ // Create sprite with card correct card image
+ Suite suite = Suite(cardNo % 4);
+ CardType cardtype = CardType(cardNo / 4);
+ CardSprite *sprite = new CardSprite(suite, cardtype, mTheme, \
mAdvancePeriod, mScene); + // Display sprite
+ sprite->hide();
+
+ // Store sprite
+ mCards[cardNo] = sprite;
+ }// next
}
--
-
-#include "abstractdisplay.moc"
diff --cc src/abstractengine.cpp
index f41117b,0f9ffd4..6b49eba
--- a/src/abstractengine.cpp
+++ b/src/abstractengine.cpp
@@@ -23,30 -23,26 +23,24 @@@
// Qt includes
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
-
// Constructor for the game document/engine
- AbstractEngine::AbstractEngine(QWidget* parent)
+ AbstractEngine::AbstractEngine(QWidget *parent)
: QObject(parent)
{
- mGameStatus = Stopped;
- mPlayers.clear();
+ mGameStatus = Stopped;
+ mPlayers.clear();
}
-
- // Add a player to the game
- void AbstractEngine::addPlayer(int no, Player* player)
+ // Add a player to the game
+ void AbstractEngine::addPlayer(int no, Player *player)
{
- mPlayers[no] = player;
+ mPlayers[no] = player;
}
-
// Retrieve the player of the given number.
- Player* AbstractEngine::player(int no)
+ Player *AbstractEngine::player(int no)
{
- return mPlayers[no];
+ return mPlayers[no];
}
--
-
-
-#include "abstractengine.moc"
diff --cc src/abstractinput.cpp
index c38f3aa,76a4f1c..d78550e
--- a/src/abstractinput.cpp
+++ b/src/abstractinput.cpp
@@@ -23,18 -23,16 +23,16 @@@
// Qt includes
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
-
// Constructor for the engine
- AbstractInput::AbstractInput(QObject* parent)
+ AbstractInput::AbstractInput(QObject *parent)
: QObject(parent)
{
- mInputAllowed = false;
- mId = -1;
+ mInputAllowed = false;
+ mId = -1;
}
-
// Set player id number
void AbstractInput::setId(int id)
{
@@@ -51,9 -48,7 +48,5 @@@ void AbstractInput::setInputAllowed(boo
// Retrieve whether input is allowed or not.
bool AbstractInput::inputAllowed()
{
- return mInputAllowed;
+ return mInputAllowed;
}
--
-
-
-#include "abstractinput.moc"
diff --cc src/aiinput.cpp
index a885e00,31e20fe..fafbd63
--- a/src/aiinput.cpp
+++ b/src/aiinput.cpp
@@@ -50,46 -49,43 +48,43 @@@ void AiInput::setInputAllowed(bool allo
// Calculate and send out AI turn
void AiInput::aiTurn()
{
- // Turn was stopped meanwhile
- if (!mInputAllowed) return;
-
- if (global_debug > 5) qCDebug(LSKAT_LOG) << \
"===================================================";
- if (global_debug > 5) qCDebug(LSKAT_LOG) << "AI TURN START " <<mInputAllowed;
-
- // Check we are the right player
- if (mId != mEngine->currentPlayer())
- {
- qCCritical(LSKAT_LOG) << "AI plays for wrong player";
- return;
- }
-
- // Retrieve game board
- AiInput::Board board = getBoardFromEngine();
- AiInput::Move move;
-
- if (global_debug > 0) qCDebug(LSKAT_LOG) << QLatin1String( "" );
-
- // Initiate move
- if (mEngine->currentMovePhase() == EngineTwo::FirstPlayerTurn)
- {
- if (global_debug > 5) qCDebug(LSKAT_LOG) << "Performing initiual move "<<mId;
- move = initiateMove(mId, board);
- }
- // Respond to move
- else
- {
- if (global_debug > 5) qCDebug(LSKAT_LOG) << "Performing answer move "<<mId;
- move = answerMove(mId, board);
- }
-
-
- // Send out move
- if (global_debug > 5) qCDebug(LSKAT_LOG) << "AI player" << mId << "moves to" << \
move.move;
- if (move.move>=0) emit signalPlayerInput(mId, mId, move.move);
- else qCCritical(LSKAT_LOG) << "Illegal AI Move ??? ";
- }
+ // Turn was stopped meanwhile
+ if (!mInputAllowed) return;
+
- if (global_debug > 5) kDebug() << \
"===================================================";
- if (global_debug > 5) kDebug() << "AI TURN START " << mInputAllowed;
++ if (global_debug > 5) qCDebug(LSKAT_LOG) << \
"==================================================="; ++ if (global_debug > 5) \
qCDebug(LSKAT_LOG) << "AI TURN START " << mInputAllowed; +
+ // Check we are the right player
+ if (mId != mEngine->currentPlayer())
+ {
- kFatal() << "AI plays for wrong player";
++ qCCritical(LSKAT_LOG) << "AI plays for wrong player";
+ return;
+ }
+
+ // Retrieve game board
+ AiInput::Board board = getBoardFromEngine();
+ AiInput::Move move;
- if (global_debug > 0) kDebug() << QLatin1String("");
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << QLatin1String("");
+
+ // Initiate move
+ if (mEngine->currentMovePhase() == EngineTwo::FirstPlayerTurn)
+ {
- if (global_debug > 5) kDebug() << "Performing initiual move " << mId;
++ if (global_debug > 5) qCDebug(LSKAT_LOG) << "Performing initial move " << \
mId; + move = initiateMove(mId, board);
+ }
+ // Respond to move
+ else
+ {
- if (global_debug > 5) kDebug() << "Performing answer move " << mId;
++ if (global_debug > 5) qCDebug(LSKAT_LOG) << "Performing answer move " << \
mId; + move = answerMove(mId, board);
+ }
+
+ // Send out move
- if (global_debug > 5) kDebug() << "AI player" << mId << "moves to" << \
move.move; ++ if (global_debug > 5) qCDebug(LSKAT_LOG) << "AI player " << mId << " \
moves to " << move.move; + if (move.move >= 0) emit signalPlayerInput(mId, mId, \
move.move);
- else kError() << "Illegal AI Move ??? ";
++ else qCCritical(LSKAT_LOG) << "Illegal AI Move???";
+ }
// Extract the current game board from the engine
AiInput::Board AiInput::getBoardFromEngine()
@@@ -136,224 -131,218 +130,218 @@@ const double RATING_WO
const double RATING_REMIS = 20000.0;
const double RATING_ONE_POINT = 500.0;
// Tactical ratings
- const double RATING_AMOUNT_TRUMPCARD = 3.0*RATING_ONE_POINT;
- const double RATING_AMOUNT_GRANDCARD = 15.0*RATING_ONE_POINT;
- const double RATING_AMOUNT_OPENCARD = 1.5*RATING_ONE_POINT;
- const double RATING_AMOUNT_ACES = 3.0*RATING_ONE_POINT;
- const double RATING_AMOUNT_TENS = 1.0*RATING_ONE_POINT;
- const double RATING_AMOUNT_JACKS = 8.5*RATING_ONE_POINT;
- const double RATING_GOOD_MISSING_SUITE = 3.5*RATING_ONE_POINT;
-
- const double RATING_JACK_OF_CLUBS = 0.8*RATING_ONE_POINT;
- const double RATING_JACK_OF_SPADE = 0.6*RATING_ONE_POINT;
- const double RATING_JACK_OF_HEART = 0.4*RATING_ONE_POINT;
- const double RATING_JACK_OF_DIAMOND = 0.2*RATING_ONE_POINT;
+ const double RATING_AMOUNT_TRUMPCARD = 3.0 * RATING_ONE_POINT;
+ const double RATING_AMOUNT_GRANDCARD = 15.0 * RATING_ONE_POINT;
+ const double RATING_AMOUNT_OPENCARD = 1.5 * RATING_ONE_POINT;
+ const double RATING_AMOUNT_ACES = 3.0 * RATING_ONE_POINT;
+ const double RATING_AMOUNT_TENS = 1.0 * RATING_ONE_POINT;
+ const double RATING_AMOUNT_JACKS = 8.5 * RATING_ONE_POINT;
+ const double RATING_GOOD_MISSING_SUITE = 3.5 * RATING_ONE_POINT;
+
+ const double RATING_JACK_OF_CLUBS = 0.8 * RATING_ONE_POINT;
+ const double RATING_JACK_OF_SPADE = 0.6 * RATING_ONE_POINT;
+ const double RATING_JACK_OF_HEART = 0.4 * RATING_ONE_POINT;
+ const double RATING_JACK_OF_DIAMOND = 0.2 * RATING_ONE_POINT;
// Evaluate the current game board and return a rating
- double AiInput::evaluteGame(int p, const AiInput::Board& current)
+ double AiInput::evaluteGame(int p, const AiInput::Board ¤t)
{
- double rating = 0.0;
-
- // ===== Poins evaulation =====
- // Check for won games of our side
- if (current.points[p] == 120) rating += RATING_SCHWARZ;
- else if (current.points[p] >= 90) rating += RATING_SCHNEIDER;
- else if (current.points[p] > 60) rating += RATING_WON;
- else if (current.points[p] == 60) rating += RATING_REMIS;
-
- // Check for won games of other side
- if (current.points[1-p] == 120) rating -= RATING_SCHWARZ;
- else if (current.points[1-p] >= 90) rating -= RATING_SCHNEIDER;
- else if (current.points[1-p] > 60) rating -= RATING_WON;
- else if (current.points[1-p] == 60) rating -= RATING_REMIS;
-
- // Evaluate points
- rating += (current.points[p]-current.points[1-p])*RATING_ONE_POINT;
-
- // ===== Tactical evaulation =====
- // Number of trumps (Stored under index Grand)
- int trump1 = current.amountOfSuite[p][int(Grand)];
- int trump2 = current.amountOfSuite[1-p][int(Grand)];
- rating += (trump1-trump2)* RATING_AMOUNT_TRUMPCARD;
- // Increase value of trumps for Grand
- if (current.trump == Grand) rating += (trump1-trump2)* RATING_AMOUNT_TRUMPCARD;
-
- // Missing suites
- //if (current.amountOfSuite[p][int(Club)] == 0 && (trump1 > trump2)) rating += \
RATING_GOOD_MISSING_SUITE;
- //if (current.amountOfSuite[p][int(Spade)] == 0 && (trump1 > trump2)) rating += \
RATING_GOOD_MISSING_SUITE;
- //if (current.amountOfSuite[p][int(Heart)] == 0 && (trump1 > trump2)) rating += \
RATING_GOOD_MISSING_SUITE;
- //if (current.amountOfSuite[p][int(Diamond)] == 0 && (trump1 > trump2)) rating += \
RATING_GOOD_MISSING_SUITE;
-
- //if (current.amountOfSuite[1-p][int(Club)] == 0 && (trump1 < trump2)) rating -= \
RATING_GOOD_MISSING_SUITE;
- //if (current.amountOfSuite[1-p][int(Spade)] == 0 && (trump1 < trump2)) rating -= \
RATING_GOOD_MISSING_SUITE;
- //if (current.amountOfSuite[1-p][int(Heart)] == 0 && (trump1 < trump2)) rating -= \
RATING_GOOD_MISSING_SUITE;
- //if (current.amountOfSuite[1-p][int(Diamond)] == 0 && (trump1 < trump2)) rating \
-= RATING_GOOD_MISSING_SUITE;
-
-
- // Number of open cards
- int amount1 = amountOfOpenCards(p, current);
- int amount2 = amountOfOpenCards(1-p, current);
- rating += (amount1-amount2)* RATING_AMOUNT_OPENCARD;
-
- // Card types
- // Aces
- int amountAce1 = current.amountOfCardType[p][int(Ace)];
- int amountAce2 = current.amountOfCardType[1-p][int(Ace)];
- rating += (amountAce1-amountAce2)* RATING_AMOUNT_ACES;
-
- // Tens
- int amountTen1 = current.amountOfCardType[p][int(Ten)];
- int amountTen2 = current.amountOfCardType[1-p][int(Ten)];
- rating += (amountTen1-amountTen2)* RATING_AMOUNT_TENS;
-
- // Jacks
- int amountJack1 = current.amountOfCardType[p][int(Jack)];
- int amountJack2 = current.amountOfCardType[1-p][int(Jack)];
- rating += (amountJack1-amountJack2)* RATING_AMOUNT_JACKS;
- //qCDebug(LSKAT_LOG) << " Add rating(p="<<p<<") for jacks j1="<< \
amountJack1<<" j2="<<amountJack2<< " has JC=" << findCard(current, \
Club, Jack);
-
- if (findCard(current, Club, Jack) == p) rating += RATING_JACK_OF_CLUBS;
- if (findCard(current, Spade, Jack) == p) rating += RATING_JACK_OF_SPADE;
- if (findCard(current, Heart, Jack) == p) rating += RATING_JACK_OF_HEART;
- if (findCard(current, Diamond, Jack) == p) rating += RATING_JACK_OF_DIAMOND;
-
- if (findCard(current, Club, Jack) == 1-p) rating -= RATING_JACK_OF_CLUBS;
- if (findCard(current, Spade, Jack) == 1-p) rating -= RATING_JACK_OF_SPADE;
- if (findCard(current, Heart, Jack) == 1-p) rating -= RATING_JACK_OF_HEART;
- if (findCard(current, Diamond, Jack) == 1-p) rating -= RATING_JACK_OF_DIAMOND;
- //qCDebug(LSKAT_LOG) << " Rating after jacks" << rating;
-
- return rating;
- }
-
+ double rating = 0.0;
+
+ // ===== Points evaluation =====
+ // Check for won games of our side
+ if (current.points[p] == 120) rating += RATING_SCHWARZ;
+ else if (current.points[p] >= 90) rating += RATING_SCHNEIDER;
+ else if (current.points[p] > 60) rating += RATING_WON;
+ else if (current.points[p] == 60) rating += RATING_REMIS;
+
+ // Check for won games of other side
+ if (current.points[1 - p] == 120) rating -= RATING_SCHWARZ;
+ else if (current.points[1 - p] >= 90) rating -= RATING_SCHNEIDER;
+ else if (current.points[1 - p] > 60) rating -= RATING_WON;
+ else if (current.points[1 - p] == 60) rating -= RATING_REMIS;
+
+ // Evaluate points
+ rating += (current.points[p] - current.points[1 - p]) * RATING_ONE_POINT;
+
+ // ===== Tactical evaluation =====
+ // Number of trumps (Stored under index Grand)
+ int trump1 = current.amountOfSuite[p][int(Grand)];
+ int trump2 = current.amountOfSuite[1 - p][int(Grand)];
+ rating += (trump1 - trump2) * RATING_AMOUNT_TRUMPCARD;
+ // Increase value of trumps for Grand
+ if (current.trump == Grand) rating += (trump1 - trump2) * \
RATING_AMOUNT_TRUMPCARD; +
+ // Missing suites
+ //if (current.amountOfSuite[p][int(Club)] == 0 && (trump1 > trump2)) rating += \
RATING_GOOD_MISSING_SUITE; + //if (current.amountOfSuite[p][int(Spade)] == 0 && \
(trump1 > trump2)) rating += RATING_GOOD_MISSING_SUITE; + //if \
(current.amountOfSuite[p][int(Heart)] == 0 && (trump1 > trump2)) rating += \
RATING_GOOD_MISSING_SUITE; + //if (current.amountOfSuite[p][int(Diamond)] == 0 && \
(trump1 > trump2)) rating += RATING_GOOD_MISSING_SUITE; +
+ //if (current.amountOfSuite[1 - p][int(Club)] == 0 && (trump1 < trump2)) rating \
-= RATING_GOOD_MISSING_SUITE; + //if (current.amountOfSuite[1 - p][int(Spade)] == \
0 && (trump1 < trump2)) rating -= RATING_GOOD_MISSING_SUITE; + //if \
(current.amountOfSuite[1 - p][int(Heart)] == 0 && (trump1 < trump2)) rating -= \
RATING_GOOD_MISSING_SUITE; + //if (current.amountOfSuite[1 - p][int(Diamond)] == \
0 && (trump1 < trump2)) rating -= RATING_GOOD_MISSING_SUITE; +
+ // Number of open cards
+ int amount1 = amountOfOpenCards(p, current);
+ int amount2 = amountOfOpenCards(1 - p, current);
+ rating += (amount1 - amount2) * RATING_AMOUNT_OPENCARD;
+
+ // Card types
+ // Aces
+ int amountAce1 = current.amountOfCardType[p][int(Ace)];
+ int amountAce2 = current.amountOfCardType[1 - p][int(Ace)];
+ rating += (amountAce1 - amountAce2) * RATING_AMOUNT_ACES;
+
+ // Tens
+ int amountTen1 = current.amountOfCardType[p][int(Ten)];
+ int amountTen2 = current.amountOfCardType[1 - p][int(Ten)];
+ rating += (amountTen1 - amountTen2) * RATING_AMOUNT_TENS;
+
+ // Jacks
+ int amountJack1 = current.amountOfCardType[p][int(Jack)];
+ int amountJack2 = current.amountOfCardType[1 - p][int(Jack)];
- rating += (amountJack1 - amountJack2)* RATING_AMOUNT_JACKS;
- //kDebug() << " Add rating(p=" << p << ") for jacks j1=" << amountJack1 << " \
j2=" << amountJack2 << " has JC=" << findCard(current, Club, Jack); ++ rating += \
(amountJack1 - amountJack2) * RATING_AMOUNT_JACKS; ++ //qCDebug(LSKAT_LOG) << " \
Add rating(p=" << p << ") for jacks j1=" << amountJack1 <<" j2=" << amountJack2 << " \
has JC=" << findCard(current, Club, Jack); +
+ if (findCard(current, Club, Jack) == p) rating += RATING_JACK_OF_CLUBS;
+ if (findCard(current, Spade, Jack) == p) rating += RATING_JACK_OF_SPADE;
+ if (findCard(current, Heart, Jack) == p) rating += RATING_JACK_OF_HEART;
+ if (findCard(current, Diamond, Jack) == p) rating += RATING_JACK_OF_DIAMOND;
+
+ if (findCard(current, Club, Jack) == 1 - p) rating -= RATING_JACK_OF_CLUBS;
+ if (findCard(current, Spade, Jack) == 1 - p) rating -= RATING_JACK_OF_SPADE;
+ if (findCard(current, Heart, Jack) == 1 - p) rating -= RATING_JACK_OF_HEART;
+ if (findCard(current, Diamond, Jack) == 1 - p) rating -= \
RATING_JACK_OF_DIAMOND;
- //kDebug() << " Rating after jacks" << rating;
++ //qCDebug(LSKAT_LOG) << " Rating after jacks " << rating;
+
+ return rating;
+ }
// Initiate a new move as first player
- AiInput::Move AiInput::initiateMove(int p, const AiInput::Board& board)
+ AiInput::Move AiInput::initiateMove(int p, const AiInput::Board &board)
{
- AiInput::Move maxMove;
- maxMove.move = -1;
- maxMove.value = -100.0*RATING_SCHWARZ; // Absolut minimum score
-
- // Loop all moves
- for (int m=0; m<8; m++)
- {
- AiInput::Board current(board);
- int card = current.takeCard(p, m);
- if (card < 0) continue; // Illegal move
- // Store move
- current.playedCard = card;
- current.whoseTurn = 1-p;
- if (global_debug > 5) qCDebug(LSKAT_LOG) << "***** First mover try move on" << \
m << " ("<<Deck::name(card) <<")";
- AiInput::Move answer = answerMove(1-p, current);
- // Negate answering moves value to get our rating
- double rating = -answer.value;
- if (global_debug > 5) qCDebug(LSKAT_LOG) << "First mover yields rating of" << \
rating;
-
- rating += rulebaseFirstMover(p, card, board);
- if (global_debug > 5) qCDebug(LSKAT_LOG) << " rulesbase correction to \
"<<rating;
-
- // New best move?
- if (rating > maxMove.value)
- {
- maxMove.value = rating;
- maxMove.move = m;
- }
- }
-
- return maxMove;
- }
+ AiInput::Move maxMove;
+ maxMove.move = -1;
- maxMove.value = -100.0 * RATING_SCHWARZ; // Absolut minimum score
++ maxMove.value = -100.0 * RATING_SCHWARZ; // Absolute minimum score
-
- // Answer a move as second player
- AiInput::Move AiInput::answerMove(int p, const AiInput::Board& board)
- {
- AiInput::Move maxMove;
- maxMove.move = -1;
- maxMove.value = -100.0*RATING_SCHWARZ; // Absolut minimum score
-
- // Loop all moves
- for (int m=0; m<8; m++)
- {
- AiInput::Board current(board);
- // qCDebug(LSKAT_LOG) << "CARD "<<m<< " is "
- // << Deck::name(current.cards[p][m]) << "on top of "
- // << Deck::name(current.cards[p][m+8]);
-
- int card = current.takeCard(p, m);
- if (card < 0) continue; // Illegal card
-
- // Check validity of move
- if (!isLegalMove(current.playedCard, card, p, current)) continue;
-
- // Check move winner
- int winner = EngineTwo::whoWonMove(current.playedCard, card, current.trump);
- if (global_debug > 5)
- qCDebug(LSKAT_LOG) << " Card" << m<< " (" << Deck::name(card) << ") is \
valid "
- << "countering" << Deck::name(current.playedCard)<<" with "
- << "winner (0:other, 1:we) " << winner;
- int deltaPoints = 0;
- deltaPoints += Deck::getCardValue(current.playedCard);
- deltaPoints += Deck::getCardValue(card);
- // The first mover won
- if (winner == 0)
- {
- current.points[1-p] += deltaPoints;
- }
- // The second mover won (us)
- else
+ // Loop all moves
+ for (int m = 0; m < 8; m++)
{
- current.points[p] += deltaPoints;
+ AiInput::Board current(board);
+ int card = current.takeCard(p, m);
+ if (card < 0) continue; // Illegal move
+ // Store move
+ current.playedCard = card;
+ current.whoseTurn = 1 - p;
- if (global_debug > 5) kDebug() << "***** First mover try move on" << m << " \
(" << Deck::name(card) << ")"; ++ if (global_debug > 5) qCDebug(LSKAT_LOG) << \
"***** First mover try move on " << m << " (" << Deck::name(card) << ")"; + \
AiInput::Move answer = answerMove(1 - p, current); + // Negate answering \
moves value to get our rating + double rating = -answer.value;
- if (global_debug > 5) kDebug() << "First mover yields rating of" << rating;
++ if (global_debug > 5) qCDebug(LSKAT_LOG) << "First mover yields rating of " \
<< rating; +
+ rating += rulebaseFirstMover(p, card, board);
- if (global_debug > 5) kDebug() << " rulesbase correction to " << rating;
++ if (global_debug > 5) qCDebug(LSKAT_LOG) << " rulesbase correction to " << \
rating; +
+ // New best move?
+ if (rating > maxMove.value)
+ {
- maxMove.value = rating;
- maxMove.move = m;
++ maxMove.value = rating;
++ maxMove.move = m;
+ }
}
- double rating = evaluteGame(p, current);
- rating += rulebaseAnswerMover(p, card, board);
+ return maxMove;
+ }
+ // Answer a move as second player
+ AiInput::Move AiInput::answerMove(int p, const AiInput::Board &board)
+ {
+ AiInput::Move maxMove;
+ maxMove.move = -1;
- maxMove.value = -100.0 * RATING_SCHWARZ; // Absolut minimum score
++ maxMove.value = -100.0 * RATING_SCHWARZ; // Absolute minimum score
- if (global_debug > 5)
- qCDebug(LSKAT_LOG) << " Points after 2nd move "<<m<<" would be we: "
- << current.points[p] << "other:" << current.points[1-p]
- << "rating is thus" << rating;
- // New best move?
- if (rating > maxMove.value)
+ // Loop all moves
+ for (int m = 0; m < 8; m++)
{
- maxMove.value = rating;
- maxMove.move = m;
+ AiInput::Board current(board);
- // kDebug() << "CARD " << m << " is "
++ // qCDebug(LSKAT_LOG) << "CARD " << m << " is "
+ // << Deck::name(current.cards[p][m]) << " on top of "
+ // << Deck::name(current.cards[p][m + 8]);
+
+ int card = current.takeCard(p, m);
+ if (card < 0) continue; // Illegal card
+
+ // Check validity of move
+ if (!isLegalMove(current.playedCard, card, p, current)) continue;
+
+ // Check move winner
+ int winner = EngineTwo::whoWonMove(current.playedCard, card, \
current.trump); + if (global_debug > 5)
- kDebug() << " Card" << m << " (" << Deck::name(card) << ") is valid "
++ qCDebug(LSKAT_LOG) << " Card" << m << " (" << Deck::name(card) << ") is \
valid " + << "countering" << Deck::name(current.playedCard) << " \
with " + << "winner (0:other, 1:we) " << winner;
+ int deltaPoints = 0;
+ deltaPoints += Deck::getCardValue(current.playedCard);
+ deltaPoints += Deck::getCardValue(card);
+ // The first mover won
+ if (winner == 0)
+ {
+ current.points[1 - p] += deltaPoints;
+ }
+ // The second mover won (us)
+ else
+ {
+ current.points[p] += deltaPoints;
+ }
+
+ double rating = evaluteGame(p, current);
+ rating += rulebaseAnswerMover(p, card, board);
+
+ if (global_debug > 5)
- kDebug() << " Points after 2nd move " << m << " would be we: "
- << current.points[p] << "other:" << current.points[1 - p]
- << "rating is thus" << rating;
++ qCDebug(LSKAT_LOG) << " Points after 2nd move " << m << " would be we: "
++ << current.points[p] << " other: " << current.points[1 - p]
++ << " rating is thus " << rating;
+ // New best move?
+ if (rating > maxMove.value)
+ {
+ maxMove.value = rating;
+ maxMove.move = m;
+ }
}
- }
- return maxMove;
+ return maxMove;
}
-
// Board copy constructor
- AiInput::Board::Board(const AiInput::Board& board)
+ AiInput::Board::Board(const AiInput::Board &board)
{
- for (int i=0;i<2;i++)
- {
- points[i] = board.points[i];
- for (int j=0;j<16;j++)
+ for (int i = 0; i < 2; i++)
{
- cards[i][j] = board.cards[i][j];
+ points[i] = board.points[i];
+ for (int j = 0; j < 16; j++)
+ {
+ cards[i][j] = board.cards[i][j];
+ }
+ for (int j = 0; j < 5; j++)
+ {
+ amountOfSuite[i][j] = board.amountOfSuite[i][j];
+ }
+ for (int j = 0; j < 8; j++)
+ {
+ amountOfCardType[i][j] = board.amountOfCardType[i][j];
+ }
}
- for (int j=0; j<5; j++)
+ for (int i = 0; i < 32; i++)
{
- amountOfSuite[i][j] = board.amountOfSuite[i][j];
+ playedCards[i] = board.playedCards[i];
}
- for (int j=0; j<8; j++)
- {
- amountOfCardType[i][j] = board.amountOfCardType[i][j];
- }
- }
- for (int i=0; i<32; i++)
- {
- playedCards[i] = board.playedCards[i];
- }
- playedCard = board.playedCard;
- whoseTurn = board.whoseTurn;
- firstPlay = board.firstPlay;
- trump = board.trump;
+ playedCard = board.playedCard;
+ whoseTurn = board.whoseTurn;
+ firstPlay = board.firstPlay;
+ trump = board.trump;
}
-
// Retrieve card at given position for given player
int AiInput::Board::card(int p, int pos) const
{
@@@ -427,379 -412,359 +411,356 @@@ const int CARD_PLAYED = 3
// Check where a card is:
// -1: unknown (still covered), 0: player 0, 1: player 1: 2: currently played, 2: \
already played
- int AiInput::findCard(const AiInput::Board& current, Suite sSuite, CardType \
sCardType) const + int AiInput::findCard(const AiInput::Board ¤t, Suite sSuite, \
CardType sCardType) const {
- // Loop player's cards
- for (int p=0; p<2; p++)
- {
- for (int i=0;i<8;i++)
- {
- int card = current.card(p, i);
- if (card < 0) continue;
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- if (suite == sSuite && type == sCardType)
- {
- //qCDebug(LSKAT_LOG) << "Found" << Deck::name(sSuite, sCardType) << "at" << \
p << "," << i;
- return p;
- }
- }
- }
-
- // Currently played card if any
- int card = current.playedCard;
- if (card >=0)
- {
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- if (suite == sSuite && type==sCardType)
- {
- //qCDebug(LSKAT_LOG) << "Found" << Deck::name(sSuite, sCardType) << "as \
currently played card";
- return CARD_CURRENTLY_PLAYED;
- }
- }
-
- // Already played cards
- for (int i=0; i<32 ;i++)
- {
- int card = current.playedCards[i];
- if (card < 0) continue;
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- if (suite == sSuite && type==sCardType)
+ // Loop player's cards
+ for (int p = 0; p < 2; p++)
{
- //qCDebug(LSKAT_LOG) << "Found" << Deck::name(sSuite, sCardType) << "as \
played card "<<i;
- return CARD_PLAYED;
+ for (int i = 0; i < 8; i++)
+ {
+ int card = current.card(p, i);
+ if (card < 0) continue;
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
+ if (suite == sSuite && type == sCardType)
+ {
- //kDebug() << "Found" << Deck::name(sSuite, sCardType) << "at" << p \
<< "," << i; ++ //qCDebug(LSKAT_LOG) << "Found" << Deck::name(sSuite, \
sCardType) << " at " << p << "," << i; + return p;
+ }
+ }
}
- }
+ // Currently played card if any
+ int card = current.playedCard;
+ if (card >= 0)
+ {
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
+ if (suite == sSuite && type == sCardType)
+ {
- //kDebug() << "Found " << Deck::name(sSuite, sCardType) << " as \
currently played card"; ++ //qCDebug(LSKAT_LOG) << "Found" << \
Deck::name(sSuite, sCardType) << " as currently played card"; + return \
CARD_CURRENTLY_PLAYED; + }
+ }
- return -1;
-
- }
+ // Already played cards
+ for (int i = 0; i < 32; i++)
+ {
+ int card = current.playedCards[i];
+ if (card < 0) continue;
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
+ if (suite == sSuite && type == sCardType)
+ {
- //kDebug() << "Found " << Deck::name(sSuite, sCardType) << " as played \
card " << i; ++ //qCDebug(LSKAT_LOG) << "Found " << Deck::name(sSuite, \
sCardType) << " as played card " << i; + return CARD_PLAYED;
+ }
+ }
+ return -1;
+ }
// How many open cards has the given player
- int AiInput::amountOfOpenCards(int p, const AiInput::Board& current) const
+ int AiInput::amountOfOpenCards(int p, const AiInput::Board ¤t) const
{
- int cnt = 0;
- for (int i=0;i<8;i++)
- {
- if (current.cardsAtPos(p, i) > 0) cnt++;
- }
- return cnt;
+ int cnt = 0;
+ for (int i = 0; i < 8; i++)
+ {
+ if (current.cardsAtPos(p, i) > 0) cnt++;
+ }
+ return cnt;
}
-
- int AiInput::amountOfWinningCards(int p, Suite sSuite, const AiInput::Board& \
current) const + int AiInput::amountOfWinningCards(int p, Suite sSuite, const \
AiInput::Board ¤t) const {
- int cnt = 0;
- for (int i=0;i<8;i++)
- {
- int card = current.card(p, i);
- if (card < 0) continue;
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- // Treat jacks as trump
- if (type == Jack) suite = Grand;
- // Check only right suite or trump cards
- if (sSuite != suite) continue;
-
- // Would we win this card?
- if (wouldWinMove(p, card, current)) cnt++;
- }
- return cnt;
+ int cnt = 0;
+ for (int i = 0; i < 8; i++)
+ {
+ int card = current.card(p, i);
+ if (card < 0) continue;
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
+ // Treat jacks as trump
+ if (type == Jack) suite = Grand;
+ // Check only right suite or trump cards
+ if (sSuite != suite) continue;
+
+ // Would we win this card?
+ if (wouldWinMove(p, card, current)) cnt++;
+ }
+ return cnt;
}
-
// Check whether the given card would win a initial move
- bool AiInput::wouldWinMove(int p, int card, const AiInput::Board& current) const
+ bool AiInput::wouldWinMove(int p, int card, const AiInput::Board ¤t) const
{
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- if (type == Jack) suite = current.trump;
-
- // Check only right suite or trump cards
- if (suite != current.trump &&
- current.amountOfSuite[1-p][suite] == 0 &&
- current.amountOfSuite[1-p][Grand] > 0)
- {
- //qCDebug(LSKAT_LOG) << "Player" << (1-p) << "can use trump against" << \
Deck::name(suite);
- return false;
- }
-
- // Other player has suite..check cards
- for (int j=0; j<8; j++)
- {
- int ocard = current.card(1-p, j);
- if (ocard < 0) continue;
- Suite osuite = Deck::getSuite(ocard);
- CardType otype = Deck::getCardType(ocard);
- if (otype == Jack) osuite = current.trump;
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
+ if (type == Jack) suite = current.trump;
// Check only right suite or trump cards
- if (suite == osuite)
+ if (suite != current.trump &&
+ current.amountOfSuite[1 - p][suite] == 0 &&
+ current.amountOfSuite[1 - p][Grand] > 0)
{
- // 0 if card wins ocards, 1 otherwise
- int owinner = EngineTwo::whoWonMove(card, ocard, current.trump);
- if (owinner == 1)
- {
- //qCDebug(LSKAT_LOG) << "Player" << p << "looses" << Deck::name(card);
- //kDebug() << "Player" << (1 - p) << "can use trump against" << \
Deck::name(suite); ++ //qCDebug(LSKAT_LOG) << "Player" << (1 - p) << "can use \
trump against" << Deck::name(suite); return false;
- }
}
- }
- //qCDebug(LSKAT_LOG) << "Player" << p << "wins" << Deck::name(card);
- return true;
+
+ // Other player has suite..check cards
+ for (int j = 0; j < 8; j++)
+ {
+ int ocard = current.card(1 - p, j);
+ if (ocard < 0) continue;
+ Suite osuite = Deck::getSuite(ocard);
+ CardType otype = Deck::getCardType(ocard);
+ if (otype == Jack) osuite = current.trump;
+
+ // Check only right suite or trump cards
+ if (suite == osuite)
+ {
+ // 0 if card wins ocards, 1 otherwise
+ int owinner = EngineTwo::whoWonMove(card, ocard, current.trump);
+ if (owinner == 1)
+ {
- //kDebug() << "Player" << p << "looses" << Deck::name(card);
++ //qCDebug(LSKAT_LOG) << "Player " << p << " looses " << \
Deck::name(card); + return false;
+ }
+ }
- }
- //kDebug() << "Player" << p << "wins" << Deck::name(card);
++ //qCDebug(LSKAT_LOG) << "Player " << p << " wins " << Deck::name(card);
+ return true;
}
// Game evaluation ratings
// Try to save a free ten
- const double RULE_FREE_TEN = 20.0*RATING_ONE_POINT;
+ const double RULE_FREE_TEN = 20.0 * RATING_ONE_POINT;
// Catch a free ten
- const double RULE_CATCH_TEN = 15.0*RATING_ONE_POINT;
+ const double RULE_CATCH_TEN = 15.0 * RATING_ONE_POINT;
// Use Ace to hunt free tens
- const double RULE_HUNTER_ACE = -20.0*RATING_ONE_POINT;
+ const double RULE_HUNTER_ACE = -20.0 * RATING_ONE_POINT;
// Do not free Ace to possibly hunt free tens
- const double RULE_SUPPORT_ACE = -14.0*RATING_ONE_POINT;
+ const double RULE_SUPPORT_ACE = -14.0 * RATING_ONE_POINT;
// Protect possible free ten with minor card
- const double RULE_PROTECT_TEN = -14.0*RATING_ONE_POINT;
+ const double RULE_PROTECT_TEN = -14.0 * RATING_ONE_POINT;
// Protect possible free ten with removing hunter Ace
- const double RULE_KILL_HUNTER_ACE = 25.0*RATING_ONE_POINT;
+ const double RULE_KILL_HUNTER_ACE = 25.0 * RATING_ONE_POINT;
// Pull trumps
- const double RULE_PULL_TRUMP = 10.0*RATING_ONE_POINT;
+ const double RULE_PULL_TRUMP = 10.0 * RATING_ONE_POINT;
// Save trumps
- const double RULE_SAVE_TRUMP = -10.0*RATING_ONE_POINT;
+ const double RULE_SAVE_TRUMP = -10.0 * RATING_ONE_POINT;
// Stay first mover
- const double RULE_FIRST_MOVER = 4.0*RATING_ONE_POINT;
+ const double RULE_FIRST_MOVER = 4.0 * RATING_ONE_POINT;
-
- // Rule based override over board evaluation to tackle special szenarios
- double AiInput::rulebaseFirstMover(int p, int card, const AiInput::Board& current) \
const + // Rule based override over board evaluation to tackle special scenarios
+ double AiInput::rulebaseFirstMover(int p, int card, const AiInput::Board ¤t) \
const {
- double result = 0.0;
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- Suite altSuite = (suite==current.trump || type == Jack)?Grand:suite;
-
- // Check whether we win the move
- if (wouldWinMove(p, card, current))
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Staying first mover" \
<< Deck::name(card);
- result += RULE_FIRST_MOVER;
- }
-
- // Protect free ten
- if (type == Ten &&
- findCard(current, suite, Ace) != CARD_PLAYED &&
- findCard(current, suite, Ace) != p &&
- wouldWinMove(p, card, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Saving Ten" << \
Deck::name(card);
- result += RULE_FREE_TEN;
- }
-
- // Catch free ten
- if (type == Ace &&
- (1-p) == findCard(current, suite, Ten) &&
- hasAmount(1-p, altSuite, 1, 1, current) &&
- wouldWinMove(p, card, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Catching Ten with" << \
Deck::name(card);
- result += RULE_CATCH_TEN;
- }
-
- // Saving Ace to try to catch free ten
- if (type == Ace &&
- suite != current.trump &&
- (1-p) == findCard(current, suite, Ten) &&
- hasAmount(1-p, suite, 2, 3, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Hunting Ten with" << \
Deck::name(card);
- result += RULE_HUNTER_ACE;
- }
-
- // Saving additional cards for hunter Ace
- if (suite != current.trump &&
- type != Jack &&
- type != Ace &&
- (1-p) == findCard(current, suite, Ten) &&
- (p) == findCard(current, suite, Ace) &&
- hasAmount(1-p, suite, 2, 3, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Supporting Hunter ACE \
with" << Deck::name(card);
- if (hasAmount(1-p, suite, 2, 2, current)) result += RULE_SUPPORT_ACE;
- else result += 0.75*RULE_SUPPORT_ACE;
- }
-
- // Saving additional cards for hunted Ten
- if (suite != current.trump &&
- type != Jack &&
- type != Ten &&
- (1-p) == findCard(current, suite, Ace) &&
- (p) == findCard(current, suite, Ten) &&
- hasAmount(p, suite, 2, 3, current) &&
- hasAmount(1-p, suite, 2, 11, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Protecting hunted TEN \
with" << Deck::name(card);
- if (hasAmount(p, suite, 2, 2, current)) result += RULE_PROTECT_TEN;
- else result += 0.5*RULE_PROTECT_TEN;
- }
-
- // Killing hunter Ace
- if (suite != current.trump &&
- type != Jack &&
- type != Ten &&
- (1-p) == findCard(current, suite, Ace) &&
- (p) == findCard(current, suite, Ten) &&
- hasAmount(p, suite, 2, 11, current) &&
- hasAmount(1-p, suite, 1, 1, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Killing hunter ACE \
with" << Deck::name(card);
- result += RULE_KILL_HUNTER_ACE;
- }
-
- // Pull trumps
- if (altSuite == Grand)
- {
- int trumpWin1 = amountOfWinningCards(p, altSuite, current);
- //int trumpWin2 = amountOfWinningCards(1-p, altSuite, current);
- int trump1 = current.amountOfSuite[p][int(altSuite)];
- int trump2 = current.amountOfSuite[1-p][int(altSuite)];
- // Pull trump
- if (
- trumpWin1 >= trump2 &&
- trump1 > trump2 &&
- trump2 > 0 &&
- wouldWinMove(p, card, current) )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Pull trump" << \
Deck::name(card);
- result += RULE_PULL_TRUMP;
- }
-
- // Do not play trump if other party has none
- if (trump2 == 0)
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER RULE: Save trump" << \
Deck::name(card);
- if (trump1 == 1) result += RULE_SAVE_TRUMP;
- else if (trump1 == 2) result += 0.75*RULE_SAVE_TRUMP;
- else result += 0.5*RULE_SAVE_TRUMP;
- }
- }
-
- return result;
+ double result = 0.0;
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
- Suite altSuite = (suite == current.trump || type == Jack)?Grand:suite;
++ Suite altSuite = (suite == current.trump || type == Jack)?Grand:suite;
+
+ // Check whether we win the move
+ if (wouldWinMove(p, card, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Staying first mover" << \
Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
RULE: Staying first mover " << Deck::name(card); + result += \
RULE_FIRST_MOVER; + }
+
+ // Protect free ten
+ if (type == Ten &&
+ findCard(current, suite, Ace) != CARD_PLAYED &&
+ findCard(current, suite, Ace) != p &&
+ wouldWinMove(p, card, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Saving Ten" << \
Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
RULE: Saving Ten " << Deck::name(card); + result += RULE_FREE_TEN;
+ }
+
+ // Catch free ten
+ if (type == Ace &&
+ (1 - p) == findCard(current, suite, Ten) &&
+ hasAmount(1 - p, altSuite, 1, 1, current) &&
+ wouldWinMove(p, card, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Catching Ten with" << \
Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
RULE: Catching Ten with " << Deck::name(card); + result += RULE_CATCH_TEN;
+ }
+
+ // Saving Ace to try to catch free ten
+ if (type == Ace &&
+ suite != current.trump &&
+ (1 - p) == findCard(current, suite, Ten) &&
+ hasAmount(1 - p, suite, 2, 3, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Hunting Ten with" << \
Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
RULE: Hunting Ten with " << Deck::name(card); + result += RULE_HUNTER_ACE;
+ }
+
+ // Saving additional cards for hunter Ace
+ if (suite != current.trump &&
+ type != Jack &&
+ type != Ace &&
+ (1 - p) == findCard(current, suite, Ten) &&
+ (p) == findCard(current, suite, Ace) &&
+ hasAmount(1 - p, suite, 2, 3, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Supporting Hunter ACE \
with" << Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << \
"TRIGGER RULE: Supporting Hunter ACE with " << Deck::name(card); + if \
(hasAmount(1 - p, suite, 2, 2, current)) result += RULE_SUPPORT_ACE; + else \
result += 0.75 * RULE_SUPPORT_ACE; + }
+
+ // Saving additional cards for hunted Ten
+ if (suite != current.trump &&
+ type != Jack &&
+ type != Ten &&
+ (1 - p) == findCard(current, suite, Ace) &&
+ (p) == findCard(current, suite, Ten) &&
+ hasAmount(p, suite, 2, 3, current) &&
+ hasAmount(1 - p, suite, 2, 11, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Protecting hunted TEN \
with" << Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << \
"TRIGGER RULE: Protecting hunted TEN with " << Deck::name(card); + if \
(hasAmount(p, suite, 2, 2, current)) result += RULE_PROTECT_TEN; + else \
result += 0.5 * RULE_PROTECT_TEN; + }
+
+ // Killing hunter Ace
+ if (suite != current.trump &&
+ type != Jack &&
+ type != Ten &&
+ (1 - p) == findCard(current, suite, Ace) &&
+ (p) == findCard(current, suite, Ten) &&
+ hasAmount(p, suite, 2, 11, current) &&
+ hasAmount(1 - p, suite, 1, 1, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Killing hunter ACE with" \
<< Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
RULE: Killing hunter ACE with " << Deck::name(card); + result += \
RULE_KILL_HUNTER_ACE; + }
+
+ // Pull trumps
+ if (altSuite == Grand)
+ {
+ int trumpWin1 = amountOfWinningCards(p, altSuite, current);
+ //int trumpWin2 = amountOfWinningCards(1 - p, altSuite, current);
+ int trump1 = current.amountOfSuite[p][int(altSuite)];
+ int trump2 = current.amountOfSuite[1 - p][int(altSuite)];
+ // Pull trump
+ if (trumpWin1 >= trump2 &&
+ trump1 > trump2 &&
+ trump2 > 0 &&
+ wouldWinMove(p, card, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Pull trump" << \
Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
RULE: Pull trump " << Deck::name(card); + result += RULE_PULL_TRUMP;
+ }
+
+ // Do not play trump if other party has none
+ if (trump2 == 0)
+ {
- if (global_debug > 1) kDebug() << "TRIGGER RULE: Save trump" << \
Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
RULE: Save trump " << Deck::name(card); + if (trump1 == 1) result += \
RULE_SAVE_TRUMP; + else if (trump1 == 2) result += 0.75 * \
RULE_SAVE_TRUMP; + else result += 0.5 * RULE_SAVE_TRUMP;
+ }
+ }
+
+ return result;
}
- // Rule based override over board evaluation to tackle special szenarios
- double AiInput::rulebaseAnswerMover(int p, int card, const AiInput::Board& \
current) const + // Rule based override over board evaluation to tackle special \
scenarios + double AiInput::rulebaseAnswerMover(int p, int card, const AiInput::Board \
¤t) const {
- double result = 0.0;
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- Suite altSuite = (suite==current.trump || type == Jack)?Grand:suite;
-
- // Check whether we win the move
- if (wouldWinMove(p, card, current))
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER ANSWER RULE: Becoming first \
mover" << Deck::name(card);
- result += RULE_FIRST_MOVER;
- }
-
- // Saving Ace to try to catch free ten
- if (type == Ace &&
- suite != current.trump &&
- (1-p) == findCard(current, suite, Ten) &&
- hasAmount(1-p, suite, 1, 2, current) &&
- hasAmount(p, suite, 2, 3, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER ANSWER RULE: Hunting Ten \
with" << Deck::name(card);
- result += RULE_HUNTER_ACE;
- }
-
- // Saving additional cards for hunter Ace
- if (suite != current.trump &&
- type != Jack &&
- type != Ace &&
- (1-p) == findCard(current, suite, Ten) &&
- (p) == findCard(current, suite, Ace) &&
- hasAmount(1-p, suite, 1, 2, current)
- )
- {
- if (global_debug>1) qCDebug(LSKAT_LOG) << "TRIGGER ANSWER RULE: Supporting \
Hunter ACE with" << Deck::name(card);
- if (hasAmount(1-p, suite, 1, 1, current)) result += RULE_SUPPORT_ACE;
- else result += 0.75*RULE_SUPPORT_ACE;
- }
-
-
- return result;
- }
+ double result = 0.0;
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
- Suite altSuite = (suite == current.trump || type == Jack)?Grand:suite;
++ Suite altSuite = (suite == current.trump || type == Jack)?Grand:suite;
+
+ // Check whether we win the move
+ if (wouldWinMove(p, card, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER ANSWER RULE: Becoming first \
mover" << Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << \
"TRIGGER ANSWER RULE: Becoming first mover" << Deck::name(card); + result += \
RULE_FIRST_MOVER; + }
+ // Saving Ace to try to catch free ten
+ if (type == Ace &&
+ suite != current.trump &&
+ (1 - p) == findCard(current, suite, Ten) &&
+ hasAmount(1 - p, suite, 1, 2, current) &&
+ hasAmount(p, suite, 2, 3, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER ANSWER RULE: Hunting Ten with" \
<< Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "TRIGGER \
ANSWER RULE: Hunting Ten with" << Deck::name(card); + result += \
RULE_HUNTER_ACE; + }
+
+ // Saving additional cards for hunter Ace
+ if (suite != current.trump &&
+ type != Jack &&
+ type != Ace &&
+ (1 - p) == findCard(current, suite, Ten) &&
+ (p) == findCard(current, suite, Ace) &&
+ hasAmount(1 - p, suite, 1, 2, current))
+ {
- if (global_debug > 1) kDebug() << "TRIGGER ANSWER RULE: Supporting Hunter \
ACE with" << Deck::name(card); ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << \
"TRIGGER ANSWER RULE: Supporting Hunter ACE with" << Deck::name(card); + if \
(hasAmount(1 - p, suite, 1, 1, current)) result += RULE_SUPPORT_ACE; + else \
result += 0.75 * RULE_SUPPORT_ACE; + }
+
+ return result;
+ }
// Check whether the given player has between [min,max] cards of the given suite
- bool AiInput::hasAmount(int player, Suite suite, int min, int max, const \
AiInput::Board& current) const + bool AiInput::hasAmount(int player, Suite suite, int \
min, int max, const AiInput::Board ¤t) const {
- if (current.amountOfSuite[player][int(suite)] >= min &&
- current.amountOfSuite[player][int(suite)] <= max)
- {
- return true;
- }
- return false;
+ if (current.amountOfSuite[player][int(suite)] >= min &&
+ current.amountOfSuite[player][int(suite)] <= max)
+ {
+ return true;
+ }
+ return false;
}
-
- // Check whether the two cards played are legal, supposed the
- // given player is the second one (as the first player always
- // plays a legal card)
- bool AiInput::isLegalMove(int card1, int card2, int pl, const AiInput::Board& \
current) const + // Check whether the two cards played are legal, supposed the given \
player is + // the second one (as the first player always plays a legal card)
+ bool AiInput::isLegalMove(int card1, int card2, int pl, const AiInput::Board \
¤t) const {
- Suite suite1 = Deck::getSuite(card1);
- Suite suite2 = Deck::getSuite(card2);
- CardType type1 = Deck::getCardType(card1);
- CardType type2 = Deck::getCardType(card2);
-
- // Force trump colour as Jacks count as Trump
- if (type1 == Jack) suite1 = current.trump;
- if (type2 == Jack) suite2 = current.trump;
-
- // Same suite is always ok
- if (suite1 == suite2) return true;
-
- // Search if current player has a card of the same colour
- // but didn't play it (if it was played we checked already
- // above)
- for (int i=0;i<8;i++)
- {
- int card = current.card(pl, i);
- // This card is not available anymore
- if (card < 0) continue;
- // if (type1 == Jack) qCDebug(LSKAT_LOG) << "Check card 2 " <<Deck::name(card);
-
- // Ignore played card
- if (card == card2) continue;
-
- // Analyze card
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
+ Suite suite1 = Deck::getSuite(card1);
+ Suite suite2 = Deck::getSuite(card2);
+ CardType type1 = Deck::getCardType(card1);
+ CardType type2 = Deck::getCardType(card2);
// Force trump colour as Jacks count as Trump
- if (type == Jack) suite = current.trump;
+ if (type1 == Jack) suite1 = current.trump;
+ if (type2 == Jack) suite2 = current.trump;
- // Check whether current card matches the first player card
- if (suite == suite1)
+ // Same suite is always OK
+ if (suite1 == suite2) return true;
+
- // Search if current player has a card of the same colour but didn't
++ // Search if current player has a card of the same colour but did not
+ // play it (if it was played we checked already above)
+ for (int i = 0; i < 8; i++)
{
- return false;
+ int card = current.card(pl, i);
+ // This card is not available anymore
+ if (card < 0) continue;
- // if (type1 == Jack) kDebug() << "Check card 2 " << Deck::name(card);
++ // if (type1 == Jack) qCDebug(LSKAT_LOG) << "Check card 2 " \
<<Deck::name(card); +
+ // Ignore played card
+ if (card == card2) continue;
+
+ // Analyze card
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
+
+ // Force trump colour as Jacks count as Trump
+ if (type == Jack) suite = current.trump;
+
+ // Check whether current card matches the first player card
+ if (suite == suite1)
+ {
+ return false;
+ }
}
- }
- // if (type1 == Jack) qCDebug(LSKAT_LOG) << "ALLOWED ";
- return true;
- // if (type1 == Jack) kDebug() << "ALLOWED ";
++ // if (type1 == Jack) qCDebug(LSKAT_LOG) << "ALLOWED ";
+ return true;
}
--
-
-#include "aiinput.moc"
diff --cc src/cardsprite.cpp
index 94bdd49,ae6ac4d..236146d
--- a/src/cardsprite.cpp
+++ b/src/cardsprite.cpp
@@@ -40,90 -39,82 +40,83 @@@
// Theme manager stuff
#define THEME_ID "card"
-
// Constructor for the view
- CardSprite::CardSprite(const Suite suite, const CardType cardtype, ThemeManager* \
theme,
- int advancePeriod, QGraphicsScene* scene)
- : Themable(QLatin1String( THEME_ID ), theme), QGraphicsPixmapItem(0)
+ CardSprite::CardSprite(const Suite suite, const CardType cardtype, ThemeManager \
*theme, + int advancePeriod, QGraphicsScene *scene)
- : Themable(QLatin1String(THEME_ID), theme), QGraphicsPixmapItem(0, scene)
++ : Themable(QLatin1String(THEME_ID), theme), QGraphicsPixmapItem(0)
{
- scene->addItem(this);
- mAnimationState = Idle;
- mCurrentFrame = -1; // Frame will be set to backside
- mAdvancePeriod = advancePeriod;
- mSuite = suite;
- mCardType = cardtype;
- mFrames.clear();
-
- // Redraw
- if (theme) theme->updateTheme(this);
++ scene->addItem(this);
+ mAnimationState = Idle;
+ mCurrentFrame = -1; // Frame will be set to backside
+ mAdvancePeriod = advancePeriod;
+ mSuite = suite;
+ mCardType = cardtype;
+ mFrames.clear();
+
+ // Redraw
+ if (theme) theme->updateTheme(this);
}
-
// Main themable function. Called for any theme change. The sprites needs to
- // resiez and redraw here.
+ // resize and redraw here.
void CardSprite::changeTheme()
{
- // Get scaling change
- double oldscale = this->getScale();
- double scale = thememanager()->getScale();
- Themable::setScale(scale);
-
- // Retrieve theme data from configuration
- KConfigGroup config = thememanager()->config(id());
- double width = config.readEntry("width", 1.0);
- width *= scale;
- mWidth = width; // Store for later use
-
- // Z-value by program only
- // Nothing to do
-
- // Animation
- int startFrame = config.readEntry("start-frame", 0);
- int endFrame = config.readEntry("end-frame", 0);
-
- // Pos py program only
- setPos(x()*scale/oldscale, y()*scale/oldscale);
-
- // Frames (loaded on demand)
- mFrames.clear();
- mHotspots.clear();
- QPixmap nullPixmap;
- for (int i=startFrame;i<=endFrame;i++)
- {
- mFrames.append(nullPixmap);
- mHotspots.append(QPointF(0.0,0.0));
- }
-
- // Start with backside to save calculation time
- if (mCurrentFrame < 0) mCurrentFrame = endFrame;
-
-
- // Set pixmap to sprite
- setFrame(mCurrentFrame, true);
- update();
- }
+ // Get scaling change
+ double oldscale = this->getScale();
+ double scale = thememanager()->getScale();
+ Themable::setScale(scale);
+
+ // Retrieve theme data from configuration
+ KConfigGroup config = thememanager()->config(id());
+ double width = config.readEntry("width", 1.0);
+ width *= scale;
+ mWidth = width; // Store for later use
+
+ // Z-value by program only
+ // Nothing to do
+
+ // Animation
+ int startFrame = config.readEntry("start-frame", 0);
+ int endFrame = config.readEntry("end-frame", 0);
+ // Pos py program only
+ setPos(x() * scale / oldscale, y() * scale / oldscale);
- // Stop all movment and animation
+ // Frames (loaded on demand)
+ mFrames.clear();
+ mHotspots.clear();
+ QPixmap nullPixmap;
+ for (int i = startFrame; i <= endFrame; i++)
+ {
+ mFrames.append(nullPixmap);
+ mHotspots.append(QPointF(0.0, 0.0));
+ }
+
+ // Start with backside to save calculation time
+ if (mCurrentFrame < 0) mCurrentFrame = endFrame;
+
+ // Set pixmap to sprite
+ setFrame(mCurrentFrame, true);
+ update();
+ }
+
+ // Stop all movement and animation
void CardSprite::stop()
{
- mAnimationState = Idle;
- mTime = 0.0;
- setBackside();
+ mAnimationState = Idle;
+ mTime = 0.0;
+ setBackside();
}
-
- // Set the current aniamtion mode of this sprite
+ // Set the current animation mode of this sprite
void CardSprite::setTurning(bool front)
{
- mFrontFlag = front;
- mAnimationState = Turning;
- mTime = 0.0;
+ mFrontFlag = front;
+ mAnimationState = Turning;
+ mTime = 0.0;
}
-
// Set target position and calculate moving speed.
void CardSprite::calcTargetAndSpeed(QPointF pos, double time)
{
diff --cc src/config_two.cpp
index f8a2a37,4229328..008d3fe
--- a/src/config_two.cpp
+++ b/src/config_two.cpp
@@@ -23,22 -23,20 +23,20 @@@
// Qt includes
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
#include <kconfiggroup.h>
-#include <klocale.h>
+#include <KLocalizedString>
-
// Constructor for the configuration
- ConfigTwo::ConfigTwo(QObject* parent)
+ ConfigTwo::ConfigTwo(QObject *parent)
: QObject(parent)
{
- // Create Players
- mPlayers.clear();
- mPlayers[0] = new Player(0, this);
- mPlayers[1] = new Player(1, this);
+ // Create Players
+ mPlayers.clear();
+ mPlayers[0] = new Player(0, this);
+ mPlayers[1] = new Player(1, this);
}
-
// Resets the data
void ConfigTwo::reset()
{
@@@ -135,10 -126,8 +126,6 @@@ InputDeviceType ConfigTwo::inputType(in
// Set the input type for a given players
void ConfigTwo::setInputType(int no, InputDeviceType type)
{
- mInputTypes[no] = type;
- emit signalInputType(no, type);
+ mInputTypes[no] = type;
+ emit signalInputType(no, type);
}
--
-
-
-#include "config_two.moc"
diff --cc src/deck.cpp
index 05e0bde,12a0c7f..184f2a4
--- a/src/deck.cpp
+++ b/src/deck.cpp
@@@ -120,13 -117,12 +117,12 @@@ void Deck::shuffle(
// Draw a card from the deck
int Deck::drawCard()
{
- if (mCards.size() < 1)
- {
- qCCritical(LSKAT_LOG) << "No more cards to draw from card deck";
- }
- int card = mCards.takeFirst();
- return card;
+ if (mCards.size() < 1)
+ {
- kFatal() << "No more cards to draw from card deck";
++ qCCritical(LSKAT_LOG) << "No more cards to draw from card deck";
+ }
+ int card = mCards.takeFirst();
+ return card;
}
int Deck::getCard(Suite suite, CardType type)
@@@ -204,6 -195,5 +195,3 @@@ QString Deck::name(Suite suite, CardTyp
QString typeName = name(type);
return i18nc("eg jack of clubs", "%1 of %2", typeName, suiteName);
}
--
-
-
-#include "deck.moc"
diff --cc src/deck.h
index 8bd9b4d,969c0ed..bb6c107
--- a/src/deck.h
+++ b/src/deck.h
@@@ -26,18 -27,20 +27,18 @@@
#include <QHash>
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
#include <krandomsequence.h>
-
- /** The card, suite and trump names
- */
+ /**
+ * The card, suite and trump names
+ */
namespace CardDeck
{
- // Suite names
- enum Suite {Club=0,Spade=1,Heart=2,Diamond=3,Grand=4};
- // Card types.
- enum CardType {Ace=0,King=1,Queen=2,Jack=3,Ten=4,Nine=5,Eight=6,Seven=7};
+ // Suite names
+ enum Suite {Club = 0, Spade = 1, Heart = 2, Diamond = 3, Grand = 4};
+ // Card types.
+ enum CardType {Ace = 0, King = 1, Queen = 2, Jack = 3, Ten = 4, Nine = 5, Eight = \
6, Seven = 7}; }
using namespace CardDeck;
diff --cc src/display_intro.cpp
index 346b183,4c18910..232cbbd
--- a/src/display_intro.cpp
+++ b/src/display_intro.cpp
@@@ -38,24 -39,23 +38,23 @@@
#define WAIT_CNT 100 /* Wait this [ms] before clearing board */
// Constructor for the display
- DisplayIntro::DisplayIntro(Deck* deck, QGraphicsScene* theScene, ThemeManager* \
theme,
- int advancePeriod, QGraphicsView* parent)
- : Themable(QLatin1String( "display_intro" ),theme), \
AbstractDisplay(deck, theScene, theme, advancePeriod, parent) + \
DisplayIntro::DisplayIntro(Deck *deck, QGraphicsScene *theScene, ThemeManager *theme, \
+ int advancePeriod, QGraphicsView *parent) + \
: Themable(QLatin1String("display_intro"), theme), AbstractDisplay(deck, theScene, \
theme, advancePeriod, parent) {
- mTextShown = false;
+ mTextShown = false;
- // Choose a background color
- scene()->setBackgroundBrush(QColor(0,0,128));
+ // Choose a background color
+ scene()->setBackgroundBrush(QColor(0, 0, 128));
- mTimer = new QTimer(this);
- connect(mTimer, &QTimer::timeout, this, &DisplayIntro::loop);
- mTimer->stop();
+ mTimer = new QTimer(this);
- connect(mTimer, SIGNAL(timeout()), this, SLOT(loop()));
++ connect(mTimer, &QTimer::timeout, this, &DisplayIntro::loop);
+ mTimer->stop();
- // Redraw
- if (theme) theme->updateTheme(this);
+ // Redraw
+ if (theme) theme->updateTheme(this);
}
-
// Called by thememanager when theme or theme geometry changes. Redraw and resize
// this display.
void DisplayIntro::changeTheme()
@@@ -89,163 -87,160 +86,158 @@@ void DisplayIntro::start(
// Animation loop
void DisplayIntro::loop()
{
- int no = mCards.size();
- // Catch no card error
- if (no<1) return;
-
- // Retrieve theme data
- KConfigGroup cardconfig = thememanager()->config(QLatin1String( "card" ));
- double card_width = cardconfig.readEntry("width", 1.0);
- KConfigGroup config = thememanager()->config(id());
- QPointF start_shift = config.readEntry("start-shift", QPointF(1.0,1.0));
- QPointF start_pos = config.readEntry("start-pos", QPointF(1.0,1.0));
- double time_clear_in = config.readEntry("time-clear-in", 1.0);
- double time_clear_out = config.readEntry("time-clear-out", 1.0);
- double aspectRatio = thememanager()->aspectRatio();
-
-
- // Display the intro text delayed
- if (mAnimCnt == 2 && mState == Putting && !mTextShown)
- {
- mTextShown = true;
- QString s1 = i18nc("Title of the game - line 1", "Lieutenant Skat");
- QString s2 = i18nc("Title of the game - line 2", "for");
- QString s3 = i18nc("Title of the game - line 3", "K D E");
-
- // Text sprite title foreground
- TextSprite* text1a = new TextSprite(s1, QLatin1String( "name-front" ), mTheme, \
scene());
- mSprites.append(text1a);
- text1a->show();
-
- // Text sprite title background
- TextSprite* text1b = new TextSprite(s1, QLatin1String( "name-back" ), mTheme, \
scene());
- mSprites.append(text1b);
- text1b->show();
-
- // Text sprite title foreground
- TextSprite* text2a = new TextSprite(s2, QLatin1String( "for-front" ), mTheme, \
scene());
- mSprites.append(text2a);
- text2a->show();
-
- // Text sprite title background
- TextSprite* text2b = new TextSprite(s2, QLatin1String( "for-back" ), mTheme, \
scene());
- mSprites.append(text2b);
- text2b->show();
-
- // Text sprite title foreground
- TextSprite* text3a = new TextSprite(s3, QLatin1String( "kde-front" ), mTheme, \
scene());
- mSprites.append(text3a);
- text3a->show();
-
- // Text sprite title background
- TextSprite* text3b = new TextSprite(s3, QLatin1String( "kde-back" ), mTheme, \
scene());
- mSprites.append(text3b);
- text3b->show();
- }
-
- // Display a card
- if (mAnimCnt < no && mState == Putting)
- {
- double factor = double(mAnimCnt)/double(no-1);
- double fsin = sin(factor*M_PI);
-
- CardSprite* sprite = mCards[mAnimCnt];
-
- QPointF pos;
- if (mAnimCnt %2 == 0)
+ int no = mCards.size();
+ // Catch no card error
+ if (no < 1) return;
+
+ // Retrieve theme data
+ KConfigGroup cardconfig = thememanager()->config(QLatin1String("card"));
+ double card_width = cardconfig.readEntry("width", 1.0);
+ KConfigGroup config = thememanager()->config(id());
+ QPointF start_shift = config.readEntry("start-shift", QPointF(1.0, 1.0));
+ QPointF start_pos = config.readEntry("start-pos", QPointF(1.0, 1.0));
+ double time_clear_in = config.readEntry("time-clear-in", 1.0);
+ double time_clear_out = config.readEntry("time-clear-out", 1.0);
+ double aspectRatio = thememanager()->aspectRatio();
+
+ // Display the intro text delayed
+ if (mAnimCnt == 2 && mState == Putting && !mTextShown)
{
- pos = QPointF(start_pos.x(), start_pos.y());
- pos += QPointF(start_shift.x() * fsin, start_shift.y() * factor);
+ mTextShown = true;
+ QString s1 = i18nc("Title of the game - line 1", "Lieutenant Skat");
+ QString s2 = i18nc("Title of the game - line 2", "for");
+ QString s3 = i18nc("Title of the game - line 3", "K D E");
+
+ // Text sprite title foreground
+ TextSprite *text1a = new TextSprite(s1, QLatin1String("name-front"), \
mTheme, scene()); + mSprites.append(text1a);
+ text1a->show();
+
+ // Text sprite title background
+ TextSprite *text1b = new TextSprite(s1, QLatin1String("name-back"), mTheme, \
scene()); + mSprites.append(text1b);
+ text1b->show();
+
+ // Text sprite title foreground
+ TextSprite *text2a = new TextSprite(s2, QLatin1String("for-front"), mTheme, \
scene()); + mSprites.append(text2a);
+ text2a->show();
+
+ // Text sprite title background
+ TextSprite *text2b = new TextSprite(s2, QLatin1String("for-back"), mTheme, \
scene()); + mSprites.append(text2b);
+ text2b->show();
+
+ // Text sprite title foreground
+ TextSprite *text3a = new TextSprite(s3, QLatin1String("kde-front"), mTheme, \
scene()); + mSprites.append(text3a);
+ text3a->show();
+
+ // Text sprite title background
+ TextSprite *text3b = new TextSprite(s3, QLatin1String("kde-back"), mTheme, \
scene()); + mSprites.append(text3b);
+ text3b->show();
}
- else
+
+ // Display a card
+ if (mAnimCnt < no && mState == Putting)
{
- pos = QPointF(1.0-start_pos.x()-card_width, start_pos.y());
- pos += QPointF(-start_shift.x() * fsin, start_shift.y() * factor);
+ double factor = double(mAnimCnt) / double(no - 1);
+ double fsin = sin(factor * M_PI);
+
+ CardSprite *sprite = mCards[mAnimCnt];
+
+ QPointF pos;
+ if (mAnimCnt % 2 == 0)
+ {
+ pos = QPointF(start_pos.x(), start_pos.y());
+ pos += QPointF(start_shift.x() * fsin, start_shift.y() * factor);
+ }
+ else
+ {
+ pos = QPointF(1.0 - start_pos.x() - card_width, start_pos.y());
+ pos += QPointF(-start_shift.x() * fsin, start_shift.y() * factor);
+ }
+ sprite->setBackside();
+ sprite->setPosition(pos);
+ sprite->setZValue(50 + mAnimCnt);
+ sprite->show();
+ mAnimCnt++;
}
- sprite->setBackside();
- sprite->setPosition(pos);
- sprite->setZValue(50+mAnimCnt);
- sprite->show();
- mAnimCnt++;
- }
- // Change state to turning
- else if (mState == Putting)
- {
- mState = Turning;
- mAnimCnt = 0;
- }
- // Turn cards
- else if (mAnimCnt < no && mState == Turning)
- {
- CardSprite* sprite = mCards[mAnimCnt];
- sprite->setTurning(true);
- mAnimCnt++;
- }
- // Change state to waiting
- else if (mState == Turning)
- {
- mState = Waiting;
- mAnimCnt = 0;
- }
- // Wait
- else if (mAnimCnt < WAIT_CNT && mState == Waiting)
- {
- mAnimCnt++;
- }
- // Change state to clearing the board
- else if (mState == Waiting)
- {
- mState = Clearing;
- mAnimCnt = 0;
- }
- // Clear the board, step 1
- else if (mAnimCnt == 0 && mState == Clearing)
- {
- for (int i=0; i<no; i++)
+ // Change state to turning
+ else if (mState == Putting)
{
- CardSprite* sprite = mCards[i];
- sprite->setMove(QPointF((1.0-card_width)/2.0, \
(1.0/aspectRatio-card_width)/2.0), time_clear_in); + mState = Turning;
+ mAnimCnt = 0;
}
- mAnimCnt++;
- }
- // Clear the board, step 2
- else if (mAnimCnt < 30 && mState == Clearing)
- {
- mAnimCnt++;
- }
- // Clear the board, step 3 and change state to waiting
- else if (mState == Clearing)
- {
- for (int i=0; i<no; i++)
+ // Turn cards
+ else if (mAnimCnt < no && mState == Turning)
{
- double r = 1.0;
- double x = r*cos(double(i)/double(no-1)*M_PI*2.0) + 0.5;
- double y = r*sin(double(i)/double(no-1)*M_PI*2.0) + 0.5;
- CardSprite* sprite = mCards[i];
- sprite->setMove(QPointF(x,y/aspectRatio), time_clear_out);
+ CardSprite *sprite = mCards[mAnimCnt];
+ sprite->setTurning(true);
+ mAnimCnt++;
}
- mState = Waiting2;
- mAnimCnt = 0;
- }
- // Wait
- else if (mAnimCnt < WAIT_CNT && mState == Waiting2)
- {
- mAnimCnt++;
- }
- // Restart cycle
- else if (mState == Waiting2)
- {
- for (int i=0; i<no; i++)
+ // Change state to waiting
+ else if (mState == Turning)
{
- CardSprite* sprite = mCards[i];
- sprite->stop();
+ mState = Waiting;
+ mAnimCnt = 0;
+ }
+ // Wait
+ else if (mAnimCnt < WAIT_CNT && mState == Waiting)
+ {
+ mAnimCnt++;
+ }
+ // Change state to clearing the board
+ else if (mState == Waiting)
+ {
+ mState = Clearing;
+ mAnimCnt = 0;
+ }
+ // Clear the board, step 1
+ else if (mAnimCnt == 0 && mState == Clearing)
+ {
+ for (int i = 0; i < no; i++)
+ {
+ CardSprite *sprite = mCards[i];
+ sprite->setMove(QPointF((1.0 - card_width) / 2.0, (1.0 / aspectRatio - \
card_width) / 2.0), time_clear_in); + }
+ mAnimCnt++;
+ }
+ // Clear the board, step 2
+ else if (mAnimCnt < 30 && mState == Clearing)
+ {
+ mAnimCnt++;
+ }
+ // Clear the board, step 3 and change state to waiting
+ else if (mState == Clearing)
+ {
+ for (int i = 0; i < no; i++)
+ {
+ double r = 1.0;
+ double x = r * cos(double(i) / double(no - 1) * M_PI * 2.0) + 0.5;
+ double y = r * sin(double(i) / double(no - 1) * M_PI * 2.0) + 0.5;
+ CardSprite *sprite = mCards[i];
+ sprite->setMove(QPointF(x, y / aspectRatio), time_clear_out);
+ }
+ mState = Waiting2;
+ mAnimCnt = 0;
+ }
+ // Wait
+ else if (mAnimCnt < WAIT_CNT && mState == Waiting2)
+ {
+ mAnimCnt++;
+ }
+ // Restart cycle
+ else if (mState == Waiting2)
+ {
+ for (int i = 0; i < no; i++)
+ {
+ CardSprite *sprite = mCards[i];
+ sprite->stop();
+ }
+
+ mState = Putting;
+ mAnimCnt = 0;
}
-
- mState = Putting;
- mAnimCnt = 0;
- }
-
}
--
-
-
-#include "display_intro.moc"
diff --cc src/display_intro.h
index 46f0a63,6fa6456..8020b94
--- a/src/display_intro.h
+++ b/src/display_intro.h
@@@ -24,9 -25,8 +25,8 @@@
#include <QGraphicsScene>
#include <QTimer>
-
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
// local includes
#include "abstractdisplay.h"
diff --cc src/display_two.cpp
index 0e1cb90,78493c2..0d352ca
--- a/src/display_two.cpp
+++ b/src/display_two.cpp
@@@ -41,290 -40,276 +40,276 @@@
#define TIME_DELAY_SHUFFLE 100 /* Delay time in shuffling in [ms] */
#define TIME_DELAY_AFTER_SHUFFLE 500 /* Extra delay after shuffling [ms] */
-
// Constructor for the engine
- DisplayTwo::DisplayTwo(Deck* deck, QGraphicsScene* theScene, ThemeManager* theme,
- int advancePeriod, QGraphicsView* parent)
- : Themable(QLatin1String( "display_two" ),theme), AbstractDisplay(deck, \
theScene, theme, advancePeriod, parent) + DisplayTwo::DisplayTwo(Deck *deck, \
QGraphicsScene *theScene, ThemeManager *theme, + int \
advancePeriod, QGraphicsView *parent) + : \
Themable(QLatin1String("display_two"), theme), AbstractDisplay(deck, theScene, theme, \
advancePeriod, parent)
{
- // Choose a background color
- scene()->setBackgroundBrush(QColor(0,0,128));
-
- // Create move icon
- mMoveSprites[0] = new PixmapSprite(QLatin1String( "moveicon0" ), mTheme, \
mAdvancePeriod, 0, scene());
- if (!mMoveSprites[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"moveicon";
- mSprites.append(mMoveSprites[0]);
-
- mMoveSprites[1] = new PixmapSprite(QLatin1String( "moveicon1" ), mTheme, \
mAdvancePeriod, 1, scene());
- if (!mMoveSprites[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"moveicon";
- mSprites.append(mMoveSprites[1]);
-
- // Create score board
- mScoreBoard[0] = new ScoreSprite(QLatin1String( "scoreboard0" ), mTheme, \
mAdvancePeriod, 0, scene());
- if (!mScoreBoard[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"scoreboard0";
- mSprites.append(mScoreBoard[0]);
-
- mScoreBoard[1] = new ScoreSprite(QLatin1String( "scoreboard1" ), mTheme, \
mAdvancePeriod, 1, scene());
- if (!mScoreBoard[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"scoreboard0";
- mSprites.append(mScoreBoard[1]);
-
- // Create card area
- mCardArea[0] = new PixmapSprite(QLatin1String( "cardarea0" ), mTheme, \
mAdvancePeriod, 0, scene());
- if (!mCardArea[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "cardarea0";
- mSprites.append(mCardArea[0]);
-
- mCardArea[1] = new PixmapSprite(QLatin1String( "cardarea1" ), mTheme, \
mAdvancePeriod, 1, scene());
- if (!mCardArea[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "cardarea1";
- mSprites.append(mCardArea[1]);
-
- // Create play area
- mPlayArea = new PixmapSprite(QLatin1String( "playarea" ), mTheme, mAdvancePeriod, \
0, scene());
- if (!mPlayArea) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "playarea";
- mSprites.append(mPlayArea);
-
- // Create text sprites
- mText[0] = new TextSprite(QLatin1String( "scoretext0" ), mTheme, scene());
- if (!mText[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "scoretext0";
- mSprites.append(mText[0]);
-
- mText[1] = new TextSprite(QLatin1String( "scoretext1" ), mTheme, scene());
- if (!mText[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "scoretext1";
- mSprites.append(mText[1]);
-
- mText[2] = new TextSprite(QLatin1String( "resulttext" ), mTheme, scene());
- if (!mText[2]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "resulttext";
- mSprites.append(mText[2]);
+ // Choose a background color
+ scene()->setBackgroundBrush(QColor(0, 0, 128));
+
+ // Create move icon
+ mMoveSprites[0] = new PixmapSprite(QLatin1String("moveicon0"), mTheme, \
mAdvancePeriod, 0, scene());
- if (!mMoveSprites[0]) kFatal() << "Cannot load sprite" << "moveicon";
++ if (!mMoveSprites[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"moveicon"; + mSprites.append(mMoveSprites[0]);
+
+ mMoveSprites[1] = new PixmapSprite(QLatin1String("moveicon1"), mTheme, \
mAdvancePeriod, 1, scene());
- if (!mMoveSprites[1]) kFatal() << "Cannot load sprite" << "moveicon";
++ if (!mMoveSprites[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"moveicon"; + mSprites.append(mMoveSprites[1]);
+
+ // Create score board
+ mScoreBoard[0] = new ScoreSprite(QLatin1String("scoreboard0"), mTheme, \
mAdvancePeriod, 0, scene());
- if (!mScoreBoard[0]) kFatal() << "Cannot load sprite" << "scoreboard0";
++ if (!mScoreBoard[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"scoreboard0"; + mSprites.append(mScoreBoard[0]);
+
+ mScoreBoard[1] = new ScoreSprite(QLatin1String("scoreboard1"), mTheme, \
mAdvancePeriod, 1, scene());
- if (!mScoreBoard[1]) kFatal() << "Cannot load sprite" << "scoreboard0";
++ if (!mScoreBoard[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"scoreboard0"; + mSprites.append(mScoreBoard[1]);
+
+ // Create card area
+ mCardArea[0] = new PixmapSprite(QLatin1String("cardarea0"), mTheme, \
mAdvancePeriod, 0, scene());
- if (!mCardArea[0]) kFatal() << "Cannot load sprite" << "cardarea0";
++ if (!mCardArea[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"cardarea0"; + mSprites.append(mCardArea[0]);
+
+ mCardArea[1] = new PixmapSprite(QLatin1String("cardarea1"), mTheme, \
mAdvancePeriod, 1, scene());
- if (!mCardArea[1]) kFatal() << "Cannot load sprite" << "cardarea1";
++ if (!mCardArea[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << \
"cardarea1"; + mSprites.append(mCardArea[1]);
+
+ // Create play area
+ mPlayArea = new PixmapSprite(QLatin1String("playarea"), mTheme, mAdvancePeriod, \
0, scene());
- if (!mPlayArea) kFatal() << "Cannot load sprite" << "playarea";
++ if (!mPlayArea) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "playarea";
+ mSprites.append(mPlayArea);
+
+ // Create text sprites
+ mText[0] = new TextSprite(QLatin1String("scoretext0"), mTheme, scene());
- if (!mText[0]) kFatal() << "Cannot load sprite" << "scoretext0";
++ if (!mText[0]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "scoretext0";
+ mSprites.append(mText[0]);
+
+ mText[1] = new TextSprite(QLatin1String("scoretext1"), mTheme, scene());
- if (!mText[1]) kFatal() << "Cannot load sprite" << "scoretext1";
++ if (!mText[1]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "scoretext1";
+ mSprites.append(mText[1]);
+
+ mText[2] = new TextSprite(QLatin1String("resulttext"), mTheme, scene());
- if (!mText[2]) kFatal() << "Cannot load sprite" << "resulttext";
++ if (!mText[2]) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "resulttext";
+ mSprites.append(mText[2]);
// Redraw
- if (theme) theme->updateTheme(this);
+ if (theme) theme->updateTheme(this);
}
-
- // Called by thememanager when theme or theme geometry changes. Redraw and resize
- // this display.
+ // Called by thememanager when theme or theme geometry changes. Redraw and
+ // resize this display.
void DisplayTwo::changeTheme()
{
- // Retrieve theme data
- KConfigGroup config = thememanager()->config(id());
-
-
- // Retrieve background pixmap
- QString bgsvgid = config.readEntry("background-svgid");
- QPixmap pixmap = thememanager()->getPixmap(bgsvgid, \
scene()->sceneRect().size().toSize());
- scene()->setBackgroundBrush(pixmap);
- mView->update();
+ // Retrieve theme data
+ KConfigGroup config = thememanager()->config(id());
+
+ // Retrieve background pixmap
+ QString bgsvgid = config.readEntry("background-svgid");
+ QPixmap pixmap = thememanager()->getPixmap(bgsvgid, \
scene()->sceneRect().size().toSize()); + scene()->setBackgroundBrush(pixmap);
+ mView->update();
}
// Start display
void DisplayTwo::start()
{
- // Stop all card sprites
- for (int i=0; i<mCards.size(); i++)
- {
- CardSprite* sprite = mCards[i];
- sprite->stop();
- }
-
- // Hide or show sprites
- mMoveSprites[0]->hide();
- mMoveSprites[1]->hide();
- mScoreBoard[0]->show();
- mScoreBoard[1]->show();
- mCardArea[0]->show();
- mCardArea[1]->show();
- mPlayArea->show();
- mText[0]->hide();
- mText[1]->hide();
- mText[2]->hide();
+ // Stop all card sprites
+ for (int i = 0; i < mCards.size(); i++)
+ {
+ CardSprite *sprite = mCards[i];
+ sprite->stop();
+ }
+ // Hide or show sprites
+ mMoveSprites[0]->hide();
+ mMoveSprites[1]->hide();
+ mScoreBoard[0]->show();
+ mScoreBoard[1]->show();
+ mCardArea[0]->show();
+ mCardArea[1]->show();
+ mPlayArea->show();
+ mText[0]->hide();
+ mText[1]->hide();
+ mText[2]->hide();
}
-
// Connect a player with the score widget
- void DisplayTwo::updatePlayer(Player* player)
+ void DisplayTwo::updatePlayer(Player *player)
{
- int id = player->id();
- mScoreBoard[id]->setPlayerName(player->name());
- mScoreBoard[id]->setPoints(player->points());
- mScoreBoard[id]->setScore(player->score());
- mScoreBoard[id]->setGames(player->wonGames(), player->games());
- mScoreBoard[id]->setInput(player->input()->type());
- mScoreBoard[id]->setTrump(player->trump());
+ int id = player->id();
+ mScoreBoard[id]->setPlayerName(player->name());
+ mScoreBoard[id]->setPoints(player->points());
+ mScoreBoard[id]->setScore(player->score());
+ mScoreBoard[id]->setGames(player->wonGames(), player->games());
+ mScoreBoard[id]->setInput(player->input()->type());
+ mScoreBoard[id]->setTrump(player->trump());
}
-
// Init a player on a given screen/board position (0,1)
- void DisplayTwo::deal(Player* player, int position)
+ void DisplayTwo::deal(Player *player, int position)
{
- if (position != 0 && position != 1)
- {
- qCCritical(LSKAT_LOG) << "Wrong player position" << position;
- return ;
- }
- if (!player)
- {
- qCCritical(LSKAT_LOG) << "No player given";
- return ;
- }
-
- KConfigGroup config = thememanager()->config(id());
- QPointF deck_pos = config.readEntry("deck-pos", QPointF(1.0,1.0));
-
- // Start offset for display
- QPointF board_pos = config.readEntry("board-pos1", QPointF(1.0,1.0));
- QPointF board_sep = config.readEntry("board-sep", QPointF(1.0,1.0));
- QPointF board_shift = config.readEntry("board-shift", QPointF(1.0,1.0));
- // Offset for second player
- if (position == 1)
- {
- board_pos = config.readEntry("board-pos2", QPointF(1.0,1.0));
- }
-
-
- // Two height level of cards
- for (int h=0; h<2; h++)
- {
- // Two rows of cards
- for (int y=0; y<2; y++)
+ if (position != 0 && position != 1)
{
- // Four columns of cards
- for (int x=0; x<4; x++)
- {
- // Get playerNumber on game board (0 1 2 3)
- // (4 5 6 7)
- int cardPos = x + 4*y + 8*h;
- // Get card of player belonging to this playerNumber
- int cardNo = player->getCard(cardPos);
- // Create sprite with card correct card image
- CardSprite* sprite = mCards[cardNo];
- // Move sprite to correct board playerNumber
- QPointF pos = board_pos + QPointF(x*board_sep.x(),y*board_sep.y());
- // Add shift for stacked cards
- pos += h*board_shift;
- sprite->setZValue(50-10*h);
- sprite->setPosition(deck_pos);
- sprite->show();
- double delay = position + 2*x + 8*y + 16*(1-h);
- delay *= TIME_DELAY_SHUFFLE; // [ms]
- // Move to the target position. The setPos is started with
- // a little delay and depending on the last argument the
- // backside or frontside is shown after the setPos
- sprite->setShuffleMove(pos, delay, h==0);
- // Store sprite
- }// next x
- }// next y
- }// next h
-
- // Check dealing for only one player to avoid double timer events
- if (position == 1)
- {
- QTimer::singleShot(100, this,SLOT(checkShuffle()));
- }
- }
- kFatal() << "Wrong player position" << position;
++ qCCritical(LSKAT_LOG) << "Wrong player position" << position;
+ return;
+ }
+ if (!player)
+ {
- kFatal() << "No player given";
++ qCCritical(LSKAT_LOG) << "No player given";
+ return;
+ }
+
+ KConfigGroup config = thememanager()->config(id());
+ QPointF deck_pos = config.readEntry("deck-pos", QPointF(1.0, 1.0));
+
+ // Start offset for display
+ QPointF board_pos = config.readEntry("board-pos1", QPointF(1.0, 1.0));
+ QPointF board_sep = config.readEntry("board-sep", QPointF(1.0, 1.0));
+ QPointF board_shift = config.readEntry("board-shift", QPointF(1.0, 1.0));
+ // Offset for second player
+ if (position == 1)
+ {
+ board_pos = config.readEntry("board-pos2", QPointF(1.0, 1.0));
+ }
+ // Two height level of cards
+ for (int h = 0; h < 2; h++)
+ {
+ // Two rows of cards
+ for (int y = 0; y < 2; y++)
+ {
+ // Four columns of cards
+ for (int x = 0; x < 4; x++)
+ {
+ // Get playerNumber on game board (0 1 2 3)
+ // (4 5 6 7)
+ int cardPos = x + 4 * y + 8 * h;
+ // Get card of player belonging to this playerNumber
+ int cardNo = player->getCard(cardPos);
+ // Create sprite with card correct card image
+ CardSprite *sprite = mCards[cardNo];
+ // Move sprite to correct board playerNumber
+ QPointF pos = board_pos + QPointF(x * board_sep.x(), y * \
board_sep.y()); + // Add shift for stacked cards
+ pos += h * board_shift;
+ sprite->setZValue(50 - 10 * h);
+ sprite->setPosition(deck_pos);
+ sprite->show();
+ double delay = position + 2 * x + 8 * y + 16 * (1 - h);
+ delay *= TIME_DELAY_SHUFFLE; // [ms]
+ // Move to the target position. The setPos is started with
+ // a little delay and depending on the last argument the
+ // backside or frontside is shown after the setPos
+ sprite->setShuffleMove(pos, delay, h == 0);
+ // Store sprite
+ }// next x
+ }// next y
+ }// next h
+
+ // Check dealing for only one player to avoid double timer events
+ if (position == 1)
+ {
+ QTimer::singleShot(100, this, SLOT(checkShuffle()));
+ }
+ }
// Check whether all cardsprites are idle
void DisplayTwo::checkShuffle()
{
- bool idle = true;
- // Check whether the sprites are idle
- for (int i=0; i<32; i++)
- {
- CardSprite* sprite = mCards[i];
- if (!sprite->isIdle())
+ bool idle = true;
+ // Check whether the sprites are idle
+ for (int i = 0; i < 32; i++)
{
- idle = false;
- break;
+ CardSprite *sprite = mCards[i];
+ if (!sprite->isIdle())
+ {
+ idle = false;
+ break;
+ }
}
- }
-
- // If sprites are not idle repeat check otherwise emit 'done' signal
- if (!idle)
- {
- QTimer::singleShot(100, this,SLOT(checkShuffle()));
- }
- else
- {
- emit dealingDone();
- }
- }
+ // If sprites are not idle repeat check otherwise emit 'done' signal
+ if (!idle)
+ {
+ QTimer::singleShot(100, this, SLOT(checkShuffle()));
+ }
+ else
+ {
+ emit dealingDone();
+ }
+ }
// Convert a mouse coordinate back to card numbers
- void DisplayTwo::convertMousePress(const QPoint &mouse, int& playerNumber, int& \
cardNumber) + void DisplayTwo::convertMousePress(const QPoint &mouse, int \
&playerNumber, int &cardNumber) {
- double scale = thememanager()->getScale();
- double x = mouse.x() / scale;
- double y = mouse.y() / scale;
-
- // Check play area 1
- KConfigGroup config0 = thememanager()->config(QLatin1String( "cardarea0" ));
- QPointF pos0 = config0.readEntry("pos", QPointF(1.0,1.0));
- double width0 = config0.readEntry("width", 1.0);
- double height0 = config0.readEntry("height", 1.0);
-
- double x0 = (x-pos0.x())/width0;
- double y0 = (y-pos0.y())/height0;
-
- // Check play area 2
- KConfigGroup config1 = thememanager()->config(QLatin1String( "cardarea1" ));
- QPointF pos1 = config1.readEntry("pos", QPointF(1.0,1.0));
- double width1 = config1.readEntry("width", 1.0);
- double height1 = config1.readEntry("height", 1.0);
-
- double x1 = (x-pos1.x())/width1;
- double y1 = (y-pos1.y())/height1;
-
-
- // Check in area 1
- if (x0>=0.0 && x0<1.0 && y0>=0.0 && y0<1.0)
- {
- int dx = int(x0*4.0);
- int dy = int(y0*2.0);
- playerNumber = 0;
- cardNumber = dx + 4*dy;
- return;
- }
-
- // Check in area 2
- if (x1>=0.0 && x1<1.0 && y1>=0.0 && y1<1.0)
- {
- int dx = int(x1*4.0);
- int dy = int(y1*2.0);
- playerNumber = 1;
- cardNumber = dx + 4*dy;
- return;
- }
+ double scale = thememanager()->getScale();
+ double x = mouse.x() / scale;
+ double y = mouse.y() / scale;
+
+ // Check play area 1
+ KConfigGroup config0 = thememanager()->config(QLatin1String("cardarea0"));
+ QPointF pos0 = config0.readEntry("pos", QPointF(1.0, 1.0));
+ double width0 = config0.readEntry("width", 1.0);
+ double height0 = config0.readEntry("height", 1.0);
+
+ double x0 = (x - pos0.x()) / width0;
+ double y0 = (y - pos0.y()) / height0;
+
+ // Check play area 2
+ KConfigGroup config1 = thememanager()->config(QLatin1String("cardarea1"));
+ QPointF pos1 = config1.readEntry("pos", QPointF(1.0, 1.0));
+ double width1 = config1.readEntry("width", 1.0);
+ double height1 = config1.readEntry("height", 1.0);
+
+ double x1 = (x - pos1.x()) / width1;
+ double y1 = (y - pos1.y()) / height1;
+
+ // Check in area 1
+ if (x0 >= 0.0 && x0 < 1.0 && y0 >= 0.0 && y0 < 1.0)
+ {
+ int dx = int(x0 * 4.0);
+ int dy = int(y0 * 2.0);
+ playerNumber = 0;
+ cardNumber = dx + 4 * dy;
+ return;
+ }
- playerNumber = -1;
- return;
- }
+ // Check in area 2
+ if (x1 >= 0.0 && x1 < 1.0 && y1 >= 0.0 && y1 < 1.0)
+ {
+ int dx = int(x1 * 4.0);
+ int dy = int(y1 * 2.0);
+ playerNumber = 1;
+ cardNumber = dx + 4 * dy;
+ return;
+ }
+ playerNumber = -1;
+ return;
+ }
// Get x (0-3) y(0-1) board coordinates from card number (0-7)
- void DisplayTwo::calcXYFromNumber(int cardNumber, int& x, int& y)
+ void DisplayTwo::calcXYFromNumber(int cardNumber, int &x, int &y)
{
- x = cardNumber % 4;
- y = cardNumber / 4;
+ x = cardNumber % 4;
+ y = cardNumber / 4;
}
-
// Get a cardsprite given the card value
- CardSprite* DisplayTwo::getCardSprite(int cardValue)
+ CardSprite *DisplayTwo::getCardSprite(int cardValue)
{
- CardSprite* sprite = mCards[cardValue];
- if (!sprite)
- {
- qCCritical(LSKAT_LOG) << "Could not find cardsprite for card value" << \
cardValue
- << "Stored are" << mCards.size() << "sprites";
- return 0;
- }
- return sprite;
- CardSprite *sprite = mCards[cardValue];
++ CardSprite *sprite = mCards[cardValue];
+ if (!sprite)
+ {
- kFatal() << "Could not find cardsprite for card value" << cardValue
++ qCCritical(LSKAT_LOG) << "Could not find cardsprite for card value" << \
cardValue + << "Stored are" << mCards.size() << "sprites";
+ return 0;
+ }
+ return sprite;
}
-
// Play a frontside card to the play area
void DisplayTwo::play(int cardNumber, int playerNumber, int phase)
{
@@@ -392,35 -374,32 +374,30 @@@ void DisplayTwo::showText(const QStrin
// Display the score on the game board
void DisplayTwo::showScore(int position, int score)
{
- if (position<0 || position>1)
- {
- qCCritical(LSKAT_LOG) << "Wrong position (0,1) for showScore =" << position;
- }
- if (score==0)
- mText[position]->setText(i18nc("Resulting score of a game with no point", "no \
point"));
- else
- mText[position]->setText(i18ncp("Resulting score of a game between 1 and 4", \
"%1 point", "%1 points", score));
- mText[position]->show();
+ if (position < 0 || position > 1)
+ {
- kFatal() << "Wrong position (0,1) for showScore =" << position;
++ qCCritical(LSKAT_LOG) << "Wrong position (0,1) for showScore =" << \
position; + }
+ if (score == 0)
+ mText[position]->setText(i18nc("Resulting score of a game with no point", \
"no point")); + else
+ mText[position]->setText(i18ncp("Resulting score of a game between 1 and \
4", "%1 point", "%1 points", score)); + mText[position]->show();
}
// Show the setPos icon for the given player
void DisplayTwo::showMove(int no)
{
- QHashIterator<int,PixmapSprite*> it(mMoveSprites);
- while(it.hasNext())
- {
- it.next();
- PixmapSprite* sprite = it.value();
- sprite->hide();
- }
-
- if (no>=0)
- {
- mMoveSprites[no]->show();
- }
- }
-
-
+ QHashIterator<int, PixmapSprite *> it(mMoveSprites);
+ while (it.hasNext())
+ {
+ it.next();
+ PixmapSprite *sprite = it.value();
+ sprite->hide();
+ }
+ if (no >= 0)
+ {
+ mMoveSprites[no]->show();
+ }
+ }
-
-#include "display_two.moc"
diff --cc src/engine_two.cpp
index a272ce4,8612374..9497b6e
--- a/src/engine_two.cpp
+++ b/src/engine_two.cpp
@@@ -33,212 -33,199 +33,199 @@@
#define TIME_END_MOVE 1000 /* Wait this [ms] after end of move */
-
// Constructor for the game document/engine
- EngineTwo::EngineTwo(QWidget* parent, Deck* deck, DisplayTwo* display)
+ EngineTwo::EngineTwo(QWidget *parent, Deck *deck, DisplayTwo *display)
: AbstractEngine(parent)
{
- mDisplay = display;
- mDeck = deck;
- mCurrentPlayer = 0;
+ mDisplay = display;
+ mDeck = deck;
+ mCurrentPlayer = 0;
- connect(mDisplay, &DisplayTwo::dealingDone, this, &EngineTwo::gameLoopStart);
- connect(mDisplay, SIGNAL(dealingDone()), this, SLOT(gameLoopStart()));
++ connect(mDisplay, &DisplayTwo::dealingDone, this, &EngineTwo::gameLoopStart);
}
// Initial part of the game loop. Prepare new move etc
void EngineTwo::gameLoopStart()
{
- if (global_debug > 1) qCDebug(LSKAT_LOG) << "GAME LOOP START";
- if (!isGameRunning()) return;
- if (global_debug > 1) kDebug() << "GAME LOOP START";
++ if (global_debug > 1) qCDebug(LSKAT_LOG) << "GAME LOOP START";
+ if (!isGameRunning()) return;
- // Switch to the current player
- activatePlayer(mCurrentPlayer);
+ // Switch to the current player
+ activatePlayer(mCurrentPlayer);
}
-
// Middle part of the game loop. Receive input of a player
// Here: inputId == playerNumber
void EngineTwo::playerInput(int inputId, int playerNumber, int cardNumber)
{
- if (global_debug > 0)
- qCDebug(LSKAT_LOG) << "Engine got player input: card=" << cardNumber
- << "Player=" << playerNumber << "Id=" << inputId;
- if (playerNumber != mCurrentPlayer)
- {
if (global_debug > 0)
- qCDebug(LSKAT_LOG) << "EngineTwo::playerInput: Input from wrong player";
- return;
- }
-
- Player* player = mPlayers[playerNumber];
- int height = 0;
- int card = player->getCard(cardNumber);
- // Check whether top card is still available - if not try bottom one
- if (card < 0)
- {
- height = 1;
- card = player->getCard(cardNumber + 8* height);
- }
- kDebug() << "Engine got player input: card=" << cardNumber
- << "Player=" << playerNumber << "Id=" << inputId;
++ qCDebug(LSKAT_LOG) << "Engine got player input: card=" << cardNumber
++ << "Player=" << playerNumber << "Id=" << inputId;
+ if (playerNumber != mCurrentPlayer)
+ {
+ if (global_debug > 0)
- kDebug() << "EngineTwo::playerInput: Input from wrong player";
++ qCDebug(LSKAT_LOG) << "EngineTwo::playerInput: Input from wrong \
player"; + return;
+ }
+ Player *player = mPlayers[playerNumber];
+ int height = 0;
+ int card = player->getCard(cardNumber);
+ // Check whether top card is still available - if not try bottom one
+ if (card < 0)
+ {
+ height = 1;
+ card = player->getCard(cardNumber + 8 * height);
+ }
+ // Check whether player still has this card
+ if (card < 0)
+ {
+ if (global_debug > 0)
- kDebug() << "EngineTwo::playerInput: Card" << cardNumber + 8 * height
- << "not available anymore ";
++ qCDebug(LSKAT_LOG) << "EngineTwo::playerInput: Card" << cardNumber + 8 \
* height ++ << "not available anymore ";
+ return;
+ }
- // Check whether player still has this card
- if (card < 0)
- {
+ // Remove this, Debug current card
if (global_debug > 0)
- qCDebug(LSKAT_LOG) << "EngineTwo::playerInput: Card" << cardNumber + 8*height
- << "not available anymore ";
- return;
- }
-
- // Remove this, Debug current card
- if (global_debug > 0)
- {
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
- qCDebug(LSKAT_LOG) << "Gameloop "<<mCurrentPlayer <<" plays" << \
Deck::name(suite, type);
- }
-
-
-
- // Check for legal move (first player always ok)
- if (mCurrentMovePhase == SecondPlayerTurn)
- {
- // Check (card of player 1), (card of player 2), (player 2)
- if (!isLegalMove(mCurrentMoveCards[FirstPlayerTurn], card, playerNumber))
{
- if (global_debug > 0)
- qCDebug(LSKAT_LOG) << "EngineTwo::playerInput: Card" << cardNumber + \
8*height
- << "is not a valid move ";
- return;
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
- kDebug() << "Gameloop " << mCurrentPlayer << " plays" << Deck::name(suite, \
type); ++ qCDebug(LSKAT_LOG) << "Gameloop " <<mCurrentPlayer <<" plays" << \
Deck::name(suite, type); }
- }
-
- // Delete card from player
- player->deleteCard(cardNumber + 8*height);
-
- // Finish input from player
- player->stopTurn();
+ // Check for legal move (first player always ok)
+ if (mCurrentMovePhase == SecondPlayerTurn)
+ {
+ // Check (card of player 1), (card of player 2), (player 2)
+ if (!isLegalMove(mCurrentMoveCards[FirstPlayerTurn], card, playerNumber))
+ {
+ if (global_debug > 0)
- kDebug() << "EngineTwo::playerInput: Card" << cardNumber + 8 * \
height
- << "is not a valid move ";
++ qCDebug(LSKAT_LOG) << "EngineTwo::playerInput: Card" << cardNumber \
+ 8 * height ++ << "is not a valid move ";
+ return;
+ }
+ }
- // Play out card
- mDisplay->play(card, playerNumber, mCurrentMovePhase);
+ // Delete card from player
+ player->deleteCard(cardNumber + 8 * height);
- // Turn back card if top card is played
- if (height == 0)
- {
- int backcard = player->getCard(cardNumber + 8);
- mCurrentTurnCards[mCurrentMovePhase] = backcard;
- }
- else
- {
- mCurrentTurnCards[mCurrentMovePhase] = -1;
- }
+ // Finish input from player
+ player->stopTurn();
+ // Play out card
+ mDisplay->play(card, playerNumber, mCurrentMovePhase);
- // Store currently played card
- mCurrentMoveCards[mCurrentMovePhase] = card;
+ // Turn back card if top card is played
+ if (height == 0)
+ {
+ int backcard = player->getCard(cardNumber + 8);
+ mCurrentTurnCards[mCurrentMovePhase] = backcard;
+ }
+ else
+ {
+ mCurrentTurnCards[mCurrentMovePhase] = -1;
+ }
- // Finish game loop
- if (mCurrentMovePhase == SecondPlayerTurn)
- {
- QTimer::singleShot(TIME_END_MOVE, this, SLOT(gameLoopFinish()) );
- }
- else
- {
- QTimer::singleShot(0, this, SLOT(gameLoopFinish()) );
- }
+ // Store currently played card
+ mCurrentMoveCards[mCurrentMovePhase] = card;
+ // Finish game loop
+ if (mCurrentMovePhase == SecondPlayerTurn)
+ {
+ QTimer::singleShot(TIME_END_MOVE, this, SLOT(gameLoopFinish()));
+ }
+ else
+ {
+ QTimer::singleShot(0, this, SLOT(gameLoopFinish()));
+ }
}
// Final part of the game loop. Switch player etc.
void EngineTwo::gameLoopFinish()
{
- if (!isGameRunning()) return;
-
- // If second move phase, remove cards
- if (mCurrentMovePhase == SecondPlayerTurn)
- {
- // Turn cards if available
- if (mCurrentTurnCards[FirstPlayerTurn] >= 0)
- mDisplay->turn(mCurrentTurnCards[FirstPlayerTurn]);
- if (mCurrentTurnCards[SecondPlayerTurn] >= 0)
- mDisplay->turn(mCurrentTurnCards[SecondPlayerTurn]);
-
- // Switch the current player if second player one
- int winner = whoWonMove(mCurrentMoveCards[FirstPlayerTurn],
- mCurrentMoveCards[SecondPlayerTurn],
- mTrump);
- // The first mover won. This means to switch the current player back
- // to him. Otherwise the current player stays untouched, that is the
- // second player plays again.
- if (winner == 0)
+ if (!isGameRunning()) return;
+
+ // If second move phase, remove cards
+ if (mCurrentMovePhase == SecondPlayerTurn)
{
- mCurrentPlayer = 1- mCurrentPlayer;
+ // Turn cards if available
+ if (mCurrentTurnCards[FirstPlayerTurn] >= 0)
+ mDisplay->turn(mCurrentTurnCards[FirstPlayerTurn]);
+ if (mCurrentTurnCards[SecondPlayerTurn] >= 0)
+ mDisplay->turn(mCurrentTurnCards[SecondPlayerTurn]);
+
+ // Switch the current player if second player one
+ int winner = whoWonMove(mCurrentMoveCards[FirstPlayerTurn],
+ mCurrentMoveCards[SecondPlayerTurn],
+ mTrump);
+ // The first mover won. This means to switch the current player back
+ // to him. Otherwise the current player stays untouched, that is the
+ // second player plays again.
+ if (winner == 0)
+ {
+ mCurrentPlayer = 1 - mCurrentPlayer;
+ }
+
+ // Move both cards away from play area. Move them to the winning mover's \
side + Player *player = mPlayers[mCurrentPlayer];
+ mDisplay->remove(mCurrentPlayer,
+ mCurrentMoveCards[FirstPlayerTurn],
+ player->noOfMovesWon());
+ mDisplay->remove(mCurrentPlayer,
+ mCurrentMoveCards[SecondPlayerTurn],
+ player->noOfMovesWon() + 1);
+ player->increaseMovesWon();
+ player->addWonCard(mCurrentMoveCards[FirstPlayerTurn]);
+ player->addWonCard(mCurrentMoveCards[SecondPlayerTurn]);
+
+ if (global_debug > 0)
+ {
- kDebug() << "Winner =" << winner << "current =" << mCurrentPlayer;
- kDebug() << " He has won" << player->noOfMovesWon() << "moves.";
- kDebug() << " He has" << player->points() << "points.";
++ qCDebug(LSKAT_LOG) << "Winner = " << winner << "current =" << \
mCurrentPlayer; ++ qCDebug(LSKAT_LOG) << " He has won" << \
player->noOfMovesWon() << "moves."; ++ qCDebug(LSKAT_LOG) << " He has" \
<< player->points() << "points."; + }
+ // Switch move phase (half moves)
+ mCurrentMovePhase = FirstPlayerTurn;
}
-
- // Move both cards away from play area. Move them to the winning mover's side
- Player* player = mPlayers[mCurrentPlayer];
- mDisplay->remove(mCurrentPlayer,
- mCurrentMoveCards[FirstPlayerTurn],
- player->noOfMovesWon());
- mDisplay->remove(mCurrentPlayer,
- mCurrentMoveCards[SecondPlayerTurn],
- player->noOfMovesWon()+1);
- player->increaseMovesWon();
- player->addWonCard(mCurrentMoveCards[FirstPlayerTurn]);
- player->addWonCard(mCurrentMoveCards[SecondPlayerTurn]);
-
- if (global_debug > 0)
+ // For the first part of a half move always swap players
+ else if (mCurrentMovePhase == FirstPlayerTurn)
{
- qCDebug(LSKAT_LOG) << "Winner =" << winner << "current =" << mCurrentPlayer;
- qCDebug(LSKAT_LOG) << " He has won" << player->noOfMovesWon() << "moves.";
- qCDebug(LSKAT_LOG) << " He has" << player->points() << "points.";
+ mCurrentPlayer = 1 - mCurrentPlayer;
+ // Switch move phase (half moves)
+ mCurrentMovePhase = SecondPlayerTurn;
}
- // Switch move phase (half moves)
- mCurrentMovePhase = FirstPlayerTurn;
- }
- // For the first part of a half move always swap players
- else if (mCurrentMovePhase == FirstPlayerTurn)
- {
- mCurrentPlayer = 1- mCurrentPlayer;
- // Switch move phase (half moves)
- mCurrentMovePhase = SecondPlayerTurn;
- }
-
- // Check whether the game is over
- if (gameOver())
- {
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "GAME OVER";
- mGameStatus = Stopped;
- mDisplay->showMove(-1);
- int winner = evaluateGame();
- emit signalGameOver(winner);
- }
- // Game continues
- else
- {
- // Increase move number
- mMoveNumber++;
-
- // Delayed call to game loop start
- QTimer::singleShot(0, this, SLOT(gameLoopStart()) );
- }
- }
+ // Check whether the game is over
+ if (gameOver())
+ {
- if (global_debug > 0) kDebug() << "GAME OVER";
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "GAME OVER";
+ mGameStatus = Stopped;
+ mDisplay->showMove(-1);
+ int winner = evaluateGame();
+ emit signalGameOver(winner);
+ }
+ // Game continues
+ else
+ {
+ // Increase move number
+ mMoveNumber++;
+
+ // Delayed call to game loop start
+ QTimer::singleShot(0, this, SLOT(gameLoopStart()));
+ }
+ }
// Check whether the game is over
bool EngineTwo::gameOver()
{
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Move number in game over" << \
mMoveNumber;
- // Check number of moves. If all moves are done game is over.
- if (mMoveNumber >= 31) return true;
- return false;
- if (global_debug > 0) kDebug() << "Move number in game over" << mMoveNumber;
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Move number in game over" << \
mMoveNumber; + // Check number of moves. If all moves are done game is over.
+ if (mMoveNumber >= 31) return true;
+ return false;
}
-
// Called after game ends..give points to players
int EngineTwo::evaluateGame()
{
@@@ -404,110 -386,108 +386,106 @@@ void EngineTwo::activatePlayer(int play
// plays a legal card)
bool EngineTwo::isLegalMove(int card1, int card2, int playerNumber)
{
- Suite suite1 = Deck::getSuite(card1);
- Suite suite2 = Deck::getSuite(card2);
- CardType type1 = Deck::getCardType(card1);
- CardType type2 = Deck::getCardType(card2);
-
- // Force trump colour as Jacks count as Trump
- if (type1 == Jack) suite1 = mTrump;
- if (type2 == Jack) suite2 = mTrump;
-
- // Same suite is always ok
- if (suite1 == suite2) return true;
-
- // Search if current player has a card of the same colour
- // but didn't play it (if it was played we checked already
- // above)
- Player* p= player(playerNumber);
- bool validMove = true;
- for (int i=0;i<8;i++)
- {
- int card = p->getCard(i);
- // Ignore played card
- if (card == card2) continue;
-
- // Check whether top card is still available - if not try bottom one
- if (card < 0)
- {
- card = p->getCard(i + 8);
- }
- // This card is not available anymore
- if (card < 0) continue;
-
- // Analyze card
- Suite suite = Deck::getSuite(card);
- CardType type = Deck::getCardType(card);
+ Suite suite1 = Deck::getSuite(card1);
+ Suite suite2 = Deck::getSuite(card2);
+ CardType type1 = Deck::getCardType(card1);
+ CardType type2 = Deck::getCardType(card2);
// Force trump colour as Jacks count as Trump
- if (type == Jack) suite = mTrump;
-
- // Check whether current card matches the first player card
- if (suite == suite1)
+ if (type1 == Jack) suite1 = mTrump;
+ if (type2 == Jack) suite2 = mTrump;
+
+ // Same suite is always ok
+ if (suite1 == suite2) return true;
+
+ // Search if current player has a card of the same colour
+ // but didn't play it (if it was played we checked already
+ // above)
+ Player *p = player(playerNumber);
+ bool validMove = true;
+ for (int i = 0; i < 8; i++)
{
- validMove = false;
- break;
+ int card = p->getCard(i);
+ // Ignore played card
+ if (card == card2) continue;
+
+ // Check whether top card is still available - if not try bottom one
+ if (card < 0)
+ {
+ card = p->getCard(i + 8);
+ }
+ // This card is not available anymore
+ if (card < 0) continue;
+
+ // Analyze card
+ Suite suite = Deck::getSuite(card);
+ CardType type = Deck::getCardType(card);
+
+ // Force trump colour as Jacks count as Trump
+ if (type == Jack) suite = mTrump;
+
+ // Check whether current card matches the first player card
+ if (suite == suite1)
+ {
+ validMove = false;
+ break;
+ }
}
- }
- return validMove;
+ return validMove;
}
-
// Check who won a move, the first or the second card.
- // The first card was played first and take precendence
+ // The first card was played first and take precedence
// when possible. The function returns 0 if the first
// card won, 1 if the second card won.
- int EngineTwo::whoWonMove(int card1, int card2, Suite trump)
+ int EngineTwo::whoWonMove(int card1, int card2, Suite trump)
{
- Suite suite1 = Deck::getSuite(card1);
- Suite suite2 = Deck::getSuite(card2);
- CardType type1 = Deck::getCardType(card1);
- CardType type2 = Deck::getCardType(card2);
-
- // Two jacks
- if (type1 == Jack && type2 == Jack)
- {
- if (suite1 < suite2) return 0;
- else return 1;
- }
- // One Jack wins always
- if ((int)type1 == (int)Jack) return 0;
- if ((int)type2 == (int)Jack) return 1;
-
- // Higher card wins if both have same suite
- if (suite1 == suite2)
- {
- // Check Ten because it is not in the right card
- // sequence. Ten is only beaten by Ace
- if (type1 == Ten)
+ Suite suite1 = Deck::getSuite(card1);
+ Suite suite2 = Deck::getSuite(card2);
+ CardType type1 = Deck::getCardType(card1);
+ CardType type2 = Deck::getCardType(card2);
+
+ // Two jacks
+ if (type1 == Jack && type2 == Jack)
{
- if (type2 == Ace) return 1;
- else return 0;
+ if (suite1 < suite2) return 0;
+ else return 1;
}
- if (type2 == Ten)
+ // One Jack wins always
+ if ((int)type1 == (int)Jack) return 0;
+ if ((int)type2 == (int)Jack) return 1;
+
+ // Higher card wins if both have same suite
+ if (suite1 == suite2)
{
- if (type1 == Ace) return 0;
- return 1;
+ // Check Ten because it is not in the right card
+ // sequence. Ten is only beaten by Ace
+ if (type1 == Ten)
+ {
+ if (type2 == Ace) return 1;
+ else return 0;
+ }
+ if (type2 == Ten)
+ {
+ if (type1 == Ace) return 0;
+ return 1;
+ }
+
+ // Otherwise the higher card wins
+ if ((int)card1 < (int)card2) return 0;
+ return 1;
}
- // Otherwise the higher card wins
- if ((int)card1 < (int)card2) return 0;
- return 1;
- }
-
- if (global_debug > 0)
- {
- if (suite1 == trump) qCDebug(LSKAT_LOG) << "FIRST card wins TRUMP";
- if (suite2 == trump) qCDebug(LSKAT_LOG) << "SECOND card wins TRUMP";
- }
+ if (global_debug > 0)
+ {
- if (suite1 == trump) kDebug() << "FIRST card wins TRUMP";
- if (suite2 == trump) kDebug() << "SECOND card wins TRUMP";
++ if (suite1 == trump) qCDebug(LSKAT_LOG) << "FIRST card wins TRUMP";
++ if (suite2 == trump) qCDebug(LSKAT_LOG) << "SECOND card wins TRUMP";
+ }
- // If cards are not of the same suite a trump wins
- if (suite1 == trump) return 0;
- if (suite2 == trump) return 1;
+ // If cards are not of the same suite a trump wins
+ if (suite1 == trump) return 0;
+ if (suite2 == trump) return 1;
- // In all other cases the first card wins
- return 0;
+ // In all other cases the first card wins
+ return 0;
}
--
-
-
-#include "engine_two.moc"
diff --cc src/engine_two.h
index 0afedbf,8501bf6..e71020c
--- a/src/engine_two.h
+++ b/src/engine_two.h
@@@ -20,11 -18,14 +18,13 @@@
Boston, MA 02110-1301, USA.
*/
- // Qt includes
+ #ifndef ENGINE_TWO_H
+ #define ENGINE_TWO_H
+ // Qt includes
-#include <QObject>
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
// Local includes
#include "abstractengine.h"
diff --cc src/fromlibkdegames/cardcache.cpp
index 97104be,4cf57a0..08cadf2
--- a/src/fromlibkdegames/cardcache.cpp
+++ b/src/fromlibkdegames/cardcache.cpp
@@@ -179,58 -178,58 +178,58 @@@ QPixmap doRender(const QString &element
return pix;
}
- QString keyForPixmap( const QString& theme, const QString& element, const QSize& s \
) + QString keyForPixmap(const QString &theme, const QString &element, const QSize \
&s) {
- return theme + QLatin1Char( '_' ) + element + QLatin1Char( '_' )
- + QString::number( s.width() ) + QLatin1Char( '_' )
- + QString::number( s.height() );
+ return theme + QLatin1Char('_') + element + QLatin1Char('_')
+ + QString::number(s.width()) + QLatin1Char('_')
+ + QString::number(s.height());
}
- QSvgRenderer* KCardCachePrivate::renderer()
+ QSvgRenderer *KCardCachePrivate::renderer()
{
- if ( !svgRenderer )
+ if (!svgRenderer)
{
- kDebug() << "Loading front SVG renderer";
+ qCDebug(LSKAT_LOG) << "Loading front SVG renderer";
- svgRenderer = new QSvgRenderer( CardDeckInfo::svgFilePath( deckName ) );
+ svgRenderer = new QSvgRenderer(CardDeckInfo::svgFilePath(deckName));
}
return svgRenderer;
}
- void KCardCachePrivate::ensureNonNullPixmap( QPixmap& pix )
+ void KCardCachePrivate::ensureNonNullPixmap(QPixmap &pix)
{
- if( pix.isNull() )
+ if (pix.isNull())
{
- qCWarning(LSKAT_LOG) << "Couldn't produce a non-null pixmap, creating a red \
cross";
- pix = QPixmap( size );
- kWarning() << "Couldn't produce a non-null pixmap, creating a red cross";
++ qCWarning(LSKAT_LOG) << "Could not produce a non-null pixmap, creating a \
red cross"; + pix = QPixmap(size);
QPainter p(&pix);
- p.fillRect( QRect( 0,0, pix.width(), pix.height() ), QBrush( Qt::white ) );
+ p.fillRect(QRect(0, 0, pix.width(), pix.height()), QBrush(Qt::white));
QPen pen = p.pen();
- pen.setWidth( 4 );
- pen.setColor( QColor( Qt::red ) );
- p.setPen( pen );
- p.drawLine( QPoint( 2,2 ), QPoint( pix.width()-2, pix.height()-2 ) );
- p.drawLine( QPoint( pix.width()-2,2 ), QPoint( 2, pix.height()-2 ) );
+ pen.setWidth(4);
+ pen.setColor(QColor(Qt::red));
+ p.setPen(pen);
+ p.drawLine(QPoint(2, 2), QPoint(pix.width()-2, pix.height()-2));
+ p.drawLine(QPoint(pix.width()-2, 2), QPoint(2, pix.height()-2));
p.end();
}
}
- QPixmap KCardCachePrivate::renderSvg( const QString& element )
+ QPixmap KCardCachePrivate::renderSvg(const QString &element)
{
- qCDebug(LSKAT_LOG) << "Renderering" << element << "in main thread.";
- QMutexLocker l( rendererMutex );
- return doRender( element, renderer(), size );
- kDebug() << "Rendering" << element << "in main thread.";
++ qCDebug(LSKAT_LOG) << "Rendering" << element << "in main thread.";
+ QMutexLocker l(rendererMutex);
+ return doRender(element, renderer(), size);
}
- void KCardCachePrivate::submitRendering( const QString& key, const QImage& image )
+ void KCardCachePrivate::submitRendering(const QString &key, const QImage &image)
{
- kDebug() << "Received render of" << key << "from rendering thread.";
+ qCDebug(LSKAT_LOG) << "Received render of" << key << "from rendering thread.";
- QPixmap pix = QPixmap::fromImage( image );
- QMutexLocker l( cacheMutex );
- cache->insert( key, pix );
+ QPixmap pix = QPixmap::fromImage(image);
+ QMutexLocker l(cacheMutex);
+ cache->insert(key, pix);
}
- LoadThread::LoadThread( KCardCachePrivate* d_ )
- : d( d_ ), doKill( false ), killMutex( new QMutex )
+ LoadThread::LoadThread(KCardCachePrivate *d_)
+ : d(d_), doKill(false), killMutex(new QMutex)
{
}
@@@ -360,25 -359,22 +359,25 @@@ QSize KCardCache::size() cons
return d->size;
}
- void KCardCache::setDeckName( const QString& theme )
+ void KCardCache::setDeckName(const QString &theme)
{
{
- QMutexLocker l( d->cacheMutex );
+ QMutexLocker l(d->cacheMutex);
delete d->cache;
- d->cache = new KPixmapCache( QString::fromLatin1( "kdegames-cards_%1" \
).arg( theme ) );
- d->cache->setUseQPixmapCache( true );
- QDateTime dt = QFileInfo( CardDeckInfo::svgFilePath( theme ) \
).lastModified(); + d->cache = new \
KPixmapCache(QString::fromLatin1("kdegames-cards_%1").arg(theme)); + \
d->cache->setUseQPixmapCache(true); + QDateTime dt = \
QFileInfo(CardDeckInfo::svgFilePath(theme)).lastModified(); +//PORT QT5
+#if 0
- if( d->cache->timestamp() < dt.toTime_t() )
+ if (d->cache->timestamp() < dt.toTime_t())
{
d->cache->discard();
- d->cache->setTimestamp( dt.toTime_t() );
+ d->cache->setTimestamp(dt.toTime_t());
}
+#endif
}
{
- QMutexLocker l( d->rendererMutex );
+ QMutexLocker l(d->rendererMutex);
delete d->svgRenderer;
d->svgRenderer = 0;
}
@@@ -492,9 -488,9 +491,7 @@@ QSizeF KCardCache::defaultBackSize() co
void KCardCache::invalidateCache()
{
- QMutexLocker l( d->cacheMutex );
- if( d->cache )
+ QMutexLocker l(d->cacheMutex);
+ if (d->cache)
d->cache->discard();
}
--
-
-#include "cardcache_p.moc"
diff --cc src/fromlibkdegames/cardcache.h
index e1f9b9d,d2cccad..2200b4f
--- a/src/fromlibkdegames/cardcache.h
+++ b/src/fromlibkdegames/cardcache.h
@@@ -18,11 -17,11 +17,11 @@@
Boston, MA 02110-1301, USA.
*/
- #ifndef __CARDCACHE_H_
- #define __CARDCACHE_H_
+ #ifndef CARDCACHE_H
+ #define CARDCACHE_H
#include "libkdegames_export.h"
-
+#include <QObject>
class QPixmap;
class QString;
class QSize;
diff --cc src/fromlibkdegames/carddeckinfo.cpp
index bfd2556,45270ea..af003db
--- a/src/fromlibkdegames/carddeckinfo.cpp
+++ b/src/fromlibkdegames/carddeckinfo.cpp
@@@ -41,7 -41,8 +41,7 @@@ class KCardThemeInfoStati
public:
KCardThemeInfoStatic()
{
- KGlobal::dirs()->addResourceType( "cards", "data", "carddecks/" );
+ KGlobal::dirs()->addResourceType("cards", "data", "carddecks/");
- KGlobal::locale()->insertCatalog(QLatin1String("libkdegames"));
readDecks();
}
~KCardThemeInfoStatic()
@@@ -74,17 -75,17 +74,18 @@@
KCardThemeInfo info;
info.name = name;
info.noi18Name = idx;
- info.comment = cfgcg.readEntry( "Comment", QString() );
+ info.comment = cfgcg.readEntry("Comment", QString());
info.preview = pixmap;
info.path = path;
- info.back = cfgcg.readEntry( "Back", QString() );
++
+ info.back = cfgcg.readEntry("Back", QString());
- // if (!info.back.isNull()) kDebug() << "FOUND BACK " << info.back;
+ // if (!info.back.isNull()) qCDebug(LSKAT_LOG) << "FOUND BACK " << \
info.back;
- info.isDefault = cfgcg.readEntry( "Default", false );
+ info.isDefault = cfgcg.readEntry("Default", false);
- QString svg = cfgcg.readEntry( "SVG", QString() );
- if ( !svg.isEmpty() )
+ QString svg = cfgcg.readEntry("SVG", QString());
+ if (!svg.isEmpty())
{
- QFileInfo svgInfo( QDir( path ), svg );
+ QFileInfo svgInfo(QDir(path), svg);
info.svgfile = svgInfo.filePath();
themeNameMap[idx] = info;
}
@@@ -133,7 -131,7 +131,7 @@@ QString defaultDeckName(
// Collect any deck if no default is stored
noDefault = v.noi18Name;
}
- if ( noDefault.isNull() ) qCCritical(LSKAT_LOG) << "Could not find default card \
name";
- if (noDefault.isNull()) kError() << "Could not find default card name";
++ if (noDefault.isNull()) qCCritical(LSKAT_LOG) << "Could not find default card \
name"; return noDefault;
}
diff --cc src/fromlibkdegames/carddeckinfo_p.h
index b0e1f9f,c9c307a..84f462c
--- a/src/fromlibkdegames/carddeckinfo_p.h
+++ b/src/fromlibkdegames/carddeckinfo_p.h
@@@ -17,13 -17,14 +17,12 @@@
Boston, MA 02110-1301, USA.
*/
- #ifndef __CARDDECKINFO_P_H_
- #define __CARDDECKINFO_P_H_
+ #ifndef CARDDECKINFO_P_H
+ #define CARDDECKINFO_P_H
-#include <QMap>
#include <QString>
#include <QPixmap>
-#include <QSize>
-
/**
* Stores the information for one card front or back side.
*/
diff --cc src/fromlibkdegames/kcarddialog.cpp
index be20e96,e23ef8e..45077e6
--- a/src/fromlibkdegames/kcarddialog.cpp
+++ b/src/fromlibkdegames/kcarddialog.cpp
@@@ -80,18 -82,17 +80,17 @@@ void KCardWidget::saveSettings(KConfigG
// Setup the user interface
void KCardWidget::setupGUI()
{
- // Inner widget
- Ui::KGameCardSelectorBase* ui = &(d->ui);
- d->ui.setupUi(this);
+ // Inner widget
+ Ui::KGameCardSelectorBase *ui = &(d->ui);
+ d->ui.setupUi(this);
- // Set lists and preview
- insertCardIcons();
+ // Set lists and preview
+ insertCardIcons();
- // Connect signals
- connect(ui->list, &QListWidget::itemSelectionChanged, this, \
&KCardWidget::updateSelection);
- }
+
+ // Connect signals
- connect(ui->list, SIGNAL(itemSelectionChanged()),
- this, SLOT(updateSelection()));
++ connect(ui->list, &QListWidget::itemSelectionChanged, this, \
&KCardWidget::updateSelection); + }
// Destroy the dialog
KCardWidget::~KCardWidget()
@@@ -149,57 -149,54 +147,52 @@@ void KCardWidget::updateSelection(
setDeckName(l.first()->data(Qt::UserRole).toString());
}
-
// Update front preview
-
- void KCardWidget::setDeckName(const QString& name)
+ void KCardWidget::setDeckName(const QString &name)
{
- // Clear item?
- if (name.isEmpty())
- {
- QList<QListWidgetItem*> items = d->ui.list->selectedItems();
- if(!items.isEmpty())
- items.first()->setSelected(false);
- d->ui.previewImage->setPixmap(QPixmap());
- d->ui.cardName->setText(QString());
- d->ui.cardDescription->setText(QString());
- }
- else
- {
- for (int i = 0; i < d->ui.list->count(); ++i)
+ // Clear item?
+ if (name.isEmpty())
{
- QListWidgetItem *item = d->ui.list->item(i);
- if (item->data(Qt::UserRole).toString() == name)
- {
- item->setSelected(true);
- d->ui.list->scrollToItem(item);
- break;
- }
+ QList<QListWidgetItem *> items = d->ui.list->selectedItems();
+ if (!items.isEmpty())
+ items.first()->setSelected(false);
+ d->ui.previewImage->setPixmap(QPixmap());
+ d->ui.cardName->setText(QString());
+ d->ui.cardDescription->setText(QString());
}
-
- KCardThemeInfo info = CardDeckInfo::deckInfo(name);
- QFont font;
- font.setBold(true);
- d->ui.cardName->setText(info.name);
- d->ui.cardName->setFont(font);
-
- d->ui.cardDescription->setText(info.comment);
- QPixmap pixmap= info.preview;
- if (pixmap.height() > d->ui.previewImage->height())
- pixmap = pixmap.scaledToHeight(d->ui.previewImage->height(), \
Qt::SmoothTransformation);
- if (pixmap.width() > d->ui.previewImage->width())
- pixmap = pixmap.scaledToWidth(d->ui.previewImage->width(), \
Qt::SmoothTransformation);
- d->ui.previewImage->setPixmap(pixmap);
- }
- d->currentDeck = name;
+ else
+ {
+ for (int i = 0; i < d->ui.list->count(); ++i)
+ {
+ QListWidgetItem *item = d->ui.list->item(i);
+ if (item->data(Qt::UserRole).toString() == name)
+ {
+ item->setSelected(true);
+ d->ui.list->scrollToItem(item);
+ break;
+ }
+ }
+
+ KCardThemeInfo info = CardDeckInfo::deckInfo(name);
+ QFont font;
+ font.setBold(true);
+ d->ui.cardName->setText(info.name);
+ d->ui.cardName->setFont(font);
+
+ d->ui.cardDescription->setText(info.comment);
+ QPixmap pixmap= info.preview;
+ if (pixmap.height() > d->ui.previewImage->height())
+ pixmap = pixmap.scaledToHeight(d->ui.previewImage->height(), \
Qt::SmoothTransformation); + if (pixmap.width() > \
d->ui.previewImage->width()) + pixmap = \
pixmap.scaledToWidth(d->ui.previewImage->width(), Qt::SmoothTransformation); + \
d->ui.previewImage->setPixmap(pixmap); + }
+ d->currentDeck = name;
}
-
- KCardDialog::KCardDialog( KCardWidget* widget )
+ KCardDialog::KCardDialog(KCardWidget *widget)
{
- setMainWidget(widget);
- setCaption(i18n("Card Deck Selection"));
- setButtons(KDialog::Ok | KDialog::Cancel);
+ setMainWidget(widget);
+ setCaption(i18n("Card Deck Selection"));
+ setButtons(KDialog::Ok | KDialog::Cancel);
}
--
-
-#include "kcarddialog.moc"
diff --cc src/fromlibkdegames/kcarddialog.h
index 155f658,6203ce7..6b5d0dc
--- a/src/fromlibkdegames/kcarddialog.h
+++ b/src/fromlibkdegames/kcarddialog.h
@@@ -36,11 -39,11 +38,11 @@@ class KCardWidget
*
* Usage Example:
* \code
- * KConfigGroup(KGlobal::config(), "CardOptions");
+ * KConfigGroup(KSharedConfig::openConfig(),"CardOptions");
- * KCardWidget* cardwiget = new KCardwidget();
+ * KCardWidget *cardwiget = new KCardwidget();
* cardwidget->readSettings(configGroup);
* KCardDialog dlg(cardwidget);
- * if(dlg.exec() == QDialog::Accepted)
+ * if (dlg.exec() == QDialog::Accepted)
* {
* cardwidget->saveSettings(configGroup);
* configGroup.sync();
diff --cc src/gameview.cpp
index c77d2ef,94f410f..fd889b9
--- a/src/gameview.cpp
+++ b/src/gameview.cpp
@@@ -36,57 -39,54 +36,55 @@@
#include "thememanager.h"
#include "lskatglobal.h"
-
// Constructor for the view
- GameView::GameView(const QSize &size, int advancePeriod, QGraphicsScene* scene, \
ThemeManager* theme, QWidget* parent) + GameView::GameView(const QSize &size, int \
advancePeriod, QGraphicsScene *scene, ThemeManager *theme, QWidget *parent) : \
QGraphicsView(scene, parent) {
- // Store attributes
- mTheme = theme;
-
- // We do not need scrolling so switch it off
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
- // Frame off
- setFrameStyle(QFrame::NoFrame);
-
- // Cache on
- setCacheMode(QGraphicsView::CacheBackground);
- setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
- setOptimizationFlags(QGraphicsView::DontClipPainter |
- QGraphicsView::DontSavePainterState |
- QGraphicsView::DontAdjustForAntialiasing );
-
- // Debug
- mDisplayUpdateTime = 0;
- mFrameSprite = new QGraphicsTextItem(0);
- scene->addItem(mFrameSprite);
- mFrameSprite->setPos(QPointF(0.0, 0.0));
- mFrameSprite->setZValue(1000.0);
- if (global_debug > 0) mFrameSprite->show();
- else mFrameSprite->hide();
-
-
- // Update/advance in [ms]
- QTimer *timer = new QTimer(this);
- connect(timer, &QTimer::timeout, this, &GameView::updateAndAdvance);
- timer->start(advancePeriod);
-
- // Set size and position of the view and the canvas:
- // they are reseized once a level is loaded
- resize(size);
- scene->setSceneRect(0, 0, this->width(), this->height());
- adjustSize();
-
- // Enable mouse
- setInteractive(true);
-
- // Scale theme
- //mTheme->rescale(this->width());
- mThemeQueue.clear();
- mThemeOffset.clear();
- mTimeStart.start();
+ // Store attributes
+ mTheme = theme;
+
+ // We do not need scrolling so switch it off
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ // Frame off
+ setFrameStyle(QFrame::NoFrame);
+
+ // Cache on
+ setCacheMode(QGraphicsView::CacheBackground);
+ setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+ setOptimizationFlags(QGraphicsView::DontClipPainter |
+ QGraphicsView::DontSavePainterState |
+ QGraphicsView::DontAdjustForAntialiasing);
+
+ // Debug
+ mDisplayUpdateTime = 0;
- mFrameSprite = new QGraphicsTextItem(0, scene);
++ mFrameSprite = new QGraphicsTextItem(0);
++ scene->addItem(mFrameSprite);
+ mFrameSprite->setPos(QPointF(0.0, 0.0));
+ mFrameSprite->setZValue(1000.0);
+ if (global_debug > 0) mFrameSprite->show();
+ else mFrameSprite->hide();
+
+ // Update/advance in [ms]
+ QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(updateAndAdvance()));
++ connect(timer, &QTimer::timeout, this, &GameView::updateAndAdvance);
+ timer->start(advancePeriod);
+
+ // Set size and position of the view and the canvas:
+ // they are resized once a level is loaded
+ resize(size);
+ scene->setSceneRect(0, 0, this->width(), this->height());
+ adjustSize();
+
+ // Enable mouse
+ setInteractive(true);
+
+ // Scale theme
+ //mTheme->rescale(this->width());
+ mThemeQueue.clear();
+ mThemeOffset.clear();
+ mTimeStart.start();
}
GameView::~GameView()
@@@ -97,120 -97,114 +95,114 @@@
// Advance and update canvas
void GameView::updateAndAdvance()
{
- static int elapsed = -1;
- static QTime timer;
- if (elapsed < 0 )
- {
- timer.start();
- elapsed = 0;
- }
- else
- {
- elapsed = timer.elapsed();
- timer.start();
- mDisplayUpdateTime = elapsed;
- }
-
- scene()->advance();
- //NOTE regarding QGV porting
- //QGV will handle dirty rects for us
- //Calling update will just dirty the view and cause a full redraw, killing \
performance
- //scene()->update();
+ static int elapsed = -1;
+ static QTime timer;
+ if (elapsed < 0)
+ {
+ timer.start();
+ elapsed = 0;
+ }
+ else
+ {
+ elapsed = timer.elapsed();
+ timer.start();
+ mDisplayUpdateTime = elapsed;
+ }
+
+ scene()->advance();
+ //NOTE regarding QGV porting
+ //QGV will handle dirty rects for us
+ //Calling update will just dirty the view and cause a full redraw, killing \
performance + //scene()->update();
}
-
- // Slot called by the framework when the window is
- // resized.
- void GameView::resizeEvent(QResizeEvent* e)
+ // Slot called by the framework when the window is resized.
+ void GameView::resizeEvent(QResizeEvent *e)
{
- QTime t;
- t.start();
- if (global_debug > 2) qCDebug(LSKAT_LOG) <<"RESIZE EVENT" << e->size() << \
"oldSize="<< e->oldSize() <<" at" << t.msecsTo(mTimeStart);
- double diffW = double(e->oldSize().width()-e->size().width());
- double diffH = double(e->oldSize().height()-e->size().height());
- double delta = fabs(diffW) + fabs(diffH);
-
- // Adapt the canvas size to the window size
- if (scene())
- {
- scene()->setSceneRect(0,0, e->size().width(), e->size().height());
- }
-
-
- QSizeF size = QSizeF(e->size());
- // Rescale on minimum fitting aspect ratio either width or height limiting
- double aspect = size.width() / size.height();
- QPoint offset;
- double width = 0.0;
-
- // Scale width:
- // Ideal size would be: 'width'*'height'
- // Offset in width is (e->size().width()-width)/2, offset in height is zero
- if (aspect > mTheme->aspectRatio())
- {
- width = e->size().height()*mTheme->aspectRatio();
- offset = QPoint(int((e->size().width()-width)/2.0), 0);
- }
- // Scale height:
- // 'height' = width/mTheme->aspectRatio()
- // Ideal size would be: 'width'*'height':
- // Offset in height is (e->size().height()-width/mTheme->aspectRatio())/2, offset \
in width is zero
- else
- {
- width = e->size().width();
- offset = QPoint(0, int((e->size().height()-width/mTheme->aspectRatio())/2.0));
- }
-
- // Pixel rescale
- double oldScale = mTheme->getScale();
- resetTransform();
- if (width > oldScale)
- {
- scale(double(width/oldScale), double(width/oldScale));
- }
- mThemeQueue.prepend(int(width));
- mThemeOffset.prepend(offset);
- if (global_debug > 2) qCDebug(LSKAT_LOG) << "Quequed resize, aspect=" << aspect \
<< "theme aspect="<< mTheme->aspectRatio();
-
- long queueDelay = 0;
- if (delta < 15) queueDelay = 750;
- else if (delta < 35) queueDelay = 500;
-
- QTimer::singleShot(queueDelay, this, SLOT(rescaleTheme()) );
+ QTime t;
+ t.start();
- if (global_debug > 2) kDebug() << "RESIZE EVENT" << e->size() << "oldSize=" << \
e->oldSize() << " at" << t.msecsTo(mTimeStart); ++ if (global_debug > 2) \
qCDebug(LSKAT_LOG) << "RESIZE EVENT " << e->size() << " oldSize="<< e->oldSize() << " \
at " << t.msecsTo(mTimeStart); + double diffW = double(e->oldSize().width() - \
e->size().width()); + double diffH = double(e->oldSize().height() - \
e->size().height()); + double delta = fabs(diffW) + fabs(diffH);
+
+ // Adapt the canvas size to the window size
+ if (scene())
+ {
+ scene()->setSceneRect(0, 0, e->size().width(), e->size().height());
+ }
+
+ QSizeF size = QSizeF(e->size());
+ // Rescale on minimum fitting aspect ratio either width or height limiting
+ double aspect = size.width() / size.height();
+ QPoint offset;
+ double width = 0.0;
+
+ // Scale width:
+ // Ideal size would be: 'width'*'height'
+ // Offset in width is (e->size().width() - width) / 2, offset in height is zero
+ if (aspect > mTheme->aspectRatio())
+ {
+ width = e->size().height() * mTheme->aspectRatio();
+ offset = QPoint(int((e->size().width() - width) / 2.0), 0);
+ }
+ // Scale height:
+ // 'height' = width / mTheme->aspectRatio()
+ // Ideal size would be: 'width'*'height':
+ // Offset in height is (e->size().height() - width / mTheme->aspectRatio()) / \
2, offset in width is zero + else
+ {
+ width = e->size().width();
+ offset = QPoint(0, int((e->size().height() - width / mTheme->aspectRatio()) \
/ 2.0)); + }
+
+ // Pixel rescale
+ double oldScale = mTheme->getScale();
+ resetTransform();
+ if (width > oldScale)
+ {
+ scale(double(width / oldScale), double(width / oldScale));
+ }
+ mThemeQueue.prepend(int(width));
+ mThemeOffset.prepend(offset);
- if (global_debug > 2) kDebug() << "Quequed resize, aspect=" << aspect << "theme \
aspect=" << mTheme->aspectRatio(); ++ if (global_debug > 2) qCDebug(LSKAT_LOG) << \
"Queued resize, aspect=" << aspect << " theme aspect=" << mTheme->aspectRatio(); +
+ long queueDelay = 0;
+ if (delta < 15) queueDelay = 750;
+ else if (delta < 35) queueDelay = 500;
+
+ QTimer::singleShot(queueDelay, this, SLOT(rescaleTheme()));
}
// Rescale the theme (update theme SVG graphics) from the theme list
void GameView::rescaleTheme()
{
- if (mThemeQueue.size() == 0)
- {
- if (global_debug > 2) qCDebug(LSKAT_LOG) << "***************** Swallowing \
rescale event ***********************";
- return;
- }
-
- QTime t;
- t.start();
-
- if (global_debug > 2) qCDebug(LSKAT_LOG) << "Theme queue rescale start at" << \
t.msecsTo(mTimeStart);
- resetTransform();
- int width = mThemeQueue.first();
- mInputOffset = mThemeOffset.first();
- if (global_debug > 2) qCDebug(LSKAT_LOG) << "Theme queue size=" << \
mThemeQueue.size() << "Rescale width to" << width;
-
- mThemeQueue.clear();
- mThemeOffset.clear();
- mTheme->rescale(width, mInputOffset);
-
- if (global_debug > 2) qCDebug(LSKAT_LOG) << "Time elapsed: "<< t.elapsed() << \
"ms"; + if (mThemeQueue.size() == 0)
+ {
- if (global_debug > 2) kDebug() << "***************** Swallowing rescale \
event ***********************"; ++ if (global_debug > 2) qCDebug(LSKAT_LOG) << \
"***************** Swallowing rescale event ***********************"; + \
return; + }
+
+ QTime t;
+ t.start();
+
- if (global_debug > 2) kDebug() << "Theme queue rescale start at" << \
t.msecsTo(mTimeStart); ++ if (global_debug > 2) qCDebug(LSKAT_LOG) << "Theme queue \
rescale start at " << t.msecsTo(mTimeStart); + resetTransform();
+ int width = mThemeQueue.first();
+ mInputOffset = mThemeOffset.first();
- if (global_debug > 2) kDebug() << "Theme queue size=" << mThemeQueue.size() << \
"Rescale width to" << width; ++ if (global_debug > 2) qCDebug(LSKAT_LOG) << "Theme \
queue size=" << mThemeQueue.size() << " Rescale width to " << width; +
+ mThemeQueue.clear();
+ mThemeOffset.clear();
+ mTheme->rescale(width, mInputOffset);
+
- if (global_debug > 2) kDebug() << "Time elapsed: " << t.elapsed() << "ms";
++ if (global_debug > 2) qCDebug(LSKAT_LOG) << "Time elapsed: " << t.elapsed() << \
"ms"; }
-
// Our subclassed (temporary) QGraphicsView paintEvent, see header file
- void GameView::paintEvent(QPaintEvent* event)
+ void GameView::paintEvent(QPaintEvent *event)
{
- QPaintEvent* newEvent = new QPaintEvent(event->region().boundingRect());
+ QPaintEvent *newEvent = new QPaintEvent(event->region().boundingRect());
QGraphicsView::paintEvent(newEvent);
delete newEvent;
}
@@@ -218,31 -212,28 +210,26 @@@
// Mouse click event
void GameView::mouseReleaseEvent(QMouseEvent *ev)
{
- if (ev->button() != Qt::LeftButton) return ;
+ if (ev->button() != Qt::LeftButton) return;
- QPointF point = ev->pos()-mInputOffset;
- emit signalLeftMousePress(point.toPoint());
+ QPointF point = ev->pos()-mInputOffset;
+ emit signalLeftMousePress(point.toPoint());
}
- void GameView::drawItems(QPainter* painter, int numItems, QGraphicsItem* items[], \
const QStyleOptionGraphicsItem options[]) + void GameView::drawItems(QPainter \
*painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem \
options[]) {
- QTime time;
- time.start();
- QGraphicsView::drawItems(painter, numItems, items, options);
-
- // Time display
- int elapsed = time.elapsed();
- mDrawTimes.append(elapsed);
- if (mDrawTimes.size() > 50) mDrawTimes.removeFirst();
- double avg = 0.0;
- for (int i=0; i<mDrawTimes.size(); i++) avg += mDrawTimes[i];
- avg /= mDrawTimes.size();
-
-
- if (global_debug > 0)
- mFrameSprite->setPlainText(QString::fromLatin1( "Draw: %1 ms Average %2 ms \
Update: %3 ms").arg(elapsed).arg(int(avg)).arg(mDisplayUpdateTime));
-
+ QTime time;
+ time.start();
+ QGraphicsView::drawItems(painter, numItems, items, options);
+
+ // Time display
+ int elapsed = time.elapsed();
+ mDrawTimes.append(elapsed);
+ if (mDrawTimes.size() > 50) mDrawTimes.removeFirst();
+ double avg = 0.0;
+ for (int i = 0; i < mDrawTimes.size(); i++) avg += mDrawTimes[i];
+ avg /= mDrawTimes.size();
+
+ if (global_debug > 0)
+ mFrameSprite->setPlainText(QString::fromLatin1("Draw: %1 ms Average %2 ms \
Update: %3 ms").arg(elapsed).arg(int(avg)).arg(mDisplayUpdateTime)); }
--
-
-#include "gameview.moc"
diff --cc src/lskat_debug.cpp
index c522565,0000000..9f753f3
mode 100644,000000..100644
--- a/src/lskat_debug.cpp
+++ b/src/lskat_debug.cpp
@@@ -1,23 -1,0 +1,21 @@@
+/* This file is part of the KDE project
+ Copyright (C) 2014 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "lskat_debug.h"
+Q_LOGGING_CATEGORY(LSKAT_LOG, "log_lskat")
-
-
diff --cc src/lskat_debug.h
index ec11ade,0000000..a05bb8a
mode 100644,000000..100644
--- a/src/lskat_debug.h
+++ b/src/lskat_debug.h
@@@ -1,27 -1,0 +1,26 @@@
+/* This file is part of the KDE project
+ Copyright (C) 2014 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef LSKAT_DEBUG_H
+#define LSKAT_DEBUG_H
+
+#include <QLoggingCategory>
+Q_DECLARE_LOGGING_CATEGORY(LSKAT_LOG)
+
- #endif
-
++#endif
diff --cc src/main.cpp
index 4e0b602,c2f6ac0..d70d1fe
--- a/src/main.cpp
+++ b/src/main.cpp
@@@ -63,72 -60,65 +61,71 @@@ bool global_skip_intro = false
// Demo (autoplay mode)
bool global_demo_mode = false;
-
int main(int argc, char *argv[])
{
- global_debug=0;
- K4AboutData aboutData( "lskat", 0, ki18n("LSkat"),
- LSKAT_VERSION,
- ki18n("LSkat: A desktop card game"),
- K4AboutData::License_GPL,
- ki18n("(c) 1995-2007, Martin Heni"),
- KLocalizedString(),
- "http://games.kde.org/lskat" );
- // I18N: These are the same strings than in kwin4, you can copy the translations
- aboutData.addAuthor(ki18n("Martin Heni"),ki18n("Game design and code"), \
"kde@heni-online.de");
- aboutData.addAuthor(ki18n("Eugene Trounev"),ki18n("Graphics"), \
"eugene.trounev@gmail.com");
- // end I18N
- aboutData.addAuthor(ki18n("Benjamin Meyer"), ki18n("Code Improvements"));
- // 'Thanks to' aboutData.addCredit(ki18n("KDE"), ki18n("KDE"));
- KCmdLineArgs::init( argc, argv, &aboutData );
-
- KCmdLineOptions options;
- options.add("d");
- options.add("debug <level>", ki18n("Enter debug level"));
- options.add("skipintro", ki18n("Skip intro animation"));
- options.add("demo", ki18n("Run game in demo (autoplay) mode"));
- KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
-
- /* command line handling */
- KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
-
- KCrash::initialize();
-
- // Check for debug command line option
- if (args->isSet("debug"))
- {
- global_debug=QString(args->getOption("debug")).toInt();
- kDebug(12010) << "Debug level set to" << global_debug;
- }
- // Check for debug command line option
- if (args->isSet("skipintro"))
- {
- global_skip_intro = true;
- kDebug(12010) << "Skip intro cmd line chosen" << global_skip_intro;
- }
- // Check for debug command line option
- if (args->isSet("demo"))
- {
- global_demo_mode = true;
- kDebug(12010) << "Running in demo mode" << global_demo_mode;
- }
- args->clear();
- KApplication application(true);
-
- KLocalizedString::setApplicationDomain("lskat");
-
- if (application.isSessionRestored())
- {
- RESTORE(Mainwindow);
- }
- else
- {
- Mainwindow *mainwindow = new Mainwindow();
- mainwindow->show();
- }
-
- application.setWindowIcon(QIcon::fromTheme(QStringLiteral("lskat")));
-
- return application.exec();
+ global_debug = 0;
- KAboutData aboutData("lskat", 0, ki18n("LSkat"),
- LSKAT_VERSION,
- ki18n("LSkat: A desktop card game"),
- KAboutData::License_GPL,
- ki18n("(c) 1995-2007, Martin Heni"),
- KLocalizedString(),
- "https://games.kde.org/game.php?game=lskat");
++ K4AboutData aboutData("lskat", 0, ki18n("LSkat"),
++ LSKAT_VERSION,
++ ki18n("LSkat: A desktop card game"),
++ K4AboutData::License_GPL,
++ ki18n("(c) 1995-2007, Martin Heni"),
++ KLocalizedString(),
++ "https://games.kde.org/game.php?game=lskat");
++
+ // I18N: These are the same strings as in kwin4, you can copy the translations
+ aboutData.addAuthor(ki18n("Martin Heni"), ki18n("Game design and code"), \
"kde@heni-online.de"); + aboutData.addAuthor(ki18n("Eugene Trounev"), \
ki18n("Graphics"), "eugene.trounev@gmail.com"); + // end I18N
+ aboutData.addAuthor(ki18n("Benjamin Meyer"), ki18n("Code Improvements"));
+ // 'Thanks to' aboutData.addCredit(ki18n("KDE"), ki18n("KDE"));
+ KCmdLineArgs::init(argc, argv, &aboutData);
+
+ KCmdLineOptions options;
+ options.add("d");
+ options.add("debug <level>", ki18n("Enter debug level"));
+ options.add("skipintro", ki18n("Skip intro animation"));
+ options.add("demo", ki18n("Run game in demo (autoplay) mode"));
+ KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
+
+ /* command line handling */
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
++ KCrash::initialize();
++
+ // Check for debug command line option
+ if (args->isSet("debug"))
+ {
+ global_debug = QString(args->getOption("debug")).toInt();
+ kDebug(12010) << "Debug level set to" << global_debug;
+ }
+ // Check for debug command line option
+ if (args->isSet("skipintro"))
+ {
+ global_skip_intro = true;
+ kDebug(12010) << "Skip intro cmd line chosen" << global_skip_intro;
+ }
+ // Check for debug command line option
+ if (args->isSet("demo"))
+ {
+ global_demo_mode = true;
+ kDebug(12010) << "Running in demo mode" << global_demo_mode;
+ }
+ args->clear();
+ KApplication application(true);
- KGlobal::locale()->insertCatalog(QLatin1String("libkdegames"));
++
++ KLocalizedString::setApplicationDomain("lskat");
+
+ if (application.isSessionRestored())
+ {
+ RESTORE(Mainwindow);
+ }
+ else
+ {
+ Mainwindow *mainwindow = new Mainwindow();
+ mainwindow->show();
+ }
+
++ application.setWindowIcon(QIcon::fromTheme(QStringLiteral("lskat")));
++
+ return application.exec();
}
-
diff --cc src/mainwindow.cpp
index 3f9ab57,502a6c8..b2c6d6f
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@@ -21,16 -21,19 +21,16 @@@
#include "mainwindow.h"
// Include files for Qt
--
-#include <QDir>
-#include <QFile>
++#include <QAction>
+ #include <QPointer>
// Include files for KDE
#include <kstandardgameaction.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#include <khelpmenu.h>
-#include <kdebug.h>
+#include "lskat_debug.h"
#include <kstandardaction.h>
- #include <QAction>
-#include <kaction.h>
#include <kactioncollection.h>
#include <kstatusbar.h>
#include <kstandarddirs.h>
@@@ -69,123 -73,120 +69,120 @@@ const int ADVANCE_PERIOD = 20
using namespace InputDevice;
-
// Construct the main application window
- Mainwindow::Mainwindow(QWidget* parent)
+ Mainwindow::Mainwindow(QWidget *parent)
: KXmlGuiWindow(parent)
{
- // Reset stuff
- mDeck = 0;
- mEngine = 0;
- mDisplay = 0;
- mView = 0;
- mLSkatConfig = 0;
- mCanvas = 0;
- mTheme = 0;
-
- // Add resource type to grafix
- KGlobal::dirs()->addResourceType("lskattheme", "appdata", "grafix/");
-
- #ifndef NDEBUG
- #ifdef SRC_DIR
- qCDebug(LSKAT_LOG) << "Found SRC_DIR =" << SRC_DIR;
- KGlobal::dirs()->addResourceDir("lskattheme",QLatin1String( \
SRC_DIR)+QString("/grafix/"));
- #endif
- #endif
-
- // Read theme files
- QStringList themeList = KGlobal::dirs()->findAllResources("lskattheme", \
QLatin1String( "*.desktop" ), KStandardDirs::NoDuplicates);
- if (themeList.isEmpty())
- {
- KMessageBox::error(this, i18n("Installation error: No theme list found."));
- QTimer::singleShot(0, this,SLOT(close()));
- return;
- }
-
- // Read theme files
- for (int i = 0; i < themeList.size(); i++)
- {
- KConfig themeInfo( themeList.at(i), KConfig::SimpleConfig);
- KConfigGroup themeGroup(&themeInfo, "Theme");
- QString name = themeGroup.readEntry("Name", QString());
- QString file = themeGroup.readEntry("File", QString());
- bool isDefault = themeGroup.readEntry("Default", false);
- mThemeFiles[name] = file;
- if (mThemeDefault.isNull()) mThemeDefault = name;
- if (isDefault) mThemeDefault = name;
-
- if (global_debug>0) qCDebug(LSKAT_LOG) << "Found theme: " <<themeList.at(i) \
<<" Name(i18n)="<<name<<" File="<<file << " default="<<isDefault;
- }
- mThemeIndexNo = themeIdxFromName(mThemeDefault);
-
- // Create menus etc
- initGUI();
-
- // The LSkat config
- mLSkatConfig = new ConfigTwo(this);
- connect(mLSkatConfig, SIGNAL(signalInputType(int,InputDeviceType)),
- this, SLOT(setInputType(int,InputDeviceType)));
- mLSkatConfig->reset();
-
- // Read game properties and set default values (after config)
- readProperties();
-
- // TODO: Bugfix: Needs to be here if initGUI is befure readProperties
- if (global_debug>0) qCDebug(LSKAT_LOG) << "Setting current theme item to" << \
mThemeIndexNo;
- ((KSelectAction*)ACTION(QLatin1String( "theme" \
)))->setCurrentItem(mThemeIndexNo);
-
-
- // Get the card deck
- long seed = KRandom::random();
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Random seed" << seed;
- mDeck = new Deck(seed, this);
-
- // Theme manager
- QString themeFile = themefileFromIdx(mThemeIndexNo);
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Load theme" << themeFile << " no=" \
<< mThemeIndexNo;
- mTheme = new ThemeManager(mCardTheme, themeFile, this, this->width());
- if (mTheme->checkTheme() != 0)
- {
- KMessageBox::error(this, i18n("Installation error: Theme file error."));
- QTimer::singleShot(0, this,SLOT(close()));
- return;
- }
-
- // Overall view
- mCanvas = new QGraphicsScene(this);
- mView = new GameView(QSize(880, 675), ADVANCE_PERIOD, mCanvas, mTheme, \
this);
-
- // Create intro
- mGameMode = Intro;
- mDisplay = new DisplayIntro(mDeck, mCanvas, mTheme, ADVANCE_PERIOD, mView);
- setCentralWidget(mView);
- connect(mView, SIGNAL(signalLeftMousePress(QPoint)),
- this, SLOT(menuNewLSkatGame()));
+ // Reset stuff
+ mDeck = 0;
+ mEngine = 0;
+ mDisplay = 0;
+ mView = 0;
+ mLSkatConfig = 0;
+ mCanvas = 0;
+ mTheme = 0;
+
+ // Add resource type to grafix
+ KGlobal::dirs()->addResourceType("lskattheme", "appdata", "grafix/");
+
+ #ifndef NDEBUG
+ #ifdef SRC_DIR
- kDebug() << "Found SRC_DIR =" << SRC_DIR;
++ qCDebug(LSKAT_LOG) << "Found SRC_DIR =" << SRC_DIR;
+ KGlobal::dirs()->addResourceDir("lskattheme", QLatin1String(SRC_DIR) + \
QString("/grafix/")); + #endif
+ #endif
+
+ // Read theme files
- QStringList themeList = KGlobal::dirs()->findAllResources("lskattheme", \
QLatin1String("*.desktop"), KStandardDirs::NoDuplicates); ++ QStringList themeList \
= KGlobal::dirs()->findAllResources("lskattheme", QLatin1String("*.desktop"), \
KStandardDirs::NoDuplicates); + if (themeList.isEmpty())
+ {
+ KMessageBox::error(this, i18n("Installation error: No theme list found."));
+ QTimer::singleShot(0, this, SLOT(close()));
+ return;
+ }
- // Create GUI
- setupGUI();
+ // Read theme files
+ for (int i = 0; i < themeList.size(); i++)
+ {
+ KConfig themeInfo(themeList.at(i), KConfig::SimpleConfig);
+ KConfigGroup themeGroup(&themeInfo, "Theme");
+ QString name = themeGroup.readEntry("Name", QString());
+ QString file = themeGroup.readEntry("File", QString());
+ bool isDefault = themeGroup.readEntry("Default", false);
+ mThemeFiles[name] = file;
+ if (mThemeDefault.isNull()) mThemeDefault = name;
+ if (isDefault) mThemeDefault = name;
+
- if (global_debug > 0) kDebug() << "Found theme: " << themeList.at(i) << " \
Name(i18n)=" << name << " File=" << file << " default=" << isDefault; ++ if \
(global_debug > 0) qCDebug(LSKAT_LOG) << "Found theme: " << themeList.at(i) << " \
Name(i18n)=" << name << " File=" << file << " default=" << isDefault; + }
+ mThemeIndexNo = themeIdxFromName(mThemeDefault);
+
+ // Create menus etc
+ initGUI();
+
+ // The LSkat config
+ mLSkatConfig = new ConfigTwo(this);
+ connect(mLSkatConfig, SIGNAL(signalInputType(int,InputDeviceType)),
+ this, SLOT(setInputType(int,InputDeviceType)));
+ mLSkatConfig->reset();
+
+ // Read game properties and set default values (after config)
+ readProperties();
+
+ // TODO: Bugfix: Needs to be here if initGUI is before readProperties
- if (global_debug > 0) kDebug() << "Setting current theme item to" << \
mThemeIndexNo; ++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Setting current \
theme item to " << mThemeIndexNo; + ((KSelectAction \
*)ACTION(QLatin1String("theme")))->setCurrentItem(mThemeIndexNo); +
+ // Get the card deck
+ long seed = KRandom::random();
- if (global_debug > 0) kDebug() << "Random seed" << seed;
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Random seed" << seed;
+ mDeck = new Deck(seed, this);
+
+ // Theme manager
+ QString themeFile = themefileFromIdx(mThemeIndexNo);
- if (global_debug > 0) kDebug() << "Load theme" << themeFile << " no=" << \
mThemeIndexNo; ++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Load theme" << \
themeFile << " no=" << mThemeIndexNo; + mTheme = new ThemeManager(mCardTheme, \
themeFile, this, this->width()); + if (mTheme->checkTheme() != 0)
+ {
+ KMessageBox::error(this, i18n("Installation error: Theme file error."));
+ QTimer::singleShot(0, this, SLOT(close()));
+ return;
+ }
- statusBar()->showMessage(i18n("Welcome to Skat! Please start a new game."));
+ // Overall view
+ mCanvas = new QGraphicsScene(this);
+ mView = new GameView(QSize(880, 675), ADVANCE_PERIOD, mCanvas, mTheme, \
this);
- // Skip intro?
- if (global_skip_intro)
- {
- menuNewLSkatGame();
- }
- // Start game automatically in demo mode
- else if (global_demo_mode)
- {
- // Start intro
- mDisplay->start();
- QTimer::singleShot(12500, this,SLOT(menuNewLSkatGame()));
- }
- else
- {
- // Start intro
- mDisplay->start();
- }
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Mainwindow setup constructor done";
+ // Create intro
+ mGameMode = Intro;
+ mDisplay = new DisplayIntro(mDeck, mCanvas, mTheme, ADVANCE_PERIOD, \
mView); + setCentralWidget(mView);
+ connect(mView, SIGNAL(signalLeftMousePress(QPoint)),
+ this, SLOT(menuNewLSkatGame()));
+
+ // Create GUI
+ setupGUI();
+
+ statusBar()->showMessage(i18n("Welcome to Skat! Please start a new game."));
+ // Skip intro?
+ if (global_skip_intro)
+ {
+ menuNewLSkatGame();
+ }
+ // Start game automatically in demo mode
+ else if (global_demo_mode)
+ {
+ // Start intro
+ mDisplay->start();
+ QTimer::singleShot(12500, this, SLOT(menuNewLSkatGame()));
+ }
+ else
+ {
+ // Start intro
+ mDisplay->start();
+ }
- if (global_debug > 0) kDebug() << "Mainwindow setup constructor done";
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Mainwindow setup constructor \
done"; }
// Destructor
@@@ -226,98 -225,93 +221,93 @@@ QString Mainwindow::themefileFromIdx(in
// Retrieve a theme idx from a theme name
int Mainwindow::themeIdxFromName(QString name)
{
- QStringList list(mThemeFiles.keys());
- list.sort();
- for (int i=0; i < list.size(); ++i)
- {
- if (list[i] == name) return i;
- }
- qCCritical(LSKAT_LOG) << "Theme index lookup failed for " << name;
- return 0;
+ QStringList list(mThemeFiles.keys());
+ list.sort();
+ for (int i = 0; i < list.size(); ++i)
+ {
+ if (list[i] == name) return i;
+ }
- kError() << "Theme index lookup failed for " << name;
++ qCCritical(LSKAT_LOG) << "Theme index lookup failed for " << name;
+ return 0;
}
// Save properties
void Mainwindow::saveProperties()
{
- KConfig *config = KSharedConfig::openConfig().data();
- KConfig *config = KGlobal::config().data();
++ KConfig *config = KSharedConfig::openConfig().data();
- // Program data
- KConfigGroup cfg = config->group("ProgramData");
- cfg.writeEntry("startplayer", mStartPlayer);
- cfg.writeEntry("ThemeIndexNo", mThemeIndexNo);
+ // Program data
+ KConfigGroup cfg = config->group("ProgramData");
+ cfg.writeEntry("startplayer", mStartPlayer);
+ cfg.writeEntry("ThemeIndexNo", mThemeIndexNo);
- // LSkat data
- mLSkatConfig->save(config);
- config->sync();
+ // LSkat data
+ mLSkatConfig->save(config);
+ config->sync();
}
// Load properties
void Mainwindow::readProperties()
{
- KConfig *config = KSharedConfig::openConfig().data();
- KConfig *config = KGlobal::config().data();
++ KConfig *config = KSharedConfig::openConfig().data();
- // Program data
- KConfigGroup cfg = config->group("ProgramData");
+ // Program data
+ KConfigGroup cfg = config->group("ProgramData");
- // Theme number
- mThemeIndexNo = cfg.readEntry("ThemeIndexNo", themeIdxFromName(mThemeDefault));
- if (mThemeIndexNo >= mThemeFiles.size()) mThemeIndexNo = 0;
+ // Theme number
+ mThemeIndexNo = cfg.readEntry("ThemeIndexNo", themeIdxFromName(mThemeDefault));
+ if (mThemeIndexNo >= mThemeFiles.size()) mThemeIndexNo = 0;
- // Read card path
- mCardTheme = CardDeckInfo::deckName( cfg );
+ // Read card path
+ mCardTheme = CardDeckInfo::deckName(cfg);
- int no = cfg.readEntry("startplayer", 0);
- setStartPlayer(no);
- mLSkatConfig->load(config);
+ int no = cfg.readEntry("startplayer", 0);
+ setStartPlayer(no);
+ mLSkatConfig->load(config);
}
-
// Create a input with the given type
- AbstractInput* Mainwindow::createInput(
+ AbstractInput *Mainwindow::createInput(
InputDeviceType inputType,
- AbstractDisplay* display,
- AbstractEngine* engine)
+ AbstractDisplay *display,
+ AbstractEngine *engine)
{
- AbstractInput* input = 0;
-
- // Always use AI input in demo mode
- if (global_demo_mode)
- {
- inputType = TypeAiInput;
- }
-
- // Create the player input
- if (inputType == TypeMouseInput)
- {
- MouseInput* mouseInput = new MouseInput(this);
- connect((QObject*)mView, SIGNAL(signalLeftMousePress(QPoint)),
- mouseInput, SLOT(mousePress(QPoint)));
- connect(mouseInput, SIGNAL(signalConvertMousePress(QPoint,int&,int&)),
- display, SLOT(convertMousePress(QPoint,int&,int&)));
- connect(mouseInput, SIGNAL(signalPlayerInput(int,int,int)),
- engine, SLOT(playerInput(int,int,int)));
- input = mouseInput;
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Create MOUSE INPUT";
- }
- else if (inputType == TypeAiInput)
- {
- AiInput* aiInput = new AiInput((EngineTwo*)engine, this);
- connect(aiInput, SIGNAL(signalPlayerInput(int,int,int)),
- engine, SLOT(playerInput(int,int,int)));
- input = aiInput;
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Create AI INPUT";
- }
- else
- {
- qCCritical(LSKAT_LOG) << "Unpupported input device type" << inputType;
- }
-
- return input;
- }
+ AbstractInput *input = 0;
+ // Always use AI input in demo mode
+ if (global_demo_mode)
+ {
+ inputType = TypeAiInput;
+ }
+
+ // Create the player input
+ if (inputType == TypeMouseInput)
+ {
+ MouseInput *mouseInput = new MouseInput(this);
+ connect((QObject *)mView, SIGNAL(signalLeftMousePress(QPoint)),
+ mouseInput, SLOT(mousePress(QPoint)));
+ connect(mouseInput, SIGNAL(signalConvertMousePress(QPoint,int&,int&)),
+ display, SLOT(convertMousePress(QPoint,int&,int&)));
+ connect(mouseInput, SIGNAL(signalPlayerInput(int,int,int)),
+ engine, SLOT(playerInput(int,int,int)));
+ input = mouseInput;
- if (global_debug > 0) kDebug() << "Create MOUSE INPUT";
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Create MOUSE INPUT";
+ }
+ else if (inputType == TypeAiInput)
+ {
+ AiInput *aiInput = new AiInput((EngineTwo *)engine, this);
+ connect(aiInput, SIGNAL(signalPlayerInput(int,int,int)),
+ engine, SLOT(playerInput(int,int,int)));
+ input = aiInput;
- if (global_debug > 0) kDebug() << "Create AI INPUT";
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Create AI INPUT";
+ }
+ else
+ {
- kFatal() << "Unpupported input device type" << inputType;
++ qCCritical(LSKAT_LOG) << "Unsupported input device type" << inputType;
+ }
+
+ return input;
+ }
// Start a new game
void Mainwindow::startGame()
@@@ -384,91 -376,88 +372,88 @@@ void Mainwindow::nextPlayer(Player *pla
// Setup the GUI
void Mainwindow::initGUI()
{
- QAction *action;
-
- // Start a new game
- action = KStandardGameAction::gameNew(this, SLOT(menuNewLSkatGame()), \
actionCollection());
- if (global_demo_mode) action->setEnabled(false);
-
- // Clear all time statistics
- action = KStandardGameAction::clearStatistics(this, SLOT(menuClearStatistics()), \
actionCollection());
- action->setWhatsThis(i18n("Clears the all time statistics which is kept in all \
sessions."));
- if (global_demo_mode) action->setEnabled(false);
-
- // End a game
- action = KStandardGameAction::end(this, SLOT(menuEndGame()), actionCollection());
- action->setWhatsThis(i18n("Ends a currently played game. No winner will be \
declared."));
- action->setEnabled(false);
-
- // Quit the program
- action = KStandardGameAction::quit(this, SLOT(close()), actionCollection());
- action->setWhatsThis(i18n("Quits the program."));
-
- // Determine start player
- KSelectAction* startPlayerAct = new KSelectAction(i18n("Starting Player"), this);
- actionCollection()->addAction( QLatin1String( "startplayer" ), startPlayerAct);
- connect(startPlayerAct, SIGNAL(triggered(int)), this, SLOT(menuStartplayer()));
- startPlayerAct->setToolTip(i18n("Changing starting player..."));
- startPlayerAct->setWhatsThis(i18n("Chooses which player begins the next game."));
- QStringList list;
- list.clear();
- list.append(i18n("Player &1"));
- list.append(i18n("Player &2"));
- startPlayerAct->setItems(list);
- if (global_demo_mode) startPlayerAct->setEnabled(false);
-
-
- // Determine who player player 1
- KSelectAction* player1Act = new KSelectAction(i18n("Player &1 Played By"), this);
- actionCollection()->addAction( QLatin1String( "player1" ), player1Act);
- connect(player1Act, SIGNAL(triggered(int)), this, SLOT(menuPlayer1By()));
- player1Act->setToolTip(i18n("Changing who plays player 1..."));
- player1Act->setWhatsThis(i18n("Changing who plays player 1."));
- list.clear();
- list.append(i18n("&Mouse"));
- list.append(i18n("&Computer"));
- player1Act->setItems(list);
- if (global_demo_mode) player1Act->setEnabled(false);
-
- // Determine who player player 2
- KSelectAction* player2Act = new KSelectAction(i18n("Player &2 Played By"), this);
- actionCollection()->addAction( QLatin1String( "player2" ), player2Act);
- connect(player2Act, SIGNAL(triggered(int)), this, SLOT(menuPlayer2By()));
- player2Act->setToolTip(i18n("Changing who plays player 2..."));
- player2Act->setWhatsThis(i18n("Changing who plays player 2."));
- player2Act->setItems(list);
- if (global_demo_mode) player2Act->setEnabled(false);
-
- // Add all theme files to the menu
- QStringList themes(mThemeFiles.keys());
- themes.sort();
-
- KSelectAction* themeAct = new KSelectAction(i18n("&Theme"), this);
- actionCollection()->addAction( QLatin1String( "theme" ), themeAct);
- themeAct->setItems(themes);
- connect( themeAct, SIGNAL(triggered(int)), SLOT(changeTheme(int)) );
- if (global_debug>0) qCDebug(LSKAT_LOG) << "Setting current theme item to" << \
mThemeIndexNo;
- themeAct->setCurrentItem(mThemeIndexNo);
- themeAct->setToolTip(i18n("Changing theme..."));
- themeAct->setWhatsThis(i18n("Changing theme."));
-
- // Choose card deck
- QAction *action1 = actionCollection()->addAction( QLatin1String( \
"select_carddeck" ));
- action1->setText(i18n("Select &Card Deck..."));
- action1->setShortcuts( KShortcut( Qt::Key_F10 ) );
- connect(action1, SIGNAL(triggered(bool)), this, SLOT(menuCardDeck()));
- action1->setToolTip(i18n("Configure card decks..."));
- action1->setWhatsThis(i18n("Choose how the cards should look."));
-
- // Change player names
- action = actionCollection()->addAction( QLatin1String( "change_names" ));
- action->setText(i18n("&Change Player Names..."));
- connect(action, SIGNAL(triggered(bool)), this, SLOT(menuPlayerNames()));
- if (global_demo_mode) action->setEnabled(false);
+ QAction *action;
+
+ // Start a new game
+ action = KStandardGameAction::gameNew(this, SLOT(menuNewLSkatGame()), \
actionCollection()); + if (global_demo_mode) action->setEnabled(false);
+
+ // Clear all time statistics
+ action = KStandardGameAction::clearStatistics(this, \
SLOT(menuClearStatistics()), actionCollection()); + \
action->setWhatsThis(i18n("Clears the all time statistics which is kept in all \
sessions.")); + if (global_demo_mode) action->setEnabled(false);
+
+ // End a game
+ action = KStandardGameAction::end(this, SLOT(menuEndGame()), \
actionCollection()); + action->setWhatsThis(i18n("Ends a currently played game. \
No winner will be declared.")); + action->setEnabled(false);
+
+ // Quit the program
+ action = KStandardGameAction::quit(this, SLOT(close()), actionCollection());
+ action->setWhatsThis(i18n("Quits the program."));
+
+ // Determine start player
+ KSelectAction *startPlayerAct = new KSelectAction(i18n("Starting Player"), \
this); + actionCollection()->addAction(QLatin1String("startplayer"), \
startPlayerAct); + connect(startPlayerAct, SIGNAL(triggered(int)), this, \
SLOT(menuStartplayer())); + startPlayerAct->setToolTip(i18n("Changing starting \
player...")); + startPlayerAct->setWhatsThis(i18n("Chooses which player begins \
the next game.")); + QStringList list;
+ list.clear();
+ list.append(i18n("Player &1"));
+ list.append(i18n("Player &2"));
+ startPlayerAct->setItems(list);
+ if (global_demo_mode) startPlayerAct->setEnabled(false);
+
+ // Determine who player player 1
+ KSelectAction *player1Act = new KSelectAction(i18n("Player &1 Played By"), \
this); + actionCollection()->addAction(QLatin1String("player1"), player1Act);
+ connect(player1Act, SIGNAL(triggered(int)), this, SLOT(menuPlayer1By()));
+ player1Act->setToolTip(i18n("Changing who plays player 1..."));
+ player1Act->setWhatsThis(i18n("Changing who plays player 1."));
+ list.clear();
+ list.append(i18n("&Mouse"));
+ list.append(i18n("&Computer"));
+ player1Act->setItems(list);
+ if (global_demo_mode) player1Act->setEnabled(false);
+
+ // Determine who player player 2
+ KSelectAction *player2Act = new KSelectAction(i18n("Player &2 Played By"), \
this); + actionCollection()->addAction(QLatin1String("player2"), player2Act);
+ connect(player2Act, SIGNAL(triggered(int)), this, SLOT(menuPlayer2By()));
+ player2Act->setToolTip(i18n("Changing who plays player 2..."));
+ player2Act->setWhatsThis(i18n("Changing who plays player 2."));
+ player2Act->setItems(list);
+ if (global_demo_mode) player2Act->setEnabled(false);
+
+ // Add all theme files to the menu
+ QStringList themes(mThemeFiles.keys());
+ themes.sort();
+
+ KSelectAction *themeAct = new KSelectAction(i18n("&Theme"), this);
+ actionCollection()->addAction(QLatin1String("theme"), themeAct);
+ themeAct->setItems(themes);
+ connect(themeAct, SIGNAL(triggered(int)), SLOT(changeTheme(int)));
- if (global_debug > 0) kDebug() << "Setting current theme item to" << \
mThemeIndexNo; ++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Setting current \
theme item to " << mThemeIndexNo; + themeAct->setCurrentItem(mThemeIndexNo);
+ themeAct->setToolTip(i18n("Changing theme..."));
+ themeAct->setWhatsThis(i18n("Changing theme."));
+
+ // Choose card deck
- KAction *action1 = \
actionCollection()->addAction(QLatin1String("select_carddeck")); ++ QAction \
*action1 = actionCollection()->addAction(QLatin1String("select_carddeck")); + \
action1->setText(i18n("Select &Card Deck...")); + \
action1->setShortcuts(KShortcut(Qt::Key_F10)); + connect(action1, \
SIGNAL(triggered(bool)), this, SLOT(menuCardDeck())); + \
action1->setToolTip(i18n("Configure card decks...")); + \
action1->setWhatsThis(i18n("Choose how the cards should look.")); +
+ // Change player names
+ action = actionCollection()->addAction(QLatin1String("change_names"));
+ action->setText(i18n("&Change Player Names..."));
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(menuPlayerNames()));
+ if (global_demo_mode) action->setEnabled(false);
}
-
// Choose start player
void Mainwindow::menuStartplayer()
{
@@@ -479,15 -468,12 +464,12 @@@
// Change the theme of the game
void Mainwindow::changeTheme(int idx)
{
- mThemeIndexNo = idx;
- QString themeFile = themefileFromIdx(idx);
- if (global_debug>0) qCDebug(LSKAT_LOG) << "Select theme" << themeFile;
- mTheme->updateTheme(themeFile);
+ mThemeIndexNo = idx;
+ QString themeFile = themefileFromIdx(idx);
- if (global_debug > 0) kDebug() << "Select theme" << themeFile;
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Select theme " << themeFile;
+ mTheme->updateTheme(themeFile);
}
-
-
// Select input for player 1
void Mainwindow::menuPlayer1By()
{
@@@ -506,34 -491,35 +487,35 @@@ void Mainwindow::menuPlayer2By(
// Choose a card deck
void Mainwindow::menuCardDeck()
{
- QString front = mCardTheme;
-
- KConfigGroup grp = KSharedConfig::openConfig()->group("ProgramData");
- KCardWidget* cardwidget = new KCardWidget();
- cardwidget->readSettings(grp);
- KCardDialog dlg(cardwidget);
- if (dlg.exec()==QDialog::Accepted)
- {
- // Always store the settings, other things than the deck may have changed
- cardwidget->saveSettings(grp);
- grp.sync();
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "NEW CARDDECK:" << front;
- bool change = false; // Avoid unnecessary changes
- if (!cardwidget->deckName().isEmpty() && cardwidget->deckName() != mCardTheme)
- {
- mCardTheme = cardwidget->deckName();
- change = true;
- }
- if (change)
+ QString front = mCardTheme;
+
- KConfigGroup grp = KGlobal::config()->group("ProgramData");
++ KConfigGroup grp = KSharedConfig::openConfig()->group("ProgramData");
+ KCardWidget *cardwidget = new KCardWidget();
+ QPointer<KCardDialog> dlg;
+
+ cardwidget->readSettings(grp);
+ dlg = new KCardDialog(cardwidget);
+ if (dlg->exec() == QDialog::Accepted)
{
- mTheme->updateCardTheme(mCardTheme);
- mView->update(); // Be on the safe side and update
+ // Always store the settings, other things than the deck may have changed
+ cardwidget->saveSettings(grp);
+ grp.sync();
- if (global_debug > 0) kDebug() << "NEW CARDDECK:" << front;
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "NEW CARDDECK: " << front;
+ bool change = false; // Avoid unnecessary changes
+ if (!cardwidget->deckName().isEmpty() && cardwidget->deckName() != \
mCardTheme) + {
+ mCardTheme = cardwidget->deckName();
+ change = true;
+ }
+ if (change)
+ {
+ mTheme->updateCardTheme(mCardTheme);
+ mView->update(); // Be on the safe side and update
+ }
}
- }
+ delete dlg;
}
-
// Clear all time statistics
void Mainwindow::menuClearStatistics()
{
@@@ -653,28 -634,25 +630,23 @@@ void Mainwindow::setStartPlayer(int no
// Set the input type for a given player number.
void Mainwindow::setInputType(int no, InputDeviceType type)
{
- Player* p = 0;
- // Player 1
- if (no == 0)
- {
- ((KSelectAction *)ACTION(QLatin1String( "player1" \
)))->setCurrentItem((int)type);
- p = mLSkatConfig->player(0);
- }
- else if (no == 1)
- {
- ((KSelectAction *)ACTION(QLatin1String( "player2" \
)))->setCurrentItem((int)type);
- p = mLSkatConfig->player(1);
- }
-
- // Exchange player input at runtime
- if (mEngine && p && mDisplay && mEngine->isGameRunning())
- {
- AbstractInput* input = createInput(type, mDisplay, mEngine);
- p->setInput(input);
- }
+ Player *p = 0;
+ // Player 1
+ if (no == 0)
+ {
+ ((KSelectAction \
*)ACTION(QLatin1String("player1")))->setCurrentItem((int)type); + p = \
mLSkatConfig->player(0); + }
+ else if (no == 1)
+ {
+ ((KSelectAction \
*)ACTION(QLatin1String("player2")))->setCurrentItem((int)type); + p = \
mLSkatConfig->player(1); + }
+ // Exchange player input at runtime
+ if (mEngine && p && mDisplay && mEngine->isGameRunning())
+ {
+ AbstractInput *input = createInput(type, mDisplay, mEngine);
+ p->setInput(input);
+ }
}
--
-
-
-#include "mainwindow.moc"
diff --cc src/mouseinput.cpp
index 153c13a,a767bd4..9b5b543
--- a/src/mouseinput.cpp
+++ b/src/mouseinput.cpp
@@@ -21,13 -21,13 +21,12 @@@
#include "mouseinput.h"
// Qt includes
-#include <QPixmap>
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
-
// Constructor for the input
- MouseInput::MouseInput(QObject* parent)
+ MouseInput::MouseInput(QObject *parent)
: AbstractInput(parent)
{
}
@@@ -35,21 -35,19 +34,17 @@@
// Mouse press received
void MouseInput::mousePress(const QPoint &point)
{
- int playerNumber;
- int cardNumber;
-
- // Do only process input if it is our turn
- if (!mInputAllowed) return;
-
- emit signalConvertMousePress(point, playerNumber, cardNumber);
- // Check whether the move is for the right player
- if (playerNumber == mId)
- {
- //qCDebug(LSKAT_LOG) << "MouseInput:: Convert to" << playerNumber << "," << \
cardNumber;
- emit signalPlayerInput(mId, playerNumber, cardNumber);
- }
+ int playerNumber;
+ int cardNumber;
+
+ // Do only process input if it is our turn
+ if (!mInputAllowed) return;
+
+ emit signalConvertMousePress(point, playerNumber, cardNumber);
+ // Check whether the move is for the right player
+ if (playerNumber == mId)
+ {
- //kDebug() << "MouseInput:: Convert to" << playerNumber << "," << \
cardNumber; ++ //qCDebug(LSKAT_LOG) << "MouseInput:: Convert to " << \
playerNumber << "," << cardNumber; + emit signalPlayerInput(mId, \
playerNumber, cardNumber); + }
}
--
-
-
-#include "mouseinput.moc"
diff --cc src/namedialogwidget.cpp
index f16ebba,b3e833c..b3243b8
--- a/src/namedialogwidget.cpp
+++ b/src/namedialogwidget.cpp
@@@ -24,17 -24,15 +24,15 @@@
#include <QWidget>
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
-
// Constructor for the widget
- NameDialogWidget::NameDialogWidget(QWidget* parent)
+ NameDialogWidget::NameDialogWidget(QWidget *parent)
: QDialog(parent)
{
- ui.setupUi(this);
+ ui.setupUi(this);
}
-
// Set a default names to the widget
void NameDialogWidget::setName(int pos, const QString &name)
{
@@@ -51,15 -49,14 +49,12 @@@
// Retrieve the name from the widget.
QString NameDialogWidget::name(int pos)
{
- if (pos == 0)
- {
- return ui.editPlayer1->text();
- }
- else
- {
- return ui.editPlayer2->text();
- }
+ if (pos == 0)
+ {
+ return ui.editPlayer1->text();
+ }
+ else
+ {
+ return ui.editPlayer2->text();
+ }
}
--
-
-#include "namedialogwidget.moc"
diff --cc src/namedialogwidget.h
index f8c8036,92b9347..c2536c1
--- a/src/namedialogwidget.h
+++ b/src/namedialogwidget.h
@@@ -20,11 -18,15 +18,14 @@@
Boston, MA 02110-1301, USA.
*/
+ #ifndef NAMEDIALOG_WIDGET_H
+ #define NAMEDIALOG_WIDGET_H
+
// Qt includes
#include <QDialog>
-#include <QSize>
// KDE includes
-#include <kdebug.h>
+#include "lskat_debug.h"
// Local includes
#include "ui_namedialog.h"
diff --cc src/pixmapsprite.cpp
index 3371e21,5e1a259..2e39df7
--- a/src/pixmapsprite.cpp
+++ b/src/pixmapsprite.cpp
@@@ -31,136 -31,129 +31,131 @@@
#include <kconfig.h>
#include <kconfiggroup.h>
-
// Constructor for the sprite
- PixmapSprite::PixmapSprite(const QString &id, ThemeManager* theme, int \
advancePeriod, int no, QGraphicsScene* canvas)
- : Themable(id, theme), QGraphicsPixmapItem(0)
+ PixmapSprite::PixmapSprite(const QString &id, ThemeManager *theme, int \
advancePeriod, int no, QGraphicsScene *canvas)
- : Themable(id, theme), QGraphicsPixmapItem(0, canvas)
++ : Themable(id, theme), QGraphicsPixmapItem(0)
{
- canvas->addItem(this);
- hide();
-
- mAnimationState = Idle;
- mAdvancePeriod = advancePeriod;
- mNo = no;
- mCurrentFrame = 0;
- mOffsetStatus = true;
++ canvas->addItem(this);
+ hide();
+ mAnimationState = Idle;
+ mAdvancePeriod = advancePeriod;
+ mNo = no;
+ mCurrentFrame = 0;
+ mOffsetStatus = true;
- if (theme) theme->updateTheme(this);
+ if (theme) theme->updateTheme(this);
}
-
// Constructor for the sprite
- PixmapSprite::PixmapSprite(int advancePeriod, int no, QGraphicsScene* canvas)
+ PixmapSprite::PixmapSprite(int advancePeriod, int no, QGraphicsScene *canvas)
- : Themable(), QGraphicsPixmapItem(0, canvas)
+ : Themable(), QGraphicsPixmapItem(0)
{
- canvas->addItem(this);
- hide();
-
- mAnimationState = Idle;
- mAdvancePeriod = advancePeriod;
- mNo = no;
- mCurrentFrame = 0;
- mOffsetStatus = true;
++ canvas->addItem(this);
+ hide();
+
+ mAnimationState = Idle;
+ mAdvancePeriod = advancePeriod;
+ mNo = no;
+ mCurrentFrame = 0;
+ mOffsetStatus = true;
}
-
// Main themable function. Called for any theme change. The sprites needs to
- // resiez and redraw here.
+ // resize and redraw here.
void PixmapSprite::changeTheme()
{
- // Clear data
- mFrames.clear();
- mHotspots.clear();
-
- // Get scaling change
- double oldscale = this->getScale();
- double scale = thememanager()->getScale();
- Themable::setScale(scale);
-
- // Retrieve theme data from configuration
- KConfigGroup config = thememanager()->config(id());
- double width = config.readEntry("width", 1.0);
- double height = config.readEntry("height", 0.0);
- width *= scale;
- height *= scale;
- QPointF pos = config.readEntry("pos", QPointF(1.0,1.0));
- pos *= scale;
- // Set fixed z value?
- if (config.hasKey("zValue"))
- {
- double zValue = config.readEntry("zValue", 0.0);
- setZValue(zValue);
- }
-
- // Centering
- bool center = config.readEntry("center", false);
+ // Clear data
+ mFrames.clear();
+ mHotspots.clear();
+
+ // Get scaling change
+ double oldscale = this->getScale();
+ double scale = thememanager()->getScale();
+ Themable::setScale(scale);
+
+ // Retrieve theme data from configuration
+ KConfigGroup config = thememanager()->config(id());
+ double width = config.readEntry("width", 1.0);
+ double height = config.readEntry("height", 0.0);
+ width *= scale;
+ height *= scale;
+ QPointF pos = config.readEntry("pos", QPointF(1.0, 1.0));
+ pos *= scale;
+ // Set fixed z value?
+ if (config.hasKey("zValue"))
+ {
+ double zValue = config.readEntry("zValue", 0.0);
+ setZValue(zValue);
+ }
- // Animation
- mStartFrame = config.readEntry("start-frame", 0);
- mEndFrame = config.readEntry("end-frame", 0);
- mDelay = config.readEntry("animation-delay", 0);
- QString refframe = config.readEntry("ref-frame", QString());
+ // Centering
+ bool center = config.readEntry("center", false);
- // Set fixed position or modify current position
- if (config.hasKey("pos"))
- {
- setPos(pos.x(), pos.y());
- }
- else
- {
- setPos(x()*scale/oldscale, y()*scale/oldscale);
- }
+ // Animation
+ mStartFrame = config.readEntry("start-frame", 0);
+ mEndFrame = config.readEntry("end-frame", 0);
+ mDelay = config.readEntry("animation-delay", 0);
+ QString refframe = config.readEntry("ref-frame", QString());
- // SVG graphics
- QString svgid = config.readEntry("svgid");
- // Read sequence of frame pixmaps when auto ID given
- QPixmap pixmap;
- if (svgid == QLatin1String( "auto" ))
- {
- for (int i=mStartFrame;i<=mEndFrame;i++)
+ // Set fixed position or modify current position
+ if (config.hasKey("pos"))
+ {
+ setPos(pos.x(), pos.y());
+ }
+ else
{
- QString name = QString::fromLatin1( "frame%1").arg(i);
- svgid = config.readEntry(name);
- if (!refframe.isNull())
- {
- pixmap = thememanager()->getPixmap(svgid, refframe, width);
- }
- else if (config.hasKey("height"))
- {
- pixmap = thememanager()->getPixmap(svgid, QSize(int(width), int(height)));
- }
- else
- {
- pixmap = thememanager()->getPixmap(svgid, width);
- }
- mFrames.append(pixmap);
- if (center) mHotspots.append(QPointF(pixmap.width()/2,pixmap.height()/2));
- else mHotspots.append(QPointF(0.0,0.0));
+ setPos(x() * scale / oldscale, y() * scale / oldscale);
}
- }
- // Read only one named pixmap
- else
- {
- if (config.hasKey("height"))
+
+ // SVG graphics
+ QString svgid = config.readEntry("svgid");
+ // Read sequence of frame pixmaps when auto ID given
+ QPixmap pixmap;
+ if (svgid == QLatin1String("auto"))
{
- pixmap = thememanager()->getPixmap(svgid, QSize(int(width), int(height)));
+ for (int i = mStartFrame; i <= mEndFrame; i++)
+ {
+ QString name = QString::fromLatin1("frame%1").arg(i);
+ svgid = config.readEntry(name);
+ if (!refframe.isNull())
+ {
+ pixmap = thememanager()->getPixmap(svgid, refframe, width);
+ }
+ else if (config.hasKey("height"))
+ {
+ pixmap = thememanager()->getPixmap(svgid, QSize(int(width), \
int(height))); + }
+ else
+ {
+ pixmap = thememanager()->getPixmap(svgid, width);
+ }
+ mFrames.append(pixmap);
+ if (center) mHotspots.append(QPointF(pixmap.width() / 2, \
pixmap.height() / 2)); + else mHotspots.append(QPointF(0.0, 0.0));
+ }
}
+ // Read only one named pixmap
else
{
- pixmap = thememanager()->getPixmap(svgid, width);
+ if (config.hasKey("height"))
+ {
+ pixmap = thememanager()->getPixmap(svgid, QSize(int(width), \
int(height))); + }
+ else
+ {
+ pixmap = thememanager()->getPixmap(svgid, width);
+ }
+ mFrames.append(pixmap);
+ if (center) mHotspots.append(QPointF(pixmap.width() / 2, pixmap.height() / \
2)); + else mHotspots.append(QPointF(0.0, 0.0));
}
- mFrames.append(pixmap);
- if (center) mHotspots.append(QPointF(pixmap.width()/2,pixmap.height()/2));
- else mHotspots.append(QPointF(0.0,0.0));
- }
- // Set pixmap to sprite
- setFrame(mCurrentFrame, true);
- update();
+ // Set pixmap to sprite
+ setFrame(mCurrentFrame, true);
+ update();
}
-
// Debug only: Retrieve double value from configuration file
double PixmapSprite::getDoubleValue(const QString &item)
{
diff --cc src/pixmapsprite.h
index ccd3354,bfcd8e1..7f0c6b7
--- a/src/pixmapsprite.h
+++ b/src/pixmapsprite.h
@@@ -20,8 -18,12 +18,11 @@@
Boston, MA 02110-1301, USA.
*/
+ #ifndef PIXMAP_SPRITE_H
+ #define PIXMAP_SPRITE_H
+
// Qt includes
#include <QPointF>
-#include <QSizeF>
#include <QGraphicsPixmapItem>
// Local includes
diff --cc src/player.cpp
index 9a4e1f5,7d3486f..d169877
--- a/src/player.cpp
+++ b/src/player.cpp
@@@ -99,59 -94,55 +93,55 @@@ void Player::clear(
// Deal a number of cards to this player
void Player::deal(int amount)
{
- if (!mDeck)
- {
- qCCritical(LSKAT_LOG) << "No deck set to player.";
- return;
- }
- mCards.clear();
- mCards.resize(amount);
- for (int i=0; i<amount; i++)
- {
- int card = mDeck->drawCard();
- mCards[i] = card;
- }
-
- // Reset moves and points
- mMovesWon = 0;
- setPoints(0);
- mWonCards.clear();
-
- refresh();
+ if (!mDeck)
+ {
- kFatal() << "No deck set to player.";
++ qCCritical(LSKAT_LOG) << "No deck set to player.";
+ return;
+ }
+ mCards.clear();
+ mCards.resize(amount);
+ for (int i = 0; i < amount; i++)
+ {
+ int card = mDeck->drawCard();
+ mCards[i] = card;
+ }
+
+ // Reset moves and points
+ mMovesWon = 0;
+ setPoints(0);
+ mWonCards.clear();
+
+ refresh();
}
-
// Retrieve the input device of the player
- AbstractInput* Player::input()
+ AbstractInput *Player::input()
{
- return mInput;
+ return mInput;
}
-
// Set the input device of the player
- void Player::setInput(AbstractInput* input)
+ void Player::setInput(AbstractInput *input)
{
- // Try to set the same turn status after changing input
- bool oldTurnAllowed = false;
- // Get rid of old input devive if existing
- if (mInput)
- {
- oldTurnAllowed = mInput->inputAllowed();
- mInput->setInputAllowed(false);
- delete mInput;
- }
- // Store new input
- mInput = input;
- // Store player
- mInput->setId(mId);
- // Restore turn status
- mInput->setInputAllowed(oldTurnAllowed);
-
- refresh();
+ // Try to set the same turn status after changing input
+ bool oldTurnAllowed = false;
+ // Get rid of old input device if existing
+ if (mInput)
+ {
+ oldTurnAllowed = mInput->inputAllowed();
+ mInput->setInputAllowed(false);
+ delete mInput;
+ }
+ // Store new input
+ mInput = input;
+ // Store player
+ mInput->setId(mId);
+ // Restore turn status
+ mInput->setInputAllowed(oldTurnAllowed);
+
+ refresh();
}
-
// Set this player to start a turn
void Player::startTurn()
{
@@@ -168,49 -158,44 +157,44 @@@ void Player::stopTurn(
// Remove a card from the given position. Typically if the card was played.
void Player::deleteCard(int cardPosition)
{
- if (cardPosition >= mCards.size())
- {
- qCCritical(LSKAT_LOG) << "Player" << mId << "tries to delete non existing card \
position "
- << cardPosition <<" >=" << mCards.size();
- }
- mCards[cardPosition] = -1;
+ if (cardPosition >= mCards.size())
+ {
- kFatal() << "Player" << mId << "tries to delete non existing card position \
"
- << cardPosition << " >=" << mCards.size();
++ qCCritical(LSKAT_LOG) << "Player " << mId << " tries to delete non existing \
card position " ++ << cardPosition << " >=" << mCards.size();
+ }
+ mCards[cardPosition] = -1;
}
// Add a card to the player
void Player::addCard(int cardPosition, int card)
{
- if (cardPosition >= mCards.size())
- {
- qCCritical(LSKAT_LOG) << "Player" << mId << "tries to add to existing card \
position "
- << cardPosition <<" >=" << mCards.size();
- }
- mCards[cardPosition] = card;
+ if (cardPosition >= mCards.size())
+ {
- kFatal() << "Player" << mId << "tries to add to existing card position "
- << cardPosition << " >=" << mCards.size();
++ qCCritical(LSKAT_LOG) << "Player " << mId << " tries to add to existing \
card position " ++ << cardPosition << " >=" << mCards.size();
+ }
+ mCards[cardPosition] = card;
}
// Retrieve card value at given logical position
int Player::getCard(int playerNumber)
{
- if (playerNumber >= mCards.size())
- {
- qCCritical(LSKAT_LOG) << "Player" << mId << "tries to get non existing card "
- << playerNumber <<" >=" << mCards.size();
- }
-
- int card = mCards[playerNumber];
- return card;
+ if (playerNumber >= mCards.size())
+ {
- kFatal() << "Player" << mId << "tries to get non existing card "
- << playerNumber << " >=" << mCards.size();
++ qCCritical(LSKAT_LOG) << "Player " << mId << " tries to get non existing \
card " ++ << playerNumber << " >=" << mCards.size();
+ }
+
+ int card = mCards[playerNumber];
+ return card;
}
-
- // Increases the numebr of moves one for this player
+ // Increases the number of moves one for this player
void Player::increaseMovesWon(int amount)
{
- mMovesWon += amount;
+ mMovesWon += amount;
}
-
// Retrieve the number of won moves for this player
int Player::noOfMovesWon()
{
@@@ -232,17 -216,15 +215,15 @@@ void Player::addWonCard(int card
// Retrieve a card won by this player.
int Player::getWonCard(int no)
{
- if (no>=mWonCards.size())
- {
- qCCritical(LSKAT_LOG) << "Player::getWonCard This card" << no << "is not \
available. "
- << "Only" << mWonCards.size() << "cards stored.";
- return -1;
- }
- return mWonCards[no];
+ if (no >= mWonCards.size())
+ {
- kFatal() << "Player::getWonCard This card" << no << "is not available. "
- << "Only" << mWonCards.size() << "cards stored.";
++ qCCritical(LSKAT_LOG) << "Player::getWonCard This card " << no << " is not \
available. " ++ << "Only " << mWonCards.size() << " cards stored.";
+ return -1;
+ }
+ return mWonCards[no];
}
-
// Retrieve the amount of points this player has
int Player::points()
{
@@@ -334,8 -306,7 +305,5 @@@ Suite Player::trump(
// Emit all signals for GUI
void Player::refresh()
{
- emit signalUpdate(this);
+ emit signalUpdate(this);
}
--
-
-#include "player.moc"
diff --cc src/scoresprite.cpp
index 31ee5d2,b34cdf9..4d051da
--- a/src/scoresprite.cpp
+++ b/src/scoresprite.cpp
@@@ -34,36 -34,30 +34,34 @@@
#include <kconfiggroup.h>
// Constructor for the score sprite
- ScoreSprite::ScoreSprite(const QString &id, ThemeManager* theme, int advancePeriod, \
int no, QGraphicsScene* scene) + ScoreSprite::ScoreSprite(const QString &id, \
ThemeManager *theme, int advancePeriod, int no, QGraphicsScene \
*scene)
: Themable(id, theme), PixmapSprite(advancePeriod, no, scene)
{
- // Create all sub sprites
- mName = new QGraphicsTextItem(this);
- scene->addItem(mName);
- mPoints = new QGraphicsTextItem(this);
- scene->addItem(mPoints);
- mScore = new QGraphicsTextItem(this);
- scene->addItem(mScore);
- mGames = new QGraphicsTextItem(this);
- scene->addItem(mGames);
- mInput = new PixmapSprite(QLatin1String( "scoreinput" ), theme, advancePeriod, \
0, scene);
- if (!mInput) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "scoreinput";
- mInput->setParentItem(this);
- mInput->setOffsetStatus(false);
- mInputFrame = 0;
-
- mTrump = new PixmapSprite(QLatin1String( "scoretrump" ), theme, advancePeriod, \
0, scene);
- if (!mTrump) qCCritical(LSKAT_LOG) << "Cannot load sprite" << "scoretrump";
- mTrump->setParentItem(this);
- mTrump->setOffsetStatus(false);
- mTrumpFrame = 0;
-
- // Redraw us
- if (theme) theme->updateTheme(this);
-
+ // Create all sub sprites
- mName = new QGraphicsTextItem(this, scene);
- mPoints = new QGraphicsTextItem(this, scene);
- mScore = new QGraphicsTextItem(this, scene);
- mGames = new QGraphicsTextItem(this, scene);
++ mName = new QGraphicsTextItem(this);
++ scene->addItem(mName);
++ mPoints = new QGraphicsTextItem(this);
++ scene->addItem(mPoints);
++ mScore = new QGraphicsTextItem(this);
++ scene->addItem(mScore);
++ mGames = new QGraphicsTextItem(this);
++ scene->addItem(mGames);
+ mInput = new PixmapSprite(QLatin1String("scoreinput"), theme, advancePeriod, \
0, scene);
- if (!mInput) kFatal() << "Cannot load sprite" << "scoreinput";
++ if (!mInput) qCCritical(LSKAT_LOG) << "Cannot load sprite " << "scoreinput";
+ mInput->setParentItem(this);
+ mInput->setOffsetStatus(false);
+ mInputFrame = 0;
+
+ mTrump = new PixmapSprite(QLatin1String("scoretrump"), theme, advancePeriod, \
0, scene);
- if (!mTrump) kFatal() << "Cannot load sprite" << "scoretrump";
++ if (!mTrump) qCCritical(LSKAT_LOG) << "Cannot load sprite " << "scoretrump";
+ mTrump->setParentItem(this);
+ mTrump->setOffsetStatus(false);
+ mTrumpFrame = 0;
+
+ // Redraw us
+ if (theme) theme->updateTheme(this);
}
-
// Destructor
ScoreSprite::~ScoreSprite()
{
diff --cc src/scoresprite.h
index d974e17,0abe464..014397a
--- a/src/scoresprite.h
+++ b/src/scoresprite.h
@@@ -20,7 -18,12 +18,10 @@@
Boston, MA 02110-1301, USA.
*/
+ #ifndef SCORE_SPRITE_H
+ #define SCORE_SPRITE_H
+
// Qt includes
-#include <QPointF>
-#include <QSizeF>
#include <QGraphicsPixmapItem>
#include <QGraphicsTextItem>
diff --cc src/textsprite.cpp
index cc750e8,e3156fb..605c2da
--- a/src/textsprite.cpp
+++ b/src/textsprite.cpp
@@@ -28,27 -27,23 +28,25 @@@
#include <kconfiggroup.h>
// Constructor for the sprite
- TextSprite::TextSprite(const QString &text, const QString &id, ThemeManager* theme, \
QGraphicsScene* scene) + TextSprite::TextSprite(const QString &text, const QString \
&id, ThemeManager *theme, QGraphicsScene *scene)
- : Themable(id, theme), QGraphicsTextItem(0, scene)
+ : Themable(id, theme), QGraphicsTextItem(0)
{
- scene->addItem(this);
- setPlainText(text);
- hide();
-
- if (theme) theme->updateTheme(this);
- }
++ scene->addItem(this);
+ setPlainText(text);
+ hide();
+ if (theme) theme->updateTheme(this);
+ }
// Constructor for the sprite
- TextSprite::TextSprite(const QString &id, ThemeManager* theme, QGraphicsScene* \
scene) + TextSprite::TextSprite(const QString &id, ThemeManager *theme, \
QGraphicsScene *scene)
- : Themable(id, theme), QGraphicsTextItem(0, scene)
+ : Themable(id, theme), QGraphicsTextItem(0)
{
- scene->addItem(this);
- hide();
-
- if (theme) theme->updateTheme(this);
- }
++ scene->addItem(this);
+ hide();
+ if (theme) theme->updateTheme(this);
+ }
void TextSprite::setText(const QString &text)
{
diff --cc src/thememanager.cpp
index c160005,09c12cf..87ae7c0
--- a/src/thememanager.cpp
+++ b/src/thememanager.cpp
@@@ -154,89 -151,84 +148,84 @@@ void ThemeManager::updateCardTheme(cons
// Update card deck and card set
void ThemeManager::updateCardTheme(const QString &themefile, const QString \
&cardTheme) {
- if (global_debug > 1)
- {
- qCDebug(LSKAT_LOG) << "ThemeManager Pixmap cards: ";
- qCDebug(LSKAT_LOG) << " Card theme =" << cardTheme;
- }
+ if (global_debug > 1)
+ {
- kDebug() << "ThemeManager Pixmap cards: ";
- kDebug() << " Card theme =" << cardTheme;
++ qCDebug(LSKAT_LOG) << "ThemeManager Pixmap cards: ";
++ qCDebug(LSKAT_LOG) << " Card theme =" << cardTheme;
+ }
- // Cards
- mCardTheme = cardTheme;
- mCardCache->setDeckName(mCardTheme);
+ // Cards
+ mCardTheme = cardTheme;
+ mCardCache->setDeckName(mCardTheme);
- mCardCache->setSize(QSize());
+ mCardCache->setSize(QSize());
- updateTheme(themefile);
+ updateTheme(themefile);
}
-
// Update the theme file and refresh all registered objects. Used
// to really change the theme.
void ThemeManager::updateTheme(const QString &themefile)
{
- // Empty cache
- mPixmapCache.clear();
- mThemeFile = themefile;
-
- // Process dirs
- QString rcfile = KStandardDirs::locate("lskattheme", themefile);
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "ThemeManager LOAD with theme \
"<<rcfile;
-
- // Read config and SVG file for theme
- delete mConfig;
- mConfig = new KConfig(rcfile, KConfig::NoGlobals);
- QString svgfile = config(QLatin1String( "general" )).readEntry("svgfile");
- svgfile = KStandardDirs::locate("lskattheme", svgfile);
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Reading SVG master file =" << \
svgfile;
-
- mAspectRatio = config(QLatin1String( "general" )).readEntry("aspect-ratio", \
1.0);
- mCardAspectRatio = config(QLatin1String( "general" \
)).readEntry("card-aspect-ratio", 1.0);
- if (global_debug > 0) qCDebug(LSKAT_LOG) << "Aspect ration =" << mAspectRatio << \
"Cards aspect=" << mCardAspectRatio;
-
-
- delete mRenderer;
- mRenderer = new QSvgRenderer(this);
- bool result = mRenderer->load(svgfile);
- if (!result)
- {
- mRenderer = 0;
- qCCritical(LSKAT_LOG) << "Cannot open file" << svgfile;
- }
-
- // Notify all theme objects of a change
- QHashIterator<Themable*, int> it(mObjects);
- while (it.hasNext())
- {
- it.next();
- Themable* ob = it.key();
- ob->changeTheme();
- }
- }
+ // Empty cache
+ mPixmapCache.clear();
+ mThemeFile = themefile;
+ // Process dirs
+ QString rcfile = KStandardDirs::locate("lskattheme", themefile);
- if (global_debug > 0) kDebug() << "ThemeManager LOAD with theme " << rcfile;
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "ThemeManager LOAD with theme " << \
rcfile; +
+ // Read config and SVG file for theme
+ delete mConfig;
+ mConfig = new KConfig(rcfile, KConfig::NoGlobals);
+ QString svgfile = config(QLatin1String("general")).readEntry("svgfile");
+ svgfile = KStandardDirs::locate("lskattheme", svgfile);
- if (global_debug > 0) kDebug() << "Reading SVG master file =" << svgfile;
++ if (global_debug > 0) qCDebug(LSKAT_LOG) << "Reading SVG master file =" << \
svgfile; +
+ mAspectRatio = config(QLatin1String("general")).readEntry("aspect-ratio", \
1.0); + mCardAspectRatio = \
config(QLatin1String("general")).readEntry("card-aspect-ratio", 1.0);
- if (global_debug > 0) kDebug() << "Aspect ration =" << mAspectRatio << "Cards \
aspect=" << mCardAspectRatio; ++ if (global_debug > 0) qCDebug(LSKAT_LOG) << \
"Aspect ration =" << mAspectRatio << "Cards aspect=" << mCardAspectRatio; +
+ delete mRenderer;
+ mRenderer = new QSvgRenderer(this);
+ bool result = mRenderer->load(svgfile);
+ if (!result)
+ {
+ mRenderer = 0;
- kFatal() << "Cannot open file" << svgfile;
++ qCCritical(LSKAT_LOG) << "Cannot open file" << svgfile;
+ }
+
+ // Notify all theme objects of a change
+ QHashIterator<Themable *, int> it(mObjects);
+ while (it.hasNext())
+ {
+ it.next();
+ Themable *ob = it.key();
+ ob->changeTheme();
+ }
+ }
// Rescale the theme. Call all registered objects so that they can refresh.
void ThemeManager::rescale(int scale, QPoint offset)
{
- if (global_debug > 1)
- {
- if (scale==mScale)
- qCDebug(LSKAT_LOG) <<" No scale change to" << scale << "If this happends to \
often its BAD";
- }
- //if (scale==mScale) return;
- mScale = scale;
- mOffset = offset;
- if (global_debug > 1) qCDebug(LSKAT_LOG) << "THEMEMANAGER:: Rescale to " << \
scale<<" offset to "<<offset;
-
- QHashIterator<Themable*, int> it(mObjects);
- while (it.hasNext())
- {
- it.next();
- Themable* ob = it.key();
- ob->changeTheme();
- }
- }
+ if (global_debug > 1)
+ {
+ if (scale == mScale)
- kDebug() << "No scale change to " << scale << ". If this happens too \
often it is BAD"; ++ qCDebug(LSKAT_LOG) << "No scale change to" << scale \
<< "If this happens too often it is BAD"; + }
+ //if (scale == mScale) return;
+ mScale = scale;
+ mOffset = offset;
- if (global_debug > 1) kDebug() << "THEMEMANAGER:: Rescale to " << scale << " \
offset to " << offset; ++ if (global_debug > 1) qCDebug(LSKAT_LOG) << \
"THEMEMANAGER:: Rescale to " << scale << " offset to " << offset;
+ QHashIterator<Themable *, int> it(mObjects);
+ while (it.hasNext())
+ {
+ it.next();
+ Themable *ob = it.key();
+ ob->changeTheme();
+ }
+ }
// Retrieve the theme's scale
double ThemeManager::getScale()
@@@ -279,57 -268,53 +265,53 @@@ const QPixmap ThemeManager::getCard(in
// Get the pixmap for a card back, given the desired card width in pixel
const QPixmap ThemeManager::getCardback(double width)
{
- QSize s(int(width), int(width/mCardAspectRatio));
- if ( s != mCardCache->size() )
- {
- mCardCache->setSize(s);
- QMetaObject::invokeMethod(this, "loadCardsInBackground", Qt::QueuedConnection);
- }
-
- QPixmap pix = mCardCache->backside();
- return pix;
- }
+ QSize s(int(width), int(width / mCardAspectRatio));
+ if (s != mCardCache->size())
+ {
+ mCardCache->setSize(s);
+ QMetaObject::invokeMethod(this, "loadCardsInBackground", \
Qt::QueuedConnection); + }
+ QPixmap pix = mCardCache->backside();
+ return pix;
+ }
// Get a pixmap when its size is given (this can distort the image)
- const QPixmap ThemeManager::getPixmap(QSvgRenderer* renderer, const QString &svgid, \
const QSize &size) + const QPixmap ThemeManager::getPixmap(QSvgRenderer *renderer, \
const QString &svgid, const QSize &size) {
- QPixmap pixmap;
- if (size.width() < 1 || size.height() < 1)
- {
- if (global_debug >1)
- qCDebug(LSKAT_LOG) << "ThemeManager::getPixmap Cannot create svgid ID" << \
svgid << "with zero size" << size;
- return pixmap;
- }
-
+ QPixmap pixmap;
+ if (size.width() < 1 || size.height() < 1)
+ {
+ if (global_debug > 1)
- kDebug() << "ThemeManager::getPixmap Cannot create svgid ID" << svgid \
<< "with zero size" << size; ++ qCDebug(LSKAT_LOG) << "ThemeManager::getPixmap \
Cannot create svgid ID " << svgid << " with zero size" << size; + return \
pixmap; + }
- // Cached pixmap?
- if (mPixmapCache.contains(svgid))
- {
- pixmap = mPixmapCache[svgid];
- if (pixmap.size() == size)
+ // Cached pixmap?
+ if (mPixmapCache.contains(svgid))
{
- return pixmap;
+ pixmap = mPixmapCache[svgid];
+ if (pixmap.size() == size)
+ {
+ return pixmap;
+ }
}
- }
-
- // Create new image
- QImage image(size, QImage::Format_ARGB32_Premultiplied);
- image.fill(0);
- QPainter p(&image);
- renderer->render(&p, svgid);
- p.end();
- pixmap = QPixmap::fromImage(image);
- if (pixmap.isNull())
- qCCritical(LSKAT_LOG) << "ThemeManager::getPixmap Cannot load svgid ID" << \
svgid;
-
- // Cache image
- mPixmapCache[svgid] = pixmap;
-
- return pixmap;
- }
+ // Create new image
+ QImage image(size, QImage::Format_ARGB32_Premultiplied);
+ image.fill(0);
+ QPainter p(&image);
+ renderer->render(&p, svgid);
+ p.end();
+ pixmap = QPixmap::fromImage(image);
+ if (pixmap.isNull())
- kFatal() << "ThemeManager::getPixmap Cannot load svgid ID" << svgid;
++ qCCritical(LSKAT_LOG) << "ThemeManager::getPixmap Cannot load svgid ID " << \
svgid; +
+ // Cache image
+ mPixmapCache[svgid] = pixmap;
+
+ return pixmap;
+ }
// Get a pixmap when its size is given (this can distort the image)
const QPixmap ThemeManager::getPixmap(const QString &svgid, const QSize &size)
@@@ -371,29 -352,25 +349,23 @@@ void ThemeManager::loadCardsInBackgroun
// Constructs a themable interface
Themable::Themable()
{
- mScale = 1.0;
- mThemeManager = 0;
+ mScale = 1.0;
+ mThemeManager = 0;
}
-
- // Constructs a themeable interface given its id and the master theme manager.
- // This automatically registeres the object with the manager.
- Themable::Themable(const QString &id, ThemeManager* thememanager)
+ // Constructs a themable interface given its id and the master theme manager.
+ // This automatically registers the object with the manager.
+ Themable::Themable(const QString &id, ThemeManager *thememanager)
{
- mScale = 1.0;
- mId = id;
- mThemeManager = thememanager;
- if (!thememanager) return;
- thememanager->registerTheme(this);
+ mScale = 1.0;
+ mId = id;
+ mThemeManager = thememanager;
+ if (!thememanager) return;
+ thememanager->registerTheme(this);
}
-
- // Destructs the themeable object
+ // Destructs the themable object
Themable::~Themable()
{
- if (mThemeManager) mThemeManager->unregisterTheme(this);
+ if (mThemeManager) mThemeManager->unregisterTheme(this);
}
--
-
-
-
-#include "thememanager.moc"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic