Ver código fonte

Class Fb2NoteDlg: create toolbar

Kandrashin Denis 13 anos atrás
pai
commit
82fe59d867
6 arquivos alterados com 149 adições e 111 exclusões
  1. 30 105
      source/fb2main.cpp
  2. 0 1
      source/fb2main.hpp
  3. 4 0
      source/fb2note.cpp
  4. 21 5
      source/fb2note.ui
  5. 83 0
      source/fb2utils.cpp
  6. 11 0
      source/fb2utils.h

+ 30 - 105
source/fb2main.cpp

@@ -196,14 +196,6 @@ void Fb2MainWindow::documentWasModified()
     if (textEdit) disconnect(textEdit->page(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));
 }
 
-QIcon Fb2MainWindow::icon(const QString &name)
-{
-    QIcon icon;
-    icon.addFile(QString(":/24x24/%1.png").arg(name), QSize(24,24));
-    icon.addFile(QString(":/16x24/%1.png").arg(name), QSize(16,16));
-    return QIcon::fromTheme(name, icon);
-}
-
 void Fb2MainWindow::createActions()
 {
     QAction * act;
@@ -215,7 +207,7 @@ void Fb2MainWindow::createActions()
     tool = addToolBar(tr("File"));
     tool->setMovable(false);
 
-    act = new QAction(icon("document-new"), tr("&New"), this);
+    act = new QAction(FB2::icon("document-new"), tr("&New"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::New);
     act->setStatusTip(tr("Create a new file"));
@@ -223,21 +215,21 @@ void Fb2MainWindow::createActions()
     menu->addAction(act);
     tool->addAction(act);
 
-    act = new QAction(icon("document-open"), tr("&Open..."), this);
+    act = new QAction(FB2::icon("document-open"), tr("&Open..."), this);
     act->setShortcuts(QKeySequence::Open);
     act->setStatusTip(tr("Open an existing file"));
     connect(act, SIGNAL(triggered()), this, SLOT(fileOpen()));
     menu->addAction(act);
     tool->addAction(act);
 
-    act = new QAction(icon("document-save"), tr("&Save"), this);
+    act = new QAction(FB2::icon("document-save"), tr("&Save"), this);
     act->setShortcuts(QKeySequence::Save);
     act->setStatusTip(tr("Save the document to disk"));
     connect(act, SIGNAL(triggered()), this, SLOT(fileSave()));
     menu->addAction(act);
     tool->addAction(act);
 
-    act = new QAction(icon("document-save-as"), tr("Save &As..."), this);
+    act = new QAction(FB2::icon("document-save-as"), tr("Save &As..."), this);
     act->setShortcuts(QKeySequence::SaveAs);
     act->setStatusTip(tr("Save the document under a new name"));
     connect(act, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
@@ -245,13 +237,13 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    act = new QAction(icon("window-close"), tr("&Close"), this);
+    act = new QAction(FB2::icon("window-close"), tr("&Close"), this);
     act->setShortcuts(QKeySequence::Close);
     act->setStatusTip(tr("Close this window"));
     connect(act, SIGNAL(triggered()), this, SLOT(close()));
     menu->addAction(act);
 
-    act = new QAction(icon("application-exit"), tr("E&xit"), this);
+    act = new QAction(FB2::icon("application-exit"), tr("E&xit"), this);
     act->setShortcuts(QKeySequence::Quit);
     act->setStatusTip(tr("Exit the application"));
     connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
@@ -261,13 +253,13 @@ void Fb2MainWindow::createActions()
 
     connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
 
-    actionUndo = act = new QAction(icon("edit-undo"), tr("&Undo"), this);
+    actionUndo = act = new QAction(FB2::icon("edit-undo"), tr("&Undo"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Undo);
     act->setEnabled(false);
     menu->addAction(act);
 
-    actionRedo = act = new QAction(icon("edit-redo"), tr("&Redo"), this);
+    actionRedo = act = new QAction(FB2::icon("edit-redo"), tr("&Redo"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Redo);
     act->setEnabled(false);
@@ -275,21 +267,21 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    actionCut = act = new QAction(icon("edit-cut"), tr("Cu&t"), this);
+    actionCut = act = new QAction(FB2::icon("edit-cut"), tr("Cu&t"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Cut);
     act->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
     act->setEnabled(false);
     menu->addAction(act);
 
-    actionCopy = act = new QAction(icon("edit-copy"), tr("&Copy"), this);
+    actionCopy = act = new QAction(FB2::icon("edit-copy"), tr("&Copy"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Copy);
     act->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
     act->setEnabled(false);
     menu->addAction(act);
 
-    actionPaste = act = new QAction(icon("edit-paste"), tr("&Paste"), this);
+    actionPaste = act = new QAction(FB2::icon("edit-paste"), tr("&Paste"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Paste);
     act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
@@ -298,28 +290,28 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    actionFind = act = new QAction(icon("edit-find"), tr("&Find..."), this);
+    actionFind = act = new QAction(FB2::icon("edit-find"), tr("&Find..."), this);
     act->setShortcuts(QKeySequence::Find);
     menu->addAction(act);
 
-    actionReplace = act = new QAction(icon("edit-find-replace"), tr("&Replace..."), this);
+    actionReplace = act = new QAction(FB2::icon("edit-find-replace"), tr("&Replace..."), this);
     menu->addAction(act);
 
     menu->addSeparator();
 
-    actionInsert = act = new QAction(icon("list-add"), tr("&Append"), this);
+    actionInsert = act = new QAction(FB2::icon("list-add"), tr("&Append"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::New);
     menu->addAction(act);
 
-    actionDelete = act = new QAction(icon("list-remove"), tr("&Delete"), this);
+    actionDelete = act = new QAction(FB2::icon("list-remove"), tr("&Delete"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Delete);
     menu->addAction(act);
 
     menu->addSeparator();
 
-    act = new QAction(icon("preferences-desktop"), tr("&Settings"), this);
+    act = new QAction(FB2::icon("preferences-desktop"), tr("&Settings"), this);
     act->setShortcuts(QKeySequence::Preferences);
     act->setStatusTip(tr("Application settings"));
     connect(act, SIGNAL(triggered()), SLOT(openSettings()));
@@ -327,39 +319,39 @@ void Fb2MainWindow::createActions()
 
     menu = menuBar()->addMenu(tr("&Insert", "Main menu"));
 
-    actionImage = act = new QAction(icon("insert-image"), tr("&Image"), this);
+    actionImage = act = new QAction(FB2::icon("insert-image"), tr("&Image"), this);
     menu->addAction(act);
 
-    actionNote = act = new QAction(icon("insert-text"), tr("&Footnote"), this);
+    actionNote = act = new QAction(FB2::icon("insert-text"), tr("&Footnote"), this);
     menu->addAction(act);
 
-    actionLink = act = new QAction(icon("insert-link"), tr("&Hiperlink"), this);
+    actionLink = act = new QAction(FB2::icon("insert-link"), tr("&Hiperlink"), this);
     menu->addAction(act);
 
-    actionBody = act = new QAction(icon("insert-object"), tr("&Body"), this);
+    actionBody = act = new QAction(FB2::icon("insert-object"), tr("&Body"), this);
     menu->addAction(act);
 
     menuText = menu = menuBar()->addMenu(tr("Fo&rmat"));
 
-    actionTextBold = act = new QAction(icon("format-text-bold"), tr("&Bold"), this);
+    actionTextBold = act = new QAction(FB2::icon("format-text-bold"), tr("&Bold"), this);
     act->setShortcuts(QKeySequence::Bold);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextItalic = act = new QAction(icon("format-text-italic"), tr("&Italic"), this);
+    actionTextItalic = act = new QAction(FB2::icon("format-text-italic"), tr("&Italic"), this);
     act->setShortcuts(QKeySequence::Italic);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextStrike = act = new QAction(icon("format-text-strikethrough"), tr("&Strikethrough"), this);
+    actionTextStrike = act = new QAction(FB2::icon("format-text-strikethrough"), tr("&Strikethrough"), this);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextSup = act = new QAction(icon("format-text-superscript"), tr("Su&perscript"), this);
+    actionTextSup = act = new QAction(FB2::icon("format-text-superscript"), tr("Su&perscript"), this);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextSub = act = new QAction(icon("format-text-subscript"), tr("Su&bscript"), this);
+    actionTextSub = act = new QAction(FB2::icon("format-text-subscript"), tr("Su&bscript"), this);
     act->setCheckable(true);
     menu->addAction(act);
 
@@ -393,15 +385,15 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    actionZoomIn = act = new QAction(icon("zoom-in"), tr("Zoom in"), this);
+    actionZoomIn = act = new QAction(FB2::icon("zoom-in"), tr("Zoom in"), this);
     act->setShortcuts(QKeySequence::ZoomIn);
     menu->addAction(act);
 
-    actionZoomOut = act = new QAction(icon("zoom-out"), tr("Zoom out"), this);
+    actionZoomOut = act = new QAction(FB2::icon("zoom-out"), tr("Zoom out"), this);
     act->setShortcuts(QKeySequence::ZoomOut);
     menu->addAction(act);
 
-    actionZoomOrig = act = new QAction(icon("zoom-original"), tr("Zoom original"), this);
+    actionZoomOrig = act = new QAction(FB2::icon("zoom-original"), tr("Zoom original"), this);
     menu->addAction(act);
 
     menu->addSeparator();
@@ -417,7 +409,7 @@ void Fb2MainWindow::createActions()
     menuBar()->addSeparator();
     menu = menuBar()->addMenu(tr("&Help"));
 
-    act = new QAction(icon("help-about"), tr("&About"), this);
+    act = new QAction(FB2::icon("help-about"), tr("&About"), this);
     act->setStatusTip(tr("Show the application's About box"));
     connect(act, SIGNAL(triggered()), this, SLOT(about()));
     menu->addAction(act);
@@ -694,74 +686,7 @@ void Fb2MainWindow::viewText()
     tool->setMovable(false);
     tool->addSeparator();
 
-    QAction *act;
-
-    act = textEdit->pageAction(QWebPage::Undo);
-    act->setIcon(icon("edit-undo"));
-    act->setText(tr("&Undo"));
-    act->setPriority(QAction::LowPriority);
-    act->setShortcut(QKeySequence::Undo);
-    tool->addAction(act);
-
-    act = textEdit->pageAction(QWebPage::Redo);
-    act->setIcon(icon("edit-redo"));
-    act->setText(tr("&Redo"));
-    act->setPriority(QAction::LowPriority);
-    act->setShortcut(QKeySequence::Redo);
-    tool->addAction(act);
-
-    tool->addSeparator();
-
-    act = textEdit->pageAction(QWebPage::Cut);
-    act->setIcon(icon("edit-cut"));
-    act->setText(tr("Cu&t"));
-    act->setPriority(QAction::LowPriority);
-    act->setShortcuts(QKeySequence::Cut);
-    act->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
-    tool->addAction(act);
-
-    act = textEdit->pageAction(QWebPage::Copy);
-    act->setIcon(icon("edit-copy"));
-    act->setText(tr("&Copy"));
-    act->setPriority(QAction::LowPriority);
-    act->setShortcuts(QKeySequence::Copy);
-    act->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
-    tool->addAction(act);
-
-    act = textEdit->pageAction(QWebPage::Paste);
-    act->setIcon(icon("edit-paste"));
-    act->setText(tr("&Paste"));
-    act->setPriority(QAction::LowPriority);
-    act->setShortcuts(QKeySequence::Paste);
-    act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
-    tool->addAction(act);
-
-    tool->addSeparator();
-
-    act = textEdit->pageAction(QWebPage::ToggleBold);
-    act->setIcon(icon("format-text-bold"));
-    act->setText(tr("&Bold"));
-    tool->addAction(act);
-
-    act = textEdit->pageAction(QWebPage::ToggleItalic);
-    act->setIcon(icon("format-text-italic"));
-    act->setText(tr("&Italic"));
-    tool->addAction(act);
-
-    act = textEdit->pageAction(QWebPage::ToggleStrikethrough);
-    act->setIcon(icon("format-text-strikethrough"));
-    act->setText(tr("&Strikethrough"));
-    tool->addAction(act);
-
-    act = textEdit->pageAction(QWebPage::ToggleSuperscript);
-    act->setIcon(icon("format-text-superscript"));
-    act->setText(tr("Su&perscript"));
-    tool->addAction(act);
-
-    act = textEdit->pageAction(QWebPage::ToggleSubscript);
-    act->setIcon(icon("format-text-subscript"));
-    act->setText(tr("Su&bscript"));
-    tool->addAction(act);
+    FB2::addTools(tool, textEdit);
 
     tool->addSeparator();
 

+ 0 - 1
source/fb2main.hpp

@@ -61,7 +61,6 @@ private slots:
 
 private:
     bool loadXML(const QString &filename);
-    QIcon icon(const QString &name);
 
 private:
     void init();

+ 4 - 0
source/fb2note.cpp

@@ -1,5 +1,6 @@
 #include "fb2note.hpp"
 #include "fb2view.hpp"
+#include "fb2utils.h"
 #include "ui_fb2note.h"
 
 Fb2NoteDlg::Fb2NoteDlg(Fb2WebView &view, QWidget *parent) :
@@ -13,7 +14,10 @@ Fb2NoteDlg::Fb2NoteDlg(Fb2WebView &view, QWidget *parent) :
 
     Fb2WebPage *page = new Fb2WebPage(this);
     page->setNetworkAccessManager(view.page()->networkAccessManager());
+    page->setContentEditable(true);
     ui->m_text->setPage(page);
+
+    FB2::addTools(ui->m_toolbar, ui->m_text);
 }
 
 Fb2NoteDlg::~Fb2NoteDlg()

+ 21 - 5
source/fb2note.ui

@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
+    <width>460</width>
     <height>300</height>
    </rect>
   </property>
@@ -24,7 +24,7 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="0" colspan="2">
+   <item row="4" column="0" colspan="2">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -34,7 +34,7 @@
      </property>
     </widget>
    </item>
-   <item row="2" column="0" colspan="2">
+   <item row="3" column="0" colspan="2">
     <widget class="QWebView" name="m_text">
      <property name="url">
       <url>
@@ -44,7 +44,7 @@
     </widget>
    </item>
    <item row="0" column="0">
-    <widget class="QLabel" name="label">
+    <widget class="QLabel" name="label1">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
        <horstretch>0</horstretch>
@@ -60,12 +60,28 @@
     <widget class="QLineEdit" name="m_title"/>
    </item>
    <item row="1" column="0">
-    <widget class="QLabel" name="label_2">
+    <widget class="QLabel" name="label2">
      <property name="text">
       <string>Title:</string>
      </property>
     </widget>
    </item>
+   <item row="2" column="0" colspan="2">
+    <widget class="QToolBar" name="m_toolbar">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="floatable">
+      <bool>true</bool>
+     </property>
+     <property name="text" stdset="0">
+      <string>TextLabel</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <customwidgets>

+ 83 - 0
source/fb2utils.cpp

@@ -1,10 +1,21 @@
 #include "fb2utils.h"
 
+#include <QAction>
 #include <QFile>
 #include <QTextStream>
+#include <QToolBar>
+#include <QWebView>
 
 namespace FB2 {
 
+QIcon icon(const QString &name)
+{
+    QIcon icon;
+    icon.addFile(QString(":/24x24/%1.png").arg(name), QSize(24,24));
+    icon.addFile(QString(":/16x24/%1.png").arg(name), QSize(16,16));
+    return QIcon::fromTheme(name, icon);
+}
+
 QString read(const QString &filename)
 {
     // TODO: throw an exception instead of
@@ -24,4 +35,76 @@ QString read(const QString &filename)
     return in.readAll();
 }
 
+void addTools(QToolBar *tool, QWebView *view)
+{
+    QAction *act;
+
+    act = view->pageAction(QWebPage::Undo);
+    act->setIcon(FB2::icon("edit-undo"));
+    act->setText(QObject::tr("&Undo"));
+    act->setPriority(QAction::LowPriority);
+    act->setShortcut(QKeySequence::Undo);
+    tool->addAction(act);
+
+    act = view->pageAction(QWebPage::Redo);
+    act->setIcon(FB2::icon("edit-redo"));
+    act->setText(QObject::tr("&Redo"));
+    act->setPriority(QAction::LowPriority);
+    act->setShortcut(QKeySequence::Redo);
+    tool->addAction(act);
+
+    tool->addSeparator();
+
+    act = view->pageAction(QWebPage::Cut);
+    act->setIcon(FB2::icon("edit-cut"));
+    act->setText(QObject::tr("Cu&t"));
+    act->setPriority(QAction::LowPriority);
+    act->setShortcuts(QKeySequence::Cut);
+    act->setStatusTip(QObject::tr("Cut the current selection's contents to the clipboard"));
+    tool->addAction(act);
+
+    act = view->pageAction(QWebPage::Copy);
+    act->setIcon(FB2::icon("edit-copy"));
+    act->setText(QObject::tr("&Copy"));
+    act->setPriority(QAction::LowPriority);
+    act->setShortcuts(QKeySequence::Copy);
+    act->setStatusTip(QObject::tr("Copy the current selection's contents to the clipboard"));
+    tool->addAction(act);
+
+    act = view->pageAction(QWebPage::Paste);
+    act->setIcon(FB2::icon("edit-paste"));
+    act->setText(QObject::tr("&Paste"));
+    act->setPriority(QAction::LowPriority);
+    act->setShortcuts(QKeySequence::Paste);
+    act->setStatusTip(QObject::tr("Paste the clipboard's contents into the current selection"));
+    tool->addAction(act);
+
+    tool->addSeparator();
+
+    act = view->pageAction(QWebPage::ToggleBold);
+    act->setIcon(FB2::icon("format-text-bold"));
+    act->setText(QObject::tr("&Bold"));
+    tool->addAction(act);
+
+    act = view->pageAction(QWebPage::ToggleItalic);
+    act->setIcon(FB2::icon("format-text-italic"));
+    act->setText(QObject::tr("&Italic"));
+    tool->addAction(act);
+
+    act = view->pageAction(QWebPage::ToggleStrikethrough);
+    act->setIcon(FB2::icon("format-text-strikethrough"));
+    act->setText(QObject::tr("&Strikethrough"));
+    tool->addAction(act);
+
+    act = view->pageAction(QWebPage::ToggleSuperscript);
+    act->setIcon(FB2::icon("format-text-superscript"));
+    act->setText(QObject::tr("Su&perscript"));
+    tool->addAction(act);
+
+    act = view->pageAction(QWebPage::ToggleSubscript);
+    act->setIcon(FB2::icon("format-text-subscript"));
+    act->setText(QObject::tr("Su&bscript"));
+    tool->addAction(act);
+}
+
 }

+ 11 - 0
source/fb2utils.h

@@ -1,14 +1,25 @@
 #ifndef FB2TOOL_H
 #define FB2TOOL_H
 
+#include <QIcon>
 #include <QString>
 
+QT_BEGIN_NAMESPACE
+class QToolBar;
+class QWebView;
+QT_END_NAMESPACE
+
+
 #define FB2DELETE(p) { if ((p) != NULL) { delete (p); (p) = NULL; } }
 
 namespace FB2 {
 
+QIcon icon(const QString &name);
+
 QString read(const QString &filename);
 
+void addTools(QToolBar *tool, QWebView *view);
+
 }
 
 #endif // FB2TOOL_H