]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QAbout.C
Wrap most of the frontend code up inside namespace lyx::frontend.
[features.git] / src / frontends / qt2 / QAbout.C
1 /**
2  * \file QAbout.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Kalle Dalheimer
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "debug.h"
14 #include "support/lstrings.h"
15 #include "support/std_sstream.h"
16 #include "qt_helpers.h"
17 #include "ButtonController.h"
18 #include "ControlAboutlyx.h"
19
20 #include <qlabel.h>
21 #include <qpushbutton.h>
22 #include <qtextview.h>
23
24 #include "QAboutDialog.h"
25 #include "Qt2BC.h"
26 #include "QAbout.h"
27
28 using lyx::support::prefixIs;
29
30 using std::getline;
31
32 using std::istringstream;
33 using std::ostringstream;
34 using std::string;
35
36 namespace lyx {
37 namespace frontend {
38
39 typedef QController<ControlAboutlyx, QView<QAboutDialog> > base_class;
40
41 QAbout::QAbout(Dialog & parent)
42         : base_class(parent, _("About LyX"))
43 {
44 }
45
46
47 void QAbout::build_dialog()
48 {
49         dialog_.reset(new QAboutDialog);
50         connect(dialog_.get()->closePB, SIGNAL(clicked()),
51                 this, SLOT(slotClose()));
52
53         dialog_->copyright->setText(toqstr(controller().getCopyright()));
54         dialog_->copyright->append("\n");
55         dialog_->copyright->append(toqstr(controller().getLicense()));
56         dialog_->copyright->append("\n");
57         dialog_->copyright->append(toqstr(controller().getDisclaimer()));
58
59         dialog_->versionLA->setText(toqstr(controller().getVersion()));
60
61         // The code below should depend on a autoconf test. (Lgb)
62 #if 1
63         // There are a lot of buggy stringstream implementations..., but the
64         // code below will work on all of them (I hope). The drawback with
65         // this solutions os the extra copying. (Lgb)
66
67         ostringstream in;
68         controller().getCredits(in);
69
70         istringstream ss(in.str());
71
72         string s;
73         ostringstream out;
74
75         while (getline(ss, s)) {
76                 if (prefixIs(s, "@b"))
77                         out << "<b>" << s.substr(2) << "</b>";
78                 else if (prefixIs(s, "@i"))
79                         out << "<i>" << s.substr(2) << "</i>";
80                 else
81                         out << s;
82                 out << "<br>";
83         }
84 #else
85         // Good stringstream implementations can handle this. It avoids
86         // some copying, and should thus be faster and use less memory. (Lgb)
87         // I'll make this the default for a short while to see if anyone
88         // see the error...
89         stringstream in;
90         controller().getCredits(in);
91         in.seekg(0);
92         string s;
93         ostringstream out;
94
95         while (getline(in, s)) {
96                 if (prefixIs(s, "@b"))
97                         out << "<b>" << s.substr(2) << "</b>";
98                 else if (prefixIs(s, "@i"))
99                         out << "<i>" << s.substr(2) << "</i>";
100                 else
101                         out << s;
102                 out << "<br>";
103         }
104 #endif
105
106         dialog_->creditsTV->setText(toqstr(out.str()));
107
108         // try to resize to a good size
109         dialog_->copyright->hide();
110         dialog_->setMinimumSize(dialog_->copyright->sizeHint());
111         dialog_->copyright->show();
112         dialog_->setMinimumSize(dialog_->sizeHint());
113
114         // Manage the cancel/close button
115         bcview().setCancel(dialog_->closePB);
116         bc().refresh();
117 }
118
119 } // namespace frontend
120 } // namespace lyx