author | zecke <zecke> | 2003-01-22 14:52:17 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-01-22 14:52:17 (UTC) |
commit | 36fab41fa6b38b9f3aa5ecd74b750eaf739beb16 (patch) (side-by-side diff) | |
tree | 44c886f9d6673b8d0ac1c446fa9cbcabad6d9bb3 | |
parent | aa611367a06617e9ad12bd6787ce255a5965f695 (diff) | |
download | opie-36fab41fa6b38b9f3aa5ecd74b750eaf739beb16.zip opie-36fab41fa6b38b9f3aa5ecd74b750eaf739beb16.tar.gz opie-36fab41fa6b38b9f3aa5ecd74b750eaf739beb16.tar.bz2 |
make it build with Qt/X11
for running one need to copy the kpacman.conf from share/kpacman to ~/Settings
-rw-r--r-- | noncore/games/kpacman/kpacman.cpp | 4 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacmanwidget.cpp | 5 | ||||
-rw-r--r-- | noncore/games/kpacman/portable.h | 5 | ||||
-rw-r--r-- | noncore/games/kpacman/status.cpp | 1 |
4 files changed, 8 insertions, 7 deletions
diff --git a/noncore/games/kpacman/kpacman.cpp b/noncore/games/kpacman/kpacman.cpp index d9d2d69..aee8eea 100644 --- a/noncore/games/kpacman/kpacman.cpp +++ b/noncore/games/kpacman/kpacman.cpp @@ -1,364 +1,364 @@ #include "portable.h" #if defined( KDE2_PORT ) #include <kpacman.h> #include <kpacman.moc> #include <kcolordlg.h> #elif defined( QPE_PORT ) #include <qmenubar.h> #include "config.h" #include <qapplication.h> #include "kpacman.h" #endif #include <qkeycode.h> #include <qcolor.h> #include <qstring.h> #include <qpopmenu.h> #include <qmsgbox.h> Kpacman::Kpacman(QWidget *parent, const char *name) : KTMainWindow(parent, name) { schemesPopup = new QList<QPopupMenu>; schemesPopup->setAutoDelete(TRUE); menu(); m_view = new QWidget( this, "m_view" ); m_view->setBackgroundColor( black ); m_layout = new QGridLayout( m_view ); m_layout->setMargin( 7 ); view = new KpacmanWidget( this, QString(name)+"widget"); m_layout->addWidget( view, 0, 0 ); setCaption( "KPacman" ); view->referee->setFocus(); connect(view->referee, SIGNAL(setScore(int, int)), view->score, SLOT(setScore(int, int))); connect(view->referee, SIGNAL(setPoints(int)), view->score, SLOT(set(int))); connect(view->referee, SIGNAL(setLifes(int)), view->status, SLOT(setLifes(int))); connect(view->referee, SIGNAL(setLevel(int)), view->status, SLOT(setLevel(int))); connect(view->referee, SIGNAL(forcedHallOfFame(bool)), this, SLOT(forcedHallOfFame(bool))); connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused())); connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew())); connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew())); connect(view->score, SIGNAL(forcedHallOfFame(bool)), this, SLOT(forcedHallOfFame(bool))); APP_CONFIG_BEGIN( cfg ); focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE); focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE); hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE); APP_CONFIG_END( cfg ); toggleFocusOutPause(); toggleFocusInContinue(); toggleHideMouseCursor(); setCentralWidget( m_view ); } Kpacman::~Kpacman() { APP_CONFIG_BEGIN( cfg ); cfg->writeEntry("FocusOutPause", focusOutPause); cfg->writeEntry("FocusInContinue", focusInContinue); cfg->writeEntry("HideMouseCursor", hideMouseCursor); APP_CONFIG_END( cfg ); delete _menuBar; } void Kpacman::menu() { gamePopup = new QPopupMenu(); CHECK_PTR( gamePopup ); newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); pauseID = gamePopup->insertItem(tr("&Pause"), this, SLOT(pauseKpacman()), Key_F3); hofID = gamePopup->insertItem(tr("&Hall of fame"), this, SLOT(toggleHallOfFame()), Key_F4); gamePopup->insertSeparator(); gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); gamePopup->setCheckable(TRUE); optionsPopup = new QPopupMenu(); CHECK_PTR(optionsPopup); modesPopup = new QPopupMenu(); CHECK_PTR(modesPopup); hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), this, SLOT(toggleHideMouseCursor()), CTRL+Key_H); optionsPopup->insertSeparator(); if (lookupSchemes() > 0) { optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); optionsPopup->insertSeparator(); } focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), this, SLOT(toggleFocusOutPause())); focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), this, SLOT(toggleFocusInContinue())); optionsPopup->insertSeparator(); optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); -#ifndef QWS +#ifndef QPE_PORT QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" "Joerg Thoennissen (joe@dsite.de)\n\n" "A pacman game for the KDE Desktop\n\n" "The program based on the source of ksnake\n" "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" "The design was strongly influenced by the pacman\n" "(c) 1980 MIDWAY MFG.CO.\n\n" "I like to thank my girlfriend Elke Krueers for\n" "the last 10 years of her friendship.\n"); aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); aboutText.replace(QRegExp("@VERSION@"), VERSION); QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); #endif //_menuBar = new KMenuBar(this); //CHECK_PTR( _menuBar ); //_menuBar->insertItem(tr("&Game"), gamePopup); //_menuBar->insertItem(tr("&Options"), optionsPopup); //_menuBar->insertSeparator(); -#ifndef QWS +#ifndef QPE_PORT _menuBar->insertItem(tr("&Help"), helpPopup); #endif } int Kpacman::lookupSchemes() { APP_CONFIG_BEGIN( cfg ); int ModeCount = cfg->readNumEntry("ModeCount", -1); int Mode = cfg->readNumEntry("Mode", -1); int SchemeCount = cfg->readNumEntry("SchemeCount"); int Scheme = cfg->readNumEntry("Scheme", -1); if (SchemeCount == 0 || Scheme == -1) { QMessageBox::warning(this, tr("Configuration Error"), tr("There are no schemes defined,\n" "or no scheme is selected.")); APP_CONFIG_END( cfg ); return 0; } connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); modeID.resize(ModeCount > 0 ? ModeCount : 0); if (!schemesPopup->isEmpty()) schemesPopup->clear(); SAVE_CONFIG_GROUP( cfg, oldgroup ); QString ModeGroup; QString ModeName; for (int m = 0; m < ModeCount; m++) { ModeGroup.sprintf("Mode %d", m); cfg->setGroup(ModeGroup); ModeName = cfg->readEntry("Description", ModeGroup); QPopupMenu *p = new QPopupMenu; p->setCheckable(TRUE); connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); schemesPopup->append(p); modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); modesPopup->setItemEnabled(modeID[m], FALSE); modesPopup->setItemChecked(modeID[m], m == Mode); } schemeID.resize(SchemeCount); schemeMode.resize(SchemeCount); QString SchemeGroup; QString SchemeName; int SchemeMode; for (int i = 0; i < SchemeCount; i++) { SchemeGroup.sprintf("Scheme %d", i); cfg->setGroup(SchemeGroup); SchemeName = cfg->readEntry("Description", SchemeGroup); SchemeMode = cfg->readNumEntry("Mode", -1); schemeMode[i] = SchemeMode; if (SchemeMode == -1) { schemeID[i] = modesPopup->insertItem(SchemeName); modesPopup->setItemChecked(schemeID[i], i == Scheme); } else { schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); schemesPopup->at(SchemeMode)-> setItemChecked(schemeID[i], i == Scheme); modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); } } RESTORE_CONFIG_GROUP( cfg, oldgroup ); APP_CONFIG_END( cfg ); return SchemeCount; } void Kpacman::quitKpacman() { APP_QUIT(); } void Kpacman::newKpacman() { if (!gamePopup->isItemEnabled(hofID)) gamePopup->setItemEnabled(hofID, TRUE); if (gamePopup->isItemChecked(hofID)) toggleHallOfFame(); if (gamePopup->isItemChecked(pauseID)) pauseKpacman(); view->referee->play(); } void Kpacman::pauseKpacman() { view->referee->pause(); view->score->setPause(gamePopup->isItemChecked(pauseID)); } void Kpacman::toggleHallOfFame() { gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); view->referee->toggleHallOfFame(); if (gamePopup->isItemChecked(hofID)) { view->referee->lower(); view->status->lower(); } else { view->status->raise(); view->referee->raise(); view->referee->setFocus(); } } /* * Disable or enable the "Hall of fame"-menuitem if the referee says so. * This is done, to disable turning off the "hall of fame"-display, in the automated * sequence of displaying the introduction, the demonstration (or playing) and the * hall of fame. * If on == TRUE then also lower the referee and the status widgets. */ void Kpacman::forcedHallOfFame(bool on) { if (!on && !gamePopup->isItemChecked(hofID)) return; gamePopup->setItemEnabled(hofID, !on); gamePopup->setItemChecked(hofID, on); view->referee->toggleHallOfFame(); if (on) { view->referee->lower(); view->status->lower(); } else { view->status->raise(); view->referee->raise(); view->referee->setFocus(); view->referee->intro(); } } void Kpacman::togglePaused() { static bool checked = FALSE; checked = !checked; gamePopup->setItemChecked( pauseID, checked ); view->score->setPause(gamePopup->isItemChecked(pauseID)); } /* * This disables the "New Game" menuitem to prevent interruptions of the current * play. */ void Kpacman::toggleNew() { gamePopup->setItemEnabled(newID, !gamePopup->isItemEnabled(newID)); } void Kpacman::toggleHideMouseCursor() { hideMouseCursor = !hideMouseCursor; optionsPopup->setItemChecked(hideMouseCursorID, hideMouseCursor); if (hideMouseCursor) view->setCursor(blankCursor); else view->setCursor(arrowCursor); } void Kpacman::toggleFocusOutPause() { focusOutPause = !focusOutPause; optionsPopup->setItemChecked(focusOutPauseID, focusOutPause); view->referee->setFocusOutPause(focusOutPause); } void Kpacman::toggleFocusInContinue() { focusInContinue = !focusInContinue; optionsPopup->setItemChecked(focusInContinueID, focusInContinue); view->referee->setFocusInContinue(focusInContinue); } void Kpacman::confKeys() { Keys *keys = new Keys(); if (keys->exec() == QDialog::Accepted) { view->referee->initKeys(); view->score->initKeys(); } delete keys; } void Kpacman::schemeChecked(int id) { int mode = 0, scheme = -1; for (uint s = 0; s < schemeID.size(); s++) { if (schemeID[s] == id) { scheme = s; mode = schemeMode[s]; } if (schemeMode[s] == -1) { modesPopup->setItemChecked(schemeID[s], schemeID[s] == id); } else { modesPopup->setItemChecked(modeID[schemeMode[s]], schemeMode[s] == mode); schemesPopup->at(schemeMode[s])->setItemChecked(schemeID[s], schemeID[s] == id); } } APP_CONFIG_BEGIN( cfg ); cfg->writeEntry("Scheme", scheme); cfg->writeEntry("Mode", mode); APP_CONFIG_END( cfg ); view->setScheme(scheme, mode); view->updateGeometry(); updateGeometry(); update(); repaint(TRUE); show(); } diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp index feb782c..cf2aed9 100644 --- a/noncore/games/kpacman/kpacmanwidget.cpp +++ b/noncore/games/kpacman/kpacmanwidget.cpp @@ -1,153 +1,158 @@ #include "portable.h" #if defined( KDE2_PORT ) #include <kapp.h> #include <kconfig.h> #include <kstddirs.h> #include <kpacmanwidget.h> #include <kpacmanwidget.moc> #elif defined( QPE_PORT ) #include <qpe/qpeapplication.h> #include "config.h" #include "kpacmanwidget.h" #endif #include <qmessagebox.h> #include "bitfont.h" #include "score.h" #include "referee.h" #include "status.h" KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) : QWidget( parent, name ) { + score = 0l; + referee = 0l; + status = 0l; bitfont = NULL; fontName = ""; scheme = mode = -1; confScheme(); score = new Score(this, name, scheme, mode, bitfont); referee = new Referee( this, name, scheme, mode, bitfont); status = new Status(this, name, scheme, mode); setBackgroundColor( black ); } KpacmanWidget::~KpacmanWidget() { } void KpacmanWidget::confMisc(bool defGroup) { APP_CONFIG_BEGIN( cfg ); //KStandardDirs *dirs = KGlobal::dirs(); QString findPath; if (defGroup || cfg->hasKey("Font")) { fontName = cfg->readEntry("Font"); if (fontName.left(1) != "/" && fontName.left(1) != "~") fontName.insert(0, "fonts/"); if (fontName.right(1) == "/") fontName.append("font.xbm"); //findPath = dirs->findResource("appdata", fontName); findPath = FIND_APP_DATA( fontName ); if (!findPath.isEmpty()) fontName = findPath; bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); } APP_CONFIG_END( cfg ); } void KpacmanWidget::confScheme() { APP_CONFIG_BEGIN( cfg ); QString lastFontName = fontName; SAVE_CONFIG_GROUP( cfg, oldgroup ); QString newgroup; // if not set, read mode and scheme from the configfile if (mode == -1 && scheme == -1) { scheme = cfg->readNumEntry("Scheme", -1); mode = cfg->readNumEntry("Mode", -1); // if mode is not set in the defGroup-group, lookup the scheme group if (scheme != -1 || mode == -1) { newgroup.sprintf("Scheme %d", scheme); cfg->setGroup(newgroup); mode = cfg->readNumEntry("Mode", -1); RESTORE_CONFIG_GROUP( cfg, oldgroup ); } } confMisc(); if (mode != -1) { newgroup.sprintf("Mode %d", mode); cfg->setGroup(newgroup); confMisc(FALSE); } if (scheme != -1) { newgroup.sprintf("Scheme %d", scheme); cfg->setGroup(newgroup); confMisc(FALSE); } if (lastFontName != fontName) { if (bitfont != 0) delete bitfont; bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); if (bitfont->width() == 0 || bitfont->height() == 0) { QString msg = tr("The bitfont could not be contructed.\n\n" "The file '@FONTNAME@' does not exist,\n" "or is of an unknown format."); msg.replace(QRegExp("@FONTNAME@"), fontName); // QMessageBox::critical(this, tr("Initialization Error"), msg); printf("%s\n", msg.data()); } } RESTORE_CONFIG_GROUP( cfg, oldgroup ); APP_CONFIG_END( cfg ); } void KpacmanWidget::setScheme(int Scheme, int Mode) { mode = Mode; scheme = Scheme; confScheme(); score->setScheme(Scheme, Mode, bitfont); referee->setScheme(Scheme, Mode, bitfont); status->setScheme(Scheme, Mode); score->repaint(FALSE); referee->repaint(FALSE); status->repaint(FALSE); } void KpacmanWidget::resizeEvent( QResizeEvent * ) { + qWarning("Resize"); referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); referee->setBackgroundColor(BLACK); + if(!status ) return; status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), status->height()); status->setBackgroundColor(BLACK); score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); score->setBackgroundColor(BLACK); } diff --git a/noncore/games/kpacman/portable.h b/noncore/games/kpacman/portable.h index ff0912b..b087be5 100644 --- a/noncore/games/kpacman/portable.h +++ b/noncore/games/kpacman/portable.h @@ -1,63 +1,58 @@ /*************************************************************************** portable.h - various bits that ease porting kpacman to other platforms. Currently KDE2 and Qtopia ports exist. ------------------- begin : Mon Mar 18 12:35:24 EET 2002 copyright : (C) 2002 by Catalin Climov email : catalin@climov.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef PORTABLE_H #define PORTABLE_H -#ifdef QWS #define QPE_PORT -#else -#define KDE2_PORT -#define KDE_PORT -#endif #if defined( KDE2_PORT ) #define APP kapp #define APP_CONFIG_BEGIN( cfgname ) KConfig cfgname = kapp->config() #define APP_CONFIG_END( cfgname ) cfgname->sync() #define SAVE_CONFIG_GROUP( cfgname, groupname ) QString groupname = configname->group() #define RESTORE_CONFIG_GROUP( cfgname, groupname ) configname->setGroup( groupname ) #define FIND_APP_DATA( dataname ) KGlobal::dirs()->findResource( "appdata", dataname ) #elif defined( QPE_PORT ) #define i18n( x ) x #define KTMainWindow QMainWindow #define KMenuBar QMenuBar #define KAccel QAccel #define APP qApp #define APP_CONFIG_BEGIN( cfgname ) Config* cfgname = new Config("kpacman"); cfgname->setGroup("Default"); #define APP_CONFIG_END( cfgname ) delete cfgname #define SAVE_CONFIG_GROUP( cfgname, groupname ) #define RESTORE_CONFIG_GROUP( cfgname, groupname ) cfgname->setGroup("Default") #define FIND_APP_DATA( dataname ) (QPEApplication::qpeDir()+"share/kpacman/"+dataname) #else #error "Err, I don't know what platform to compile for (KDE2 or Qtopia)" #endif #define APP_QUIT() APP->quit() #endif // PORTABLE_H diff --git a/noncore/games/kpacman/status.cpp b/noncore/games/kpacman/status.cpp index 3453d37..1ef910d 100644 --- a/noncore/games/kpacman/status.cpp +++ b/noncore/games/kpacman/status.cpp @@ -1,367 +1,368 @@ #include "portable.h" #if defined( KDE2_PORT ) #include <kapp.h> #include <klocale.h> #include <kstddirs.h> #include <status.h> #include <status.moc> #elif defined( QPE_PORT ) #include <qpe/qpeapplication.h> #include "config.h" #include "status.h" #endif #include <qpixmap.h> #include <qbitmap.h> #include <qstring.h> #include <qmsgbox.h> #include <qfileinfo.h> Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) : QWidget( parent, name ) { + qWarning("Status::Status"); actualLifes = 0; actualLevel = 0; lifesPix = NULL; levelPix = NULL; scheme = Scheme; mode = Mode; level = 0; confScheme(); } QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName, QList<QPixmap> *pixmaps) { if (pixmaps == NULL) { pixmaps = new QList<QPixmap>; pixmaps->setAutoDelete(TRUE); } if (!pixmaps->isEmpty()) pixmaps->clear(); QPixmap PIXMAP(pixmapName); if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { QString msg = tr("The pixmap could not be contructed.\n\n" "The file '@PIXMAPNAME@' does not exist,\n" "or is of an unknown format."); msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); QMessageBox::information(parent, tr("Initialization Error"), (const char *) msg); return 0; } int height = PIXMAP.height(); int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); QBitmap BITMAP; QBitmap MASK; BITMAP = *PIXMAP.mask(); MASK.resize(width, height); for (int x = 0; x < PIXMAP.width()/width; x++) { QPixmap *pixmap = new QPixmap(width, height); pixmaps->append(pixmap); bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, CopyROP, TRUE); bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, CopyROP, TRUE); pixmap->setMask(MASK); } return pixmaps; } void Status::paintEvent( QPaintEvent *) { for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++) bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x), (height()-lifesPix->at(0)->height())/2, lifesPix->at(0), 0, 0, lifesPix->at(0)->width(), lifesPix->at(0)->height()); for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) { erase((width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), (height()-levelPix->at(x)->height())/2, levelPix->at(x)->width(), levelPix->at(x)->height()); bitBlt(this, (width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), (height()-levelPix->at(x)->height())/2, levelPix->at(x), 0, 0, levelPix->at(x)->width(), levelPix->at(x)->height()); } } void Status::initPixmaps() { if (lastLifesPixmapName != lifesPixmapName.at(level)) { lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix); lastLifesPixmapName = lifesPixmapName.at(level); } if (lastLevelPixmapName != levelPixmapName.at(level)) { levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix); lastLevelPixmapName = levelPixmapName.at(level); } } QString Status::decodeHexOctString(QString s) { QString value; QString valids; int pos, xpos = 0, opos = 0; int v, len, leadin; const char *ptr; uchar c; while (((xpos = s.find(QRegExp("\\\\x[0-9a-fA-F]+"), xpos)) != -1) || ((opos = s.find(QRegExp("\\\\[0-7]+"), opos)) != -1)) { if (xpos != -1) { valids = "0123456789abcdef"; leadin = 2; pos = xpos; } else { valids = "01234567"; leadin = 1; pos = opos; } c = '\0'; len = 0; value = s.mid(pos+leadin, 3); ptr = (const char *) value; while (*ptr != '\0' && (v = valids.find(*ptr++, 0, FALSE)) != -1) { c = (c * valids.length()) + v; len++; } value.fill(c, 1); s.replace(pos, len+leadin, value); } return s; } void Status::fillArray(QArray<int> &array, QString values, int max) { array.resize(max); int last = 0; bool ok; QString value; for (uint i = 0; i < array.size(); i++) { if (values.find(',') < 0 && values.length() > 0) { value = values; values = ""; } if (values.find(',') >= 0) { value = values.left(values.find(',')); values.remove(0,values.find(',')+1); } array[i] = value.toInt(&ok); if (ok) last = array[i]; else array[i] = last; } } void Status::fillStrList(QStrList &list, QString values, int max) { if (!list.isEmpty()) list.clear(); QString last = ""; QString value; for (uint i = 0; i < (uint) max; i++) { if (values.find(',') < 0 && values.length() > 0) { value = values; values = ""; } if (values.find(',') >= 0) { value = values.left(values.find(',')); values.remove(0,values.find(',')+1); } if (!value.isEmpty()) last = decodeHexOctString(value); list.append(last); } } void Status::fillPixmapName(QStrList &pixmapName) { QStrList list = pixmapName; if (!pixmapName.isEmpty()) pixmapName.clear(); QString pixmap; QFileInfo fileInfo; for (uint i = 0; i < list.count(); i++) { pixmap = list.at(i); if (pixmap.left(1) != "/" && pixmap.left(1) != "~") pixmap = FIND_APP_DATA( pixmapDirectory+pixmap ); fileInfo.setFile(pixmap); if (!fileInfo.isReadable() || !fileInfo.isFile()) pixmap = ""; pixmapName.append(pixmap); } } void Status::confLevels(bool defGroup) { APP_CONFIG_BEGIN( cfg ); if (defGroup || cfg->hasKey("Levels")) maxLevel = cfg->readNumEntry("Levels", 13); APP_CONFIG_END( cfg ); } void Status::confMisc(bool defGroup) { APP_CONFIG_BEGIN( cfg ); if (defGroup || cfg->hasKey("LevelPosition")) fillArray(levelPos, cfg->readEntry("LevelPosition", "0,1,2,3,,4,,5,,6,,7"), maxLevel); if (defGroup || cfg->hasKey("PixmapDirectory")) { pixmapDirectory = cfg->readEntry("PixmapDirectory"); if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") pixmapDirectory.insert(0, "pics/"); if (pixmapDirectory.right(1) != "/") pixmapDirectory.append("/"); } if (defGroup || cfg->hasKey("LifesPixmapName")) fillStrList(lifesPixmapName, cfg->readEntry("LifesPixmapName", "lifes.xpm"), maxLevel+1); if (defGroup || cfg->hasKey("LevelPixmapName")) fillStrList(levelPixmapName, cfg->readEntry("LevelPixmapName", "level.xpm"), maxLevel+1); APP_CONFIG_END( cfg ); } void Status::confScheme() { APP_CONFIG_BEGIN( cfg ); SAVE_CONFIG_GROUP( cfg, oldgroup ); QString newgroup; // if not set, read mode and scheme from the configfile if (mode == -1 && scheme == -1) { scheme = cfg->readNumEntry("Scheme", -1); mode = cfg->readNumEntry("Mode", -1); // if mode is not set in the defGroup-group, lookup the scheme group if (scheme != -1 || mode == -1) { newgroup.sprintf("Scheme %d", scheme); cfg->setGroup(newgroup); mode = cfg->readNumEntry("Mode", -1); RESTORE_CONFIG_GROUP( cfg, oldgroup ); } } confLevels(); if (mode != -1) { newgroup.sprintf("Mode %d", mode); cfg->setGroup(newgroup); confLevels(FALSE); } if (scheme != -1) { newgroup.sprintf("Scheme %d", scheme); cfg->setGroup(newgroup); confLevels(FALSE); } RESTORE_CONFIG_GROUP( cfg, oldgroup ); confMisc(); if (mode != -1) { newgroup.sprintf("Mode %d", mode); cfg->setGroup(newgroup); confMisc(FALSE); } if (scheme != -1) { newgroup.sprintf("Scheme %d", scheme); cfg->setGroup(newgroup); confMisc(FALSE); } fillPixmapName(lifesPixmapName); fillPixmapName(levelPixmapName); initPixmaps(); setFixedHeight(minHeight()); RESTORE_CONFIG_GROUP( cfg, oldgroup ); APP_CONFIG_END( cfg ); } void Status::setScheme(int Scheme, int Mode) { mode = Mode; scheme = Scheme; confScheme(); repaint(); } int Status::minHeight() { if (lifesPix->isEmpty() && levelPix->isEmpty()) return 0; if (levelPix->isEmpty()) return lifesPix->at(0)->height(); if (lifesPix->isEmpty()) return levelPix->at(0)->height(); return (lifesPix->at(0)->height() > levelPix->at(0)->height()) ? lifesPix->at(0)->height() : levelPix->at(0)->height(); } int Status::minWidth() { if (lifesPix->isEmpty() && levelPix->isEmpty()) return 0; if (levelPix->isEmpty()) return lifesPix->at(0)->width(); if (lifesPix->isEmpty()) return levelPix->at(0)->width(); return (lifesPix->at(0)->width() > levelPix->at(0)->width()) ? lifesPix->at(0)->width() : levelPix->at(0)->width(); } void Status::setLifes(int lifes) { actualLifes = lifes; repaint(); } void Status::setLevel(int Level) { level = Level; initPixmaps(); actualLevel = (level > (int) levelPix->count()) ? (int) levelPix->count() : level; repaint(); } |