00001
00002 #include "portable.h"
00003
00004 #if defined( KDE2_PORT )
00005 #include <kapp.h>
00006 #include <kconfig.h>
00007 #include <kstddirs.h>
00008 #include <kpacmanwidget.h>
00009 #include <kpacmanwidget.moc>
00010 #elif defined( QPE_PORT )
00011 #include <qpe/qpeapplication.h>
00012 #include <qpe/config.h>
00013 #include "kpacmanwidget.h"
00014 #endif
00015
00016 #include <opie2/odebug.h>
00017 using namespace Opie::Core;
00018
00019 KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name)
00020 : QWidget( parent, name )
00021 {
00022 score = 0l;
00023 referee = 0l;
00024 status = 0l;
00025 bitfont = NULL;
00026 fontName = "";
00027
00028 scheme = mode = -1;
00029 confScheme();
00030
00031 score = new Score(this, name, scheme, mode, bitfont);
00032 referee = new Referee( this, name, scheme, mode, bitfont);
00033 status = new Status(this, name, scheme, mode);
00034
00035 setBackgroundColor( black );
00036 }
00037
00038 KpacmanWidget::~KpacmanWidget()
00039 {
00040 }
00041
00042 void KpacmanWidget::confMisc(bool defGroup)
00043 {
00044 APP_CONFIG_BEGIN( cfg );
00045
00046 QString findPath;
00047
00048 if (defGroup || cfg->hasKey("Font")) {
00049 fontName = cfg->readEntry("Font");
00050
00051 if (fontName.left(1) != "/" && fontName.left(1) != "~")
00052 fontName.insert(0, "fonts/");
00053 if (fontName.right(1) == "/")
00054 fontName.append("font.xbm");
00055
00056
00057 findPath = FIND_APP_DATA( fontName );
00058 if (!findPath.isEmpty())
00059 fontName = findPath;
00060
00061 bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e);
00062 bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f);
00063 }
00064 APP_CONFIG_END( cfg );
00065 }
00066
00067 void KpacmanWidget::confScheme()
00068 {
00069 APP_CONFIG_BEGIN( cfg );
00070 QString lastFontName = fontName;
00071 SAVE_CONFIG_GROUP( cfg, oldgroup );
00072 QString newgroup;
00073
00074
00075 if (mode == -1 && scheme == -1) {
00076 scheme = cfg->readNumEntry("Scheme", -1);
00077 mode = cfg->readNumEntry("Mode", -1);
00078
00079
00080 if (scheme != -1 || mode == -1) {
00081 newgroup.sprintf("Scheme %d", scheme);
00082 cfg->setGroup(newgroup);
00083
00084 mode = cfg->readNumEntry("Mode", -1);
00085 RESTORE_CONFIG_GROUP( cfg, oldgroup );
00086 }
00087 }
00088
00089 confMisc();
00090
00091 if (mode != -1) {
00092 newgroup.sprintf("Mode %d", mode);
00093 cfg->setGroup(newgroup);
00094
00095 confMisc(FALSE);
00096 }
00097
00098 if (scheme != -1) {
00099 newgroup.sprintf("Scheme %d", scheme);
00100 cfg->setGroup(newgroup);
00101
00102 confMisc(FALSE);
00103 }
00104
00105 if (lastFontName != fontName) {
00106
00107 if (bitfont != 0)
00108 delete bitfont;
00109
00110 bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar);
00111 if (bitfont->width() == 0 || bitfont->height() == 0) {
00112 QString msg = tr("The bitfont could not be contructed.\n\n"
00113 "The file '@FONTNAME@' does not exist,\n"
00114 "or is of an unknown format.");
00115 msg.replace(QRegExp("@FONTNAME@"), fontName);
00116
00117 printf("%s\n", msg.data());
00118 }
00119 }
00120
00121 RESTORE_CONFIG_GROUP( cfg, oldgroup );
00122 APP_CONFIG_END( cfg );
00123 }
00124
00125 void KpacmanWidget::setScheme(int Scheme, int Mode)
00126 {
00127 mode = Mode;
00128 scheme = Scheme;
00129
00130 confScheme();
00131
00132 score->setScheme(Scheme, Mode, bitfont);
00133 referee->setScheme(Scheme, Mode, bitfont);
00134 status->setScheme(Scheme, Mode);
00135
00136 score->repaint(FALSE);
00137 referee->repaint(FALSE);
00138 status->repaint(FALSE);
00139 }
00140
00141 void KpacmanWidget::resizeEvent( QResizeEvent * )
00142 {
00143 owarn << "Resize" << oendl;
00144 referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height());
00145 referee->setBackgroundColor(BLACK);
00146
00147 if(!status ) return;
00148 status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(),
00149 status->height());
00150 status->setBackgroundColor(BLACK);
00151
00152 score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height());
00153 score->setBackgroundColor(BLACK);
00154 }