Skip to content

Commit

Permalink
Move the Turn Done button to the bottom right
Browse files Browse the repository at this point in the history
This is a more experimental commit, aimed at understanding which code would be
touched by the changes described in #1002 -- anchoring the button to the bottom
right together with the minimap.

Use a command link button to benefit from the built-in description.
  • Loading branch information
lmoureaux committed Jun 24, 2022
1 parent 262204e commit 59bb8f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
5 changes: 3 additions & 2 deletions client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include <memory>

// Qt
#include <QCommandLinkButton>
#include <QMouseEvent>
#include <QPainter>

// utility
#include "log.h"
// common
Expand Down Expand Up @@ -469,8 +471,7 @@ void update_mouse_cursor(enum cursor_type new_cursor_type)
*/
void update_timeout_label()
{
queen()->sw_endturn->setCustomLabels(QString(get_timeout_label_text()));
queen()->sw_endturn->update();
queen()->endturn->setDescription(get_timeout_label_text());
}

/**
Expand Down
22 changes: 14 additions & 8 deletions client/page_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

#include "page_game.h"
// Qt
#include <QCommandLinkButton>
#include <QGridLayout>
#include <QResizeEvent>

// utility
#include "fcintl.h"
// common
Expand Down Expand Up @@ -101,10 +103,6 @@ pageGame::pageGame(QWidget *parent)
sw_economy->setIcon(
fcIcons::instance()->getIcon(QStringLiteral("economy")));
sw_economy->setCheckable(true);
sw_endturn = new top_bar_widget(_("Turn Done"), QLatin1String(""),
top_bar_finish_turn);
sw_endturn->setIcon(
fcIcons::instance()->getIcon(QStringLiteral("endturn")));
sw_cunit->setRightClick(top_bar_center_unit);
sw_cunit->setWheelUp(cycle_enemy_units);
sw_cunit->setWheelDown(key_unit_wait);
Expand Down Expand Up @@ -139,6 +137,11 @@ pageGame::pageGame(QWidget *parent)
}
});

endturn = new QCommandLinkButton(_("Turn Done"), QLatin1String(""));
connect(endturn, &QAbstractButton::clicked, top_bar_finish_turn);
endturn->setIcon(fcIcons::instance()->getIcon(QStringLiteral("endturn")));
endturn->setParent(mapview_wdg);

top_bar_wdg->addWidget(sw_map);
top_bar_wdg->addWidget(sw_cunit);
top_bar_wdg->addWidget(sw_cities);
Expand All @@ -147,7 +150,6 @@ pageGame::pageGame(QWidget *parent)
top_bar_wdg->addWidget(sw_economy);
top_bar_wdg->addWidget(sw_tax);
top_bar_wdg->addWidget(sw_indicators);
top_bar_wdg->addWidget(sw_endturn);
top_bar_wdg->addWidget(sw_message);

civ_status = new civstatus(mapview_wdg);
Expand Down Expand Up @@ -211,10 +213,9 @@ void pageGame::reloadSidebarIcons()
fcIcons::instance()->getIcon(QStringLiteral("research")));
sw_economy->setIcon(
fcIcons::instance()->getIcon(QStringLiteral("economy")));
sw_endturn->setIcon(
fcIcons::instance()->getIcon(QStringLiteral("endturn")));
sw_message->setIcon(
fcIcons::instance()->getIcon(QStringLiteral("messages")));
endturn->setIcon(fcIcons::instance()->getIcon(QStringLiteral("endturn")));
}

/**
Expand Down Expand Up @@ -545,7 +546,12 @@ void fc_game_tab_widget::resizeEvent(QResizeEvent *event)
queen()->civ_status->move(
qRound(king()->qt_settings.civstatus_x * mapview.width),
qRound(king()->qt_settings.civstatus_y * mapview.height));
// It could be resized before mapview, so delayed it a bit

// QT6: remove the cast (QTBUG-68722)
const auto hint = qobject_cast<QWidget *>(queen()->endturn)->sizeHint();
const auto location = size - hint;
queen()->endturn->move(location.width(), location.height());
queen()->endturn->resize(hint);
}
event->setAccepted(true);
}
Expand Down
4 changes: 3 additions & 1 deletion client/page_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <QStackedWidget>
#include <QWidget>

class QCommandLinkButton;

class city_dialog;
class fc_client;
class map_view;
Expand Down Expand Up @@ -83,7 +85,7 @@ class pageGame : public QWidget {
civstatus *civ_status;
top_bar_widget *sw_diplo;
indicators_widget *sw_indicators;
top_bar_widget *sw_endturn;
QCommandLinkButton *endturn;
top_bar_widget *sw_science;
public slots:
private slots:
Expand Down
7 changes: 4 additions & 3 deletions client/top_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Qt
#include <QAction>
#include <QApplication>
#include <QCommandLinkButton>
#include <QHBoxLayout>
#include <QMenu>
#include <QPaintEvent>
Expand Down Expand Up @@ -492,7 +493,7 @@ void top_bar_disable_end_turn(bool do_restore)
if (king()->current_page() != PAGE_GAME) {
return;
}
queen()->sw_endturn->setEnabled(do_restore);
queen()->endturn->setEnabled(do_restore);
}

/**
Expand All @@ -503,8 +504,8 @@ void top_bar_blink_end_turn(bool do_restore)
if (king()->current_page() != PAGE_GAME) {
return;
}
queen()->sw_endturn->blink = !do_restore;
queen()->sw_endturn->update();
//queen()->endturn->blink = !do_restore;
queen()->endturn->update();
}

/**
Expand Down

0 comments on commit 59bb8f0

Please sign in to comment.