fb2main.cpp 19 KB

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