]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QAbout.C
Joao latest bits
[lyx.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
37 typedef QController<ControlAboutlyx, QView<QAboutDialog> > base_class;
38
39 QAbout::QAbout(Dialog & parent)
40         : base_class(parent, _("About LyX"))
41 {
42 }
43
44
45 void QAbout::build_dialog()
46 {
47         dialog_.reset(new QAboutDialog);
48         connect(dialog_.get()->closePB, SIGNAL(clicked()),
49                 this, SLOT(slotClose()));
50
51         dialog_->copyright->setText(toqstr(controller().getCopyright()));
52         dialog_->copyright->append("\n");
53         dialog_->copyright->append(toqstr(controller().getLicense()));
54         dialog_->copyright->append("\n");
55         dialog_->copyright->append(toqstr(controller().getDisclaimer()));
56
57         dialog_->versionLA->setText(toqstr(controller().getVersion()));
58
59         // The code below should depend on a autoconf test. (Lgb)
60 #if 1
61         // There are a lot of buggy stringstream implementations..., but the
62         // code below will work on all of them (I hope). The drawback with
63         // this solutions os the extra copying. (Lgb)
64
65         ostringstream in;
66         controller().getCredits(in);
67
68         istringstream ss(in.str());
69
70         string s;
71         ostringstream out;
72
73         while (getline(ss, s)) {
74                 if (prefixIs(s, "@b"))
75                         out << "<b>" << s.substr(2) << "</b>";
76                 else if (prefixIs(s, "@i"))
77                         out << "<i>" << s.substr(2) << "</i>";
78                 else
79                         out << s;
80                 out << "<br>";
81         }
82 #else
83         // Good stringstream implementations can handle this. It avoids
84         // some copying, and should thus be faster and use less memory. (Lgb)
85         // I'll make this the default for a short while to see if anyone
86         // see the error...
87         stringstream in;
88         controller().getCredits(in);
89         in.seekg(0);
90         string s;
91         ostringstream out;
92
93         while (getline(in, s)) {
94                 if (prefixIs(s, "@b"))
95                         out << "<b>" << s.substr(2) << "</b>";
96                 else if (prefixIs(s, "@i"))
97                         out << "<i>" << s.substr(2) << "</i>";
98                 else
99                         out << s;
100                 out << "<br>";
101         }
102 #endif
103
104         dialog_->creditsTV->setText(toqstr(out.str()));
105
106         // try to resize to a good size
107         dialog_->copyright->hide();
108         dialog_->setMinimumSize(dialog_->copyright->sizeHint());
109         dialog_->copyright->show();
110         dialog_->setMinimumSize(dialog_->sizeHint());
111
112         // Manage the cancel/close button
113         bcview().setCancel(dialog_->closePB);
114         bc().refresh();
115 }