Pārlūkot izejas kodu

New class: Fb2Icon

Kandrashin Denis 13 gadi atpakaļ
vecāks
revīzija
c0a5504c3d
7 mainītis faili ar 67 papildinājumiem un 58 dzēšanām
  1. 2 2
      fb2edit.pro
  2. 3 3
      source/fb2head.cpp
  3. 27 27
      source/fb2main.cpp
  4. 11 11
      source/fb2text.cpp
  5. 9 9
      source/fb2tree.cpp
  6. 9 4
      source/fb2utils.cpp
  7. 6 2
      source/fb2utils.h

+ 2 - 2
fb2edit.pro

@@ -8,11 +8,11 @@ HEADERS = \
     source/fb2read.hpp \
     source/fb2temp.hpp \
     source/fb2tree.hpp \
-    source/fb2utils.h \
     source/fb2save.hpp \
     source/fb2dlgs.hpp \
     source/fb2html.h \
-    source/fb2text.hpp
+    source/fb2text.hpp \
+    source/fb2utils.h
 
 SOURCES = \
     source/fb2app.cpp \

+ 3 - 3
source/fb2head.cpp

@@ -463,17 +463,17 @@ Fb2HeadView::Fb2HeadView(Fb2TextEdit &view, QWidget *parent)
 
     setContextMenuPolicy(Qt::ActionsContextMenu);
 
-    actionInsert = act = new QAction(FB2::icon("list-add"), tr("&Append"), this);
+    actionInsert = act = new QAction(Fb2Icon("list-add"), tr("&Append"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(Qt::Key_Insert);
     act->setPriority(QAction::LowPriority);
     connect(act, SIGNAL(triggered()), SLOT(appendNode()));
     addAction(act);
 
-    actionModify = act = new QAction(FB2::icon("list-add"), tr("&Modify"), this);
+    actionModify = act = new QAction(Fb2Icon("list-add"), tr("&Modify"), this);
     act->setPriority(QAction::LowPriority);
 
-    actionDelete = act = new QAction(FB2::icon("list-remove"), tr("&Delete"), this);
+    actionDelete = act = new QAction(Fb2Icon("list-remove"), tr("&Delete"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(Qt::Key_Delete);
     act->setPriority(QAction::LowPriority);

+ 27 - 27
source/fb2main.cpp

@@ -209,7 +209,7 @@ void Fb2MainWindow::createActions()
     tool = addToolBar(tr("File"));
     tool->setMovable(false);
 
-    act = new QAction(FB2::icon("document-new"), tr("&New"), this);
+    act = new QAction(Fb2Icon("document-new"), tr("&New"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::New);
     act->setStatusTip(tr("Create a new file"));
@@ -217,21 +217,21 @@ void Fb2MainWindow::createActions()
     menu->addAction(act);
     tool->addAction(act);
 
-    act = new QAction(FB2::icon("document-open"), tr("&Open..."), this);
+    act = new QAction(Fb2Icon("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(FB2::icon("document-save"), tr("&Save"), this);
+    act = new QAction(Fb2Icon("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(FB2::icon("document-save-as"), tr("Save &As..."), this);
+    act = new QAction(Fb2Icon("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()));
@@ -239,13 +239,13 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    act = new QAction(FB2::icon("window-close"), tr("&Close"), this);
+    act = new QAction(Fb2Icon("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(FB2::icon("application-exit"), tr("E&xit"), this);
+    act = new QAction(Fb2Icon("application-exit"), tr("E&xit"), this);
     act->setShortcuts(QKeySequence::Quit);
     act->setStatusTip(tr("Exit the application"));
     connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
@@ -255,13 +255,13 @@ void Fb2MainWindow::createActions()
 
     connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
 
-    actionUndo = act = new QAction(FB2::icon("edit-undo"), tr("&Undo"), this);
+    actionUndo = act = new QAction(Fb2Icon("edit-undo"), tr("&Undo"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Undo);
     act->setEnabled(false);
     menu->addAction(act);
 
-    actionRedo = act = new QAction(FB2::icon("edit-redo"), tr("&Redo"), this);
+    actionRedo = act = new QAction(Fb2Icon("edit-redo"), tr("&Redo"), this);
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Redo);
     act->setEnabled(false);
@@ -269,7 +269,7 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    actionCut = act = new QAction(FB2::icon("edit-cut"), tr("Cu&t"), this);
+    actionCut = act = new QAction(Fb2Icon("edit-cut"), tr("Cu&t"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Cut);
@@ -277,7 +277,7 @@ void Fb2MainWindow::createActions()
     act->setEnabled(false);
     menu->addAction(act);
 
-    actionCopy = act = new QAction(FB2::icon("edit-copy"), tr("&Copy"), this);
+    actionCopy = act = new QAction(Fb2Icon("edit-copy"), tr("&Copy"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Copy);
@@ -285,7 +285,7 @@ void Fb2MainWindow::createActions()
     act->setEnabled(false);
     menu->addAction(act);
 
-    actionPaste = act = new QAction(FB2::icon("edit-paste"), tr("&Paste"), this);
+    actionPaste = act = new QAction(Fb2Icon("edit-paste"), tr("&Paste"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Paste);
@@ -295,16 +295,16 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    actionFind = act = new QAction(FB2::icon("edit-find"), tr("&Find..."), this);
+    actionFind = act = new QAction(Fb2Icon("edit-find"), tr("&Find..."), this);
     act->setShortcuts(QKeySequence::Find);
     menu->addAction(act);
 
-    actionReplace = act = new QAction(FB2::icon("edit-find-replace"), tr("&Replace..."), this);
+    actionReplace = act = new QAction(Fb2Icon("edit-find-replace"), tr("&Replace..."), this);
     menu->addAction(act);
 
     menu->addSeparator();
 
-    act = new QAction(FB2::icon("preferences-desktop"), tr("&Settings"), this);
+    act = new QAction(Fb2Icon("preferences-desktop"), tr("&Settings"), this);
     act->setShortcuts(QKeySequence::Preferences);
     act->setStatusTip(tr("Application settings"));
     connect(act, SIGNAL(triggered()), SLOT(openSettings()));
@@ -312,18 +312,18 @@ void Fb2MainWindow::createActions()
 
     menu = menuBar()->addMenu(tr("&Insert", "Main menu"));
 
-    actionImage = act = new QAction(FB2::icon("insert-image"), tr("&Image"), this);
+    actionImage = act = new QAction(Fb2Icon("insert-image"), tr("&Image"), this);
     menu->addAction(act);
 
-    actionNote = act = new QAction(FB2::icon("insert-text"), tr("&Footnote"), this);
+    actionNote = act = new QAction(Fb2Icon("insert-text"), tr("&Footnote"), this);
     menu->addAction(act);
 
-    actionLink = act = new QAction(FB2::icon("insert-link"), tr("&Hiperlink"), this);
+    actionLink = act = new QAction(Fb2Icon("insert-link"), tr("&Hiperlink"), this);
     menu->addAction(act);
 
     menu->addSeparator();
 
-    actionSection = act = new QAction(FB2::icon("insert-object"), tr("&Section"), this);
+    actionSection = act = new QAction(Fb2Icon("insert-object"), tr("&Section"), this);
     menu->addAction(act);
 
     actionTitle = act = new QAction(tr("&Title"), this);
@@ -352,25 +352,25 @@ void Fb2MainWindow::createActions()
 
     menuText = menu = menuBar()->addMenu(tr("Fo&rmat"));
 
-    actionTextBold = act = new QAction(FB2::icon("format-text-bold"), tr("&Bold"), this);
+    actionTextBold = act = new QAction(Fb2Icon("format-text-bold"), tr("&Bold"), this);
     act->setShortcuts(QKeySequence::Bold);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextItalic = act = new QAction(FB2::icon("format-text-italic"), tr("&Italic"), this);
+    actionTextItalic = act = new QAction(Fb2Icon("format-text-italic"), tr("&Italic"), this);
     act->setShortcuts(QKeySequence::Italic);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextStrike = act = new QAction(FB2::icon("format-text-strikethrough"), tr("&Strikethrough"), this);
+    actionTextStrike = act = new QAction(Fb2Icon("format-text-strikethrough"), tr("&Strikethrough"), this);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextSup = act = new QAction(FB2::icon("format-text-superscript"), tr("Su&perscript"), this);
+    actionTextSup = act = new QAction(Fb2Icon("format-text-superscript"), tr("Su&perscript"), this);
     act->setCheckable(true);
     menu->addAction(act);
 
-    actionTextSub = act = new QAction(FB2::icon("format-text-subscript"), tr("Su&bscript"), this);
+    actionTextSub = act = new QAction(Fb2Icon("format-text-subscript"), tr("Su&bscript"), this);
     act->setCheckable(true);
     menu->addAction(act);
 
@@ -404,15 +404,15 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    actionZoomIn = act = new QAction(FB2::icon("zoom-in"), tr("Zoom in"), this);
+    actionZoomIn = act = new QAction(Fb2Icon("zoom-in"), tr("Zoom in"), this);
     act->setShortcuts(QKeySequence::ZoomIn);
     menu->addAction(act);
 
-    actionZoomOut = act = new QAction(FB2::icon("zoom-out"), tr("Zoom out"), this);
+    actionZoomOut = act = new QAction(Fb2Icon("zoom-out"), tr("Zoom out"), this);
     act->setShortcuts(QKeySequence::ZoomOut);
     menu->addAction(act);
 
-    actionZoomReset = act = new QAction(FB2::icon("zoom-original"), tr("Zoom original"), this);
+    actionZoomReset = act = new QAction(Fb2Icon("zoom-original"), tr("Zoom original"), this);
     menu->addAction(act);
 
     menu->addSeparator();
@@ -427,7 +427,7 @@ void Fb2MainWindow::createActions()
     menuBar()->addSeparator();
     menu = menuBar()->addMenu(tr("&Help"));
 
-    act = new QAction(FB2::icon("help-about"), tr("&About"), this);
+    act = new QAction(Fb2Icon("help-about"), tr("&About"), this);
     act->setStatusTip(tr("Show the application's About box"));
     connect(act, SIGNAL(triggered()), this, SLOT(about()));
     menu->addAction(act);

+ 11 - 11
source/fb2text.cpp

@@ -193,14 +193,14 @@ void Fb2TextBase::addTools(QToolBar *tool)
     QAction *act;
 
     act = pageAction(QWebPage::Undo);
-    act->setIcon(FB2::icon("edit-undo"));
+    act->setIcon(Fb2Icon("edit-undo"));
     act->setText(QObject::tr("&Undo"));
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Undo);
     tool->addAction(act);
 
     act = pageAction(QWebPage::Redo);
-    act->setIcon(FB2::icon("edit-redo"));
+    act->setIcon(Fb2Icon("edit-redo"));
     act->setText(QObject::tr("&Redo"));
     act->setPriority(QAction::LowPriority);
     act->setShortcut(QKeySequence::Redo);
@@ -209,7 +209,7 @@ void Fb2TextBase::addTools(QToolBar *tool)
     tool->addSeparator();
 
     act = pageAction(QWebPage::Cut);
-    act->setIcon(FB2::icon("edit-cut"));
+    act->setIcon(Fb2Icon("edit-cut"));
     act->setText(QObject::tr("Cu&t"));
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Cut);
@@ -217,7 +217,7 @@ void Fb2TextBase::addTools(QToolBar *tool)
     tool->addAction(act);
 
     act = pageAction(QWebPage::Copy);
-    act->setIcon(FB2::icon("edit-copy"));
+    act->setIcon(Fb2Icon("edit-copy"));
     act->setText(QObject::tr("&Copy"));
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Copy);
@@ -225,7 +225,7 @@ void Fb2TextBase::addTools(QToolBar *tool)
     tool->addAction(act);
 
     act = pageAction(QWebPage::Paste);
-    act->setIcon(FB2::icon("edit-paste"));
+    act->setIcon(Fb2Icon("edit-paste"));
     act->setText(QObject::tr("&Paste"));
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Paste);
@@ -235,27 +235,27 @@ void Fb2TextBase::addTools(QToolBar *tool)
     tool->addSeparator();
 
     act = pageAction(QWebPage::ToggleBold);
-    act->setIcon(FB2::icon("format-text-bold"));
+    act->setIcon(Fb2Icon("format-text-bold"));
     act->setText(QObject::tr("&Bold"));
     tool->addAction(act);
 
     act = pageAction(QWebPage::ToggleItalic);
-    act->setIcon(FB2::icon("format-text-italic"));
+    act->setIcon(Fb2Icon("format-text-italic"));
     act->setText(QObject::tr("&Italic"));
     tool->addAction(act);
 
     act = pageAction(QWebPage::ToggleStrikethrough);
-    act->setIcon(FB2::icon("format-text-strikethrough"));
+    act->setIcon(Fb2Icon("format-text-strikethrough"));
     act->setText(QObject::tr("&Strikethrough"));
     tool->addAction(act);
 
     act = pageAction(QWebPage::ToggleSuperscript);
-    act->setIcon(FB2::icon("format-text-superscript"));
+    act->setIcon(Fb2Icon("format-text-superscript"));
     act->setText(QObject::tr("Su&perscript"));
     tool->addAction(act);
 
     act = pageAction(QWebPage::ToggleSubscript);
-    act->setIcon(FB2::icon("format-text-subscript"));
+    act->setIcon(Fb2Icon("format-text-subscript"));
     act->setText(QObject::tr("Su&bscript"));
     tool->addAction(act);
 }
@@ -279,7 +279,7 @@ Fb2TextEdit::Fb2TextEdit(QWidget *parent)
 
 Fb2TextEdit::~Fb2TextEdit()
 {
-    FB2DELETE(m_noteView);
+    if (m_noteView) delete m_noteView;
 }
 
 Fb2TextPage * Fb2TextEdit::page()

+ 9 - 9
source/fb2tree.cpp

@@ -404,7 +404,7 @@ void Fb2TreeView::initActions(QToolBar *toolbar)
 {
     QAction * act;
 
-    act = new QAction(FB2::icon("list-add"), tr("&Insert"), this);
+    act = new QAction(Fb2Icon("list-add"), tr("&Insert"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(Qt::Key_Insert);
     act->setPriority(QAction::LowPriority);
@@ -412,7 +412,7 @@ void Fb2TreeView::initActions(QToolBar *toolbar)
     toolbar->addAction(act);
     m_menu.addAction(act);
 
-    act = new QAction(FB2::icon("list-remove"), tr("&Delete"), this);
+    act = new QAction(Fb2Icon("list-remove"), tr("&Delete"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(Qt::Key_Delete);
     act->setPriority(QAction::LowPriority);
@@ -422,21 +422,21 @@ void Fb2TreeView::initActions(QToolBar *toolbar)
 
     m_menu.addSeparator();
 
-    actionCut = act = new QAction(FB2::icon("edit-cut"), tr("Cu&t"), this);
+    actionCut = act = new QAction(Fb2Icon("edit-cut"), tr("Cu&t"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Cut);
     act->setEnabled(false);
     m_menu.addAction(act);
 
-    actionCopy = act = new QAction(FB2::icon("edit-copy"), tr("&Copy"), this);
+    actionCopy = act = new QAction(Fb2Icon("edit-copy"), tr("&Copy"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Copy);
     act->setEnabled(false);
     m_menu.addAction(act);
 
-    actionPaste = act = new QAction(FB2::icon("edit-paste"), tr("&Paste"), this);
+    actionPaste = act = new QAction(Fb2Icon("edit-paste"), tr("&Paste"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Paste);
@@ -445,28 +445,28 @@ void Fb2TreeView::initActions(QToolBar *toolbar)
     toolbar->addSeparator();
     m_menu.addSeparator();
 
-    act = new QAction(FB2::icon("go-up"), tr("&Up"), this);
+    act = new QAction(Fb2Icon("go-up"), tr("&Up"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
     connect(act, SIGNAL(triggered()), SLOT(moveUp()));
     toolbar->addAction(act);
     m_menu.addAction(act);
 
-    act = new QAction(FB2::icon("go-down"), tr("&Down"), this);
+    act = new QAction(Fb2Icon("go-down"), tr("&Down"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
     connect(act, SIGNAL(triggered()), SLOT(moveDown()));
     toolbar->addAction(act);
     m_menu.addAction(act);
 
-    act = new QAction(FB2::icon("go-previous"), tr("&Left"), this);
+    act = new QAction(Fb2Icon("go-previous"), tr("&Left"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
     connect(act, SIGNAL(triggered()), SLOT(moveLeft()));
     toolbar->addAction(act);
     m_menu.addAction(act);
 
-    act = new QAction(FB2::icon("go-next"), tr("&Right"), this);
+    act = new QAction(Fb2Icon("go-next"), tr("&Right"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
     connect(act, SIGNAL(triggered()), SLOT(moveRight()));

+ 9 - 4
source/fb2utils.cpp

@@ -3,16 +3,21 @@
 #include <QFile>
 #include <QTextStream>
 
-namespace FB2 {
-
-QIcon icon(const QString &name)
+static QIcon loadIcon(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);
+    return icon;
 }
 
+Fb2Icon::Fb2Icon(const QString &name)
+    : QIcon(fromTheme(name, loadIcon(name)))
+{
+}
+
+namespace FB2 {
+
 QString read(const QString &filename)
 {
     // TODO: throw an exception instead of

+ 6 - 2
source/fb2utils.h

@@ -6,9 +6,13 @@
 
 #define FB2DELETE(p) { if ((p) != NULL) { delete (p); (p) = NULL; } }
 
-namespace FB2 {
+class Fb2Icon : public QIcon
+{
+public:
+    explicit Fb2Icon(const QString &name);
+};
 
-QIcon icon(const QString &name);
+namespace FB2 {
 
 QString read(const QString &filename);