Skip to content

Commit

Permalink
Move the sidebar to the top of the window
Browse files Browse the repository at this point in the history
We decided that the contents of the sidebar would be shown above the map. Start
this change by moving the widget to the top.

See longturn#940.
  • Loading branch information
lmoureaux committed Mar 25, 2022
1 parent 6366d7f commit 5b46499
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 73 deletions.
10 changes: 0 additions & 10 deletions client/gui-qt/gui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ static fc_client *freeciv_qt;
void reset_unit_table();
static void apply_help_font(struct option *poption);
static void apply_notify_font(struct option *poption);
static void apply_sidebar(struct option *poption);
static void apply_titlebar(struct option *poption);

/**
Expand Down Expand Up @@ -134,7 +133,6 @@ void qtg_options_extra_init()
option_var_set_callback(gui_qt_font_chatline, gui_qt_apply_font);
option_var_set_callback(gui_qt_font_notify_label, apply_notify_font);
option_var_set_callback(gui_qt_show_titlebar, apply_titlebar);
option_var_set_callback(gui_qt_sidebar_left, apply_sidebar);
#undef option_var_set_callback
}

Expand Down Expand Up @@ -264,14 +262,6 @@ void apply_titlebar(struct option *poption)
king()->show();
}

/**
Change sidebar position
*/
void apply_sidebar(struct option *poption)
{
queen()->updateSidebarPosition();
}

/**
Change the given font.
*/
Expand Down
29 changes: 5 additions & 24 deletions client/gui-qt/page_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ extern void toggle_units_report(bool);
pageGame::pageGame(QWidget *parent)
: QWidget(parent), unit_selector(nullptr), update_info_timer(nullptr)
{
QGridLayout *page_game_layout;
QGridLayout *game_layout;

page_game_layout = new QGridLayout;
game_main_widget = new QWidget;
game_layout = new QGridLayout;
game_layout->setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -160,15 +158,14 @@ pageGame::pageGame(QWidget *parent)
game_tab_widget->setContentsMargins(0, 0, 0, 0);

game_tab_widget->addWidget(game_main_widget);
if (gui_options.gui_qt_sidebar_left) {
page_game_layout->addWidget(sidebar_wdg, 1, 0);
} else {
page_game_layout->addWidget(sidebar_wdg, 1, 2);
}
page_game_layout->addWidget(game_tab_widget, 1, 1);

auto page_game_layout = new QVBoxLayout;
page_game_layout->addWidget(sidebar_wdg);
page_game_layout->addWidget(game_tab_widget);
page_game_layout->setContentsMargins(0, 0, 0, 0);
page_game_layout->setSpacing(0);
setLayout(page_game_layout);

game_tab_widget->init();
}

Expand All @@ -192,21 +189,6 @@ void pageGame::reloadSidebarIcons()
fcIcons::instance()->getPixmap(QStringLiteral("economy")));
sw_endturn->setPixmap(
fcIcons::instance()->getPixmap(QStringLiteral("endturn")));
sidebar_wdg->resizeMe();
}

/**
Update position
*/
void pageGame::updateSidebarPosition()
{
QGridLayout *l = qobject_cast<QGridLayout *>(layout());
l->removeWidget(queen()->sidebar_wdg);
if (gui_options.gui_qt_sidebar_left) {
l->addWidget(queen()->sidebar_wdg, 1, 0);
} else {
l->addWidget(sidebar_wdg, 1, 2);
}
}

/**
Expand Down Expand Up @@ -515,7 +497,6 @@ void fc_game_tab_widget::resizeEvent(QResizeEvent *event)
QSize size;
size = event->size();
if (C_S_RUNNING <= client_state()) {
queen()->sidebar_wdg->resizeMe();
map_canvas_resized(size.width(), size.height());
queen()->message->resize(
qRound((size.width() * king()->qt_settings.chat_fwidth)),
Expand Down
1 change: 0 additions & 1 deletion client/gui-qt/page_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class pageGame : public QWidget {
public:
pageGame(QWidget *);
~pageGame() override;
void updateSidebarPosition();
void reloadSidebarIcons();
void updateSidebarTooltips();
int addGameTab(QWidget *widget);
Expand Down
17 changes: 0 additions & 17 deletions client/gui-qt/sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,23 +471,6 @@ void sidebar::paint(QPainter *painter, QPaintEvent *event)
painter->drawRect(event->rect());
}

void sidebar::resizeEvent(QResizeEvent *event)
{
if (C_S_RUNNING <= client_state()) {
resizeMe();
}
}

/**
* Resize the sidebar according to the user preference. The default is 90px
* and can be changed in increments of 15px using
* `gui_options.gui_qt_sidebar_width`.
*/
void sidebar::resizeMe()
{
setFixedWidth(15 + gui_options.gui_qt_sidebar_width * 15);
}

/**
Callback to show map
*/
Expand Down
2 changes: 0 additions & 2 deletions client/gui-qt/sidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ class sidebar : public QWidget {
void addWidget(sidebarWidget *fsw);
void addSpacer();
void paint(QPainter *painter, QPaintEvent *event);
void resizeMe();
QList<sidebarWidget *> objects;

protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;

private:
QVBoxLayout *layout;
Expand Down
18 changes: 1 addition & 17 deletions client/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ struct client_options gui_options = {
false, //.gui_qt_fullscreen =
true, //.gui_qt_show_preview =
true, //.gui_qt_allied_chat_only =
true, //.gui_qt_sidebar_left =
0, // font_increase
FC_QT_DEFAULT_THEME_NAME,
"Monospace,8,-1,5,75,0,0,0,0,0", //.gui_qt_font_notify_label =
Expand All @@ -205,7 +204,6 @@ struct client_options gui_options = {
"Sans Serif,10,-1,5,50,1,0,0,0,0", //.gui_qt_font_reqtree_text =
{true}, //=?
true, //.gui_qt_show_titlebar
5,
{}};

/* Set to TRUE after the first call to options_init(), to avoid the usage
Expand Down Expand Up @@ -1469,7 +1467,6 @@ static void manual_turn_done_callback(struct option *poption);
static void voteinfo_bar_callback(struct option *poption);
static void font_changed_callback(struct option *poption);
static void allfont_changed_callback(struct option *poption);
static void sidebar_changed_callback(struct option *poption);
static void mapimg_changed_callback(struct option *poption);
static void game_music_enable_callback(struct option *poption);
static void menu_music_enable_callback(struct option *poption);
Expand Down Expand Up @@ -2026,9 +2023,6 @@ static struct client_option client_options[] = {
"That options is not unsaveable. Hit Apply button"
"after changing this."),
COC_FONT, 0, -100, 100, allfont_changed_callback),
GEN_INT_OPTION(gui_qt_sidebar_width, N_("Sidebar width"),
N_("Change width of sidebar. 1 - narrow, 9 - fat"),
COC_INTERFACE, 5, 1, 31, sidebar_changed_callback),
GEN_FONT_OPTION(gui_qt_font_default, "default_font", N_("Default font"),
N_("This is default font"), COC_FONT,
"Sans Serif,10,-1,5,75,0,0,0,0,0",
Expand Down Expand Up @@ -2073,11 +2067,7 @@ static struct client_option client_options[] = {
N_("If this option is set the client will show "
"information and map preview of current savegame."),
COC_GRAPHICS, true, nullptr),
GEN_BOOL_OPTION(
gui_qt_sidebar_left, N_("Sidebar position"),
N_("If this option is set, the sidebar will be to the left "
"of the map, otherwise to the right."),
COC_INTERFACE, true, nullptr)};
};
static const int client_options_num = ARRAY_SIZE(client_options);

// Iteration loop, including invalid options for the current gui type.
Expand Down Expand Up @@ -4866,12 +4856,6 @@ static void allfont_changed_callback(struct option *poption)
gui_update_allfonts();
}

static void sidebar_changed_callback(struct option *poption)
{
Q_UNUSED(poption)
gui_update_sidebar();
}

/**
Callback for font options.
*/
Expand Down
2 changes: 0 additions & 2 deletions client/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ struct client_options {
bool gui_qt_fullscreen;
bool gui_qt_show_preview;
bool gui_qt_allied_chat_only;
bool gui_qt_sidebar_left;
int gui_qt_increase_fonts;
char gui_qt_default_theme_name[512];
char gui_qt_font_default[512];
Expand All @@ -169,7 +168,6 @@ struct client_options {
char gui_qt_font_city_productions[512];
char gui_qt_font_reqtree_text[512];
bool gui_qt_show_titlebar;
int gui_qt_sidebar_width;

struct overview overview;
};
Expand Down

0 comments on commit 5b46499

Please sign in to comment.