1
0

fb2head.cpp 22 KB

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