fb2main.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. #include <QtGui>
  2. #include <QtDebug>
  3. #include <QTreeView>
  4. #include <QWebFrame>
  5. #include "fb2app.hpp"
  6. #include "fb2main.hpp"
  7. #include "fb2code.hpp"
  8. #include "fb2dlgs.hpp"
  9. #include "fb2dock.hpp"
  10. #include "fb2logs.hpp"
  11. #include "fb2save.hpp"
  12. #include "fb2text.hpp"
  13. #include "fb2utils.h"
  14. //---------------------------------------------------------------------------
  15. // FbMainWindow
  16. //---------------------------------------------------------------------------
  17. FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
  18. : QMainWindow()
  19. , noteEdit(0)
  20. , toolEdit(0)
  21. , inspector(0)
  22. , messageEdit(0)
  23. , isSwitched(false)
  24. , isUntitled(true)
  25. {
  26. connect(qApp, SIGNAL(logMessage(QString)), SLOT(logMessage(QString)));
  27. setUnifiedTitleAndToolBarOnMac(true);
  28. setAttribute(Qt::WA_DeleteOnClose);
  29. setWindowIcon(QIcon(":icon.ico"));
  30. mainDock = new FbMainDock(this);
  31. setCentralWidget(mainDock);
  32. createActions();
  33. createStatusBar();
  34. readSettings();
  35. QString filepath = filename.isEmpty() ? QString(":blank.fb2") : filename;
  36. mainDock->setMode(Fb::Text);
  37. setCurrentFile(filename);
  38. mainDock->load(filepath);
  39. }
  40. void FbMainWindow::warning(int row, int col, const QString &msg)
  41. {
  42. logMessage(msg.simplified());
  43. }
  44. void FbMainWindow::error(int row, int col, const QString &msg)
  45. {
  46. logMessage(msg.simplified());
  47. }
  48. void FbMainWindow::fatal(int row, int col, const QString &msg)
  49. {
  50. logMessage(msg.simplified());
  51. }
  52. void FbMainWindow::logMessage(const QString &message)
  53. {
  54. if (!messageEdit) {
  55. messageEdit = new QTextEdit(this);
  56. connect(messageEdit, SIGNAL(destroyed()), SLOT(logDestroyed()));
  57. QDockWidget * dock = new FbLogDock(tr("Message log"), this);
  58. dock->setAttribute(Qt::WA_DeleteOnClose);
  59. dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
  60. dock->setWidget(messageEdit);
  61. addDockWidget(Qt::BottomDockWidgetArea, dock);
  62. messageEdit->setMaximumHeight(80);
  63. }
  64. messageEdit->append(message);
  65. }
  66. void FbMainWindow::logShowed()
  67. {
  68. messageEdit->setMaximumHeight(QWIDGETSIZE_MAX);
  69. }
  70. void FbMainWindow::logDestroyed()
  71. {
  72. messageEdit = NULL;
  73. }
  74. void FbMainWindow::closeEvent(QCloseEvent *event)
  75. {
  76. if (maybeSave()) {
  77. writeSettings();
  78. event->accept();
  79. } else {
  80. event->ignore();
  81. }
  82. }
  83. void FbMainWindow::fileNew()
  84. {
  85. FbMainWindow *other = new FbMainWindow;
  86. other->move(x() + 40, y() + 40);
  87. other->show();
  88. }
  89. void FbMainWindow::fileOpen()
  90. {
  91. QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), QString(), "Fiction book files (*.fb2)");
  92. if (filename.isEmpty()) return;
  93. FbMainWindow * existing = findFbMainWindow(filename);
  94. if (existing) {
  95. existing->show();
  96. existing->raise();
  97. existing->activateWindow();
  98. return;
  99. }
  100. if (isUntitled && !isWindowModified()) {
  101. mainDock->load(filename);
  102. } else {
  103. FbMainWindow * other = new FbMainWindow(filename, FB2);
  104. other->mainDock->load(filename);
  105. other->move(x() + 40, y() + 40);
  106. other->show();
  107. }
  108. }
  109. bool FbMainWindow::fileSave()
  110. {
  111. if (isUntitled) {
  112. return fileSaveAs();
  113. } else {
  114. return saveFile(curFile);
  115. }
  116. }
  117. bool FbMainWindow::fileSaveAs()
  118. {
  119. FbSaveDialog dlg(this, tr("Save As..."));
  120. dlg.selectFile(curFile);
  121. if (!dlg.exec()) return false;
  122. QString fileName = dlg.fileName();
  123. if (fileName.isEmpty()) return false;
  124. return saveFile(fileName, dlg.codec());
  125. }
  126. void FbMainWindow::about()
  127. {
  128. QString text = tr("<b>fb2edit</b> is an application for creating and editing FB2-files.");
  129. text += QString("<br>") += QString("<br>") += FbApplication::lastCommit();
  130. QMessageBox::about(this, tr("About fb2edit"), text);
  131. }
  132. void FbMainWindow::documentWasModified()
  133. {
  134. // setModified(isSwitched || codeEdit->isModified());
  135. }
  136. void FbMainWindow::setModified(bool modified)
  137. {
  138. QFileInfo info = windowFilePath();
  139. QString title = info.fileName();
  140. if (modified) title += QString("[*]");
  141. title += appTitle();
  142. setWindowTitle(title);
  143. setWindowModified(modified);
  144. }
  145. void FbMainWindow::createActions()
  146. {
  147. QAction * act;
  148. QMenu * menu;
  149. QToolBar * tool;
  150. FbTextEdit *text = mainDock->text();
  151. FbHeadEdit *head = mainDock->head();
  152. FbCodeEdit *code = mainDock->code();
  153. menu = menuBar()->addMenu(tr("&File"));
  154. tool = addToolBar(tr("File"));
  155. tool->setMovable(false);
  156. act = new QAction(FbIcon("document-new"), tr("&New"), this);
  157. act->setPriority(QAction::LowPriority);
  158. act->setShortcuts(QKeySequence::New);
  159. act->setStatusTip(tr("Create a new file"));
  160. connect(act, SIGNAL(triggered()), this, SLOT(fileNew()));
  161. menu->addAction(act);
  162. tool->addAction(act);
  163. act = new QAction(FbIcon("document-open"), tr("&Open..."), this);
  164. act->setShortcuts(QKeySequence::Open);
  165. act->setStatusTip(tr("Open an existing file"));
  166. connect(act, SIGNAL(triggered()), this, SLOT(fileOpen()));
  167. menu->addAction(act);
  168. tool->addAction(act);
  169. act = new QAction(FbIcon("document-save"), tr("&Save"), this);
  170. act->setShortcuts(QKeySequence::Save);
  171. act->setStatusTip(tr("Save the document to disk"));
  172. connect(act, SIGNAL(triggered()), this, SLOT(fileSave()));
  173. menu->addAction(act);
  174. tool->addAction(act);
  175. act = new QAction(FbIcon("document-save-as"), tr("Save &As..."), this);
  176. act->setShortcuts(QKeySequence::SaveAs);
  177. act->setStatusTip(tr("Save the document under a new name"));
  178. connect(act, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
  179. menu->addAction(act);
  180. menu->addSeparator();
  181. act = new QAction(FbIcon("window-close"), tr("&Close"), this);
  182. act->setShortcuts(QKeySequence::Close);
  183. act->setStatusTip(tr("Close this window"));
  184. connect(act, SIGNAL(triggered()), this, SLOT(close()));
  185. menu->addAction(act);
  186. act = new QAction(FbIcon("application-exit"), tr("E&xit"), this);
  187. act->setShortcuts(QKeySequence::Quit);
  188. act->setStatusTip(tr("Exit the application"));
  189. connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
  190. menu->addAction(act);
  191. menu = menuBar()->addMenu(tr("&Edit"));
  192. act = new FbTextAction(FbIcon("edit-undo"), tr("&Undo"), QWebPage::Undo, text);
  193. text->setAction(Fb::EditUndo, act);
  194. code->setAction(Fb::EditUndo, act);
  195. act->setPriority(QAction::LowPriority);
  196. act->setShortcut(QKeySequence::Undo);
  197. act->setEnabled(false);
  198. menu->addAction(act);
  199. act = new FbTextAction(FbIcon("edit-redo"), tr("&Redo"), QWebPage::Redo, text);
  200. text->setAction(Fb::EditRedo, act);
  201. code->setAction(Fb::EditRedo, act);
  202. act->setPriority(QAction::LowPriority);
  203. act->setShortcut(QKeySequence::Redo);
  204. act->setEnabled(false);
  205. menu->addAction(act);
  206. menu->addSeparator();
  207. act = new FbTextAction(FbIcon("edit-cut"), tr("Cu&t"), QWebPage::Cut, text);
  208. text->setAction(Fb::EditCut, act);
  209. code->setAction(Fb::EditCut, act);
  210. act->setShortcutContext(Qt::WidgetShortcut);
  211. act->setPriority(QAction::LowPriority);
  212. act->setShortcuts(QKeySequence::Cut);
  213. act->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
  214. act->setEnabled(false);
  215. menu->addAction(act);
  216. act = new FbTextAction(FbIcon("edit-copy"), tr("&Copy"), QWebPage::Copy, text);
  217. text->setAction(Fb::EditCopy, act);
  218. code->setAction(Fb::EditCopy, act);
  219. act->setShortcutContext(Qt::WidgetShortcut);
  220. act->setPriority(QAction::LowPriority);
  221. act->setShortcuts(QKeySequence::Copy);
  222. act->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
  223. act->setEnabled(false);
  224. menu->addAction(act);
  225. act = new FbTextAction(FbIcon("edit-paste"), tr("&Paste"), QWebPage::Paste, text);
  226. text->setAction(Fb::EditPaste, act);
  227. code->setAction(Fb::EditPaste, act);
  228. act->setShortcutContext(Qt::WidgetShortcut);
  229. act->setPriority(QAction::LowPriority);
  230. act->setShortcuts(QKeySequence::Paste);
  231. act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
  232. menu->addAction(act);
  233. act = new FbTextAction(tr("Paste (no style)"), QWebPage::PasteAndMatchStyle, text);
  234. text->setAction(Fb::PasteText, act);
  235. menu->addAction(act);
  236. menu->addSeparator();
  237. act = new QAction(FbIcon("edit-find"), tr("&Find..."), this);
  238. text->setAction(Fb::EditFind, act);
  239. code->setAction(Fb::EditFind, act);
  240. act->setShortcuts(QKeySequence::Find);
  241. menu->addAction(act);
  242. act = new QAction(FbIcon("edit-find-replace"), tr("&Replace..."), this);
  243. text->setAction(Fb::EditReplace, act);
  244. code->setAction(Fb::EditReplace, act);
  245. menu->addAction(act);
  246. act = new QAction(FbIcon("tools-check-spelling"), tr("&Check..."), this);
  247. code->setAction(Fb::CheckText, act);
  248. menu->addAction(act);
  249. menu->addSeparator();
  250. act = new QAction(FbIcon("preferences-desktop"), tr("&Settings"), this);
  251. act->setShortcuts(QKeySequence::Preferences);
  252. act->setStatusTip(tr("Application settings"));
  253. connect(act, SIGNAL(triggered()), SLOT(openSettings()));
  254. menu->addAction(act);
  255. menu = menuBar()->addMenu(tr("&Insert", "Main menu"));
  256. mainDock->addMenu(menu);
  257. act = new QAction(FbIcon("insert-image"), tr("&Image"), this);
  258. text->setAction(Fb::InsertImage, act);
  259. menu->addAction(act);
  260. act = new QAction(FbIcon("insert-text"), tr("&Footnote"), this);
  261. text->setAction(Fb::InsertNote, act);
  262. menu->addAction(act);
  263. act = new QAction(FbIcon("insert-link"), tr("&Hiperlink"), this);
  264. text->setAction(Fb::InsertLink, act);
  265. menu->addAction(act);
  266. menu->addSeparator();
  267. act = new QAction(tr("&Body"), this);
  268. text->setAction(Fb::InsertBody, act);
  269. menu->addAction(act);
  270. act = new QAction(FbIcon("insert-object"), tr("&Section"), this);
  271. text->setAction(Fb::InsertSection, act);
  272. menu->addAction(act);
  273. act = new QAction(tr("&Title"), this);
  274. text->setAction(Fb::InsertTitle, act);
  275. menu->addAction(act);
  276. act = new QAction(tr("&Epigraph"), this);
  277. text->setAction(Fb::InsertEpigraph, act);
  278. menu->addAction(act);
  279. act = new QAction(tr("&Annotation"), this);
  280. text->setAction(Fb::InsertAnnot, act);
  281. menu->addAction(act);
  282. act = new QAction(tr("&Subtitle"), this);
  283. text->setAction(Fb::InsertSubtitle, act);
  284. menu->addAction(act);
  285. act = new QAction(tr("&Cite"), this);
  286. text->setAction(Fb::InsertCite, act);
  287. menu->addAction(act);
  288. act = new QAction(tr("&Poem"), this);
  289. text->setAction(Fb::InsertPoem, act);
  290. menu->addAction(act);
  291. act = new QAction(tr("&Stanza"), this);
  292. text->setAction(Fb::InsertStanza, act);
  293. menu->addAction(act);
  294. act = new QAction(tr("&Author"), this);
  295. text->setAction(Fb::InsertAuthor, act);
  296. menu->addAction(act);
  297. act = new QAction(tr("&Date"), this);
  298. text->setAction(Fb::InsertDate, act);
  299. menu->addAction(act);
  300. menu->addSeparator();
  301. act = new QAction(tr("Simple text"), this);
  302. text->setAction(Fb::InsertText, act);
  303. menu->addAction(act);
  304. act = new FbTextAction(tr("Paragraph"), QWebPage::InsertParagraphSeparator, text);
  305. text->setAction(Fb::InsertParag, act);
  306. menu->addAction(act);
  307. menu = menuBar()->addMenu(tr("Fo&rmat"));
  308. mainDock->addMenu(menu);
  309. act = new FbTextAction(FbIcon("edit-clear"), tr("Clear format"), QWebPage::RemoveFormat, text);
  310. text->setAction(Fb::ClearFormat, act);
  311. menu->addAction(act);
  312. menu->addSeparator();
  313. act = new FbTextAction(FbIcon("format-text-bold"), tr("&Bold"), QWebPage::ToggleBold, text);
  314. text->setAction(Fb::TextBold, act);
  315. act->setShortcuts(QKeySequence::Bold);
  316. act->setCheckable(true);
  317. menu->addAction(act);
  318. act = new FbTextAction(FbIcon("format-text-italic"), tr("&Italic"), QWebPage::ToggleItalic, text);
  319. text->setAction(Fb::TextItalic, act);
  320. act->setShortcuts(QKeySequence::Italic);
  321. act->setCheckable(true);
  322. menu->addAction(act);
  323. act = new FbTextAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), QWebPage::ToggleStrikethrough, text);
  324. text->setAction(Fb::TextStrike, act);
  325. act->setCheckable(true);
  326. menu->addAction(act);
  327. act = new FbTextAction(FbIcon("format-text-superscript"), tr("Su&perscript"), QWebPage::ToggleSuperscript, text);
  328. text->setAction(Fb::TextSup, act);
  329. act->setCheckable(true);
  330. menu->addAction(act);
  331. act = new FbTextAction(FbIcon("format-text-subscript"), tr("Su&bscript"), QWebPage::ToggleSubscript, text);
  332. text->setAction(Fb::TextSub, act);
  333. act->setCheckable(true);
  334. menu->addAction(act);
  335. act = new QAction(FbIcon("utilities-terminal"), tr("&Code"), this);
  336. text->setAction(Fb::TextCode, act);
  337. act->setCheckable(true);
  338. menu->addAction(act);
  339. menu->addSeparator();
  340. act = new QAction(FbIcon("format-indent-more"), tr("Create section"), text);
  341. text->setAction(Fb::SectionAdd, act);
  342. menu->addAction(act);
  343. act = new QAction(FbIcon("format-indent-less"), tr("Remove section"), text);
  344. text->setAction(Fb::SectionDel, act);
  345. menu->addAction(act);
  346. act = new QAction(FbIcon("format-justify-center"), tr("Make title"), text);
  347. text->setAction(Fb::TextTitle, act);
  348. menu->addAction(act);
  349. menu = menuBar()->addMenu(tr("&View"));
  350. tool->addSeparator();
  351. QActionGroup * viewGroup = new QActionGroup(this);
  352. act = new FbModeAction(mainDock, Fb::Text, FbIcon("x-office-document"), tr("&Text"));
  353. viewGroup->addAction(act);
  354. mainDock->addAction(Fb::Text, act);
  355. menu->addAction(act);
  356. tool->addAction(act);
  357. act->setChecked(true);
  358. act = new FbModeAction(mainDock, Fb::Head, FbIcon("document-properties"), tr("&Head"));
  359. viewGroup->addAction(act);
  360. mainDock->addAction(Fb::Head, act);
  361. menu->addAction(act);
  362. tool->addAction(act);
  363. act = new FbModeAction(mainDock, Fb::Code, FbIcon("text-x-generic"), tr("&XML"));
  364. viewGroup->addAction(act);
  365. mainDock->addAction(Fb::Code, act);
  366. menu->addAction(act);
  367. tool->addAction(act);
  368. #ifdef QT_DEBUG
  369. act = new FbModeAction(mainDock, Fb::Html, FbIcon("text-html"), tr("&HTML"));
  370. mainDock->addAction(Fb::Html, act);
  371. viewGroup->addAction(act);
  372. menu->addAction(act);
  373. #endif // _DEBUG
  374. menu->addSeparator();
  375. act = new QAction(FbIcon("zoom-in"), tr("Zoom in"), this);
  376. text->setAction(Fb::ZoomIn, act);
  377. code->setAction(Fb::ZoomIn, act);
  378. act->setShortcuts(QKeySequence::ZoomIn);
  379. menu->addAction(act);
  380. act = new QAction(FbIcon("zoom-out"), tr("Zoom out"), this);
  381. text->setAction(Fb::ZoomOut, act);
  382. code->setAction(Fb::ZoomOut, act);
  383. act->setShortcuts(QKeySequence::ZoomOut);
  384. menu->addAction(act);
  385. act = new QAction(FbIcon("zoom-original"), tr("Zoom original"), this);
  386. text->setAction(Fb::ZoomReset, act);
  387. code->setAction(Fb::ZoomReset, act);
  388. menu->addAction(act);
  389. menu->addSeparator();
  390. act = new QAction(tr("&Contents"), this);
  391. text->setAction(Fb::ViewContents, act);
  392. act->setCheckable(true);
  393. menu->addAction(act);
  394. act = new QAction(tr("&Pictures"), this);
  395. text->setAction(Fb::ViewPictures, act);
  396. act->setCheckable(true);
  397. menu->addAction(act);
  398. act = new QAction(tr("&Footnotes"), this);
  399. text->setAction(Fb::ViewFootnotes, act);
  400. act->setCheckable(true);
  401. menu->addAction(act);
  402. act = new QAction(tr("&Web inspector"), this);
  403. text->setAction(Fb::ViewInspector, act);
  404. act->setCheckable(true);
  405. menu->addAction(act);
  406. menuBar()->addSeparator();
  407. menu = menuBar()->addMenu(tr("&Help"));
  408. act = new QAction(FbIcon("help-about"), tr("&About"), this);
  409. act->setStatusTip(tr("Show the application's About box"));
  410. connect(act, SIGNAL(triggered()), this, SLOT(about()));
  411. menu->addAction(act);
  412. act = new QAction(tr("About &Qt"), this);
  413. act->setStatusTip(tr("Show the Qt library's About box"));
  414. connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
  415. menu->addAction(act);
  416. toolEdit = tool = addToolBar(tr("Edit"));
  417. tool->setMovable(false);
  418. tool->addSeparator();
  419. mainDock->setTool(tool);
  420. }
  421. void FbMainWindow::openSettings()
  422. {
  423. FbSetupDlg dlg(this);
  424. dlg.exec();
  425. }
  426. void FbMainWindow::createStatusBar()
  427. {
  428. statusBar()->showMessage(tr("Ready"));
  429. }
  430. void FbMainWindow::readSettings()
  431. {
  432. QSettings settings;
  433. QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
  434. QSize size = settings.value("size", QSize(400, 400)).toSize();
  435. move(pos);
  436. resize(size);
  437. }
  438. void FbMainWindow::writeSettings()
  439. {
  440. QSettings settings;
  441. settings.setValue("pos", pos());
  442. settings.setValue("size", size());
  443. }
  444. bool FbMainWindow::maybeSave()
  445. {
  446. if (mainDock->isModified()) {
  447. QMessageBox::StandardButton ret;
  448. ret = QMessageBox::warning(this, qApp->applicationName(),
  449. tr("The document has been modified. Do you want to save your changes?"),
  450. QMessageBox::Save | QMessageBox::Discard
  451. | QMessageBox::Cancel);
  452. if (ret == QMessageBox::Save)
  453. return fileSave();
  454. else if (ret == QMessageBox::Cancel)
  455. return false;
  456. }
  457. return true;
  458. }
  459. bool FbMainWindow::saveFile(const QString &fileName, const QString &codec)
  460. {
  461. QFile file(fileName);
  462. if (!file.open(QFile::WriteOnly | QFile::Text)) {
  463. QMessageBox::warning(this, qApp->applicationName(), tr("Cannot write file %1: %2.").arg(fileName).arg(file.errorString()));
  464. return false;
  465. }
  466. bool ok = mainDock->save(&file, codec);
  467. setCurrentFile(fileName);
  468. return ok;
  469. }
  470. void FbMainWindow::setCurrentFile(const QString &filename)
  471. {
  472. if (filename.isEmpty()) {
  473. static int sequenceNumber = 1;
  474. curFile = QString("book%1.fb2").arg(sequenceNumber++);
  475. } else {
  476. QFileInfo info = filename;
  477. curFile = info.canonicalFilePath();
  478. }
  479. setWindowFilePath(curFile);
  480. setModified(false);
  481. }
  482. QString FbMainWindow::appTitle() const
  483. {
  484. return QString(" - ") += qApp->applicationName() += QString(" ") += qApp->applicationVersion();
  485. }
  486. FbMainWindow *FbMainWindow::findFbMainWindow(const QString &fileName)
  487. {
  488. QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
  489. foreach (QWidget *widget, qApp->topLevelWidgets()) {
  490. FbMainWindow *mainWin = qobject_cast<FbMainWindow *>(widget);
  491. if (mainWin && mainWin->curFile == canonicalFilePath)
  492. return mainWin;
  493. }
  494. return 0;
  495. }
  496. /*
  497. void FbMainWindow::viewHead()
  498. {
  499. if (headTree && centralWidget() == headTree) return;
  500. if (textFrame) textFrame->hideInspector();
  501. FbTextPage *page = 0;
  502. if (codeEdit) {
  503. QString xml = codeEdit->text();
  504. page = new FbTextPage(this);
  505. if (!page->load(QString(), xml)) {
  506. delete page;
  507. return;
  508. }
  509. isSwitched = true;
  510. }
  511. FB2DELETE(dockTree);
  512. FB2DELETE(dockImgs);
  513. FB2DELETE(codeEdit);
  514. FB2DELETE(toolEdit);
  515. if (!textFrame) {
  516. textFrame = new FbTextFrame(this, actionInspect);
  517. FbTextEdit *textEdit = textFrame->view();
  518. if (page) {
  519. page->setParent(textEdit);
  520. textEdit->setPage(page);
  521. }
  522. }
  523. if (!headTree) {
  524. headTree = new FbHeadEdit(this);
  525. headTree->setText(textFrame->view());
  526. connect(headTree, SIGNAL(status(QString)), this, SLOT(status(QString)));
  527. }
  528. this->setFocus();
  529. textFrame->setParent(NULL);
  530. setCentralWidget(headTree);
  531. textFrame->setParent(this);
  532. headTree->updateTree();
  533. headTree->setFocus();
  534. if (textFrame) {
  535. actionUndo->disconnect();
  536. actionRedo->disconnect();
  537. actionCut->disconnect();
  538. actionCopy->disconnect();
  539. actionPaste->disconnect();
  540. actionTextBold->disconnect();
  541. actionTextItalic->disconnect();
  542. actionTextStrike->disconnect();
  543. actionTextSub->disconnect();
  544. actionTextSup->disconnect();
  545. }
  546. FB2DELETE(toolEdit);
  547. toolEdit = addToolBar(tr("Edit"));
  548. headTree->initToolbar(*toolEdit);
  549. toolEdit->addSeparator();
  550. toolEdit->setMovable(false);
  551. actionContents->setEnabled(false);
  552. actionPictures->setEnabled(false);
  553. actionInspect->setEnabled(true);
  554. }
  555. */
  556. void FbMainWindow::status(const QString &text)
  557. {
  558. statusBar()->showMessage(text);
  559. }