浏览代码

Text actions

Kandrashin Denis 12 年之前
父节点
当前提交
0046f7c74b
共有 6 个文件被更改,包括 78 次插入65 次删除
  1. 1 1
      source/fb2dock.cpp
  2. 10 9
      source/fb2main.cpp
  3. 1 1
      source/fb2mode.h
  4. 1 1
      source/fb2temp.cpp
  5. 52 42
      source/fb2text.cpp
  6. 13 11
      source/fb2text.hpp

+ 1 - 1
source/fb2dock.cpp

@@ -32,7 +32,7 @@ FbMainDock::FbMainDock(QWidget *parent)
     : QStackedWidget(parent)
     : QStackedWidget(parent)
     , isSwitched(false)
     , isSwitched(false)
 {
 {
-    textFrame = new FbWebFrame(this);
+    textFrame = new FbTextFrame(this);
     m_text = new FbTextEdit(textFrame, parent);
     m_text = new FbTextEdit(textFrame, parent);
     textFrame->layout()->addWidget(m_text);
     textFrame->layout()->addWidget(m_text);
 
 

+ 10 - 9
source/fb2main.cpp

@@ -218,7 +218,7 @@ void FbMainWindow::createActions()
 
 
     connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
     connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
 
 
-    act = new QAction(FbIcon("edit-undo"), tr("&Undo"), this);
+    act = new FbTextAction(FbIcon("edit-undo"), tr("&Undo"), QWebPage::Undo, text);
     text->setAction(Fb::EditUndo, act);
     text->setAction(Fb::EditUndo, act);
     code->setAction(Fb::EditUndo, act);
     code->setAction(Fb::EditUndo, act);
     act->setPriority(QAction::LowPriority);
     act->setPriority(QAction::LowPriority);
@@ -226,7 +226,7 @@ void FbMainWindow::createActions()
     act->setEnabled(false);
     act->setEnabled(false);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    act = new QAction(FbIcon("edit-redo"), tr("&Redo"), this);
+    act = new FbTextAction(FbIcon("edit-redo"), tr("&Redo"), QWebPage::Redo, text);
     text->setAction(Fb::EditRedo, act);
     text->setAction(Fb::EditRedo, act);
     code->setAction(Fb::EditUndo, act);
     code->setAction(Fb::EditUndo, act);
     act->setPriority(QAction::LowPriority);
     act->setPriority(QAction::LowPriority);
@@ -236,7 +236,7 @@ void FbMainWindow::createActions()
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    act = new QAction(FbIcon("edit-cut"), tr("Cu&t"), this);
+    act = new FbTextAction(FbIcon("edit-cut"), tr("Cu&t"), QWebPage::Cut, text);
     text->setAction(Fb::EditCut, act);
     text->setAction(Fb::EditCut, act);
     code->setAction(Fb::EditCut, act);
     code->setAction(Fb::EditCut, act);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcutContext(Qt::WidgetShortcut);
@@ -246,7 +246,7 @@ void FbMainWindow::createActions()
     act->setEnabled(false);
     act->setEnabled(false);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    act = new QAction(FbIcon("edit-copy"), tr("&Copy"), this);
+    act = new FbTextAction(FbIcon("edit-copy"), tr("&Copy"), QWebPage::Copy, text);
     text->setAction(Fb::EditCopy, act);
     text->setAction(Fb::EditCopy, act);
     code->setAction(Fb::EditCopy, act);
     code->setAction(Fb::EditCopy, act);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcutContext(Qt::WidgetShortcut);
@@ -256,7 +256,7 @@ void FbMainWindow::createActions()
     act->setEnabled(false);
     act->setEnabled(false);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    act = new QAction(FbIcon("edit-paste"), tr("&Paste"), this);
+    act = new FbTextAction(FbIcon("edit-paste"), tr("&Paste"), QWebPage::Paste, text);
     text->setAction(Fb::EditPaste, act);
     text->setAction(Fb::EditPaste, act);
     code->setAction(Fb::EditPaste, act);
     code->setAction(Fb::EditPaste, act);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcutContext(Qt::WidgetShortcut);
@@ -265,6 +265,7 @@ void FbMainWindow::createActions()
     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);
 
 
+    act = new FbTextAction(FbIcon("Paste (no style)"), tr("&Paste"), QWebPage::PasteAndMatchStyle, text);
     act = new QAction(tr("Paste (no style)"), this);
     act = new QAction(tr("Paste (no style)"), this);
     text->setAction(Fb::PasteText, act);
     text->setAction(Fb::PasteText, act);
     menu->addAction(act);
     menu->addAction(act);
@@ -408,15 +409,15 @@ void FbMainWindow::createActions()
 
 
     menu->addSeparator();
     menu->addSeparator();
 
 
-    act = new FbTextAction(FbIcon("format-indent-more"), tr("Create section"), QWebPage::ToggleSubscript, text);
+    act = new QAction(FbIcon("format-indent-more"), tr("Create section"), text);
     text->setAction(Fb::SectionAdd, act);
     text->setAction(Fb::SectionAdd, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    act = new FbTextAction(FbIcon("format-indent-less"), tr("Remove section"), QWebPage::ToggleSubscript, text);
+    act = new QAction(FbIcon("format-indent-less"), tr("Remove section"), text);
     text->setAction(Fb::SectionDel, act);
     text->setAction(Fb::SectionDel, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
-    act = new FbTextAction(FbIcon("format-justify-center"), tr("Make title"), QWebPage::ToggleSubscript, text);
+    act = new QAction(FbIcon("format-justify-center"), tr("Make title"), text);
     text->setAction(Fb::TextTitle, act);
     text->setAction(Fb::TextTitle, act);
     menu->addAction(act);
     menu->addAction(act);
 
 
@@ -480,7 +481,7 @@ void FbMainWindow::createActions()
     menu->addAction(act);
     menu->addAction(act);
 
 
     act = new QAction(tr("&Web inspector"), this);
     act = new QAction(tr("&Web inspector"), this);
-    text->setAction(Fb::ViewInspect, act);
+    text->setAction(Fb::ViewInspector, act);
     act->setCheckable(true);
     act->setCheckable(true);
     menu->addAction(act);
     menu->addAction(act);
 
 

+ 1 - 1
source/fb2mode.h

@@ -54,7 +54,7 @@ enum Actions {
     SectionDel,
     SectionDel,
     ViewContents,
     ViewContents,
     ViewPictures,
     ViewPictures,
-    ViewInspect,
+    ViewInspector,
     ZoomIn,
     ZoomIn,
     ZoomOut,
     ZoomOut,
     ZoomReset,
     ZoomReset,

+ 1 - 1
source/fb2temp.cpp

@@ -348,7 +348,7 @@ FbListWidget::FbListWidget(FbTextEdit *text, QWidget* parent)
     m_list = new FbListView(text->files(), splitter);
     m_list = new FbListView(text->files(), splitter);
     splitter->addWidget(m_list);
     splitter->addWidget(m_list);
 
 
-    FbWebFrame *frame = new FbWebFrame(splitter);
+    FbTextFrame *frame = new FbTextFrame(splitter);
     splitter->addWidget(frame);
     splitter->addWidget(frame);
 
 
     m_view = new FbTextBase(frame);
     m_view = new FbTextBase(frame);

+ 52 - 42
source/fb2text.cpp

@@ -197,6 +197,11 @@ QAction * FbTextEdit::act(Fb::Actions index) const
     return m_actions[index];
     return m_actions[index];
 }
 }
 
 
+QAction * FbTextEdit::pAct(QWebPage::WebAction index) const
+{
+    return pageAction(index);
+}
+
 void FbTextEdit::setAction(Fb::Actions index, QAction *action)
 void FbTextEdit::setAction(Fb::Actions index, QAction *action)
 {
 {
     m_actions[index] = action;
     m_actions[index] = action;
@@ -206,36 +211,22 @@ void FbTextEdit::connectActions(QToolBar *tool)
 {
 {
     m_actions.connect();
     m_actions.connect();
 
 
-    connect(act(Fb::ViewContents), SIGNAL(triggered(bool)), this, SLOT(viewTree(bool)));
-    connect(act(Fb::ViewPictures), SIGNAL(triggered(bool)), this, SLOT(viewImgs(bool)));
-    connect(act(Fb::ViewInspect), SIGNAL(triggered(bool)), this, SLOT(viewInsp(bool)));
-/*
-    connect(textPage->undoStack(), SIGNAL(cleanChanged(bool)), SLOT(cleanChanged(bool)));
-    connect(textPage->undoStack(), SIGNAL(canUndoChanged(bool)), SLOT(canUndoChanged(bool)));
-    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()));
+    foreach (QAction *action, m_actions) {
+        if (FbTextAction *a = qobject_cast<FbTextAction*>(action)) {
+            a->connectAction();
+        }
+    }
 
 
-    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(act(Fb::ViewContents), SIGNAL(triggered(bool)), this, SLOT(viewContents(bool)));
+    connect(act(Fb::ViewPictures), SIGNAL(triggered(bool)), this, SLOT(viewPictures(bool)));
+    connect(act(Fb::ViewInspector), SIGNAL(triggered(bool)), this, SLOT(viewInspector(bool)));
 
 
-    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(act(Fb::ZoomIn), SIGNAL(triggered()), SLOT(zoomIn()));
+    connect(act(Fb::ZoomOut), SIGNAL(triggered()), SLOT(zoomOut()));
+    connect(act(Fb::ZoomReset), SIGNAL(triggered()), SLOT(zoomReset()));
 
 
-    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(textPage, SIGNAL(selectionChanged()), SLOT(selectionChanged()));
 
 
     connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(find()));
     connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(find()));
     connect(actionImage, SIGNAL(triggered()), textEdit, SLOT(insertImage()));
     connect(actionImage, SIGNAL(triggered()), textEdit, SLOT(insertImage()));
@@ -261,10 +252,6 @@ void FbTextEdit::connectActions(QToolBar *tool)
     connect(actionSectionDel, SIGNAL(triggered()), textPage, SLOT(deleteSection()));
     connect(actionSectionDel, SIGNAL(triggered()), textPage, SLOT(deleteSection()));
     connect(actionTextTitle, SIGNAL(triggered()), textPage, SLOT(createTitle()));
     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->clear();
@@ -299,10 +286,16 @@ void FbTextEdit::connectActions(QToolBar *tool)
 
 
 void FbTextEdit::disconnectActions()
 void FbTextEdit::disconnectActions()
 {
 {
-    m_actions.disconnect();
+    foreach (QAction *action, m_actions) {
+        if (FbTextAction *a = qobject_cast<FbTextAction*>(action)) {
+            a->disconnectAction();
+        } else {
+            action->disconnect();
+        }
+    }
 }
 }
 
 
-void FbTextEdit::viewTree(bool show)
+void FbTextEdit::viewContents(bool show)
 {
 {
     if (show) {
     if (show) {
         if (dockTree) { dockTree->show(); return; }
         if (dockTree) { dockTree->show(); return; }
@@ -317,7 +310,7 @@ void FbTextEdit::viewTree(bool show)
     }
     }
 }
 }
 
 
-void FbTextEdit::viewImgs(bool show)
+void FbTextEdit::viewPictures(bool show)
 {
 {
     if (show) {
     if (show) {
         if (dockImgs) { dockImgs->show(); return; }
         if (dockImgs) { dockImgs->show(); return; }
@@ -332,7 +325,7 @@ void FbTextEdit::viewImgs(bool show)
     }
     }
 }
 }
 
 
-void FbTextEdit::viewInsp(bool show)
+void FbTextEdit::viewInspector(bool show)
 {
 {
     if (show) {
     if (show) {
         if (dockInsp) { dockInsp->show(); return; }
         if (dockInsp) { dockInsp->show(); return; }
@@ -341,7 +334,7 @@ void FbTextEdit::viewInsp(bool show)
         dockInsp = new QDockWidget(tr("Web inspector"), this);
         dockInsp = new QDockWidget(tr("Web inspector"), this);
         dockInsp->setFeatures(QDockWidget::AllDockWidgetFeatures);
         dockInsp->setFeatures(QDockWidget::AllDockWidgetFeatures);
         dockInsp->setWidget(inspector);
         dockInsp->setWidget(inspector);
-        connect(dockInsp, SIGNAL(visibilityChanged(bool)), act(Fb::ViewInspect), SLOT(setChecked(bool)));
+        connect(dockInsp, SIGNAL(visibilityChanged(bool)), act(Fb::ViewInspector), SLOT(setChecked(bool)));
         m_owner->addDockWidget(Qt::BottomDockWidgetArea, dockInsp);
         m_owner->addDockWidget(Qt::BottomDockWidgetArea, dockInsp);
     } else {
     } else {
         dockImgs->hide();
         dockImgs->hide();
@@ -588,10 +581,10 @@ void FbTextEdit::execCommand(const QString &cmd, const QString &arg)
 }
 }
 
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
-//  FbWebFrame
+//  FbTextFrame
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
 
-FbWebFrame::FbWebFrame(QWidget *parent)
+FbTextFrame::FbTextFrame(QWidget *parent)
     : QFrame(parent)
     : QFrame(parent)
 {
 {
     setFrameShape(QFrame::StyledPanel);
     setFrameShape(QFrame::StyledPanel);
@@ -626,13 +619,30 @@ QAction * FbTextAction::action(QWebPage::WebAction action)
     return m_parent->pageAction(m_action);
     return m_parent->pageAction(m_action);
 }
 }
 
 
-void FbTextAction::updateChecked()
+void FbTextAction::updateAction()
 {
 {
-    if (QAction * act = action(m_action)) setChecked(act->isChecked());
+    if (QAction * act = action(m_action)) {
+        if (isCheckable()) setChecked(act->isChecked());
+        setEnabled(act->isEnabled());
+    }
 }
 }
 
 
-void FbTextAction::updateEnabled()
+void FbTextAction::connectAction()
 {
 {
-    if (QAction * act = action(m_action)) setEnabled(act->isEnabled());
+    if (QAction * act = action(m_action)) {
+        connect(this, SIGNAL(triggered(bool)), act, SIGNAL(triggered(bool)));
+        connect(act, SIGNAL(changed()), this, SLOT(updateAction()));
+        if (isCheckable()) setChecked(act->isChecked());
+        setEnabled(act->isEnabled());
+    } else {
+        if (isCheckable()) setChecked(false);
+        setEnabled(false);
+    }
 }
 }
 
 
+void FbTextAction::disconnectAction()
+{
+    QAction * act = action(m_action);
+    disconnect(act, 0, this, 0);
+    disconnect(this, 0, act, 0);
+}

+ 13 - 11
source/fb2text.hpp

@@ -83,6 +83,7 @@ public:
     bool save(QString *string);
     bool save(QString *string);
 
 
     QAction * act(Fb::Actions index) const;
     QAction * act(Fb::Actions index) const;
+    QAction * pAct(QWebPage::WebAction index) const;
     void setAction(Fb::Actions index, QAction *action);
     void setAction(Fb::Actions index, QAction *action);
     void connectActions(QToolBar *tool);
     void connectActions(QToolBar *tool);
     void disconnectActions();
     void disconnectActions();
@@ -102,9 +103,6 @@ public slots:
     void insertImage();
     void insertImage();
     void insertNote();
     void insertNote();
     void insertLink();
     void insertLink();
-    void zoomIn();
-    void zoomOut();
-    void zoomReset();
     void find();
     void find();
 
 
 private slots:
 private slots:
@@ -112,9 +110,12 @@ private slots:
     void contextMenu(const QPoint &pos);
     void contextMenu(const QPoint &pos);
     void treeDestroyed();
     void treeDestroyed();
     void imgsDestroyed();
     void imgsDestroyed();
-    void viewTree(bool show);
-    void viewImgs(bool show);
-    void viewInsp(bool show);
+    void viewContents(bool show);
+    void viewPictures(bool show);
+    void viewInspector(bool show);
+    void zoomIn();
+    void zoomOut();
+    void zoomReset();
 
 
 private:
 private:
     bool actionEnabled(QWebPage::WebAction action);
     bool actionEnabled(QWebPage::WebAction action);
@@ -136,11 +137,11 @@ private:
     QPoint m_point;
     QPoint m_point;
 };
 };
 
 
-class FbWebFrame : public QFrame
+class FbTextFrame : public QFrame
 {
 {
     Q_OBJECT
     Q_OBJECT
 public:
 public:
-    explicit FbWebFrame(QWidget *parent = 0);
+    explicit FbTextFrame(QWidget *parent = 0);
 };
 };
 
 
 class FbTextAction : public QAction
 class FbTextAction : public QAction
@@ -150,10 +151,11 @@ class FbTextAction : public QAction
 public:
 public:
     explicit FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit* parent);
     explicit FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit* parent);
     explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit *parent);
     explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit *parent);
+    void connectAction();
+    void disconnectAction();
 
 
-public slots:
-    void updateChecked();
-    void updateEnabled();
+private slots:
+    void updateAction();
 
 
 private:
 private:
     QAction * action(QWebPage::WebAction action);
     QAction * action(QWebPage::WebAction action);