OSDN Git Service

upgrade to 3.6.1
[jnethack/source.git] / win / Qt4 / qt4win.cpp
1 // Copyright (c) Warwick Allison, 1999.
2 // Qt4 conversion copyright (c) Ray Chason, 2012-2014.
3 // NetHack may be freely redistributed.  See license for details.
4
5 // Qt Binding for NetHack 3.4
6 //
7 // Copyright (C) 1996-2001 by Warwick W. Allison (warwick@troll.no)
8 // 
9 // Contributors:
10 //    Michael Hohmuth <hohmuth@inf.tu-dresden.de>
11 //       - Userid control
12 //    Svante Gerhard <svante@algonet.se>
13 //       - .nethackrc tile and font size settings
14 //    Dirk Schoenberger <schoenberger@signsoft.com>
15 //       - KDE support
16 //       - SlashEm support
17 //    and many others for bug reports.
18 // 
19 // Unfortunately, this doesn't use Qt as well as I would like,
20 // primarily because NetHack is fundamentally a getkey-type program
21 // rather than being event driven (hence the ugly key and click buffer)
22 // and also because this is my first major application of Qt.  
23 // 
24 // The problem of NetHack's getkey requirement is solved by intercepting
25 // key events by overiding QApplicion::notify(...), and putting them in
26 // a buffer.  Mouse clicks on the map window are treated with a similar
27 // buffer.  When the NetHack engine calls for a key, one is taken from
28 // the buffer, or if that is empty, QApplication::exec() is called.
29 // Whenever keys or clicks go into the buffer, QApplication::exit()
30 // is called.
31 //
32 // Another problem is that some NetHack players are decade-long players who
33 // demand complete keyboard control (while Qt and X11 conspire to make this
34 // difficult by having widget-based focus rather than application based -
35 // a good thing in general).  This problem is solved by again using the key
36 // event buffer.
37 //
38 // Out of all this hackery comes a silver lining however, as macros for
39 // the super-expert and menus for the ultra-newbie are also made possible
40 // by the key event buffer.
41 //
42
43 // This includes all the definitions we need from the NetHack main
44 // engine.  We pretend MSC is a STDC compiler, because C++ is close
45 // enough, and we undefine NetHack macros which conflict with Qt
46 // identifiers.
47
48 #define QT_DEPRECATED_WARNINGS
49 #include "hack.h"
50 #undef Invisible
51 #undef Warning
52 #undef index
53 #undef msleep
54 #undef rindex
55 #undef wizard
56 #undef yn
57 #undef min
58 #undef max
59
60 #include <QtGui/QtGui>
61 #if QT_VERSION >= 0x050000
62 #include <QtWidgets/QtWidgets>
63 #endif
64 #include "qt4win.h"
65 #include "qt4bind.h"
66 #include "qt4click.h"
67 #include "qt4glyph.h"
68 #include "qt4inv.h"
69 #include "qt4key.h"
70 #include "qt4icon.h"
71 #include "qt4map.h"
72 #include "qt4menu.h"
73 #include "qt4msg.h"
74 #include "qt4set.h"
75
76 #include <ctype.h>
77
78 #include "qt4clust.h"
79
80 #include <dirent.h>
81
82 #ifdef _WS_X11_
83 // For userid control
84 #include <unistd.h>
85 #endif
86
87 #ifdef USER_SOUNDS
88 #if QT_VERSION >= 0x050000
89 #  include <QtMultimedia/QSound>
90 # else
91 #  include <QtGui/QSound>
92 # endif
93 #endif
94
95
96 #ifdef USER_SOUNDS
97 extern void play_sound_for_message(const std::string& str);
98 #endif
99
100 namespace nethack_qt4 {
101
102 void
103 centerOnMain( QWidget* w )
104 {
105     QWidget* m = NetHackQtBind::mainWidget();
106     if (!m) m = qApp->desktop();
107     QPoint p = m->mapToGlobal(QPoint(0,0));
108     w->move( p.x() + m->width()/2  - w->width()/2,
109               p.y() + m->height()/2 - w->height()/2 );
110 }
111
112 NetHackQtWindow::NetHackQtWindow()
113 {
114 }
115 NetHackQtWindow::~NetHackQtWindow()
116 {
117 }
118
119 // XXX Use "expected ..." for now, abort or default later.
120 //
121 void NetHackQtWindow::Clear() { puts("unexpected Clear"); }
122 void NetHackQtWindow::Display(bool block) { puts("unexpected Display"); }
123 bool NetHackQtWindow::Destroy() { return true; }
124 void NetHackQtWindow::CursorTo(int x,int y) { puts("unexpected CursorTo"); }
125 void NetHackQtWindow::PutStr(int attr, const QString& text) { puts("unexpected PutStr"); }
126 void NetHackQtWindow::StartMenu() { puts("unexpected StartMenu"); }
127 void NetHackQtWindow::AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr,
128     const QString& str, bool presel) { puts("unexpected AddMenu"); }
129 void NetHackQtWindow::EndMenu(const QString& prompt) { puts("unexpected EndMenu"); }
130 int NetHackQtWindow::SelectMenu(int how, MENU_ITEM_P **menu_list) { puts("unexpected SelectMenu"); return 0; }
131 void NetHackQtWindow::ClipAround(int x,int y) { puts("unexpected ClipAround"); }
132 void NetHackQtWindow::PrintGlyph(int x,int y,int glyph) { puts("unexpected PrintGlyph"); }
133 //void NetHackQtWindow::PrintGlyphCompose(int x,int y,int,int) { puts("unexpected PrintGlyphCompose"); }
134 void NetHackQtWindow::UseRIP(int how, time_t when) { puts("unexpected UseRIP"); }
135
136 } // namespace nethack_qt4