fb2main.cpp 20 KB

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