Freeciv21
Develop your civilization from humble roots to a global empire
view_research.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2023 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 
12 // utility
13 #include "fc_types.h"
14 // client
15 #include "repodlgs_g.h"
17 
18 class QComboBox;
19 class QGridLayout;
20 class QLabel;
21 class QMouseEvent;
22 class QObject;
23 class QPaintEvent;
24 class QScrollArea;
25 class progress_bar;
26 class QPushButton;
27 class QToolButton;
28 
29 /****************************************************************************
30  Custom widget representing research diagram in science_report
31 ****************************************************************************/
32 class research_diagram : public QWidget {
33  Q_OBJECT
34 
35 public:
36  research_diagram(QWidget *parent = 0);
37  ~research_diagram() override;
38  void update_reqtree();
39  void reset();
40  QSize size();
41  bool get_tech_position(Tech_type_id id, int *x, int *y);
42 private slots:
43  void show_tooltip();
44 
45 private:
46  void mousePressEvent(QMouseEvent *event) override;
47  void mouseMoveEvent(QMouseEvent *event) override;
48  void paintEvent(QPaintEvent *event) override;
49  QPixmap *pcanvas;
50  struct reqtree *req;
52  int width;
53  int height;
54  QList<req_tooltip_help *> *tt_help{nullptr};
55  QPoint tooltip_pos;
56  QString tooltip_text;
57  QRect tooltip_rect;
58 };
59 
60 /****************************************************************************
61  Helper item for comboboxes, holding string of tech and its id
62 ****************************************************************************/
63 struct qlist_item {
64  QString tech_str;
66 };
67 
68 /****************************************************************************
69  Widget embedded as tab on game view (F6 default)
70  Uses string "SCI" to mark it as opened
71  You can check it using if (queen()->is_repo_dlg_open("SCI"))
72 ****************************************************************************/
73 class science_report : public QWidget {
74  Q_OBJECT
75 
76  QScrollArea *scroll;
77  QComboBox *goal_combo;
78  QComboBox *researching_combo;
79  QPushButton *refresh_but;
80  QToolButton *locate_researching_but;
81  QToolButton *locate_goal_but;
83  QLabel *info_label;
84  QLabel *progress_label;
85  QList<qlist_item> *curr_list{nullptr};
86  QList<qlist_item> *goal_list{nullptr};
88 
89 public:
91  ~science_report() override;
92  void update_report();
93  void init(bool raise);
94  void redraw();
95  void reset_tree();
96 
97 private:
98  void update_reqtree();
99  int index{0};
101 
102 private slots:
103  void current_tech_changed(int index);
104  void goal_tech_changed(int index);
105  void push_research();
106  void locate_researching();
107  void locate_goal();
108 };
109 
111 bool comp_less_than(const qlist_item &q1, const qlist_item &q2);
void show_tooltip()
Slot for timer used to show tooltip.
QPixmap * pcanvas
Definition: view_research.h:49
void reset()
Initializes research diagram.
~research_diagram() override
Destructor for research diagram.
QSize size()
Returns size of research_diagram.
bool get_tech_position(Tech_type_id id, int *x, int *y)
Find the center of a node, identified by tech id, and return true if the node was found; false otherw...
void paintEvent(QPaintEvent *event) override
Paint event for research_diagram.
void mousePressEvent(QMouseEvent *event) override
Mouse handler for research_diagram.
struct reqtree * req
Definition: view_research.h:50
QString tooltip_text
Definition: view_research.h:56
QList< req_tooltip_help * > * tt_help
Definition: view_research.h:54
void mouseMoveEvent(QMouseEvent *event) override
Mouse move handler for research_diagram - for showing tooltips.
research_diagram(QWidget *parent=0)
Constructor for research diagram.
void update_reqtree()
Recreates whole diagram and schedules update.
void locate_researching()
Locate the currently researched technology in tree and scroll so that it is visible.
QLabel * progress_label
Definition: view_research.h:84
void locate_goal()
Locate technology goal in tree and scroll so that it is visible.
QPushButton * refresh_but
Definition: view_research.h:79
QToolButton * locate_goal_but
Definition: view_research.h:81
progress_bar * progress
Definition: view_research.h:82
science_report()
Consctructor for science_report.
void push_research()
Push (redo) research when qty bulbs researched is greater than the number needed.
QScrollArea * scroll
Definition: view_research.h:76
QComboBox * goal_combo
Definition: view_research.h:77
QList< qlist_item > * curr_list
Definition: view_research.h:85
QLabel * info_label
Definition: view_research.h:83
QToolButton * locate_researching_but
Definition: view_research.h:80
research_diagram * res_diag
Definition: view_research.h:87
void scroll_reqtree_to_tech(Tech_type_id id)
Scroll the science tree to display the technology identified by tech id.
QList< qlist_item > * goal_list
Definition: view_research.h:86
void update_report()
Updates all important widgets on science_report.
void redraw()
Schedules paint event in some qt queue.
void init(bool raise)
Updates science_report and marks it as opened It has to be called soon after constructor.
void update_reqtree()
Calls update for research_diagram.
void reset_tree()
Recalculates research diagram again and updates science report.
void current_tech_changed(int index)
Slot used when combo box with current tech changes.
void goal_tech_changed(int index)
Slot used when combo box with goal have been changed.
QComboBox * researching_combo
Definition: view_research.h:78
~science_report() override
Destructor for science report Removes "SCI" string marking it as closed And frees given index on list...
enum event_type event
Definition: events.cpp:68
int Tech_type_id
Definition: fc_types.h:294
Tech_type_id id
Definition: view_research.h:65
QString tech_str
Definition: view_research.h:64
bool comp_less_than(const qlist_item &q1, const qlist_item &q2)
Compare unit_items (used for techs) by name.
void popdown_science_report()
Closes science report.