addToolBar(toolbar);
menubar = menuBar();
- QCoreApplication::setOrganizationName("The NetHack DevTeam");
- QCoreApplication::setOrganizationDomain("nethack.org");
- QCoreApplication::setApplicationName("NetHack");
- {
- char cvers[BUFSZ];
- QString qvers = version_string(cvers);
- QCoreApplication::setApplicationVersion(qvers);
- }
-#ifdef MACOSX
- /* without this, neither control+x nor option+x do anything;
- with it, control+x is ^X and option+x still does nothing */
- QCoreApplication::setAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
-#endif
-
setWindowTitle("Qt NetHack");
setWindowIcon(QIcon(QPixmap(qt_compact_mode ? nh_icon_small : nh_icon)));
void NetHackQtMainWindow::updateInventory()
{
- if ( invusage )
+ if (invusage) {
invusage->repaint();
+ }
}
void NetHackQtMainWindow::fadeHighlighting()
toph,c->width(),maph);
}
#endif
+
+ if (qt_settings && !qt_compact_mode
+ && map && message && status && invusage) {
+ // For the initial PaperDoll sizing, message window
+ // and/or status window might still be empty;
+ // widen them before changing PaperDoll to use saved settings.
+ QList<int> splittersizes = hsplitter->sizes();
+#define MIN_WIN_WIDTH 400
+ if (splittersizes[0] < MIN_WIN_WIDTH
+ || splittersizes[2] < MIN_WIN_WIDTH) {
+ if (splittersizes[0] < MIN_WIN_WIDTH)
+ splittersizes[0] = MIN_WIN_WIDTH;
+#ifndef ENHANCED_PAPERDOLL
+ if (splittersizes[1] < 6) // TILEWMIN
+ splittersizes[1] = 16; // 16x16
+#endif
+ if (splittersizes[2] < MIN_WIN_WIDTH)
+ splittersizes[2] = MIN_WIN_WIDTH;
+ hsplitter->setSizes(splittersizes);
+ }
+#ifdef ENHANCED_PAPERDOLL
+ // call resizePaperDoll() indirectly...
+ qt_settings->resizeDoll();
+#endif
+ }
+}
+
+void NetHackQtMainWindow::resizePaperDoll(bool showdoll)
+{
+#ifdef ENHANCED_PAPERDOLL
+ // this is absurd...
+ NetHackQtInvUsageWindow *w = static_cast <NetHackQtMainWindow *>
+ (NetHackQtBind::mainWidget())->invusage;
+ QList<int> hsplittersizes = hsplitter->sizes(),
+ vsplittersizes = vsplitter->sizes();
+ w->resize(w->sizeHint());
+
+ int oldwidth = hsplittersizes[1],
+ newwidth = w->width();
+ if (newwidth != oldwidth) {
+ if (oldwidth > newwidth)
+ hsplittersizes[0] += (oldwidth - newwidth);
+ else
+ hsplittersizes[2] += (newwidth - oldwidth);
+ hsplittersizes[1] = newwidth;
+ hsplitter->setSizes(hsplittersizes);
+ }
+
+ // Height limit is 48 pixels per doll cell;
+ // values greater than 44 need taller window which pushes the map down.
+ // FIXME: this doesn't shrink the window back if size is reduced from 45+
+ int oldheight = vsplittersizes[0],
+ newheight = w->height();
+ if (newheight > oldheight && oldheight > 0 && vsplittersizes[1] > 0) {
+ vsplittersizes[0] = newheight;
+ vsplitter->setSizes(vsplittersizes);
+ }
+
+ if (showdoll) {
+ if (w->isHidden())
+ w->show();
+ else
+ w->repaint();
+ } else {
+ if (w->isVisible())
+ w->hide();
+ }
+#else
+ nhUse(showdoll);
+#endif /* ENHANCED_PAPERDOLL */
}
void NetHackQtMainWindow::resizeEvent(QResizeEvent*)
// Qt4 conversion copyright (c) Ray Chason, 2012-2014.
// NetHack may be freely redistributed. See license for details.
-// qt_set.cpp -- the Qt settings
+// qt_set.cpp -- Qt-specific settings, saved and restored by Qt so
+// persist not just across save/restore but into new games.
extern "C" {
#include "hack.h"
#include "qt_set.h"
#include "qt_set.moc"
#include "qt_glyph.h"
+#include "qt_main.h"
+#include "qt_bind.h"
#include "qt_str.h"
+// Dialog box accessed via "Qt Settings..." in the games menu (non-OSX)
+// or via "Preferences..." in the application menu (OSX):
+//--
+// "Qt NetHack Settings"
+// "Map:" [ ] Zoomed -- check box
+// tilewidth -- number entry spinner
+// tileheight -- ditto
+// "Invent:" [ ] Shown -- check box
+// dollwidth -- number entry spinner
+// dollheight -- ditto
+// "Font:" fontsize -- Huge:18pt, Large:14, Medium:12, Small:10, Tiny:8
+// [dismiss] -- button
+//--
+// Map remembers 2 size pairs, one for Zoomed unchecked, another for checked.
+// (Player controls whether the box is checked, using the dialog to manually
+// switch back and forth if desired; nothing forces the Zoomed setting to
+// specify larger tile size than not-Zoomed.)
+// Paper doll inventory subset is shown or suppressed depending on check box.
+// (It only remembers one tile size pair and that only matters when shown.
+// The size could be different from both map settings but it is highly
+// recommended that it match one of those unless Zoomed is never toggled.)
+// Font size is used for message window and for text in the status window.
+// (TODO: support separate font sizes for the two windows.)
+// There's no way to undo or avoid saving any changes which player makes but
+// all of the fields can be manually reversed.
+
/* Used by tile/font-size patch below and in ../../src/files.c */
char *qt_tilewidth=NULL;
char *qt_tileheight=NULL;
#define TILEWMIN 6
#define TILEHMIN 6
-NetHackQtSettings::NetHackQtSettings(int w UNUSED, int h UNUSED) :
+NetHackQtSettings::NetHackQtSettings() :
settings(),
+ whichsize("&Zoomed", this),
tilewidth(this),
tileheight(this),
- widthlbl("&Width:",this),
- heightlbl("&Height:",this),
- whichsize("&Zoomed",this),
+ widthlbl("Tile &width:", this),
+ heightlbl("Tile &height:", this),
+#ifdef ENHANCED_PAPERDOLL
+ dollshown("&Shown", this),
+ dollwidth(this),
+ dollheight(this),
+ dollwidthlbl("&Doll width:", this), // should "Doll tile width"...
+ dollheightlbl("Doll height:", this), // ...but that's too verbose
+#endif
fontsize(this),
normal("times"),
#ifdef WS_WIN
#endif
large("times"),
theglyphs(0)
-
{
int default_fontsize;
tilewidth.setRange(TILEWMIN, 128);
heightlbl.setBuddy(&tileheight);
tileheight.setRange(TILEHMIN, 128);
-
tilewidth.setValue(settings.value("tilewidth", 16).toInt());
tileheight.setValue(settings.value("tileheight", 16).toInt());
+#ifdef ENHANCED_PAPERDOLL
+ dollwidthlbl.setBuddy(&dollwidth);
+ dollwidth.setRange(TILEWMIN, 48);
+ dollheightlbl.setBuddy(&dollheight);
+ dollheight.setRange(TILEHMIN, 48);
+ dollwidth.setValue(settings.value("dollwidth", 32).toInt());
+ dollheight.setValue(settings.value("dollheight", 32).toInt());
+ doll_is_shown = settings.value("dollShown", true).toBool();
+ // needed the very first time
+ settings.setValue("dollShown", QVariant(doll_is_shown));
+#endif
default_fontsize = settings.value("fontsize", 2).toInt();
// Tile/font sizes read from .nethackrc
theglyphs=new NetHackQtGlyphs();
resizeTiles();
- connect(&tilewidth,SIGNAL(valueChanged(int)),this,SLOT(resizeTiles()));
- connect(&tileheight,SIGNAL(valueChanged(int)),this,SLOT(resizeTiles()));
- connect(&whichsize,SIGNAL(toggled(bool)),this,SLOT(setGlyphSize(bool)));
+ connect(&whichsize, SIGNAL(toggled(bool)), this, SLOT(setGlyphSize(bool)));
+ connect(&tilewidth, SIGNAL(valueChanged(int)), this, SLOT(resizeTiles()));
+ connect(&tileheight, SIGNAL(valueChanged(int)), this, SLOT(resizeTiles()));
+
+#ifdef ENHANCED_PAPERDOLL
+ connect(&dollshown, SIGNAL(toggled(bool)), this, SLOT(setDollShown(bool)));
+ connect(&dollwidth, SIGNAL(valueChanged(int)), this, SLOT(resizeDoll()));
+ connect(&dollheight, SIGNAL(valueChanged(int)), this, SLOT(resizeDoll()));
+#endif
fontsize.addItem("Huge");
fontsize.addItem("Large");
fontsize.addItem("Small");
fontsize.addItem("Tiny");
fontsize.setCurrentIndex(default_fontsize);
- connect(&fontsize,SIGNAL(activated(int)),this,SLOT(changedFont()));
+ connect(&fontsize, SIGNAL(activated(int)), this, SLOT(changedFont()));
- QGridLayout* grid = new QGridLayout(this);
- grid->addWidget(&whichsize, 0, 0, 1, 2);
- grid->addWidget(&tilewidth, 1, 1); grid->addWidget(&widthlbl, 1, 0);
- grid->addWidget(&tileheight, 2, 1); grid->addWidget(&heightlbl, 2, 0);
- QLabel* flabel=new QLabel("&Font:",this);
+ int row = 0; // used like X11-style XtSetArg(), ++argc
+ QGridLayout *grid = new QGridLayout(this);
+ // dialog box label, spans first two rows and all three columns
+ QLabel *settings_label = new QLabel("Qt NetHack Settings\n", this);
+ grid->addWidget(settings_label, row, 0, 2, 3), row += 2; // uses extra row
+ settings_label->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
+
+ QLabel *map_label = new QLabel("&Map:", this);
+ map_label->setBuddy(&whichsize);
+ grid->addWidget(map_label, row, 0), // "Map: [ ]Zoomed"
+ grid->addWidget(&whichsize, row, 1), ++row;
+ grid->addWidget(&widthlbl, row, 1),
+ grid->addWidget(&tilewidth, row, 2), ++row;
+ grid->addWidget(&heightlbl, row, 1),
+ grid->addWidget(&tileheight, row, 2), ++row;
+
+#ifdef ENHANCED_PAPERDOLL
+ dollshown.QAbstractButton::setChecked(doll_is_shown);
+ QLabel *doll_label = new QLabel("&Invent:", this);
+ doll_label->setBuddy(&dollshown);
+ grid->addWidget(doll_label, row, 0), // "Invent: [ ]Shown"
+ grid->addWidget(&dollshown, row, 1), ++row;
+ grid->addWidget(&dollwidthlbl, row, 1),
+ grid->addWidget(&dollwidth, row, 2), ++row;
+ grid->addWidget(&dollheightlbl, row, 1),
+ grid->addWidget(&dollheight, row, 2), ++row;
+#endif
+
+ QLabel *flabel = new QLabel("&Font:", this);
flabel->setBuddy(&fontsize);
- grid->addWidget(flabel, 3, 0); grid->addWidget(&fontsize, 3, 1);
- QPushButton* dismiss=new QPushButton("Dismiss",this);
+ grid->addWidget(flabel, row, 0),
+ grid->addWidget(&fontsize, row, 1), ++row;
+
+ QPushButton *dismiss = new QPushButton("Dismiss", this);
dismiss->setDefault(true);
- grid->addWidget(dismiss, 4, 0, 1, 2);
- grid->setRowStretch(4,0);
- grid->setColumnStretch(1,1);
- grid->setColumnStretch(2,2);
+ grid->addWidget(dismiss, row, 0, 1, 3), ++row;
+ grid->setRowStretch(row - 1, 0);
+ grid->setColumnStretch(1, 1);
+ grid->setColumnStretch(2, 2);
grid->activate();
- connect(dismiss,SIGNAL(clicked()),this,SLOT(accept()));
- resize(150,140);
+ connect(dismiss, SIGNAL(clicked()), this, SLOT(accept()));
+ resize(150, 140);
}
NetHackQtGlyphs& NetHackQtSettings::glyphs()
void NetHackQtSettings::resizeTiles()
{
- int w = tilewidth.value();
- int h = tileheight.value();
+ tileWidth = tilewidth.value();
+ tileHeight = tileheight.value();
+
+ settings.setValue("tilewidth", tileWidth);
+ settings.setValue("tileheight", tileHeight);
- settings.setValue("tilewidth", tilewidth.value());
- settings.setValue("tileheight", tileheight.value());
- theglyphs->setSize(w,h);
+ theglyphs->setSize(tileWidth, tileHeight);
emit tilesChanged();
}
othersize = n;
}
+#ifdef ENHANCED_PAPERDOLL
+void NetHackQtSettings::resizeDoll()
+{
+ dollWidth = dollwidth.value();
+ dollHeight = dollheight.value();
+
+ settings.setValue("dollwidth", dollWidth);
+ settings.setValue("dollheight", dollHeight);
+ settings.setValue("dollShown", doll_is_shown);
+
+ //NetHackQtMainWindow::resizePaperDoll(doll_is_shown);
+ NetHackQtMainWindow *w = static_cast <NetHackQtMainWindow *>
+ (NetHackQtBind::mainWidget());
+ w->resizePaperDoll(doll_is_shown);
+}
+
+void NetHackQtSettings::toggleDollShown()
+{
+ dollshown.toggle();
+}
+
+void NetHackQtSettings::setDollShown(bool on_off)
+{
+ if (on_off != doll_is_shown) {
+ dollshown.QAbstractButton::setChecked(on_off);
+ doll_is_shown = on_off;
+ resizeDoll();
+ }
+}
+#endif
+
const QFont& NetHackQtSettings::normalFont()
{
static int size[]={ 18, 14, 12, 10, 8 };