fb2head.cpp 21 KB

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