fb2head.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. #include "fb2head.hpp"
  2. #include <QtDebug>
  3. #include <QAction>
  4. #include <QComboBox>
  5. #include <QDialogButtonBox>
  6. #include <QFormLayout>
  7. #include <QGridLayout>
  8. #include <QHeaderView>
  9. #include <QLabel>
  10. #include <QLineEdit>
  11. #include <QToolBar>
  12. #include <QWebFrame>
  13. #include <QWebPage>
  14. #include <QWebView>
  15. #include <QItemDelegate>
  16. #include <QTreeView>
  17. #include "fb2text.hpp"
  18. #include "fb2utils.h"
  19. //---------------------------------------------------------------------------
  20. // FbScheme::Fb
  21. //---------------------------------------------------------------------------
  22. FbScheme::Fb::Fb()
  23. {
  24. QFile file(":/fb2/FictionBook2.1.xsd");
  25. if (file.open(QIODevice::ReadOnly)) setContent(&file);
  26. }
  27. //---------------------------------------------------------------------------
  28. // FbScheme
  29. //---------------------------------------------------------------------------
  30. const QDomDocument & FbScheme::fb2()
  31. {
  32. static const Fb doc;
  33. return doc;
  34. }
  35. FB2_BEGIN_KEYHASH(FbScheme)
  36. FB2_KEY( XsElement , "xs:element" );
  37. FB2_KEY( XsChoice , "xs:choice" );
  38. FB2_KEY( XsComplexType , "xs:complexType" );
  39. FB2_KEY( XsSequence , "xs:sequence" );
  40. FB2_END_KEYHASH
  41. void FbScheme::items(QStringList &list) const
  42. {
  43. FbScheme child = typeScheme().firstChildElement();
  44. while (!child.isNull()) {
  45. switch (toKeyword(child.tagName())) {
  46. case XsElement: {
  47. QString name = child.attribute("name");
  48. if (!list.contains(name)) list << name;
  49. } break;
  50. case XsChoice:
  51. case XsComplexType:
  52. case XsSequence: {
  53. child.items(list);
  54. } break;
  55. default: ;
  56. }
  57. child = child.nextSiblingElement();
  58. }
  59. }
  60. FbScheme FbScheme::typeScheme() const
  61. {
  62. QString typeName = type();
  63. if (typeName.isEmpty()) return *this;
  64. FbScheme child = fb2().firstChildElement("xs:schema").firstChildElement();
  65. while (!child.isNull()) {
  66. if (child.tagName() == "xs:complexType") {
  67. if (child.attribute("name") == typeName) return child.element(typeName);
  68. }
  69. child = child.nextSiblingElement();
  70. }
  71. return FbScheme();
  72. }
  73. QString FbScheme::info() const
  74. {
  75. QDomElement element = *this;
  76. if (element.isNull()) return QString();
  77. element = element.firstChildElement("xs:annotation");
  78. if (element.isNull()) return QString();
  79. element = element.firstChildElement("xs:documentation");
  80. if (element.isNull()) return QString();
  81. return element.text();
  82. }
  83. QString FbScheme::type() const
  84. {
  85. if (isNull()) return QString();
  86. QString result = attribute("type");
  87. if (!result.isEmpty()) return result;
  88. FbScheme child = firstChildElement("xs:complexType");
  89. child = child.firstChildElement("xs:complexContent");
  90. child = child.firstChildElement("xs:extension");
  91. return child.attribute("base");
  92. }
  93. FbScheme FbScheme::element(const QString &name) const
  94. {
  95. FbScheme parent = *this;
  96. if (parent.isNull()) {
  97. parent = fb2().documentElement();
  98. parent = parent.element("FictionBook");
  99. }
  100. FbScheme child = parent.firstChildElement();
  101. while (!child.isNull()) {
  102. switch (toKeyword(child.tagName())) {
  103. case XsElement: {
  104. if (child.attribute("name") == name) return child;
  105. } break;
  106. case XsChoice:
  107. case XsComplexType:
  108. case XsSequence: {
  109. FbScheme result = child.element(name);
  110. if (!result.isNull()) return result;
  111. } break;
  112. default: ;
  113. }
  114. child = child.nextSiblingElement();
  115. }
  116. QString type = this->type();
  117. if (type.isEmpty()) return *this;
  118. child = fb2().firstChildElement("xs:schema").firstChildElement();
  119. while (!child.isNull()) {
  120. if (child.tagName() == "xs:complexType") {
  121. if (child.attribute("name") == type) return child.element(name);
  122. }
  123. child = child.nextSiblingElement();
  124. }
  125. return FbScheme();
  126. }
  127. //---------------------------------------------------------------------------
  128. // FbHeadItem
  129. //---------------------------------------------------------------------------
  130. FbHeadItem::HintHash::HintHash()
  131. {
  132. insert( "title-info" , tr( "Book" ));
  133. insert( "document-info" , tr( "File" ));
  134. insert( "publish-info" , tr( "Publish" ));
  135. insert( "custom-info" , tr( "Add-ons" ));
  136. insert( "genre" , tr( "Genre" ));
  137. insert( "author" , tr( "Author" ));
  138. insert( "book-title" , tr( "Title" ));
  139. insert( "annotation" , tr( "Annotation" ));
  140. insert( "coverpage" , tr( "Cover" ));
  141. insert( "date" , tr( "Date" ));
  142. insert( "lang" , tr( "Language" ));
  143. insert( "translator" , tr( "Translator" ));
  144. insert( "sequence" , tr( "Sequence" ));
  145. insert( "first-name" , tr( "First name" ));
  146. insert( "middle-name" , tr( "Middle name" ));
  147. insert( "last-name" , tr( "Last name" ));
  148. insert( "history" , tr( "History" ));
  149. }
  150. FB2_BEGIN_KEYHASH(FbHeadItem)
  151. FB2_KEY( Auth , "author" );
  152. FB2_KEY( Cover , "coverpage" );
  153. FB2_KEY( Image , "image" );
  154. FB2_KEY( Seqn , "sequence" );
  155. FB2_END_KEYHASH
  156. FbHeadItem::FbHeadItem(QWebElement &element, FbHeadItem *parent)
  157. : QObject(parent)
  158. , m_element(element)
  159. , m_parent(parent)
  160. {
  161. m_name = element.tagName().toLower();
  162. m_id = element.attribute("id");
  163. if (m_name == "div") {
  164. QString style = element.attribute("class").toLower();
  165. if (!style.isEmpty()) m_name = style;
  166. if (style == "annotation") return;
  167. if (style == "history") return;
  168. } else if (m_name == "img") {
  169. m_name = "image";
  170. m_text = element.attribute("alt");
  171. }
  172. addChildren(element);
  173. }
  174. FbHeadItem::~FbHeadItem()
  175. {
  176. foreach (FbHeadItem * item, m_list) {
  177. delete item;
  178. }
  179. }
  180. FbHeadItem * FbHeadItem::append(const QString name)
  181. {
  182. m_element.appendInside("<div></div>");
  183. QWebElement element = m_element.lastChild();
  184. element.addClass(name);
  185. if (name == "annotation" || name == "history") {
  186. element.appendInside("<p><br></p>");
  187. }
  188. FbHeadItem * child = new FbHeadItem(element, this);
  189. m_list << child;
  190. return child;
  191. }
  192. void FbHeadItem::addChildren(QWebElement &parent)
  193. {
  194. QWebElement child = parent.firstChild();
  195. while (!child.isNull()) {
  196. QString tag = child.tagName().toLower();
  197. if (tag == "div") {
  198. m_list << new FbHeadItem(child, this);
  199. } else if (tag == "img") {
  200. m_list << new FbHeadItem(child, this);
  201. } else {
  202. addChildren(child);
  203. }
  204. child = child.nextSibling();
  205. }
  206. }
  207. FbHeadItem * FbHeadItem::item(const QModelIndex &index) const
  208. {
  209. int row = index.row();
  210. if (row < 0 || row >= m_list.size()) return NULL;
  211. return m_list[row];
  212. }
  213. FbHeadItem * FbHeadItem::item(int row) const
  214. {
  215. if (row < 0 || row >= m_list.size()) return NULL;
  216. return m_list[row];
  217. }
  218. QString FbHeadItem::text(int col) const
  219. {
  220. switch (col) {
  221. case 0: return QString("<%1> %2").arg(m_name).arg(hint());
  222. case 1: return value();
  223. case 2: return scheme().info();
  224. case 3: return scheme().type();
  225. case 4: return scheme().attribute("minOccurs");
  226. case 5: return scheme().attribute("maxOccurs");
  227. }
  228. return QString();
  229. }
  230. QString FbHeadItem::hint() const
  231. {
  232. static HintHash hints;
  233. HintHash::const_iterator it = hints.find(m_name);
  234. if (it == hints.end()) return QString();
  235. return it.value();
  236. }
  237. QString FbHeadItem::value() const
  238. {
  239. switch (toKeyword(m_name)) {
  240. case Auth : {
  241. QString result = sub("last-name");
  242. result += " " + sub("first-name");
  243. result += " " + sub("middle-name");
  244. return result.simplified();
  245. } break;
  246. case Cover : {
  247. QString text;
  248. foreach (FbHeadItem * item, m_list) {
  249. if (item->m_name == "image") {
  250. if (!text.isEmpty()) text += ", ";
  251. text += item->value();
  252. }
  253. }
  254. return text;
  255. } break;
  256. case Image : {
  257. return m_element.attribute("src");
  258. } break;
  259. case Seqn : {
  260. QString text = m_element.attribute("fb2_name");
  261. QString numb = m_element.attribute("fb2_number");
  262. if (numb.isEmpty() || numb == "0") return text;
  263. return text + ", " + tr("#") + numb;
  264. } break;
  265. default: ;
  266. }
  267. if (m_list.count()) return QString();
  268. return m_element.toPlainText().simplified();
  269. }
  270. QString FbHeadItem::sub(const QString &key) const
  271. {
  272. foreach (FbHeadItem * item, m_list) {
  273. if (item->m_name == key) return item->value();
  274. }
  275. return QString();
  276. }
  277. FbScheme FbHeadItem::scheme() const
  278. {
  279. FbScheme parent = m_parent ? m_parent->scheme() : FbScheme();
  280. return parent.element(m_name);
  281. }
  282. void FbHeadItem::remove(int row)
  283. {
  284. if (row < 0 || row >= count()) return;
  285. m_list[row]->m_element.removeFromDocument();
  286. m_list.removeAt(row);
  287. }
  288. //---------------------------------------------------------------------------
  289. // FbHeadModel
  290. //---------------------------------------------------------------------------
  291. FbHeadModel::FbHeadModel(QWebView &view, QObject *parent)
  292. : QAbstractItemModel(parent)
  293. , m_view(view)
  294. , m_root(NULL)
  295. {
  296. QWebElement doc = view.page()->mainFrame()->documentElement();
  297. QWebElement head = doc.findFirst("div.description");
  298. if (head.isNull()) return;
  299. m_root = new FbHeadItem(head);
  300. }
  301. FbHeadModel::~FbHeadModel()
  302. {
  303. if (m_root) delete m_root;
  304. }
  305. void FbHeadModel::expand(QTreeView *view)
  306. {
  307. QModelIndex parent = QModelIndex();
  308. int count = rowCount(parent);
  309. for (int i = 0; i < count; i++) {
  310. QModelIndex child = index(i, 0, parent);
  311. FbHeadItem *node = item(child);
  312. if (!node) continue;
  313. view->expand(child);
  314. int count = rowCount(child);
  315. for (int j = 0; j < count; j++) {
  316. QModelIndex ch = index(j, 0, child);
  317. FbHeadItem *node = item(ch);
  318. if (node) view->expand(ch);
  319. }
  320. }
  321. }
  322. FbHeadItem * FbHeadModel::item(const QModelIndex &index) const
  323. {
  324. if (index.isValid()) {
  325. return static_cast<FbHeadItem*>(index.internalPointer());
  326. } else {
  327. return 0;
  328. }
  329. }
  330. int FbHeadModel::columnCount(const QModelIndex &parent) const
  331. {
  332. Q_UNUSED(parent);
  333. return 6;
  334. }
  335. QModelIndex FbHeadModel::index(int row, int column, const QModelIndex &parent) const
  336. {
  337. if (!m_root || row < 0 || column < 0) return QModelIndex();
  338. if (!parent.isValid() && m_root) {
  339. return createIndex(row, column, (void*)m_root);
  340. }
  341. if (FbHeadItem *owner = item(parent)) {
  342. if (FbHeadItem *child = owner->item(row)) {
  343. return createIndex(row, column, (void*)child);
  344. }
  345. }
  346. return QModelIndex();
  347. }
  348. QModelIndex FbHeadModel::parent(const QModelIndex &child) const
  349. {
  350. if (FbHeadItem * node = static_cast<FbHeadItem*>(child.internalPointer())) {
  351. if (FbHeadItem * parent = node->parent()) {
  352. if (FbHeadItem * owner = parent->parent()) {
  353. return createIndex(owner->index(parent), 0, (void*)parent);
  354. } else {
  355. return createIndex(0, 0, (void*)parent);
  356. }
  357. }
  358. }
  359. return QModelIndex();
  360. }
  361. int FbHeadModel::rowCount(const QModelIndex &parent) const
  362. {
  363. if (parent.column() > 0) return 0;
  364. if (!parent.isValid()) return m_root ? 1 : 0;
  365. FbHeadItem *owner = item(parent);
  366. return owner ? owner->count() : 0;
  367. }
  368. QVariant FbHeadModel::data(const QModelIndex &index, int role) const
  369. {
  370. if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
  371. FbHeadItem * i = item(index);
  372. return i ? i->text(index.column()) : QVariant();
  373. }
  374. QVariant FbHeadModel::headerData(int section, Qt::Orientation orientation, int role) const
  375. {
  376. if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
  377. switch (section) {
  378. case 0: return tr("Key");
  379. case 1: return tr("Value");
  380. }
  381. }
  382. return QVariant();
  383. }
  384. void FbHeadItem::setText(const QString &text)
  385. {
  386. m_text = text;
  387. }
  388. bool FbHeadModel::setData(const QModelIndex &index, const QVariant &value, int role)
  389. {
  390. if (role != Qt::EditRole) return false;
  391. FbHeadItem * i = item(index);
  392. if (!i) return false;
  393. i->setText(value.toString());
  394. emit dataChanged(index, index);
  395. return true;
  396. }
  397. Qt::ItemFlags FbHeadModel::flags(const QModelIndex &index) const
  398. {
  399. if (!index.isValid()) return 0;
  400. Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
  401. if (index.column() == 1) flags |= Qt::ItemIsEditable;
  402. return flags;
  403. }
  404. //---------------------------------------------------------------------------
  405. // FbTreeView
  406. //---------------------------------------------------------------------------
  407. FbHeadView::FbHeadView(FbTextEdit *view, QWidget *parent)
  408. : QTreeView(parent)
  409. , m_view(*view)
  410. {
  411. QAction * act;
  412. setContextMenuPolicy(Qt::ActionsContextMenu);
  413. actionInsert = act = new QAction(FbIcon("list-add"), tr("&Append"), this);
  414. act->setShortcutContext(Qt::WidgetShortcut);
  415. act->setShortcut(Qt::Key_Insert);
  416. act->setPriority(QAction::LowPriority);
  417. connect(act, SIGNAL(triggered()), SLOT(appendNode()));
  418. addAction(act);
  419. actionModify = act = new QAction(FbIcon("list-add"), tr("&Modify"), this);
  420. act->setPriority(QAction::LowPriority);
  421. actionDelete = act = new QAction(FbIcon("list-remove"), tr("&Delete"), this);
  422. act->setShortcutContext(Qt::WidgetShortcut);
  423. act->setShortcut(Qt::Key_Delete);
  424. act->setPriority(QAction::LowPriority);
  425. connect(act, SIGNAL(triggered()), SLOT(removeNode()));
  426. addAction(act);
  427. //setItemDelegate(new QItemDelegate(this));
  428. setRootIsDecorated(false);
  429. setSelectionBehavior(QAbstractItemView::SelectRows);
  430. setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
  431. connect(&m_view, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
  432. connect(this, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex)));
  433. connect(this, SIGNAL(collapsed(QModelIndex)), SLOT(collapsed(QModelIndex)));
  434. header()->setDefaultSectionSize(200);
  435. connect(actionModify, SIGNAL(triggered()), SLOT(editCurrent()));
  436. }
  437. void FbHeadView::initToolbar(QToolBar &toolbar)
  438. {
  439. toolbar.addSeparator();
  440. toolbar.addAction(actionInsert);
  441. toolbar.addAction(actionDelete);
  442. }
  443. void FbHeadView::updateTree()
  444. {
  445. FbHeadModel * model = new FbHeadModel(m_view, this);
  446. setModel(model);
  447. model->expand(this);
  448. }
  449. void FbHeadView::editCurrent()
  450. {
  451. if (!model()) return;
  452. QModelIndex current = currentIndex();
  453. if (!current.isValid()) return;
  454. QModelIndex parent = model()->parent(current);
  455. QModelIndex index = model()->index(current.row(), 1, parent);
  456. setCurrentIndex(index);
  457. edit(index);
  458. }
  459. void FbHeadView::activated(const QModelIndex &index)
  460. {
  461. if (index.isValid() && index.column() == 1) edit(index);
  462. showStatus(index);
  463. }
  464. void FbHeadView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
  465. {
  466. QTreeView::currentChanged(current, previous);
  467. showStatus(current);
  468. }
  469. void FbHeadView::showStatus(const QModelIndex &current)
  470. {
  471. if (!model()) return;
  472. if (!current.isValid()) return;
  473. QModelIndex parent = model()->parent(current);
  474. QModelIndex index = model()->index(current.row(), 2, parent);
  475. emit status(model()->data(index).toString());
  476. }
  477. void FbHeadView::collapsed(const QModelIndex &index)
  478. {
  479. if (model() && !model()->parent(index).isValid()) {
  480. expand(index);
  481. }
  482. }
  483. void FbHeadView::appendNode()
  484. {
  485. FbHeadModel * m = qobject_cast<FbHeadModel*>(model());
  486. if (!m) return;
  487. QModelIndex current = currentIndex();
  488. FbHeadItem * item = m->item(current);
  489. if (!item) return;
  490. QString name = item->name().toLower();
  491. if (name == "annotation" || name == "history") {
  492. current = m->parent(current);
  493. item = m->item(current);
  494. }
  495. QStringList list;
  496. item->scheme().items(list);
  497. if (list.count() == 0) {
  498. current = m->parent(current);
  499. item = m->item(current);
  500. if (!item) return;
  501. item->scheme().items(list);
  502. }
  503. FbNodeDlg dlg(this, item->scheme(), list);
  504. if (dlg.exec()) {
  505. current = m->append(current, dlg.value());
  506. if (current.isValid()) setCurrentIndex(current);
  507. }
  508. }
  509. void FbHeadView::removeNode()
  510. {
  511. FbHeadModel * m = qobject_cast<FbHeadModel*>(model());
  512. if (m) m->remove(currentIndex());
  513. }
  514. QModelIndex FbHeadModel::append(const QModelIndex &parent, const QString &name)
  515. {
  516. FbHeadItem * owner = item(parent);
  517. if (!owner) return QModelIndex();
  518. int row = owner->count();
  519. beginInsertRows(parent, row, row);
  520. FbHeadItem * item = owner->append(name);
  521. endInsertRows();
  522. return createIndex(row, 0, (void*)item);
  523. }
  524. void FbHeadModel::remove(const QModelIndex &index)
  525. {
  526. int r = index.row();
  527. QModelIndex p = parent(index);
  528. beginRemoveRows(p, r, r + 1);
  529. FbHeadItem * i = item(p);
  530. if (i) i->remove(r);
  531. endRemoveRows();
  532. }
  533. //---------------------------------------------------------------------------
  534. // FbNodeDlg
  535. //---------------------------------------------------------------------------
  536. FbNodeDlg::FbNodeDlg(QWidget *parent, FbScheme scheme, QStringList &list)
  537. : QDialog(parent)
  538. , m_scheme(scheme)
  539. {
  540. setWindowTitle(tr("Insert tag"));
  541. QGridLayout * layout = new QGridLayout(this);
  542. QLabel * label = new QLabel(this);
  543. label->setObjectName(QString::fromUtf8("label"));
  544. label->setText(tr("Tag name:"));
  545. layout->addWidget(label, 0, 0, 1, 1);
  546. m_combo = new QComboBox(this);
  547. m_combo->setEditable(true);
  548. m_combo->addItems(list);
  549. layout->addWidget(m_combo, 0, 1, 1, 1);
  550. m_text = new QLabel(this);
  551. m_text->setStyleSheet(QString::fromUtf8("border-style:outset;border-width:1px;border-radius:10px;padding:6px;"));
  552. m_text->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop);
  553. m_text->setMinimumSize(QSize(300, 100));
  554. m_text->setWordWrap(true);
  555. layout->addWidget(m_text, 1, 0, 1, 2);
  556. QDialogButtonBox * buttons = new QDialogButtonBox(this);
  557. buttons->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
  558. buttons->setOrientation(Qt::Horizontal);
  559. layout->addWidget(buttons, 2, 0, 1, 2);
  560. layout->setColumnStretch(1, 1);
  561. connect(m_combo, SIGNAL(editTextChanged(QString)), SLOT(comboChanged(QString)));
  562. connect(buttons, SIGNAL(accepted()), SLOT(accept()));
  563. connect(buttons, SIGNAL(rejected()), SLOT(reject()));
  564. if (list.count()) {
  565. m_combo->setCurrentIndex(0);
  566. comboChanged(list.first());
  567. }
  568. }
  569. void FbNodeDlg::comboChanged(const QString &text)
  570. {
  571. m_text->setText(m_scheme.element(text).info());
  572. }
  573. QString FbNodeDlg::value() const
  574. {
  575. return m_combo->currentText();
  576. }
  577. //---------------------------------------------------------------------------
  578. // FbAuthorDlg
  579. //---------------------------------------------------------------------------
  580. FbAuthorDlg::FbAuthorDlg(QWidget *parent)
  581. : QDialog(parent)
  582. {
  583. setWindowTitle(tr("Author"));
  584. QFormLayout * layout = new QFormLayout(this);
  585. add(layout, "last-name", tr("Last name"));
  586. add(layout, "first-name", tr("First name"));
  587. add(layout, "moddle-name", tr("Middle name"));
  588. add(layout, "nickname", tr("Nic name"));
  589. add(layout, "home-page", tr("Home page"));
  590. add(layout, "email", tr("E-mail"));
  591. QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
  592. buttonBox->setOrientation(Qt::Horizontal);
  593. buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
  594. layout->addRow(buttonBox);
  595. QObject::connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
  596. QObject::connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
  597. }
  598. void FbAuthorDlg::add(QFormLayout *layout, const QString &key, const QString &text)
  599. {
  600. QLabel * label = new QLabel(this);
  601. label->setText(text);
  602. QLineEdit * field = new QLineEdit(this);
  603. field->setMinimumWidth(200);
  604. m_fields[key] = field;
  605. layout->addRow(label, field);
  606. }