fb2main.cpp 20 KB

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