#include "qt_post.h"
#include "qt_streq.h"
#include "qt_str.h"
+#include "qt_set.h"
namespace nethack_qt_ {
void centerOnMain(QWidget *);
// end temporary
-NetHackQtStringRequestor::NetHackQtStringRequestor(QWidget *parent, const char* p, const char* cancelstr) :
+NetHackQtStringRequestor::NetHackQtStringRequestor(QWidget *parent,
+ const char *p, const char *cancelstr, const char *okaystr) :
QDialog(parent),
prompt(QString::fromLatin1(p),this),
input(this,"input")
{
+ if (qt_settings)
+ input.setFont(qt_settings->normalFixedFont());
+
cancel=new QPushButton(cancelstr,this);
connect(cancel,SIGNAL(clicked()),this,SLOT(reject()));
- okay=new QPushButton("Okay",this);
+ okay = new QPushButton(okaystr, this);
connect(okay,SIGNAL(clicked()),this,SLOT(accept()));
connect(&input,SIGNAL(returnPressed()),this,SLOT(accept()));
okay->setDefault(true);
const int margin=5;
const int gutter=5;
- int h=(height()-margin*2-gutter);
-
+ int h = (height() - margin * 2 - gutter);
+ int w = (width() - margin * 2 - gutter);
+ int ifw = input.hasFrame() ? 3 : 0; // hack alert for input.frameWidth()
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);
+ h /= 3;
+ prompt.setGeometry(margin + ifw * 2 + 1, margin, w + gutter, h);
+ input.setGeometry(width() * 1 / 5 - ifw, margin + h + gutter,
+ w * 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);
+ h /= 2;
+ prompt.setGeometry(margin + ifw * 2 + 1, margin, w * 2 / 5, h);
+ input.setGeometry(prompt.geometry().right() + gutter
+ - (ifw * 2 + 1) - ifw * 2,
+ margin, w * 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);
+ cancel->setGeometry(margin, input.geometry().bottom() + gutter, w / 2, h);
+ okay->setGeometry(cancel->geometry().right() + gutter,
+ cancel->geometry().y(), w / 2, h);
}
-void NetHackQtStringRequestor::SetDefault(const char* d)
+void NetHackQtStringRequestor::SetDefault(const char *d)
{
input.setText(d);
}
-bool NetHackQtStringRequestor::Get(char* buffer, int maxchar)
+bool NetHackQtStringRequestor::Get(char *buffer, int maxchar, int minchar)
{
- 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);
- }
+ input.setMaxLength(maxchar - 1);
+
+ const QString &txt = prompt.text();
+ int pw = fontMetrics().width(txt),
+ ww = minchar * input.fontMetrics().width(QChar('X'));
+ int heightfactor = ((txt.size() > 16) ? 3 : 2) * 2; // 2 or 3 lines high
+ int widthfudge = (((txt.size() > 16) ? 1 : 2) * 5) * 2; // 5: margn, guttr
+ resize(pw + ww + widthfudge, fontMetrics().height() * heightfactor);
#ifdef EDIT_GETLIN
input.setText(buffer);
exec();
if (result()) {
- str_copy(buffer,input.text().toLatin1().constData(),maxchar);
+ str_copy(buffer, input.text().toLatin1().constData(), maxchar);
return true;
} else {
return false;
QPushButton* cancel;
public:
- NetHackQtStringRequestor(QWidget *parent, const char* p,const char* cancelstr="Cancel");
- void SetDefault(const char*);
- bool Get(char* buffer, int maxchar=80);
- virtual void resizeEvent(QResizeEvent*);
+ NetHackQtStringRequestor(QWidget *parent, const char *p,
+ const char *cancelstr = "Cancel",
+ const char *okaystr = "Okay");
+ void SetDefault(const char *);
+ // maxchar is size of buffer[], minchar is size of line edit widget
+ bool Get(char *buffer, int maxchar = 80, int minchar = 20);
+ virtual void resizeEvent(QResizeEvent *);
};
} // namespace nethack_qt_