fb2main.cpp 20 KB

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