20 #include <QStyleOptionButton>
21 #include <QStylePainter>
29 const int font_increase = 1;
31 const int contents_margin = 10;
33 const int line_separation = 6;
43 setShortcut(Qt::Key_Shift + Qt::Key_Enter);
44 connect(
new QShortcut(Qt::Key_Shift + Qt::Key_Return,
this),
45 &QShortcut::activated,
this, [
this] { animateClick(); });
47 setText(
_(
"Turn Done"));
52 font.setPointSize(font.pointSize() + metrics::font_increase);
56 setContentsMargins(metrics::contents_margin, metrics::contents_margin,
57 metrics::contents_margin, metrics::contents_margin);
67 auto size = QPushButton::sizeHint();
69 const auto margins = contentsMargins();
70 const auto fm_title = QFontMetrics(font());
74 size.setHeight(margins.top() + fm_title.height() + metrics::line_separation
75 + fm_text.height() + margins.bottom());
86 QPushButton::paintEvent(
event);
89 QStylePainter p(
this);
99 isDown() ? style()->pixelMetric(QStyle::PM_ButtonShiftVertical) : 0;
101 isDown() ? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal)
104 const auto margins = contentsMargins();
105 auto text_rect = rect().adjusted(0, margins.top(), 0, -margins.bottom());
106 text_rect = text_rect.translated(hoffset, voffset);
109 p.drawControl(QStyle::CE_PushButton,
option);
112 int title_flags = Qt::TextShowMnemonic | Qt::AlignHCenter | Qt::AlignTop;
113 if (!style()->styleHint(QStyle::SH_UnderlineShortcut, &
option,
this)) {
114 title_flags |= Qt::TextHideMnemonic;
118 p.drawItemText(text_rect, title_flags,
option.palette, isEnabled(),
119 text(), QPalette::ButtonText);
124 text_rect, Qt::AlignHCenter | Qt::AlignBottom | Qt::TextSingleLine,
142 return QString(
Q_(
"?seconds:%1s")).arg(seconds, 2);
143 }
else if (seconds < 5 * 60) {
144 return QString(
Q_(
"?mins/secs:%1min %2s"))
145 .arg(seconds / 60, 2)
146 .arg(seconds % 60, 2);
147 }
else if (seconds < 3600) {
149 return QString(
_(
"%1 minutes")).arg(seconds / 60);
152 const auto minutes = seconds / 60;
153 return QString(
_(
"%1h %2min")).arg(minutes / 60).arg(minutes % 60);
168 const auto now = QDateTime::currentDateTime();
169 const auto turn_change = now.addSecs(duration);
170 const auto days_left = now.daysTo(turn_change);
172 if (duration < 3600) {
174 }
else if (days_left == 0) {
176 QLocale().toString(turn_change, QStringLiteral(
"hh:mm"));
178 return QString(
_(
"until %1")).arg(time);
179 }
else if (days_left == 1) {
181 QLocale().toString(turn_change, QStringLiteral(
"hh:mm"));
183 return QString(
_(
"until tomorrow %1")).arg(time);
184 }
else if (days_left < 7) {
186 QLocale().toString(turn_change, QStringLiteral(
"dddd hh:mm"));
188 return QString(
_(
"until %1")).arg(time);
192 return QString(
PL_(
"%1 day",
"%1 days", days_left)).arg(days_left);
200 QString tooltip =
_(
"End the current turn");
209 tooltip += QStringLiteral(
"\n");
212 tooltip = QString(
_(
"End the current turn (%1 remaining)"))
QFont getFont(const QString &name, double zoom=1.0) const
Returns desired font.
static fcFont * instance()
Returns instance of fc_font.
int get_seconds_to_new_turn()
Return the number of seconds until turn-done.
int get_seconds_to_turndone()
Return the number of seconds until turn-done.
bool is_waiting_turn_change()
Are we in turn-change wait state?
#define PL_(String1, String2, n)
int current_turn_timeout()
Return timeout value for the current turn.
const char *const default_font
Constants used when drawing the button.
struct packet_timeout_info tinfo
The base class for options.