Kaynağa Gözat

New tree actions

Kandrashin Denis 13 yıl önce
ebeveyn
işleme
52e4104e10
6 değiştirilmiş dosya ile 189 ekleme ve 27 silme
  1. 10 1
      source/fb2html.cpp
  2. 1 0
      source/fb2html.h
  3. 107 22
      source/fb2tree.cpp
  4. 22 3
      source/fb2tree.hpp
  5. BIN
      source/ts/ru.qm
  6. 49 1
      source/ts/ru.ts

+ 10 - 1
source/fb2html.cpp

@@ -1,6 +1,5 @@
 #include "fb2html.h"
 #include "fb2utils.h"
-
 #include "fb2text.hpp"
 
 //---------------------------------------------------------------------------
@@ -35,6 +34,16 @@ void FbTextElement::select()
     evaluateJavaScript(javascript);
 }
 
+bool FbTextElement::hasChild(const QString &style) const
+{
+    FbTextElement child = firstChild();
+    while (!child.isNull()) {
+        if (child.tagName() == "DIV" && child.attribute("class").toLower() == style) return true;
+        child = child.nextSibling();
+    }
+    return false;
+}
+
 bool FbTextElement::isDiv(const QString &style) const
 {
     return tagName() == "DIV" && attribute("class").toLower() == style;

+ 1 - 0
source/fb2html.h

@@ -20,6 +20,7 @@ public:
     QString location();
 
 public:
+    bool hasChild(const QString &style) const;
     bool isDiv(const QString &style) const;
     bool isBody() const;
     bool isSection() const;

+ 107 - 22
source/fb2tree.cpp

@@ -416,74 +416,83 @@ void FbTreeView::initActions(QToolBar *toolbar)
 {
     QAction * act;
 
-    act = new QAction(FbIcon("list-add"), tr("&Insert"), this);
+    actionSection = act = new QAction(FbIcon("list-add"), tr("&Add section"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(Qt::Key_Insert);
     act->setPriority(QAction::LowPriority);
-    connect(act, SIGNAL(triggered()), SLOT(insertNode()));
+    connect(act, SIGNAL(triggered()), SLOT(insertSection()));
     toolbar->addAction(act);
-    m_menu.addAction(act);
 
-    act = new QAction(FbIcon("list-remove"), tr("&Delete"), this);
+    actionTitle = act = new QAction(tr("+ Title"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertTitle()));
+
+    actionEpigraph = act = new QAction(tr("+ Epigraph"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertEpigraph()));
+
+    actionImage = act = new QAction(tr("+ Image"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertImage()));
+
+    actionAnnot = act = new QAction(tr("+ Annotation"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertAnnot()));
+
+    actionStanza = act = new QAction(tr("+ Stanza"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertStanza()));
+
+    actionAuthor = act = new QAction(tr("+ Author"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertAuthor()));
+
+    actionDate = act = new QAction(tr("+ Date"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertDate()));
+
+    actionDelete = act = new QAction(FbIcon("list-remove"), tr("&Delete"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(Qt::Key_Delete);
     act->setPriority(QAction::LowPriority);
     connect(act, SIGNAL(triggered()), SLOT(deleteNode()));
     toolbar->addAction(act);
-    m_menu.addAction(act);
-
-    m_menu.addSeparator();
 
     actionCut = act = new QAction(FbIcon("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(FbIcon("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(FbIcon("edit-paste"), tr("&Paste"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setPriority(QAction::LowPriority);
     act->setShortcuts(QKeySequence::Paste);
-    m_menu.addAction(act);
 
     toolbar->addSeparator();
-    m_menu.addSeparator();
 
-    act = new QAction(FbIcon("go-up"), tr("&Up"), this);
+    actionMoveUp = act = new QAction(FbIcon("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(FbIcon("go-down"), tr("&Down"), this);
+    actionMoveDown = act = new QAction(FbIcon("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(FbIcon("go-previous"), tr("&Left"), this);
+    actionMoveLeft = act = new QAction(FbIcon("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(FbIcon("go-next"), tr("&Right"), this);
+    actionMoveRight = act = new QAction(FbIcon("go-next"), tr("&Right"), this);
     act->setShortcutContext(Qt::WidgetShortcut);
     act->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
     connect(act, SIGNAL(triggered()), SLOT(moveRight()));
     toolbar->addAction(act);
-    m_menu.addAction(act);
 }
 
 void FbTreeView::keyPressEvent(QKeyEvent *event)
@@ -491,7 +500,7 @@ void FbTreeView::keyPressEvent(QKeyEvent *event)
     switch (event->modifiers()) {
         case Qt::NoModifier:
             switch (event->key()) {
-                case Qt::Key_Insert: insertNode(); return;
+                case Qt::Key_Insert: insertSection(); return;
                 case Qt::Key_Delete: deleteNode(); return;
             }
             break;
@@ -509,7 +518,55 @@ void FbTreeView::keyPressEvent(QKeyEvent *event)
 
 void FbTreeView::contextMenu(const QPoint &pos)
 {
-    m_menu.exec(mapToGlobal(pos));
+    FbTreeModel * m = model();
+    if (!m) return;
+
+    FbTreeItem * i = m->item(currentIndex());
+    if (!i) return;
+
+    FbTextElement e = i->element();
+    if (e.isTitle()) e = e.parent();
+    if (e.isNull()) return;
+
+    QMenu menu;
+    menu.addAction(actionSection);
+
+    if (e.isBody()) {
+        if (!e.hasChild("image")) menu.addAction(actionImage);
+        if (!e.hasChild("title")) menu.addAction(actionTitle);
+        menu.addAction(actionEpigraph);
+    }
+
+    if (e.isSection()) {
+        if (!e.hasChild("title")) menu.addAction(actionTitle);
+        menu.addAction(actionEpigraph);
+        if (!e.hasChild("image")) menu.addAction(actionImage);
+        if (!e.hasChild("annotetion")) menu.addAction(actionAnnot);
+    }
+
+    if (e.isDiv("poem")) {
+        if (!e.hasChild("title")) menu.addAction(actionTitle);
+        menu.addAction(actionEpigraph);
+        menu.addAction(actionStanza);
+        menu.addAction(actionAuthor);
+        if (!e.hasChild("date")) menu.addAction(actionDate);
+    }
+
+    if (e.isDiv("cite")) {
+        menu.addAction(actionAuthor);
+    }
+
+    menu.addAction(actionDelete);
+    menu.addSeparator();
+    menu.addAction(actionCut);
+    menu.addAction(actionCopy);
+    menu.addAction(actionPaste);
+    menu.addSeparator();
+    menu.addAction(actionMoveUp);
+    menu.addAction(actionMoveDown);
+    menu.addAction(actionMoveLeft);
+    menu.addAction(actionMoveRight);
+    menu.exec(mapToGlobal(pos));
 }
 
 void FbTreeView::selectionChanged()
@@ -566,7 +623,7 @@ QModelIndex FbTreeModel::append(const QModelIndex &parent, FbTextElement element
     return createIndex(row, 0, (void*)child);
 }
 
-void FbTreeView::insertNode()
+void FbTreeView::insertSection()
 {
     if (FbTreeModel * m = model()) {
         QModelIndex index = currentIndex();
@@ -591,6 +648,34 @@ void FbTreeView::insertNode()
     }
 }
 
+void FbTreeView::insertTitle()
+{
+}
+
+void FbTreeView::insertAuthor()
+{
+}
+
+void FbTreeView::insertEpigraph()
+{
+}
+
+void FbTreeView::insertImage()
+{
+}
+
+void FbTreeView::insertAnnot()
+{
+}
+
+void FbTreeView::insertStanza()
+{
+}
+
+void FbTreeView::insertDate()
+{
+}
+
 void FbTreeView::deleteNode()
 {
     if (FbTreeModel * m = model()) {

+ 22 - 3
source/fb2tree.hpp

@@ -148,7 +148,14 @@ private slots:
     void selectionChanged();
     void selectTree();
 
-    void insertNode();
+    void insertSection();
+    void insertTitle();
+    void insertAuthor();
+    void insertEpigraph();
+    void insertImage();
+    void insertAnnot();
+    void insertStanza();
+    void insertDate();
     void deleteNode();
 
     void moveUp();
@@ -167,11 +174,23 @@ private:
     FbTextEdit & m_view;
     QTimer m_timerSelect;
     QTimer m_timerUpdate;
-    QMenu m_menu;
     QAction
+        *actionSection,
+        *actionDelete,
+        *actionTitle,
+        *actionAuthor,
+        *actionEpigraph,
+        *actionStanza,
+        *actionImage,
+        *actionAnnot,
+        *actionDate,
         *actionCut,
         *actionCopy,
-        *actionPaste;
+        *actionPaste,
+        *actionMoveUp,
+        *actionMoveDown,
+        *actionMoveLeft,
+        *actionMoveRight;
 };
 
 class FbTreeWidget : public QWidget

BIN
source/ts/ru.qm


+ 49 - 1
source/ts/ru.ts

@@ -459,6 +459,14 @@
         <source>&amp;Epigraph</source>
         <translation>&amp;Эпиграф &lt;epigraph&gt;</translation>
     </message>
+    <message>
+        <source>&amp;Cite</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>&amp;Code</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>FbNodeDlg</name>
@@ -572,6 +580,14 @@
         <source>Insert subtitle</source>
         <translation type="unfinished"></translation>
     </message>
+    <message>
+        <source>Insert poem</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Append stanza</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>FbTreeModel</name>
@@ -584,7 +600,7 @@
     <name>FbTreeView</name>
     <message>
         <source>&amp;Insert</source>
-        <translation>&amp;Вставка</translation>
+        <translation type="obsolete">&amp;Вставка</translation>
     </message>
     <message>
         <source>&amp;Delete</source>
@@ -618,6 +634,38 @@
         <source>&amp;Paste</source>
         <translation>&amp;Вставить</translation>
     </message>
+    <message>
+        <source>&amp;Add section</source>
+        <translation>Добавить &amp;секцию</translation>
+    </message>
+    <message>
+        <source>+ Title</source>
+        <translation>+ Заголовок</translation>
+    </message>
+    <message>
+        <source>+ Epigraph</source>
+        <translation>+ Эпиграф</translation>
+    </message>
+    <message>
+        <source>+ Image</source>
+        <translation>+ Изображение</translation>
+    </message>
+    <message>
+        <source>+ Annotation</source>
+        <translation>+ Аннотация</translation>
+    </message>
+    <message>
+        <source>+ Stanza</source>
+        <translation>+ Строфа</translation>
+    </message>
+    <message>
+        <source>+ Author</source>
+        <translation>+ Автор</translation>
+    </message>
+    <message>
+        <source>+ Date</source>
+        <translation>+ Дата</translation>
+    </message>
 </context>
 <context>
     <name>QObject</name>