Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lintest/fb2edit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKandrashin Denis <mail@lintest.ru>2012-09-16 17:26:24 +0400
committerKandrashin Denis <mail@lintest.ru>2012-09-16 17:26:24 +0400
commitc74aad6ef5d4878f7848b1aa1d788b9cd63fdc71 (patch)
treea24993a7531a9d7e0bb74d0aa28f6d68dd08974c
parent95e15c351bdc5d90767a7afcd678af21bf51e075 (diff)
New class: FbTextAction
-rw-r--r--3rdparty/gnome/16x16/edit-clear.pngbin0 -> 739 bytes
-rw-r--r--source/fb2main.cpp55
-rw-r--r--source/fb2main.hpp7
-rw-r--r--source/fb2text.cpp26
-rw-r--r--source/fb2text.hpp22
5 files changed, 84 insertions, 26 deletions
diff --git a/3rdparty/gnome/16x16/edit-clear.png b/3rdparty/gnome/16x16/edit-clear.png
new file mode 100644
index 0000000..3be482d
--- /dev/null
+++ b/3rdparty/gnome/16x16/edit-clear.png
Binary files differ
diff --git a/source/fb2main.cpp b/source/fb2main.cpp
index 981fa7d..d41e450 100644
--- a/source/fb2main.cpp
+++ b/source/fb2main.cpp
@@ -24,6 +24,21 @@ FbDockWidget::FbDockWidget(const QString &title, QWidget *parent, Qt::WindowFlag
}
//---------------------------------------------------------------------------
+// FbTextAction
+//---------------------------------------------------------------------------
+
+QAction * FbTextAction::action(QWebPage::WebAction action)
+{
+ FbMainWindow * main = qobject_cast<FbMainWindow*>(parent());
+ if (!main) return 0;
+
+ FbTextPage * page = main->page();
+ if (!page) return 0;
+
+ return page->action(action);
+}
+
+//---------------------------------------------------------------------------
// FbMainWindow
//---------------------------------------------------------------------------
@@ -61,6 +76,11 @@ FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
}
}
+FbTextPage * FbMainWindow::page()
+{
+ return textFrame ? textFrame->view()->page() : 0;
+}
+
void FbMainWindow::logMessage(const QString &message)
{
if (!messageEdit) {
@@ -378,30 +398,30 @@ void FbMainWindow::createActions()
menuText = menu = menuBar()->addMenu(tr("Fo&rmat"));
- actionClearFormat = act = new QAction(FbIcon("edit-clear"), tr("Clear format"), this);
+ actionClearFormat = act = new FbTextAction(FbIcon("edit-clear"), tr("Clear format"), QWebPage::RemoveFormat, this);
menu->addAction(act);
menu->addSeparator();
- actionTextBold = act = new QAction(FbIcon("format-text-bold"), tr("&Bold"), this);
+ actionTextBold = act = new FbTextAction(FbIcon("format-text-bold"), tr("&Bold"), QWebPage::ToggleBold, this);
act->setShortcuts(QKeySequence::Bold);
act->setCheckable(true);
menu->addAction(act);
- actionTextItalic = act = new QAction(FbIcon("format-text-italic"), tr("&Italic"), this);
+ actionTextItalic = act = new FbTextAction(FbIcon("format-text-italic"), tr("&Italic"), QWebPage::ToggleItalic, this);
act->setShortcuts(QKeySequence::Italic);
act->setCheckable(true);
menu->addAction(act);
- actionTextStrike = act = new QAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), this);
+ actionTextStrike = act = new FbTextAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), QWebPage::ToggleStrikethrough, this);
act->setCheckable(true);
menu->addAction(act);
- actionTextSup = act = new QAction(FbIcon("format-text-superscript"), tr("Su&perscript"), this);
+ actionTextSup = act = new FbTextAction(FbIcon("format-text-superscript"), tr("Su&perscript"), QWebPage::ToggleSuperscript, this);
act->setCheckable(true);
menu->addAction(act);
- actionTextSub = act = new QAction(FbIcon("format-text-subscript"), tr("Su&bscript"), this);
+ actionTextSub = act = new FbTextAction(FbIcon("format-text-subscript"), tr("Su&bscript"), QWebPage::ToggleSubscript, this);
act->setCheckable(true);
menu->addAction(act);
@@ -518,17 +538,6 @@ void FbMainWindow::selectionChanged()
statusBar()->showMessage(view->page()->status());
}
-void FbMainWindow::formatChanged()
-{
- FbTextEdit *view = textFrame->view();
- actionClearFormat->setEnabled(view->actionEnabled(QWebPage::RemoveFormat));
- actionTextBold->setChecked(view->actionChecked(QWebPage::ToggleBold));
- actionTextItalic->setChecked(view->actionChecked(QWebPage::ToggleItalic));
- actionTextStrike->setChecked(view->actionChecked(QWebPage::ToggleStrikethrough));
- actionTextSub->setChecked(view->actionChecked(QWebPage::ToggleSubscript));
- actionTextSup->setChecked(view->actionChecked(QWebPage::ToggleSuperscript));
-}
-
void FbMainWindow::canUndoChanged(bool canUndo)
{
actionUndo->setEnabled(canUndo);
@@ -673,12 +682,12 @@ void FbMainWindow::createTextToolbar()
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()), SLOT(formatChanged()));
- connect(textEdit->pageAction(QWebPage::ToggleBold), SIGNAL(changed()), SLOT(formatChanged()));
- connect(textEdit->pageAction(QWebPage::ToggleItalic), SIGNAL(changed()), SLOT(formatChanged()));
- connect(textEdit->pageAction(QWebPage::ToggleStrikethrough), SIGNAL(changed()), SLOT(formatChanged()));
- connect(textEdit->pageAction(QWebPage::ToggleSubscript), SIGNAL(changed()), SLOT(formatChanged()));
- connect(textEdit->pageAction(QWebPage::ToggleSuperscript), SIGNAL(changed()), SLOT(formatChanged()));
+ 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()));
diff --git a/source/fb2main.hpp b/source/fb2main.hpp
index 06b9ad1..eef1222 100644
--- a/source/fb2main.hpp
+++ b/source/fb2main.hpp
@@ -17,8 +17,9 @@ QT_END_NAMESPACE
class FbCodeEdit;
class FbTreeView;
class FbHeadView;
-class FbTextFrame;
class FbTextEdit;
+class FbTextFrame;
+class FbTextPage;
class FbDockWidget : public QDockWidget
{
@@ -35,6 +36,9 @@ public:
enum ViewMode { FB2, XML };
explicit FbMainWindow(const QString &filename = QString(), ViewMode mode = FB2);
+public:
+ FbTextPage * page();
+
protected:
void closeEvent(QCloseEvent *event);
@@ -70,7 +74,6 @@ private slots:
void status(const QString &text);
void clipboardDataChanged();
void selectionChanged();
- void formatChanged();
void undoChanged();
void redoChanged();
void openSettings();
diff --git a/source/fb2text.cpp b/source/fb2text.cpp
index f936a09..4a114a6 100644
--- a/source/fb2text.cpp
+++ b/source/fb2text.cpp
@@ -726,3 +726,29 @@ void FbTextFrame::dockDestroyed()
m_dock = 0;
}
+//---------------------------------------------------------------------------
+// FbTextAction
+//---------------------------------------------------------------------------
+
+FbTextAction::FbTextAction(const QString &text, QWebPage::WebAction action, QObject* parent)
+ : QAction(text, parent)
+ , m_action(action)
+{
+}
+
+FbTextAction::FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, QObject* parent)
+ : QAction(icon, text, parent)
+ , m_action(action)
+{
+}
+
+void FbTextAction::updateChecked()
+{
+ if (QAction * act = action(m_action)) setChecked(act->isChecked());
+}
+
+void FbTextAction::updateEnabled()
+{
+ if (QAction * act = action(m_action)) setEnabled(act->isEnabled());
+}
+
diff --git a/source/fb2text.hpp b/source/fb2text.hpp
index 54c573f..38550fb 100644
--- a/source/fb2text.hpp
+++ b/source/fb2text.hpp
@@ -1,6 +1,7 @@
#ifndef FB2TEXT_H
#define FB2TEXT_H
+#include <QAction>
#include <QFrame>
#include <QResizeEvent>
#include <QTimer>
@@ -168,7 +169,7 @@ public:
~FbTextFrame();
public:
- FbTextEdit *view() { return &m_view; }
+ FbTextEdit * view() { return &m_view; }
public slots:
void showInspector();
@@ -182,4 +183,23 @@ private:
QDockWidget *m_dock;
};
+class FbTextAction : public QAction
+{
+ Q_OBJECT
+
+public:
+ explicit FbTextAction(const QString &text, QWebPage::WebAction action, QObject* parent);
+ explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, QObject* parent);
+
+public slots:
+ void updateChecked();
+ void updateEnabled();
+
+private:
+ QAction * action(QWebPage::WebAction action);
+
+private:
+ QWebPage::WebAction m_action;
+};
+
#endif // FB2TEXT_H