Add Qt4 windowport

Originally by Ray Chason for 3.4.3, based on the Qt windowport by
Warwick Allison. The look and feel is mostly the same.

Some improvements over the Qt 3 interface are:

* Panes are resizable
* Full support for IBMgraphics, and walls and corridors are drawn with
  graphical primitives for a continuous appearance no matter what the font
  says
* Lots of irritating glitches fixed
* Menus support proportional fonts correctly

Adding this because the old Qt windowport cannot be compiled on Qt4,
even with Qt3 compatibility stuff.

TODO:
 - background map glyphs
 - status hilites
 - menucolors
This commit is contained in:
Pasi Kallinen
2017-10-08 01:15:02 +03:00
parent a4706b0928
commit ed335dd0a7
52 changed files with 8024 additions and 9 deletions
+99
View File
@@ -0,0 +1,99 @@
// Copyright (c) Warwick Allison, 1999.
// Qt4 conversion copyright (c) Ray Chason, 2012-2014.
// NetHack may be freely redistributed. See license for details.
// qt4streq.cpp -- string requestor
#include "hack.h"
#undef Invisible
#undef Warning
#undef index
#undef msleep
#undef rindex
#undef wizard
#undef yn
#undef min
#undef max
#include <QtGui/QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets/QtWidgets>
#endif
#include "qt4streq.h"
#include "qt4str.h"
namespace nethack_qt4 {
// temporary
void centerOnMain(QWidget *);
// end temporary
NetHackQtStringRequestor::NetHackQtStringRequestor(QWidget *parent, const char* p, const char* cancelstr) :
QDialog(parent),
prompt(QString::fromLatin1(p),this),
input(this,"input")
{
cancel=new QPushButton(cancelstr,this);
connect(cancel,SIGNAL(clicked()),this,SLOT(reject()));
okay=new QPushButton("Okay",this);
connect(okay,SIGNAL(clicked()),this,SLOT(accept()));
connect(&input,SIGNAL(returnPressed()),this,SLOT(accept()));
okay->setDefault(true);
setFocusPolicy(Qt::StrongFocus);
}
void NetHackQtStringRequestor::resizeEvent(QResizeEvent*)
{
const int margin=5;
const int gutter=5;
int h=(height()-margin*2-gutter);
if (prompt.text().size() > 16) {
h/=3;
prompt.setGeometry(margin,margin,width()-margin*2,h);
input.setGeometry(width()*1/5,margin+h+gutter,
(width()-margin-2-gutter)*4/5,h);
} else {
h/=2;
prompt.setGeometry(margin,margin,(width()-margin*2-gutter)*2/5,h);
input.setGeometry(prompt.geometry().right()+gutter,margin,
(width()-margin-2-gutter)*3/5,h);
}
cancel->setGeometry(margin,input.geometry().bottom()+gutter,
(width()-margin*2-gutter)/2,h);
okay->setGeometry(cancel->geometry().right()+gutter,cancel->geometry().y(),
cancel->width(),h);
}
void NetHackQtStringRequestor::SetDefault(const char* d)
{
input.setText(d);
}
bool NetHackQtStringRequestor::Get(char* buffer, int maxchar)
{
input.setMaxLength(maxchar);
if (prompt.text().size() > 16) {
resize(fontMetrics().width(prompt.text())+50,fontMetrics().height()*6);
} else {
resize(fontMetrics().width(prompt.text())*2+50,fontMetrics().height()*4);
}
centerOnMain(this);
show();
input.setFocus();
exec();
if (result()) {
str_copy(buffer,input.text().toLatin1().constData(),maxchar);
return true;
} else {
return false;
}
}
} // namespace nethack_qt4