Freeciv21
Develop your civilization from humble roots to a global empire
helpdlg.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9 **************************************************************************/
10 #pragma once
11 // Qt
12 #include <QDialog>
13 #include <QHash>
14 #include <QList>
15 // common
16 #include "extras.h"
17 // client
18 #include "dialogs.h"
19 #include "helpdata.h"
20 
21 class QCloseEvent;
22 class QFrame;
23 class QHideEvent;
24 class QLabel;
25 class QLayout;
26 class QObject;
27 class QPixmap;
28 class QPushButton;
29 class QShowEvent;
30 class QSplitter;
31 class QTextBrowser;
32 class QTreeWidget;
33 class QTreeWidgetItem;
34 class QVBoxLayout;
35 class help_widget;
36 struct help_item;
37 
38 class help_dialog : public qfc_dialog {
39  Q_OBJECT
40  QPushButton *prev_butt;
41  QPushButton *next_butt;
42  QTreeWidget *tree_wdg;
44  QSplitter *splitter;
45  QList<QTreeWidgetItem *> item_history;
46  QHash<QTreeWidgetItem *, const help_item *> topics_map;
48  void make_tree();
49 
50 public:
51  help_dialog(QWidget *parent = 0);
52  void update_fonts();
54 
55 public slots:
56  void set_topic(const help_item *item);
57  void history_forward();
58  void history_back();
59 
60 protected:
61  void showEvent(QShowEvent *event) override;
62  void hideEvent(QHideEvent *event) override;
63  void closeEvent(QCloseEvent *event) override;
64 
65 private slots:
66  void item_changed(QTreeWidgetItem *item, QTreeWidgetItem *prev);
67 
68 private:
69  void update_buttons();
70 };
71 
72 class help_widget : public QWidget {
73  Q_OBJECT
74  QFrame *box_wdg;
75  QLabel *title_label;
76 
77  QWidget *main_widget;
78  QTextBrowser *text_browser;
79  QWidget *bottom_panel;
80  QWidget *info_panel;
81  QSplitter *splitter;
82  QVBoxLayout *info_layout;
83  QList<int> splitter_sizes;
84 
85  void setup_ui();
86 
87  void do_layout();
88  void undo_layout();
89 
90  void show_info_panel();
91  void add_info_pixmap(const QPixmap *pm, bool shadow = false);
92  void add_info_label(const QString &text);
93  void add_info_progress(const QString &label, int progress, int min,
94  int max, const QString &value = QString());
95  void add_extras_of_act_for_terrain(struct terrain *pterr,
96  enum unit_activity act,
97  const char *label);
98  void add_info_separator();
99  void info_panel_done();
100 
101  void set_bottom_panel(QWidget *widget);
102 
103  QLayout *create_terrain_widget(const QString &title, const QPixmap *image,
104  const int &food, const int &sh,
105  const int &eco,
106  const QString &tooltip = QString());
107 
108  void set_topic_other(const help_item *item, const char *title);
109 
110  void set_topic_unit(const help_item *item, const char *title);
111  void set_topic_building(const help_item *item, const char *title);
112  void set_topic_tech(const help_item *item, const char *title);
113  void set_topic_terrain(const help_item *item, const char *title);
114  void set_topic_extra(const help_item *item, const char *title);
115  void set_topic_specialist(const help_item *item, const char *title);
116  void set_topic_government(const help_item *item, const char *title);
117  void set_topic_nation(const help_item *item, const char *title);
118  void set_topic_goods(const help_item *item, const char *title);
119  void make_terrain_lab(QString &str);
120 
121 public:
122  help_widget(QWidget *parent = 0);
123  help_widget(const help_item *item, QWidget *parent = 0);
124  ~help_widget() override;
125  void update_fonts();
126 
127 private:
128  QString link_me(const char *str, help_page_type hpt);
129 
130 public slots:
131  void set_topic(const help_item *item);
132 private slots:
133  void anchor_clicked(const QString &link);
134 
135 public:
136  struct terrain *terrain_max_values();
137  struct unit_type *uclass_max_values(struct unit_class *uclass);
138 };
139 
140 void update_help_fonts();
141 void popup_help_dialog_typed(const char *item, help_page_type htype);
142 void popdown_help_dialog();
QTreeWidget * tree_wdg
Definition: helpdlg.h:42
void showEvent(QShowEvent *event) override
Show event.
Definition: helpdlg.cpp:172
int history_pos
Definition: helpdlg.h:47
bool update_history
Definition: helpdlg.h:53
QPushButton * prev_butt
Definition: helpdlg.h:40
help_dialog(QWidget *parent=0)
Constructor for help dialog.
Definition: helpdlg.cpp:97
void history_forward()
Goes to next topic in history.
Definition: helpdlg.cpp:328
QPushButton * next_butt
Definition: helpdlg.h:41
void set_topic(const help_item *item)
Changes the displayed topic.
Definition: helpdlg.cpp:310
void closeEvent(QCloseEvent *event) override
Close event.
Definition: helpdlg.cpp:192
help_widget * help_wdg
Definition: helpdlg.h:43
void make_tree()
Create the help tree.
Definition: helpdlg.cpp:202
QHash< QTreeWidgetItem *, const help_item * > topics_map
Definition: helpdlg.h:46
void item_changed(QTreeWidgetItem *item, QTreeWidgetItem *prev)
Called when a tree item is activated.
Definition: helpdlg.cpp:379
void update_fonts()
Update fonts for help_wdg.
Definition: helpdlg.cpp:157
void hideEvent(QHideEvent *event) override
Hide event.
Definition: helpdlg.cpp:162
QSplitter * splitter
Definition: helpdlg.h:44
void update_buttons()
Update buttons (back and next)
Definition: helpdlg.cpp:362
QList< QTreeWidgetItem * > item_history
Definition: helpdlg.h:45
void history_back()
Backs in history to previous topic.
Definition: helpdlg.cpp:345
void add_info_separator()
Adds a separator to the information panel.
Definition: helpdlg.cpp:727
QString link_me(const char *str, help_page_type hpt)
Creates link to given help page.
Definition: helpdlg.cpp:716
void add_info_pixmap(const QPixmap *pm, bool shadow=false)
Adds a pixmap to the information panel.
Definition: helpdlg.cpp:594
void show_info_panel()
Creates the information panel.
Definition: helpdlg.cpp:585
void update_fonts()
Updates fonts for manual.
Definition: helpdlg.cpp:533
void set_topic_specialist(const help_item *item, const char *title)
Creates specialist help pages.
Definition: helpdlg.cpp:1475
void info_panel_done()
Called when everything needed has been added to the information panel.
Definition: helpdlg.cpp:735
void add_info_progress(const QString &label, int progress, int min, int max, const QString &value=QString())
Adds a widget indicating a progress to the information panel.
Definition: helpdlg.cpp:632
QSplitter * splitter
Definition: helpdlg.h:81
void anchor_clicked(const QString &link)
Hyperlink clicked, link has 2 variables, string(name of given help) and int(help_page_type)
Definition: helpdlg.cpp:741
void set_bottom_panel(QWidget *widget)
Sets the bottom panel.
Definition: helpdlg.cpp:826
QWidget * main_widget
Definition: helpdlg.h:77
void setup_ui()
Creates the UI.
Definition: helpdlg.cpp:445
void add_info_label(const QString &text)
Adds a text label to the information panel.
Definition: helpdlg.cpp:615
QVBoxLayout * info_layout
Definition: helpdlg.h:82
void set_topic_tech(const help_item *item, const char *title)
Creates technology help pages.
Definition: helpdlg.cpp:1051
void add_extras_of_act_for_terrain(struct terrain *pterr, enum unit_activity act, const char *label)
Create labels about all extras of one cause buildable to the terrain.
Definition: helpdlg.cpp:680
QFrame * box_wdg
Definition: helpdlg.h:74
void set_topic_other(const help_item *item, const char *title)
Creates help pages with no special widgets.
Definition: helpdlg.cpp:834
QLayout * create_terrain_widget(const QString &title, const QPixmap *image, const int &food, const int &sh, const int &eco, const QString &tooltip=QString())
Creates a terrain widget with title, terrain image, legend.
Definition: helpdlg.cpp:1239
void set_topic_extra(const help_item *item, const char *title)
Creates extra help pages.
Definition: helpdlg.cpp:1459
void set_topic(const help_item *item)
Shows the given help page.
Definition: helpdlg.cpp:768
void set_topic_nation(const help_item *item, const char *title)
Creates nation help pages.
Definition: helpdlg.cpp:1509
void undo_layout()
Deletes the widgets created by do_complex_layout().
Definition: helpdlg.cpp:562
~help_widget() override
Destructor.
Definition: helpdlg.cpp:437
QList< int > splitter_sizes
Definition: helpdlg.h:83
struct unit_type * uclass_max_values(struct unit_class *uclass)
Retrieves the maximum values any unit of uclass will ever have.
Definition: helpdlg.cpp:1618
void make_terrain_lab(QString &str)
Definition: helpdlg.cpp:1284
QTextBrowser * text_browser
Definition: helpdlg.h:78
void do_layout()
Lays things out.
Definition: helpdlg.cpp:495
help_widget(QWidget *parent=0)
Creates a new, empty help widget.
Definition: helpdlg.cpp:414
void set_topic_terrain(const help_item *item, const char *title)
Creates terrain help pages.
Definition: helpdlg.cpp:1295
void set_topic_goods(const help_item *item, const char *title)
Creates goods help page.
Definition: helpdlg.cpp:1524
QWidget * info_panel
Definition: helpdlg.h:80
void set_topic_building(const help_item *item, const char *title)
Creates improvement help pages.
Definition: helpdlg.cpp:959
void set_topic_government(const help_item *item, const char *title)
Creates government help pages.
Definition: helpdlg.cpp:1492
void set_topic_unit(const help_item *item, const char *title)
Creates unit help pages.
Definition: helpdlg.cpp:848
QWidget * bottom_panel
Definition: helpdlg.h:79
QLabel * title_label
Definition: helpdlg.h:75
struct terrain * terrain_max_values()
Retrieves the maximum values any terrain will ever have.
Definition: helpdlg.cpp:1547
enum event_type event
Definition: events.cpp:68
help_page_type
Definition: helpdata.h:20
void popup_help_dialog_typed(const char *item, help_page_type htype)
Popup the help dialog to display help on the given string topic from the given section.
Definition: helpdlg.cpp:56
void update_help_fonts()
Updates fonts.
Definition: helpdlg.cpp:87
void popdown_help_dialog()
Close the help dialog.
Definition: helpdlg.cpp:75
Definition: climisc.h:66
struct unit_class * uclass
Definition: unittype.h:519