Bläddra i källkod

small changes

Kandrashin Denis 12 år sedan
förälder
incheckning
7bd496b5e4
4 ändrade filer med 33 tillägg och 60 borttagningar
  1. 16 0
      source/fb2dock.cpp
  2. 1 1
      source/fb2dock.hpp
  3. 14 55
      source/fb2main.cpp
  4. 2 4
      source/fb2main.hpp

+ 16 - 0
source/fb2dock.cpp

@@ -39,3 +39,19 @@ void FbMainDock::setMode(Mode mode)
         case Code: setCurrentWidget(m_code); return;
         case Code: setCurrentWidget(m_code); return;
     }
     }
 }
 }
+
+bool FbMainDock::load(const QString &filename)
+{
+    QFile file(filename);
+    if (!file.open(QFile::ReadOnly | QFile::Text)) {
+        qCritical() << QObject::tr("Cannot read file %1: %2.").arg(filename).arg(file.errorString());
+        return false;
+    }
+
+    if (mode == Code) {
+        m_code->clear();
+        return m_code->read(&file);
+    }
+
+    return false;
+}

+ 1 - 1
source/fb2dock.hpp

@@ -17,7 +17,7 @@ public:
     FbTextEdit * text() { return m_text; }
     FbTextEdit * text() { return m_text; }
     FbHeadEdit * head() { return m_head; }
     FbHeadEdit * head() { return m_head; }
     FbCodeEdit * code() { return m_code; }
     FbCodeEdit * code() { return m_code; }
-
+    bool load(const QString &filename);
     Mode mode() const;
     Mode mode() const;
     void setMode(Mode mode);
     void setMode(Mode mode);
 
 

+ 14 - 55
source/fb2main.cpp

@@ -7,6 +7,7 @@
 #include "fb2main.hpp"
 #include "fb2main.hpp"
 #include "fb2code.hpp"
 #include "fb2code.hpp"
 #include "fb2dlgs.hpp"
 #include "fb2dlgs.hpp"
+#include "fb2dock.hpp"
 #include "fb2read.hpp"
 #include "fb2read.hpp"
 #include "fb2save.hpp"
 #include "fb2save.hpp"
 #include "fb2text.hpp"
 #include "fb2text.hpp"
@@ -46,9 +47,6 @@ QAction * FbTextAction::action(QWebPage::WebAction action)
 
 
 FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
 FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
     : QMainWindow()
     : QMainWindow()
-    , textFrame(0)
-    , codeEdit(0)
-    , headTree(0)
     , noteEdit(0)
     , noteEdit(0)
     , toolEdit(0)
     , toolEdit(0)
     , dockTree(0)
     , dockTree(0)
@@ -64,32 +62,23 @@ FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
     setAttribute(Qt::WA_DeleteOnClose);
     setAttribute(Qt::WA_DeleteOnClose);
     setWindowIcon(QIcon(":icon.ico"));
     setWindowIcon(QIcon(":icon.ico"));
 
 
+    mainDock = new FbMainDock(this);
+    setCentralWidget(mainDock);
+
     createActions();
     createActions();
     createStatusBar();
     createStatusBar();
     readSettings();
     readSettings();
 
 
     setCurrentFile(filename);
     setCurrentFile(filename);
-    if (mode == FB2) {
-        QString filepath = filename.isEmpty() ? ":blank.fb2" : filename;
-        FbTextPage *page = new FbTextPage(this);
-        if (page->load(filepath, QString())) {
-            viewText(page);
-        } else {
-            delete page;
-            viewCode();
-            if (!filename.isEmpty()) loadXML(filepath);
-        }
-    } else {
-        viewCode();
-        if (!filename.isEmpty()) loadXML(filename);
-    }
+    mainDock->load(filename);
 }
 }
 
 
+/*
 FbTextPage * FbMainWindow::page()
 FbTextPage * FbMainWindow::page()
 {
 {
     return textFrame ? textFrame->view()->page() : 0;
     return textFrame ? textFrame->view()->page() : 0;
 }
 }
-
+*/
 
 
 void FbMainWindow::logMessage(const QString &message)
 void FbMainWindow::logMessage(const QString &message)
 {
 {
@@ -128,18 +117,6 @@ void FbMainWindow::imgsDestroyed()
     dockImgs = NULL;
     dockImgs = NULL;
 }
 }
 
 
-bool FbMainWindow::loadXML(const QString &filename)
-{
-    if (!filename.isEmpty()) {
-        QFile file(filename);
-        if (file.open(QFile::ReadOnly | QFile::Text)) {
-            codeEdit->clear();
-            return codeEdit->read(&file);
-        }
-    }
-    return false;
-}
-
 void FbMainWindow::closeEvent(QCloseEvent *event)
 void FbMainWindow::closeEvent(QCloseEvent *event)
 {
 {
     if (maybeSave()) {
     if (maybeSave()) {
@@ -170,31 +147,13 @@ void FbMainWindow::fileOpen()
         return;
         return;
     }
     }
 
 
-    if (textFrame) {
-        if (isUntitled && !isWindowModified()) {
-            setCurrentFile(filename);
-            FbTextPage *page = new FbTextPage(this);
-            if (page->load(filename, QString())) {
-                viewText(page);
-            } else {
-                delete page;
-                viewCode();
-                if (!filename.isEmpty()) loadXML(filename);
-            }
-        } else {
-            FbMainWindow * other = new FbMainWindow(filename, FB2);
-            other->move(x() + 40, y() + 40);
-            other->show();
-        }
-    } else if (codeEdit) {
-        if (isUntitled && !isWindowModified()) {
-            setCurrentFile(filename);
-            loadXML(filename);
-        } else {
-            FbMainWindow * other = new FbMainWindow(filename, XML);
-            other->move(x() + 40, y() + 40);
-            other->show();
-        }
+    if (isUntitled && !isWindowModified()) {
+        mainDock->load(filename);
+    } else {
+        FbMainWindow * other = new FbMainWindow(filename, FB2);
+        other->mainDock->load(filename);
+        other->move(x() + 40, y() + 40);
+        other->show();
     }
     }
 }
 }
 
 

+ 2 - 4
source/fb2main.hpp

@@ -14,6 +14,7 @@ class QTreeView;
 class QWebInspector;
 class QWebInspector;
 QT_END_NAMESPACE
 QT_END_NAMESPACE
 
 
+class FbMainDock;
 class FbCodeEdit;
 class FbCodeEdit;
 class FbTreeView;
 class FbTreeView;
 class FbHeadEdit;
 class FbHeadEdit;
@@ -95,7 +96,6 @@ private slots:
     void openSettings();
     void openSettings();
 
 
 private:
 private:
-    bool loadXML(const QString &filename);
     QString appTitle() const;
     QString appTitle() const;
 
 
 private:
 private:
@@ -112,9 +112,7 @@ private:
     void setCurrentFile(const QString &fileName = QString());
     void setCurrentFile(const QString &fileName = QString());
     FbMainWindow *findFbMainWindow(const QString &fileName);
     FbMainWindow *findFbMainWindow(const QString &fileName);
 
 
-    FbTextFrame *textFrame;
-    FbCodeEdit *codeEdit;
-    FbHeadEdit *headTree;
+    FbMainDock *mainDock;
     QTextEdit *noteEdit;
     QTextEdit *noteEdit;
     QToolBar *toolEdit;
     QToolBar *toolEdit;
     QDockWidget *dockTree;
     QDockWidget *dockTree;