fb2main.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. #ifdef QT_DEBUG
  171. act = new QAction(tr("&Export HTML"), this);
  172. connect(act, SIGNAL(triggered()), text, SLOT(exportHtml()));
  173. menu->addAction(act);
  174. #endif // QT_DEBUG
  175. menu->addSeparator();
  176. act = new QAction(FbIcon("window-close"), tr("&Close"), this);
  177. act->setShortcuts(QKeySequence::Close);
  178. act->setStatusTip(tr("Close this window"));
  179. connect(act, SIGNAL(triggered()), this, SLOT(close()));
  180. menu->addAction(act);
  181. act = new QAction(FbIcon("application-exit"), tr("E&xit"), this);
  182. act->setShortcuts(QKeySequence::Quit);
  183. act->setStatusTip(tr("Exit the application"));
  184. connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
  185. menu->addAction(act);
  186. menu = menuBar()->addMenu(tr("&Edit"));
  187. act = new FbTextAction(FbIcon("edit-undo"), tr("&Undo"), QWebPage::Undo, text);
  188. text->setAction(Fb::EditUndo, act);
  189. code->setAction(Fb::EditUndo, act);
  190. act->setPriority(QAction::LowPriority);
  191. act->setShortcut(QKeySequence::Undo);
  192. act->setEnabled(false);
  193. menu->addAction(act);
  194. act = new FbTextAction(FbIcon("edit-redo"), tr("&Redo"), QWebPage::Redo, text);
  195. text->setAction(Fb::EditRedo, act);
  196. code->setAction(Fb::EditRedo, act);
  197. act->setPriority(QAction::LowPriority);
  198. act->setShortcut(QKeySequence::Redo);
  199. act->setEnabled(false);
  200. menu->addAction(act);
  201. menu->addSeparator();
  202. act = new FbTextAction(FbIcon("edit-cut"), tr("Cu&t"), QWebPage::Cut, text);
  203. text->setAction(Fb::EditCut, act);
  204. code->setAction(Fb::EditCut, act);
  205. act->setShortcutContext(Qt::WidgetShortcut);
  206. act->setPriority(QAction::LowPriority);
  207. act->setShortcuts(QKeySequence::Cut);
  208. act->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
  209. act->setEnabled(false);
  210. menu->addAction(act);
  211. act = new FbTextAction(FbIcon("edit-copy"), tr("&Copy"), QWebPage::Copy, text);
  212. text->setAction(Fb::EditCopy, act);
  213. code->setAction(Fb::EditCopy, act);
  214. act->setShortcutContext(Qt::WidgetShortcut);
  215. act->setPriority(QAction::LowPriority);
  216. act->setShortcuts(QKeySequence::Copy);
  217. act->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
  218. act->setEnabled(false);
  219. menu->addAction(act);
  220. act = new FbTextAction(FbIcon("edit-paste"), tr("&Paste"), QWebPage::Paste, text);
  221. text->setAction(Fb::EditPaste, act);
  222. code->setAction(Fb::EditPaste, act);
  223. act->setShortcutContext(Qt::WidgetShortcut);
  224. act->setPriority(QAction::LowPriority);
  225. act->setShortcuts(QKeySequence::Paste);
  226. act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
  227. menu->addAction(act);
  228. act = new FbTextAction(tr("Paste (no style)"), QWebPage::PasteAndMatchStyle, text);
  229. text->setAction(Fb::PasteText, act);
  230. menu->addAction(act);
  231. menu->addSeparator();
  232. act = new QAction(FbIcon("edit-find"), tr("&Find..."), this);
  233. text->setAction(Fb::EditFind, act);
  234. code->setAction(Fb::EditFind, act);
  235. act->setShortcuts(QKeySequence::Find);
  236. menu->addAction(act);
  237. act = new QAction(FbIcon("edit-find-replace"), tr("&Replace..."), this);
  238. text->setAction(Fb::EditReplace, act);
  239. code->setAction(Fb::EditReplace, act);
  240. menu->addAction(act);
  241. act = new QAction(FbIcon("tools-check-spelling"), tr("&Check..."), this);
  242. code->setAction(Fb::CheckText, act);
  243. menu->addAction(act);
  244. menu->addSeparator();
  245. act = new QAction(FbIcon("preferences-desktop"), tr("&Settings"), this);
  246. act->setShortcuts(QKeySequence::Preferences);
  247. act->setStatusTip(tr("Application settings"));
  248. connect(act, SIGNAL(triggered()), SLOT(openSettings()));
  249. menu->addAction(act);
  250. menu = menuBar()->addMenu(tr("&Insert", "Main menu"));
  251. mainDock->addMenu(menu);
  252. act = new QAction(FbIcon("insert-image"), tr("&Image"), this);
  253. text->setAction(Fb::InsertImage, act);
  254. menu->addAction(act);
  255. act = new QAction(FbIcon("insert-text"), tr("&Footnote"), this);
  256. text->setAction(Fb::InsertNote, act);
  257. menu->addAction(act);
  258. act = new QAction(FbIcon("insert-link"), tr("&Hiperlink"), this);
  259. text->setAction(Fb::InsertLink, act);
  260. menu->addAction(act);
  261. menu->addSeparator();
  262. act = new QAction(tr("&Body"), this);
  263. text->setAction(Fb::InsertBody, act);
  264. menu->addAction(act);
  265. act = new QAction(FbIcon("insert-object"), tr("&Section"), this);
  266. text->setAction(Fb::InsertSection, act);
  267. menu->addAction(act);
  268. act = new QAction(tr("&Title"), this);
  269. text->setAction(Fb::InsertTitle, act);
  270. menu->addAction(act);
  271. act = new QAction(tr("&Epigraph"), this);
  272. text->setAction(Fb::InsertEpigraph, act);
  273. menu->addAction(act);
  274. act = new QAction(tr("&Annotation"), this);
  275. text->setAction(Fb::InsertAnnot, act);
  276. menu->addAction(act);
  277. act = new QAction(tr("&Subtitle"), this);
  278. text->setAction(Fb::InsertSubtitle, act);
  279. menu->addAction(act);
  280. act = new QAction(tr("&Cite"), this);
  281. text->setAction(Fb::InsertCite, act);
  282. menu->addAction(act);
  283. act = new QAction(tr("&Poem"), this);
  284. text->setAction(Fb::InsertPoem, act);
  285. menu->addAction(act);
  286. act = new QAction(tr("&Stanza"), this);
  287. text->setAction(Fb::InsertStanza, act);
  288. menu->addAction(act);
  289. act = new QAction(tr("&Author"), this);
  290. text->setAction(Fb::InsertAuthor, act);
  291. menu->addAction(act);
  292. act = new QAction(tr("&Date"), this);
  293. text->setAction(Fb::InsertDate, act);
  294. menu->addAction(act);
  295. menu->addSeparator();
  296. act = new QAction(tr("Simple text"), this);
  297. text->setAction(Fb::InsertText, act);
  298. menu->addAction(act);
  299. act = new FbTextAction(tr("Paragraph"), QWebPage::InsertParagraphSeparator, text);
  300. text->setAction(Fb::InsertParag, act);
  301. menu->addAction(act);
  302. menu = menuBar()->addMenu(tr("Fo&rmat"));
  303. mainDock->addMenu(menu);
  304. act = new FbTextAction(FbIcon("edit-clear"), tr("Clear format"), QWebPage::RemoveFormat, text);
  305. text->setAction(Fb::ClearFormat, act);
  306. menu->addAction(act);
  307. menu->addSeparator();
  308. act = new FbTextAction(FbIcon("format-text-bold"), tr("&Bold"), QWebPage::ToggleBold, text);
  309. text->setAction(Fb::TextBold, act);
  310. act->setShortcuts(QKeySequence::Bold);
  311. act->setCheckable(true);
  312. menu->addAction(act);
  313. act = new FbTextAction(FbIcon("format-text-italic"), tr("&Italic"), QWebPage::ToggleItalic, text);
  314. text->setAction(Fb::TextItalic, act);
  315. act->setShortcuts(QKeySequence::Italic);
  316. act->setCheckable(true);
  317. menu->addAction(act);
  318. act = new FbTextAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), QWebPage::ToggleStrikethrough, text);
  319. text->setAction(Fb::TextStrike, act);
  320. act->setCheckable(true);
  321. menu->addAction(act);
  322. act = new FbTextAction(FbIcon("format-text-superscript"), tr("Su&perscript"), QWebPage::ToggleSuperscript, text);
  323. text->setAction(Fb::TextSup, act);
  324. act->setCheckable(true);
  325. menu->addAction(act);
  326. act = new FbTextAction(FbIcon("format-text-subscript"), tr("Su&bscript"), QWebPage::ToggleSubscript, text);
  327. text->setAction(Fb::TextSub, act);
  328. act->setCheckable(true);
  329. menu->addAction(act);
  330. act = new QAction(FbIcon("utilities-terminal"), tr("&Code"), this);
  331. text->setAction(Fb::TextCode, act);
  332. act->setCheckable(true);
  333. menu->addAction(act);
  334. menu->addSeparator();
  335. act = new QAction(FbIcon("format-indent-more"), tr("Create section"), text);
  336. text->setAction(Fb::SectionAdd, act);
  337. menu->addAction(act);
  338. act = new QAction(FbIcon("format-indent-less"), tr("Remove section"), text);
  339. text->setAction(Fb::SectionDel, act);
  340. menu->addAction(act);
  341. act = new QAction(FbIcon("format-justify-center"), tr("Make title"), text);
  342. text->setAction(Fb::TextTitle, act);
  343. menu->addAction(act);
  344. menu = menuBar()->addMenu(tr("&View"));
  345. tool->addSeparator();
  346. QActionGroup * viewGroup = new QActionGroup(this);
  347. act = new FbModeAction(mainDock, Fb::Text, FbIcon("x-office-document"), tr("&Text"));
  348. viewGroup->addAction(act);
  349. mainDock->addAction(Fb::Text, act);
  350. menu->addAction(act);
  351. tool->addAction(act);
  352. act->setChecked(true);
  353. act = new FbModeAction(mainDock, Fb::Head, FbIcon("document-properties"), tr("&Head"));
  354. viewGroup->addAction(act);
  355. mainDock->addAction(Fb::Head, act);
  356. menu->addAction(act);
  357. tool->addAction(act);
  358. act = new FbModeAction(mainDock, Fb::Code, FbIcon("text-x-generic"), tr("&XML"));
  359. viewGroup->addAction(act);
  360. mainDock->addAction(Fb::Code, act);
  361. menu->addAction(act);
  362. tool->addAction(act);
  363. #ifdef QT_DEBUG
  364. act = new FbModeAction(mainDock, Fb::Html, FbIcon("text-html"), tr("&HTML"));
  365. mainDock->addAction(Fb::Html, act);
  366. viewGroup->addAction(act);
  367. menu->addAction(act);
  368. #endif // QT_DEBUG
  369. menu->addSeparator();
  370. act = new QAction(FbIcon("zoom-in"), tr("Zoom in"), this);
  371. text->setAction(Fb::ZoomIn, act);
  372. code->setAction(Fb::ZoomIn, act);
  373. act->setShortcuts(QKeySequence::ZoomIn);
  374. menu->addAction(act);
  375. act = new QAction(FbIcon("zoom-out"), tr("Zoom out"), this);
  376. text->setAction(Fb::ZoomOut, act);
  377. code->setAction(Fb::ZoomOut, act);
  378. act->setShortcuts(QKeySequence::ZoomOut);
  379. menu->addAction(act);
  380. act = new QAction(FbIcon("zoom-original"), tr("Zoom original"), this);
  381. text->setAction(Fb::ZoomReset, act);
  382. code->setAction(Fb::ZoomReset, act);
  383. menu->addAction(act);
  384. menu->addSeparator();
  385. act = new QAction(tr("&Contents"), this);
  386. text->setAction(Fb::ViewContents, act);
  387. act->setCheckable(true);
  388. menu->addAction(act);
  389. act = new QAction(tr("&Pictures"), this);
  390. text->setAction(Fb::ViewPictures, act);
  391. act->setCheckable(true);
  392. menu->addAction(act);
  393. act = new QAction(tr("&Footnotes"), this);
  394. text->setAction(Fb::ViewFootnotes, act);
  395. act->setCheckable(true);
  396. menu->addAction(act);
  397. act = new QAction(tr("&Web inspector"), this);
  398. text->setAction(Fb::ViewInspector, act);
  399. act->setCheckable(true);
  400. menu->addAction(act);
  401. menuBar()->addSeparator();
  402. menu = menuBar()->addMenu(tr("&Help"));
  403. act = new QAction(FbIcon("help-about"), tr("&About"), this);
  404. act->setStatusTip(tr("Show the application's About box"));
  405. connect(act, SIGNAL(triggered()), this, SLOT(about()));
  406. menu->addAction(act);
  407. act = new QAction(tr("About &Qt"), this);
  408. act->setStatusTip(tr("Show the Qt library's About box"));
  409. connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
  410. menu->addAction(act);
  411. toolEdit = tool = addToolBar(tr("Edit"));
  412. tool->setIconSize(QSize(24, 24));
  413. tool->setMovable(false);
  414. tool->addSeparator();
  415. mainDock->setTool(tool);
  416. }
  417. void FbMainWindow::openSettings()
  418. {
  419. FbSetupDlg dlg(this);
  420. dlg.exec();
  421. }
  422. void FbMainWindow::createStatusBar()
  423. {
  424. statusBar()->showMessage(tr("Ready"));
  425. }
  426. void FbMainWindow::readSettings()
  427. {
  428. QSettings settings;
  429. QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
  430. QSize size = settings.value("size", QSize(400, 400)).toSize();
  431. move(pos);
  432. resize(size);
  433. }
  434. void FbMainWindow::writeSettings()
  435. {
  436. QSettings settings;
  437. settings.setValue("pos", pos());
  438. settings.setValue("size", size());
  439. }
  440. bool FbMainWindow::maybeSave()
  441. {
  442. if (mainDock->isModified()) {
  443. QMessageBox::StandardButton ret;
  444. ret = QMessageBox::warning(this, qApp->applicationName(),
  445. tr("The document has been modified. Do you want to save your changes?"),
  446. QMessageBox::Save | QMessageBox::Discard
  447. | QMessageBox::Cancel);
  448. if (ret == QMessageBox::Save)
  449. return fileSave();
  450. else if (ret == QMessageBox::Cancel)
  451. return false;
  452. }
  453. return true;
  454. }
  455. bool FbMainWindow::saveFile(const QString &fileName, const QString &codec)
  456. {
  457. QFile file(fileName);
  458. if (!file.open(QFile::WriteOnly | QFile::Text)) {
  459. QMessageBox::warning(this, qApp->applicationName(), tr("Cannot write file %1: %2.").arg(fileName).arg(file.errorString()));
  460. return false;
  461. }
  462. bool ok = mainDock->save(&file, codec);
  463. setCurrentFile(fileName);
  464. return ok;
  465. }
  466. void FbMainWindow::setCurrentFile(const QString &filename)
  467. {
  468. if (filename.isEmpty()) {
  469. static int sequenceNumber = 1;
  470. curFile = QString("book%1.fb2").arg(sequenceNumber++);
  471. } else {
  472. QFileInfo info = filename;
  473. curFile = info.canonicalFilePath();
  474. }
  475. setWindowFilePath(curFile);
  476. textChanged(false);
  477. }
  478. QString FbMainWindow::appTitle() const
  479. {
  480. return QString(" - ") += qApp->applicationName() += QString(" ") += qApp->applicationVersion();
  481. }
  482. FbMainWindow *FbMainWindow::findFbMainWindow(const QString &fileName)
  483. {
  484. QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
  485. foreach (QWidget *widget, qApp->topLevelWidgets()) {
  486. FbMainWindow *mainWin = qobject_cast<FbMainWindow *>(widget);
  487. if (mainWin && mainWin->curFile == canonicalFilePath)
  488. return mainWin;
  489. }
  490. return 0;
  491. }
  492. /*
  493. void FbMainWindow::viewHead()
  494. {
  495. if (headTree && centralWidget() == headTree) return;
  496. if (textFrame) textFrame->hideInspector();
  497. FbTextPage *page = 0;
  498. if (codeEdit) {
  499. QString xml = codeEdit->text();
  500. page = new FbTextPage(this);
  501. if (!page->load(QString(), xml)) {
  502. delete page;
  503. return;
  504. }
  505. isSwitched = true;
  506. }
  507. FB2DELETE(dockTree);
  508. FB2DELETE(dockImgs);
  509. FB2DELETE(codeEdit);
  510. FB2DELETE(toolEdit);
  511. if (!textFrame) {
  512. textFrame = new FbTextFrame(this, actionInspect);
  513. FbTextEdit *textEdit = textFrame->view();
  514. if (page) {
  515. page->setParent(textEdit);
  516. textEdit->setPage(page);
  517. }
  518. }
  519. if (!headTree) {
  520. headTree = new FbHeadEdit(this);
  521. headTree->setText(textFrame->view());
  522. connect(headTree, SIGNAL(status(QString)), this, SLOT(status(QString)));
  523. }
  524. this->setFocus();
  525. textFrame->setParent(NULL);
  526. setCentralWidget(headTree);
  527. textFrame->setParent(this);
  528. headTree->updateTree();
  529. headTree->setFocus();
  530. if (textFrame) {
  531. actionUndo->disconnect();
  532. actionRedo->disconnect();
  533. actionCut->disconnect();
  534. actionCopy->disconnect();
  535. actionPaste->disconnect();
  536. actionTextBold->disconnect();
  537. actionTextItalic->disconnect();
  538. actionTextStrike->disconnect();
  539. actionTextSub->disconnect();
  540. actionTextSup->disconnect();
  541. }
  542. FB2DELETE(toolEdit);
  543. toolEdit = addToolBar(tr("Edit"));
  544. headTree->initToolbar(*toolEdit);
  545. toolEdit->addSeparator();
  546. toolEdit->setMovable(false);
  547. actionContents->setEnabled(false);
  548. actionPictures->setEnabled(false);
  549. actionInspect->setEnabled(true);
  550. }
  551. */
  552. void FbMainWindow::status(const QString &text)
  553. {
  554. statusBar()->showMessage(text);
  555. }