1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
|
// SCCS Id: @(#)qt_win.h 3.4 1999/11/19
// Copyright (c) Warwick Allison, 1999.
// NetHack may be freely redistributed. See license for details.
//
// Qt Binding for NetHack 3.4
//
// Unfortunately, this doesn't use Qt as well as I would like,
// primarily because NetHack is fundamentally a getkey-type
// program rather than being event driven (hence the ugly key
// and click buffer rather), but also because this is my first
// major application of Qt.
//
#ifndef qt_win_h
#define qt_win_h
#define QT_CLEAN_NAMESPACE
#include <qdialog.h>
#include <qpushbutton.h>
#include <qbuttongroup.h>
#include <qlabel.h>
#include <qlineedit.h>
#if defined(QWS)
#include <qpe/qpeapplication.h>
#else
#include <qapplication.h>
#endif
#include <qspinbox.h>
#include <qcheckbox.h>
#include <qfile.h>
#include <qlistbox.h>
#include <qlistview.h>
#include <qmessagebox.h>
#include <qpixmap.h>
#include <qimage.h>
#include <qarray.h>
#include <qcombobox.h>
#include <qscrollview.h>
#if QT_VERSION >= 300
#include <qttableview.h>
// Should stop using QTableView
#define QTableView QtTableView
#else
#include <qtableview.h>
#endif
#include <qmainwindow.h>
#include <qwidgetstack.h>
#ifdef KDE
#include <kapp.h>
#include <ktopwidget.h>
#endif
#include "qt_clust.h"
class QVBox;
class QMenuBar;
class QRadioButton;
class NhPSListView;
//////////////////////////////////////////////////////////////
//
// The beautiful, abstracted and well-modelled classes...
//
//////////////////////////////////////////////////////////////
class NetHackQtGlyphs;
class NetHackQtLineEdit : public QLineEdit {
public:
NetHackQtLineEdit();
NetHackQtLineEdit(QWidget* parent, const char* name);
void fakeEvent(int key, int ascii, int state);
};
class NetHackQtSettings : public QDialog {
Q_OBJECT
public:
// Size of window - used to decide default sizes
NetHackQtSettings(int width, int height);
NetHackQtGlyphs& glyphs();
const QFont& normalFont();
const QFont& normalFixedFont();
const QFont& largeFont();
bool ynInMessages();
signals:
void fontChanged();
void tilesChanged();
public slots:
void toggleGlyphSize();
void setGlyphSize(bool);
private:
QSpinBox tilewidth;
QSpinBox tileheight;
QLabel widthlbl;
QLabel heightlbl;
QCheckBox whichsize;
QSize othersize;
QComboBox fontsize;
QFont normal, normalfixed, large;
NetHackQtGlyphs* theglyphs;
private slots:
void resizeTiles();
};
class NetHackQtKeyBuffer {
public:
NetHackQtKeyBuffer();
bool Empty() const;
bool Full() const;
void Put(int k, int ascii, int state);
void Put(char a);
void Put(const char* str);
int GetKey();
int GetAscii();
int GetState();
int TopKey() const;
int TopAscii() const;
int TopState() const;
private:
enum { maxkey=64 };
int key[maxkey];
int ascii[maxkey];
int state[maxkey];
int in,out;
};
class NetHackQtClickBuffer {
public:
NetHackQtClickBuffer();
bool Empty() const;
bool Full() const;
void Put(int x, int y, int mod);
int NextX() const;
int NextY() const;
int NextMod() const;
void Get();
private:
enum { maxclick=64 };
struct ClickRec {
int x,y,mod;
} click[maxclick];
int in,out;
};
class NetHackQtSavedGameSelector : public QDialog {
public:
NetHackQtSavedGameSelector(const char** saved);
int choose();
};
class NetHackQtPlayerSelector : private QDialog {
Q_OBJECT
public:
enum { R_None=-1, R_Quit=-2, R_Rand=-3 };
NetHackQtPlayerSelector(NetHackQtKeyBuffer&);
protected:
virtual void done(int);
public slots:
void Quit();
void Random();
void selectName(const QString& n);
void selectRole();
void selectRace();
void setupOthers();
void selectGender(int);
void selectAlignment(int);
public:
bool Choose();
private:
NetHackQtKeyBuffer& keysource;
NhPSListView* role;
NhPSListView* race;
QRadioButton **gender;
QRadioButton **alignment;
bool fully_specified_role;
};
class NetHackQtStringRequestor : QDialog {
private:
QLabel prompt;
NetHackQtLineEdit input;
QPushButton* okay;
QPushButton* cancel;
NetHackQtKeyBuffer& keysource;
virtual void done(int);
public:
NetHackQtStringRequestor(NetHackQtKeyBuffer&, const char* p,const char* cancelstr="Cancel");
void SetDefault(const char*);
bool Get(char* buffer, int maxchar=80);
virtual void resizeEvent(QResizeEvent*);
};
class NetHackQtExtCmdRequestor : public QDialog {
Q_OBJECT
NetHackQtKeyBuffer& keysource;
public:
NetHackQtExtCmdRequestor(NetHackQtKeyBuffer& ks);
int get();
private slots:
void cancel();
void done(int i);
};
class NetHackQtWindow {
public:
NetHackQtWindow();
virtual ~NetHackQtWindow();
virtual QWidget* Widget() =0;
virtual void Clear();
virtual void Display(bool block);
virtual bool Destroy();
virtual void CursorTo(int x,int y);
virtual void PutStr(int attr, const char* text);
virtual void StartMenu();
virtual void AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr,
const char* str, bool presel);
virtual void EndMenu(const char* prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);
virtual void ClipAround(int x,int y);
virtual void PrintGlyph(int x,int y,int glyph);
virtual void UseRIP(int how);
int nhid;
};
class NetHackQtGlyphs {
public:
NetHackQtGlyphs();
int width() const { return size.width(); }
int height() const { return size.height(); }
void toggleSize();
void setSize(int w, int h);
void drawGlyph(QPainter&, int glyph, int pixelx, int pixely);
void drawCell(QPainter&, int glyph, int cellx, int celly);
private:
QImage img;
QPixmap pm,pm1, pm2;
QSize size;
int tiles_per_row;
};
class BlackScrollView : public QScrollView {
public:
BlackScrollView()
{
viewport()->setBackgroundColor(black);
}
};
class NetHackQtMapWindow : public QWidget, public NetHackQtWindow {
Q_OBJECT
private:
NetHackQtClickBuffer& clicksink;
unsigned short glyph[ROWNO][COLNO];
unsigned short& Glyph(int x, int y) { return glyph[y][x]; }
QPoint cursor;
BlackScrollView viewport;
QPixmap pet_annotation;
Clusterizer change;
QFont *rogue_font;
QString messages;
QRect messages_rect;
void Changed(int x,int y);
signals:
void resized();
private slots:
void updateTiles();
void moveMessages(int x, int y);
protected:
virtual void paintEvent(QPaintEvent*);
virtual void mousePressEvent(QMouseEvent*);
public:
NetHackQtMapWindow(NetHackQtClickBuffer& click_sink);
~NetHackQtMapWindow();
virtual QWidget* Widget();
virtual bool Destroy();
virtual void Clear();
virtual void Display(bool block);
virtual void CursorTo(int x,int y);
virtual void PutStr(int attr, const char* text);
virtual void ClipAround(int x,int y);
virtual void PrintGlyph(int x,int y,int glyph);
void Scroll(int dx, int dy);
// For messages
void displayMessages(bool block);
void putMessage(int attr, const char* text);
void clearMessages();
void clickCursor();
};
class NetHackQtScrollText;
class NetHackQtMessageWindow : QObject, public NetHackQtWindow {
Q_OBJECT
public:
NetHackQtMessageWindow();
~NetHackQtMessageWindow();
virtual QWidget* Widget();
virtual void Clear();
virtual void Display(bool block);
virtual void PutStr(int attr, const char* text);
void Scroll(int dx, int dy);
void setMap(NetHackQtMapWindow*);
private:
NetHackQtScrollText* list;
bool changed;
NetHackQtMapWindow* map;
private slots:
void updateFont();
};
class NetHackQtLabelledIcon : public QWidget {
public:
NetHackQtLabelledIcon(QWidget* parent, const char* label);
NetHackQtLabelledIcon(QWidget* parent, const char* label, const QPixmap& icon);
enum { NoNum=-99999 };
void setLabel(const char*, bool lower=TRUE); // a string
void setLabel(const char*, long, const char* tail=""); // a number
void setLabel(const char*, long show_value, long comparative_value, const char* tail="");
void setIcon(const QPixmap&);
virtual void setFont(const QFont&);
void highlightWhenChanging();
void lowIsGood();
void dissipateHighlight();
virtual void show();
protected:
void resizeEvent(QResizeEvent*);
private:
void initHighlight();
void setAlignments();
void highlight(const QPalette& highlight);
void unhighlight();
bool low_is_good;
int prev_value;
int turn_count; /* last time the value changed */
QPalette hl_good;
QPalette hl_bad;
QLabel* label;
QLabel* icon;
};
class NetHackQtStatusWindow : QWidget, public NetHackQtWindow {
Q_OBJECT
public:
NetHackQtStatusWindow();
virtual QWidget* Widget();
virtual void Clear();
virtual void Display(bool block);
virtual void CursorTo(int x,int y);
virtual void PutStr(int attr, const char* text);
void fadeHighlighting();
protected:
void resizeEvent(QResizeEvent*);
private slots:
void doUpdate();
private:
enum { hilight_time=1 };
QPixmap p_str;
QPixmap p_dex;
QPixmap p_con;
QPixmap p_int;
QPixmap p_wis;
QPixmap p_cha;
QPixmap p_chaotic;
QPixmap p_neutral;
QPixmap p_lawful;
QPixmap p_satiated;
QPixmap p_hungry;
QPixmap p_confused;
QPixmap p_sick_fp;
QPixmap p_sick_il;
QPixmap p_blind;
QPixmap p_stunned;
QPixmap p_hallu;
QPixmap p_encumber[5];
NetHackQtLabelledIcon name;
NetHackQtLabelledIcon dlevel;
NetHackQtLabelledIcon str;
NetHackQtLabelledIcon dex;
NetHackQtLabelledIcon con;
NetHackQtLabelledIcon intel;
NetHackQtLabelledIcon wis;
NetHackQtLabelledIcon cha;
NetHackQtLabelledIcon gold;
NetHackQtLabelledIcon hp;
NetHackQtLabelledIcon power;
NetHackQtLabelledIcon ac;
NetHackQtLabelledIcon level;
NetHackQtLabelledIcon exp;
NetHackQtLabelledIcon align;
NetHackQtLabelledIcon time;
NetHackQtLabelledIcon score;
NetHackQtLabelledIcon hunger;
NetHackQtLabelledIcon confused;
NetHackQtLabelledIcon sick_fp;
NetHackQtLabelledIcon sick_il;
NetHackQtLabelledIcon blind;
NetHackQtLabelledIcon stunned;
NetHackQtLabelledIcon hallu;
NetHackQtLabelledIcon encumber;
QFrame hline1;
QFrame hline2;
QFrame hline3;
int cursy;
bool first_set;
void nullOut();
void updateStats();
void checkTurnEvents();
};
class NetHackQtMenuDialog : public QDialog {
Q_OBJECT
public:
NetHackQtMenuDialog();
void Accept();
void Reject();
void SetResult(int);
virtual void done(int);
protected:
void resizeEvent(QResizeEvent*);
signals:
void Resized();
};
class NetHackQtMenuWindow : public QTableView, public NetHackQtWindow {
Q_OBJECT
public:
NetHackQtMenuWindow(NetHackQtKeyBuffer&);
~NetHackQtMenuWindow();
virtual QWidget* Widget();
virtual void StartMenu();
virtual void AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr,
const char* str, bool presel);
virtual void EndMenu(const char* prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);
public slots:
void All();
void ChooseNone();
void Invert();
void Search();
void Layout();
void ToggleSelect(int);
protected:
virtual void keyPressEvent(QKeyEvent*);
//virtual void mouseDoubleClickEvent(QMouseEvent*);
virtual void mousePressEvent(QMouseEvent*);
virtual void mouseReleaseEvent(QMouseEvent*);
virtual void mouseMoveEvent(QMouseEvent*);
virtual void focusOutEvent(QFocusEvent*);
virtual void focusInEvent(QFocusEvent*);
virtual void paintCell(QPainter*, int, int);
virtual int cellWidth(int col);
private:
struct MenuItem {
MenuItem();
~MenuItem();
int glyph;
ANY_P identifier;
int attr;
const char* str;
int count;
char ch;
bool selected;
bool Selectable() const { return identifier.a_void!=0; }
};
QArray<MenuItem> item;
int itemcount;
int str_width;
bool str_fixed;
int next_accel;
NetHackQtKeyBuffer& keysource;
NetHackQtMenuDialog* dialog;
QPushButton* ok;
QPushButton* cancel;
QPushButton* all;
QPushButton* none;
QPushButton* invert;
QPushButton* search;
QLabel prompt;
int how;
bool has_glyphs;
int pressed;
bool was_sel;
};
class NetHackQtTextListBox;
class NetHackQtRIP : public QWidget {
private:
static QPixmap* pixmap;
char** line;
int riplines;
public:
NetHackQtRIP(QWidget* parent);
void setLines(char** l, int n);
protected:
virtual void paintEvent(QPaintEvent* event);
QSize sizeHint() const;
};
class NetHackQtTextWindow : public QDialog, public NetHackQtWindow {
Q_OBJECT
public:
NetHackQtTextWindow(NetHackQtKeyBuffer&);
~NetHackQtTextWindow();
virtual QWidget* Widget();
virtual void Clear();
virtual bool Destroy();
virtual void Display(bool block);
virtual void PutStr(int attr, const char* text);
virtual void UseRIP(int how);
public slots:
void Search();
protected:
virtual void done(int);
virtual void keyPressEvent(QKeyEvent*);
private slots:
void doUpdate();
private:
NetHackQtKeyBuffer& keysource;
bool use_rip;
bool str_fixed;
QPushButton ok;
QPushButton search;
NetHackQtTextListBox* lines;
NetHackQtRIP rip;
};
class NetHackQtMenuOrTextWindow : public NetHackQtWindow {
private:
NetHackQtWindow* actual;
NetHackQtKeyBuffer& keysource;
public:
NetHackQtMenuOrTextWindow(NetHackQtKeyBuffer&);
virtual QWidget* Widget();
// Text
virtual void Clear();
virtual bool Destroy();
virtual void Display(bool block);
virtual void PutStr(int attr, const char* text);
// Menu
virtual void StartMenu();
virtual void AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr,
const char* str, bool presel);
virtual void EndMenu(const char* prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);
};
class NetHackQtDelay : QObject {
private:
int msec;
public:
NetHackQtDelay(int ms);
void wait();
virtual void timerEvent(QTimerEvent* timer);
};
class NetHackQtInvUsageWindow : public QWidget {
public:
NetHackQtInvUsageWindow(QWidget* parent);
virtual void paintEvent(QPaintEvent*);
private:
void drawWorn(QPainter& painter, obj*, int x, int y, bool canbe=TRUE);
};
// This class is the main widget for NetHack
//
// It is a collection of Message, Map, and Status windows. In the current
// version of nethack there is only one of each, and this class makes this
// assumption, not showing itself until all are inserted.
//
// This class simply knows how to layout such children sensibly.
//
// Since it is only responsible for layout, the class does not
// note the actual class of the windows.
//
#ifndef KDE
#include "qt_kde0.h"
#endif
class NetHackQtMainWindow : public KTopLevelWidget {
Q_OBJECT
public:
NetHackQtMainWindow(NetHackQtKeyBuffer&);
void AddMessageWindow(NetHackQtMessageWindow* window);
void AddMapWindow(NetHackQtMapWindow* window);
void AddStatusWindow(NetHackQtStatusWindow* window);
void RemoveWindow(NetHackQtWindow* window);
void updateInventory();
void fadeHighlighting();
public slots:
void doMenuItem(int);
void doKeys(const QString&);
protected:
virtual void resizeEvent(QResizeEvent*);
virtual void keyPressEvent(QKeyEvent*);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void closeEvent(QCloseEvent*);
private slots:
void layout();
void raiseMap();
void zoomMap();
void raiseMessages();
void raiseStatus();
private:
void ShowIfReady();
#ifdef KDE
KMenuBar* menubar;
#else
QMenuBar* menubar;
#endif
NetHackQtMessageWindow* message;
NetHackQtMapWindow* map;
NetHackQtStatusWindow* status;
NetHackQtInvUsageWindow* invusage;
NetHackQtKeyBuffer& keysink;
QWidgetStack* stack;
int dirkey;
const char* *macro;
};
class NetHackQtYnDialog : QDialog {
Q_OBJECT
private:
const char* question;
const char* choices;
char def;
NetHackQtKeyBuffer& keysource;
protected:
virtual void keyPressEvent(QKeyEvent*);
virtual void done(int);
private slots:
void doneItem(int);
public:
NetHackQtYnDialog(NetHackQtKeyBuffer& keysource,const char*,const char*,char);
char Exec();
};
#ifdef KDE
#define NetHackQtBindBase KApplication
#elif defined(QWS)
#define NetHackQtBindBase QPEApplication
#else
#define NetHackQtBindBase QApplication
#endif
class NetHackQtBind : NetHackQtBindBase {
private:
// Single-instance preservation...
NetHackQtBind(int& argc, char** argv);
static NetHackQtBind* instance;
static NetHackQtKeyBuffer keybuffer;
static NetHackQtClickBuffer clickbuffer;
static QWidget* splash;
static NetHackQtMainWindow* main;
public:
static void qt_init_nhwindows(int* argc, char** argv);
static void qt_player_selection();
static void qt_askname();
static void qt_get_nh_event();
static void qt_exit_nhwindows(const char *);
static void qt_suspend_nhwindows(const char *);
static void qt_resume_nhwindows();
static winid qt_create_nhwindow(int type);
static void qt_clear_nhwindow(winid wid);
static void qt_display_nhwindow(winid wid, BOOLEAN_P block);
static void qt_destroy_nhwindow(winid wid);
static void qt_curs(winid wid, int x, int y);
static void qt_putstr(winid wid, int attr, const char *text);
static void qt_display_file(const char *filename, BOOLEAN_P must_exist);
static void qt_start_menu(winid wid);
static void qt_add_menu(winid wid, int glyph,
const ANY_P * identifier, CHAR_P ch, CHAR_P gch, int attr,
const char *str, BOOLEAN_P presel);
static void qt_end_menu(winid wid, const char *prompt);
static int qt_select_menu(winid wid, int how, MENU_ITEM_P **menu_list);
static void qt_update_inventory();
static void qt_mark_synch();
static void qt_wait_synch();
static void qt_cliparound(int x, int y);
static void qt_cliparound_window(winid wid, int x, int y);
static void qt_print_glyph(winid wid,XCHAR_P x,XCHAR_P y,int glyph);
static void qt_raw_print(const char *str);
static void qt_raw_print_bold(const char *str);
static int qt_nhgetch();
static int qt_nh_poskey(int *x, int *y, int *mod);
static void qt_nhbell();
static int qt_doprev_message();
static char qt_yn_function(const char *question, const char *choices, CHAR_P def);
static void qt_getlin(const char *prompt, char *line);
static int qt_get_ext_cmd();
static void qt_number_pad(int);
static void qt_delay_output();
static void qt_start_screen();
static void qt_end_screen();
static void qt_outrip(winid wid, int how);
static int qt_kbhit();
private:
virtual bool notify(QObject *receiver, QEvent *event);
};
#endif
|