Explorar o código

Standart edit actions

Kandrashin Denis %!s(int64=13) %!d(string=hai) anos
pai
achega
2cfd89fafd
Modificáronse 4 ficheiros con 118 adicións e 14 borrados
  1. 46 10
      source/fb2main.cpp
  2. 5 3
      source/fb2main.h
  3. 46 0
      source/fb2view.cpp
  4. 21 1
      source/fb2view.h

+ 46 - 10
source/fb2main.cpp

@@ -1,7 +1,6 @@
 #include <QtGui>
 #include <QtDebug>
 #include <QTreeView>
-#include <QWebView>
 #include <QWebFrame>
 
 #include "fb2main.h"
@@ -150,8 +149,7 @@ void Fb2MainWindow::fileOpen()
 
     if (textEdit) {
         if (isUntitled && !isWindowModified()) {
-            Fb2WebView *view = dynamic_cast<Fb2WebView*>(textEdit);
-            view->load(filename);
+            textEdit->load(filename);
         } else {
             Fb2MainWindow * other = new Fb2MainWindow(filename, NULL);
             other->move(x() + 40, y() + 40);
@@ -168,14 +166,11 @@ void Fb2MainWindow::fileOpen()
         }
     }
 }
-
+/*
 void Fb2MainWindow::sendDocument()
 {
-//    setCurrentFile(thread->file(), thread->html());
-    return;
-
     treeView = new QTreeView(this);
-//    treeView->setModel(new Fb2TreeModel(*textEdit));
+    treeView->setModel(new Fb2TreeModel(*textEdit));
     treeView->setHeaderHidden(true);
     connect(treeView, SIGNAL(activated(QModelIndex)), SLOT(treeActivated(QModelIndex)));
     connect(treeView, SIGNAL(destroyed()), SLOT(treeDestroyed()));
@@ -185,7 +180,7 @@ void Fb2MainWindow::sendDocument()
     dock->setWidget(treeView);
     addDockWidget(Qt::LeftDockWidgetArea, dock);
 }
-
+*/
 bool Fb2MainWindow::fileSave()
 {
     if (isUntitled) {
@@ -286,12 +281,14 @@ void Fb2MainWindow::createActions()
     actionUndo = act = new QAction(icon("edit-undo"), tr("&Undo"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Undo);
+    act->setEnabled(false);
     menu->addAction(act);
     tool->addAction(act);
 
     actionRedo = act = new QAction(icon("edit-redo"), tr("&Redo"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Redo);
+    act->setEnabled(false);
     menu->addAction(act);
     tool->addAction(act);
 
@@ -420,11 +417,50 @@ void Fb2MainWindow::createText()
     setCentralWidget(textEdit);
     textEdit->setFocus();
 
+    connect(textEdit->page(), SIGNAL(contentChanged()), this, SLOT(contentChanged()));
+    connect(textEdit->page(), SIGNAL(selectionChanged()), this, SLOT(contentChanged()));
+
     connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
     connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
     connect(actionZoomOrig, SIGNAL(triggered()), textEdit, SLOT(zoomOrig()));
 
-    QAction *action = textEdit->pageAction(QWebPage::Undo);
+    connect(actionUndo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Undo), SIGNAL(triggered()));
+    connect(actionRedo, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Redo), SIGNAL(triggered()));
+
+    connect(textEdit->pageAction(QWebPage::Undo), SIGNAL(changed()), this, SLOT(undoChanged()));
+    connect(textEdit->pageAction(QWebPage::Redo), SIGNAL(changed()), this, SLOT(redoChanged()));
+
+    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(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()));
+}
+
+void Fb2MainWindow::contentChanged()
+{
+    actionCut->setEnabled(textEdit->CutEnabled());
+    actionCopy->setEnabled(textEdit->CopyEnabled());
+
+    actionTextBold->setChecked(textEdit->BoldChecked());
+    actionTextItalic->setChecked(textEdit->ItalicChecked());
+    actionTextStrike->setChecked(textEdit->StrikeChecked());
+    actionTextSub->setChecked(textEdit->SubChecked());
+    actionTextSup->setChecked(textEdit->SupChecked());
+}
+
+void Fb2MainWindow::undoChanged()
+{
+    actionUndo->setEnabled(textEdit->UndoEnabled());
+}
+
+void Fb2MainWindow::redoChanged()
+{
+    actionRedo->setEnabled(textEdit->RedoEnabled());
 }
 
 void Fb2MainWindow::createQsci()

+ 5 - 3
source/fb2main.h

@@ -11,12 +11,12 @@ class QModelIndex;
 class QTextEdit;
 class QThread;
 class QTreeView;
-class QWebView;
 QT_END_NAMESPACE
 
 class QsciScintilla;
 class Fb2MainDocument;
 class Fb2ReadThread;
+class Fb2WebView;
 
 class Fb2MainWindow : public QMainWindow
 {
@@ -32,7 +32,6 @@ protected:
 
 public slots:
     void logMessage(const QString &message);
-    void sendDocument();
 
 private slots:
     void fileNew();
@@ -57,6 +56,9 @@ private slots:
 
     void cursorPositionChanged();
     void clipboardDataChanged();
+    void contentChanged();
+    void undoChanged();
+    void redoChanged();
 
 private:
     bool loadXML(const QString &filename);
@@ -76,7 +78,7 @@ private:
     Fb2MainWindow *findFb2MainWindow(const QString &fileName);
 
     Fb2ReadThread *thread;
-    QWebView *textEdit;
+    Fb2WebView *textEdit;
     QTextEdit *noteEdit;
     QTextEdit *messageEdit;
     QsciScintilla *qsciEdit;

+ 46 - 0
source/fb2view.cpp

@@ -1,6 +1,7 @@
 #include "fb2view.h"
 #include "fb2read.h"
 
+#include <QAction>
 #include <QtDebug>
 
 //---------------------------------------------------------------------------
@@ -63,3 +64,48 @@ void Fb2WebView::zoomOrig()
 {
     setZoomFactor(1);
 }
+
+bool Fb2WebView::UndoEnabled()
+{
+    return pageAction(QWebPage::Undo)->isEnabled();
+}
+
+bool Fb2WebView::RedoEnabled()
+{
+    return pageAction(QWebPage::Redo)->isEnabled();
+}
+
+bool Fb2WebView::CutEnabled()
+{
+    return pageAction(QWebPage::Cut)->isEnabled();
+}
+
+bool Fb2WebView::CopyEnabled()
+{
+    return pageAction(QWebPage::Copy)->isEnabled();
+}
+
+bool Fb2WebView::BoldChecked()
+{
+    return pageAction(QWebPage::ToggleBold)->isChecked();
+}
+
+bool Fb2WebView::ItalicChecked()
+{
+    return pageAction(QWebPage::ToggleItalic)->isChecked();
+}
+
+bool Fb2WebView::StrikeChecked()
+{
+    return pageAction(QWebPage::ToggleStrikethrough)->isChecked();
+}
+
+bool Fb2WebView::SubChecked()
+{
+    return pageAction(QWebPage::ToggleSubscript)->isChecked();
+}
+
+bool Fb2WebView::SupChecked()
+{
+    return pageAction(QWebPage::ToggleSuperscript)->isChecked();
+}

+ 21 - 1
source/fb2view.h

@@ -45,12 +45,32 @@ public:
     explicit Fb2WebView(QWidget *parent = 0);
     virtual ~Fb2WebView();
     bool load(const QString &filename);
-    
+
+    bool UndoEnabled();
+    bool RedoEnabled();
+    bool CutEnabled();
+    bool CopyEnabled();
+    bool BoldChecked();
+    bool ItalicChecked();
+    bool StrikeChecked();
+    bool SubChecked();
+    bool SupChecked();
+
 signals:
     
 public slots:
     void file(QString name, QString path);
     void html(QString name, QString html);
+/*
+    void Undo();
+    void Redo();
+    void Cut();
+    void Copy();
+    void Paste();
+    void Bold();
+    void Italic();
+    void Strike();
+*/
     void zoomIn();
     void zoomOut();
     void zoomOrig();