]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QAbout.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / 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 "QAbout.h"
14 #include "QAboutDialog.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "controllers/ButtonController.h"
19 #include "controllers/ControlAboutlyx.h"
20
21 #include "support/lstrings.h"
22
23 #include <sstream>
24
25 #include <QLabel>
26 #include <QPushButton>
27 #include <QTextCodec>
28 #include <QTextBrowser>
29
30 using lyx::support::prefixIs;
31
32 using std::getline;
33
34 using std::istringstream;
35 using std::ostringstream;
36 using std::string;
37
38 namespace lyx {
39 namespace frontend {
40
41 typedef QController<ControlAboutlyx, QView<QAboutDialog> > base_class;
42
43 QAbout::QAbout(Dialog & parent)
44         : base_class(parent, lyx::to_utf8(_("About LyX")))
45 {
46 }
47
48
49 void QAbout::build_dialog()
50 {
51         dialog_.reset(new QAboutDialog);
52         connect(dialog_.get()->closePB, SIGNAL(clicked()),
53                 this, SLOT(slotClose()));
54
55         dialog_->copyrightTB->setPlainText(toqstr(controller().getCopyright()));
56         dialog_->copyrightTB->append("\n");
57         dialog_->copyrightTB->append(toqstr(controller().getLicense()));
58         dialog_->copyrightTB->append("\n");
59         dialog_->copyrightTB->append(toqstr(controller().getDisclaimer()));
60
61         dialog_->versionLA->setText(toqstr(controller().getVersion()));
62
63         // The code below should depend on a autoconf test. (Lgb)
64 #if 1
65         // There are a lot of buggy stringstream implementations..., but the
66         // code below will work on all of them (I hope). The drawback with
67         // this solutions os the extra copying. (Lgb)
68
69         ostringstream in;
70         controller().getCredits(in);
71
72         istringstream ss(in.str());
73
74         string s;
75         ostringstream out;
76
77         while (getline(ss, s)) {
78                 if (prefixIs(s, "@b"))
79                         out << "<b>" << s.substr(2) << "</b>";
80                 else if (prefixIs(s, "@i"))
81                         out << "<i>" << s.substr(2) << "</i>";
82                 else
83                         out << s;
84                 out << "<br>";
85         }
86 #else
87         // Good stringstream implementations can handle this. It avoids
88         // some copying, and should thus be faster and use less memory. (Lgb)
89         // I'll make this the default for a short while to see if anyone
90         // see the error...
91         stringstream in;
92         controller().getCredits(in);
93         in.seekg(0);
94         string s;
95         ostringstream out;
96
97         while (getline(in, s)) {
98                 if (prefixIs(s, "@b"))
99                         out << "<b>" << s.substr(2) << "</b>";
100                 else if (prefixIs(s, "@i"))
101                         out << "<i>" << s.substr(2) << "</i>";
102                 else
103                         out << s;
104                 out << "<br>";
105         }
106 #endif
107
108         // Try and grab the latin1 codec
109         QTextCodec * const codec =
110                 QTextCodec::codecForName("ISO8859-1");
111         if (!codec)
112                 lyxerr << "Unable to find ISO8859-1 codec" << std::endl;
113
114         QString const qtext = codec ?
115                 codec->toUnicode(out.str().c_str()) :
116                 toqstr(out.str());
117         dialog_->creditsTB->setHtml(qtext);
118
119         // try to resize to a good size
120         dialog_->copyrightTB->hide();
121         dialog_->setMinimumSize(dialog_->copyrightTB->sizeHint());
122         dialog_->copyrightTB->show();
123         dialog_->setMinimumSize(dialog_->sizeHint());
124
125         // Manage the cancel/close button
126         bcview().setCancel(dialog_->closePB);
127         bc().refresh();
128 }
129
130 } // namespace frontend
131 } // namespace lyx