diff options
Diffstat (limited to 'kpacman/kpacmanview.cpp')
-rw-r--r-- | kpacman/kpacmanview.cpp | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/kpacman/kpacmanview.cpp b/kpacman/kpacmanview.cpp new file mode 100644 index 0000000..73d3f44 --- /dev/null +++ b/kpacman/kpacmanview.cpp @@ -0,0 +1,161 @@ +/*************************************************************************** + kpacmanview.cpp - description + ------------------- + begin : Sam Jan 19 13:37:57 CET 2002 + copyright : (C) 1998-2003 by Jörg Thönnissen + email : joe@dsite.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// include files for Qt +#include <qmessagebox.h> + +// include files for KDE +#include <kapp.h> +#include <kconfig.h> +#include <kstddirs.h> + +// application specific includes +#include "kpacmanview.h" +#include "bitfont.h" +#include "score.h" +#include "referee.h" +#include "status.h" + +KpacmanView::KpacmanView( QWidget *parent, const char *name) : QWidget( parent, name ) +{ + 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); + + setFixedSize(referee->width(), bitfont->height()*3 + referee->height() + status->height()); +} + +KpacmanView::~KpacmanView() +{ +} + +void KpacmanView::confMisc(bool defGroup) +{ + KStandardDirs *dirs = KGlobal::dirs(); + QString findPath; + + if (defGroup || kapp->config()->hasKey("Font")) { + fontName = kapp->config()->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); + if (!findPath.isEmpty()) + fontName = findPath; + + bitfontFirstChar = kapp->config()->readNumEntry("FontFirstChar", 0x0e); + bitfontLastChar = kapp->config()->readNumEntry("FontLastChar", 0x5f); + } +} + +void KpacmanView::confScheme() +{ + QString lastFontName = fontName; + QString oldgroup = kapp->config()->group(); + QString newgroup; + + // if not set, read mode and scheme from the configfile + if (mode == -1 && scheme == -1) { + scheme = kapp->config()->readNumEntry("Scheme", -1); + mode = kapp->config()->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); + kapp->config()->setGroup(newgroup); + + mode = kapp->config()->readNumEntry("Mode", -1); + kapp->config()->setGroup(oldgroup); + } + } + + confMisc(); + + if (mode != -1) { + newgroup.sprintf("Mode %d", mode); + kapp->config()->setGroup(newgroup); + + confMisc(FALSE); + } + + if (scheme != -1) { + newgroup.sprintf("Scheme %d", scheme); + kapp->config()->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 = i18n("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, i18n("Initialization Error"), msg); + printf("%s\n", msg.data()); + } + } + + kapp->config()->setGroup(oldgroup); +} + +void KpacmanView::setScheme(int Scheme, int Mode) +{ + mode = Mode; + scheme = Scheme; + + confScheme(); + + score->setScheme(Scheme, Mode, bitfont); + referee->setScheme(Scheme, Mode, bitfont); + status->setScheme(Scheme, Mode); + + setFixedSize(referee->width(), + bitfont->height()*3 + referee->height() + status->height()); + updateGeometry(); + + score->repaint(FALSE); + referee->repaint(FALSE); + status->repaint(FALSE); +} + +void KpacmanView::resizeEvent( QResizeEvent * ) +{ + referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); + referee->setBackgroundColor(BLACK); + + 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); +} |