浏览代码

Show status and switch HTML

Kandrashin Denis 12 年之前
父节点
当前提交
43b3116f7f
共有 4 个文件被更改,包括 21 次插入12 次删除
  1. 11 7
      source/fb2dock.cpp
  2. 1 1
      source/fb2main.hpp
  3. 5 3
      source/fb2page.cpp
  4. 4 1
      source/fb2page.hpp

+ 11 - 7
source/fb2dock.cpp

@@ -44,28 +44,32 @@ FbMainDock::FbMainDock(QWidget *parent)
     addWidget(textFrame);
     addWidget(m_head);
     addWidget(m_code);
+
+    connect(m_text->page(), SIGNAL(status(QString)), parent, SLOT(status(QString)));
 }
 
 void FbMainDock::switchMode(Fb::Mode mode)
 {
-    QString xml;
+    if (mode == m_mode) return;
     if (currentWidget() == m_code) {
-        switch (mode) {
-            case Fb::Text:
-            case Fb::Head:
+        QString xml = m_code->toPlainText();
+        switch (m_mode) {
+            case Fb::Code: m_text->page()->read(xml); break;
+            case Fb::Html: m_text->setHtml(xml, m_text->url()); break;
             default: ;
         }
     } else {
+        QString xml;
         switch (mode) {
             case Fb::Code: m_text->save(&xml); break;
             case Fb::Html: xml = m_text->toHtml(); break;
             default: ;
         }
+        if (!xml.isEmpty()) {
+            m_code->setPlainText(xml);
+        }
     }
     setMode(mode);
-    if (!xml.isEmpty()) {
-        m_code->setPlainText(xml);
-    }
 }
 
 void FbMainDock::setMode(Fb::Mode mode)

+ 1 - 1
source/fb2main.hpp

@@ -47,6 +47,7 @@ signals:
 
 public slots:
     void logMessage(const QString &message);
+    void status(const QString &text);
 
 private slots:
     void fileNew();
@@ -59,7 +60,6 @@ private slots:
     void logDestroyed();
     void logShowed();
 
-    void status(const QString &text);
     void openSettings();
 
 private:

+ 5 - 3
source/fb2page.cpp

@@ -46,6 +46,7 @@ FbTextPage::FbTextPage(QObject *parent)
     connect(this, SIGNAL(linkHovered(QString,QString,QString)), parent, SLOT(linkHovered(QString,QString,QString)));
     connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
     connect(this, SIGNAL(contentsChanged()), SLOT(fixContents()));
+    connect(this, SIGNAL(selectionChanged()), SLOT(showStatus()));
 
     QFile *file = new QFile(":blank.fb2");
     if (file->open(QFile::ReadOnly | QFile::Text)) {
@@ -392,11 +393,12 @@ QString FbTextPage::location()
     return mainFrame()->evaluateJavaScript(javascript).toString();
 }
 
-QString FbTextPage::status()
+void FbTextPage::showStatus()
 {
     QString javascript = jScript("get_status.js");
-    QString status = mainFrame()->evaluateJavaScript(javascript).toString();
-    return status.replace("FB:", "");
+    QString text = mainFrame()->evaluateJavaScript(javascript).toString();
+    text.replace("FB:", "");
+    emit status(text);
 }
 
 void FbTextPage::loadFinished()

+ 4 - 1
source/fb2page.hpp

@@ -35,7 +35,6 @@ public:
     FbTextElement element(const QString &location);
     FbTextElement current();
     QString location();
-    QString status();
 
     FbTextElement body();
     FbTextElement doc();
@@ -45,6 +44,9 @@ public:
     FbTextElement appendText(const FbTextElement &parent);
     static QUrl createUrl();
 
+signals:
+    void status(const QString &text);
+
 public slots:
     void html(QObject *temp, const QString &html);
     void insertBody();
@@ -75,6 +77,7 @@ protected:
 private slots:
     void loadFinished();
     void fixContents();
+    void showStatus();
 
 private:
     FbActionMap m_actions;