Diffstat (limited to 'noncore/games/kpacman/kpacmanwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/kpacman/kpacmanwidget.cpp | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp new file mode 100644 index 0000000..330c88e --- a/dev/null +++ b/noncore/games/kpacman/kpacmanwidget.cpp | |||
@@ -0,0 +1,162 @@ | |||
1 | |||
2 | #include "portable.h" | ||
3 | |||
4 | #if defined( KDE2_PORT ) | ||
5 | #include <kapp.h> | ||
6 | #include <kconfig.h> | ||
7 | #include <kstddirs.h> | ||
8 | #include <kpacmanwidget.h> | ||
9 | #include <kpacmanwidget.moc> | ||
10 | #elif defined( QPE_PORT ) | ||
11 | #include <qpe/qpeapplication.h> | ||
12 | #include "config.h" | ||
13 | #include "kpacmanwidget.h" | ||
14 | #endif | ||
15 | |||
16 | #include <qmessagebox.h> | ||
17 | |||
18 | #include "bitfont.h" | ||
19 | #include "score.h" | ||
20 | #include "referee.h" | ||
21 | #include "status.h" | ||
22 | |||
23 | KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) | ||
24 | : QWidget( parent, name ) | ||
25 | { | ||
26 | bitfont = NULL; | ||
27 | fontName = ""; | ||
28 | |||
29 | scheme = mode = -1; | ||
30 | confScheme(); | ||
31 | |||
32 | score = new Score(this, name, scheme, mode, bitfont); | ||
33 | referee = new Referee( this, name, scheme, mode, bitfont); | ||
34 | status = new Status(this, name, scheme, mode); | ||
35 | |||
36 | #ifndef QWS | ||
37 | setFixedSize(referee->width(), bitfont->height()*3 + referee->height() + status->height()); | ||
38 | #else | ||
39 | setBackgroundColor( black ); | ||
40 | #endif | ||
41 | } | ||
42 | |||
43 | KpacmanWidget::~KpacmanWidget() | ||
44 | { | ||
45 | } | ||
46 | |||
47 | void KpacmanWidget::confMisc(bool defGroup) | ||
48 | { | ||
49 | APP_CONFIG_BEGIN( cfg ); | ||
50 | //KStandardDirs *dirs = KGlobal::dirs(); | ||
51 | QString findPath; | ||
52 | |||
53 | if (defGroup || cfg->hasKey("Font")) { | ||
54 | fontName = cfg->readEntry("Font"); | ||
55 | |||
56 | if (fontName.left(1) != "/" && fontName.left(1) != "~") | ||
57 | fontName.insert(0, "fonts/"); | ||
58 | if (fontName.right(1) == "/") | ||
59 | fontName.append("font.xbm"); | ||
60 | |||
61 | //findPath = dirs->findResource("appdata", fontName); | ||
62 | findPath = FIND_APP_DATA( fontName ); | ||
63 | if (!findPath.isEmpty()) | ||
64 | fontName = findPath; | ||
65 | |||
66 | bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); | ||
67 | bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); | ||
68 | } | ||
69 | APP_CONFIG_END( cfg ); | ||
70 | } | ||
71 | |||
72 | void KpacmanWidget::confScheme() | ||
73 | { | ||
74 | APP_CONFIG_BEGIN( cfg ); | ||
75 | QString lastFontName = fontName; | ||
76 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | ||
77 | QString newgroup; | ||
78 | |||
79 | // if not set, read mode and scheme from the configfile | ||
80 | if (mode == -1 && scheme == -1) { | ||
81 | scheme = cfg->readNumEntry("Scheme", -1); | ||
82 | mode = cfg->readNumEntry("Mode", -1); | ||
83 | |||
84 | // if mode is not set in the defGroup-group, lookup the scheme group | ||
85 | if (scheme != -1 || mode == -1) { | ||
86 | newgroup.sprintf("Scheme %d", scheme); | ||
87 | cfg->setGroup(newgroup); | ||
88 | |||
89 | mode = cfg->readNumEntry("Mode", -1); | ||
90 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | confMisc(); | ||
95 | |||
96 | if (mode != -1) { | ||
97 | newgroup.sprintf("Mode %d", mode); | ||
98 | cfg->setGroup(newgroup); | ||
99 | |||
100 | confMisc(FALSE); | ||
101 | } | ||
102 | |||
103 | if (scheme != -1) { | ||
104 | newgroup.sprintf("Scheme %d", scheme); | ||
105 | cfg->setGroup(newgroup); | ||
106 | |||
107 | confMisc(FALSE); | ||
108 | } | ||
109 | |||
110 | if (lastFontName != fontName) { | ||
111 | |||
112 | if (bitfont != 0) | ||
113 | delete bitfont; | ||
114 | |||
115 | bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); | ||
116 | if (bitfont->width() == 0 || bitfont->height() == 0) { | ||
117 | QString msg = i18n("The bitfont could not be contructed.\n\n" | ||
118 | "The file '@FONTNAME@' does not exist,\n" | ||
119 | "or is of an unknown format."); | ||
120 | msg.replace(QRegExp("@FONTNAME@"), fontName); | ||
121 | // QMessageBox::critical(this, i18n("Initialization Error"), msg); | ||
122 | printf("%s\n", msg.data()); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | ||
127 | APP_CONFIG_END( cfg ); | ||
128 | } | ||
129 | |||
130 | void KpacmanWidget::setScheme(int Scheme, int Mode) | ||
131 | { | ||
132 | mode = Mode; | ||
133 | scheme = Scheme; | ||
134 | |||
135 | confScheme(); | ||
136 | |||
137 | score->setScheme(Scheme, Mode, bitfont); | ||
138 | referee->setScheme(Scheme, Mode, bitfont); | ||
139 | status->setScheme(Scheme, Mode); | ||
140 | |||
141 | #ifndef QWS | ||
142 | setFixedSize(referee->width(), | ||
143 | bitfont->height()*3 + referee->height() + status->height()); | ||
144 | #endif | ||
145 | |||
146 | score->repaint(FALSE); | ||
147 | referee->repaint(FALSE); | ||
148 | status->repaint(FALSE); | ||
149 | } | ||
150 | |||
151 | void KpacmanWidget::resizeEvent( QResizeEvent * ) | ||
152 | { | ||
153 | referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); | ||
154 | referee->setBackgroundColor(BLACK); | ||
155 | |||
156 | status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), | ||
157 | status->height()); | ||
158 | status->setBackgroundColor(BLACK); | ||
159 | |||
160 | score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); | ||
161 | score->setBackgroundColor(BLACK); | ||
162 | } | ||