diff --git a/client/fc_client.cpp b/client/fc_client.cpp index 60dcdb7cc5..59195dffc3 100644 --- a/client/fc_client.cpp +++ b/client/fc_client.cpp @@ -234,6 +234,10 @@ void fc_client::switch_page(int new_pg) } menuBar()->setVisible(true); queen()->mapview_wdg->setFocus(); + queen()->sw_message->setIcon( + fcIcons::instance()->getIcon(QStringLiteral("messages"))); + queen()->message->hide(); + queen()->message->clr(); center_on_something(); voteinfo_gui_update(); update_info_label(); diff --git a/client/messagewin.cpp b/client/messagewin.cpp index 4a1d993f6f..b13ede837e 100644 --- a/client/messagewin.cpp +++ b/client/messagewin.cpp @@ -53,55 +53,12 @@ message_widget::message_widget(QWidget *parent) mesg_table->setWordWrap(true); layout->addWidget(mesg_table, 1, 0, 1, 3); - mw = new move_widget(this); - layout->addWidget(mw, 0, 0, Qt::AlignLeft | Qt::AlignTop); - - min_max = new QPushButton(this); - min_max->setIcon(fcIcons::instance()->getIcon("expand-up")); - min_max->setIconSize(QSize(24, 24)); - min_max->setFixedWidth(25); - min_max->setFixedHeight(25); - min_max->setCheckable(true); - min_max->setChecked(true); - layout->addWidget(min_max, 0, 2); connect(mesg_table->selectionModel(), &QItemSelectionModel::selectionChanged, this, &message_widget::item_selected); - connect(min_max, &QAbstractButton::toggled, this, - &message_widget::set_events_visible); setMouseTracking(true); } -/** - Manages toggling minimization. - */ -void message_widget::set_events_visible(bool visible) -{ - mesg_table->setVisible(visible); - - int h = visible ? qRound(parentWidget()->size().height() - * king()->qt_settings.chat_fheight) - : sizeHint().height(); - - // Heuristic that more or less works - bool expand_up = - (y() > parentWidget()->height() - y() - (visible ? h : height())); - - QString icon_name = (expand_up ^ visible) ? QLatin1String("expand-up") - : QLatin1String("expand-down"); - min_max->setIcon(fcIcons::instance()->getIcon(icon_name)); - - auto geo = geometry(); - if (expand_up) { - geo.setTop( - std::clamp(geo.bottom() - h, 0, parentWidget()->height() - h)); - geo.setHeight(h); - } else { - geo.setBottom(std::clamp(geo.top() + h, h, parentWidget()->height())); - } - setGeometry(geo); -} - /** Slot executed when selection on meg_table has changed */ @@ -195,6 +152,7 @@ void message_widget::msg(const struct message *pmsg) if (icon != nullptr) { item->setIcon(QIcon(*icon)); } + emit add_msg(); } /** diff --git a/client/messagewin.h b/client/messagewin.h index 0a52228f60..985d3d81dd 100644 --- a/client/messagewin.h +++ b/client/messagewin.h @@ -46,13 +46,14 @@ class message_widget : public resizable_widget { void enterEvent(QEvent *event) override; void leaveEvent(QEvent *event) override; void paintEvent(QPaintEvent *event) override; + public slots: void item_selected(const QItemSelection &sl, const QItemSelection &ds); - void set_events_visible(bool visible); + +signals: + void add_msg(); private: - QPushButton *min_max; - move_widget *mw; static void scroll_to_bottom(void *); }; diff --git a/client/page_game.cpp b/client/page_game.cpp index 19088ea744..272358c5be 100644 --- a/client/page_game.cpp +++ b/client/page_game.cpp @@ -111,6 +111,34 @@ pageGame::pageGame(QWidget *parent) sw_diplo->setRightClick(top_bar_right_click_diplomacy); sw_science->setRightClick(top_bar_right_click_science); + message = new message_widget(mapview_wdg); + message->setAttribute(Qt::WA_NoMousePropagation); + message->hide(); + sw_message = new top_bar_widget( + _("Messages"), QLatin1String(""), +[] { + const auto message = queen()->message; + if (message) { + message->setVisible(!message->isVisible()); + + // change icon to default if icon is notify + const auto sw_message = queen()->sw_message; + if (sw_message) { + queen()->sw_message->setIcon( + fcIcons::instance()->getIcon(QStringLiteral("messages"))); + } + } + }); + sw_message->setIcon( + fcIcons::instance()->getIcon(QStringLiteral("messages"))); + connect( + message, &message_widget::add_msg, +[] { + const auto message = queen()->message; + if (message && !message->isVisible()) { + queen()->sw_message->setIcon( + fcIcons::instance()->getIcon(QStringLiteral("notify"))); + } + }); + top_bar_wdg->addWidget(sw_map); top_bar_wdg->addWidget(sw_cunit); top_bar_wdg->addWidget(sw_cities); @@ -120,6 +148,7 @@ pageGame::pageGame(QWidget *parent) 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); civ_status->setAttribute(Qt::WA_NoMousePropagation); @@ -137,9 +166,6 @@ pageGame::pageGame(QWidget *parent) battlelog_wdg = new hud_battle_log(mapview_wdg); battlelog_wdg->setAttribute(Qt::WA_NoMousePropagation); battlelog_wdg->hide(); - message = new message_widget(mapview_wdg); - message->setAttribute(Qt::WA_NoMousePropagation); - message->show(); chat = new chat_widget(mapview_wdg); chat->setAttribute(Qt::WA_NoMousePropagation); chat->show(); @@ -187,6 +213,8 @@ void pageGame::reloadSidebarIcons() fcIcons::instance()->getIcon(QStringLiteral("economy"))); sw_endturn->setIcon( fcIcons::instance()->getIcon(QStringLiteral("endturn"))); + sw_message->setIcon( + fcIcons::instance()->getIcon(QStringLiteral("messages"))); } /** @@ -491,7 +519,7 @@ void fc_game_tab_widget::resizeEvent(QResizeEvent *event) queen()->message->resize( qRound((size.width() * king()->qt_settings.chat_fwidth)), qRound((size.height() * king()->qt_settings.chat_fheight))); - queen()->message->move(0, 0); + queen()->message->move(size.width() - queen()->message->width(), 0); queen()->chat->resize( qRound((size.width() * king()->qt_settings.chat_fwidth)), qRound((size.height() * king()->qt_settings.chat_fheight))); diff --git a/client/page_game.h b/client/page_game.h index f9486c0790..cd34d639da 100644 --- a/client/page_game.h +++ b/client/page_game.h @@ -74,6 +74,7 @@ class pageGame : public QWidget { hud_battle_log *battlelog_wdg; hud_units *unitinfo_wdg; message_widget *message; + top_bar_widget *sw_message; chat_widget *chat; map_view *mapview_wdg; minimap_view *minimapview_wdg; diff --git a/data/themes/gui-qt/icons/messages.svg b/data/themes/gui-qt/icons/messages.svg new file mode 100644 index 0000000000..248a645b55 --- /dev/null +++ b/data/themes/gui-qt/icons/messages.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/themes/gui-qt/icons/messages.svg.license b/data/themes/gui-qt/icons/messages.svg.license new file mode 100644 index 0000000000..0c0cb8eda0 --- /dev/null +++ b/data/themes/gui-qt/icons/messages.svg.license @@ -0,0 +1,2 @@ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright Ant Design diff --git a/data/themes/gui-qt/icons/notify.svg b/data/themes/gui-qt/icons/notify.svg new file mode 100644 index 0000000000..ceba5417c1 --- /dev/null +++ b/data/themes/gui-qt/icons/notify.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/data/themes/gui-qt/icons/notify.svg.license b/data/themes/gui-qt/icons/notify.svg.license new file mode 100644 index 0000000000..94b1540de2 --- /dev/null +++ b/data/themes/gui-qt/icons/notify.svg.license @@ -0,0 +1,2 @@ +SPDX-License-Identifier: CC0-1.0 +SPDX-FileCopyrightText: Copyright Significa Labs