Răsfoiți Sursa

Setup view actions

Kandrashin Denis 12 ani în urmă
părinte
comite
dfb3dadde7
4 a modificat fișierele cu 126 adăugiri și 101 ștergeri
  1. 115 98
      source/fb2main.cpp
  2. 6 1
      source/fb2main.hpp
  3. 4 1
      source/fb2text.cpp
  4. 1 1
      source/fb2text.hpp

+ 115 - 98
source/fb2main.cpp

@@ -88,11 +88,13 @@ void FbMainWindow::logDestroyed()
 
 
 void FbMainWindow::treeDestroyed()
 void FbMainWindow::treeDestroyed()
 {
 {
+    actionContents->setChecked(false);
     dockTree = NULL;
     dockTree = NULL;
 }
 }
 
 
 void FbMainWindow::imgsDestroyed()
 void FbMainWindow::imgsDestroyed()
 {
 {
+    actionPictures->setChecked(false);
     dockImgs = NULL;
     dockImgs = NULL;
 }
 }
 
 
@@ -434,15 +436,19 @@ void FbMainWindow::createActions()
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    act = new QAction(tr("&Contents"), this);
+    actionContents = act = new QAction(tr("&Contents"), this);
+    act->setCheckable(true);
     connect(act, SIGNAL(triggered()), this, SLOT(viewTree()));
     connect(act, SIGNAL(triggered()), this, SLOT(viewTree()));
     menu->addAction(act);
     menu->addAction(act);
 
 
-    act = new QAction(tr("&Pictures"), this);
+    actionPictures = act = new QAction(tr("&Pictures"), this);
+    act->setCheckable(true);
     connect(act, SIGNAL(triggered()), this, SLOT(viewImgs()));
     connect(act, SIGNAL(triggered()), this, SLOT(viewImgs()));
     menu->addAction(act);
     menu->addAction(act);
 
 
     actionInspect = act = new QAction(tr("&Web inspector"), this);
     actionInspect = act = new QAction(tr("&Web inspector"), this);
+    act->setCheckable(true);
+    connect(this, SIGNAL(showInspectorChecked(bool)), actionInspect, SLOT(setChecked(bool)));
     menu->addAction(act);
     menu->addAction(act);
 
 
     menuBar()->addSeparator();
     menuBar()->addSeparator();
@@ -470,6 +476,7 @@ void FbMainWindow::createTree()
     if (textFrame && centralWidget() == textFrame) {
     if (textFrame && centralWidget() == textFrame) {
         dockTree = new FbDockWidget(tr("Contents"), this);
         dockTree = new FbDockWidget(tr("Contents"), this);
         dockTree->setWidget(new FbTreeWidget(textFrame->view(), this));
         dockTree->setWidget(new FbTreeWidget(textFrame->view(), this));
+        connect(dockTree, SIGNAL(visibilityChanged(bool)), actionContents, SLOT(setChecked(bool)));
         connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
         connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
         addDockWidget(Qt::LeftDockWidgetArea, dockTree);
         addDockWidget(Qt::LeftDockWidgetArea, dockTree);
     }
     }
@@ -480,6 +487,7 @@ void FbMainWindow::createImgs()
     if (textFrame && centralWidget() == textFrame) {
     if (textFrame && centralWidget() == textFrame) {
         dockImgs = new FbDockWidget(tr("Pictures"), this);
         dockImgs = new FbDockWidget(tr("Pictures"), this);
         dockImgs->setWidget(new FbListWidget(textFrame->view(), this));
         dockImgs->setWidget(new FbListWidget(textFrame->view(), this));
+        connect(dockImgs, SIGNAL(visibilityChanged(bool)), actionPictures, SLOT(setChecked(bool)));
         connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed()));
         connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed()));
         addDockWidget(Qt::RightDockWidgetArea, dockImgs);
         addDockWidget(Qt::RightDockWidgetArea, dockImgs);
     }
     }
@@ -618,97 +626,7 @@ void FbMainWindow::checkScintillaUndo()
     actionRedo->setEnabled(codeEdit->isRedoAvailable());
     actionRedo->setEnabled(codeEdit->isRedoAvailable());
 }
 }
 
 
-void FbMainWindow::viewCode()
-{
-    if (codeEdit && centralWidget() == codeEdit) return;
-
-    bool load = false;
-    QByteArray xml;
-    if (textFrame) {
-        textFrame->view()->save(&xml);
-        isSwitched = true;
-        load = true;
-    }
-
-    FB2DELETE(textFrame);
-    FB2DELETE(dockTree);
-    FB2DELETE(dockImgs);
-    FB2DELETE(headTree);
-
-    if (!codeEdit) {
-        codeEdit = new FbCodeEdit;
-    }
-    if (load) codeEdit->load(xml);
-    setCentralWidget(codeEdit);
-    codeEdit->setFocus();
-
-    FB2DELETE(toolEdit);
-    QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
-    tool->addSeparator();
-    tool->addAction(actionUndo);
-    tool->addAction(actionRedo);
-    tool->addSeparator();
-    tool->addAction(actionCut);
-    tool->addAction(actionCopy);
-    tool->addAction(actionPaste);
-    tool->addSeparator();
-    tool->addAction(actionZoomIn);
-    tool->addAction(actionZoomOut);
-    tool->addAction(actionZoomReset);
-    tool->setMovable(false);
-
-    connect(codeEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
-    connect(codeEdit, SIGNAL(textChanged()), this, SLOT(checkScintillaUndo()));
-
-    connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
-    connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
-
-    connect(actionUndo, SIGNAL(triggered()), codeEdit, SLOT(undo()));
-    connect(actionRedo, SIGNAL(triggered()), codeEdit, SLOT(redo()));
-
-    connect(actionCut, SIGNAL(triggered()), codeEdit, SLOT(cut()));
-    connect(actionCopy, SIGNAL(triggered()), codeEdit, SLOT(copy()));
-    connect(actionPaste, SIGNAL(triggered()), codeEdit, SLOT(paste()));
-
-    connect(actionFind, SIGNAL(triggered()), codeEdit, SLOT(find()));
-
-    connect(actionZoomIn, SIGNAL(triggered()), codeEdit, SLOT(zoomIn()));
-    connect(actionZoomOut, SIGNAL(triggered()), codeEdit, SLOT(zoomOut()));
-    connect(actionZoomReset, SIGNAL(triggered()), codeEdit, SLOT(zoomReset()));
-}
-
-void FbMainWindow::viewText()
-{
-    if (textFrame && centralWidget() == textFrame) return;
-
-    bool load = false;
-    QString xml;
-    if (codeEdit) {
-        xml = codeEdit->text();
-        isSwitched = true;
-        load = true;
-    }
-
-    FB2DELETE(codeEdit);
-    FB2DELETE(headTree);
-    if (!textFrame) {
-        textFrame = new FbTextFrame(this);
-    }
-    setCentralWidget(textFrame);
-    textFrame->view()->setFocus();
-    viewTree();
-
-    FbTextEdit *textEdit = textFrame->view();
-
-    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()));
-    connect(actionInspect, SIGNAL(triggered()), textFrame, SLOT(showInspector()));
-
-    if (load) textFrame->view()->load(curFile, xml);
-}
-
-void FbMainWindow::loadFinished(bool)
+void FbMainWindow::createTextToolbar()
 {
 {
     FbTextEdit * textEdit = textFrame->view();
     FbTextEdit * textEdit = textFrame->view();
     FbTextPage * textPage = textEdit->page();
     FbTextPage * textPage = textEdit->page();
@@ -764,12 +682,44 @@ void FbMainWindow::loadFinished(bool)
     tool->addAction(actionNote);
     tool->addAction(actionNote);
     tool->addAction(actionLink);
     tool->addAction(actionLink);
     tool->addAction(actionSection);
     tool->addAction(actionSection);
+}
 
 
-    tool->addSeparator();
+void FbMainWindow::viewText()
+{
+    if (textFrame && centralWidget() == textFrame) return;
 
 
-    tool->addAction(actionZoomIn);
-    tool->addAction(actionZoomOut);
-    tool->addAction(actionZoomReset);
+    if (textFrame) textFrame->hideInspector();
+
+    bool load = false;
+    QString xml;
+    if (codeEdit) {
+        xml = codeEdit->text();
+        isSwitched = true;
+        load = true;
+    }
+
+    FB2DELETE(codeEdit);
+    FB2DELETE(headTree);
+    if (textFrame) {
+        createTextToolbar();
+    } else {
+        textFrame = new FbTextFrame(this, actionInspect);
+    }
+    setCentralWidget(textFrame);
+    textFrame->view()->setFocus();
+    viewTree();
+
+    FbTextEdit *textEdit = textFrame->view();
+
+    connect(textEdit, SIGNAL(loadFinished(bool)), SLOT(createTextToolbar()));
+    connect(textEdit->pageAction(QWebPage::Undo), SIGNAL(changed()), SLOT(undoChanged()));
+    connect(textEdit->pageAction(QWebPage::Redo), SIGNAL(changed()), SLOT(redoChanged()));
+
+    if (load) textFrame->view()->load(curFile, xml);
+
+    actionContents->setEnabled(true);
+    actionPictures->setEnabled(true);
+    actionInspect->setEnabled(true);
 }
 }
 
 
 void FbMainWindow::viewHead()
 void FbMainWindow::viewHead()
@@ -787,7 +737,7 @@ void FbMainWindow::viewHead()
     FB2DELETE(toolEdit);
     FB2DELETE(toolEdit);
 
 
     if (!textFrame) {
     if (!textFrame) {
-        textFrame = new FbTextFrame(this);
+        textFrame = new FbTextFrame(this, actionInspect);
     }
     }
 
 
     if (!headTree) {
     if (!headTree) {
@@ -825,6 +775,73 @@ void FbMainWindow::viewHead()
     headTree->initToolbar(*toolEdit);
     headTree->initToolbar(*toolEdit);
     toolEdit->addSeparator();
     toolEdit->addSeparator();
     toolEdit->setMovable(false);
     toolEdit->setMovable(false);
+
+    actionContents->setEnabled(false);
+    actionPictures->setEnabled(false);
+    actionInspect->setEnabled(true);
+}
+
+void FbMainWindow::viewCode()
+{
+    if (codeEdit && centralWidget() == codeEdit) return;
+
+    bool load = false;
+    QByteArray xml;
+    if (textFrame) {
+        textFrame->view()->save(&xml);
+        isSwitched = true;
+        load = true;
+    }
+
+    FB2DELETE(textFrame);
+    FB2DELETE(dockTree);
+    FB2DELETE(dockImgs);
+    FB2DELETE(headTree);
+
+    if (!codeEdit) {
+        codeEdit = new FbCodeEdit;
+    }
+    if (load) codeEdit->load(xml);
+    setCentralWidget(codeEdit);
+    codeEdit->setFocus();
+
+    FB2DELETE(toolEdit);
+    QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
+    tool->addSeparator();
+    tool->addAction(actionUndo);
+    tool->addAction(actionRedo);
+    tool->addSeparator();
+    tool->addAction(actionCut);
+    tool->addAction(actionCopy);
+    tool->addAction(actionPaste);
+    tool->addSeparator();
+    tool->addAction(actionZoomIn);
+    tool->addAction(actionZoomOut);
+    tool->addAction(actionZoomReset);
+    tool->setMovable(false);
+
+    connect(codeEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
+    connect(codeEdit, SIGNAL(textChanged()), this, SLOT(checkScintillaUndo()));
+
+    connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
+    connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
+
+    connect(actionUndo, SIGNAL(triggered()), codeEdit, SLOT(undo()));
+    connect(actionRedo, SIGNAL(triggered()), codeEdit, SLOT(redo()));
+
+    connect(actionCut, SIGNAL(triggered()), codeEdit, SLOT(cut()));
+    connect(actionCopy, SIGNAL(triggered()), codeEdit, SLOT(copy()));
+    connect(actionPaste, SIGNAL(triggered()), codeEdit, SLOT(paste()));
+
+    connect(actionFind, SIGNAL(triggered()), codeEdit, SLOT(find()));
+
+    connect(actionZoomIn, SIGNAL(triggered()), codeEdit, SLOT(zoomIn()));
+    connect(actionZoomOut, SIGNAL(triggered()), codeEdit, SLOT(zoomOut()));
+    connect(actionZoomReset, SIGNAL(triggered()), codeEdit, SLOT(zoomReset()));
+
+    actionContents->setEnabled(false);
+    actionPictures->setEnabled(false);
+    actionInspect->setEnabled(false);
 }
 }
 
 
 void FbMainWindow::viewTree()
 void FbMainWindow::viewTree()

+ 6 - 1
source/fb2main.hpp

@@ -38,6 +38,9 @@ public:
 protected:
 protected:
     void closeEvent(QCloseEvent *event);
     void closeEvent(QCloseEvent *event);
 
 
+signals:
+    void showInspectorChecked(bool);
+
 public slots:
 public slots:
     void logMessage(const QString &message);
     void logMessage(const QString &message);
 
 
@@ -48,7 +51,7 @@ private slots:
     bool fileSaveAs();
     bool fileSaveAs();
 
 
     void about();
     void about();
-    void loadFinished(bool);
+    void createTextToolbar();
     void documentWasModified();
     void documentWasModified();
     void checkScintillaUndo();
     void checkScintillaUndo();
     void treeDestroyed();
     void treeDestroyed();
@@ -137,6 +140,8 @@ private:
         *actionTextCode,
         *actionTextCode,
         *actionTextSub,
         *actionTextSub,
         *actionTextSup,
         *actionTextSup,
+        *actionContents,
+        *actionPictures,
         *actionInspect,
         *actionInspect,
         *actionZoomIn,
         *actionZoomIn,
         *actionZoomOut,
         *actionZoomOut,

+ 4 - 1
source/fb2text.cpp

@@ -651,7 +651,7 @@ void FbTextEdit::execCommand(const QString &cmd, const QString &arg)
 //  FbTextFrame
 //  FbTextFrame
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
 
-FbTextFrame::FbTextFrame(QWidget* parent)
+FbTextFrame::FbTextFrame(QWidget *parent, QAction *action)
     : QFrame(parent)
     : QFrame(parent)
     , m_view(this)
     , m_view(this)
     , m_dock(0)
     , m_dock(0)
@@ -663,6 +663,8 @@ FbTextFrame::FbTextFrame(QWidget* parent)
     layout->setSpacing(0);
     layout->setSpacing(0);
     layout->setMargin(0);
     layout->setMargin(0);
     layout->addWidget(&m_view);
     layout->addWidget(&m_view);
+
+    connect(action, SIGNAL(triggered()), SLOT(showInspector()));
 }
 }
 
 
 FbTextFrame::~FbTextFrame()
 FbTextFrame::~FbTextFrame()
@@ -688,6 +690,7 @@ void FbTextFrame::showInspector()
     inspector->setPage(m_view.page());
     inspector->setPage(m_view.page());
     m_dock->setWidget(inspector);
     m_dock->setWidget(inspector);
 
 
+    connect(m_dock, SIGNAL(visibilityChanged(bool)), main, SIGNAL(showInspectorChecked(bool)));
     connect(m_dock, SIGNAL(destroyed()), SLOT(dockDestroyed()));
     connect(m_dock, SIGNAL(destroyed()), SLOT(dockDestroyed()));
 }
 }
 
 

+ 1 - 1
source/fb2text.hpp

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