diff options
author | Kandrashin Denis <mail@lintest.ru> | 2012-10-26 01:15:57 +0400 |
---|---|---|
committer | Kandrashin Denis <mail@lintest.ru> | 2012-10-26 01:15:57 +0400 |
commit | 94cbe25acb9de2e7b319e9c3e2551159fa3ce1a6 (patch) | |
tree | e757e5fb584366ed62b9c04b15259f0c85f2aeb4 | |
parent | 397346510ec1cd0f46510d41601a7bdc0139c429 (diff) |
Try to use QStackWidgetstack
-rw-r--r-- | source/fb2head.cpp | 14 | ||||
-rw-r--r-- | source/fb2head.hpp | 5 | ||||
-rw-r--r-- | source/fb2main.cpp | 39 | ||||
-rw-r--r-- | source/fb2main.hpp | 2 | ||||
-rw-r--r-- | source/fb2text.hpp | 2 |
5 files changed, 36 insertions, 26 deletions
diff --git a/source/fb2head.cpp b/source/fb2head.cpp index 1e6c6d3..c8a245e 100644 --- a/source/fb2head.cpp +++ b/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); } diff --git a/source/fb2head.hpp b/source/fb2head.hpp index d1e6085..d5c6819 100644 --- a/source/fb2head.hpp +++ b/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 ¤t); private: - FbTextEdit & m_view; + FbTextEdit * m_view; QAction * actionInsert; QAction * actionModify; QAction * actionDelete; diff --git a/source/fb2main.cpp b/source/fb2main.cpp index db7709f..f05ddbf 100644 --- a/source/fb2main.cpp +++ b/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); diff --git a/source/fb2main.hpp b/source/fb2main.hpp index 50b8f79..2001390 100644 --- a/source/fb2main.hpp +++ b/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; diff --git a/source/fb2text.hpp b/source/fb2text.hpp index 06cdc88..650ed35 100644 --- a/source/fb2text.hpp +++ b/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: |