Browse Source

New file: fb2page.cpp

Kandrashin Denis 12 years ago
parent
commit
3c353995c7

+ 75 - 72
fb2edit.pro

@@ -1,72 +1,75 @@
-HEADERS = \
-    source/fb2xml.h \
-    source/fb2xml2.h \
-    source/fb2app.hpp \
-    source/fb2code.hpp \
-    source/fb2head.hpp \
-    source/fb2main.hpp \
-    source/fb2read.hpp \
-    source/fb2temp.hpp \
-    source/fb2tree.hpp \
-    source/fb2save.hpp \
-    source/fb2dlgs.hpp \
-    source/fb2html.h \
-    source/fb2text.hpp \
-    source/fb2utils.h \
-    source/fb2dock.hpp
-
-SOURCES = \
-    source/fb2app.cpp \
-    source/fb2code.cpp \
-    source/fb2head.cpp \
-    source/fb2main.cpp \
-    source/fb2read.cpp \
-    source/fb2save.cpp \
-    source/fb2temp.cpp \
-    source/fb2tree.cpp \
-    source/fb2xml.cpp \
-    source/fb2xml2.cpp \
-    source/fb2utils.cpp \
-    source/fb2dlgs.cpp \
-    source/fb2html.cpp \
-    source/fb2text.cpp \
-    source/fb2dock.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/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

+ 5 - 0
source/fb2code.cpp

@@ -356,6 +356,11 @@ FbCodeEdit::FbCodeEdit(QWidget *parent) : QPlainTextEdit(parent)
     highlightCurrentLine();
     highlightCurrentLine();
 }
 }
 
 
+void FbCodeEdit::setAction(Fb::Actions index, QAction *action)
+{
+    m_actions[index] = action;
+}
+
 bool FbCodeEdit::read(QIODevice *device)
 bool FbCodeEdit::read(QIODevice *device)
 {
 {
     QByteArray data = device->readAll();
     QByteArray data = device->readAll();

+ 7 - 1
source/fb2code.hpp

@@ -5,12 +5,13 @@
 #include <QList>
 #include <QList>
 #include <QPlainTextEdit>
 #include <QPlainTextEdit>
 #include <QObject>
 #include <QObject>
-
 #include <QSyntaxHighlighter>
 #include <QSyntaxHighlighter>
 #include <QTextCharFormat>
 #include <QTextCharFormat>
 #include <QColor>
 #include <QColor>
 #include <QTextEdit>
 #include <QTextEdit>
 
 
+#include "fb2enum.h"
+
 class FbHighlighter : public QSyntaxHighlighter
 class FbHighlighter : public QSyntaxHighlighter
 {
 {
 public:
 public:
@@ -82,6 +83,10 @@ class FbCodeEdit : public QPlainTextEdit
 public:
 public:
     FbCodeEdit(QWidget *parent = 0);
     FbCodeEdit(QWidget *parent = 0);
 
 
+    void setAction(Fb::Actions index, QAction *action);
+    void connectActions();
+    void disconnectActions();
+
     QString text() const { return toPlainText(); }
     QString text() const { return toPlainText(); }
 
 
     bool read(QIODevice *device);
     bool read(QIODevice *device);
@@ -133,6 +138,7 @@ private:
 private:
 private:
     FbHighlighter * highlighter;
     FbHighlighter * highlighter;
     QWidget *lineNumberArea;
     QWidget *lineNumberArea;
+    QMap<Fb::Actions, QAction*> m_actions;
     qreal zoomRatio;
     qreal zoomRatio;
     static qreal baseFontSize;
     static qreal baseFontSize;
     static qreal zoomRatioMin;
     static qreal zoomRatioMin;

+ 1 - 0
source/fb2dlgs.cpp

@@ -1,5 +1,6 @@
 #include "fb2dlgs.hpp"
 #include "fb2dlgs.hpp"
 #include "fb2code.hpp"
 #include "fb2code.hpp"
+#include "fb2page.hpp"
 #include "fb2text.hpp"
 #include "fb2text.hpp"
 #include "fb2tree.hpp"
 #include "fb2tree.hpp"
 #include "fb2utils.h"
 #include "fb2utils.h"

+ 8 - 20
source/fb2dock.cpp

@@ -4,13 +4,18 @@
 #include "fb2text.hpp"
 #include "fb2text.hpp"
 
 
 #include <QLayout>
 #include <QLayout>
+#include <QtDebug>
+
+//---------------------------------------------------------------------------
+//  FbMainDock
+//---------------------------------------------------------------------------
 
 
 FbMainDock::FbMainDock(QWidget *parent)
 FbMainDock::FbMainDock(QWidget *parent)
     : QStackedWidget(parent)
     : QStackedWidget(parent)
     , isSwitched(false)
     , isSwitched(false)
 {
 {
     textFrame = new FbWebFrame(this);
     textFrame = new FbWebFrame(this);
-    m_text = new FbTextEdit(textFrame);
+    m_text = new FbTextEdit(textFrame, parent);
     textFrame->layout()->addWidget(m_text);
     textFrame->layout()->addWidget(m_text);
 
 
     m_head = new FbHeadEdit(this);
     m_head = new FbHeadEdit(this);
@@ -23,23 +28,6 @@ FbMainDock::FbMainDock(QWidget *parent)
     m_head->setText(m_text);
     m_head->setText(m_text);
 }
 }
 
 
-void FbMainDock::createActions()
-{
-    QAction * act;
-
-    actionUndo = act = new QAction(FbIcon("edit-undo"), tr("&Undo"), this);
-    act->setPriority(QAction::LowPriority);
-    act->setShortcut(QKeySequence::Undo);
-    act->setEnabled(false);
-    menu->addAction(act);
-
-    actionRedo = act = new QAction(FbIcon("edit-redo"), tr("&Redo"), this);
-    act->setPriority(QAction::LowPriority);
-    act->setShortcut(QKeySequence::Redo);
-    act->setEnabled(false);
-    menu->addAction(act);
-}
-
 FbMainDock::Mode FbMainDock::mode() const
 FbMainDock::Mode FbMainDock::mode() const
 {
 {
     QWidget * current = currentWidget();
     QWidget * current = currentWidget();
@@ -66,7 +54,7 @@ bool FbMainDock::load(const QString &filename)
         return false;
         return false;
     }
     }
 
 
-    if (mode == Code) {
+    if (currentWidget() == m_code) {
         m_code->clear();
         m_code->clear();
         return m_code->read(&file);
         return m_code->read(&file);
     }
     }
@@ -74,7 +62,7 @@ bool FbMainDock::load(const QString &filename)
     return false;
     return false;
 }
 }
 
 
-bool FbMainDock::save(QIODevice *device)
+bool FbMainDock::save(QIODevice *device, const QString &codec)
 {
 {
     if (currentWidget() == m_code) {
     if (currentWidget() == m_code) {
         QTextStream out(device);
         QTextStream out(device);

+ 6 - 5
source/fb2dock.hpp

@@ -1,7 +1,10 @@
 #ifndef FB2DOCK_H
 #ifndef FB2DOCK_H
 #define FB2DOCK_H
 #define FB2DOCK_H
 
 
+#include <QAction>
+#include <QIcon>
 #include <QStackedWidget>
 #include <QStackedWidget>
+#include <QToolBar>
 #include <QIODevice>
 #include <QIODevice>
 
 
 class FbTextEdit;
 class FbTextEdit;
@@ -19,23 +22,21 @@ public:
     FbHeadEdit * head() { return m_head; }
     FbHeadEdit * head() { return m_head; }
     FbCodeEdit * code() { return m_code; }
     FbCodeEdit * code() { return m_code; }
     bool load(const QString &filename);
     bool load(const QString &filename);
-    bool save(QIODevice *device);
+    bool save(QIODevice *device, const QString &codec = QString());
     Mode mode() const;
     Mode mode() const;
     void setMode(Mode mode);
     void setMode(Mode mode);
+    void setTool(QToolBar *tool) { m_tool = tool; }
 
 
 signals:
 signals:
     
     
 public slots:
 public slots:
 
 
-private slots:
-    void createImgs();
-    void createTree();
-
 private:
 private:
     QFrame *textFrame;
     QFrame *textFrame;
     FbTextEdit *m_text;
     FbTextEdit *m_text;
     FbHeadEdit *m_head;
     FbHeadEdit *m_head;
     FbCodeEdit *m_code;
     FbCodeEdit *m_code;
+    QToolBar *m_tool;
     bool isSwitched;
     bool isSwitched;
 };
 };
 
 

+ 55 - 0
source/fb2enum.h

@@ -0,0 +1,55 @@
+#ifndef FB2ENUM_H
+#define FB2ENUM_H
+
+namespace Fb {
+
+enum Actions {
+    GoBack,
+    GoForward,
+    EditUndo,
+    EditRedo,
+    EditCut,
+    EditCopy,
+    EditPaste,
+    PasteText,
+    TextSelect,
+    TextFind,
+    TextReplace,
+    InsertImage,
+    InsertNote,
+    InsertLink,
+    InsertBody,
+    InsertTitle,
+    InsertEpigraph,
+    InsertSubtitle,
+    InsertAnnot,
+    InsertCite,
+    InsertPoem,
+    InsertDate,
+    InsertStanza,
+    InsertAuthor,
+    InsertSection,
+    InsertText,
+    InsertParag,
+    InsertLine,
+    ClearFormat,
+    TextBold,
+    TextItalic,
+    TextStrike,
+    TextSub,
+    TextSup,
+    TextCode,
+    TextTitle,
+    SectionAdd,
+    SectionDel,
+    ViewContents,
+    ViewPictures,
+    ViewInspect,
+    ZoomIn,
+    ZoomOut,
+    ZoomReset,
+};
+
+}
+
+#endif // FB2ENUM_H

+ 7 - 2
source/fb2head.cpp

@@ -23,7 +23,7 @@
 //  FbScheme::Fb
 //  FbScheme::Fb
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
 
-FbScheme::Fb::Fb()
+FbScheme::FbDom::FbDom()
 {
 {
     QFile file(":/fb2/FictionBook2.1.xsd");
     QFile file(":/fb2/FictionBook2.1.xsd");
     if (file.open(QIODevice::ReadOnly)) setContent(&file);
     if (file.open(QIODevice::ReadOnly)) setContent(&file);
@@ -35,7 +35,7 @@ FbScheme::Fb::Fb()
 
 
 const QDomDocument & FbScheme::fb2()
 const QDomDocument & FbScheme::fb2()
 {
 {
-    static const Fb doc;
+    static const FbDom doc;
     return doc;
     return doc;
 }
 }
 
 
@@ -589,6 +589,11 @@ FbHeadEdit::FbHeadEdit(QWidget *parent)
     header()->setDefaultSectionSize(200);
     header()->setDefaultSectionSize(200);
 }
 }
 
 
+void FbHeadEdit::setAction(Fb::Actions index, QAction *action)
+{
+    m_actions[index] = action;
+}
+
 void FbHeadEdit::setText(FbTextEdit *text)
 void FbHeadEdit::setText(FbTextEdit *text)
 {
 {
     connect(m_text = text, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
     connect(m_text = text, SIGNAL(loadFinished(bool)), SLOT(updateTree()));

+ 12 - 1
source/fb2head.hpp

@@ -19,6 +19,7 @@ class QToolBar;
 class QLineEdit;
 class QLineEdit;
 QT_END_NAMESPACE
 QT_END_NAMESPACE
 
 
+#include "fb2enum.h"
 #include "fb2xml.h"
 #include "fb2xml.h"
 
 
 class FbTextEdit;
 class FbTextEdit;
@@ -33,7 +34,7 @@ class FbScheme : public QDomElement
     FB2_END_KEYLIST
     FB2_END_KEYLIST
 
 
 private:
 private:
-    class Fb : public QDomDocument { public: Fb(); };
+    class FbDom : public QDomDocument { public: FbDom(); };
 
 
 public:
 public:
     FbScheme() {}
     FbScheme() {}
@@ -41,6 +42,10 @@ public:
     FbScheme(const QDomElement &x) : QDomElement(x) {}
     FbScheme(const QDomElement &x) : QDomElement(x) {}
     FbScheme& operator=(const FbScheme &x) { QDomElement::operator=(x); return *this; }
     FbScheme& operator=(const FbScheme &x) { QDomElement::operator=(x); return *this; }
 
 
+    void setAction(Fb::Actions index, QAction *action);
+    void connectActions();
+    void disconnectActions();
+
     static const QDomDocument & fb2();
     static const QDomDocument & fb2();
     FbScheme element(const QString &name) const;
     FbScheme element(const QString &name) const;
     void items(QStringList &list) const;
     void items(QStringList &list) const;
@@ -51,6 +56,7 @@ public:
 private:
 private:
     FbScheme typeScheme() const;
     FbScheme typeScheme() const;
     FbScheme item(const QString &name) const;
     FbScheme item(const QString &name) const;
+    QMap<Fb::Actions, QAction*> m_actions;
 };
 };
 
 
 class FbHeadItem: public QObject
 class FbHeadItem: public QObject
@@ -173,6 +179,10 @@ public:
     void initToolbar(QToolBar &toolbar);
     void initToolbar(QToolBar &toolbar);
     FbHeadModel * model() const;
     FbHeadModel * model() const;
 
 
+    void setAction(Fb::Actions index, QAction *action);
+    void connectActions();
+    void disconnectActions();
+
 signals:
 signals:
     void status(const QString &text);
     void status(const QString &text);
 
 
@@ -197,6 +207,7 @@ private:
     QAction * actionInsert;
     QAction * actionInsert;
     QAction * actionModify;
     QAction * actionModify;
     QAction * actionDelete;
     QAction * actionDelete;
+    QMap<Fb::Actions, QAction*> m_actions;
 };
 };
 
 
 class FbNodeDlg : public QDialog
 class FbNodeDlg : public QDialog

+ 107 - 207
source/fb2main.cpp

@@ -8,24 +8,12 @@
 #include "fb2code.hpp"
 #include "fb2code.hpp"
 #include "fb2dlgs.hpp"
 #include "fb2dlgs.hpp"
 #include "fb2dock.hpp"
 #include "fb2dock.hpp"
+#include "fb2page.hpp"
 #include "fb2read.hpp"
 #include "fb2read.hpp"
 #include "fb2save.hpp"
 #include "fb2save.hpp"
 #include "fb2text.hpp"
 #include "fb2text.hpp"
-#include "fb2tree.hpp"
-#include "fb2head.hpp"
 #include "fb2utils.h"
 #include "fb2utils.h"
 
 
-//---------------------------------------------------------------------------
-//  FbDockWidget
-//---------------------------------------------------------------------------
-
-FbDockWidget::FbDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
-    : QDockWidget(title, parent, flags)
-{
-    setFeatures(QDockWidget::AllDockWidgetFeatures);
-    setAttribute(Qt::WA_DeleteOnClose);
-}
-
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 //  FbTextAction
 //  FbTextAction
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -49,8 +37,6 @@ FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
     : QMainWindow()
     : QMainWindow()
     , noteEdit(0)
     , noteEdit(0)
     , toolEdit(0)
     , toolEdit(0)
-    , dockTree(0)
-    , dockImgs(0)
     , inspector(0)
     , inspector(0)
     , messageEdit(0)
     , messageEdit(0)
     , isSwitched(false)
     , isSwitched(false)
@@ -105,18 +91,6 @@ void FbMainWindow::logDestroyed()
     messageEdit = NULL;
     messageEdit = NULL;
 }
 }
 
 
-void FbMainWindow::treeDestroyed()
-{
-    actionContents->setChecked(false);
-    dockTree = NULL;
-}
-
-void FbMainWindow::imgsDestroyed()
-{
-    actionPictures->setChecked(false);
-    dockImgs = NULL;
-}
-
 void FbMainWindow::closeEvent(QCloseEvent *event)
 void FbMainWindow::closeEvent(QCloseEvent *event)
 {
 {
     if (maybeSave()) {
     if (maybeSave()) {
@@ -208,7 +182,10 @@ void FbMainWindow::createActions()
     QAction * act;
     QAction * act;
     QMenu * menu;
     QMenu * menu;
     QToolBar * tool;
     QToolBar * tool;
-    QList<QAction*> actions;
+
+    FbTextEdit *text = mainDock->text();
+    FbHeadEdit *head = mainDock->head();
+    FbCodeEdit *code = mainDock->code();
 
 
     menu = menuBar()->addMenu(tr("&File"));
     menu = menuBar()->addMenu(tr("&File"));
     tool = addToolBar(tr("File"));
     tool = addToolBar(tr("File"));
@@ -256,17 +233,26 @@ void FbMainWindow::createActions()
     connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
     connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
     menu->addAction(act);
     menu->addAction(act);
 
 
-    menuEdit = menu = menuBar()->addMenu(tr("&Edit"));
+    menu = menuBar()->addMenu(tr("&Edit"));
+
+    tool = addToolBar(tr("Edit"));
+    tool->setMovable(false);
+    tool->addSeparator();
+    mainDock->setTool(tool);
 
 
     connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
     connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
 
 
-    actionUndo = act = new QAction(FbIcon("edit-undo"), tr("&Undo"), this);
+    act = new QAction(FbIcon("edit-undo"), tr("&Undo"), this);
+    text->setAction(Fb::EditUndo, act);
+    code->setAction(Fb::EditUndo, act);
     act->setPriority(QAction::LowPriority);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Undo);
     act->setShortcut(QKeySequence::Undo);
     act->setEnabled(false);
     act->setEnabled(false);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionRedo = act = new QAction(FbIcon("edit-redo"), tr("&Redo"), this);
+    act = new QAction(FbIcon("edit-redo"), tr("&Redo"), this);
+    text->setAction(Fb::EditRedo, act);
+    code->setAction(Fb::EditUndo, act);
     act->setPriority(QAction::LowPriority);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Redo);
     act->setShortcut(QKeySequence::Redo);
     act->setEnabled(false);
     act->setEnabled(false);
@@ -274,7 +260,9 @@ void FbMainWindow::createActions()
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionCut = act = new QAction(FbIcon("edit-cut"), tr("Cu&t"), this);
+    act = new QAction(FbIcon("edit-cut"), tr("Cu&t"), this);
+    text->setAction(Fb::EditCut, act);
+    code->setAction(Fb::EditCut, act);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Cut);
     act->setShortcuts(QKeySequence::Cut);
@@ -282,7 +270,9 @@ void FbMainWindow::createActions()
     act->setEnabled(false);
     act->setEnabled(false);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionCopy = act = new QAction(FbIcon("edit-copy"), tr("&Copy"), this);
+    act = new QAction(FbIcon("edit-copy"), tr("&Copy"), this);
+    text->setAction(Fb::EditCopy, act);
+    code->setAction(Fb::EditCopy, act);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Copy);
     act->setShortcuts(QKeySequence::Copy);
@@ -290,25 +280,32 @@ void FbMainWindow::createActions()
     act->setEnabled(false);
     act->setEnabled(false);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionPaste = act = new QAction(FbIcon("edit-paste"), tr("&Paste"), this);
+    act = new QAction(FbIcon("edit-paste"), tr("&Paste"), this);
+    text->setAction(Fb::EditPaste, act);
+    code->setAction(Fb::EditPaste, act);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Paste);
     act->setShortcuts(QKeySequence::Paste);
     act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
     act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionPasteText = act = new QAction(tr("Paste (no style)"), this);
+    act = new QAction(tr("Paste (no style)"), this);
+    text->setAction(Fb::PasteText, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
     clipboardDataChanged();
     clipboardDataChanged();
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionFind = act = new QAction(FbIcon("edit-find"), tr("&Find..."), this);
+    act = new QAction(FbIcon("edit-find"), tr("&Find..."), this);
+    text->setAction(Fb::TextFind, act);
+    code->setAction(Fb::TextFind, act);
     act->setShortcuts(QKeySequence::Find);
     act->setShortcuts(QKeySequence::Find);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionReplace = act = new QAction(FbIcon("edit-find-replace"), tr("&Replace..."), this);
+    act = new QAction(FbIcon("edit-find-replace"), tr("&Replace..."), this);
+    text->setAction(Fb::TextReplace, act);
+    code->setAction(Fb::TextReplace, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
     menu->addSeparator();
     menu->addSeparator();
@@ -321,106 +318,133 @@ void FbMainWindow::createActions()
 
 
     menu = menuBar()->addMenu(tr("&Insert", "Main menu"));
     menu = menuBar()->addMenu(tr("&Insert", "Main menu"));
 
 
-    actionImage = act = new QAction(FbIcon("insert-image"), tr("&Image"), this);
+    act = new QAction(FbIcon("insert-image"), tr("&Image"), this);
+    text->setAction(Fb::InsertImage, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionNote = act = new QAction(FbIcon("insert-text"), tr("&Footnote"), this);
+    act = new QAction(FbIcon("insert-text"), tr("&Footnote"), this);
+    text->setAction(Fb::InsertNote, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionLink = act = new QAction(FbIcon("insert-link"), tr("&Hiperlink"), this);
+    act = new QAction(FbIcon("insert-link"), tr("&Hiperlink"), this);
+    text->setAction(Fb::InsertLink, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionBody = act = new QAction(tr("&Body"), this);
+    act = new QAction(tr("&Body"), this);
+    text->setAction(Fb::InsertBody, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionSection = act = new QAction(FbIcon("insert-object"), tr("&Section"), this);
+    act = new QAction(FbIcon("insert-object"), tr("&Section"), this);
+    text->setAction(Fb::InsertSection, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionTitle = act = new QAction(tr("&Title"), this);
+    act = new QAction(tr("&Title"), this);
+    text->setAction(Fb::InsertTitle, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionEpigraph = act = new QAction(tr("&Epigraph"), this);
+    act = new QAction(tr("&Epigraph"), this);
+    text->setAction(Fb::InsertEpigraph, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionAnnot = act = new QAction(tr("&Annotation"), this);
+    act = new QAction(tr("&Annotation"), this);
+    text->setAction(Fb::InsertAnnot, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionSubtitle = act = new QAction(tr("&Subtitle"), this);
+    act = new QAction(tr("&Subtitle"), this);
+    text->setAction(Fb::InsertSubtitle, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionAuthor = act = new QAction(tr("&Cite"), this);
+    act = new QAction(tr("&Cite"), this);
+    text->setAction(Fb::InsertCite, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionPoem = act = new QAction(tr("&Poem"), this);
+    act = new QAction(tr("&Poem"), this);
+    text->setAction(Fb::InsertPoem, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionStanza = act = new QAction(tr("&Stanza"), this);
+    act = new QAction(tr("&Stanza"), this);
+    text->setAction(Fb::InsertStanza, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionAuthor = act = new QAction(tr("&Author"), this);
+    act = new QAction(tr("&Author"), this);
+    text->setAction(Fb::InsertAuthor, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionDate = act = new QAction(tr("&Date"), this);
+    act = new QAction(tr("&Date"), this);
+    text->setAction(Fb::InsertDate, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionSimpleText = act = new QAction(tr("Simple text"), this);
+    act = new QAction(tr("Simple text"), this);
+    text->setAction(Fb::InsertText, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionParaSeparator = act = new QAction(tr("Paragraph"), this);
+    act = new QAction(tr("Paragraph"), this);
+    text->setAction(Fb::InsertParag, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionLineSeparator = act = new QAction(tr("Line end"), this);
+    act = new QAction(tr("Line end"), this);
+    text->setAction(Fb::InsertLine, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    menuText = menu = menuBar()->addMenu(tr("Fo&rmat"));
+    menu = menuBar()->addMenu(tr("Fo&rmat"));
 
 
-    actionClearFormat = act = new FbTextAction(FbIcon("edit-clear"), tr("Clear format"), QWebPage::RemoveFormat, this);
+    act = new FbTextAction(FbIcon("edit-clear"), tr("Clear format"), QWebPage::RemoveFormat, this);
+    text->setAction(Fb::ClearFormat, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionTextBold = act = new FbTextAction(FbIcon("format-text-bold"), tr("&Bold"), QWebPage::ToggleBold, this);
+    act = new FbTextAction(FbIcon("format-text-bold"), tr("&Bold"), QWebPage::ToggleBold, this);
+    text->setAction(Fb::TextBold, act);
     act->setShortcuts(QKeySequence::Bold);
     act->setShortcuts(QKeySequence::Bold);
     act->setCheckable(true);
     act->setCheckable(true);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionTextItalic = act = new FbTextAction(FbIcon("format-text-italic"), tr("&Italic"), QWebPage::ToggleItalic, this);
+    act = new FbTextAction(FbIcon("format-text-italic"), tr("&Italic"), QWebPage::ToggleItalic, this);
+    text->setAction(Fb::TextItalic, act);
     act->setShortcuts(QKeySequence::Italic);
     act->setShortcuts(QKeySequence::Italic);
     act->setCheckable(true);
     act->setCheckable(true);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionTextStrike = act = new FbTextAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), QWebPage::ToggleStrikethrough, this);
+    act = new FbTextAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), QWebPage::ToggleStrikethrough, this);
+    text->setAction(Fb::TextStrike, act);
     act->setCheckable(true);
     act->setCheckable(true);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionTextSup = 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, this);
+    text->setAction(Fb::TextSup, act);
     act->setCheckable(true);
     act->setCheckable(true);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionTextSub = 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, this);
+    text->setAction(Fb::TextSub, act);
     act->setCheckable(true);
     act->setCheckable(true);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionTextCode = act = new QAction(FbIcon("utilities-terminal"), tr("&Code"), this);
+    act = new QAction(FbIcon("utilities-terminal"), tr("&Code"), this);
+    text->setAction(Fb::TextCode, act);
     act->setCheckable(true);
     act->setCheckable(true);
     menu->addAction(act);
     menu->addAction(act);
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionSectionAdd = 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, this);
+    text->setAction(Fb::SectionAdd, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionSectionDel = 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, this);
+    text->setAction(Fb::SectionDel, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionTextTitle = 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, this);
+    text->setAction(Fb::TextTitle, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    menuView = menu = menuBar()->addMenu(tr("&View"));
+    menu = menuBar()->addMenu(tr("&View"));
 
 
     tool->addSeparator();
     tool->addSeparator();
 
 
@@ -458,32 +482,37 @@ void FbMainWindow::createActions()
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionZoomIn = act = new QAction(FbIcon("zoom-in"), tr("Zoom in"), this);
+    act = new QAction(FbIcon("zoom-in"), tr("Zoom in"), this);
+    text->setAction(Fb::ZoomIn, act);
+    code->setAction(Fb::ZoomIn, act);
     act->setShortcuts(QKeySequence::ZoomIn);
     act->setShortcuts(QKeySequence::ZoomIn);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionZoomOut = act = new QAction(FbIcon("zoom-out"), tr("Zoom out"), this);
+    act = new QAction(FbIcon("zoom-out"), tr("Zoom out"), this);
+    text->setAction(Fb::ZoomOut, act);
+    code->setAction(Fb::ZoomOut, act);
     act->setShortcuts(QKeySequence::ZoomOut);
     act->setShortcuts(QKeySequence::ZoomOut);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionZoomReset = act = new QAction(FbIcon("zoom-original"), tr("Zoom original"), this);
+    act = new QAction(FbIcon("zoom-original"), tr("Zoom original"), this);
+    text->setAction(Fb::ZoomReset, act);
+    code->setAction(Fb::ZoomReset, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    actionContents = act = new QAction(tr("&Contents"), this);
-    act->setCheckable(true);
-    connect(act, SIGNAL(triggered()), this, SLOT(viewTree()));
+    act = new QAction(tr("&Contents"), this);
+    text->setAction(Fb::ViewContents, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionPictures = act = new QAction(tr("&Pictures"), this);
+    act = new QAction(tr("&Pictures"), this);
+    text->setAction(Fb::ViewPictures, act);
     act->setCheckable(true);
     act->setCheckable(true);
-    connect(act, SIGNAL(triggered()), this, SLOT(viewImgs()));
     menu->addAction(act);
     menu->addAction(act);
 
 
-    actionInspect = act = new QAction(tr("&Web inspector"), this);
+    act = new QAction(tr("&Web inspector"), this);
+    text->setAction(Fb::ViewInspect, act);
     act->setCheckable(true);
     act->setCheckable(true);
-    connect(this, SIGNAL(showInspectorChecked(bool)), actionInspect, SLOT(setChecked(bool)));
     menu->addAction(act);
     menu->addAction(act);
 
 
     menuBar()->addSeparator();
     menuBar()->addSeparator();
@@ -506,54 +535,6 @@ void FbMainWindow::openSettings()
     dlg.exec();
     dlg.exec();
 }
 }
 
 
-void FbMainWindow::createTree()
-{
-    if (mainDock->mode() != FbMainDock::Text) return;
-    dockTree = new FbDockWidget(tr("Contents"), this);
-    dockTree->setWidget(new FbTreeWidget(mainDock->text(), this));
-    connect(dockTree, SIGNAL(visibilityChanged(bool)), actionContents, SLOT(setChecked(bool)));
-    connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
-    addDockWidget(Qt::LeftDockWidgetArea, dockTree);
-}
-
-void FbMainWindow::createImgs()
-{
-    if (mainDock->mode() != FbMainDock::Text) return;
-    dockImgs = new FbDockWidget(tr("Pictures"), this);
-    dockImgs->setWidget(new FbListWidget(mainDock->text(), this));
-    connect(dockImgs, SIGNAL(visibilityChanged(bool)), actionPictures, SLOT(setChecked(bool)));
-    connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed()));
-    addDockWidget(Qt::RightDockWidgetArea, dockImgs);
-}
-
-void FbMainWindow::selectionChanged()
-{
-    FbTextEdit *view = mainDock->text();
-    actionCut->setEnabled(view->actionEnabled(QWebPage::Cut));
-    actionCopy->setEnabled(view->actionEnabled(QWebPage::Copy));
-    statusBar()->showMessage(view->page()->status());
-}
-
-void FbMainWindow::canUndoChanged(bool canUndo)
-{
-    actionUndo->setEnabled(canUndo);
-}
-
-void FbMainWindow::canRedoChanged(bool canRedo)
-{
-    actionRedo->setEnabled(canRedo);
-}
-
-void FbMainWindow::undoChanged()
-{
-    actionUndo->setEnabled(mainDock->text()->actionEnabled(QWebPage::Undo));
-}
-
-void FbMainWindow::redoChanged()
-{
-    actionRedo->setEnabled(mainDock->text()->actionEnabled(QWebPage::Redo));
-}
-
 void FbMainWindow::createStatusBar()
 void FbMainWindow::createStatusBar()
 {
 {
     statusBar()->showMessage(tr("Ready"));
     statusBar()->showMessage(tr("Ready"));
@@ -634,93 +615,12 @@ FbMainWindow *FbMainWindow::findFbMainWindow(const QString &fileName)
     }
     }
     return 0;
     return 0;
 }
 }
-
+/*
 void FbMainWindow::checkScintillaUndo()
 void FbMainWindow::checkScintillaUndo()
 {
 {
-/*
     if (!codeEdit) return;
     if (!codeEdit) return;
     actionUndo->setEnabled(codeEdit->isUndoAvailable());
     actionUndo->setEnabled(codeEdit->isUndoAvailable());
     actionRedo->setEnabled(codeEdit->isRedoAvailable());
     actionRedo->setEnabled(codeEdit->isRedoAvailable());
-*/
-}
-
-void FbMainWindow::createTextToolbar()
-{
-    FbTextEdit * textEdit = mainDock->text();
-    FbTextPage * textPage = textEdit->page();
-
-    connect(textPage->undoStack(), SIGNAL(cleanChanged(bool)), SLOT(cleanChanged(bool)));
-    connect(textPage->undoStack(), SIGNAL(canUndoChanged(bool)), SLOT(canUndoChanged(bool)));
-    connect(textPage->undoStack(), SIGNAL(canRedoChanged(bool)), SLOT(canRedoChanged(bool)));
-    connect(textPage, SIGNAL(selectionChanged()), SLOT(selectionChanged()));
-
-    connect(actionUndo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Undo), SIGNAL(triggered()));
-    connect(actionRedo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Redo), SIGNAL(triggered()));
-
-    connect(actionCut, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Cut), SIGNAL(triggered()));
-    connect(actionCopy, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Copy), SIGNAL(triggered()));
-    connect(actionPaste, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Paste), SIGNAL(triggered()));
-    connect(actionPasteText, SIGNAL(triggered()), textEdit->pageAction(QWebPage::PasteAndMatchStyle), SIGNAL(triggered()));
-
-    connect(actionClearFormat, SIGNAL(triggered()), textEdit->pageAction(QWebPage::RemoveFormat), SIGNAL(triggered()));
-    connect(actionTextBold, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleBold), SIGNAL(triggered()));
-    connect(actionTextItalic, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleItalic), SIGNAL(triggered()));
-    connect(actionTextStrike, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleStrikethrough), SIGNAL(triggered()));
-    connect(actionTextSub, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleSubscript), SIGNAL(triggered()));
-    connect(actionTextSup, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleSuperscript), SIGNAL(triggered()));
-
-    connect(textEdit->pageAction(QWebPage::RemoveFormat), SIGNAL(changed()), actionClearFormat, SLOT(updateEnabled()));
-    connect(textEdit->pageAction(QWebPage::ToggleBold), SIGNAL(changed()), actionTextBold, SLOT(updateChecked()));
-    connect(textEdit->pageAction(QWebPage::ToggleItalic), SIGNAL(changed()), actionTextItalic, SLOT(updateChecked()));
-    connect(textEdit->pageAction(QWebPage::ToggleStrikethrough), SIGNAL(changed()), actionTextStrike, SLOT(updateChecked()));
-    connect(textEdit->pageAction(QWebPage::ToggleSubscript), SIGNAL(changed()), actionTextSub, SLOT(updateChecked()));
-    connect(textEdit->pageAction(QWebPage::ToggleSuperscript), SIGNAL(changed()), actionTextSup, SLOT(updateChecked()));
-
-    connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(find()));
-    connect(actionImage, SIGNAL(triggered()), textEdit, SLOT(insertImage()));
-    connect(actionNote, SIGNAL(triggered()), textEdit, SLOT(insertNote()));
-    connect(actionLink, SIGNAL(triggered()), textEdit, SLOT(insertLink()));
-
-    connect(actionTitle, SIGNAL(triggered()), textPage, SLOT(insertTitle()));
-    connect(actionAnnot, SIGNAL(triggered()), textPage, SLOT(insertAnnot()));
-    connect(actionAuthor, SIGNAL(triggered()), textPage, SLOT(insertAuthor()));
-    connect(actionEpigraph, SIGNAL(triggered()), textPage, SLOT(insertEpigraph()));
-    connect(actionSubtitle, SIGNAL(triggered()), textPage, SLOT(insertSubtitle()));
-    connect(actionSection, SIGNAL(triggered()), textPage, SLOT(insertSection()));
-    connect(actionStanza, SIGNAL(triggered()), textPage, SLOT(insertStanza()));
-    connect(actionPoem, SIGNAL(triggered()), textPage, SLOT(insertPoem()));
-    connect(actionDate, SIGNAL(triggered()), textPage, SLOT(insertDate()));
-    connect(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
-
-    connect(actionSimpleText, SIGNAL(triggered()), textPage, SLOT(insertText()));
-    connect(actionParaSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertParagraphSeparator), SIGNAL(triggered()));
-    connect(actionLineSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertLineSeparator), SIGNAL(triggered()));
-
-    connect(actionSectionAdd, SIGNAL(triggered()), textPage, SLOT(createSection()));
-    connect(actionSectionDel, SIGNAL(triggered()), textPage, SLOT(deleteSection()));
-    connect(actionTextTitle, SIGNAL(triggered()), textPage, SLOT(createTitle()));
-
-    connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
-    connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
-    connect(actionZoomReset, SIGNAL(triggered()), textEdit, SLOT(zoomReset()));
-
-    FB2DELETE(toolEdit);
-    QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
-    tool->setMovable(false);
-    tool->addSeparator();
-
-    textEdit->addTools(tool);
-
-    tool->addSeparator();
-    tool->addAction(actionSectionAdd);
-    tool->addAction(actionSectionDel);
-    tool->addAction(actionTextTitle);
-
-    tool->addSeparator();
-    tool->addAction(actionImage);
-    tool->addAction(actionNote);
-    tool->addAction(actionLink);
-    tool->addAction(actionSection);
 }
 }
 
 
 void FbMainWindow::viewText(FbTextPage *page)
 void FbMainWindow::viewText(FbTextPage *page)
@@ -978,7 +878,7 @@ void FbMainWindow::clipboardDataChanged()
         actionPasteText->setEnabled(md->hasText());
         actionPasteText->setEnabled(md->hasText());
     }
     }
 }
 }
-
+*/
 void FbMainWindow::status(const QString &text)
 void FbMainWindow::status(const QString &text)
 {
 {
     statusBar()->showMessage(text);
     statusBar()->showMessage(text);

+ 0 - 64
source/fb2main.hpp

@@ -37,13 +37,6 @@ public:
     }
     }
 };
 };
 
 
-class FbDockWidget : public QDockWidget
-{
-    Q_OBJECT
-public:
-    explicit FbDockWidget(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0);
-};
-
 class FbMainWindow : public QMainWindow
 class FbMainWindow : public QMainWindow
 {
 {
     Q_OBJECT
     Q_OBJECT
@@ -74,16 +67,12 @@ private slots:
     void createTextToolbar();
     void createTextToolbar();
     void documentWasModified();
     void documentWasModified();
     void checkScintillaUndo();
     void checkScintillaUndo();
-    void treeDestroyed();
-    void imgsDestroyed();
     void logDestroyed();
     void logDestroyed();
     void logShowed();
     void logShowed();
     void viewCode();
     void viewCode();
     void viewHtml();
     void viewHtml();
     void viewText(FbTextPage *page = 0);
     void viewText(FbTextPage *page = 0);
     void viewHead();
     void viewHead();
-    void viewTree();
-    void viewImgs();
 
 
     void cleanChanged(bool clean);
     void cleanChanged(bool clean);
     void canUndoChanged(bool canUndo);
     void canUndoChanged(bool canUndo);
@@ -115,64 +104,11 @@ private:
     FbMainDock *mainDock;
     FbMainDock *mainDock;
     QTextEdit *noteEdit;
     QTextEdit *noteEdit;
     QToolBar *toolEdit;
     QToolBar *toolEdit;
-    QDockWidget *dockTree;
-    QDockWidget *dockImgs;
     QWebInspector *inspector;
     QWebInspector *inspector;
     QTextEdit *messageEdit;
     QTextEdit *messageEdit;
     QString curFile;
     QString curFile;
     bool isSwitched;
     bool isSwitched;
     bool isUntitled;
     bool isUntitled;
-
-    QMenu
-        *menuEdit,
-        *menuText,
-        *menuView;
-
-    QAction
-        *actionBack,
-        *actionForward,
-        *actionUndo,
-        *actionRedo,
-        *actionCut,
-        *actionCopy,
-        *actionPaste,
-        *actionPasteText,
-        *actionSelect,
-        *actionFind,
-        *actionReplace,
-        *actionImage,
-        *actionNote,
-        *actionLink,
-        *actionBody,
-        *actionTitle,
-        *actionEpigraph,
-        *actionSubtitle,
-        *actionAnnot,
-        *actionPoem,
-        *actionDate,
-        *actionStanza,
-        *actionAuthor,
-        *actionSection,
-        *actionSimpleText,
-        *actionParaSeparator,
-        *actionLineSeparator,
-        *actionClearFormat,
-        *actionTextBold,
-        *actionTextItalic,
-        *actionTextStrike,
-        *actionTextCode,
-        *actionTextSub,
-        *actionTextSup,
-        *actionTextTitle,
-        *actionSectionAdd,
-        *actionSectionDel,
-        *actionContents,
-        *actionPictures,
-        *actionInspect,
-        *actionZoomIn,
-        *actionZoomOut,
-        *actionZoomReset
-    ;
 };
 };
 
 
 #endif // FB2MAIN_H
 #endif // FB2MAIN_H

+ 426 - 0
source/fb2page.cpp

@@ -0,0 +1,426 @@
+#include "fb2page.hpp"
+
+#include <QTimer>
+#include <QWebFrame>
+#include <QtDebug>
+
+#include "fb2read.hpp"
+#include "fb2save.hpp"
+#include "fb2temp.hpp"
+#include "fb2utils.h"
+#include "fb2html.h"
+#include "fb2xml2.h"
+
+//---------------------------------------------------------------------------
+//  FbTextLogger
+//---------------------------------------------------------------------------
+
+void FbTextLogger::trace(const QString &text)
+{
+    qCritical() << text;
+}
+
+//---------------------------------------------------------------------------
+//  FbTextPage
+//---------------------------------------------------------------------------
+
+FbTextPage::FbTextPage(QObject *parent)
+    : QWebPage(parent)
+    , m_logger(this)
+{
+    QWebSettings *s = settings();
+    s->setAttribute(QWebSettings::AutoLoadImages, true);
+    s->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+    s->setAttribute(QWebSettings::JavaEnabled, false);
+    s->setAttribute(QWebSettings::JavascriptEnabled, true);
+    s->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
+    s->setAttribute(QWebSettings::PluginsEnabled, false);
+    s->setAttribute(QWebSettings::ZoomTextOnly, true);
+    s->setUserStyleSheetUrl(QUrl::fromLocalFile(":style.css"));
+
+    setContentEditable(true);
+    setNetworkAccessManager(new FbNetworkAccessManager(this));
+    connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
+    connect(this, SIGNAL(contentsChanged()), SLOT(fixContents()));
+}
+
+FbNetworkAccessManager *FbTextPage::temp()
+{
+    return qobject_cast<FbNetworkAccessManager*>(networkAccessManager());
+}
+
+void FbTextPage::binary(const QString &name, const QByteArray &data)
+{
+    if (FbNetworkAccessManager *t = temp()) t->data(name, data);
+}
+
+bool FbTextPage::load(const QString &filename, const QString &xml)
+{
+    QXmlInputSource source;
+    if (xml.isEmpty()) {
+        QFile file(filename);
+        if (!file.open(QFile::ReadOnly | QFile::Text)) {
+            qCritical() << QObject::tr("Cannot read file %1: %2.").arg(filename).arg(file.errorString());
+            return false;
+        }
+        source.setData(file.readAll());
+    } else {
+        source.setData(xml);
+    }
+
+    bool ok = FbReadHandler::load(this, source, m_html);
+    if (ok) QTimer::singleShot(1000, this, SLOT(onTimer()));
+
+    return ok;
+}
+
+QAction * FbTextPage::act(Fb::Actions index) const
+{
+    return m_actions[index];
+}
+
+void FbTextPage::setAction(Fb::Actions index, QAction *action)
+{
+    m_actions[index] = action;
+}
+
+void FbTextPage::connectActions()
+{
+}
+
+void FbTextPage::disconnectActions()
+{
+}
+
+void FbTextPage::onTimer()
+{
+    static int number = 0;
+    QUrl url(QString("fb2:/%1/").arg(number++));
+    temp()->setPath(url.path());
+    mainFrame()->setHtml(m_html, url);
+}
+
+void FbTextPage::html(const QString &html, const QUrl &url)
+{
+    mainFrame()->setHtml(html, url);
+    temp()->setPath(url.path());
+}
+
+bool FbTextPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
+{
+    Q_UNUSED(frame);
+    if (type == NavigationTypeLinkClicked) {
+        qCritical() << request.url().fragment();
+        return false;
+    }
+    return QWebPage::acceptNavigationRequest(frame, request, type);
+}
+
+QString FbTextPage::block(const QString &name)
+{
+    return block(name, p());
+}
+
+QString FbTextPage::block(const QString &name, const QString &text)
+{
+    return QString("<fb:%1>%2</fb:%1>").arg(name).arg(text);
+}
+
+QString FbTextPage::p(const QString &text)
+{
+    return QString("<p>%1</p>").arg(text);
+}
+
+FbTextElement FbTextPage::body()
+{
+    return doc().findFirst("body");
+}
+
+FbTextElement FbTextPage::doc()
+{
+    return mainFrame()->documentElement();
+}
+
+void FbTextPage::push(QUndoCommand * command, const QString &text)
+{
+    undoStack()->beginMacro(text);
+    undoStack()->push(command);
+    undoStack()->endMacro();
+}
+
+void FbTextPage::update()
+{
+    emit contentsChanged();
+    emit selectionChanged();
+}
+
+FbTextElement FbTextPage::appendSection(const FbTextElement &parent)
+{
+    QString html = block("section", block("title", p()) + p());
+    FbTextElement element = parent;
+    element.appendInside(html);
+    element = parent.lastChild();
+    QUndoCommand * command = new FbInsertCmd(element);
+    push(command, tr("Append section"));
+    return element;
+}
+
+FbTextElement FbTextPage::appendTitle(const FbTextElement &parent)
+{
+    QString html = block("title", p());
+    FbTextElement element = parent;
+    element.prependInside(html);
+    element = parent.firstChild();
+    QUndoCommand * command = new FbInsertCmd(element);
+    push(command, tr("Append section"));
+    return element;
+}
+
+void FbTextPage::insertBody()
+{
+    QString html = block("body", block("title", p()) + block("section", block("title", p()) + p()));
+    FbTextElement element = body();
+    element.appendInside(html);
+    element = element.lastChild();
+    QUndoCommand * command = new FbInsertCmd(element);
+    push(command, tr("Append body"));
+}
+
+void FbTextPage::insertSection()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        if (element.isSection() || element.isBody()) {
+            appendSection(element);
+            break;
+        }
+        element = element.parent();
+    }
+}
+
+void FbTextPage::insertTitle()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        FbTextElement parent = element.parent();
+        if ((parent.isSection() || parent.isBody()) && !parent.hasTitle()) {
+            QString html = block("title", p());
+            parent.prependInside(html);
+            element = parent.firstChild();
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Insert title"));
+            break;
+        }
+        element = parent;
+    }
+}
+
+void FbTextPage::insertSubtitle()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        FbTextElement parent = element.parent();
+        if (parent.isSection()) {
+            QString html = block("subtitle", p());
+            if (element.isTitle()) {
+                element.appendOutside(html);
+                element = element.nextSibling();
+            } else {
+                element.prependOutside(html);
+                element = element.previousSibling();
+            }
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Insert subtitle"));
+            break;
+        }
+        element = parent;
+    }
+}
+
+void FbTextPage::insertPoem()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        FbTextElement parent = element.parent();
+        if (parent.isSection()) {
+            QString html = block("poem", block("stanza", p()));
+            if (element.isTitle()) {
+                element.appendOutside(html);
+                element = element.nextSibling();
+            } else {
+                element.prependOutside(html);
+                element = element.previousSibling();
+            }
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Insert poem"));
+            break;
+        }
+        element = parent;
+    }
+}
+
+void FbTextPage::insertStanza()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        if (element.isStanza()) {
+            QString html = block("stanza", p());
+            element.appendOutside(html);
+            element = element.nextSibling();
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Append stanza"));
+            break;
+        }
+        element = element.parent();
+    }
+}
+
+void FbTextPage::insertAnnot()
+{
+}
+
+void FbTextPage::insertAuthor()
+{
+}
+
+void FbTextPage::insertEpigraph()
+{
+    const QString type = "epigraph";
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        if (element.hasSubtype(type)) {
+            QString html = block("epigraph", p());
+            element = element.insertInside(type, html);
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Insert epigraph"));
+            break;
+        }
+        element = element.parent();
+    }
+}
+
+void FbTextPage::insertDate()
+{
+}
+
+void FbTextPage::insertText()
+{
+}
+
+void FbTextPage::createBlock(const QString &name)
+{
+    QString style = name;
+    QString js1 = jScript("section_get.js");
+    QString result = mainFrame()->evaluateJavaScript(js1).toString();
+    QStringList list = result.split("|");
+    if (list.count() < 2) return;
+    const QString location = list[0];
+    const QString position = list[1];
+    if (style == "title" && position.left(2) != "0,") style.prepend("sub");
+    FbTextElement original = element(location);
+    FbTextElement duplicate = original.clone();
+    original.appendOutside(duplicate);
+    original.takeFromDocument();
+    QString js2 = jScript("section_new.js") + ";f(this,'fb:%1',%2)";
+    duplicate.evaluateJavaScript(js2.arg(style).arg(position));
+    QUndoCommand * command = new FbReplaceCmd(original, duplicate);
+    push(command, tr("Create <%1>").arg(style));
+}
+
+void FbTextPage::createSection()
+{
+    createBlock("section");
+}
+
+void FbTextPage::deleteSection()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        if (element.isSection()) {
+            if (element.parent().isBody()) return;
+            FbTextElement original = element.parent();
+            FbTextElement duplicate = original.clone();
+            int index = element.index();
+            original.appendOutside(duplicate);
+            original.takeFromDocument();
+            element = duplicate.child(index);
+            if (index) {
+                FbTextElement title = element.firstChild();
+                if (title.isTitle()) {
+                    title.removeClass("title");
+                    title.addClass("subtitle");
+                }
+            }
+            QString xml = element.toInnerXml();
+            element.setOuterXml(xml);
+            QUndoCommand * command = new FbReplaceCmd(original, duplicate);
+            push(command, tr("Remove section"));
+            element.select();
+            break;
+        }
+        element = element.parent();
+    }
+}
+
+void FbTextPage::createTitle()
+{
+    createBlock("title");
+}
+
+FbTextElement FbTextPage::current()
+{
+    return element(location());
+}
+
+FbTextElement FbTextPage::element(const QString &location)
+{
+    if (location.isEmpty()) return FbTextElement();
+    QStringList list = location.split(",", QString::SkipEmptyParts);
+    QStringListIterator iterator(list);
+    QWebElement result = doc();
+    while (iterator.hasNext()) {
+        QString str = iterator.next();
+        int pos = str.indexOf("=");
+        QString tag = str.left(pos);
+        int key = str.mid(pos + 1).toInt();
+        if (key < 0) break;
+        result = result.firstChild();
+        while (0 < key--) result = result.nextSibling();
+    }
+    return result;
+}
+
+QString FbTextPage::location()
+{
+    QString javascript = "location(document.getSelection().anchorNode)";
+    return mainFrame()->evaluateJavaScript(javascript).toString();
+}
+
+QString FbTextPage::status()
+{
+    QString javascript = jScript("get_status.js");
+    QString status = mainFrame()->evaluateJavaScript(javascript).toString();
+    return status.replace("FB:", "");
+}
+
+void FbTextPage::loadFinished()
+{
+    mainFrame()->addToJavaScriptWindowObject("logger", &m_logger);
+    FbTextElement element = body().findFirst("fb\\:section");
+    if (element.isNull()) element = body().findFirst("fb\\:body");
+    if (element.isNull()) element = body();
+    FbTextElement child = element.firstChild();
+    if (child.isTitle()) child = child.nextSibling();
+    if (!child.isNull()) element = child;
+    element.select();
+}
+
+void FbTextPage::fixContents()
+{
+    foreach (QWebElement span, doc().findAll("span.apple-style-span[style]")) {
+        span.removeAttribute("style");
+    }
+    foreach (QWebElement span, doc().findAll("[style]")) {
+        span.removeAttribute("style");
+    }
+}

+ 89 - 0
source/fb2page.hpp

@@ -0,0 +1,89 @@
+#ifndef FB2PAGE_HPP
+#define FB2PAGE_HPP
+
+#include <QAction>
+#include <QUndoCommand>
+#include <QWebPage>
+
+class FbTextElement;
+class FbNetworkAccessManager;
+
+#include "fb2enum.h"
+
+class FbTextLogger : public QObject
+{
+    Q_OBJECT
+
+public:
+    explicit FbTextLogger(QObject *parent = 0) : QObject(parent) {}
+
+public slots:
+    void trace(const QString &text);
+
+};
+
+class FbTextPage : public QWebPage
+{
+    Q_OBJECT
+
+public:
+    explicit FbTextPage(QObject *parent = 0);
+    FbNetworkAccessManager *temp();
+    bool load(const QString &filename, const QString &xml = QString());
+    void push(QUndoCommand * command, const QString &text = QString());
+    FbTextElement element(const QString &location);
+    FbTextElement current();
+    QString location();
+    QString status();
+
+    QAction * act(Fb::Actions index) const;
+    void setAction(Fb::Actions index, QAction *action);
+    void connectActions();
+    void disconnectActions();
+
+    FbTextElement body();
+    FbTextElement doc();
+
+    FbTextElement appendSection(const FbTextElement &parent);
+    FbTextElement appendTitle(const FbTextElement &parent);
+
+public slots:
+    void html(const QString &html, const QUrl &url);
+    void insertBody();
+    void insertTitle();
+    void insertAnnot();
+    void insertAuthor();
+    void insertEpigraph();
+    void insertSubtitle();
+    void insertSection();
+    void insertPoem();
+    void insertStanza();
+    void insertDate();
+    void insertText();
+    void createSection();
+    void deleteSection();
+    void createTitle();
+
+protected:
+    virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
+    void createBlock(const QString &name);
+
+protected:
+    static QString block(const QString &name);
+    static QString block(const QString &name, const QString &text);
+    static QString p(const QString &text = "<br/>");
+    void update();
+
+private slots:
+    void onTimer();
+    void binary(const QString &name, const QByteArray &data);
+    void loadFinished();
+    void fixContents();
+
+private:
+    QMap<Fb::Actions, QAction*> m_actions;
+    FbTextLogger m_logger;
+    QString m_html;
+};
+
+#endif // FB2PAGE_HPP

+ 1 - 0
source/fb2save.cpp

@@ -1,6 +1,7 @@
 #include <QtGui>
 #include <QtGui>
 #include <QtDebug>
 #include <QtDebug>
 
 
+#include "fb2page.hpp"
 #include "fb2save.hpp"
 #include "fb2save.hpp"
 #include "fb2text.hpp"
 #include "fb2text.hpp"
 #include "fb2utils.h"
 #include "fb2utils.h"

+ 1 - 0
source/fb2temp.cpp

@@ -10,6 +10,7 @@
 #include <QVBoxLayout>
 #include <QVBoxLayout>
 #include <QtDebug>
 #include <QtDebug>
 
 
+#include "fb2page.hpp"
 #include "fb2text.hpp"
 #include "fb2text.hpp"
 
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------

+ 138 - 397
source/fb2text.cpp

@@ -1,10 +1,4 @@
 #include "fb2text.hpp"
 #include "fb2text.hpp"
-#include "fb2dlgs.hpp"
-#include "fb2read.hpp"
-#include "fb2save.hpp"
-#include "fb2utils.h"
-#include "fb2html.h"
-#include "fb2xml2.h"
 
 
 #include <QAction>
 #include <QAction>
 #include <QBoxLayout>
 #include <QBoxLayout>
@@ -26,13 +20,20 @@
 #include <QWebPage>
 #include <QWebPage>
 #include <QtDebug>
 #include <QtDebug>
 
 
+#include "fb2dlgs.hpp"
+#include "fb2page.hpp"
+#include "fb2tree.hpp"
+#include "fb2utils.h"
+
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
-//  FbTextLogger
+//  FbDockWidget
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
 
-void FbTextLogger::trace(const QString &text)
+FbDockWidget::FbDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
+    : QDockWidget(title, parent, flags)
 {
 {
-    qCritical() << text;
+    setFeatures(QDockWidget::AllDockWidgetFeatures);
+    setAttribute(Qt::WA_DeleteOnClose);
 }
 }
 
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -77,393 +78,6 @@ void FbNoteView::hint(const QWebElement element, const QRect &rect)
     show();
     show();
 }
 }
 
 
-//---------------------------------------------------------------------------
-//  FbTextPage
-//---------------------------------------------------------------------------
-
-FbTextPage::FbTextPage(QObject *parent)
-    : QWebPage(parent)
-    , m_logger(this)
-{
-    QWebSettings *s = settings();
-    s->setAttribute(QWebSettings::AutoLoadImages, true);
-    s->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
-    s->setAttribute(QWebSettings::JavaEnabled, false);
-    s->setAttribute(QWebSettings::JavascriptEnabled, true);
-    s->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
-    s->setAttribute(QWebSettings::PluginsEnabled, false);
-    s->setAttribute(QWebSettings::ZoomTextOnly, true);
-    s->setUserStyleSheetUrl(QUrl::fromLocalFile(":style.css"));
-
-    setContentEditable(true);
-    setNetworkAccessManager(new FbNetworkAccessManager(this));
-    connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
-    connect(this, SIGNAL(contentsChanged()), SLOT(fixContents()));
-}
-
-FbNetworkAccessManager *FbTextPage::temp()
-{
-    return qobject_cast<FbNetworkAccessManager*>(networkAccessManager());
-}
-
-void FbTextPage::binary(const QString &name, const QByteArray &data)
-{
-    if (FbNetworkAccessManager *t = temp()) t->data(name, data);
-}
-
-bool FbTextPage::load(const QString &filename, const QString &xml)
-{
-    QXmlInputSource source;
-    if (xml.isEmpty()) {
-        QFile file(filename);
-        if (!file.open(QFile::ReadOnly | QFile::Text)) {
-            qCritical() << QObject::tr("Cannot read file %1: %2.").arg(filename).arg(file.errorString());
-            return false;
-        }
-        source.setData(file.readAll());
-    } else {
-        source.setData(xml);
-    }
-
-    bool ok = FbReadHandler::load(this, source, m_html);
-    if (ok) QTimer::singleShot(1000, this, SLOT(onTimer()));
-
-    return ok;
-}
-
-void FbTextPage::onTimer()
-{
-    static int number = 0;
-    QUrl url(QString("fb2:/%1/").arg(number++));
-    temp()->setPath(url.path());
-    mainFrame()->setHtml(m_html, url);
-}
-
-void FbTextPage::html(const QString &html, const QUrl &url)
-{
-    mainFrame()->setHtml(html, url);
-    temp()->setPath(url.path());
-}
-
-bool FbTextPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
-{
-    Q_UNUSED(frame);
-    if (type == NavigationTypeLinkClicked) {
-        qCritical() << request.url().fragment();
-        return false;
-    }
-    return QWebPage::acceptNavigationRequest(frame, request, type);
-}
-
-QString FbTextPage::block(const QString &name)
-{
-    return block(name, p());
-}
-
-QString FbTextPage::block(const QString &name, const QString &text)
-{
-    return QString("<fb:%1>%2</fb:%1>").arg(name).arg(text);
-}
-
-QString FbTextPage::p(const QString &text)
-{
-    return QString("<p>%1</p>").arg(text);
-}
-
-FbTextElement FbTextPage::body()
-{
-    return doc().findFirst("body");
-}
-
-FbTextElement FbTextPage::doc()
-{
-    return mainFrame()->documentElement();
-}
-
-void FbTextPage::push(QUndoCommand * command, const QString &text)
-{
-    undoStack()->beginMacro(text);
-    undoStack()->push(command);
-    undoStack()->endMacro();
-}
-
-void FbTextPage::update()
-{
-    emit contentsChanged();
-    emit selectionChanged();
-}
-
-FbTextElement FbTextPage::appendSection(const FbTextElement &parent)
-{
-    QString html = block("section", block("title", p()) + p());
-    FbTextElement element = parent;
-    element.appendInside(html);
-    element = parent.lastChild();
-    QUndoCommand * command = new FbInsertCmd(element);
-    push(command, tr("Append section"));
-    return element;
-}
-
-FbTextElement FbTextPage::appendTitle(const FbTextElement &parent)
-{
-    QString html = block("title", p());
-    FbTextElement element = parent;
-    element.prependInside(html);
-    element = parent.firstChild();
-    QUndoCommand * command = new FbInsertCmd(element);
-    push(command, tr("Append section"));
-    return element;
-}
-
-void FbTextPage::insertBody()
-{
-    QString html = block("body", block("title", p()) + block("section", block("title", p()) + p()));
-    FbTextElement element = body();
-    element.appendInside(html);
-    element = element.lastChild();
-    QUndoCommand * command = new FbInsertCmd(element);
-    push(command, tr("Append body"));
-}
-
-void FbTextPage::insertSection()
-{
-    FbTextElement element = current();
-    while (!element.isNull()) {
-        if (element.isSection() || element.isBody()) {
-            appendSection(element);
-            break;
-        }
-        element = element.parent();
-    }
-}
-
-void FbTextPage::insertTitle()
-{
-    FbTextElement element = current();
-    while (!element.isNull()) {
-        FbTextElement parent = element.parent();
-        if ((parent.isSection() || parent.isBody()) && !parent.hasTitle()) {
-            QString html = block("title", p());
-            parent.prependInside(html);
-            element = parent.firstChild();
-            QUndoCommand * command = new FbInsertCmd(element);
-            push(command, tr("Insert title"));
-            break;
-        }
-        element = parent;
-    }
-}
-
-void FbTextPage::insertSubtitle()
-{
-    FbTextElement element = current();
-    while (!element.isNull()) {
-        FbTextElement parent = element.parent();
-        if (parent.isSection()) {
-            QString html = block("subtitle", p());
-            if (element.isTitle()) {
-                element.appendOutside(html);
-                element = element.nextSibling();
-            } else {
-                element.prependOutside(html);
-                element = element.previousSibling();
-            }
-            QUndoCommand * command = new FbInsertCmd(element);
-            push(command, tr("Insert subtitle"));
-            break;
-        }
-        element = parent;
-    }
-}
-
-void FbTextPage::insertPoem()
-{
-    FbTextElement element = current();
-    while (!element.isNull()) {
-        FbTextElement parent = element.parent();
-        if (parent.isSection()) {
-            QString html = block("poem", block("stanza", p()));
-            if (element.isTitle()) {
-                element.appendOutside(html);
-                element = element.nextSibling();
-            } else {
-                element.prependOutside(html);
-                element = element.previousSibling();
-            }
-            QUndoCommand * command = new FbInsertCmd(element);
-            push(command, tr("Insert poem"));
-            break;
-        }
-        element = parent;
-    }
-}
-
-void FbTextPage::insertStanza()
-{
-    FbTextElement element = current();
-    while (!element.isNull()) {
-        if (element.isStanza()) {
-            QString html = block("stanza", p());
-            element.appendOutside(html);
-            element = element.nextSibling();
-            QUndoCommand * command = new FbInsertCmd(element);
-            push(command, tr("Append stanza"));
-            break;
-        }
-        element = element.parent();
-    }
-}
-
-void FbTextPage::insertAnnot()
-{
-}
-
-void FbTextPage::insertAuthor()
-{
-}
-
-void FbTextPage::insertEpigraph()
-{
-    const QString type = "epigraph";
-    FbTextElement element = current();
-    while (!element.isNull()) {
-        if (element.hasSubtype(type)) {
-            QString html = block("epigraph", p());
-            element = element.insertInside(type, html);
-            QUndoCommand * command = new FbInsertCmd(element);
-            push(command, tr("Insert epigraph"));
-            break;
-        }
-        element = element.parent();
-    }
-}
-
-void FbTextPage::insertDate()
-{
-}
-
-void FbTextPage::insertText()
-{
-}
-
-void FbTextPage::createBlock(const QString &name)
-{
-    QString style = name;
-    QString js1 = jScript("section_get.js");
-    QString result = mainFrame()->evaluateJavaScript(js1).toString();
-    QStringList list = result.split("|");
-    if (list.count() < 2) return;
-    const QString location = list[0];
-    const QString position = list[1];
-    if (style == "title" && position.left(2) != "0,") style.prepend("sub");
-    FbTextElement original = element(location);
-    FbTextElement duplicate = original.clone();
-    original.appendOutside(duplicate);
-    original.takeFromDocument();
-    QString js2 = jScript("section_new.js") + ";f(this,'fb:%1',%2)";
-    duplicate.evaluateJavaScript(js2.arg(style).arg(position));
-    QUndoCommand * command = new FbReplaceCmd(original, duplicate);
-    push(command, tr("Create <%1>").arg(style));
-}
-
-void FbTextPage::createSection()
-{
-    createBlock("section");
-}
-
-void FbTextPage::deleteSection()
-{
-    FbTextElement element = current();
-    while (!element.isNull()) {
-        if (element.isSection()) {
-            if (element.parent().isBody()) return;
-            FbTextElement original = element.parent();
-            FbTextElement duplicate = original.clone();
-            int index = element.index();
-            original.appendOutside(duplicate);
-            original.takeFromDocument();
-            element = duplicate.child(index);
-            if (index) {
-                FbTextElement title = element.firstChild();
-                if (title.isTitle()) {
-                    title.removeClass("title");
-                    title.addClass("subtitle");
-                }
-            }
-            QString xml = element.toInnerXml();
-            element.setOuterXml(xml);
-            QUndoCommand * command = new FbReplaceCmd(original, duplicate);
-            push(command, tr("Remove section"));
-            element.select();
-            break;
-        }
-        element = element.parent();
-    }
-}
-
-void FbTextPage::createTitle()
-{
-    createBlock("title");
-}
-
-FbTextElement FbTextPage::current()
-{
-    return element(location());
-}
-
-FbTextElement FbTextPage::element(const QString &location)
-{
-    if (location.isEmpty()) return FbTextElement();
-    QStringList list = location.split(",", QString::SkipEmptyParts);
-    QStringListIterator iterator(list);
-    QWebElement result = doc();
-    while (iterator.hasNext()) {
-        QString str = iterator.next();
-        int pos = str.indexOf("=");
-        QString tag = str.left(pos);
-        int key = str.mid(pos + 1).toInt();
-        if (key < 0) break;
-        result = result.firstChild();
-        while (0 < key--) result = result.nextSibling();
-    }
-    return result;
-}
-
-QString FbTextPage::location()
-{
-    QString javascript = "location(document.getSelection().anchorNode)";
-    return mainFrame()->evaluateJavaScript(javascript).toString();
-}
-
-QString FbTextPage::status()
-{
-    QString javascript = jScript("get_status.js");
-    QString status = mainFrame()->evaluateJavaScript(javascript).toString();
-    return status.replace("FB:", "");
-}
-
-void FbTextPage::loadFinished()
-{
-    mainFrame()->addToJavaScriptWindowObject("logger", &m_logger);
-    FbTextElement element = body().findFirst("fb\\:section");
-    if (element.isNull()) element = body().findFirst("fb\\:body");
-    if (element.isNull()) element = body();
-    FbTextElement child = element.firstChild();
-    if (child.isTitle()) child = child.nextSibling();
-    if (!child.isNull()) element = child;
-    element.select();
-}
-
-void FbTextPage::fixContents()
-{
-    foreach (QWebElement span, doc().findAll("span.apple-style-span[style]")) {
-        span.removeAttribute("style");
-    }
-    foreach (QWebElement span, doc().findAll("[style]")) {
-        span.removeAttribute("style");
-    }
-}
-
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 //  FbTextBase
 //  FbTextBase
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -548,10 +162,13 @@ void FbTextBase::addTools(QToolBar *tool)
 //  FbTextEdit
 //  FbTextEdit
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
 
-FbTextEdit::FbTextEdit(QWidget *parent)
+FbTextEdit::FbTextEdit(QWidget *parent, QWidget *owner)
     : FbTextBase(parent)
     : FbTextBase(parent)
+    , m_owner(qobject_cast<QMainWindow*>(owner))
     , m_noteView(0)
     , m_noteView(0)
     , m_thread(0)
     , m_thread(0)
+    , dockTree(0)
+    , dockImgs(0)
 {
 {
     setContextMenuPolicy(Qt::CustomContextMenu);
     setContextMenuPolicy(Qt::CustomContextMenu);
     connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint)));
     connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint)));
@@ -573,6 +190,130 @@ FbNetworkAccessManager *FbTextEdit::files()
     return page()->temp();
     return page()->temp();
 }
 }
 
 
+QAction * FbTextEdit::act(Fb::Actions index) const
+{
+    return m_actions[index];
+}
+
+void FbTextEdit::setAction(Fb::Actions index, QAction *action)
+{
+    m_actions[index] = 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()));
+/*
+    connect(textPage->undoStack(), SIGNAL(cleanChanged(bool)), SLOT(cleanChanged(bool)));
+    connect(textPage->undoStack(), SIGNAL(canUndoChanged(bool)), SLOT(canUndoChanged(bool)));
+    connect(textPage->undoStack(), SIGNAL(canRedoChanged(bool)), SLOT(canRedoChanged(bool)));
+    connect(textPage, SIGNAL(selectionChanged()), SLOT(selectionChanged()));
+
+    connect(actionUndo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Undo), SIGNAL(triggered()));
+    connect(actionRedo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Redo), SIGNAL(triggered()));
+
+    connect(actionCut, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Cut), SIGNAL(triggered()));
+    connect(actionCopy, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Copy), SIGNAL(triggered()));
+    connect(actionPaste, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Paste), SIGNAL(triggered()));
+    connect(actionPasteText, SIGNAL(triggered()), textEdit->pageAction(QWebPage::PasteAndMatchStyle), SIGNAL(triggered()));
+
+    connect(actionClearFormat, SIGNAL(triggered()), textEdit->pageAction(QWebPage::RemoveFormat), SIGNAL(triggered()));
+    connect(actionTextBold, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleBold), SIGNAL(triggered()));
+    connect(actionTextItalic, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleItalic), SIGNAL(triggered()));
+    connect(actionTextStrike, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleStrikethrough), SIGNAL(triggered()));
+    connect(actionTextSub, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleSubscript), SIGNAL(triggered()));
+    connect(actionTextSup, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleSuperscript), SIGNAL(triggered()));
+
+    connect(textEdit->pageAction(QWebPage::RemoveFormat), SIGNAL(changed()), actionClearFormat, SLOT(updateEnabled()));
+    connect(textEdit->pageAction(QWebPage::ToggleBold), SIGNAL(changed()), actionTextBold, SLOT(updateChecked()));
+    connect(textEdit->pageAction(QWebPage::ToggleItalic), SIGNAL(changed()), actionTextItalic, SLOT(updateChecked()));
+    connect(textEdit->pageAction(QWebPage::ToggleStrikethrough), SIGNAL(changed()), actionTextStrike, SLOT(updateChecked()));
+    connect(textEdit->pageAction(QWebPage::ToggleSubscript), SIGNAL(changed()), actionTextSub, SLOT(updateChecked()));
+    connect(textEdit->pageAction(QWebPage::ToggleSuperscript), SIGNAL(changed()), actionTextSup, SLOT(updateChecked()));
+
+    connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(find()));
+    connect(actionImage, SIGNAL(triggered()), textEdit, SLOT(insertImage()));
+    connect(actionNote, SIGNAL(triggered()), textEdit, SLOT(insertNote()));
+    connect(actionLink, SIGNAL(triggered()), textEdit, SLOT(insertLink()));
+
+    connect(actionTitle, SIGNAL(triggered()), textPage, SLOT(insertTitle()));
+    connect(actionAnnot, SIGNAL(triggered()), textPage, SLOT(insertAnnot()));
+    connect(actionAuthor, SIGNAL(triggered()), textPage, SLOT(insertAuthor()));
+    connect(actionEpigraph, SIGNAL(triggered()), textPage, SLOT(insertEpigraph()));
+    connect(actionSubtitle, SIGNAL(triggered()), textPage, SLOT(insertSubtitle()));
+    connect(actionSection, SIGNAL(triggered()), textPage, SLOT(insertSection()));
+    connect(actionStanza, SIGNAL(triggered()), textPage, SLOT(insertStanza()));
+    connect(actionPoem, SIGNAL(triggered()), textPage, SLOT(insertPoem()));
+    connect(actionDate, SIGNAL(triggered()), textPage, SLOT(insertDate()));
+    connect(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
+
+    connect(actionSimpleText, SIGNAL(triggered()), textPage, SLOT(insertText()));
+    connect(actionParaSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertParagraphSeparator), SIGNAL(triggered()));
+    connect(actionLineSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertLineSeparator), SIGNAL(triggered()));
+
+    connect(actionSectionAdd, SIGNAL(triggered()), textPage, SLOT(createSection()));
+    connect(actionSectionDel, SIGNAL(triggered()), textPage, SLOT(deleteSection()));
+    connect(actionTextTitle, SIGNAL(triggered()), textPage, SLOT(createTitle()));
+
+    connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
+    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->addSeparator();
+    tool->addAction(actionImage);
+    tool->addAction(actionNote);
+    tool->addAction(actionLink);
+    tool->addAction(actionSection);
+*/
+}
+
+void FbTextEdit::disconnectActions()
+{
+    foreach (QAction *action, m_actions) {
+        action->setDisabled(true);
+        disconnect(action);
+    }
+}
+
+void FbTextEdit::createTree()
+{
+    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);
+}
+
+void FbTextEdit::createImgs()
+{
+    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);
+}
+
+void FbTextEdit::treeDestroyed()
+{
+    m_actions[Fb::ViewContents]->setChecked(false);
+    dockTree = 0;
+}
+
+void FbTextEdit::imgsDestroyed()
+{
+    m_actions[Fb::ViewPictures]->setChecked(false);
+    dockImgs = 0;
+}
+
 FbNoteView & FbTextEdit::noteView()
 FbNoteView & FbTextEdit::noteView()
 {
 {
     if (m_noteView) return *m_noteView;
     if (m_noteView) return *m_noteView;

+ 24 - 72
source/fb2text.hpp

@@ -2,36 +2,32 @@
 #define FB2TEXT_H
 #define FB2TEXT_H
 
 
 #include <QAction>
 #include <QAction>
+#include <QDockWidget>
 #include <QFrame>
 #include <QFrame>
+#include <QMainWindow>
 #include <QResizeEvent>
 #include <QResizeEvent>
 #include <QTimer>
 #include <QTimer>
 #include <QThread>
 #include <QThread>
 #include <QWebElement>
 #include <QWebElement>
 #include <QWebView>
 #include <QWebView>
 
 
+#include "fb2enum.h"
 #include "fb2temp.hpp"
 #include "fb2temp.hpp"
 
 
 QT_BEGIN_NAMESPACE
 QT_BEGIN_NAMESPACE
-class QDockWidget;
 class QToolBar;
 class QToolBar;
-class QUndoCommand;
 class QWebInspector;
 class QWebInspector;
 QT_END_NAMESPACE
 QT_END_NAMESPACE
 
 
 class FbNoteView;
 class FbNoteView;
 class FbReadThread;
 class FbReadThread;
-class FbTextElement;
+class FbTextPage;
 
 
-class FbTextLogger : public QObject
+class FbDockWidget : public QDockWidget
 {
 {
     Q_OBJECT
     Q_OBJECT
-
 public:
 public:
-    explicit FbTextLogger(QObject *parent = 0) : QObject(parent) {}
-
-public slots:
-    void trace(const QString &text);
-
+    explicit FbDockWidget(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0);
 };
 };
 
 
 class FbTextBase : public QWebView
 class FbTextBase : public QWebView
@@ -72,70 +68,12 @@ private:
     QSize m_size;
     QSize m_size;
 };
 };
 
 
-class FbTextPage : public QWebPage
-{
-    Q_OBJECT
-
-public:
-    explicit FbTextPage(QObject *parent = 0);
-    FbNetworkAccessManager *temp();
-    bool load(const QString &filename, const QString &xml = QString());
-    void push(QUndoCommand * command, const QString &text = QString());
-    FbTextElement element(const QString &location);
-    FbTextElement current();
-    QString location();
-    QString status();
-
-    FbTextElement body();
-    FbTextElement doc();
-
-    FbTextElement appendSection(const FbTextElement &parent);
-    FbTextElement appendTitle(const FbTextElement &parent);
-
-public slots:
-    void html(const QString &html, const QUrl &url);
-    void insertBody();
-    void insertTitle();
-    void insertAnnot();
-    void insertAuthor();
-    void insertEpigraph();
-    void insertSubtitle();
-    void insertSection();
-    void insertPoem();
-    void insertStanza();
-    void insertDate();
-    void insertText();
-    void createSection();
-    void deleteSection();
-    void createTitle();
-
-protected:
-    virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
-    void createBlock(const QString &name);
-
-protected:
-    static QString block(const QString &name);
-    static QString block(const QString &name, const QString &text);
-    static QString p(const QString &text = "<br/>");
-    void update();
-
-private slots:
-    void onTimer();
-    void binary(const QString &name, const QByteArray &data);
-    void loadFinished();
-    void fixContents();
-
-private:
-    FbTextLogger m_logger;
-    QString m_html;
-};
-
 class FbTextEdit : public FbTextBase
 class FbTextEdit : public FbTextBase
 {
 {
     Q_OBJECT
     Q_OBJECT
 
 
 public:
 public:
-    explicit FbTextEdit(QWidget *parent = 0);
+    explicit FbTextEdit(QWidget *parent, QWidget *owner);
     virtual ~FbTextEdit();
     virtual ~FbTextEdit();
 
 
     FbTextPage *page();
     FbTextPage *page();
@@ -144,8 +82,10 @@ public:
     bool save(QByteArray *array);
     bool save(QByteArray *array);
     bool save(QString *string);
     bool save(QString *string);
 
 
-    bool actionEnabled(QWebPage::WebAction action);
-    bool actionChecked(QWebPage::WebAction action);
+    QAction * act(Fb::Actions index) const;
+    void setAction(Fb::Actions index, QAction *action);
+    void connectActions(QToolBar *tool);
+    void disconnectActions();
 
 
     bool BoldChecked();
     bool BoldChecked();
     bool ItalicChecked();
     bool ItalicChecked();
@@ -170,18 +110,30 @@ public slots:
 private slots:
 private slots:
     void linkHovered(const QString &link, const QString &title, const QString &textContent);
     void linkHovered(const QString &link, const QString &title, const QString &textContent);
     void contextMenu(const QPoint &pos);
     void contextMenu(const QPoint &pos);
+    void createImgs();
+    void createTree();
+    void treeDestroyed();
+    void imgsDestroyed();
 
 
 private:
 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);
     void execCommand(const QString &cmd, const QString &arg);
-    void exec(QUndoCommand *command);
     FbTemporaryFile * file(const QString &name);
     FbTemporaryFile * file(const QString &name);
     FbNoteView & noteView();
     FbNoteView & noteView();
     QWebElement body();
     QWebElement body();
     QWebElement doc();
     QWebElement doc();
 
 
 private:
 private:
+    QMainWindow *m_owner;
     FbNoteView *m_noteView;
     FbNoteView *m_noteView;
     FbReadThread *m_thread;
     FbReadThread *m_thread;
+    QMap<Fb::Actions, QAction*> m_actions;
+    QDockWidget *dockTree;
+    QDockWidget *dockImgs;
     QPoint m_point;
     QPoint m_point;
 };
 };
 
 

+ 1 - 0
source/fb2tree.cpp

@@ -10,6 +10,7 @@
 #include <QTreeView>
 #include <QTreeView>
 #include <QUrl>
 #include <QUrl>
 
 
+#include "fb2page.hpp"
 #include "fb2text.hpp"
 #include "fb2text.hpp"
 #include "fb2html.h"
 #include "fb2html.h"
 #include "fb2utils.h"
 #include "fb2utils.h"

+ 3 - 0
source/fb2tree.hpp

@@ -162,6 +162,9 @@ private slots:
     void moveLeft();
     void moveLeft();
     void moveRight();
     void moveRight();
 
 
+    void treeDestroyed();
+    void imgsDestroyed();
+
 protected:
 protected:
     void keyPressEvent(QKeyEvent *event);
     void keyPressEvent(QKeyEvent *event);