19#include <QApplication>
20#include <QGraphicsDropShadowEffect>
23#include <QProgressBar>
30#include <QTextBrowser>
53#define MAX_HELP_TEXT_SIZE 8192
54#define REQ_LABEL_NEVER _("(Never)")
55#define REQ_LABEL_NONE _("?tech:None")
59 enum extra_cause cause = EC_COUNT);
127 QTreeWidgetItem *first;
131 setWindowTitle(
_(
"Freeciv Help Browser"));
134 layout =
new QVBoxLayout(
this);
147 &QTreeWidget::currentItemChanged,
150 help_wdg->layout()->setContentsMargins(0, 0, 0, 0);
153 buttons =
new QWidget;
154 hbox =
new QHBoxLayout;
155 prev_butt =
new QPushButton(style()->standardIcon(
156 QStyle::QStyle::SP_ArrowLeft), (
""));
157 connect(
prev_butt, &QAbstractButton::clicked,
this,
160 next_butt =
new QPushButton(style()->standardIcon(
161 QStyle::QStyle::SP_ArrowRight), (
""));
162 connect(
next_butt, &QAbstractButton::clicked,
this,
165 hbox->addStretch(20);
166 but =
new QPushButton(style()->standardIcon(
167 QStyle::SP_DialogHelpButton),
_(
"About Qt"));
168 connect(but, &QPushButton::pressed, &QApplication::aboutQt);
169 hbox->addWidget(but, Qt::AlignRight);
170 but =
new QPushButton(style()->standardIcon(
171 QStyle::SP_DialogDiscardButton),
_(
"Close"));
172 connect(but, &QPushButton::pressed,
this, &QWidget::close);
173 hbox->addWidget(but, Qt::AlignRight);
174 buttons->setLayout(hbox);
175 layout->addWidget(buttons, 0, Qt::AlignBottom);
197 gui()->qt_settings.help_geometry = saveGeometry();
198 gui()->qt_settings.help_splitter1 =
splitter->saveState();
208 if (!
gui()->qt_settings.help_geometry.isNull()) {
209 restoreGeometry(
gui()->qt_settings.help_geometry);
210 splitter->restoreState(
gui()->qt_settings.help_splitter1);
212 QRect rect = QApplication::primaryScreen()->availableGeometry();
214 resize((rect.width() * 3) / 5, (rect.height() * 3) / 6);
215 sizes << rect.width() / 10 << rect.width() / 3;
225 gui()->qt_settings.help_geometry = saveGeometry();
226 gui()->qt_settings.help_splitter1 =
splitter->saveState();
237 QHash<int, QTreeWidgetItem *>
hash;
239 QTreeWidgetItem *
item;
254 title = pitem->topic;
256 for (s = pitem->topic; *s ==
' '; s++) {
260 item =
new QTreeWidgetItem(QStringList(
title));
262 dep = s - pitem->topic;
271 switch (pitem->type) {
282 icon = QIcon(*spite->
pm);
291 icon = QIcon(*spite->
pm);
298 icon = QIcon(*spite->
pm);
306 icon = QIcon(*spite->
pm);
326 icon = QIcon(*spite->
pm);
334 if (!icon.isNull()) {
335 item->setIcon(0, icon);
350 QHash<QTreeWidgetItem *, const help_item *>::const_iterator
353 if (i.value() == topic) {
437 main_widget(NULL), text_browser(NULL), bottom_panel(NULL),
438 info_panel(NULL), splitter(NULL), info_layout(NULL)
448 main_widget(NULL), text_browser(NULL), bottom_panel(NULL),
449 info_panel(NULL), splitter(NULL), info_layout(NULL)
468 QHBoxLayout *group_layout;
470 layout =
new QVBoxLayout();
475 group_layout =
new QHBoxLayout(
box_wdg);
476 box_wdg->setLayout(group_layout);
477 box_wdg->setFrameShape(QFrame::StyledPanel);
478 box_wdg->setFrameShadow(QFrame::Raised);
519 enum Qt::Orientation main_layout;
520 enum Qt::Orientation bottom_layout;
523 main_layout = Qt::Horizontal;
524 bottom_layout = Qt::Vertical;
526 main_layout = Qt::Vertical;
527 bottom_layout = Qt::Horizontal;
534 splitter =
new QSplitter(bottom_layout);
545 splitter =
new QSplitter(main_layout);
569 l = findChildren<QWidget *>();
572 for (
int i = 0; i < l.size(); ++i) {
574 l.at(i)->setFont(*f);
578 for (
int i = 0; i < l.size(); ++i) {
580 l.at(i)->setFont(*f);
584 for (
int i = 0; i < l.size(); ++i) {
586 l.at(i)->setFont(*f);
628 QLabel *label =
new QLabel();
629 QGraphicsDropShadowEffect *
effect;
631 label->setAlignment(Qt::AlignHCenter);
632 label->setPixmap(*pm);
635 effect =
new QGraphicsDropShadowEffect(label);
638 label->setGraphicsEffect(
effect);
649 QLabel *label =
new QLabel(text);
650 label->setWordWrap(
true);
651 label->setTextFormat(Qt::RichText);
665 int min,
int max,
const QString &value)
673 layout =
new QGridLayout(wdg);
674 layout->setContentsMargins(0, 0, 0, 0);
675 layout->setVerticalSpacing(0);
677 label =
new QLabel(text, wdg);
678 layout->addWidget(label, 0, 0);
680 label =
new QLabel(wdg);
681 if (value.isEmpty()) {
682 label->setNum(progress);
684 label->setText(value);
687 layout->addWidget(label, 0, 1, Qt::AlignRight);
689 bar =
new QProgressBar(wdg);
690 bar->setMaximumHeight(4);
691 bar->setRange(min, max != min ? max : min + 1);
692 bar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
693 bar->setTextVisible(
false);
694 bar->setValue(progress);
695 layout->addWidget(bar, 1, 0, 1, 2);
704 enum unit_activity act,
710 for_terr.
kind = VUT_TERRAIN;
714 if (pextra->buildable
720 tb =
new QLabel(
this);
722 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
723 tb->setTextFormat(Qt::RichText);
725 str =
str + QString(label)
730 tb->setText(
str.trimmed());
731 connect(tb, &QLabel::linkActivated,
744 s = QString(
str).toHtmlEscaped().replace(
" ",
" ");
745 return " <a href=" + QString::number(hpt)
746 +
"," + s +
">" + s +
"</a> ";
776 sl = link.split(
",");
777 n = sl.at(0).toInt();
780 st = st.replace(
"\u00A0",
" ");
783 && strcmp(qPrintable(st),
785 && strcmp(qPrintable(st),
807 switch (topic->
type) {
877 int upkeep, max_upkeep;
939 tb =
new QLabel(
this);
942 str =
"<b>" +
str +
"</b> "
946 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
947 tb->setTextFormat(Qt::RichText);
948 tb->setText(
str.trimmed());
949 connect(tb, &QLabel::linkActivated,
963 tb =
new QLabel(
this);
964 str =
_(
"Obsoleted by");
965 str =
"<b>" +
str +
"</b> "
970 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
971 tb->setTextFormat(Qt::RichText);
972 tb->setText(
str.trimmed());
973 connect(tb, &QLabel::linkActivated,
979 QString(
_(
"Obsoleted by %1."))
1006 QString
str, s1, s2;
1011 topic->
text, itype);
1018 str =
_(
"Base Cost:");
1019 str =
"<b>" +
str +
"</b>" +
" "
1025 str =
"<b>" +
str +
"</b>" +
" "
1026 + QString::number(itype->
upkeep).toHtmlEscaped();
1031 if (!preq->present) {
1035 if (
type == VUT_ADVANCE) {
1038 }
else if (
type == VUT_GOVERNMENT) {
1041 }
else if (
type == VUT_TERRAIN) {
1048 if (!s1.isEmpty()) {
1049 tb =
new QLabel(
this);
1050 str =
_(
"Requirement:");
1051 str =
"<b>" +
str +
"</b> " + s1;
1053 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1054 tb->setTextFormat(Qt::RichText);
1055 tb->setText(
str.trimmed());
1056 connect(tb, &QLabel::linkActivated,
1062 if (pobs->source.kind == VUT_ADVANCE) {
1069 str =
_(
"Obsolete by:");
1070 str =
"<b>" +
str +
"</b> " + s2;
1071 if (!s2.isEmpty()) {
1072 tb =
new QLabel(
this);
1074 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1075 tb->setTextFormat(Qt::RichText);
1076 tb->setText(
str.trimmed());
1077 connect(tb, &QLabel::linkActivated,
1111 if (VUT_ADVANCE == preq->source.kind
1112 && preq->source.value.advance == padvance) {
1113 tb =
new QLabel(
this);
1115 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1116 tb->setTextFormat(Qt::RichText);
1118 str =
"<b>" +
str +
"</b> "
1120 tb->setText(
str.trimmed());
1121 connect(tb, &QLabel::linkActivated,
1131 if (VUT_ADVANCE == preq->source.kind
1132 && preq->source.value.advance == padvance) {
1134 str =
"<b>" +
str +
"</b> "
1138 tb =
new QLabel(
this);
1140 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1141 tb->setTextFormat(Qt::RichText);
1142 tb->setText(
str.trimmed());
1143 connect(tb, &QLabel::linkActivated,
1150 if (pobs->source.kind == VUT_ADVANCE
1151 && pobs->source.value.advance == padvance) {
1152 str =
_(
"Obsoletes");
1153 str =
"<b>" +
str +
"</b> "
1157 tb =
new QLabel(
this);
1159 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1160 tb->setTextFormat(Qt::RichText);
1161 tb->setText(
str.trimmed());
1162 connect(tb, &QLabel::linkActivated,
1171 if (padvance != punittype->require_advance) {
1175 str =
"<b>" +
str +
"</b> "
1177 tb =
new QLabel(
this);
1179 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1180 tb->setTextFormat(Qt::RichText);
1181 tb->setText(
str.trimmed());
1182 connect(tb, &QLabel::linkActivated,
1203 enum extra_cause cause)
1216 for (i = 0; i < 3; ++i) {
1223 if (cause != EC_COUNT) {
1246 const struct canvas *image,
1247 const QString &legend,
1250 QGraphicsDropShadowEffect *
effect;
1252 QGridLayout *
layout =
new QGridLayout();
1254 label =
new QLabel();
1255 effect =
new QGraphicsDropShadowEffect(label);
1256 effect->setBlurRadius(3);
1258 label->setGraphicsEffect(
effect);
1260 layout->addWidget(label, 0, 0, 2, 1);
1262 label =
new QLabel(
title);
1263 label->setTextFormat(Qt::PlainText);
1264 layout->addWidget(label, 0, 1, Qt::AlignBottom);
1267 label =
new QLabel(legend);
1268 label->setTextFormat(Qt::PlainText);
1269 layout->addWidget(label, 1, 1, Qt::AlignTop);
1274 label->setCursor(Qt::WhatsThisCursor);
1277 layout->setColumnStretch(0, 0);
1278 layout->setColumnStretch(1, 100);
1290 struct terrain *pterrain, *max;
1292 bool show_panel =
false;
1302 for_terr.
kind = VUT_TERRAIN;
1306 topic->
text, pterrain);
1340 char cult_buffer[1024];
1342 fc_snprintf(cult_buffer,
sizeof(cult_buffer),
PL_(
"%d turn",
"%d turns",
1345 str =
N_(
"Cultiv. Rslt/Time:");;
1348 + QString(cult_buffer).toHtmlEscaped();
1349 tb =
new QLabel(
this);
1351 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1352 tb->setTextFormat(Qt::RichText);
1353 tb->setText(
str.trimmed());
1354 connect(tb, &QLabel::linkActivated,
1362 char plant_buffer[1024];
1364 fc_snprintf(plant_buffer,
sizeof(plant_buffer),
PL_(
"%d turn",
"%d turns",
1367 str =
N_(
"Plant Rslt/Time:");;
1370 + QString(plant_buffer).toHtmlEscaped();
1371 tb =
new QLabel(
this);
1373 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1374 tb->setTextFormat(Qt::RichText);
1375 tb->setText(
str.trimmed());
1376 connect(tb, &QLabel::linkActivated,
1385 char tf_buffer[1024];
1387 fc_snprintf(tf_buffer,
sizeof(tf_buffer),
PL_(
"%d turn",
"%d turns",
1390 str =
N_(
"Trans. Rslt/Time:");
1393 + QString(tf_buffer).toHtmlEscaped();
1394 tb =
new QLabel(
this);
1396 tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
1397 tb->setTextFormat(Qt::RichText);
1398 tb->setText(
str.trimmed());
1399 connect(tb, &QLabel::linkActivated,
1423 panel =
new QWidget();
1424 vbox =
new QVBoxLayout(panel);
1429 for (r = pterrain->
resources; *r; r++) {
1435 QString(
_(
"Tile output becomes %1, %2, %3."))
1440 _(
"Output (Food, Shields, Trade) of a tile where the resource is "
1447 vbox->addStretch(100);
1448 vbox->setSizeConstraint(QLayout::SetMinimumSize);
1450 area =
new QScrollArea();
1451 area->setWidget(panel);
1454 panel->deleteLater();
1480 topic->
text, pextra);
1515 topic->
text, pspec);
1565 topic->
text, pgood);
1612 for (i = 0; i < count; ++i) {
1615 max->v = max->v > terrain->v ? max->v : terrain->v
1618 SET_MAX(clean_pollution_time);
1620 SET_MAX(irrigation_food_incr);
1680 if (utype->uclass == uclass) {
1683 max->v = max->v > utype->v ? max->v : utype->v
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
void qtg_canvas_free(struct canvas *store)
struct canvas * qtg_canvas_create(int width, int height)
struct canvas int int struct sprite int int int int height
struct canvas int int canvas_y
struct canvas int int struct sprite int int int width
static fc_font * instance()
QFont * get_font(QString name)
void hideEvent(QHideEvent *event)
help_dialog(QWidget *parent=0)
void set_topic(const help_item *item)
void showEvent(QShowEvent *event)
QHash< QTreeWidgetItem *, const help_item * > topics_map
void item_changed(QTreeWidgetItem *item, QTreeWidgetItem *prev)
void closeEvent(QCloseEvent *event)
QList< QTreeWidgetItem * > item_history
static struct fc_sockaddr_list * list
const char * skip_intl_qualifier_prefix(const char *str)
#define PL_(String1, String2, n)
const char * government_name_translation(const struct government *pgovern)
struct government * government_by_translated_name(const char *name)
#define governments_iterate(NAME_pgov)
#define governments_iterate_end
static PangoLayout * layout
void popup_help_dialog_typed(const char *item, enum help_page_type htype)
static struct canvas * terrain_canvas
void helptext_government(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct government *gov)
void helptext_advance(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, int i)
void helptext_extra(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct extra_type *pextra)
void helptext_goods(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct goods_type *pgood)
char * helptext_unit_upkeep_str(const struct unit_type *utype)
const char * helptext_extra_for_terrain_str(struct extra_type *pextra, struct terrain *pterrain, enum unit_activity act)
void helptext_specialist(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct specialist *pspec)
const struct help_item * get_help_item_spec(const char *name, enum help_page_type htype, int *pos)
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
void helptext_terrain(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct terrain *pterrain)
char * helptext_unit(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct unit_type *utype)
void helptext_nation(char *buf, size_t bufsz, struct nation_type *pnation, const char *user_text)
#define help_items_iterate(pitem)
#define help_items_iterate_end
void popdown_help_dialog(void)
void popup_help_dialog_string(const char *item)
static help_dialog * help_dlg
void popup_help_dialog_typed(const char *item, enum help_page_type htype)
#define MAX_HELP_TEXT_SIZE
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
int impr_base_build_shield_cost(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
struct impr_type * improvement_by_translated_name(const char *name)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
void put_drawn_sprites(struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y, int count, struct drawn_sprite *pdrawn, bool fog)
void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
const char * move_points_text(int mp, bool reduce)
const char *const default_font
const char *const notify_label
const char *const help_label
const char *const help_text
struct nation_type * nation_by_translated_plural(const char *name)
void universal_extraction(const struct universal *source, int *kind, int *value)
bool universal_fulfills_requirements(bool check_necessary, const struct requirement_vector *reqs, const struct universal *source)
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
struct specialist * specialist_by_translated_name(const char *name)
struct requirement_vector obsolete_by
struct requirement_vector reqs
struct terrain * cultivate_result
struct extra_type ** resources
struct terrain * plant_result
int road_output_incr_pct[O_LAST]
struct terrain * transform_result
struct unit_class * uclass
const struct unit_type * obsoleted_by
struct advance * require_advance
int fc_snprintf(char *str, size_t n, const char *format,...)
struct advance * advance_by_number(const Tech_type_id atype)
bool is_future_tech(Tech_type_id tech)
struct advance * advance_by_translated_name(const char *name)
const char * advance_name_translation(const struct advance *padvance)
Tech_type_id advance_number(const struct advance *padvance)
Terrain_type_id terrain_count(void)
struct terrain * terrain_by_translated_name(const char *name)
const char * terrain_name_translation(const struct terrain *pterrain)
struct terrain * terrain_by_number(const Terrain_type_id type)
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum direction8 facing)
int tileset_full_tile_height(const struct tileset *t)
int fill_basic_extra_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
int fill_basic_terrain_layer_sprite_array(struct tileset *t, struct drawn_sprite *sprs, int layer, struct terrain *pterrain)
int tileset_tile_height(const struct tileset *t)
int tileset_full_tile_width(const struct tileset *t)
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
struct goods_type * goods_by_translated_name(const char *name)
int utype_build_shield_cost_base(const struct unit_type *punittype)
struct unit_type * unit_type_by_translated_name(const char *name)
const char * utype_name_translation(const struct unit_type *punittype)
#define unit_type_iterate(_p)
#define unit_type_iterate_end