fb2main.cpp 20 KB

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