1
0
Kandrashin Denis 13 жил өмнө
parent
commit
1f923d0fcd
2 өөрчлөгдсөн 20 нэмэгдсэн , 62 устгасан
  1. 17 50
      source/fb2main.cpp
  2. 3 12
      source/fb2main.h

+ 17 - 50
source/fb2main.cpp

@@ -15,31 +15,25 @@
 Fb2MainWindow::Fb2MainWindow()
 {
     init();
+    setCurrentFile();
     createText();
-    setCurrentFile("");
 }
 
-Fb2MainWindow::Fb2MainWindow(const QString &filename)
+Fb2MainWindow::Fb2MainWindow(const QString &filename, ViewMode mode)
 {
     init();
-    createQsci();
-    loadXML(filename);
     setCurrentFile(filename);
-}
-
-Fb2MainWindow::Fb2MainWindow(const QString &filename, Fb2MainDocument * document)
-{
-    init();
-    createText();
-    thread = new Fb2ReadThread(this, filename);
-    connect(thread, SIGNAL(sendDocument()), SLOT(sendDocument()));
-    thread->start();
+    if (mode == FB2) {
+        createText();
+        textEdit->load(filename);
+    } else {
+        createQsci();
+        loadXML(filename);
+    }
 }
 
 void Fb2MainWindow::init()
 {
-    thread = NULL;
-
     connect(qApp, SIGNAL(logMessage(QString)), SLOT(logMessage(QString)));
 
     setAttribute(Qt::WA_DeleteOnClose);
@@ -149,18 +143,19 @@ void Fb2MainWindow::fileOpen()
 
     if (textEdit) {
         if (isUntitled && !isWindowModified()) {
+            setCurrentFile(filename);
             textEdit->load(filename);
         } else {
-            Fb2MainWindow * other = new Fb2MainWindow(filename, NULL);
+            Fb2MainWindow * other = new Fb2MainWindow(filename, FB2);
             other->move(x() + 40, y() + 40);
             other->show();
         }
     } else if (qsciEdit) {
         if (isUntitled && !isWindowModified()) {
-            loadXML(filename);
             setCurrentFile(filename);
+            loadXML(filename);
         } else {
-            Fb2MainWindow * other = new Fb2MainWindow(filename);
+            Fb2MainWindow * other = new Fb2MainWindow(filename, XML);
             other->move(x() + 40, y() + 40);
             other->show();
         }
@@ -403,21 +398,15 @@ void Fb2MainWindow::createActions()
     connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
     menu->addAction(act);
 }
-/*
-void Fb2MainWindow::connectTextDocument(QTextDocument * document)
-{
-    connect(document, SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
-    connect(document, SIGNAL(undoAvailable(bool)), actionUndo, SLOT(setEnabled(bool)));
-    connect(document, SIGNAL(redoAvailable(bool)), actionRedo, SLOT(setEnabled(bool)));
-}
-*/
+
 void Fb2MainWindow::createText()
 {
     textEdit = new Fb2WebView(this);
     setCentralWidget(textEdit);
     textEdit->setFocus();
 
-    connect(textEdit, SIGNAL(selectionChanged()), this, SLOT(contentChanged()));
+    connect(textEdit->page(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
+    connect(textEdit, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
 
     connect(actionUndo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Undo), SIGNAL(triggered()));
     connect(actionRedo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Redo), SIGNAL(triggered()));
@@ -573,7 +562,7 @@ bool Fb2MainWindow::saveFile(const QString &fileName)
     return true;
 }
 
-void Fb2MainWindow::setCurrentFile(const QString &filename, const QString &html)
+void Fb2MainWindow::setCurrentFile(const QString &filename)
 {
     static int sequenceNumber = 1;
 
@@ -589,8 +578,6 @@ void Fb2MainWindow::setCurrentFile(const QString &filename, const QString &html)
     }
     title += QString(" - ") += qApp->applicationName();
 
-    textEdit->setHtml(html, QUrl("fb2://s/"));
-
     setWindowModified(false);
     setWindowFilePath(curFile);
     setWindowTitle(title);
@@ -635,23 +622,3 @@ void Fb2MainWindow::clipboardDataChanged()
     }
 }
 
-void Fb2MainWindow::textBold()
-{
-}
-
-void Fb2MainWindow::textItalic()
-{
-}
-
-void Fb2MainWindow::textStrike()
-{
-}
-
-void Fb2MainWindow::textSub()
-{
-}
-
-void Fb2MainWindow::textSup()
-{
-}
-

+ 3 - 12
source/fb2main.h

@@ -9,13 +9,11 @@ class QMenu;
 class QFile;
 class QModelIndex;
 class QTextEdit;
-class QThread;
 class QTreeView;
 QT_END_NAMESPACE
 
 class QsciScintilla;
 class Fb2MainDocument;
-class Fb2ReadThread;
 class Fb2WebView;
 
 class Fb2MainWindow : public QMainWindow
@@ -23,9 +21,9 @@ class Fb2MainWindow : public QMainWindow
     Q_OBJECT
 
 public:
+    enum ViewMode { FB2, XML };
     explicit Fb2MainWindow();
-    explicit Fb2MainWindow(const QString &filename);
-    explicit Fb2MainWindow(const QString &filename, Fb2MainDocument * document);
+    explicit Fb2MainWindow(const QString &filename, ViewMode mode = FB2);
 
 protected:
     void closeEvent(QCloseEvent *event);
@@ -48,12 +46,6 @@ private slots:
     void viewQsci();
     void viewText();
 
-    void textBold();
-    void textItalic();
-    void textStrike();
-    void textSub();
-    void textSup();
-
     void clipboardDataChanged();
     void selectionChanged();
     void undoChanged();
@@ -73,10 +65,9 @@ private:
     void writeSettings();
     bool maybeSave();
     bool saveFile(const QString &fileName);
-    void setCurrentFile(const QString &fileName, const QString &html = QString());
+    void setCurrentFile(const QString &fileName = QString());
     Fb2MainWindow *findFb2MainWindow(const QString &fileName);
 
-    Fb2ReadThread *thread;
     Fb2WebView *textEdit;
     QTextEdit *noteEdit;
     QTextEdit *messageEdit;