fb2main.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. #include <QtGui>
  2. #include <QtDebug>
  3. #include <QTreeView>
  4. #include <QWebFrame>
  5. #include "fb2main.h"
  6. #include "fb2read.h"
  7. #include "fb2tree.h"
  8. #include "fb2view.h"
  9. #include "fb2main.h"
  10. #include <Qsci/qsciscintilla.h>
  11. #include <Qsci/qscilexerxml.h>
  12. Fb2MainWindow::Fb2MainWindow()
  13. {
  14. init();
  15. setCurrentFile();
  16. createText();
  17. }
  18. Fb2MainWindow::Fb2MainWindow(const QString &filename, ViewMode mode)
  19. {
  20. init();
  21. setCurrentFile(filename);
  22. if (mode == FB2) {
  23. createText();
  24. textEdit->load(filename);
  25. } else {
  26. createQsci();
  27. loadXML(filename);
  28. }
  29. }
  30. void Fb2MainWindow::init()
  31. {
  32. connect(qApp, SIGNAL(logMessage(QString)), SLOT(logMessage(QString)));
  33. setAttribute(Qt::WA_DeleteOnClose);
  34. isUntitled = true;
  35. createActions();
  36. createStatusBar();
  37. textEdit = NULL;
  38. noteEdit = NULL;
  39. qsciEdit = NULL;
  40. treeView = NULL;
  41. messageEdit = NULL;
  42. readSettings();
  43. setUnifiedTitleAndToolBarOnMac(true);
  44. }
  45. void Fb2MainWindow::logMessage(const QString &message)
  46. {
  47. if (!messageEdit) {
  48. messageEdit = new QTextEdit(this);
  49. connect(messageEdit, SIGNAL(destroyed()), SLOT(logDestroyed()));
  50. QDockWidget * dock = new QDockWidget(tr("Message log"), this);
  51. dock->setAttribute(Qt::WA_DeleteOnClose);
  52. dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
  53. dock->setWidget(messageEdit);
  54. addDockWidget(Qt::BottomDockWidgetArea, dock);
  55. messageEdit->setMaximumHeight(80);
  56. }
  57. messageEdit->append(message);
  58. }
  59. void Fb2MainWindow::logShowed()
  60. {
  61. messageEdit->setMaximumHeight(QWIDGETSIZE_MAX);
  62. }
  63. void Fb2MainWindow::logDestroyed()
  64. {
  65. messageEdit = NULL;
  66. }
  67. static QTextFrame * findFrame(QTextFrame *root, const QModelIndex &index)
  68. {
  69. if (!index.isValid()) return root;
  70. if (QTextFrame *frame = findFrame(root, index.parent())) {
  71. QTextFrame *child = static_cast<QTextFrame*>(index.internalPointer());
  72. int i = frame->childFrames().indexOf(child);
  73. if (i >= 0) return child;
  74. }
  75. return NULL;
  76. }
  77. void Fb2MainWindow::treeActivated(const QModelIndex &index)
  78. {
  79. }
  80. void Fb2MainWindow::treeDestroyed()
  81. {
  82. treeView = NULL;
  83. }
  84. bool Fb2MainWindow::loadXML(const QString &filename)
  85. {
  86. if (!filename.isEmpty()) {
  87. QFile file(filename);
  88. if (file.open(QFile::ReadOnly | QFile::Text)) {
  89. qsciEdit->clear();
  90. return qsciEdit->read(&file);
  91. }
  92. }
  93. return false;
  94. }
  95. void Fb2MainWindow::closeEvent(QCloseEvent *event)
  96. {
  97. if (maybeSave()) {
  98. writeSettings();
  99. event->accept();
  100. } else {
  101. event->ignore();
  102. }
  103. }
  104. void Fb2MainWindow::fileNew()
  105. {
  106. Fb2MainWindow *other = new Fb2MainWindow;
  107. other->move(x() + 40, y() + 40);
  108. other->show();
  109. }
  110. void Fb2MainWindow::fileOpen()
  111. {
  112. QString filename = QFileDialog::getOpenFileName(this);
  113. if (filename.isEmpty()) return;
  114. Fb2MainWindow * existing = findFb2MainWindow(filename);
  115. if (existing) {
  116. existing->show();
  117. existing->raise();
  118. existing->activateWindow();
  119. return;
  120. }
  121. if (textEdit) {
  122. if (isUntitled && !isWindowModified()) {
  123. setCurrentFile(filename);
  124. textEdit->load(filename);
  125. } else {
  126. Fb2MainWindow * other = new Fb2MainWindow(filename, FB2);
  127. other->move(x() + 40, y() + 40);
  128. other->show();
  129. }
  130. } else if (qsciEdit) {
  131. if (isUntitled && !isWindowModified()) {
  132. setCurrentFile(filename);
  133. loadXML(filename);
  134. } else {
  135. Fb2MainWindow * other = new Fb2MainWindow(filename, XML);
  136. other->move(x() + 40, y() + 40);
  137. other->show();
  138. }
  139. }
  140. }
  141. /*
  142. void Fb2MainWindow::sendDocument()
  143. {
  144. treeView = new QTreeView(this);
  145. treeView->setModel(new Fb2TreeModel(*textEdit));
  146. treeView->setHeaderHidden(true);
  147. connect(treeView, SIGNAL(activated(QModelIndex)), SLOT(treeActivated(QModelIndex)));
  148. connect(treeView, SIGNAL(destroyed()), SLOT(treeDestroyed()));
  149. QDockWidget * dock = new QDockWidget(tr("Contents"), this);
  150. dock->setAttribute(Qt::WA_DeleteOnClose);
  151. dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
  152. dock->setWidget(treeView);
  153. addDockWidget(Qt::LeftDockWidgetArea, dock);
  154. }
  155. */
  156. bool Fb2MainWindow::fileSave()
  157. {
  158. if (isUntitled) {
  159. return fileSaveAs();
  160. } else {
  161. return saveFile(curFile);
  162. }
  163. }
  164. bool Fb2MainWindow::fileSaveAs()
  165. {
  166. QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), curFile);
  167. if (fileName.isEmpty()) return false;
  168. return saveFile(fileName);
  169. }
  170. void Fb2MainWindow::about()
  171. {
  172. QMessageBox::about(this, tr("About SDI"),
  173. tr("The <b>SDI</b> example demonstrates how to write single "
  174. "document interface applications using Qt."));
  175. }
  176. void Fb2MainWindow::documentWasModified()
  177. {
  178. QFileInfo info = windowFilePath();
  179. QString title = info.fileName();
  180. title += QString("[*]") += QString(" - ") += qApp->applicationName();
  181. setWindowTitle(title);
  182. setWindowModified(true);
  183. }
  184. QIcon Fb2MainWindow::icon(const QString &name)
  185. {
  186. QIcon icon;
  187. icon.addFile(QString(":/res/24/%1.png").arg(name), QSize(24,24));
  188. icon.addFile(QString(":/res/16/%1.png").arg(name), QSize(16,16));
  189. return QIcon::fromTheme(name, icon);
  190. }
  191. void Fb2MainWindow::createActions()
  192. {
  193. QAction * act;
  194. QMenu * menu;
  195. QToolBar * tool;
  196. QList<QAction*> actions;
  197. menu = menuBar()->addMenu(tr("&File"));
  198. tool = addToolBar(tr("File"));
  199. act = new QAction(icon("document-new"), tr("&New"), this);
  200. act->setPriority(QAction::LowPriority);
  201. act->setShortcuts(QKeySequence::New);
  202. act->setStatusTip(tr("Create a new file"));
  203. connect(act, SIGNAL(triggered()), this, SLOT(fileNew()));
  204. menu->addAction(act);
  205. tool->addAction(act);
  206. act = new QAction(icon("document-open"), tr("&Open..."), this);
  207. act->setShortcuts(QKeySequence::Open);
  208. act->setStatusTip(tr("Open an existing file"));
  209. connect(act, SIGNAL(triggered()), this, SLOT(fileOpen()));
  210. menu->addAction(act);
  211. tool->addAction(act);
  212. act = new QAction(icon("document-save"), tr("&Save"), this);
  213. act->setShortcuts(QKeySequence::Save);
  214. act->setStatusTip(tr("Save the document to disk"));
  215. connect(act, SIGNAL(triggered()), this, SLOT(fileSave()));
  216. menu->addAction(act);
  217. tool->addAction(act);
  218. act = new QAction(icon("document-save-as"), tr("Save &As..."), this);
  219. act->setShortcuts(QKeySequence::SaveAs);
  220. act->setStatusTip(tr("Save the document under a new name"));
  221. connect(act, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
  222. menu->addAction(act);
  223. menu->addSeparator();
  224. act = new QAction(icon("window-close"), tr("&Close"), this);
  225. act->setShortcuts(QKeySequence::Close);
  226. act->setStatusTip(tr("Close this window"));
  227. connect(act, SIGNAL(triggered()), this, SLOT(close()));
  228. menu->addAction(act);
  229. act = new QAction(icon("application-exit"), tr("E&xit"), this);
  230. act->setShortcuts(QKeySequence::Quit);
  231. act->setStatusTip(tr("Exit the application"));
  232. connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
  233. menu->addAction(act);
  234. menu = menuBar()->addMenu(tr("&Edit"));
  235. tool = addToolBar(tr("Edit"));
  236. connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
  237. actionUndo = act = new QAction(icon("edit-undo"), tr("&Undo"), this);
  238. act->setPriority(QAction::LowPriority);
  239. act->setShortcut(QKeySequence::Undo);
  240. act->setEnabled(false);
  241. menu->addAction(act);
  242. tool->addAction(act);
  243. actionRedo = act = new QAction(icon("edit-redo"), tr("&Redo"), this);
  244. act->setPriority(QAction::LowPriority);
  245. act->setShortcut(QKeySequence::Redo);
  246. act->setEnabled(false);
  247. menu->addAction(act);
  248. tool->addAction(act);
  249. menu->addSeparator();
  250. tool->addSeparator();
  251. actionCut = act = new QAction(icon("edit-cut"), tr("Cu&t"), this);
  252. act->setPriority(QAction::LowPriority);
  253. act->setShortcuts(QKeySequence::Cut);
  254. act->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
  255. act->setEnabled(false);
  256. menu->addAction(act);
  257. tool->addAction(act);
  258. actionCopy = act = new QAction(icon("edit-copy"), tr("&Copy"), this);
  259. act->setPriority(QAction::LowPriority);
  260. act->setShortcuts(QKeySequence::Copy);
  261. act->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
  262. act->setEnabled(false);
  263. menu->addAction(act);
  264. tool->addAction(act);
  265. actionPaste = act = new QAction(icon("edit-paste"), tr("&Paste"), this);
  266. act->setPriority(QAction::LowPriority);
  267. act->setShortcuts(QKeySequence::Paste);
  268. act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
  269. menu->addAction(act);
  270. tool->addAction(act);
  271. clipboardDataChanged();
  272. menu = menuBar()->addMenu(tr("Format"));
  273. tool = addToolBar(tr("Format"));
  274. actionTextBold = act = new QAction(icon("format-text-bold"), tr("Bold"), this);
  275. act->setShortcuts(QKeySequence::Bold);
  276. act->setCheckable(true);
  277. connect(act, SIGNAL(triggered()), SLOT(textBold()));
  278. menu->addAction(act);
  279. tool->addAction(act);
  280. actionTextItalic = act = new QAction(icon("format-text-italic"), tr("Italic"), this);
  281. act->setShortcuts(QKeySequence::Italic);
  282. act->setCheckable(true);
  283. connect(act, SIGNAL(triggered()), SLOT(textItalic()));
  284. menu->addAction(act);
  285. tool->addAction(act);
  286. actionTextStrike = act = new QAction(icon("format-text-strikethrough"), tr("Strikethrough"), this);
  287. act->setCheckable(true);
  288. connect(act, SIGNAL(triggered()), SLOT(textStrike()));
  289. menu->addAction(act);
  290. tool->addAction(act);
  291. actionTextSup = act = new QAction(icon("format-text-superscript"), tr("Superscript"), this);
  292. act->setCheckable(true);
  293. connect(act, SIGNAL(triggered()), SLOT(textSup()));
  294. menu->addAction(act);
  295. tool->addAction(act);
  296. actionTextSub = act = new QAction(icon("format-text-subscript"), tr("Subscript"), this);
  297. act->setCheckable(true);
  298. connect(act, SIGNAL(triggered()), SLOT(textSub()));
  299. menu->addAction(act);
  300. tool->addAction(act);
  301. menu = menuBar()->addMenu(tr("&View"));
  302. QAction * actText = act = new QAction(tr("&Text"), this);
  303. act->setCheckable(true);
  304. connect(act, SIGNAL(triggered()), this, SLOT(viewText()));
  305. QAction * actQsci = act = new QAction(tr("&XML"), this);
  306. act->setCheckable(true);
  307. connect(act, SIGNAL(triggered()), this, SLOT(viewQsci()));
  308. QActionGroup * viewGroup = new QActionGroup(this);
  309. viewGroup->addAction(actText);
  310. viewGroup->addAction(actQsci);
  311. actText->setChecked(true);
  312. menu->addAction(actText);
  313. menu->addAction(actQsci);
  314. menu->addSeparator();
  315. tool = addToolBar(tr("Zoom"));
  316. actionZoomIn = act = new QAction(icon("zoom-in"), tr("Zoom in"), this);
  317. act->setShortcuts(QKeySequence::ZoomIn);
  318. menu->addAction(act);
  319. tool->addAction(act);
  320. actionZoomOut = act = new QAction(icon("zoom-out"), tr("Zoom out"), this);
  321. act->setShortcuts(QKeySequence::ZoomOut);
  322. menu->addAction(act);
  323. tool->addAction(act);
  324. actionZoomOrig = act = new QAction(icon("zoom-original"), tr("Zoom original"), this);
  325. menu->addAction(act);
  326. tool->addAction(act);
  327. menuBar()->addSeparator();
  328. menu = menuBar()->addMenu(tr("&Help"));
  329. act = new QAction(icon("help-about"), tr("&About"), this);
  330. act->setStatusTip(tr("Show the application's About box"));
  331. connect(act, SIGNAL(triggered()), this, SLOT(about()));
  332. menu->addAction(act);
  333. act = new QAction(tr("About &Qt"), this);
  334. act->setStatusTip(tr("Show the Qt library's About box"));
  335. connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
  336. menu->addAction(act);
  337. }
  338. void Fb2MainWindow::createText()
  339. {
  340. textEdit = new Fb2WebView(this);
  341. setCentralWidget(textEdit);
  342. textEdit->setFocus();
  343. connect(textEdit->page(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
  344. connect(textEdit, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
  345. connect(actionUndo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Undo), SIGNAL(triggered()));
  346. connect(actionRedo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Redo), SIGNAL(triggered()));
  347. connect(textEdit->pageAction(QWebPage::Undo), SIGNAL(changed()), this, SLOT(undoChanged()));
  348. connect(textEdit->pageAction(QWebPage::Redo), SIGNAL(changed()), this, SLOT(redoChanged()));
  349. connect(actionCut, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Cut), SIGNAL(triggered()));
  350. connect(actionCopy, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Copy), SIGNAL(triggered()));
  351. connect(actionPaste, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Paste), SIGNAL(triggered()));
  352. connect(actionTextBold, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleBold), SIGNAL(triggered()));
  353. connect(actionTextItalic, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleItalic), SIGNAL(triggered()));
  354. connect(actionTextStrike, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleStrikethrough), SIGNAL(triggered()));
  355. connect(actionTextSub, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleSubscript), SIGNAL(triggered()));
  356. connect(actionTextSup, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleSuperscript), SIGNAL(triggered()));
  357. connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
  358. connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
  359. connect(actionZoomOrig, SIGNAL(triggered()), textEdit, SLOT(zoomOrig()));
  360. }
  361. void Fb2MainWindow::selectionChanged()
  362. {
  363. actionCut->setEnabled(textEdit->CutEnabled());
  364. actionCopy->setEnabled(textEdit->CopyEnabled());
  365. actionTextBold->setChecked(textEdit->BoldChecked());
  366. actionTextItalic->setChecked(textEdit->ItalicChecked());
  367. actionTextStrike->setChecked(textEdit->StrikeChecked());
  368. actionTextSub->setChecked(textEdit->SubChecked());
  369. actionTextSup->setChecked(textEdit->SupChecked());
  370. }
  371. void Fb2MainWindow::undoChanged()
  372. {
  373. actionUndo->setEnabled(textEdit->UndoEnabled());
  374. }
  375. void Fb2MainWindow::redoChanged()
  376. {
  377. actionRedo->setEnabled(textEdit->RedoEnabled());
  378. }
  379. void Fb2MainWindow::createQsci()
  380. {
  381. // http://qtcoder.blogspot.com/2010/10/qscintills.html
  382. // http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciScintilla.html
  383. qsciEdit = new QsciScintilla;
  384. qsciEdit->setUtf8(true);
  385. qsciEdit->setCaretLineVisible(true);
  386. qsciEdit->setCaretLineBackgroundColor(QColor("gainsboro"));
  387. qsciEdit->setWrapMode(QsciScintilla::WrapWord);
  388. qsciEdit->setEolMode(QsciScintilla::EolWindows);
  389. qsciEdit->setAutoIndent(true);
  390. qsciEdit->setIndentationGuides(true);
  391. qsciEdit->setAutoCompletionSource(QsciScintilla::AcsAll);
  392. qsciEdit->setAutoCompletionCaseSensitivity(true);
  393. qsciEdit->setAutoCompletionReplaceWord(true);
  394. qsciEdit->setAutoCompletionShowSingle(true);
  395. qsciEdit->setAutoCompletionThreshold(2);
  396. qsciEdit->setMarginsBackgroundColor(QColor("gainsboro"));
  397. qsciEdit->setMarginWidth(0, 0);
  398. qsciEdit->setMarginLineNumbers(1, true);
  399. qsciEdit->setMarginWidth(1, QString("10000"));
  400. qsciEdit->setFolding(QsciScintilla::BoxedFoldStyle, 2);
  401. qsciEdit->setBraceMatching(QsciScintilla::SloppyBraceMatch);
  402. qsciEdit->setMatchedBraceBackgroundColor(Qt::yellow);
  403. qsciEdit->setUnmatchedBraceForegroundColor(Qt::blue);
  404. QFont font("Courier", 10);
  405. font.setStyleHint(QFont::TypeWriter);
  406. QsciLexerXML * lexer = new QsciLexerXML;
  407. lexer->setFont(font, -1);
  408. qsciEdit->setBraceMatching(QsciScintilla::SloppyBraceMatch);
  409. qsciEdit->setLexer(lexer);
  410. setCentralWidget(qsciEdit);
  411. qsciEdit->setFocus();
  412. // connect(qsciEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
  413. actionUndo->setEnabled(false);
  414. actionRedo->setEnabled(false);
  415. }
  416. void Fb2MainWindow::createStatusBar()
  417. {
  418. statusBar()->showMessage(tr("Ready"));
  419. }
  420. void Fb2MainWindow::readSettings()
  421. {
  422. QSettings settings;
  423. QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
  424. QSize size = settings.value("size", QSize(400, 400)).toSize();
  425. move(pos);
  426. resize(size);
  427. }
  428. void Fb2MainWindow::writeSettings()
  429. {
  430. QSettings settings;
  431. settings.setValue("pos", pos());
  432. settings.setValue("size", size());
  433. }
  434. bool Fb2MainWindow::maybeSave()
  435. {
  436. if (textEdit && textEdit->isModified()) {
  437. QMessageBox::StandardButton ret;
  438. ret = QMessageBox::warning(this, tr("SDI"),
  439. tr("The document has been modified.\n"
  440. "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 Fb2MainWindow::saveFile(const QString &fileName)
  451. {
  452. return false;
  453. QFile file(fileName);
  454. if (!file.open(QFile::WriteOnly | QFile::Text)) {
  455. QMessageBox::warning(this, tr("SDI"),
  456. tr("Cannot write file %1:\n%2.")
  457. .arg(fileName)
  458. .arg(file.errorString()));
  459. return false;
  460. }
  461. QTextStream out(&file);
  462. QApplication::setOverrideCursor(Qt::WaitCursor);
  463. // out << textEdit->toPlainText();
  464. QApplication::restoreOverrideCursor();
  465. setCurrentFile(fileName);
  466. statusBar()->showMessage(tr("File saved"), 2000);
  467. return true;
  468. }
  469. void Fb2MainWindow::setCurrentFile(const QString &filename)
  470. {
  471. static int sequenceNumber = 1;
  472. QString title;
  473. isUntitled = filename.isEmpty();
  474. if (isUntitled) {
  475. curFile = tr("book%1.fb2").arg(sequenceNumber++);
  476. title = curFile;
  477. } else {
  478. QFileInfo info = filename;
  479. curFile = info.canonicalFilePath();
  480. title = info.fileName();
  481. }
  482. title += QString(" - ") += qApp->applicationName();
  483. setWindowModified(false);
  484. setWindowFilePath(curFile);
  485. setWindowTitle(title);
  486. }
  487. Fb2MainWindow *Fb2MainWindow::findFb2MainWindow(const QString &fileName)
  488. {
  489. QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
  490. foreach (QWidget *widget, qApp->topLevelWidgets()) {
  491. Fb2MainWindow *mainWin = qobject_cast<Fb2MainWindow *>(widget);
  492. if (mainWin && mainWin->curFile == canonicalFilePath)
  493. return mainWin;
  494. }
  495. return 0;
  496. }
  497. void Fb2MainWindow::viewQsci()
  498. {
  499. if (centralWidget() == qsciEdit) return;
  500. QString html;
  501. if (textEdit) {
  502. html = textEdit->page()->mainFrame()->toHtml();
  503. delete textEdit;
  504. textEdit = NULL;
  505. }
  506. createQsci();
  507. qsciEdit->setText(html);
  508. }
  509. void Fb2MainWindow::viewText()
  510. {
  511. if (centralWidget() == textEdit) return;
  512. if (qsciEdit) { delete qsciEdit; qsciEdit = NULL; }
  513. createText();
  514. }
  515. void Fb2MainWindow::clipboardDataChanged()
  516. {
  517. if (const QMimeData *md = QApplication::clipboard()->mimeData()) {
  518. actionPaste->setEnabled(md->hasText());
  519. }
  520. }