• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kgoldrunner

kgrdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002     Copyright 2003 Marco Krüger <grisuji@gmx.de>
00003     Copyright 2003 Ian Wadham <ianw2@optusnet.com.au>
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "kgrdialog.h"
00012 
00013 #include "kgrconsts.h"
00014 #include "kgrcanvas.h"
00015 #include "kgrgame.h"
00016 
00017 #include <KGlobalSettings>
00018 #include <QTextStream>
00019 #include <QGridLayout>
00020 #include <QLabel>
00021 #include <QVBoxLayout>
00022 #include <QSpacerItem>
00023 #include <QHeaderView>
00024 
00025 /******************************************************************************/
00026 /*****************    DIALOG BOX TO SELECT A GAME AND LEVEL   *****************/
00027 /******************************************************************************/
00028 
00029 KGrSLDialog::KGrSLDialog (int action, int requestedLevel, int collnIndex,
00030             QList<KGrCollection *> & gamesList, KGrGame * theGame,
00031             QWidget * parent)
00032         : KDialog (parent)
00033 {
00034     slAction     = action;
00035     defaultLevel = requestedLevel;
00036     defaultGame  = collnIndex;
00037     collections  = gamesList;
00038     game         = theGame;
00039     collection   = collections.at(defaultGame);
00040     slParent     = parent;
00041 
00042     int margin      = marginHint(); 
00043     int spacing     = spacingHint(); 
00044     QWidget * dad   = new QWidget(this);
00045     setMainWidget(dad);
00046     setCaption(i18n("Select Game"));
00047     setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Help);
00048     setDefaultButton(KDialog::Ok);
00049 
00050     QVBoxLayout * mainLayout = new QVBoxLayout (dad);
00051     mainLayout->setSpacing(spacing);
00052     mainLayout->setMargin(margin);
00053 
00054     collnL    = new QLabel
00055                 (i18n("<html><b>Please select a game:</b></html>"), dad);
00056     mainLayout->addWidget (collnL, 5);
00057 
00058     colln     = new QTreeWidget (dad);
00059     mainLayout->addWidget (colln, 50);
00060     colln->setColumnCount (4);
00061     colln->setHeaderLabels (QStringList() <<
00062                             i18n("Name of Game") <<
00063                             i18n("Rules") <<
00064                             i18n("Levels") <<
00065                             i18n("Skill"));
00066     colln->setRootIsDecorated (false);
00067 
00068     QHBoxLayout * hboxLayout1 = new QHBoxLayout();
00069     hboxLayout1->setSpacing(6);
00070     hboxLayout1->setMargin(0);
00071 
00072     collnN    = new QLabel ("", dad);   // Name of selected collection.
00073     QFont f = collnN->font();
00074     f.setBold (true);
00075     collnN->setFont (f);
00076     hboxLayout1->addWidget(collnN);
00077 
00078     QSpacerItem * spacerItem1 = new QSpacerItem
00079             (21, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
00080     hboxLayout1->addItem(spacerItem1);
00081 
00082     collnD    = new QLabel ("", dad);       // Description of collection.
00083     hboxLayout1->addWidget(collnD);
00084     mainLayout->addLayout(hboxLayout1, 5);
00085 
00086     collnAbout = new QTextEdit (dad);
00087     collnAbout->setReadOnly (true);
00088     mainLayout->addWidget (collnAbout, 25);
00089 
00090     QFrame * separator = new QFrame (dad);
00091     separator->setFrameShape(QFrame::HLine);
00092     mainLayout->addWidget (separator);
00093 
00094     if ((action == SL_START) || (action == SL_UPD_GAME)) {
00095     dad->   setWindowTitle (i18n("Select Game"));
00096     QLabel * startMsg = new QLabel
00097         ("<b>" + i18n("Level 1 of the selected game is:") + "</b>", dad);
00098     mainLayout->addWidget (startMsg, 5);
00099     }
00100     else {
00101     dad->   setWindowTitle (i18n("Select Game/Level"));
00102     QLabel * selectLev = new QLabel
00103         ("<b>" + i18n("Please select a level:") + "</b>", dad);
00104     mainLayout->addWidget (selectLev, 5);
00105     }
00106 
00107     QGridLayout * grid = new QGridLayout;
00108     mainLayout->addLayout (grid);
00109 
00110     number    = new QScrollBar (Qt::Vertical, dad); // IDW
00111     // IDW number    = new QSlider (Qt::Vertical, dad);
00112     number->setRange(1, 150);
00113     // IDW number->setRange(0, 150); // IDW 0 is kludge for QSlider tick layout.
00114     number->setSingleStep(1);
00115     number->setPageStep(10);
00116     number->setValue(1);
00117     // IDW number->setTickPosition (QSlider::TicksRight);
00118     // IDW number->setTickInterval (number->pageStep());
00119     grid->addWidget (number, 1, 5, 4, 1);
00120 
00121     QWidget * numberPair = new QWidget(dad);
00122     QHBoxLayout *hboxLayout2 = new QHBoxLayout(numberPair);
00123     hboxLayout2->setMargin (0);
00124     numberPair->setLayout(hboxLayout2);
00125     grid->addWidget (numberPair, 1, 1, 1, 3);
00126     numberL   = new QLabel (i18n("Level number:"), numberPair);
00127     display   = new QSpinBox (numberPair);
00128     display->setRange(1, 150);
00129     hboxLayout2->addWidget (numberL);
00130     hboxLayout2->addWidget (display);
00131 
00132     levelNH   = new QPushButton (i18n("Edit Level Name && Hint"), dad);
00133     mainLayout->addWidget (levelNH);
00134 
00135     slName    = new QLabel ("", dad);
00136     grid->addWidget (slName, 2, 1, 1, 4);
00137     thumbNail = new KGrThumbNail (dad);
00138     grid->addWidget (thumbNail, 1, 6, 4, 5);
00139 
00140     // Set thumbnail cell size to about 1/5 of game cell size.
00141     int cellSize = parent->width() / (5 * (FIELDWIDTH + 4));
00142     cellSize = (cellSize < 4) ? 4 : cellSize;
00143     thumbNail-> setFixedWidth  ((FIELDWIDTH  * cellSize) + 2);
00144     thumbNail-> setFixedHeight ((FIELDHEIGHT * cellSize) + 2);
00145 
00146     // Base the geometry of the dialog box on the playing area.
00147     int cell = qMin(parent->height() / (FIELDHEIGHT + 4), parent->width() / FIELDWIDTH + 4);
00148     dad->   setMinimumSize ((FIELDWIDTH*cell/2), (FIELDHEIGHT-3)*cell);
00149 
00150     // Set the default for the level-number in the scrollbar.
00151     number->    setTracking (true);
00152     number->setValue (requestedLevel);
00153 
00154     slSetCollections (defaultGame);
00155 
00156     // Vary the dialog according to the action.
00157     QString s1 = i18nc("Default action at startup of game", "PLAY");
00158     QString s2 = i18nc("Alternate action at startup of game", "Select Level");
00159     QString s3 = i18nc("Alternate action at startup of game", "Use Menu");
00160 
00161     QString OKText = "";
00162     switch (slAction) {
00163     case SL_START:  // Must start at level 1, but can choose a collection.
00164             OKText = i18n("Start Game");
00165             number->setValue (1);
00166             number->setEnabled(false);
00167             display->setEnabled(false);
00168             number->hide();
00169             numberL->hide();
00170             display->hide();
00171             break;
00172     case SL_ANY:    // Can start playing at any level in any collection.
00173             OKText = i18n("Play Level");
00174             break;
00175     case SL_UPDATE: // Can use any level in any collection as edit input.
00176             OKText = i18n("Edit Level");
00177             break;
00178     case SL_CREATE: // Can save a new level only in a USER collection.
00179             OKText = i18n("Save New");
00180             break;
00181     case SL_SAVE:   // Can save an edited level only in a USER collection.
00182             OKText = i18n("Save Change");
00183             break;
00184     case SL_DELETE: // Can delete a level only in a USER collection.
00185             OKText = i18n("Delete Level");
00186             break;
00187     case SL_MOVE:   // Can move a level only into a USER collection.
00188             OKText = i18n("Move To...");
00189             break;
00190     case SL_UPD_GAME:   // Can only edit USER collection details.
00191             OKText = i18n("Edit Game Info");
00192             number->setValue (1);
00193             number->setEnabled(false);
00194             display->setEnabled(false);
00195             number->hide();
00196             numberL->hide();
00197             display->hide();
00198             break;
00199 
00200     default:        break;          // Keep the default settings.
00201     }
00202     if (!OKText.isEmpty()) {
00203     setButtonGuiItem( KDialog::Ok, KGuiItem(OKText));
00204     }
00205 
00206     // Set value in the line-edit box.
00207     slShowLevel (number->value());
00208 
00209     if (display->isEnabled()) {
00210     display->setFocus();            // Set the keyboard input on.
00211     display->selectAll();
00212     }
00213 
00214     // Paint a thumbnail sketch of the level.
00215     thumbNail->setFrameStyle (QFrame::Box | QFrame::Plain);
00216     thumbNail->setLineWidth (1);
00217     slPaintLevel();
00218     thumbNail->show();
00219 
00220     connect (colln,   SIGNAL (itemSelectionChanged()), this, SLOT (slColln()));
00221 
00222     connect (display, SIGNAL (valueChanged (const QString &)),
00223         this, SLOT (slUpdate (const QString &)));
00224 
00225     connect (number,  SIGNAL (valueChanged(int)), this, SLOT(slShowLevel(int)));
00226 
00227     // Only enable name and hint dialog here if saving a new or edited level.
00228     // At other times the name and hint have not been loaded or initialised yet.
00229     if ((slAction == SL_CREATE) || (slAction == SL_SAVE)) {
00230     connect (levelNH,  SIGNAL (clicked()), game, SLOT (editNameAndHint()));
00231     }
00232     else {
00233     levelNH->setEnabled (false);
00234     levelNH->hide();
00235     }
00236 
00237     connect (colln, SIGNAL(itemSelectionChanged()), this, SLOT(slPaintLevel()));
00238     connect (number,  SIGNAL (sliderReleased()), this, SLOT (slPaintLevel()));
00239 
00240     connect (this,    SIGNAL (helpClicked()), this, SLOT (slotHelp ()));
00241 }
00242 
00243 KGrSLDialog::~KGrSLDialog()
00244 {
00245 }
00246 
00247 /******************************************************************************/
00248 /*****************    LOAD THE LIST OF GAMES (COLLECTIONS)    *****************/
00249 /******************************************************************************/
00250 
00251 void KGrSLDialog::slSetCollections (int cIndex)
00252 {
00253     int i;
00254     int imax = collections.count();
00255 
00256     // Set values in the list box that holds details of available games.
00257     // The list is displayed in order of skill then the kind of rules.
00258     colln->clear();
00259     slCollnIndex = -1;
00260 
00261     QList<char> sortOrder1, sortOrder2;     // Crude, but effective.
00262     sortOrder1 << 'N' << 'C' << 'T';
00263     sortOrder2 << 'T' << 'K';
00264 
00265     foreach (char sortItem1, sortOrder1) {
00266     foreach (char sortItem2, sortOrder2) {
00267         for (i = 0; i < imax; i++) {
00268         if ((collections.at(i)->skill == sortItem1) &&
00269             (collections.at(i)->settings == sortItem2)) {
00270             QStringList data;
00271             data
00272             << collections.at(i)->name
00273             << ((collections.at(i)->settings == 'K') ? 
00274                 i18nc("Rules", "KGoldrunner") :
00275                 i18nc("Rules", "Traditional"))
00276             << QString().setNum (collections.at(i)->nLevels)
00277             << ((collections.at(i)->skill == 'T') ? 
00278                 i18nc("Skill Level", "Tutorial") :
00279                 ((collections.at(i)->skill == 'N') ? 
00280                 i18nc("Skill Level", "Normal") :
00281                 i18nc("Skill Level", "Championship")));
00282             KGrGameListItem * thisGame = new KGrGameListItem (data, i);
00283             colln->addTopLevelItem (thisGame);
00284 
00285             if (slCollnIndex < 0) {
00286             slCollnIndex = i; // There is at least one collection.
00287             }
00288             if (i == cIndex) {
00289             // Mark the currently selected collection (default 0).
00290             colln->setCurrentItem (thisGame);
00291             }
00292         }
00293         } // End "for" loop.
00294     }
00295     }
00296 
00297     if (slCollnIndex < 0) {
00298     return;             // There are no collections (unlikely).
00299     }
00300 
00301     // Fetch and display information on the selected collection.
00302     slColln ();
00303 
00304     // Make the column for the game's name a bit wider.
00305     colln->header()->setResizeMode (0, QHeaderView::ResizeToContents);
00306     colln->header()->setResizeMode (1, QHeaderView::ResizeToContents);
00307     colln->header()->setResizeMode (2, QHeaderView::ResizeToContents);
00308 }
00309 
00310 /******************************************************************************/
00311 /*****************    SLOTS USED BY LEVEL SELECTION DIALOG    *****************/
00312 /******************************************************************************/
00313 
00314 void KGrSLDialog::slColln ()
00315 {
00316 
00317     if (slCollnIndex < 0) {
00318     // Ignore the "highlighted" signal caused by inserting in an empty box.
00319     return;
00320     }
00321 
00322     if (colln->selectedItems().size() <= 0) {
00323     return;
00324     }
00325 
00326     slCollnIndex = (dynamic_cast<KGrGameListItem *>
00327             (colln->selectedItems().first()))->id();
00328     int n = slCollnIndex;               // Collection selected.
00329     int N = defaultGame;                // Current collection.
00330     if (collections.at(n)->nLevels > 0) {
00331     number->setMaximum (collections.at(n)->nLevels);
00332     display->setMaximum (collections.at(n)->nLevels);
00333     }
00334     else {
00335     number->setMaximum (1);         // Avoid range errors.
00336     display->setMaximum (1);
00337     }
00338 
00339     // Set a default level number for the selected collection.
00340     switch (slAction) {
00341     case SL_ANY:
00342     case SL_UPDATE:
00343     case SL_DELETE:
00344     case SL_UPD_GAME:
00345     // If selecting the current collection, use the current level number.
00346     if (n == N)
00347         number->setValue (defaultLevel);
00348     else
00349         number->setValue (1);           // Else use level 1.
00350     break;
00351     case SL_CREATE:
00352     case SL_SAVE:
00353     case SL_MOVE:
00354     if ((n == N) && (slAction != SL_CREATE)) {
00355         // Saving/moving level in current collection: use current number.
00356         number->setValue (defaultLevel);
00357     }
00358     else {
00359         // Saving new/edited level or relocating a level: use "nLevels + 1".
00360         number->setMaximum (collections.at(n)->nLevels + 1);
00361         display->setMaximum (collections.at(n)->nLevels + 1);
00362         number->setValue (number->maximum());
00363     }
00364     break;
00365     default:
00366     number->setValue (1);               // Default is level 1.
00367     break;
00368     }
00369 
00370     slShowLevel (number->value());
00371 
00372     int levCnt = collections.at(n)->nLevels;
00373     if (collections.at(n)->settings == 'K')
00374     collnD->setText (i18np("1 level, uses KGoldrunner rules.",
00375                 "%1 levels, uses KGoldrunner rules.", levCnt));
00376     else
00377     collnD->setText (i18np("1 level, uses Traditional rules.",
00378                 "%1 levels, uses Traditional rules.", levCnt));
00379     collnN->setText (collections.at(n)->name);
00380     QString s;
00381     if (collections.at(n)->about.isEmpty()) {
00382     s = i18n("Sorry, there is no further information about this game.");
00383     }
00384     else {
00385     s = (i18n(collections.at(n)->about.toUtf8().constData()));
00386     } 
00387     collnAbout->setText (s);
00388 }
00389 
00390 void KGrSLDialog::slShowLevel (int i)
00391 {
00392     // Display the level number as the slider is moved.
00393     // IDW // QSlider has minimum = zero: that gets the tick-marks laid out OK.
00394     // IDW if (i <= 0) {
00395     // IDW i = 1;
00396     // IDW number->setValue(i);     // Force the level to be >= 1.
00397     // IDW }
00398     display->setValue(i);
00399 }
00400 
00401 void KGrSLDialog::slUpdate (const QString & text)
00402 {
00403     // Move the slider when a valid level number is entered.
00404     QString s = text;
00405     bool ok = false;
00406     int n = s.toInt (&ok);
00407     if (ok) {
00408     number->setValue (n);
00409     slPaintLevel();
00410     }
00411     else
00412     KGrMessage::information (this, i18n("Select Level"),
00413         i18n("This level number is not valid. It can not be used."));
00414 }
00415 
00416 void KGrSLDialog::slPaintLevel ()
00417 {
00418     // Repaint the thumbnail sketch of the level whenever the level changes.
00419     int n = slCollnIndex;
00420     if (n < 0) {
00421     return;                 // Owner has no collections.
00422     }
00423     // Fetch level-data and save layout, name and label in the thumbnail.
00424     QString dir = game->getDirectory (collections.at(n)->owner);
00425     thumbNail->setLevelData (dir, collections.at(n)->prefix,
00426                 number->value(), slName);
00427     thumbNail->repaint();           // Will call "paintEvent (e)".
00428 }
00429 
00430 void KGrSLDialog::slotHelp ()
00431 {
00432     // Help for "Select Game and Level" dialog box.
00433     QString s =
00434     i18n("The main button at the bottom echoes the "
00435     "menu action you selected. Click it after choosing "
00436     "a game and level - or use \"Cancel\".");
00437 
00438     if (slAction == SL_START) {
00439     s += i18n("\n\nIf this is your first time in KGoldrunner, select the "
00440          "tutorial game or click \"Cancel\" and click that item in "
00441          "the Game or Help menu. The tutorial game gives you hints "
00442          "as you go.\n\n"
00443          "Otherwise, just click on the name of a game (in the list box), "
00444          "then, to start at level 001, click on the main button at the "
00445          "bottom. Play begins when you move the mouse or press a key.");
00446     }
00447     else {
00448     switch (slAction) {
00449     case SL_UPDATE:
00450         s += i18n("\n\nYou can select System levels for editing (or "
00451          "copying), but you must save the result in a game you have "
00452          "created. Use the mouse as a paintbrush and the editor "
00453          "toolbar buttons as a palette. Use the 'Empty Space' button "
00454          "to erase.");
00455         break;
00456     case SL_CREATE:
00457         s += i18n("\n\nYou can add a name and hint to your new level here, "
00458          "but you must save the level you have created into one of "
00459          "your own games. By default your new level will go at the "
00460          "end of your game, but you can also select a level number and "
00461          "save into the middle of your game.");
00462         break;
00463     case SL_SAVE:
00464         s += i18n("\n\nYou can create or edit a name and hint here, before "
00465          "saving. If you change the game or level, you can do a copy "
00466          "or \"Save As\", but you must always save into one of your "
00467          "own games. If you save a level into the middle of a series, "
00468          "the other levels are automatically re-numbered.");
00469         break;
00470     case SL_DELETE:
00471         s += i18n("\n\nYou can only delete levels from one of your own "
00472          "games. If you delete a level from the middle of a series, "
00473          "the other levels are automatically re-numbered.");
00474         break;
00475     case SL_MOVE:
00476         s += i18n("\n\nTo move (re-number) a level, you must first select "
00477          "it by using \"Edit Any Level...\", then you can use "
00478          "\"Move Level...\" to assign it a new number or even a different "
00479          "game. Other levels are automatically re-numbered as "
00480          "required. You can only move levels within your own games.");
00481         break;
00482     case SL_UPD_GAME:
00483         s += i18n("\n\nWhen editing game info you only need to choose a "
00484          "game, then you can go to a dialog where you edit the "
00485          "details of the game.");
00486         break;
00487     default:
00488         break;
00489     }
00490     s += i18n("\n\nClick on the list box to choose a game.  "
00491          "Below the list box you can see more information about the "
00492          "selected game, including how many levels there are and what "
00493          "rules the enemies follow (see the Settings menu).\n\n"
00494          "You select "
00495          "a level number by typing it or using the scroll bar.  As "
00496          "you vary the game or level, the thumbnail area shows a "
00497          "preview of your choice.");
00498     }
00499 
00500     KGrMessage::information (slParent, i18n("Help: Select Game & Level"), s);
00501 }
00502 
00503 /*******************************************************************************
00504 *************** DIALOG BOX TO CREATE/EDIT A LEVEL NAME AND HINT ****************
00505 *******************************************************************************/
00506 
00507 KGrNHDialog::KGrNHDialog(const QString & levelName, const QString & levelHint,
00508             QWidget * parent)
00509         : KDialog (parent)
00510 {
00511     setCaption(i18n("Edit Name & Hint"));
00512     setButtons(KDialog::Ok | KDialog::Cancel);
00513     setDefaultButton(KDialog::Ok);
00514     int margin      = marginHint();
00515     int spacing     = spacingHint();
00516     QWidget * dad   = new QWidget(this);
00517     setMainWidget(dad);
00518 
00519     QVBoxLayout * mainLayout = new QVBoxLayout (dad);
00520     mainLayout->setSpacing(spacing);
00521     mainLayout->setMargin(margin);
00522 
00523     QLabel *        nameL  = new QLabel (i18n("Name of level:"), dad);
00524     mainLayout->addWidget (nameL);
00525             nhName  = new QLineEdit (dad);
00526     mainLayout->addWidget (nhName);
00527 
00528     QLabel *        mleL = new QLabel (i18n("Hint for level:"), dad);
00529     mainLayout->addWidget (mleL);
00530 
00531    // Set up a widget to hold the wrapped text, using \n for paragraph breaks.
00532             mle = new QTextEdit (dad);
00533     mle->       setAcceptRichText (false);
00534     mainLayout->addWidget (mle);
00535 
00536     // Base the geometry of the text box on the playing area.
00537     QPoint      p = parent->mapToGlobal (QPoint (0,0));
00538     int         c = parent->width() / (FIELDWIDTH + 4);
00539     dad->       move (p.x()+4*c, p.y()+4*c);
00540     mle->       setMinimumSize ((FIELDWIDTH*c/2), (FIELDHEIGHT/2)*c);
00541 
00542     // Configure the text box.
00543     mle->       setAlignment (Qt::AlignLeft);
00544 
00545     nhName->        setText (levelName);
00546     mle->       setText (levelHint);
00547 }
00548 
00549 KGrNHDialog::~KGrNHDialog()
00550 {
00551 }
00552 
00553 /*******************************************************************************
00554 *************** DIALOG BOX TO CREATE OR EDIT A GAME (COLLECTION) ***************
00555 *******************************************************************************/
00556 
00557 KGrECDialog::KGrECDialog (int action, int collnIndex,
00558             QList<KGrCollection *> & gamesList,
00559             QWidget * parent)
00560         : KDialog(parent)
00561 {
00562     collections  = gamesList;
00563     defaultGame  = collnIndex;
00564 
00565     setCaption(i18n("Edit Game Info"));
00566     setButtons(KDialog::Ok | KDialog::Cancel);
00567     setDefaultButton(KDialog::Ok);
00568     int margin      = marginHint();
00569     int spacing     = spacingHint();
00570     QWidget * dad   = new QWidget(this);
00571     setMainWidget(dad);
00572 
00573     QVBoxLayout * mainLayout = new QVBoxLayout (dad);
00574     mainLayout->setSpacing(spacing);
00575     mainLayout->setMargin(margin);
00576 
00577     QHBoxLayout *hboxLayout5 = new QHBoxLayout();
00578     hboxLayout5->setSpacing (spacing);
00579     nameL    = new QLabel (i18n("Name of game:"), dad);
00580     hboxLayout5->addWidget(nameL);
00581     ecName   = new QLineEdit (dad);
00582     hboxLayout5->addWidget(ecName);
00583     mainLayout->addLayout(hboxLayout5);
00584 
00585     QHBoxLayout *hboxLayout6 = new QHBoxLayout();
00586     hboxLayout6->setSpacing (spacing);
00587     prefixL  = new QLabel (i18n("File name prefix:"), dad);
00588     hboxLayout6->addWidget(prefixL);
00589     ecPrefix = new QLineEdit (dad);
00590     hboxLayout6->addWidget(ecPrefix);
00591     mainLayout->addLayout(hboxLayout6);
00592 
00593     //In Qt4, QButtonGroup is no longer a widget...
00594     ecGrp    = new QButtonGroup (dad);
00595     ecTradB  = new QRadioButton (i18n("Traditional rules"), dad); //last parameter was ecGrp
00596     ecKGrB   = new QRadioButton (i18n("KGoldrunner rules"), dad); //last parameter was ecGrp
00597     ecGrp->addButton(ecTradB);
00598     ecGrp->addButton(ecKGrB);
00599 
00600     //..so we need to add the radio buttons directly to the layout
00601     mainLayout->addWidget (ecTradB);
00602     mainLayout->addWidget (ecKGrB);
00603 
00604 
00605     nLevL    = new QLabel (i18n( "0 levels" ), dad);
00606     mainLayout->addWidget (nLevL);
00607 
00608     mleL     = new QLabel (i18n("About this game:"), dad);
00609     mainLayout->addWidget (mleL);
00610 
00611    // Set up a widget to hold the wrapped text, using \n for paragraph breaks.
00612     mle      = new QTextEdit (dad);
00613     mle->    setAcceptRichText (false);
00614     mainLayout->addWidget (mle);
00615 
00616     QPoint p = parent->mapToGlobal (QPoint (0,0));
00617 
00618     // Base the geometry of the dialog box on the playing area.
00619     int cell = parent->width() / (FIELDWIDTH + 4);
00620     dad->   move (p.x()+2*cell, p.y()+2*cell);
00621     dad->   setMinimumSize ((FIELDWIDTH*cell/2), (FIELDHEIGHT-1)*cell);
00622 
00623     if (action == SL_CR_GAME) {
00624          setCaption (i18n("Create Game"));
00625     }
00626     else {
00627          setCaption (i18n("Edit Game Info"));
00628     }
00629 
00630     QString OKText = "";
00631     if (action == SL_UPD_GAME) {        // Edit existing collection.
00632     ecName->    setText (collections.at(defaultGame)->name);
00633     ecPrefix->  setText (collections.at(defaultGame)->prefix);
00634     if (collections.at(defaultGame)->nLevels > 0) {
00635         // Collection already has some levels, so cannot change the prefix.
00636         ecPrefix->  setEnabled (false);
00637     }
00638     QString     s;
00639     nLevL->     setText (i18np("1 level", "%1 levels",
00640                     collections.at(defaultGame)->nLevels));
00641     OKText = i18n("Save Changes");
00642     }
00643     else {                  // Create a collection.
00644     ecName->        setText ("");
00645     ecPrefix->      setText ("");
00646     nLevL->         setText (i18n("0 levels"));
00647     OKText = i18n("Save New");
00648     }
00649     setButtonGuiItem( KDialog::Ok, KGuiItem(OKText));
00650 
00651     if ((action == SL_CR_GAME) ||
00652     (collections.at(defaultGame)->settings == 'T')) {
00653     ecSetRules ('T');           // Traditional settings.
00654     }
00655     else {
00656     ecSetRules ('K');           // KGoldrunner settings.
00657     }
00658 
00659     // Configure the edit box.
00660     mle->       setAlignment (Qt::AlignLeft);
00661 
00662     if ((action == SL_UPD_GAME) &&
00663     (collections.at(defaultGame)->about.length() > 0)) {
00664     // Display and edit the game description in its original language.
00665     mle->       setText (collections.at(defaultGame)->about);
00666     }
00667     else {
00668     mle->       setText ("");
00669     }
00670 
00671     connect (ecKGrB,  SIGNAL (clicked ()), this, SLOT (ecSetKGr ()));
00672     connect (ecTradB, SIGNAL (clicked ()), this, SLOT (ecSetTrad ()));
00673 }
00674 
00675 KGrECDialog::~KGrECDialog()
00676 {
00677 }
00678 
00679 void KGrECDialog::ecSetRules (const char settings)
00680 {
00681     ecKGrB->    setChecked (false);
00682     ecTradB->   setChecked (false);
00683     if (settings == 'K')
00684     ecKGrB->    setChecked (true);
00685     else
00686     ecTradB->   setChecked (true);
00687 }
00688 
00689 void KGrECDialog::ecSetKGr ()  {ecSetRules ('K');}  // Radio button slots.
00690 void KGrECDialog::ecSetTrad () {ecSetRules ('T');}
00691 
00692 /*******************************************************************************
00693 ***************  DIALOG TO SELECT A SAVED GAME TO BE RE-LOADED  ****************
00694 *******************************************************************************/
00695 
00696 KGrLGDialog::KGrLGDialog (QFile * savedGames,
00697             QList<KGrCollection *> & collections,
00698             QWidget * parent)
00699         : KDialog (parent)
00700 {
00701     setCaption(i18n("Select Saved Game"));
00702     setButtons(KDialog::Ok | KDialog::Cancel);
00703     setDefaultButton(KDialog::Ok);
00704     int margin      = marginHint();
00705     int spacing     = spacingHint();
00706     QWidget * dad   = new QWidget(this);
00707     setMainWidget(dad);
00708 
00709     QVBoxLayout *   mainLayout = new QVBoxLayout (dad);
00710     mainLayout->setSpacing(spacing);
00711     mainLayout->setMargin(margin);
00712 
00713     QLabel *        lgHeader = new QLabel (
00714             i18n("Game                       Level/Lives/Score   "
00715             "Day    Date     Time  "), dad);
00716 
00717     lgList   = new QListWidget (dad);
00718     QFont       f = KGlobalSettings::fixedFont();   // KDE version.
00719             f.setFixedPitch (true);
00720     lgList->        setFont (f);
00721             f.setBold (true);
00722     lgHeader->      setFont (f);
00723 
00724     mainLayout->    addWidget (lgHeader);
00725     mainLayout->    addWidget (lgList);
00726 
00727     // Base the geometry of the list box on the playing area.
00728     QPoint      p = parent->mapToGlobal (QPoint (0,0));
00729     int         c = parent->width() / (FIELDWIDTH + 4);
00730     dad->       move (p.x()+2*c, p.y()+2*c);
00731     lgList->        setMinimumHeight ((FIELDHEIGHT/2)*c);
00732 
00733             lgHighlight  = -1;
00734 
00735     QTextStream     gameText (savedGames);
00736     QString     s = "";
00737     QString     pr = "";
00738     int         i;
00739     int         imax = collections.count();
00740 
00741     // Read the saved games into the list box.
00742     while (! gameText.endData()) {
00743     s = gameText.readLine();        // Read in one saved game.
00744     pr = s.left (s.indexOf (" ", 0, Qt::CaseInsensitive));  // Get the collection prefix.
00745     for (i = 0; i < imax; i++) {        // Get the collection name.
00746         if (collections.at(i)->prefix == pr) {
00747         s = s.insert (0,
00748             collections.at(i)->name.leftJustified (20, ' ', true) + ' ');
00749         break;
00750         }
00751     }
00752     lgList-> addItem (s);
00753     }
00754     savedGames->close();
00755 
00756     // Mark row 0 (the most recently saved game) as the default selection.
00757     lgList->    setSelectionMode (QAbstractItemView::SingleSelection);
00758     lgList->    setCurrentRow (0);
00759     lgList->    setItemSelected  (lgList->currentItem(), true);
00760         lgHighlight = 0;
00761 
00762     connect (lgList, SIGNAL ( itemClicked ( QListWidgetItem * )),
00763         this, SLOT (lgSelect (QListWidgetItem *)));
00764 }
00765 
00766 void KGrLGDialog::lgSelect (QListWidgetItem * item)
00767 {
00768     lgHighlight = lgList->row(item);
00769 }
00770 
00771 /*******************************************************************************
00772 ***********************  CENTRALIZED MESSAGE FUNCTIONS  ************************
00773 *******************************************************************************/
00774 
00775 void KGrMessage::information (QWidget * parent,
00776             const QString &caption, const QString &text)
00777 {
00778     // KDE does word-wrapping and will observe "\n" line-breaks.
00779     KMessageBox::information (parent, text, caption);
00780 }
00781 
00782 int KGrMessage::warning (QWidget * parent, const QString &caption,
00783             const QString &text, const QString &label0,
00784             const QString &label1, const QString &label2)
00785 {
00786     // KDE does word-wrapping and will observe "\n" line-breaks.
00787     int ans = 0;
00788     if (label2.isEmpty()) {
00789     // Display a box with 2 buttons.
00790     ans = KMessageBox::questionYesNo (parent, text, caption,
00791                 KGuiItem(label0), KGuiItem(label1));
00792     ans = (ans == KMessageBox::Yes) ? 0 : 1;
00793     }
00794     else {
00795     // Display a box with 3 buttons.
00796     ans = KMessageBox::questionYesNoCancel (parent, text, caption,
00797                 KGuiItem(label0), KGuiItem(label1));
00798     if (ans == KMessageBox::Cancel)
00799         ans = 2;
00800     else
00801         ans = (ans == KMessageBox::Yes) ? 0 : 1;
00802     }
00803     return (ans);
00804 }
00805 
00806 /*******************************************************************************
00807 *************************  ITEM FOR THE LIST OF GAMES  *************************
00808 *******************************************************************************/
00809 
00810 KGrGameListItem::KGrGameListItem (const QStringList & data,
00811                                   const int internalId)
00812         : QTreeWidgetItem (data)
00813 {
00814     mInternalId = internalId;
00815 }
00816 
00817 int KGrGameListItem::id () const
00818 {
00819     return mInternalId;
00820 }
00821 
00822 void KGrGameListItem::setId (const int internalId)
00823 {
00824     mInternalId = internalId;
00825 }
00826 
00827 #include "kgrdialog.moc"

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal