Przeglądaj źródła

Insert epigraph

Kandrashin Denis 13 lat temu
rodzic
commit
d47d19e0cb
7 zmienionych plików z 74 dodań i 10 usunięć
  1. 18 3
      source/fb2html.cpp
  2. 2 0
      source/fb2html.h
  3. 12 5
      source/fb2main.cpp
  4. 2 1
      source/fb2main.hpp
  5. 28 1
      source/fb2text.cpp
  6. 4 0
      source/fb2text.hpp
  7. 8 0
      source/fb2tree.cpp

+ 18 - 3
source/fb2html.cpp

@@ -87,7 +87,7 @@ bool FbTextElement::Sublist::operator <(const QWebElement &element) const
 {
     const QString name = element.attribute("class");
     for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
-        if (it->name() == name) return it < m_pos || element.isNull();
+        if (it->name() == name) return m_pos < it  || element.isNull();
     }
     return false;
 }
@@ -96,11 +96,16 @@ bool FbTextElement::Sublist::operator >=(const QWebElement &element) const
 {
     const QString name = element.attribute("class");
     for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
-        if (it->name() == name) return it >= m_pos || element.isNull();
+        if (it->name() == name) return m_pos >= it || element.isNull();
     }
     return false;
 }
 
+bool FbTextElement::Sublist::operator !=(const QWebElement &element) const
+{
+    return element.isNull() || m_pos->name() != element.attribute("class");
+}
+
 //---------------------------------------------------------------------------
 //  FbTextElement
 //---------------------------------------------------------------------------
@@ -132,6 +137,16 @@ const FbTextElement::TypeList * FbTextElement::subtypes() const
     return scheme[attribute("class").toLower()];
 }
 
+bool FbTextElement::hasSubtype(const QString &style) const
+{
+    if (const TypeList * list = subtypes()) {
+        for (TypeList::const_iterator item = list->begin(); item != list->end(); item++) {
+            if (item->name() == style) return true;
+        }
+    }
+    return false;
+}
+
 FbTextElement::TypeList::const_iterator FbTextElement::subtype(const TypeList &list, const QString &style)
 {
     for (TypeList::const_iterator item = list.begin(); item != list.end(); item++) {
@@ -156,7 +171,7 @@ FbTextElement FbTextElement::insertInside(const QString &style, const QString &h
 
     while (!child.isNull()) {
         FbTextElement subling = child.nextSibling();
-        if (sublist >= child && sublist < subling) {
+        if (sublist >= child && sublist != subling) {
             child.appendOutside(html);
             return child.nextSibling();
         }

+ 2 - 0
source/fb2html.h

@@ -48,6 +48,7 @@ private:
         bool operator !() const;
         bool operator <(const QWebElement &element) const;
         bool operator >=(const QWebElement &element) const;
+        bool operator !=(const QWebElement &element) const;
     private:
         const TypeList &m_list;
         TypeList::const_iterator m_pos;
@@ -59,6 +60,7 @@ public:
     FbTextElement &operator=(const QWebElement &x) { QWebElement::operator=(x); return *this; }
     FbTextElement insertInside(const QString &style, const QString &html);
     void getChildren(FbElementList &list);
+    bool hasSubtype(const QString &style) const;
     bool hasScheme() const;
     QString location();
 

+ 12 - 5
source/fb2main.cpp

@@ -323,6 +323,9 @@ void FbMainWindow::createActions()
 
     menu->addSeparator();
 
+    actionBody = act = new QAction(tr("&Body"), this);
+    menu->addAction(act);
+
     actionSection = act = new QAction(FbIcon("insert-object"), tr("&Section"), this);
     menu->addAction(act);
 
@@ -332,15 +335,12 @@ void FbMainWindow::createActions()
     actionEpigraph = act = new QAction(tr("&Epigraph"), this);
     menu->addAction(act);
 
-    actionDescr = act = new QAction(tr("&Annotation"), this);
+    actionAnnot = act = new QAction(tr("&Annotation"), this);
     menu->addAction(act);
 
     actionSubtitle = act = new QAction(tr("&Subtitle"), this);
     menu->addAction(act);
 
-    actionAuthor = act = new QAction(tr("&Author"), this);
-    menu->addAction(act);
-
     actionAuthor = act = new QAction(tr("&Cite"), this);
     menu->addAction(act);
 
@@ -350,7 +350,10 @@ void FbMainWindow::createActions()
     actionStanza = act = new QAction(tr("&Stanza"), this);
     menu->addAction(act);
 
-    actionBody = act = new QAction(tr("&Body"), this);
+    actionAuthor = act = new QAction(tr("&Author"), this);
+    menu->addAction(act);
+
+    actionDate = act = new QAction(tr("&Date"), this);
     menu->addAction(act);
 
     menuText = menu = menuBar()->addMenu(tr("Fo&rmat"));
@@ -705,10 +708,14 @@ void FbMainWindow::viewText()
     connect(actionLink, SIGNAL(triggered()), textEdit, SLOT(insertLink()));
 
     connect(actionTitle, SIGNAL(triggered()), textPage, SLOT(insertTitle()));
+    connect(actionAnnot, SIGNAL(triggered()), textPage, SLOT(insertAnnot()));
+    connect(actionAuthor, SIGNAL(triggered()), textPage, SLOT(insertAuthor()));
+    connect(actionEpigraph, SIGNAL(triggered()), textPage, SLOT(insertEpigraph()));
     connect(actionSubtitle, SIGNAL(triggered()), textPage, SLOT(insertSubtitle()));
     connect(actionSection, SIGNAL(triggered()), textPage, SLOT(insertSection()));
     connect(actionStanza, SIGNAL(triggered()), textPage, SLOT(insertStanza()));
     connect(actionPoem, SIGNAL(triggered()), textPage, SLOT(insertPoem()));
+    connect(actionDate, SIGNAL(triggered()), textPage, SLOT(insertDate()));
     connect(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
 
     connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));

+ 2 - 1
source/fb2main.hpp

@@ -114,8 +114,9 @@ private:
         *actionTitle,
         *actionEpigraph,
         *actionSubtitle,
-        *actionDescr,
+        *actionAnnot,
         *actionPoem,
+        *actionDate,
         *actionStanza,
         *actionAuthor,
         *actionSection,

+ 28 - 1
source/fb2text.cpp

@@ -237,6 +237,34 @@ void FbTextPage::insertStanza()
     }
 }
 
+void FbTextPage::insertAnnot()
+{
+}
+
+void FbTextPage::insertAuthor()
+{
+}
+
+void FbTextPage::insertEpigraph()
+{
+    const QString type = "epigraph";
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        if (element.hasSubtype(type)) {
+            QString html = div("epigraph", p());
+            element = element.insertInside(type, html);
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Insert epigraph"));
+            break;
+        }
+        element = element.parent();
+    }
+}
+
+void FbTextPage::insertDate()
+{
+}
+
 FbTextElement FbTextPage::current()
 {
     return element(location());
@@ -577,7 +605,6 @@ void FbTextEdit::insertNote()
     dlg.exec();
 }
 
-
 void FbTextEdit::insertLink()
 {
 }

+ 4 - 0
source/fb2text.hpp

@@ -74,10 +74,14 @@ public:
 public slots:
     void insertBody();
     void insertTitle();
+    void insertAnnot();
+    void insertAuthor();
+    void insertEpigraph();
     void insertSubtitle();
     void insertSection();
     void insertPoem();
     void insertStanza();
+    void insertDate();
 
 protected:
     virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);

+ 8 - 0
source/fb2tree.cpp

@@ -552,6 +552,14 @@ void FbTreeView::contextMenu(const QPoint &pos)
         if (!e.hasChild("date")) menu.addAction(actionDate);
     }
 
+    if (e.isDiv("stanza")) {
+        if (!e.hasChild("title")) menu.addAction(actionTitle);
+    }
+
+    if (e.isDiv("epigraph")) {
+        menu.addAction(actionAuthor);
+    }
+
     if (e.isDiv("cite")) {
         menu.addAction(actionAuthor);
     }