Browse Source

Text actions

Kandrashin Denis 12 năm trước cách đây
mục cha
commit
4e6944e2aa
13 tập tin đã thay đổi với 307 bổ sung245 xóa
  1. 76 75
      fb2edit.pro
  2. 8 0
      source/fb2code.cpp
  3. 4 3
      source/fb2code.hpp
  4. 42 7
      source/fb2dock.cpp
  5. 21 17
      source/fb2dock.hpp
  6. 12 3
      source/fb2head.cpp
  7. 5 6
      source/fb2head.hpp
  8. 11 9
      source/fb2main.cpp
  9. 22 0
      source/fb2mode.cpp
  10. 13 3
      source/fb2mode.h
  11. 2 2
      source/fb2page.hpp
  12. 82 88
      source/fb2text.cpp
  13. 9 32
      source/fb2text.hpp

+ 76 - 75
fb2edit.pro

@@ -1,75 +1,76 @@
-HEADERS = \
-    source/fb2xml.h \
-    source/fb2xml2.h \
-    source/fb2html.h \
-    source/fb2app.hpp \
-    source/fb2code.hpp \
-    source/fb2dlgs.hpp \
-    source/fb2dock.hpp \
-    source/fb2head.hpp \
-    source/fb2main.hpp \
-    source/fb2page.hpp \
-    source/fb2read.hpp \
-    source/fb2temp.hpp \
-    source/fb2tree.hpp \
-    source/fb2save.hpp \
-    source/fb2text.hpp \
-    source/fb2utils.h \
-    source/fb2enum.h
-
-SOURCES = \
-    source/fb2app.cpp \
-    source/fb2code.cpp \
-    source/fb2dlgs.cpp \
-    source/fb2dock.cpp \
-    source/fb2head.cpp \
-    source/fb2html.cpp \
-    source/fb2main.cpp \
-    source/fb2page.cpp \
-    source/fb2read.cpp \
-    source/fb2save.cpp \
-    source/fb2temp.cpp \
-    source/fb2tree.cpp \
-    source/fb2xml.cpp \
-    source/fb2xml2.cpp \
-    source/fb2text.cpp \
-    source/fb2utils.cpp
-
-RESOURCES = \
-    3rdparty/gnome/gnome.qrc \
-    source/res/fb2edit.qrc \
-    source/js/javascript.qrc \
-    3rdparty/fb2/fb2.qrc
-
-TARGET = fb2edit
-
-TRANSLATIONS = source/ts/ru.ts
-
-QT += xml
-QT += webkit
-QT += network
-
-OTHER_FILES += \
-    source/res/style.css \
-    source/res/blank.fb2 \
-    source/js/export.js \
-    source/js/set_cursor.js \
-    source/js/get_status.js \
-    source/js/insert_title.js \
-    CMakeLists.txt \
-    source/js/new_section1.js \
-    source/js/section_get.js \
-    source/js/section_new.js \
-    source/js/location.js
-
-if (unix) {
-
-    DEFINES += FB2_USE_LIBXML2
-    INCLUDEPATH += /usr/include/libxml2
-    LIBS += -lxml2
-
-}
-
-FORMS += \
-    source/fb2find.ui \
-    source/fb2setup.ui
+HEADERS = \
+    source/fb2xml.h \
+    source/fb2xml2.h \
+    source/fb2html.h \
+    source/fb2app.hpp \
+    source/fb2code.hpp \
+    source/fb2dlgs.hpp \
+    source/fb2dock.hpp \
+    source/fb2head.hpp \
+    source/fb2main.hpp \
+    source/fb2page.hpp \
+    source/fb2read.hpp \
+    source/fb2temp.hpp \
+    source/fb2tree.hpp \
+    source/fb2save.hpp \
+    source/fb2text.hpp \
+    source/fb2utils.h \
+    source/fb2mode.h
+
+SOURCES = \
+    source/fb2app.cpp \
+    source/fb2code.cpp \
+    source/fb2dlgs.cpp \
+    source/fb2dock.cpp \
+    source/fb2head.cpp \
+    source/fb2html.cpp \
+    source/fb2main.cpp \
+    source/fb2page.cpp \
+    source/fb2read.cpp \
+    source/fb2save.cpp \
+    source/fb2temp.cpp \
+    source/fb2tree.cpp \
+    source/fb2xml.cpp \
+    source/fb2xml2.cpp \
+    source/fb2text.cpp \
+    source/fb2utils.cpp \
+    source/fb2mode.cpp
+
+RESOURCES = \
+    3rdparty/gnome/gnome.qrc \
+    source/res/fb2edit.qrc \
+    source/js/javascript.qrc \
+    3rdparty/fb2/fb2.qrc
+
+TARGET = fb2edit
+
+TRANSLATIONS = source/ts/ru.ts
+
+QT += xml
+QT += webkit
+QT += network
+
+OTHER_FILES += \
+    source/res/style.css \
+    source/res/blank.fb2 \
+    source/js/export.js \
+    source/js/set_cursor.js \
+    source/js/get_status.js \
+    source/js/insert_title.js \
+    CMakeLists.txt \
+    source/js/new_section1.js \
+    source/js/section_get.js \
+    source/js/section_new.js \
+    source/js/location.js
+
+if (unix) {
+
+    DEFINES += FB2_USE_LIBXML2
+    INCLUDEPATH += /usr/include/libxml2
+    LIBS += -lxml2
+
+}
+
+FORMS += \
+    source/fb2find.ui \
+    source/fb2setup.ui

+ 8 - 0
source/fb2code.cpp

@@ -361,6 +361,14 @@ void FbCodeEdit::setAction(Fb::Actions index, QAction *action)
     m_actions[index] = action;
 }
 
+void FbCodeEdit::connectActions(QToolBar *tool)
+{
+}
+
+void FbCodeEdit::disconnectActions()
+{
+}
+
 bool FbCodeEdit::read(QIODevice *device)
 {
     QByteArray data = device->readAll();

+ 4 - 3
source/fb2code.hpp

@@ -9,8 +9,9 @@
 #include <QTextCharFormat>
 #include <QColor>
 #include <QTextEdit>
+#include <QToolBar>
 
-#include "fb2enum.h"
+#include "fb2mode.h"
 
 class FbHighlighter : public QSyntaxHighlighter
 {
@@ -84,7 +85,7 @@ public:
     FbCodeEdit(QWidget *parent = 0);
 
     void setAction(Fb::Actions index, QAction *action);
-    void connectActions();
+    void connectActions(QToolBar *tool);
     void disconnectActions();
 
     QString text() const { return toPlainText(); }
@@ -138,7 +139,7 @@ private:
 private:
     FbHighlighter * highlighter;
     QWidget *lineNumberArea;
-    QMap<Fb::Actions, QAction*> m_actions;
+    FbActionMap m_actions;
     qreal zoomRatio;
     static qreal baseFontSize;
     static qreal zoomRatioMin;

+ 42 - 7
source/fb2dock.cpp

@@ -36,27 +36,62 @@ FbMainDock::FbMainDock(QWidget *parent)
     m_text = new FbTextEdit(textFrame, parent);
     textFrame->layout()->addWidget(m_text);
 
-    m_head = new FbHeadEdit(this);
+    m_head = new FbHeadEdit(this, m_text);
+
     m_code = new FbCodeEdit(this);
 
     addWidget(textFrame);
     addWidget(m_head);
     addWidget(m_code);
-
-    m_head->setText(m_text);
 }
 
 void FbMainDock::setMode(Fb::Mode mode)
 {
     if (mode == m_mode) return;
     switch (m_mode = mode) {
-        case Fb::Text: setCurrentWidget(textFrame); break;
-        case Fb::Head: setCurrentWidget(m_head); break;
-        case Fb::Code: setCurrentWidget(m_code); break;
-        case Fb::Html: setCurrentWidget(m_code); break;
+        case Fb::Text: setModeText(); return;
+        case Fb::Head: setModeHead(); return;
+        case Fb::Code: setModeCode(); return;
+        case Fb::Html: setModeHtml(); return;
     }
 }
 
+void FbMainDock::setModeText()
+{
+    m_mode = Fb::Text;
+    setCurrentWidget(textFrame);
+    m_head->disconnectActions();
+    m_code->disconnectActions();
+    m_text->connectActions(m_tool);
+}
+
+void FbMainDock::setModeHead()
+{
+    m_mode = Fb::Head;
+    setCurrentWidget(m_head);
+    m_text->disconnectActions();
+    m_code->disconnectActions();
+    m_head->connectActions(m_tool);
+}
+
+void FbMainDock::setModeCode()
+{
+    m_mode = Fb::Code;
+    setCurrentWidget(m_code);
+    m_head->disconnectActions();
+    m_code->disconnectActions();
+    m_code->connectActions(m_tool);
+}
+
+void FbMainDock::setModeHtml()
+{
+    m_mode = Fb::Html;
+    setCurrentWidget(m_code);
+    m_head->disconnectActions();
+    m_code->disconnectActions();
+    m_code->connectActions(m_tool);
+}
+
 bool FbMainDock::load(const QString &filename)
 {
     QFile file(filename);

+ 21 - 17
source/fb2dock.hpp

@@ -7,28 +7,12 @@
 #include <QToolBar>
 #include <QIODevice>
 
-#include "fb2enum.h"
+#include "fb2mode.h"
 
 class FbTextEdit;
 class FbHeadEdit;
 class FbCodeEdit;
 
-class FbMainDock;
-
-class FbModeAction : public QAction
-{
-    Q_OBJECT
-public:
-    explicit FbModeAction(FbMainDock *parent, Fb::Mode mode, const QString &text);
-
-private slots:
-    void switchMode();
-
-private:
-    FbMainDock * m_dock;
-    Fb::Mode m_mode;
-};
-
 class FbMainDock : public QStackedWidget
 {
     Q_OBJECT
@@ -49,6 +33,12 @@ signals:
     
 public slots:
 
+private:
+    void setModeText();
+    void setModeHead();
+    void setModeCode();
+    void setModeHtml();
+
 private:
     QFrame *textFrame;
     FbTextEdit *m_text;
@@ -59,4 +49,18 @@ private:
     Fb::Mode m_mode;
 };
 
+class FbModeAction : public QAction
+{
+    Q_OBJECT
+public:
+    explicit FbModeAction(FbMainDock *parent, Fb::Mode mode, const QString &text);
+
+private slots:
+    void switchMode();
+
+private:
+    FbMainDock * m_dock;
+    Fb::Mode m_mode;
+};
+
 #endif // FB2DOCK_H

+ 12 - 3
source/fb2head.cpp

@@ -554,8 +554,9 @@ bool FbHeadModel::canEdit(const QModelIndex &index) const
 //  FbTreeView
 //---------------------------------------------------------------------------
 
-FbHeadEdit::FbHeadEdit(QWidget *parent)
+FbHeadEdit::FbHeadEdit(QWidget *parent, FbTextEdit *text)
     : QTreeView(parent)
+    , m_text(text)
 {
     QAction * act;
 
@@ -594,9 +595,17 @@ void FbHeadEdit::setAction(Fb::Actions index, QAction *action)
     m_actions[index] = action;
 }
 
-void FbHeadEdit::setText(FbTextEdit *text)
+void FbHeadEdit::connectActions(QToolBar *tool)
 {
-    connect(m_text = text, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
+}
+
+void FbHeadEdit::disconnectActions()
+{
+    foreach (QAction *action, m_actions) {
+        action->setDisabled(true);
+        action->setChecked(false);
+        disconnect(action);
+    }
 }
 
 FbHeadModel * FbHeadEdit::model() const

+ 5 - 6
source/fb2head.hpp

@@ -19,7 +19,7 @@ class QToolBar;
 class QLineEdit;
 QT_END_NAMESPACE
 
-#include "fb2enum.h"
+#include "fb2mode.h"
 #include "fb2xml.h"
 
 class FbTextEdit;
@@ -56,7 +56,7 @@ public:
 private:
     FbScheme typeScheme() const;
     FbScheme item(const QString &name) const;
-    QMap<Fb::Actions, QAction*> m_actions;
+    FbActionMap m_actions;
 };
 
 class FbHeadItem: public QObject
@@ -174,13 +174,12 @@ class FbHeadEdit : public QTreeView
     Q_OBJECT
 
 public:
-    explicit FbHeadEdit(QWidget *parent = 0);
-    void setText(FbTextEdit *text);
+    explicit FbHeadEdit(QWidget *parent, FbTextEdit *text);
     void initToolbar(QToolBar &toolbar);
     FbHeadModel * model() const;
 
     void setAction(Fb::Actions index, QAction *action);
-    void connectActions();
+    void connectActions(QToolBar *tool);
     void disconnectActions();
 
 signals:
@@ -207,7 +206,7 @@ private:
     QAction * actionInsert;
     QAction * actionModify;
     QAction * actionDelete;
-    QMap<Fb::Actions, QAction*> m_actions;
+    FbActionMap m_actions;
 };
 
 class FbNodeDlg : public QDialog

+ 11 - 9
source/fb2main.cpp

@@ -40,6 +40,7 @@ FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
     createStatusBar();
     readSettings();
 
+    mainDock->setMode(Fb::Text);
     setCurrentFile(filename);
     mainDock->load(filename);
 }
@@ -367,35 +368,35 @@ void FbMainWindow::createActions()
 
     menu = menuBar()->addMenu(tr("Fo&rmat"));
 
-    act = new FbTextAction(FbIcon("edit-clear"), tr("Clear format"), QWebPage::RemoveFormat, this);
+    act = new FbTextAction(FbIcon("edit-clear"), tr("Clear format"), QWebPage::RemoveFormat, text);
     text->setAction(Fb::ClearFormat, act);
     menu->addAction(act);
 
     menu->addSeparator();
 
-    act = new FbTextAction(FbIcon("format-text-bold"), tr("&Bold"), QWebPage::ToggleBold, this);
+    act = new FbTextAction(FbIcon("format-text-bold"), tr("&Bold"), QWebPage::ToggleBold, text);
     text->setAction(Fb::TextBold, act);
     act->setShortcuts(QKeySequence::Bold);
     act->setCheckable(true);
     menu->addAction(act);
 
-    act = new FbTextAction(FbIcon("format-text-italic"), tr("&Italic"), QWebPage::ToggleItalic, this);
+    act = new FbTextAction(FbIcon("format-text-italic"), tr("&Italic"), QWebPage::ToggleItalic, text);
     text->setAction(Fb::TextItalic, act);
     act->setShortcuts(QKeySequence::Italic);
     act->setCheckable(true);
     menu->addAction(act);
 
-    act = new FbTextAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), QWebPage::ToggleStrikethrough, this);
+    act = new FbTextAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), QWebPage::ToggleStrikethrough, text);
     text->setAction(Fb::TextStrike, act);
     act->setCheckable(true);
     menu->addAction(act);
 
-    act = new FbTextAction(FbIcon("format-text-superscript"), tr("Su&perscript"), QWebPage::ToggleSuperscript, this);
+    act = new FbTextAction(FbIcon("format-text-superscript"), tr("Su&perscript"), QWebPage::ToggleSuperscript, text);
     text->setAction(Fb::TextSup, act);
     act->setCheckable(true);
     menu->addAction(act);
 
-    act = new FbTextAction(FbIcon("format-text-subscript"), tr("Su&bscript"), QWebPage::ToggleSubscript, this);
+    act = new FbTextAction(FbIcon("format-text-subscript"), tr("Su&bscript"), QWebPage::ToggleSubscript, text);
     text->setAction(Fb::TextSub, act);
     act->setCheckable(true);
     menu->addAction(act);
@@ -407,15 +408,15 @@ void FbMainWindow::createActions()
 
     menu->addSeparator();
 
-    act = new FbTextAction(FbIcon("format-indent-more"), tr("Create section"), QWebPage::ToggleSubscript, this);
+    act = new FbTextAction(FbIcon("format-indent-more"), tr("Create section"), QWebPage::ToggleSubscript, text);
     text->setAction(Fb::SectionAdd, act);
     menu->addAction(act);
 
-    act = new FbTextAction(FbIcon("format-indent-less"), tr("Remove section"), QWebPage::ToggleSubscript, this);
+    act = new FbTextAction(FbIcon("format-indent-less"), tr("Remove section"), QWebPage::ToggleSubscript, text);
     text->setAction(Fb::SectionDel, act);
     menu->addAction(act);
 
-    act = new FbTextAction(FbIcon("format-justify-center"), tr("Make title"), QWebPage::ToggleSubscript, this);
+    act = new FbTextAction(FbIcon("format-justify-center"), tr("Make title"), QWebPage::ToggleSubscript, text);
     text->setAction(Fb::TextTitle, act);
     menu->addAction(act);
 
@@ -470,6 +471,7 @@ void FbMainWindow::createActions()
 
     act = new QAction(tr("&Contents"), this);
     text->setAction(Fb::ViewContents, act);
+    act->setCheckable(true);
     menu->addAction(act);
 
     act = new QAction(tr("&Pictures"), this);

+ 22 - 0
source/fb2mode.cpp

@@ -0,0 +1,22 @@
+#include "fb2mode.h"
+
+//---------------------------------------------------------------------------
+//  FbActionMap
+//---------------------------------------------------------------------------
+
+void FbActionMap::connect()
+{
+    foreach (QAction *action, *this) {
+        action->setEnabled(true);
+    }
+}
+
+void FbActionMap::disconnect()
+{
+    foreach (QAction *action, *this) {
+        action->setEnabled(false);
+        action->setChecked(false);
+        action->disconnect();
+    }
+}
+

+ 13 - 3
source/fb2enum.h → source/fb2mode.h

@@ -1,5 +1,8 @@
-#ifndef FB2ENUM_H
-#define FB2ENUM_H
+#ifndef FB2MODE_H
+#define FB2MODE_H
+
+#include <QAction>
+#include <QMap>
 
 namespace Fb {
 
@@ -59,4 +62,11 @@ enum Actions {
 
 }
 
-#endif // FB2ENUM_H
+class FbActionMap : public QMap<Fb::Actions, QAction*>
+{
+public:
+    void connect();
+    void disconnect();
+};
+
+#endif // FB2MODE_H

+ 2 - 2
source/fb2page.hpp

@@ -8,7 +8,7 @@
 class FbTextElement;
 class FbNetworkAccessManager;
 
-#include "fb2enum.h"
+#include "fb2mode.h"
 
 class FbTextLogger : public QObject
 {
@@ -81,7 +81,7 @@ private slots:
     void fixContents();
 
 private:
-    QMap<Fb::Actions, QAction*> m_actions;
+    FbActionMap m_actions;
     FbTextLogger m_logger;
     QString m_html;
 };

+ 82 - 88
source/fb2text.cpp

@@ -170,6 +170,7 @@ FbTextEdit::FbTextEdit(QWidget *parent, QObject *owner)
     , m_thread(0)
     , dockTree(0)
     , dockImgs(0)
+    , dockInsp(0)
 {
     setContextMenuPolicy(Qt::CustomContextMenu);
     connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint)));
@@ -203,9 +204,11 @@ void FbTextEdit::setAction(Fb::Actions index, QAction *action)
 
 void FbTextEdit::connectActions(QToolBar *tool)
 {
-    connect(act(Fb::ViewContents), SIGNAL(triggered()), this, SLOT(viewTree()));
-    connect(act(Fb::ViewPictures), SIGNAL(triggered()), this, SLOT(viewImgs()));
-    connect(act(Fb::ViewPictures), SIGNAL(triggered()), this, SLOT(viewInsp()));
+    m_actions.connect();
+
+    connect(act(Fb::ViewContents), SIGNAL(triggered(bool)), this, SLOT(viewTree(bool)));
+    connect(act(Fb::ViewPictures), SIGNAL(triggered(bool)), this, SLOT(viewImgs(bool)));
+    connect(act(Fb::ViewInspect), SIGNAL(triggered(bool)), this, SLOT(viewInsp(bool)));
 /*
     connect(textPage->undoStack(), SIGNAL(cleanChanged(bool)), SLOT(cleanChanged(bool)));
     connect(textPage->undoStack(), SIGNAL(canUndoChanged(bool)), SLOT(canUndoChanged(bool)));
@@ -262,46 +265,87 @@ void FbTextEdit::connectActions(QToolBar *tool)
     connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
     connect(actionZoomReset, SIGNAL(triggered()), textEdit, SLOT(zoomReset()));
 
+*/
+
     tool->clear();
 
     tool->addSeparator();
-    tool->addAction(actionSectionAdd);
-    tool->addAction(actionSectionDel);
-    tool->addAction(actionTextTitle);
+    tool->addAction(act(Fb::EditUndo));
+    tool->addAction(act(Fb::EditRedo));
 
     tool->addSeparator();
-    tool->addAction(actionImage);
-    tool->addAction(actionNote);
-    tool->addAction(actionLink);
-    tool->addAction(actionSection);
-*/
+    tool->addAction(act(Fb::EditCut));
+    tool->addAction(act(Fb::EditCopy));
+    tool->addAction(act(Fb::EditPaste));
+
+    tool->addSeparator();
+    tool->addAction(act(Fb::TextBold));
+    tool->addAction(act(Fb::TextItalic));
+    tool->addAction(act(Fb::TextStrike));
+    tool->addAction(act(Fb::TextSup));
+    tool->addAction(act(Fb::TextSub));
+
+    tool->addSeparator();
+    tool->addAction(act(Fb::SectionAdd));
+    tool->addAction(act(Fb::SectionDel));
+    tool->addAction(act(Fb::TextTitle));
+
+    tool->addSeparator();
+    tool->addAction(act(Fb::InsertImage));
+    tool->addAction(act(Fb::InsertNote));
+    tool->addAction(act(Fb::InsertLink));
+    tool->addAction(act(Fb::InsertSection));
 }
 
 void FbTextEdit::disconnectActions()
 {
-    foreach (QAction *action, m_actions) {
-        action->setDisabled(true);
-        action->setChecked(false);
-        disconnect(action);
+    m_actions.disconnect();
+}
+
+void FbTextEdit::viewTree(bool show)
+{
+    if (show) {
+        if (dockTree) { dockTree->show(); return; }
+        dockTree = new FbDockWidget(tr("Contents"), this);
+        dockTree->setWidget(new FbTreeWidget(this, m_owner));
+        connect(dockTree, SIGNAL(visibilityChanged(bool)), act(Fb::ViewContents), SLOT(setChecked(bool)));
+        connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
+        m_owner->addDockWidget(Qt::LeftDockWidgetArea, dockTree);
+    } else {
+        dockTree->deleteLater();
+        dockTree = 0;
     }
 }
 
-void FbTextEdit::createTree()
+void FbTextEdit::viewImgs(bool show)
 {
-    dockTree = new FbDockWidget(tr("Contents"), this);
-    dockTree->setWidget(new FbTreeWidget(this, m_owner));
-//    connect(dockTree, SIGNAL(visibilityChanged(bool)), actionContents, SLOT(setChecked(bool)));
-//    connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
-    m_owner->addDockWidget(Qt::LeftDockWidgetArea, dockTree);
+    if (show) {
+        if (dockImgs) { dockImgs->show(); return; }
+        dockImgs = new FbDockWidget(tr("Pictures"), this);
+        dockImgs->setWidget(new FbListWidget(this, m_owner));
+        connect(dockImgs, SIGNAL(visibilityChanged(bool)), act(Fb::ViewPictures), SLOT(setChecked(bool)));
+        connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed()));
+        m_owner->addDockWidget(Qt::RightDockWidgetArea, dockImgs);
+    } else {
+        dockImgs->deleteLater();
+        dockImgs = 0;
+    }
 }
 
-void FbTextEdit::createImgs()
+void FbTextEdit::viewInsp(bool show)
 {
-    dockImgs = new FbDockWidget(tr("Pictures"), this);
-    dockImgs->setWidget(new FbListWidget(this, m_owner));
-//    connect(dockImgs, SIGNAL(visibilityChanged(bool)), actionPictures, SLOT(setChecked(bool)));
-//    connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed()));
-    m_owner->addDockWidget(Qt::RightDockWidgetArea, dockImgs);
+    if (show) {
+        if (dockInsp) { dockInsp->show(); return; }
+        QWebInspector *inspector = new QWebInspector(this);
+        inspector->setPage(page());
+        dockInsp = new QDockWidget(tr("Web inspector"), this);
+        dockInsp->setFeatures(QDockWidget::AllDockWidgetFeatures);
+        dockInsp->setWidget(inspector);
+        connect(dockInsp, SIGNAL(visibilityChanged(bool)), act(Fb::ViewInspect), SLOT(setChecked(bool)));
+        m_owner->addDockWidget(Qt::BottomDockWidgetArea, dockInsp);
+    } else {
+        dockImgs->hide();
+    }
 }
 
 void FbTextEdit::treeDestroyed()
@@ -559,86 +603,36 @@ FbWebFrame::FbWebFrame(QWidget *parent)
     setLayout(layout);
 }
 
-//---------------------------------------------------------------------------
-//  FbTextFrame
-//---------------------------------------------------------------------------
-
-FbTextFrame::FbTextFrame(QWidget *parent, QAction *action)
-    : QFrame(parent)
-    , m_view(this, parent->parent())
-    , m_dock(0)
-{
-    setFrameShape(QFrame::StyledPanel);
-    setFrameShadow(QFrame::Sunken);
-
-    QLayout * layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
-    layout->setSpacing(0);
-    layout->setMargin(0);
-    layout->addWidget(&m_view);
-
-    connect(action, SIGNAL(triggered()), SLOT(showInspector()));
-}
-
-FbTextFrame::~FbTextFrame()
-{
-    if (m_dock) m_dock->deleteLater();
-}
-
-void FbTextFrame::showInspector()
-{
-    if (m_dock) {
-        m_dock->setVisible(m_dock->isHidden());
-        return;
-    }
-
-    QMainWindow *main = qobject_cast<QMainWindow*>(parent());
-    if (!main) return;
-
-    m_dock = new QDockWidget(tr("Web inspector"), this);
-    m_dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
-    main->addDockWidget(Qt::BottomDockWidgetArea, m_dock);
-
-    QWebInspector *inspector = new QWebInspector(this);
-    inspector->setPage(m_view.page());
-    m_dock->setWidget(inspector);
-
-    connect(m_dock, SIGNAL(visibilityChanged(bool)), main, SIGNAL(showInspectorChecked(bool)));
-    connect(m_dock, SIGNAL(destroyed()), SLOT(dockDestroyed()));
-}
-
-void FbTextFrame::hideInspector()
-{
-    if (m_dock) m_dock->hide();
-}
-
-void FbTextFrame::dockDestroyed()
-{
-    m_dock = 0;
-}
-
 //---------------------------------------------------------------------------
 //  FbTextAction
 //---------------------------------------------------------------------------
 
-FbTextAction::FbTextAction(const QString &text, QWebPage::WebAction action, QObject* parent)
+FbTextAction::FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit *parent)
     : QAction(text, parent)
     , m_action(action)
+    , m_parent(parent)
 {
 }
 
-FbTextAction::FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, QObject* parent)
+FbTextAction::FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit* parent)
     : QAction(icon, text, parent)
     , m_action(action)
+    , m_parent(parent)
+{
+}
+
+QAction * FbTextAction::action(QWebPage::WebAction action)
 {
+    return m_parent->pageAction(m_action);
 }
 
 void FbTextAction::updateChecked()
 {
-//    if (QAction * act = action(m_action)) setChecked(act->isChecked());
+    if (QAction * act = action(m_action)) setChecked(act->isChecked());
 }
 
 void FbTextAction::updateEnabled()
 {
-//    if (QAction * act = action(m_action)) setEnabled(act->isEnabled());
+    if (QAction * act = action(m_action)) setEnabled(act->isEnabled());
 }
 

+ 9 - 32
source/fb2text.hpp

@@ -11,7 +11,7 @@
 #include <QWebElement>
 #include <QWebView>
 
-#include "fb2enum.h"
+#include "fb2mode.h"
 #include "fb2temp.hpp"
 
 QT_BEGIN_NAMESPACE
@@ -110,15 +110,13 @@ public slots:
 private slots:
     void linkHovered(const QString &link, const QString &title, const QString &textContent);
     void contextMenu(const QPoint &pos);
-    void createImgs();
-    void createTree();
     void treeDestroyed();
     void imgsDestroyed();
+    void viewTree(bool show);
+    void viewImgs(bool show);
+    void viewInsp(bool show);
 
 private:
-    void viewTree();
-    void viewImgs();
-    void viewInsp();
     bool actionEnabled(QWebPage::WebAction action);
     bool actionChecked(QWebPage::WebAction action);
     void execCommand(const QString &cmd, const QString &arg);
@@ -131,9 +129,10 @@ private:
     QMainWindow *m_owner;
     FbNoteView *m_noteView;
     FbReadThread *m_thread;
-    QMap<Fb::Actions, QAction*> m_actions;
+    FbActionMap m_actions;
     QDockWidget *dockTree;
     QDockWidget *dockImgs;
+    QDockWidget *dockInsp;
     QPoint m_point;
 };
 
@@ -144,36 +143,13 @@ public:
     explicit FbWebFrame(QWidget *parent = 0);
 };
 
-class FbTextFrame : public QFrame
-{
-    Q_OBJECT
-
-public:
-    explicit FbTextFrame(QWidget *parent, QAction *action);
-    ~FbTextFrame();
-
-public:
-    FbTextEdit * view() { return &m_view; }
-
-public slots:
-    void showInspector();
-    void hideInspector();
-
-private slots:
-    void dockDestroyed();
-
-private:
-    FbTextEdit m_view;
-    QDockWidget *m_dock;
-};
-
 class FbTextAction : public QAction
 {
     Q_OBJECT
 
 public:
-    explicit FbTextAction(const QString &text, QWebPage::WebAction action, QObject* parent);
-    explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, QObject* parent);
+    explicit FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit* parent);
+    explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit *parent);
 
 public slots:
     void updateChecked();
@@ -184,6 +160,7 @@ private:
 
 private:
     QWebPage::WebAction m_action;
+    FbTextEdit *m_parent;
 };
 
 #endif // FB2TEXT_H