KCardDialog Class Reference

#include <kcarddialog.h>

List of all members.


Detailed Description

A carddeck selection dialog for card games.

The KCardDialog provides a dialog for interactive carddeck selection. It gives cardgames an easy to use interface to select front and back of the card sets. As card sets the KDE default cardsets are offered as well as used specified ones.

In most cases, the simplest use of this class is the static method KCardDialog::getCardDeck, which pops up the dialog, allows the user to select a carddeck, and returns when the dialog is closed. Only if you really need some specific behaviour or if you overwrite the dialog you need all the other access functions.

Example:

      QString deck,card;
      int result = KCardDialog::getCardDeck(deck,card );
      if ( result == KCardDialog::Accepted )
            ...

Here you can see a card dialog in action

kcarddialog.png

KCarddialog

KCardDialog::getCardDeck takes a lot of different parameters which are probably very useful. You can e.g. use the parameters randomDeck and randomCardDir to give the end-user the ability to choose a random deck/carddir. You have to save the value of those parameters in your config file - that's why the parameters are needed.

You can also provide a KConfig pointer (usually kapp->config()). This pointer is used to store information about the dialog in an own group ("KCardDailog"). So you can just ignore the randomCardDir and randomDeck values and call KCardDialog::getConfigCardDeck instead. The only reson for this function is to read a previously written configuration and give you the information about it. This way you don't have to save any configuration on your own - KCardDialog does this for you.

Another Parameter for KCardDialog::getCardDeck is scale. This pointer to a double variable contains the scaling factor the user has chosen in the dialog (the scale box won't be shown if you don't provide this parameter). You might want to check out QPixmap::xFrom which gives you access to scaling. You can e.g. use

 QWMatrix m;
 m.scale(s,s);
 pixmap.xForm(m);
to scale your pixmap.

Author:
Martin Heni <martin@heni-online.de>
Version:
Id
kcarddialog.h 465369 2005-09-29 14:33:08Z mueller

Definition at line 90 of file kcarddialog.h.


Public Types

enum  CardFlags { Both = 0, NoDeck = 0x01, NoCards = 0x02 }

Public Member Functions

 KCardDialog (QWidget *parent=NULL, const char *name=NULL, CardFlags flags=Both)
 ~KCardDialog ()
void showRandomDeckBox (bool s)
void showRandomCardDirBox (bool s)
const QString & deck () const
void setDeck (const QString &file)
const QString & cardDir () const
void setCardDir (const QString &dir)
CardFlags flags () const
void setupDialog (bool showResizeBox=false)
bool isRandomDeck () const
bool isRandomCardDir () const
bool isGlobalDeck () const
bool isGlobalCardDir () const
double cardScale () const
void loadConfig (KConfig *conf)
void saveConfig (KConfig *conf)

Static Public Member Functions

static int getCardDeck (QString &deck, QString &carddir, QWidget *parent=0, CardFlags flags=Both, bool *randomDeck=0, bool *randomCardDir=0, double *scale=0, KConfig *conf=0)
static void getConfigCardDeck (KConfig *conf, QString &deck, QString &cardDir, double &scale)
static QString getDefaultDeck ()
static QString getDefaultCardDir ()
static QString getCardPath (const QString &carddir, int index)
static QString getRandomDeck ()
static QString getRandomCardDir ()

Protected Slots

void slotDeckClicked (QIconViewItem *)
void slotCardClicked (QIconViewItem *)
void slotRandomCardDirToggled (bool on)
void slotRandomDeckToggled (bool on)
void slotCardResized (int)
void slotDefaultSize ()
void slotSetGlobalDeck ()
void slotSetGlobalCardDir ()

Protected Member Functions

void insertCardIcons ()
void insertDeckIcons ()

Static Protected Member Functions

static void getGlobalDeck (QString &cardDir, bool &random)
static void getGlobalCardDir (QString &deck, bool &random)
static QString getDeckName (const QString &desktop)
static QString group ()

Member Enumeration Documentation

  • Both - both are shown

  • NoDeck - The deck (back) selection is not shown
  • NoCards - The cards (front) selection is not shown

Definition at line 101 of file kcarddialog.h.


Constructor & Destructor Documentation

KCardDialog::KCardDialog ( QWidget *  parent = NULL,
const char *  name = NULL,
CardFlags  flags = Both 
)

Constructs a card deck selection dialog.

Parameters:
parent The parent widget of the dialog, if any.
name The name of the dialog.
flags Specifies whether the dialog is modal or not.

Definition at line 531 of file kcarddialog.cpp.

KCardDialog::~KCardDialog (  ) 

Destructs a card deck selection dialog.

Definition at line 524 of file kcarddialog.cpp.


Member Function Documentation

int KCardDialog::getCardDeck ( QString &  deck,
QString &  carddir,
QWidget *  parent = 0,
CardFlags  flags = Both,
bool *  randomDeck = 0,
bool *  randomCardDir = 0,
double *  scale = 0,
KConfig *  conf = 0 
) [static]

Creates a modal carddeck dialog, lets the user choose a deck, and returns when the dialog is closed.

Parameters:
deck a reference to the filename used as backside of the cards. It is an absolute path and can directly be loaded as pixmap.
carddir a reference to the directory name used as front of the cards. The directory contains the card images as 1.png to 52.png
parent an optional pointer to the parent window of the dialog
flags what to show
randomDeck if this pointer is non-zero, *ok is set to TRUE if the user wants a random deck otherwise to FALSE. Use this in the config file of your game to load a random deck on startup. See getRandomDeck()
randomCardDir if this pointer is non-zero, *ok is set to TRUE if the user wants a random card otherwise to FALSE. Use this in the config file of your game to load a random card foregrounds on startup. See getRandomCardDir()
scale If non-zero a box is shown which provides the possibility to change the size of the cards. The desired scaling factor is returned to the game in this variable.
conf If non-zero KCardDialog reads the initial settings for this dialog from the applications config file and stores them there when the dialog is closed. You can just use getConfigCardDeck to get the deck/carddir the user selected before. Note that the parameters randomDeck and randomCardDir overwrite the initial settings from the config file.
Returns:
QDialog::result().

Definition at line 112 of file kcarddialog.cpp.

void KCardDialog::getConfigCardDeck ( KConfig *  conf,
QString &  deck,
QString &  cardDir,
double &  scale 
) [static]

Read the configuration from the applications rc file and put the previously chosen deck/frontside in the parameter deck and carddir.

You probably want to use this function on startup of your program so that the user gets exactly the card/frontside he/she chose before. Note that you don't have to care whether the user wants to get a random carddeck or not as this function takes care of this.

Parameters:
conf The config file to read from
deck This will contain the chosen deck from the config file (or a random deck if this is desired according to the config)
cardDir This will contain the chosen cardDir from the config file (or a random cardDir if this is desired according to the config)
scale The scaling factor (usually 1)

Definition at line 179 of file kcarddialog.cpp.

QString KCardDialog::getDefaultDeck (  )  [static]

Returns the default path to the card deck backsides.

You want to use this usually before the user used the card dialog the first time to get a default deck. You can assume that

   getDefaultDeckPath()
is a valid deck.

Returns:
The default path

Definition at line 218 of file kcarddialog.cpp.

QString KCardDialog::getDefaultCardDir (  )  [static]

Returns the default path to the card frontsides.

You want to use this usually before the user used the card dialog the first time to get an default deck. You can assume that

   getCardPath(getDefaultCardPath(), *)
are valid cards for * from 1 to 52.

Returns:
returns the path to the card directory

Definition at line 224 of file kcarddialog.cpp.

QString KCardDialog::getCardPath ( const QString &  carddir,
int  index 
) [static]

Returns the path to the card frontside specified in dir carddir.

Parameters:
index the card to open
carddir The carddir which's path shall be searched for
Returns:
returns the path to the card

Definition at line 232 of file kcarddialog.cpp.

QString KCardDialog::getRandomDeck (  )  [static]

Returns a random deck in deckPath().

Returns:
A random deck

Definition at line 574 of file kcarddialog.cpp.

QString KCardDialog::getRandomCardDir (  )  [static]

Returns a random directory of cards.

Returns:
A random card dir

Definition at line 586 of file kcarddialog.cpp.

void KCardDialog::showRandomDeckBox ( bool  s  ) 

Show or hides the "random backside" checkbox.

Parameters:
s Shows the checkbox if true otherwise hides it

Definition at line 599 of file kcarddialog.cpp.

void KCardDialog::showRandomCardDirBox ( bool  s  ) 

Show or hides the "random foreside" checkbox.

Parameters:
s Shows the checkbox if true otherwise hides it

Definition at line 610 of file kcarddialog.cpp.

const QString & KCardDialog::deck (  )  const

Returns the chosen deck, which is a valid path to a imagefile.

Returns:
The deck

Definition at line 247 of file kcarddialog.cpp.

void KCardDialog::setDeck ( const QString &  file  ) 

Sets the default deck.

Parameters:
file The full path to an image file

Definition at line 248 of file kcarddialog.cpp.

const QString & KCardDialog::cardDir (  )  const

Returns:
The chosen card directory

Definition at line 249 of file kcarddialog.cpp.

void KCardDialog::setCardDir ( const QString &  dir  ) 

Sets the default card directory.

Parameters:
dir The full path to an card directory

Definition at line 250 of file kcarddialog.cpp.

KCardDialog::CardFlags KCardDialog::flags (  )  const

Returns:
the flags set to the dialog

Definition at line 251 of file kcarddialog.cpp.

void KCardDialog::setupDialog ( bool  showResizeBox = false  ) 

Creates the default widgets in the dialog.

Must be called after all flags are set. This is only needed if you do NOT use the getCardDeck static function which provides all calls for you.

Definition at line 262 of file kcarddialog.cpp.

bool KCardDialog::isRandomDeck (  )  const

Returns:
TRUE if the selected deck is a random deck (i.e.

the user checked the random checkbox) otherwise FALSE

Definition at line 253 of file kcarddialog.cpp.

bool KCardDialog::isRandomCardDir (  )  const

Returns:
TRUE if the selected carddir is a random dir (i.e.

the user checked the random checkbox) otherwise FALSE

Definition at line 255 of file kcarddialog.cpp.

bool KCardDialog::isGlobalDeck (  )  const

Returns:
TRUE if the global checkbox was selected

Definition at line 257 of file kcarddialog.cpp.

bool KCardDialog::isGlobalCardDir (  )  const

Returns:
TRUE if the global checkbox was selected

Definition at line 259 of file kcarddialog.cpp.

double KCardDialog::cardScale (  )  const

Returns:
The scaling factor of the card pixmap

Definition at line 252 of file kcarddialog.cpp.

void KCardDialog::loadConfig ( KConfig *  conf  ) 

Load the default settings into the dialog (e.g.

whether the "use random deck" checkbox is checked or not).

Definition at line 646 of file kcarddialog.cpp.

void KCardDialog::saveConfig ( KConfig *  conf  ) 

Saves the KCardDialog config into a config file.

This should be the applications config file - KCardDialog creates an own group ("KCardDialog"). These settings are used by loadConfig and getConfigCardDeck.

Definition at line 720 of file kcarddialog.cpp.

static QString KCardDialog::group (  )  [static, protected]

Returns:
the groupname used by functions like saveConfig and loadConfig.


The documentation for this class was generated from the following files:
KDE Home | KDE Accessibility Home | Description of Access Keys