Kandrashin Denis 12 лет назад
Родитель
Сommit
94cbe25acb
5 измененных файлов с 36 добавлено и 26 удалено
  1. 10 4
      source/fb2head.cpp
  2. 3 2
      source/fb2head.hpp
  3. 20 19
      source/fb2main.cpp
  4. 2 0
      source/fb2main.hpp
  5. 1 1
      source/fb2text.hpp

+ 10 - 4
source/fb2head.cpp

@@ -554,9 +554,9 @@ bool FbHeadModel::canEdit(const QModelIndex &index) const
 //  FbTreeView
 //---------------------------------------------------------------------------
 
-FbHeadView::FbHeadView(FbTextEdit *view, QWidget *parent)
+FbHeadView::FbHeadView(QWidget *parent)
     : QTreeView(parent)
-    , m_view(*view)
+    , m_view(0)
 {
     QAction * act;
 
@@ -584,13 +584,18 @@ FbHeadView::FbHeadView(FbTextEdit *view, QWidget *parent)
     setRootIsDecorated(false);
     setSelectionBehavior(QAbstractItemView::SelectItems);
     setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
-    connect(&m_view, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
     connect(this, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex)));
     connect(this, SIGNAL(collapsed(QModelIndex)), SLOT(collapsed(QModelIndex)));
 
     header()->setDefaultSectionSize(200);
 }
 
+void FbHeadView::setView(FbTextEdit *view)
+{
+    m_view = view;
+    connect(m_view, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
+}
+
 FbHeadModel * FbHeadView::model() const
 {
     return qobject_cast<FbHeadModel*>(QTreeView::model());
@@ -605,7 +610,8 @@ void FbHeadView::initToolbar(QToolBar &toolbar)
 
 void FbHeadView::updateTree()
 {
-    FbHeadModel * model = new FbHeadModel(m_view, this);
+    if (!m_view) return;
+    FbHeadModel * model = new FbHeadModel(*m_view, this);
     setModel(model);
     model->expand(this);
 }

+ 3 - 2
source/fb2head.hpp

@@ -168,8 +168,9 @@ class FbHeadView : public QTreeView
     Q_OBJECT
 
 public:
-    explicit FbHeadView(FbTextEdit *view, QWidget *parent = 0);
+    explicit FbHeadView(QWidget *parent = 0);
     void initToolbar(QToolBar &toolbar);
+    void setView(FbTextEdit *view);
     FbHeadModel * model() const;
 
 signals:
@@ -192,7 +193,7 @@ private:
     void showStatus(const QModelIndex &current);
 
 private:
-    FbTextEdit & m_view;
+    FbTextEdit * m_view;
     QAction * actionInsert;
     QAction * actionModify;
     QAction * actionDelete;

+ 20 - 19
source/fb2main.cpp

@@ -1,5 +1,6 @@
 #include <QtGui>
 #include <QtDebug>
+#include <QStackedWidget>
 #include <QTreeView>
 #include <QWebFrame>
 
@@ -67,6 +68,14 @@ FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
     createStatusBar();
     readSettings();
 
+    mainDock = new QStackedWidget(this);
+    mainDock->addWidget(textFrame = new FbTextFrame(mainDock));
+    mainDock->addWidget(codeEdit = new FbCodeEdit(mainDock));
+    mainDock->addWidget(headTree = new FbHeadView(mainDock));
+    setCentralWidget(mainDock);
+
+    headTree->setView(textFrame->view());
+
     setCurrentFile(filename);
     if (mode == FB2) {
         viewText();
@@ -780,7 +789,7 @@ void FbMainWindow::viewText()
     } else {
         textFrame = new FbTextFrame(this, actionInspect);
     }
-    setCentralWidget(textFrame);
+//    setCentralWidget(textFrame);
     viewTree();
 
     FbTextEdit *textEdit = textFrame->view();
@@ -800,30 +809,22 @@ void FbMainWindow::viewText()
 
 void FbMainWindow::viewHead()
 {
-    if (headTree && centralWidget() == headTree) return;
-
-    if (textFrame) textFrame->hideInspector();
-
-    QString xml;
-    if (codeEdit) xml = codeEdit->text();
+    if (mainDock->currentWidget() == headTree) return;
 
     FB2DELETE(dockTree);
     FB2DELETE(dockImgs);
-    FB2DELETE(codeEdit);
-    FB2DELETE(toolEdit);
+    textFrame->hideInspector();
 
-    if (!textFrame) {
-        textFrame = new FbTextFrame(this, actionInspect);
-    }
+    mainDock->setCurrentWidget(headTree);
 
-    if (!headTree) {
-        headTree = new FbHeadView(textFrame->view(), this);
-        connect(headTree, SIGNAL(status(QString)), this, SLOT(status(QString)));
-    }
+    QString xml;
+    if (codeEdit) xml = codeEdit->text();
+
+    connect(headTree, SIGNAL(status(QString)), this, SLOT(status(QString)));
 
     this->setFocus();
     textFrame->setParent(NULL);
-    setCentralWidget(headTree);
+//    setCentralWidget(headTree);
     textFrame->setParent(this);
     headTree->updateTree();
 
@@ -878,7 +879,7 @@ void FbMainWindow::viewCode()
         codeEdit = new FbCodeEdit;
     }
     if (load) codeEdit->load(xml);
-    setCentralWidget(codeEdit);
+//    setCentralWidget(codeEdit);
     codeEdit->setFocus();
 
     FB2DELETE(toolEdit);
@@ -938,7 +939,7 @@ void FbMainWindow::viewHtml()
     }
 
     codeEdit->setPlainText(html);
-    setCentralWidget(codeEdit);
+//    setCentralWidget(codeEdit);
     codeEdit->setFocus();
 
     FB2DELETE(toolEdit);

+ 2 - 0
source/fb2main.hpp

@@ -9,6 +9,7 @@ class QAction;
 class QFile;
 class QMenu;
 class QModelIndex;
+class QStackedWidget;
 class QTextEdit;
 class QTreeView;
 class QWebInspector;
@@ -112,6 +113,7 @@ private:
     void setCurrentFile(const QString &fileName = QString());
     FbMainWindow *findFbMainWindow(const QString &fileName);
 
+    QStackedWidget *mainDock;
     FbTextFrame *textFrame;
     FbCodeEdit *codeEdit;
     FbHeadView *headTree;

+ 1 - 1
source/fb2text.hpp

@@ -199,7 +199,7 @@ class FbTextFrame : public QFrame
     Q_OBJECT
 
 public:
-    explicit FbTextFrame(QWidget *parent, QAction *action);
+    explicit FbTextFrame(QWidget *parent, QAction *action = 0);
     ~FbTextFrame();
 
 public: