1
0
Kandrashin Denis 13 жил өмнө
parent
commit
b651017129

+ 16 - 6
source/fb2html.cpp

@@ -35,24 +35,34 @@ void FbTextElement::select()
     evaluateJavaScript(javascript);
 }
 
+bool FbTextElement::isDiv(const QString &style) const
+{
+    return tagName() == "DIV" && attribute("class").toLower() == style;
+}
+
 bool FbTextElement::isBody() const
 {
-    return tagName() == "DIV" && attribute("class").toLower() == "body";
+    return isDiv("body");
 }
 
 bool FbTextElement::isSection() const
 {
-    return tagName() == "DIV" && attribute("class").toLower() == "section";
+    return isDiv("section");
 }
 
-bool FbTextElement::hasTitle() const
+bool FbTextElement::isTitle() const
 {
-    return FbTextElement(firstChild()).isTitle();
+    return isDiv("title");
 }
 
-bool FbTextElement::isTitle() const
+bool FbTextElement::isStanza() const
+{
+    return isDiv("stanza");
+}
+
+bool FbTextElement::hasTitle() const
 {
-    return tagName() == "DIV" && attribute("class").toLower() == "title";
+    return FbTextElement(firstChild()).isTitle();
 }
 
 //---------------------------------------------------------------------------

+ 6 - 1
source/fb2html.h

@@ -18,10 +18,14 @@ public:
     FbTextElement &operator=(const QWebElement &x) { QWebElement::operator=(x); return *this; }
     void getChildren(FbElementList &list);
     QString location();
-    bool hasTitle() const;
+
+public:
+    bool isDiv(const QString &style) const;
     bool isBody() const;
     bool isSection() const;
     bool isTitle() const;
+    bool isStanza() const;
+    bool hasTitle() const;
 
 public:
     FbTextElement findFirst(const QString &selectorQuery) const { return QWebElement::findFirst(selectorQuery); }
@@ -34,6 +38,7 @@ public:
 
 public:
     void select();
+
 };
 
 class FbInsertCmd : public QUndoCommand

+ 15 - 0
source/fb2main.cpp

@@ -320,6 +320,7 @@ void FbMainWindow::createActions()
 
     actionLink = act = new QAction(FbIcon("insert-link"), tr("&Hiperlink"), this);
     menu->addAction(act);
+    act->setEnabled(false);
 
     menu->addSeparator();
 
@@ -331,15 +332,18 @@ void FbMainWindow::createActions()
 
     actionEpigraph = act = new QAction(tr("&Epigraph"), this);
     menu->addAction(act);
+    act->setEnabled(false);
 
     actionDescr = act = new QAction(tr("&Annotation"), this);
     menu->addAction(act);
+    act->setEnabled(false);
 
     actionSubtitle = act = new QAction(tr("&Subtitle"), this);
     menu->addAction(act);
 
     actionAuthor = act = new QAction(tr("&Author"), this);
     menu->addAction(act);
+    act->setEnabled(false);
 
     actionPoem = act = new QAction(tr("&Poem"), this);
     menu->addAction(act);
@@ -374,6 +378,15 @@ void FbMainWindow::createActions()
     act->setCheckable(true);
     menu->addAction(act);
 
+    actionTextSub = act = new QAction(FbIcon("format-text-subscript"), tr("Su&bscript"), this);
+    act->setCheckable(true);
+    menu->addAction(act);
+
+    actionTextCode = act = new QAction(tr("&Code"), this);
+    act->setCheckable(true);
+    menu->addAction(act);
+    act->setEnabled(false);
+
     menuView = menu = menuBar()->addMenu(tr("&View"));
 
     tool->addSeparator();
@@ -698,6 +711,8 @@ void FbMainWindow::viewText()
     connect(actionTitle, SIGNAL(triggered()), textPage, SLOT(insertTitle()));
     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(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
 
     connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));

+ 1 - 0
source/fb2main.hpp

@@ -122,6 +122,7 @@ private:
         *actionTextBold,
         *actionTextItalic,
         *actionTextStrike,
+        *actionTextCode,
         *actionTextSub,
         *actionTextSup,
         *actionInspect,

+ 45 - 2
source/fb2text.cpp

@@ -184,8 +184,13 @@ void FbTextPage::insertSubtitle()
         FbTextElement parent = element.parent();
         if (parent.isSection()) {
             QString html = div("subtitle", p());
-            element.prependOutside(html);
-            element = element.previousSibling();
+            if (element.isTitle()) {
+                element.appendOutside(html);
+                element = element.nextSibling();
+            } else {
+                element.prependOutside(html);
+                element = element.previousSibling();
+            }
             QUndoCommand * command = new FbInsertCmd(element);
             push(command, tr("Insert subtitle"));
             break;
@@ -194,6 +199,44 @@ void FbTextPage::insertSubtitle()
     }
 }
 
+void FbTextPage::insertPoem()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        FbTextElement parent = element.parent();
+        if (parent.isSection()) {
+            QString html = div("poem", div("stanza", p()));
+            if (element.isTitle()) {
+                element.appendOutside(html);
+                element = element.nextSibling();
+            } else {
+                element.prependOutside(html);
+                element = element.previousSibling();
+            }
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Insert poem"));
+            break;
+        }
+        element = parent;
+    }
+}
+
+void FbTextPage::insertStanza()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        if (element.isStanza()) {
+            QString html = div("stanza", p());
+            element.appendOutside(html);
+            element = element.nextSibling();
+            QUndoCommand * command = new FbInsertCmd(element);
+            push(command, tr("Append stanza"));
+            break;
+        }
+        element = element.parent();
+    }
+}
+
 FbTextElement FbTextPage::current()
 {
     return element(location());

+ 2 - 0
source/fb2text.hpp

@@ -76,6 +76,8 @@ public slots:
     void insertTitle();
     void insertSubtitle();
     void insertSection();
+    void insertPoem();
+    void insertStanza();
 
 protected:
     virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);

+ 6 - 1
source/res/style.css

@@ -135,7 +135,12 @@ div.cite {
 div.poem {
   border-left: thin solid blue;
   margin-left: 5%;
-  padding-left: 4; 
+  padding-left: 4;
+}
+
+div.poem div.stanza {
+  border-left: thin solid blue;
+  padding-left: 4;
 }
 
 div.poem div {