Author: mir3x Date: Wed Oct 12 08:26:30 2016 New Revision: 34103 URL: http://svn.gna.org/viewcvs/freeciv?rev=34103&view=rev Log: Qt client - replaced QInputDialog with custom dialog
See patch #7812 Modified: branches/S2_6/client/gui-qt/citydlg.cpp branches/S2_6/client/gui-qt/hudwidget.cpp branches/S2_6/client/gui-qt/hudwidget.h branches/S2_6/client/gui-qt/mapctrl.cpp branches/S2_6/data/themes/gui-qt/Classic/resource.qss branches/S2_6/data/themes/gui-qt/Necrophos/resource.qss branches/S2_6/data/themes/gui-qt/NightStalker/resource.qss Modified: branches/S2_6/client/gui-qt/citydlg.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/citydlg.cpp?rev=34103&r1=34102&r2=34103&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/citydlg.cpp (original) +++ branches/S2_6/client/gui-qt/citydlg.cpp Wed Oct 12 08:26:30 2016 @@ -19,7 +19,6 @@ #include <QApplication> #include <QDesktopWidget> #include <QHeaderView> -#include <QInputDialog> #include <QMessageBox> #include <QRadioButton> #include <QScrollArea> @@ -1872,15 +1871,12 @@ ****************************************************************************/ void city_dialog::city_rename() { - bool ok; - QString text = QInputDialog::getText(this, - _("Rename City"), - _("What should we rename the city to?"), - QLineEdit::Normal, - city_name_get(pcity), &ok); - - if (ok && !text.isEmpty()) { - ::city_rename(pcity, text.toLocal8Bit().data()); + hud_input_box ask(gui()->central_wdg); + + ask.set_text_title_definput(_("What should we rename the city to?"), + _("Rename City"), city_name_get(pcity)); + if (ask.exec() == QDialog::Accepted) { + ::city_rename(pcity, ask.input_edit.text().toLocal8Bit().data()); } } @@ -1890,26 +1886,28 @@ void city_dialog::save_cma() { struct cm_parameter param; - bool ok; - QString text = QInputDialog::getText(this, - _("Name new preset"), - _("What should we name the preset?"), - QLineEdit::Normal, - _("new preset"), &ok); - - if (ok && !text.isEmpty()) { - param.allow_disorder = false; - param.allow_specialists = true; - param.require_happy = cma_celeb_checkbox->isChecked(); - param.happy_factor = slider_tab[2 * O_LAST + 1]->value(); - - for (int i = O_FOOD; i < O_LAST; i++) { - param.minimal_surplus[i] = slider_tab[2 * i]->value(); - param.factor[i] = slider_tab[2 * i + 1]->value(); - } - - cmafec_preset_add(text.toLocal8Bit().data(), ¶m); - update_cma_tab(); + QString text; + hud_input_box ask(gui()->central_wdg); + + ask.set_text_title_definput(_("What should we name the preset?"), + _("Name new preset"), + _("new preset")); + if (ask.exec() == QDialog::Accepted) { + text = ask.input_edit.text().toLocal8Bit().data(); + if (!text.isEmpty()) { + param.allow_disorder = false; + param.allow_specialists = true; + param.require_happy = cma_celeb_checkbox->isChecked(); + param.happy_factor = slider_tab[2 * O_LAST + 1]->value(); + + for (int i = O_FOOD; i < O_LAST; i++) { + param.minimal_surplus[i] = slider_tab[2 * i]->value(); + param.factor[i] = slider_tab[2 * i + 1]->value(); + } + + cmafec_preset_add(text.toLocal8Bit().data(), ¶m); + update_cma_tab(); + } } } @@ -3142,17 +3140,19 @@ { struct worklist queue; struct global_worklist *gw; - bool ok; - QString text = QInputDialog::getText(this, - _("Save current worklist"), - _("What should we name new worklist?"), - QLineEdit::Normal, - _("New worklist"), &ok); - - if (ok && !text.isEmpty()) { - gw = global_worklist_new(text.toLocal8Bit().data()); - city_get_queue(pcity, &queue); - global_worklist_set(gw, &queue); + QString text; + hud_input_box ask(gui()->central_wdg); + + ask.set_text_title_definput(_("What should we name new worklist?"), + _("Save current worklist"), + _("New worklist")); + if (ask.exec() == QDialog::Accepted) { + text = ask.input_edit.text().toLocal8Bit().data(); + if (!text.isEmpty()) { + gw = global_worklist_new(text.toLocal8Bit().data()); + city_get_queue(pcity, &queue); + global_worklist_set(gw, &queue); + } } } Modified: branches/S2_6/client/gui-qt/hudwidget.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/hudwidget.cpp?rev=34103&r1=34102&r2=34103&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/hudwidget.cpp (original) +++ branches/S2_6/client/gui-qt/hudwidget.cpp Wed Oct 12 08:26:30 2016 @@ -18,6 +18,9 @@ // Qt #include <QGridLayout> #include <QPaintEvent> +#include <QLineEdit> +#include <QDialogButtonBox> +#include <QDebug> #include <QPainter> #include <QSpacerItem> @@ -155,3 +158,158 @@ event->accept(); } +/**************************************************************************** + Custom input box constructor +****************************************************************************/ +hud_input_box::hud_input_box(QWidget *parent): QDialog(parent) +{ + int size; + + setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog + | Qt::FramelessWindowHint); + + f_text = *fc_font::instance()->get_font(fonts::default_font); + f_title = *fc_font::instance()->get_font(fonts::default_font); + + size = f_text.pointSize(); + if (size > 0) { + f_text.setPointSize(size * 4 / 3); + f_title.setPointSize(size * 3 / 2); + } else { + size = f_text.pixelSize(); + f_text.setPixelSize(size * 4 / 3); + f_title.setPointSize(size * 3 / 2); + } + f_title.setBold(true); + f_title.setCapitalization(QFont::SmallCaps); + fm_text = new QFontMetrics(f_text); + fm_title = new QFontMetrics(f_title); + top = 0; + hide(); + mult = 1; +} + +/**************************************************************************** + Sets text, title and default text and shows input box +****************************************************************************/ +void hud_input_box::set_text_title_definput(QString s1, QString s2, + QString def_input) +{ + QSpacerItem *spacer; + QVBoxLayout *layout; + int w, w2, h; + QDialogButtonBox *button_box; + QPoint p; + + button_box = new QDialogButtonBox(QDialogButtonBox::Ok + | QDialogButtonBox::Cancel, + Qt::Horizontal, this); + layout = new QVBoxLayout; + if (s1.contains('\n')) { + int i; + i = s1.indexOf('\n'); + cs1 = s1.left(i); + cs2 = s1.right(s1.count() - i); + mult = 2; + w2 = qMax(fm_text->width(cs1), fm_text->width(cs2)); + w = qMax(w2, fm_title->width(s2)); + } else { + w = qMax(fm_text->width(s1), fm_title->width(s2)); + } + w = w + 20; + h = mult * (fm_text->height() * 3 / 2) + 2 * fm_title->height(); + top = 2 * fm_title->height(); + + spacer = new QSpacerItem(w, h, QSizePolicy::Expanding, + QSizePolicy::Minimum); + layout->addItem(spacer); + layout->addWidget(&input_edit); + layout->addWidget(button_box); + input_edit.setFont(f_text); + input_edit.setText(def_input); + setLayout(layout); + QObject::connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); + QObject::connect(button_box, SIGNAL(rejected()), this, SLOT(reject())); + + text = s1; + title = s2; + p = QPoint((parentWidget()->width() - w) / 2, + (parentWidget()->height() - h) / 2); + p = parentWidget()->mapToGlobal(p); + move(p); + update(); + show(); + input_edit.activateWindow(); + input_edit.setFocus(); + m_timer.start(); + startTimer(41); +} + +/**************************************************************************** + Timer event used to animate input box +****************************************************************************/ +void hud_input_box::timerEvent(QTimerEvent *event) +{ + m_animate_step = m_timer.elapsed() / 40; + update(); +} + + +/**************************************************************************** + Paint event for custom input box +****************************************************************************/ +void hud_input_box::paintEvent(QPaintEvent *event) +{ + QPainter p; + QRect rx, ry; + QLinearGradient g; + QColor c1; + QColor c2; + QColor c3; + int step; + + + step = m_animate_step % 300; + if (step > 150) { + step = step - 150; + step = 150 - step; + } + step = step + 100; + rx = QRect(2 , 2, width() - 4 , top); + ry = QRect(2 , top, width() - 4, height() - top - 4); + + c1 = QColor(palette().color(QPalette::Highlight)); + c2 = QColor(palette().color(QPalette::AlternateBase)); + c3 = QColor(palette().color(QPalette::Highlight)).lighter(145); + step = qMax(0, step); + step = qMin(255, step); + c1.setAlpha(step); + c2.setAlpha(step); + c3.setAlpha(step); + + g = QLinearGradient(0 , 0, width(), height()); + g.setColorAt(0, c1); + g.setColorAt(static_cast<float>(step) / 400, c3); + g.setColorAt(1, c1); + + p.begin(this); + p.fillRect(rx, QColor(palette().color(QPalette::Highlight))); + p.fillRect(ry, QColor(palette().color(QPalette::AlternateBase))); + p.fillRect(rx, g); + p.setFont(f_title); + p.drawText((width() - fm_title->width(title)) / 2, + fm_title->height() * 4 / 3, title); + p.setFont(f_text); + if (mult == 1) { + p.drawText((width() - fm_text->width(text)) / 2, + 2 * fm_title->height() + fm_text->height() * 4 / 3, text); + } else { + p.drawText((width() - fm_text->width(cs1)) / 2, + 2 * fm_title->height() + fm_text->height() * 4 / 3, cs1); + p.drawText((width() - fm_text->width(cs2)) / 2, + 2 * fm_title->height() + fm_text->height() * 8 / 3, cs2); + } + p.end(); + event->accept(); +} + Modified: branches/S2_6/client/gui-qt/hudwidget.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/hudwidget.h?rev=34103&r1=34102&r2=34103&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/hudwidget.h (original) +++ branches/S2_6/client/gui-qt/hudwidget.h Wed Oct 12 08:26:30 2016 @@ -15,8 +15,10 @@ #define FC__HUDWIDGET_H // Qt +#include <QDialog> #include <QMessageBox> #include <QElapsedTimer> +#include <QLineEdit> class QIcon; @@ -31,8 +33,36 @@ public: hud_message_box(QWidget *parent); void set_text_title(QString s1, QString s2); - void update_size(); - + +protected: + void paintEvent(QPaintEvent *event); + void timerEvent(QTimerEvent *event); +private: + int m_animate_step; + QString text; + QString title; + QFontMetrics *fm_text; + QFontMetrics *fm_title; + QFont f_text; + QString cs1, cs2; + QFont f_title; + int top; + int mult; +}; + +/**************************************************************************** + Custom message box with animated background +****************************************************************************/ +class hud_input_box: public QDialog +{ + Q_OBJECT + QElapsedTimer m_timer; + +public: + hud_input_box(QWidget *parent); + void set_text_title_definput(QString s1, QString s2, QString def_input); + QLineEdit input_edit; + protected: void paintEvent(QPaintEvent *event); void timerEvent(QTimerEvent *event); Modified: branches/S2_6/client/gui-qt/mapctrl.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/mapctrl.cpp?rev=34103&r1=34102&r2=34103&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/mapctrl.cpp (original) +++ branches/S2_6/client/gui-qt/mapctrl.cpp Wed Oct 12 08:26:30 2016 @@ -20,7 +20,6 @@ // Qt #include <QApplication> -#include <QInputDialog> #include <QKeyEvent> #include <QPushButton> #include <QMouseEvent> @@ -51,18 +50,15 @@ **************************************************************************/ void popup_newcity_dialog(struct unit *punit, const char *suggestname) { - bool ok; - QString text = QInputDialog::getText(gui()->central_wdg, - _("Build New City"), - _("What should we call our new city?"), - QLineEdit::Normal, - QString::fromUtf8(suggestname), &ok); + hud_input_box ask(gui()->central_wdg); int index = tile_index(unit_tile(punit)); - - if (!ok) { + ask.set_text_title_definput(_("What should we call our new city?"), + _("Build New City"), QString(suggestname)); + if (ask.exec() == QDialog::Accepted) { + finish_city(index_to_tile(index), + ask.input_edit.text().toLocal8Bit().data()); + } else { cancel_city(index_to_tile(index)); - } else { - finish_city(index_to_tile(index), text.toLocal8Bit().data()); } return; Modified: branches/S2_6/data/themes/gui-qt/Classic/resource.qss URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/themes/gui-qt/Classic/resource.qss?rev=34103&r1=34102&r2=34103&view=diff ============================================================================== --- branches/S2_6/data/themes/gui-qt/Classic/resource.qss (original) +++ branches/S2_6/data/themes/gui-qt/Classic/resource.qss Wed Oct 12 08:26:30 2016 @@ -665,7 +665,7 @@ background: transparent; } -hud_message_box { +hud_message_box, hud_input_box { background-color: transparent; color: black; selection-background-color: rgba(231, 214, 176, 220); @@ -683,3 +683,14 @@ border-radius: 8px; padding: 2px; } + +hud_input_box QPushButton { + color: black; + background: rgb(231, 214, 176); + border-top: 3px solid #c3b48e; + border-bottom: 3px solid #c3b48e; + border-right: 3px solid #c3b48e; + border-left: 3px solid #c3b48e; + border-radius: 8px; + padding: 2px; +} Modified: branches/S2_6/data/themes/gui-qt/Necrophos/resource.qss URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/themes/gui-qt/Necrophos/resource.qss?rev=34103&r1=34102&r2=34103&view=diff ============================================================================== --- branches/S2_6/data/themes/gui-qt/Necrophos/resource.qss (original) +++ branches/S2_6/data/themes/gui-qt/Necrophos/resource.qss Wed Oct 12 08:26:30 2016 @@ -613,3 +613,11 @@ alternate-background-color: rgba(220, 220, 220,220); border: 2px solid black; } + +hud_input_box { + background-color: transparent; + color: black; + selection-background-color: rgba(0, 140, 0,220); + alternate-background-color: rgba(220, 220, 220,220); + border: 2px solid black; +} Modified: branches/S2_6/data/themes/gui-qt/NightStalker/resource.qss URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/themes/gui-qt/NightStalker/resource.qss?rev=34103&r1=34102&r2=34103&view=diff ============================================================================== --- branches/S2_6/data/themes/gui-qt/NightStalker/resource.qss (original) +++ branches/S2_6/data/themes/gui-qt/NightStalker/resource.qss Wed Oct 12 08:26:30 2016 @@ -620,3 +620,15 @@ border: 2px solid #3399FF; } +hud_input_box { + background-color: transparent; + color: white; + selection-background-color: rgba(50, 150, 250,220); + alternate-background-color: rgba(0, 0, 60,220); + border: 2px solid #3399FF; +} + +hud_message_box QLineEdit { + text: white; + background: #2704b2; +} _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits