fb2main.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. #include <QtGui>
  2. #include <QtDebug>
  3. #include <QTreeView>
  4. #include <QWebInspector>
  5. #include <QWebFrame>
  6. #include "fb2main.h"
  7. #include "fb2read.h"
  8. #include "fb2tree.h"
  9. #include "fb2view.h"
  10. #include "fb2head.h"
  11. #include <Qsci/qsciscintilla.h>
  12. #include <Qsci/qscilexerxml.h>
  13. #define FB2DELETE(p) { if ( (p) != NULL ) { delete p; p = NULL; } }
  14. Fb2MainWindow::Fb2MainWindow()
  15. {
  16. init();
  17. setCurrentFile();
  18. textEdit = new Fb2WebView(this);
  19. viewText();
  20. textEdit->setHtml("<body/>");
  21. }
  22. Fb2MainWindow::Fb2MainWindow(const QString &filename, ViewMode mode)
  23. {
  24. init();
  25. setCurrentFile(filename);
  26. if (mode == FB2) {
  27. viewText();
  28. textEdit->load(filename);
  29. } else {
  30. createQsci();
  31. loadXML(filename);
  32. }
  33. }
  34. void Fb2MainWindow::init()
  35. {
  36. connect(qApp, SIGNAL(logMessage(QString)), SLOT(logMessage(QString)));
  37. setAttribute(Qt::WA_DeleteOnClose);
  38. isUntitled = true;
  39. createActions();
  40. createStatusBar();
  41. textEdit = NULL;
  42. noteEdit = NULL;
  43. qsciEdit = NULL;
  44. treeView = NULL;
  45. headTree = NULL;
  46. toolEdit = NULL;
  47. messageEdit = NULL;
  48. readSettings();
  49. setUnifiedTitleAndToolBarOnMac(true);
  50. }
  51. void Fb2MainWindow::logMessage(const QString &message)
  52. {
  53. if (!messageEdit) {
  54. messageEdit = new QTextEdit(this);
  55. connect(messageEdit, SIGNAL(destroyed()), SLOT(logDestroyed()));
  56. QDockWidget * dock = new QDockWidget(tr("Message log"), this);
  57. dock->setAttribute(Qt::WA_DeleteOnClose);
  58. dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
  59. dock->setWidget(messageEdit);
  60. addDockWidget(Qt::BottomDockWidgetArea, dock);
  61. messageEdit->setMaximumHeight(80);
  62. }
  63. messageEdit->append(message);
  64. }
  65. void Fb2MainWindow::logShowed()
  66. {
  67. messageEdit->setMaximumHeight(QWIDGETSIZE_MAX);
  68. }
  69. void Fb2MainWindow::logDestroyed()
  70. {
  71. messageEdit = NULL;
  72. }
  73. void Fb2MainWindow::treeActivated(const QModelIndex &index)
  74. {
  75. if (!treeView) return;
  76. Fb2TreeModel *model = dynamic_cast<Fb2TreeModel*>(treeView->model());
  77. if (model) model->select(index);
  78. }
  79. void Fb2MainWindow::treeDestroyed()
  80. {
  81. treeView = NULL;
  82. dockTree = NULL;
  83. }
  84. bool Fb2MainWindow::loadXML(const QString &filename)
  85. {
  86. if (!filename.isEmpty()) {
  87. QFile file(filename);
  88. if (file.open(QFile::ReadOnly | QFile::Text)) {
  89. qsciEdit->clear();
  90. return qsciEdit->read(&file);
  91. }
  92. }
  93. return false;
  94. }
  95. void Fb2MainWindow::closeEvent(QCloseEvent *event)
  96. {
  97. if (maybeSave()) {
  98. writeSettings();
  99. event->accept();
  100. } else {
  101. event->ignore();
  102. }
  103. }
  104. void Fb2MainWindow::fileNew()
  105. {
  106. Fb2MainWindow *other = new Fb2MainWindow;
  107. other->move(x() + 40, y() + 40);
  108. other->show();
  109. }
  110. void Fb2MainWindow::fileOpen()
  111. {
  112. QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), QString(), "Fiction book files (*.fb2)");
  113. if (filename.isEmpty()) return;
  114. Fb2MainWindow * existing = findFb2MainWindow(filename);
  115. if (existing) {
  116. existing->show();
  117. existing->raise();
  118. existing->activateWindow();
  119. return;
  120. }
  121. if (textEdit) {
  122. if (isUntitled && !isWindowModified()) {
  123. setCurrentFile(filename);
  124. textEdit->load(filename);
  125. } else {
  126. Fb2MainWindow * other = new Fb2MainWindow(filename, FB2);
  127. other->move(x() + 40, y() + 40);
  128. other->show();
  129. }
  130. } else if (qsciEdit) {
  131. if (isUntitled && !isWindowModified()) {
  132. setCurrentFile(filename);
  133. loadXML(filename);
  134. } else {
  135. Fb2MainWindow * other = new Fb2MainWindow(filename, XML);
  136. other->move(x() + 40, y() + 40);
  137. other->show();
  138. }
  139. }
  140. }
  141. bool Fb2MainWindow::fileSave()
  142. {
  143. if (isUntitled) {
  144. return fileSaveAs();
  145. } else {
  146. return saveFile(curFile);
  147. }
  148. }
  149. bool Fb2MainWindow::fileSaveAs()
  150. {
  151. QString fileName = QFileDialog::getSaveFileName(this, tr("Save As..."), curFile);
  152. if (fileName.isEmpty()) return false;
  153. return saveFile(fileName);
  154. }
  155. void Fb2MainWindow::about()
  156. {
  157. QMessageBox::about(this, tr("About fb2edit"),
  158. tr("The <b>fb2edit</b> is application for editing FB2-files."));
  159. }
  160. void Fb2MainWindow::documentWasModified()
  161. {
  162. if (isWindowModified()) return;
  163. QFileInfo info = windowFilePath();
  164. QString title = info.fileName();
  165. if (textEdit && textEdit->isModified()) title += QString("[*]");
  166. title += QString(" - ") += qApp->applicationName();
  167. setWindowTitle(title);
  168. setWindowModified(true);
  169. }
  170. QIcon Fb2MainWindow::icon(const QString &name)
  171. {
  172. QIcon icon;
  173. icon.addFile(QString(":/24/%1.png").arg(name), QSize(24,24));
  174. icon.addFile(QString(":/16/%1.png").arg(name), QSize(16,16));
  175. return QIcon::fromTheme(name, icon);
  176. }
  177. void Fb2MainWindow::createActions()
  178. {
  179. QAction * act;
  180. QMenu * menu;
  181. QToolBar * tool;
  182. QList<QAction*> actions;
  183. menu = menuBar()->addMenu(tr("&File"));
  184. tool = addToolBar(tr("File"));
  185. tool->setMovable(false);
  186. act = new QAction(icon("document-new"), tr("&New"), this);
  187. act->setPriority(QAction::LowPriority);
  188. act->setShortcuts(QKeySequence::New);
  189. act->setStatusTip(tr("Create a new file"));
  190. connect(act, SIGNAL(triggered()), this, SLOT(fileNew()));
  191. menu->addAction(act);
  192. tool->addAction(act);
  193. act = new QAction(icon("document-open"), tr("&Open..."), this);
  194. act->setShortcuts(QKeySequence::Open);
  195. act->setStatusTip(tr("Open an existing file"));
  196. connect(act, SIGNAL(triggered()), this, SLOT(fileOpen()));
  197. menu->addAction(act);
  198. tool->addAction(act);
  199. act = new QAction(icon("document-save"), tr("&Save"), this);
  200. act->setShortcuts(QKeySequence::Save);
  201. act->setStatusTip(tr("Save the document to disk"));
  202. connect(act, SIGNAL(triggered()), this, SLOT(fileSave()));
  203. menu->addAction(act);
  204. tool->addAction(act);
  205. act = new QAction(icon("document-save-as"), tr("Save &As..."), this);
  206. act->setShortcuts(QKeySequence::SaveAs);
  207. act->setStatusTip(tr("Save the document under a new name"));
  208. connect(act, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
  209. menu->addAction(act);
  210. menu->addSeparator();
  211. act = new QAction(icon("window-close"), tr("&Close"), this);
  212. act->setShortcuts(QKeySequence::Close);
  213. act->setStatusTip(tr("Close this window"));
  214. connect(act, SIGNAL(triggered()), this, SLOT(close()));
  215. menu->addAction(act);
  216. act = new QAction(icon("application-exit"), tr("E&xit"), this);
  217. act->setShortcuts(QKeySequence::Quit);
  218. act->setStatusTip(tr("Exit the application"));
  219. connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
  220. menu->addAction(act);
  221. menuEdit = menu = menuBar()->addMenu(tr("&Edit"));
  222. menuText = menu = menuBar()->addMenu(tr("Fo&rmat"));
  223. menuView = menu = menuBar()->addMenu(tr("&View"));
  224. tool->addSeparator();
  225. QActionGroup * viewGroup = new QActionGroup(this);
  226. act = new QAction(tr("&Text"), this);
  227. act->setCheckable(true);
  228. act->setChecked(true);
  229. connect(act, SIGNAL(triggered()), this, SLOT(viewText()));
  230. viewGroup->addAction(act);
  231. menu->addAction(act);
  232. tool->addAction(act);
  233. act = new QAction(tr("&Head"), this);
  234. act->setCheckable(true);
  235. connect(act, SIGNAL(triggered()), this, SLOT(viewHead()));
  236. viewGroup->addAction(act);
  237. menu->addAction(act);
  238. tool->addAction(act);
  239. act = new QAction(tr("&XML"), this);
  240. act->setCheckable(true);
  241. connect(act, SIGNAL(triggered()), this, SLOT(viewQsci()));
  242. viewGroup->addAction(act);
  243. menu->addAction(act);
  244. tool->addAction(act);
  245. menu->addSeparator();
  246. actionZoomIn = act = new QAction(icon("zoom-in"), tr("Zoom in"), this);
  247. act->setShortcuts(QKeySequence::ZoomIn);
  248. menu->addAction(act);
  249. actionZoomOut = act = new QAction(icon("zoom-out"), tr("Zoom out"), this);
  250. act->setShortcuts(QKeySequence::ZoomOut);
  251. menu->addAction(act);
  252. actionZoomOrig = act = new QAction(icon("zoom-original"), tr("Zoom original"), this);
  253. menu->addAction(act);
  254. menu->addSeparator();
  255. act = new QAction(tr("&Contents"), this);
  256. connect(act, SIGNAL(triggered()), this, SLOT(viewTree()));
  257. menu->addAction(act);
  258. act = new QAction(tr("&Web inspector"), this);
  259. connect(act, SIGNAL(triggered()), this, SLOT(showInspector()));
  260. menu->addAction(act);
  261. menuBar()->addSeparator();
  262. menu = menuBar()->addMenu(tr("&Help"));
  263. act = new QAction(icon("help-about"), tr("&About"), this);
  264. act->setStatusTip(tr("Show the application's About box"));
  265. connect(act, SIGNAL(triggered()), this, SLOT(about()));
  266. menu->addAction(act);
  267. act = new QAction(tr("About &Qt"), this);
  268. act->setStatusTip(tr("Show the Qt library's About box"));
  269. connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
  270. menu->addAction(act);
  271. }
  272. void Fb2MainWindow::createTree()
  273. {
  274. if (treeView) return;
  275. treeView = new QTreeView(this);
  276. treeView->setHeaderHidden(true);
  277. connect(treeView, SIGNAL(activated(QModelIndex)), SLOT(treeActivated(QModelIndex)));
  278. connect(treeView, SIGNAL(destroyed()), SLOT(treeDestroyed()));
  279. dockTree = new QDockWidget(tr("Contents"), this);
  280. dockTree->setAttribute(Qt::WA_DeleteOnClose);
  281. dockTree->setFeatures(QDockWidget::AllDockWidgetFeatures);
  282. dockTree->setWidget(treeView);
  283. addDockWidget(Qt::LeftDockWidgetArea, dockTree);
  284. treeView->setFocus();
  285. }
  286. void Fb2MainWindow::createHead()
  287. {
  288. if (headTree) return;
  289. headTree = new QTreeView(this);
  290. if (textEdit) {
  291. this->setFocus();
  292. textEdit->setParent(NULL);
  293. setCentralWidget(headTree);
  294. textEdit->setParent(this);
  295. Fb2HeadModel *model = new Fb2HeadModel(*textEdit, treeView);
  296. headTree->setModel(model);
  297. model->expand(headTree);
  298. } else {
  299. setCentralWidget(headTree);
  300. }
  301. headTree->setFocus();
  302. }
  303. void Fb2MainWindow::loadFinished(bool ok)
  304. {
  305. if (!treeView) return ;
  306. Fb2TreeModel *model = new Fb2TreeModel(*textEdit, treeView);
  307. treeView->setModel(model);
  308. model->expand(treeView);
  309. }
  310. void Fb2MainWindow::selectionChanged()
  311. {
  312. // QString script = "document.getSelection().baseNode.parentNode.tagName";
  313. // qCritical() << textEdit->page()->mainFrame()->evaluateJavaScript(script).toString();
  314. }
  315. void Fb2MainWindow::undoChanged()
  316. {
  317. actionUndo->setEnabled(textEdit->UndoEnabled());
  318. }
  319. void Fb2MainWindow::redoChanged()
  320. {
  321. actionRedo->setEnabled(textEdit->RedoEnabled());
  322. }
  323. void Fb2MainWindow::createQsci()
  324. {
  325. // http://qtcoder.blogspot.com/2010/10/qscintills.html
  326. // http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciScintilla.html
  327. if (qsciEdit) return;
  328. qsciEdit = new QsciScintilla;
  329. qsciEdit->setUtf8(true);
  330. qsciEdit->setCaretLineVisible(true);
  331. qsciEdit->setCaretLineBackgroundColor(QColor("gainsboro"));
  332. qsciEdit->setWrapMode(QsciScintilla::WrapWord);
  333. qsciEdit->setEolMode(QsciScintilla::EolWindows);
  334. qsciEdit->setAutoIndent(true);
  335. qsciEdit->setIndentationGuides(true);
  336. qsciEdit->setAutoCompletionSource(QsciScintilla::AcsAll);
  337. qsciEdit->setAutoCompletionCaseSensitivity(true);
  338. qsciEdit->setAutoCompletionReplaceWord(true);
  339. qsciEdit->setAutoCompletionShowSingle(true);
  340. qsciEdit->setAutoCompletionThreshold(2);
  341. qsciEdit->setMarginsBackgroundColor(QColor("gainsboro"));
  342. qsciEdit->setMarginWidth(0, 0);
  343. qsciEdit->setMarginLineNumbers(1, true);
  344. qsciEdit->setMarginWidth(1, QString("10000"));
  345. qsciEdit->setFolding(QsciScintilla::BoxedFoldStyle, 2);
  346. qsciEdit->setBraceMatching(QsciScintilla::SloppyBraceMatch);
  347. qsciEdit->setMatchedBraceBackgroundColor(Qt::yellow);
  348. qsciEdit->setUnmatchedBraceForegroundColor(Qt::blue);
  349. QFont font("Courier", 10);
  350. font.setStyleHint(QFont::TypeWriter);
  351. QsciLexerXML * lexer = new QsciLexerXML;
  352. lexer->setFont(font, -1);
  353. qsciEdit->setBraceMatching(QsciScintilla::SloppyBraceMatch);
  354. qsciEdit->setLexer(lexer);
  355. setCentralWidget(qsciEdit);
  356. qsciEdit->setFocus();
  357. // connect(qsciEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
  358. }
  359. void Fb2MainWindow::createStatusBar()
  360. {
  361. statusBar()->showMessage(tr("Ready"));
  362. }
  363. void Fb2MainWindow::readSettings()
  364. {
  365. QSettings settings;
  366. QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
  367. QSize size = settings.value("size", QSize(400, 400)).toSize();
  368. move(pos);
  369. resize(size);
  370. }
  371. void Fb2MainWindow::writeSettings()
  372. {
  373. QSettings settings;
  374. settings.setValue("pos", pos());
  375. settings.setValue("size", size());
  376. }
  377. bool Fb2MainWindow::maybeSave()
  378. {
  379. if (textEdit && textEdit->isModified()) {
  380. QMessageBox::StandardButton ret;
  381. ret = QMessageBox::warning(this, qApp->applicationName(),
  382. tr("The document has been modified. Do you want to save your changes?"),
  383. QMessageBox::Save | QMessageBox::Discard
  384. | QMessageBox::Cancel);
  385. if (ret == QMessageBox::Save)
  386. return fileSave();
  387. else if (ret == QMessageBox::Cancel)
  388. return false;
  389. }
  390. return true;
  391. }
  392. bool Fb2MainWindow::saveFile(const QString &fileName)
  393. {
  394. QFile file(fileName);
  395. if (!file.open(QFile::WriteOnly | QFile::Text)) {
  396. QMessageBox::warning(this, qApp->applicationName(), tr("Cannot write file %1: %2.").arg(fileName).arg(file.errorString()));
  397. return false;
  398. }
  399. if (textEdit) return textEdit->save(&file);
  400. return true;
  401. /*
  402. QTextStream out(&file);
  403. QApplication::setOverrideCursor(Qt::WaitCursor);
  404. out << textEdit->toPlainText();
  405. QApplication::restoreOverrideCursor();
  406. setCurrentFile(fileName);
  407. statusBar()->showMessage(tr("File saved"), 2000);
  408. */
  409. }
  410. void Fb2MainWindow::setCurrentFile(const QString &filename)
  411. {
  412. static int sequenceNumber = 1;
  413. QString title;
  414. isUntitled = filename.isEmpty();
  415. if (isUntitled) {
  416. curFile = QString("book%1.fb2").arg(sequenceNumber++);
  417. title = curFile;
  418. } else {
  419. QFileInfo info = filename;
  420. curFile = info.canonicalFilePath();
  421. title = info.fileName();
  422. }
  423. title += QString(" - ") += qApp->applicationName();
  424. setWindowModified(false);
  425. setWindowFilePath(curFile);
  426. setWindowTitle(title);
  427. }
  428. Fb2MainWindow *Fb2MainWindow::findFb2MainWindow(const QString &fileName)
  429. {
  430. QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
  431. foreach (QWidget *widget, qApp->topLevelWidgets()) {
  432. Fb2MainWindow *mainWin = qobject_cast<Fb2MainWindow *>(widget);
  433. if (mainWin && mainWin->curFile == canonicalFilePath)
  434. return mainWin;
  435. }
  436. return 0;
  437. }
  438. void Fb2MainWindow::viewQsci()
  439. {
  440. if (centralWidget() == qsciEdit) return;
  441. QString xml;
  442. if (textEdit) textEdit->save(&xml);
  443. FB2DELETE(textEdit);
  444. FB2DELETE(dockTree);
  445. FB2DELETE(headTree);
  446. FB2DELETE(toolEdit);
  447. menuEdit->clear();
  448. menuText->clear();
  449. createQsci();
  450. qsciEdit->setText(xml);
  451. }
  452. void Fb2MainWindow::viewText()
  453. {
  454. if (centralWidget() == textEdit) return;
  455. FB2DELETE(qsciEdit);
  456. FB2DELETE(headTree);
  457. if (!textEdit) {
  458. textEdit = new Fb2WebView(this);
  459. }
  460. setCentralWidget(textEdit);
  461. textEdit->setFocus();
  462. viewTree();
  463. // connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
  464. connect(textEdit->page(), SIGNAL(contentsChanged()), SLOT(documentWasModified()));
  465. connect(textEdit, SIGNAL(selectionChanged()), SLOT(selectionChanged()));
  466. connect(textEdit, SIGNAL(loadFinished(bool)), SLOT(loadFinished(bool)));
  467. connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
  468. connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
  469. connect(actionZoomOrig, SIGNAL(triggered()), textEdit, SLOT(zoomOrig()));
  470. menuEdit->clear();
  471. menuText->clear();
  472. FB2DELETE(toolEdit);
  473. QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
  474. tool->setMovable(false);
  475. tool->addSeparator();
  476. QAction *act;
  477. QMenu *menu;
  478. menu = menuEdit;
  479. act = textEdit->pageAction(QWebPage::Undo);
  480. act->setIcon(icon("edit-undo"));
  481. act->setText(tr("&Undo"));
  482. act->setPriority(QAction::LowPriority);
  483. act->setShortcut(QKeySequence::Undo);
  484. menu->addAction(act);
  485. tool->addAction(act);
  486. act = textEdit->pageAction(QWebPage::Redo);
  487. act->setIcon(icon("edit-redo"));
  488. act->setText(tr("&Redo"));
  489. act->setPriority(QAction::LowPriority);
  490. act->setShortcut(QKeySequence::Redo);
  491. menu->addAction(act);
  492. tool->addAction(act);
  493. menu->addSeparator();
  494. tool->addSeparator();
  495. act = textEdit->pageAction(QWebPage::Cut);
  496. act->setIcon(icon("edit-cut"));
  497. act->setText(tr("Cu&t"));
  498. act->setPriority(QAction::LowPriority);
  499. act->setShortcuts(QKeySequence::Cut);
  500. act->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
  501. menu->addAction(act);
  502. tool->addAction(act);
  503. act = textEdit->pageAction(QWebPage::Copy);
  504. act->setIcon(icon("edit-copy"));
  505. act->setText(tr("&Copy"));
  506. act->setPriority(QAction::LowPriority);
  507. act->setShortcuts(QKeySequence::Copy);
  508. act->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
  509. menu->addAction(act);
  510. tool->addAction(act);
  511. act = textEdit->pageAction(QWebPage::Paste);
  512. act->setIcon(icon("edit-paste"));
  513. act->setText(tr("&Paste"));
  514. act->setPriority(QAction::LowPriority);
  515. act->setShortcuts(QKeySequence::Paste);
  516. act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
  517. menu->addAction(act);
  518. tool->addAction(act);
  519. tool->addSeparator();
  520. menu = menuText;
  521. act = textEdit->pageAction(QWebPage::ToggleBold);
  522. act->setIcon(icon("format-text-bold"));
  523. act->setText(tr("&Bold"));
  524. act->setShortcuts(QKeySequence::Bold);
  525. menu->addAction(act);
  526. tool->addAction(act);
  527. act = textEdit->pageAction(QWebPage::ToggleItalic);
  528. act->setIcon(icon("format-text-italic"));
  529. act->setText(tr("&Italic"));
  530. act->setShortcuts(QKeySequence::Italic);
  531. menu->addAction(act);
  532. tool->addAction(act);
  533. act = textEdit->pageAction(QWebPage::ToggleStrikethrough);
  534. act->setIcon(icon("format-text-strikethrough"));
  535. act->setText(tr("&Strikethrough"));
  536. menu->addAction(act);
  537. tool->addAction(act);
  538. act = textEdit->pageAction(QWebPage::ToggleSuperscript);
  539. act->setIcon(icon("format-text-superscript"));
  540. act->setText(tr("Superscript"));
  541. menu->addAction(act);
  542. tool->addAction(act);
  543. act = textEdit->pageAction(QWebPage::ToggleSubscript);
  544. act->setIcon(icon("format-text-subscript"));
  545. act->setText(tr("Subscript"));
  546. menu->addAction(act);
  547. tool->addAction(act);
  548. tool->addSeparator();
  549. tool->addAction(actionZoomIn);
  550. tool->addAction(actionZoomOut);
  551. tool->addAction(actionZoomOrig);
  552. act = textEdit->pageAction(QWebPage::InspectElement);
  553. menuView->addAction(act);
  554. }
  555. void Fb2MainWindow::viewHead()
  556. {
  557. if (centralWidget() == headTree) return;
  558. FB2DELETE(dockTree);
  559. FB2DELETE(qsciEdit);
  560. FB2DELETE(toolEdit);
  561. menuEdit->clear();
  562. menuText->clear();
  563. createHead();
  564. FB2DELETE(toolEdit);
  565. QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
  566. tool->setMovable(false);
  567. tool->addSeparator();
  568. QAction *act;
  569. QMenu *menu = menuEdit;
  570. act = new QAction(icon("list-add"), tr("Insert"), this);
  571. act->setPriority(QAction::LowPriority);
  572. act->setShortcuts(QKeySequence::New);
  573. menu->addAction(act);
  574. tool->addAction(act);
  575. act = new QAction(icon("list-remove"), tr("Delete"), this);
  576. act->setPriority(QAction::LowPriority);
  577. act->setShortcuts(QKeySequence::Delete);
  578. menu->addAction(act);
  579. tool->addAction(act);
  580. }
  581. void Fb2MainWindow::viewTree()
  582. {
  583. if (centralWidget() != textEdit) return;
  584. if (treeView == NULL) createTree();
  585. loadFinished(true);
  586. }
  587. void Fb2MainWindow::clipboardDataChanged()
  588. {
  589. /*
  590. if (const QMimeData *md = QApplication::clipboard()->mimeData()) {
  591. actionPaste->setEnabled(md->hasText());
  592. }
  593. */
  594. }
  595. void Fb2MainWindow::showInspector()
  596. {
  597. if (!textEdit) return;
  598. QWebInspector * inspector = new QWebInspector();
  599. inspector->setPage(textEdit->page());
  600. inspector->show();
  601. }