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

Fix minimap show/hide #1103

Merged
merged 4 commits into from
Jul 11, 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
6 changes: 5 additions & 1 deletion client/icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class icon_engine : public QIconEngine {
Q_UNUSED(mode)
Q_UNUSED(state)

if (rect.width() <= 0 || rect.height() <= 0) {
return;
}

auto col = QApplication::palette().color(QPalette::ButtonText);
QString key = path + "-" + QString::number(rect.width()) + "-"
+ QString::number(rect.height()) + "-" + col.name();
Expand All @@ -92,7 +96,7 @@ class icon_engine : public QIconEngine {
}
QPixmapCache::insert(key, pix);
}
painter->drawPixmap(rect.topLeft(), pix);
painter->drawPixmap(rect, pix);
}

QPixmap pixmap(const QSize &size, QIcon::Mode mode,
Expand Down
5 changes: 2 additions & 3 deletions client/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ void mr_menu::setup_menus()
minimap_status->setCheckable(true);
minimap_status->setShortcut(shortcut2key(SC_MINIMAP));
minimap_status->setChecked(true);
connect(minimap_status, &QAction::triggered,
queen()->minimap_panel->minimap(), &QWidget::setVisible);
connect(minimap_status, &QAction::triggered, queen()->minimap_panel,
&minimap_panel::set_minimap_visible);
osd_status = menu->addAction(_("Show new turn information"));
osd_status->setCheckable(true);
osd_status->setChecked(king()->qt_settings.show_new_turn_text);
Expand All @@ -643,7 +643,6 @@ void mr_menu::setup_menus()
lock_status->setShortcut(shortcut2key(SC_IFACE_LOCK));
lock_status->setChecked(false);
connect(lock_status, &QAction::triggered, this, &mr_menu::slot_lock);
connect(minimap_status, &QAction::triggered, this, &mr_menu::slot_lock);
menu->addSeparator();
act = menu->addAction(_("Zoom in"));
act->setShortcut(shortcut2key(SC_ZOOM_IN));
Expand Down
7 changes: 6 additions & 1 deletion client/minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ void minimap_view::update_image()
int minimap_view::heightForWidth(int width) const
{
const auto size = gui_options.overview.map->size();
return size.height() * width / size.width();
if (tileset_is_isometric(tileset)) {
// Traditional iso tilesets have more or less this aspect ratio
return size.height() * width / size.width() / 2;
} else {
return size.height() * width / size.width();
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions client/minimap_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ minimap_panel::minimap_panel(map_view *map, QWidget *parent)
connect(ui.turn_done, &QAbstractButton::clicked, top_bar_finish_turn);
}

/**
* Shows or hides the minimap
*/
void minimap_panel::set_minimap_visible(bool visible)
{
ui.minimap->setVisible(visible);
ui.zoom_in->setVisible(visible);
ui.zoom_reset->setVisible(visible);
ui.zoom_out->setVisible(visible);
ui.spacer->changeSize(0, 0, QSizePolicy::Minimum,
visible ? QSizePolicy::Expanding
: QSizePolicy::Minimum);
// See documentation for QSpacerItem::changeSize
ui.verticalLayout->invalidate();

// This isn't properly propagated by the map view. One day we'll have a
// proper QLayout...
QApplication::postEvent(queen()->game_tab_widget,
new QEvent(QEvent::LayoutRequest));
}

/**
* Update the timeout display. The timeout is the time until the turn ends.
*/
Expand Down
2 changes: 2 additions & 0 deletions client/minimap_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class minimap_panel : public fcwidget {

void update_menu() override {}

void set_minimap_visible(bool visible);

/// Retrieves the minimap widget.
auto minimap() { return ui.minimap; }

Expand Down
12 changes: 12 additions & 0 deletions client/minimap_panel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -72,6 +78,12 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
Expand Down
77 changes: 41 additions & 36 deletions client/page_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,53 +504,58 @@ void fc_game_tab_widget::init()
/**
Resize event for all game tab widgets
*/
void fc_game_tab_widget::resizeEvent(QResizeEvent *event)
bool fc_game_tab_widget::event(QEvent *event)
{
QSize size;
size = event->size();
if (C_S_RUNNING <= client_state()) {
map_canvas_resized(size.width(), size.height());
queen()->message->resize(
qRound((size.width() * king()->qt_settings.chat_fwidth)),
qRound((size.height() * king()->qt_settings.chat_fheight)));
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)));
queen()->chat->move(
qRound((size.width() * king()->qt_settings.chat_fx_pos)),
qRound((size.height() * king()->qt_settings.chat_fy_pos)));
queen()->battlelog_wdg->set_scale(king()->qt_settings.battlelog_scale);
queen()->battlelog_wdg->move(
qRound(king()->qt_settings.battlelog_x * mapview.width),
qRound(king()->qt_settings.battlelog_y * mapview.height));
queen()->x_vote->move(width() / 2 - queen()->x_vote->width() / 2, 0);
queen()->updateSidebarTooltips();
queen()->minimap_panel->turn_done()->setEnabled(
get_turn_done_button_state());
queen()->mapview_wdg->resize(event->size().width(), size.height());
queen()->city_overlay->resize(queen()->mapview_wdg->size());
queen()->unitinfo_wdg->update_actions(nullptr);
queen()->civ_status->move(
qRound(king()->qt_settings.civstatus_x * mapview.width),
qRound(king()->qt_settings.civstatus_y * mapview.height));
if (C_S_RUNNING <= client_state()
&& (event->type() == QEvent::Resize
|| event->type() == QEvent::LayoutRequest)) {
const auto size = event->type() == QEvent::Resize
? static_cast<QResizeEvent *>(event)->size()
: this->size();
if (event->type() == QEvent::Resize) {
map_canvas_resized(size.width(), size.height());
queen()->message->resize(
qRound((size.width() * king()->qt_settings.chat_fwidth)),
qRound((size.height() * king()->qt_settings.chat_fheight)));
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)));
queen()->chat->move(
qRound((size.width() * king()->qt_settings.chat_fx_pos)),
qRound((size.height() * king()->qt_settings.chat_fy_pos)));
queen()->battlelog_wdg->set_scale(king()->qt_settings.battlelog_scale);
queen()->battlelog_wdg->move(
qRound(king()->qt_settings.battlelog_x * mapview.width),
qRound(king()->qt_settings.battlelog_y * mapview.height));
queen()->x_vote->move(width() / 2 - queen()->x_vote->width() / 2, 0);
queen()->civ_status->move(
qRound(king()->qt_settings.civstatus_x * mapview.width),
qRound(king()->qt_settings.civstatus_y * mapview.height));

queen()->updateSidebarTooltips();
queen()->minimap_panel->turn_done()->setEnabled(
get_turn_done_button_state());
queen()->mapview_wdg->resize(size.width(), size.height());
queen()->city_overlay->resize(queen()->mapview_wdg->size());
queen()->unitinfo_wdg->update_actions(nullptr);
}

/*
* Resize the panel at the bottom right.
*/
const auto max_size = QSize(std::max(300, size.width() / 4),
std::max(200, size.height() / 3));
const auto hint = queen()->minimap_panel->sizeHint();
// Try to keep aspect ratio
const auto width = std::min(max_size.width(), hint.width());
const auto height = std::min(
max_size.height(), queen()->minimap_panel->heightForWidth(width));
const auto panel_size = QSize(width, height);
const auto panel_size =
QLayout::closestAcceptableSize(queen()->minimap_panel, max_size);
const auto location = size - panel_size;
queen()->minimap_panel->move(location.width(), location.height());
queen()->minimap_panel->resize(panel_size);

return true;
}
event->setAccepted(true);

return QWidget::event(event);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/page_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class fc_game_tab_widget : public QStackedWidget {
void init();

protected:
void resizeEvent(QResizeEvent *event) override;
bool event(QEvent *event) override;
private slots:
void current_changed(int index);
};
Expand Down