Kandrashin Denis 12 anni fa
parent
commit
402bce962a
2 ha cambiato i file con 72 aggiunte e 0 eliminazioni
  1. 71 0
      source/fb2main.cpp
  2. 1 0
      source/fb2main.hpp

+ 71 - 0
source/fb2main.cpp

@@ -472,6 +472,12 @@ void FbMainWindow::createActions()
     menu->addAction(act);
     tool->addAction(act);
 
+    act = new QAction(tr("&HTML"), this);
+    act->setCheckable(true);
+    connect(act, SIGNAL(triggered()), this, SLOT(viewHtml()));
+    viewGroup->addAction(act);
+    menu->addAction(act);
+
     menu->addSeparator();
 
     actionZoomIn = act = new QAction(FbIcon("zoom-in"), tr("Zoom in"), this);
@@ -852,8 +858,10 @@ void FbMainWindow::viewCode()
 
     bool load = false;
     QByteArray xml;
+    QString html;
     if (textFrame) {
         textFrame->view()->save(&xml);
+        html = textFrame->view()->page()->mainFrame()->toHtml();
         isSwitched = true;
         load = true;
     }
@@ -867,6 +875,69 @@ void FbMainWindow::viewCode()
         codeEdit = new FbCodeEdit;
     }
     if (load) codeEdit->load(xml);
+    codeEdit->setPlainText(html);
+    setCentralWidget(codeEdit);
+    codeEdit->setFocus();
+
+    FB2DELETE(toolEdit);
+    QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
+    tool->addSeparator();
+    tool->addAction(actionUndo);
+    tool->addAction(actionRedo);
+    tool->addSeparator();
+    tool->addAction(actionCut);
+    tool->addAction(actionCopy);
+    tool->addAction(actionPaste);
+    tool->addSeparator();
+    tool->addAction(actionZoomIn);
+    tool->addAction(actionZoomOut);
+    tool->addAction(actionZoomReset);
+    tool->setMovable(false);
+
+    connect(codeEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
+    connect(codeEdit, SIGNAL(textChanged()), this, SLOT(checkScintillaUndo()));
+
+    connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
+    connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
+
+    connect(actionUndo, SIGNAL(triggered()), codeEdit, SLOT(undo()));
+    connect(actionRedo, SIGNAL(triggered()), codeEdit, SLOT(redo()));
+
+    connect(actionCut, SIGNAL(triggered()), codeEdit, SLOT(cut()));
+    connect(actionCopy, SIGNAL(triggered()), codeEdit, SLOT(copy()));
+    connect(actionPaste, SIGNAL(triggered()), codeEdit, SLOT(paste()));
+
+    connect(actionFind, SIGNAL(triggered()), codeEdit, SLOT(find()));
+
+    connect(actionZoomIn, SIGNAL(triggered()), codeEdit, SLOT(zoomIn()));
+    connect(actionZoomOut, SIGNAL(triggered()), codeEdit, SLOT(zoomOut()));
+    connect(actionZoomReset, SIGNAL(triggered()), codeEdit, SLOT(zoomReset()));
+
+    actionContents->setEnabled(false);
+    actionPictures->setEnabled(false);
+    actionInspect->setEnabled(false);
+}
+
+void FbMainWindow::viewHtml()
+{
+    if (codeEdit && centralWidget() == codeEdit) return;
+    if (!textFrame) return;
+
+    bool load = false;
+    QString html = textFrame->view()->page()->mainFrame()->toHtml();
+    isSwitched = true;
+    load = true;
+
+    FB2DELETE(textFrame);
+    FB2DELETE(dockTree);
+    FB2DELETE(dockImgs);
+    FB2DELETE(headTree);
+
+    if (!codeEdit) {
+        codeEdit = new FbCodeEdit;
+    }
+
+    codeEdit->setPlainText(html);
     setCentralWidget(codeEdit);
     codeEdit->setFocus();
 

+ 1 - 0
source/fb2main.hpp

@@ -63,6 +63,7 @@ private slots:
     void logDestroyed();
     void logShowed();
     void viewCode();
+    void viewHtml();
     void viewText();
     void viewHead();
     void viewTree();