Browse Source

New class Fb2HeadView

Kandrashin Denis 13 years ago
parent
commit
e268c2c91e
6 changed files with 57 additions and 35 deletions
  1. 22 0
      source/fb2head.cpp
  2. 17 4
      source/fb2head.hpp
  3. 13 26
      source/fb2main.cpp
  4. 2 2
      source/fb2main.hpp
  5. 0 2
      source/fb2tree.cpp
  6. 3 1
      source/fb2tree.hpp

+ 22 - 0
source/fb2head.cpp

@@ -6,6 +6,8 @@
 #include <QWebView>
 #include <QTreeView>
 
+#include "fb2view.hpp"
+
 Fb2HeadItem::HintHash::HintHash()
 {
     insert( "title-info"    , tr( "Book"        ));
@@ -242,3 +244,23 @@ void Fb2HeadModel::select(const QModelIndex &index)
     if (!node || node->id().isEmpty()) return;
     m_view.page()->mainFrame()->scrollToAnchor(node->id());
 }
+
+
+//---------------------------------------------------------------------------
+//  Fb2TreeView
+//---------------------------------------------------------------------------
+
+Fb2HeadView::Fb2HeadView(Fb2WebView &view, QWidget *parent)
+    : QTreeView(parent)
+    , m_view(view)
+{
+    connect(&m_view, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
+}
+
+void Fb2HeadView::updateTree()
+{
+    Fb2HeadModel * model = new Fb2HeadModel(m_view, this);
+    setModel(model);
+    model->expand(this);
+}
+

+ 17 - 4
source/fb2head.hpp

@@ -2,15 +2,14 @@
 #define FB2HEAD_H
 
 #include <QAbstractItemModel>
+#include <QTreeView>
 #include <QWebElement>
 #include <QWebView>
 
-QT_BEGIN_NAMESPACE
-class QTreeView;
-QT_END_NAMESPACE
-
 #include "fb2xml.h"
 
+class Fb2WebView;
+
 class Fb2HeadItem: public QObject
 {
     Q_OBJECT
@@ -102,4 +101,18 @@ private:
     Fb2HeadItem * m_root;
 };
 
+class Fb2HeadView : public QTreeView
+{
+    Q_OBJECT
+
+public:
+    explicit Fb2HeadView(Fb2WebView &view, QWidget *parent = 0);
+
+public slots:
+    void updateTree();
+
+private:
+    Fb2WebView & m_view;
+};
+
 #endif // FB2HEAD_H

+ 13 - 26
source/fb2main.cpp

@@ -449,16 +449,6 @@ void Fb2MainWindow::createTree()
     treeView->setFocus();
 }
 
-void Fb2MainWindow::loadFinished(bool ok)
-{
-    Q_UNUSED(ok);
-    if (headTree) {
-        Fb2HeadModel *model = new Fb2HeadModel(*textEdit, treeView);
-        headTree->setModel(model);
-        model->expand(headTree);
-    }
-}
-
 void Fb2MainWindow::selectionChanged()
 {
     actionCut->setEnabled(textEdit->CutEnabled());
@@ -664,7 +654,6 @@ void Fb2MainWindow::viewText()
 
     connect(textEdit->page(), SIGNAL(contentsChanged()), SLOT(documentWasModified()));
     connect(textEdit->page(), SIGNAL(selectionChanged()), SLOT(selectionChanged()));
-    connect(textEdit, SIGNAL(loadFinished(bool)), SLOT(loadFinished(bool)));
 
     connect(textEdit->pageAction(QWebPage::Undo), SIGNAL(changed()), SLOT(undoChanged()));
     connect(textEdit->pageAction(QWebPage::Redo), SIGNAL(changed()), SLOT(redoChanged()));
@@ -726,23 +715,21 @@ void Fb2MainWindow::viewHead()
     FB2DELETE(codeEdit);
     FB2DELETE(toolEdit);
 
+    if (!textEdit) {
+        textEdit = new Fb2WebView(this);
+    }
+
     if (!headTree) {
-        headTree = new QTreeView(this);
+        headTree = new Fb2HeadView(*textEdit, this);
         headTree->header()->setDefaultSectionSize(200);
     }
-    if (textEdit) {
-        this->setFocus();
-        textEdit->setParent(NULL);
-        setCentralWidget(headTree);
-        textEdit->setParent(this);
-        Fb2HeadModel *model = new Fb2HeadModel(*textEdit, treeView);
-        headTree->setModel(model);
-        model->expand(headTree);
-    } else {
-        textEdit = new Fb2WebView(this);
-        connect(textEdit, SIGNAL(loadFinished(bool)), SLOT(loadFinished(bool)));
-        setCentralWidget(headTree);
-    }
+
+    this->setFocus();
+    textEdit->setParent(NULL);
+    setCentralWidget(headTree);
+    textEdit->setParent(this);
+    headTree->updateTree();
+
     headTree->setFocus();
 
     if (!xml.isEmpty()) textEdit->load(curFile, xml);
@@ -774,7 +761,7 @@ void Fb2MainWindow::viewTree()
 {
     if (centralWidget() != textEdit) return;
     if (treeView == NULL) createTree();
-    loadFinished(true);
+    treeView->updateTree();
 }
 
 void Fb2MainWindow::clipboardDataChanged()

+ 2 - 2
source/fb2main.hpp

@@ -16,6 +16,7 @@ QT_END_NAMESPACE
 
 class Fb2CodeEdit;
 class Fb2TreeView;
+class Fb2HeadView;
 class Fb2WebView;
 
 class Fb2MainWindow : public QMainWindow
@@ -51,7 +52,6 @@ private slots:
     void viewTree();
 
     void clipboardDataChanged();
-    void loadFinished(bool ok);
     void selectionChanged();
     void undoChanged();
     void redoChanged();
@@ -76,7 +76,7 @@ private:
 
     Fb2WebView *textEdit;
     QWebInspector *inspector;
-    QTreeView *headTree;
+    Fb2HeadView *headTree;
     QTextEdit *noteEdit;
     QTextEdit *messageEdit;
     QDockWidget *dockTree;

+ 0 - 2
source/fb2tree.cpp

@@ -248,8 +248,6 @@ Fb2TreeView::Fb2TreeView(Fb2WebView &view, QWidget *parent)
 {
     setHeaderHidden(true);
     connect(&m_view, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
-    connect(&m_view, SIGNAL(updateTree()), SLOT(updateTree()));
-    connect(&m_view, SIGNAL(selectTree()), SLOT(selectTree()));
     connect(this, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex)));
     connect(m_view.page(), SIGNAL(contentsChanged()), SLOT(contentsChanged()));
     connect(m_view.page(), SIGNAL(selectionChanged()), SLOT(selectionChanged()));

+ 3 - 1
source/fb2tree.hpp

@@ -100,12 +100,14 @@ class Fb2TreeView : public QTreeView
 public:
     explicit Fb2TreeView(Fb2WebView &view, QWidget *parent = 0);
 
+public slots:
+    void updateTree();
+
 private slots:
     void activated(const QModelIndex &index);
     void contentsChanged();
     void selectionChanged();
     void selectTree();
-    void updateTree();
 
 private:
     Fb2WebView & m_view;