Sfoglia il codice sorgente

Modify head editor

Kandrashin Denis 13 anni fa
parent
commit
fe5b1cc51b
4 ha cambiato i file con 42 aggiunte e 27 eliminazioni
  1. 29 0
      source/fb2head.cpp
  2. 9 0
      source/fb2head.hpp
  3. 4 24
      source/fb2main.cpp
  4. 0 3
      source/fb2main.hpp

+ 29 - 0
source/fb2head.cpp

@@ -1,6 +1,9 @@
 #include "fb2head.hpp"
 
 #include <QtDebug>
+#include <QAction>
+#include <QHeaderView>
+#include <QToolBar>
 #include <QWebFrame>
 #include <QWebPage>
 #include <QWebView>
@@ -8,6 +11,7 @@
 #include <QTreeView>
 
 #include "fb2view.hpp"
+#include "fb2utils.h"
 
 Fb2HeadItem::HintHash::HintHash()
 {
@@ -263,6 +267,7 @@ bool Fb2HeadModel::setData(const QModelIndex &index, const QVariant &value, int
     if (!i) return false;
     i->setText(value.toString());
     emit dataChanged(index, index);
+    return true;
 }
 
 Qt::ItemFlags Fb2HeadModel::flags(const QModelIndex &index) const
@@ -281,11 +286,34 @@ Fb2HeadView::Fb2HeadView(Fb2WebView &view, QWidget *parent)
     : QTreeView(parent)
     , m_view(view)
 {
+    QAction * act;
+
+    actionInsert = act = new QAction(FB2::icon("list-add"), tr("&Append"), this);
+    act->setPriority(QAction::LowPriority);
+    act->setShortcuts(QKeySequence::New);
+
+    actionModify = act = new QAction(FB2::icon("list-add"), tr("&Modify"), this);
+    act->setPriority(QAction::LowPriority);
+
+    actionDelete = act = new QAction(FB2::icon("list-remove"), tr("&Delete"), this);
+    act->setPriority(QAction::LowPriority);
+    act->setShortcuts(QKeySequence::Delete);
+
     //setItemDelegate(new QItemDelegate(this));
     setSelectionBehavior(QAbstractItemView::SelectItems);
     setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
     connect(&m_view, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
     connect(this, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex)));
+
+    header()->setDefaultSectionSize(200);
+    connect(actionModify, SIGNAL(triggered()), SLOT(editCurrent()));
+}
+
+void Fb2HeadView::initToolbar(QToolBar &toolbar)
+{
+    toolbar.addSeparator();
+    toolbar.addAction(actionInsert);
+    toolbar.addAction(actionDelete);
 }
 
 void Fb2HeadView::updateTree()
@@ -309,3 +337,4 @@ void Fb2HeadView::activated(const QModelIndex &index)
 {
     if (index.isValid() && index.column() == 1) edit(index);
 }
+

+ 9 - 0
source/fb2head.hpp

@@ -6,6 +6,11 @@
 #include <QWebElement>
 #include <QWebView>
 
+QT_BEGIN_NAMESPACE
+class QAction;
+class QToolBar;
+QT_END_NAMESPACE
+
 #include "fb2xml.h"
 
 class Fb2WebView;
@@ -111,6 +116,7 @@ class Fb2HeadView : public QTreeView
 
 public:
     explicit Fb2HeadView(Fb2WebView &view, QWidget *parent = 0);
+    void initToolbar(QToolBar &toolbar);
 
 public slots:
     void editCurrent();
@@ -121,6 +127,9 @@ private slots:
 
 private:
     Fb2WebView & m_view;
+    QAction * actionInsert;
+    QAction * actionModify;
+    QAction * actionDelete;
 };
 
 #endif // FB2HEAD_H

+ 4 - 24
source/fb2main.cpp

@@ -289,22 +289,6 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    actionInsert = act = new QAction(FB2::icon("list-add"), tr("&Append"), this);
-    act->setPriority(QAction::LowPriority);
-    act->setShortcuts(QKeySequence::New);
-    menu->addAction(act);
-
-    actionModify = act = new QAction(FB2::icon("list-add"), tr("&Modify"), this);
-    act->setPriority(QAction::LowPriority);
-    menu->addAction(act);
-
-    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(FB2::icon("preferences-desktop"), tr("&Settings"), this);
     act->setShortcuts(QKeySequence::Preferences);
     act->setStatusTip(tr("Application settings"));
@@ -724,8 +708,6 @@ void Fb2MainWindow::viewHead()
 
     if (!headTree) {
         headTree = new Fb2HeadView(*textEdit, this);
-        headTree->header()->setDefaultSectionSize(200);
-        connect(actionModify, SIGNAL(triggered()), headTree, SLOT(editCurrent()));
     }
 
     this->setFocus();
@@ -754,12 +736,10 @@ void Fb2MainWindow::viewHead()
     }
 
     FB2DELETE(toolEdit);
-    QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
-    tool->addSeparator();
-    tool->addAction(actionInsert);
-    tool->addAction(actionModify);
-    tool->addAction(actionDelete);
-    tool->setMovable(false);
+    toolEdit = addToolBar(tr("Edit"));
+    headTree->initToolbar(*toolEdit);
+    toolEdit->addSeparator();
+    toolEdit->setMovable(false);
 }
 
 void Fb2MainWindow::viewTree()

+ 0 - 3
source/fb2main.hpp

@@ -102,9 +102,6 @@ private:
         *actionSelect,
         *actionFind,
         *actionReplace,
-        *actionInsert,
-        *actionModify,
-        *actionDelete,
         *actionImage,
         *actionNote,
         *actionLink,