Freeciv-3.1: /fast/freeciv/nightly/S3_1/tools/ruledit/helpeditor.cpp Source File

Freeciv-3.1

Loading...
Searching...
No Matches
helpeditor.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18// Qt
19#include <QGridLayout>
20#include <QPushButton>
21
22// utility
23#include "fcintl.h"
24#include "mem.h"
25#include "string_vector.h"
26
27// ruledit
28#include "values_dlg.h"
29
30#include "helpeditor.h"
31
32/**********************************************************************/
35helpeditor::helpeditor(values_dlg *parent_dlg, struct strvec *helptext_in) : QDialog()
36{
37 QGridLayout *main_layout = new QGridLayout(this);
38 QPushButton *close_button;
39 int row = 0;
40 int i;
41
42 pdlg = parent_dlg;
43 helptext = helptext_in;
44
45 helps = (QTextEdit **)fc_malloc(sizeof(QTextEdit *) * strvec_size(helptext));
46
47 i = 0;
48 strvec_iterate(helptext, text) {
49 helps[i] = new QTextEdit(QString::fromUtf8(text));
50 helps[i]->setParent(this);
51 main_layout->addWidget(helps[i++], row++, 0);
52 } strvec_iterate_end;
53
54 close_button = new QPushButton(QString::fromUtf8(R__("Close")), this);
55 connect(close_button, SIGNAL(pressed()), this, SLOT(close_now()));
56 main_layout->addWidget(close_button, row++, 0);
57
58 setLayout(main_layout);
59}
60
61/**********************************************************************/
64 void helpeditor::close()
65{
66 int i;
67 int count = strvec_size(helptext);
68
69 for (i = 0; i < count; i++) {
70 QByteArray hbytes;
71
72 hbytes = helps[i]->toPlainText().toUtf8();
73 strvec_set(helptext, i, hbytes.data());
74 }
75
76 free(helps);
77
78 strvec_remove_empty(helptext);
79
80 done(0);
81}
82
83/**********************************************************************/
86 void helpeditor::close_now()
87{
88 // Both closes this dialog, and handles parent's own bookkeeping
89 pdlg->close_help();
90}
helpeditor::close_now
void close_now()
Definition helpeditor.cpp:86
helpeditor::close
void close()
Definition helpeditor.cpp:64
helpeditor::helptext
struct strvec * helptext
Definition helpeditor.h:37
helpeditor::helps
QTextEdit ** helps
Definition helpeditor.h:40
helpeditor::helpeditor
helpeditor(values_dlg *parent_dlg, struct strvec *helptext_in)
Definition helpeditor.cpp:35
helpeditor::pdlg
values_dlg * pdlg
Definition helpeditor.h:38
values_dlg
Definition values_dlg.h:28
values_dlg::close_help
void close_help()
Definition values_dlg.cpp:60
fcintl.h
R__
#define R__(String)
Definition fcintl.h:75
helpeditor.h
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
strvec_set
bool strvec_set(struct strvec *psv, size_t svindex, const char *string)
Definition string_vector.c:305
strvec_size
size_t strvec_size(const struct strvec *psv)
Definition string_vector.c:343
strvec_remove_empty
void strvec_remove_empty(struct strvec *psv)
Definition string_vector.c:207
string_vector.h
strvec_iterate
#define strvec_iterate(psv, str)
Definition string_vector.h:61
strvec_iterate_end
#define strvec_iterate_end
Definition string_vector.h:68
strvec
Definition string_vector.c:29
values_dlg.h