Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button to show/hide the messages widget #1001 #1026

Merged
merged 1 commit into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/fc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
44 changes: 1 addition & 43 deletions client/messagewin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -195,6 +152,7 @@ void message_widget::msg(const struct message *pmsg)
if (icon != nullptr) {
item->setIcon(QIcon(*icon));
}
emit add_msg();
}

/**
Expand Down
7 changes: 4 additions & 3 deletions client/messagewin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
};

Expand Down
36 changes: 32 additions & 4 deletions client/page_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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")));
}

/**
Expand Down Expand Up @@ -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)));
Expand Down
1 change: 1 addition & 0 deletions client/page_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions data/themes/gui-qt/icons/messages.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/themes/gui-qt/icons/messages.svg.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-License-Identifier: MIT
SPDX-FileCopyrightText: Copyright Ant Design
5 changes: 5 additions & 0 deletions data/themes/gui-qt/icons/notify.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/themes/gui-qt/icons/notify.svg.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: Copyright Significa Labs