Mercurial > hg > svgui
comparison widgets/TipDialog.cpp @ 228:1c4c9e3e44e6
* updates to tip dialog
author | Chris Cannam |
---|---|
date | Tue, 13 Mar 2007 19:51:09 +0000 |
parents | 6f46179086c0 |
children | 387f2f6fc333 |
comparison
equal
deleted
inserted
replaced
227:6dab3ac2fe73 | 228:1c4c9e3e44e6 |
---|---|
22 #include <QLocale> | 22 #include <QLocale> |
23 #include <QXmlInputSource> | 23 #include <QXmlInputSource> |
24 #include <QFileInfo> | 24 #include <QFileInfo> |
25 #include <QGridLayout> | 25 #include <QGridLayout> |
26 #include <QGroupBox> | 26 #include <QGroupBox> |
27 #include <QCheckBox> | |
27 | 28 |
28 #include <iostream> | 29 #include <iostream> |
29 | 30 |
30 TipDialog::TipDialog(QWidget *parent, Qt::WFlags flags) : | 31 TipDialog::TipDialog(QWidget *parent, Qt::WFlags flags) : |
31 QDialog(parent, flags), | 32 QDialog(parent, flags), |
46 | 47 |
47 QGridLayout *grid = new QGridLayout; | 48 QGridLayout *grid = new QGridLayout; |
48 setLayout(grid); | 49 setLayout(grid); |
49 | 50 |
50 QGroupBox *groupBox = new QGroupBox; | 51 QGroupBox *groupBox = new QGroupBox; |
51 groupBox->setTitle(m_caption); | 52 // groupBox->setTitle(m_caption); |
52 grid->addWidget(groupBox, 0, 0); | 53 grid->addWidget(groupBox, 0, 0); |
53 | 54 |
54 QGridLayout *subgrid = new QGridLayout; | 55 QGridLayout *subgrid = new QGridLayout; |
55 groupBox->setLayout(subgrid); | 56 groupBox->setLayout(subgrid); |
56 | 57 |
57 m_label = new QLabel; | 58 m_label = new QLabel; |
58 subgrid->addWidget(m_label, 0, 0); | 59 subgrid->addWidget(m_label, 0, 0); |
60 m_label->setWordWrap(true); | |
59 | 61 |
60 QHBoxLayout *hbox = new QHBoxLayout; | 62 QHBoxLayout *hbox = new QHBoxLayout; |
61 grid->addLayout(hbox, 1, 0); | 63 grid->addLayout(hbox, 1, 0); |
64 | |
65 QCheckBox *show = new QCheckBox(tr("Show tips on startup")); | |
66 hbox->addWidget(show); | |
67 | |
68 hbox->addStretch(10); | |
69 | |
70 QPushButton *prev = new QPushButton(tr("<< Previous")); | |
71 hbox->addWidget(prev); | |
72 connect(prev, SIGNAL(clicked()), this, SLOT(previous())); | |
73 | |
74 QPushButton *next = new QPushButton(tr("Next >>")); | |
75 hbox->addWidget(next); | |
76 connect(next, SIGNAL(clicked()), this, SLOT(next())); | |
62 | 77 |
63 QPushButton *close = new QPushButton(tr("Close")); | 78 QPushButton *close = new QPushButton(tr("Close")); |
64 hbox->addStretch(10); | |
65 hbox->addWidget(close); | 79 hbox->addWidget(close); |
66 connect(close, SIGNAL(clicked()), this, SLOT(accept())); | 80 connect(close, SIGNAL(clicked()), this, SLOT(accept())); |
67 | 81 |
82 close->setDefault(true); | |
83 | |
68 showTip(); | 84 showTip(); |
69 } | 85 } |
70 | 86 |
71 TipDialog::~TipDialog() | 87 TipDialog::~TipDialog() |
72 { | 88 { |
144 } | 160 } |
145 | 161 |
146 TipDialog::TipFileParser::TipFileParser(TipDialog *dialog) : | 162 TipDialog::TipFileParser::TipFileParser(TipDialog *dialog) : |
147 m_dialog(dialog), | 163 m_dialog(dialog), |
148 m_inTip(false), | 164 m_inTip(false), |
149 m_inText(false) | 165 m_inText(false), |
166 m_inHtml(false) | |
150 { | 167 { |
151 } | 168 } |
152 | 169 |
153 TipDialog::TipFileParser::~TipFileParser() | 170 TipDialog::TipFileParser::~TipFileParser() |
154 { | 171 { |
187 std::cerr << "TipFileParser: adding new tip" << std::endl; | 204 std::cerr << "TipFileParser: adding new tip" << std::endl; |
188 m_dialog->m_tips.push_back(""); | 205 m_dialog->m_tips.push_back(""); |
189 } else { | 206 } else { |
190 std::cerr << "WARNING: TipFileParser: <text> outside <tip> element" << std::endl; | 207 std::cerr << "WARNING: TipFileParser: <text> outside <tip> element" << std::endl; |
191 } | 208 } |
209 } else if (name == "html") { | |
210 if (m_inTip) { | |
211 m_inHtml = true; | |
212 std::cerr << "TipFileParser: adding new tip" << std::endl; | |
213 m_dialog->m_tips.push_back(""); | |
214 } else { | |
215 std::cerr << "WARNING: TipFileParser: <html> outside <tip> element" << std::endl; | |
216 } | |
217 } else if (m_inHtml) { | |
218 m_dialog->m_tips[m_dialog->m_tips.size()-1] += "<" + qName; | |
219 for (int i = 0; i < attributes.count(); ++i) { | |
220 m_dialog->m_tips[m_dialog->m_tips.size()-1] += | |
221 " " + attributes.qName(i) + "=\"" + attributes.value(i) + "\""; | |
222 } | |
223 m_dialog->m_tips[m_dialog->m_tips.size()-1] += ">"; | |
192 } | 224 } |
193 | 225 |
194 std::cerr << "TipFileParser::startElement done" << std::endl; | 226 std::cerr << "TipFileParser::startElement done" << std::endl; |
195 return true; | 227 return true; |
196 } | 228 } |
200 const QString &qName) | 232 const QString &qName) |
201 { | 233 { |
202 QString name = qName.toLower(); | 234 QString name = qName.toLower(); |
203 | 235 |
204 if (name == "text") { | 236 if (name == "text") { |
205 if (m_inText) { | 237 if (!m_inText) { |
206 std::cerr << "WARNING: TipFileParser: </text> without <text>" << std::endl; | 238 std::cerr << "WARNING: TipFileParser: </text> without <text>" << std::endl; |
207 } | 239 } |
208 m_inText = false; | 240 m_inText = false; |
241 } else if (name == "html") { | |
242 if (!m_inHtml) { | |
243 std::cerr << "WARNING: TipFileParser: </html> without <html>" << std::endl; | |
244 } | |
245 m_inHtml = false; | |
209 } else if (name == "tip") { | 246 } else if (name == "tip") { |
210 if (m_inText) { | 247 if (m_inText) { |
211 std::cerr << "WARNING: TipFileParser: <text> without </text>" << std::endl; | 248 std::cerr << "WARNING: TipFileParser: <text> without </text>" << std::endl; |
249 } else if (m_inHtml) { | |
250 std::cerr << "WARNING: TipFileParser: <html> without </html>" << std::endl; | |
212 } else if (!m_inTip) { | 251 } else if (!m_inTip) { |
213 std::cerr << "WARNING: TipFileParser: </tip> without <tip>" << std::endl; | 252 std::cerr << "WARNING: TipFileParser: </tip> without <tip>" << std::endl; |
214 } | 253 } |
215 m_inTip = false; | 254 m_inTip = false; |
255 } else if (m_inHtml) { | |
256 m_dialog->m_tips[m_dialog->m_tips.size()-1] += "</" + qName + ">"; | |
216 } | 257 } |
217 | 258 |
218 return true; | 259 return true; |
219 } | 260 } |
220 | 261 |
221 bool | 262 bool |
222 TipDialog::TipFileParser::characters(const QString &text) | 263 TipDialog::TipFileParser::characters(const QString &text) |
223 { | 264 { |
224 std::cerr << "TipFileParser::characters(" << text.toStdString() << ")" << std::endl; | 265 std::cerr << "TipFileParser::characters(" << text.toStdString() << ")" << std::endl; |
225 | 266 |
226 if (m_inText) { | 267 if (m_inText || m_inHtml) { |
227 m_dialog->m_tips[m_dialog->m_tips.size()-1] += text; | 268 m_dialog->m_tips[m_dialog->m_tips.size()-1] += text; |
228 } | 269 } |
229 | 270 |
230 return true; | 271 return true; |
231 } | 272 } |