Sfoglia il codice sorgente

Replace tags: <div class=section> ==> <fb:section>

Kandrashin Denis 12 anni fa
parent
commit
8e92ec27f2
7 ha cambiato i file con 77 aggiunte e 78 eliminazioni
  1. 1 0
      source/fb2main.cpp
  2. 21 42
      source/fb2read.cpp
  3. 2 3
      source/fb2read.hpp
  4. 1 8
      source/fb2save.cpp
  5. 15 0
      source/fb2text.cpp
  6. 1 0
      source/fb2text.hpp
  7. 36 25
      source/res/style.css

+ 1 - 0
source/fb2main.cpp

@@ -727,6 +727,7 @@ void FbMainWindow::createTextToolbar()
     connect(actionDate, SIGNAL(triggered()), textPage, SLOT(insertDate()));
     connect(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
 
+    connect(actionSimpleText, SIGNAL(triggered()), textPage, SLOT(insertText()));
     connect(actionParaSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertParagraphSeparator), SIGNAL(triggered()));
     connect(actionLineSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertLineSeparator), SIGNAL(triggered()));
 

+ 21 - 42
source/fb2read.cpp

@@ -95,9 +95,7 @@ void FbReadHandler::BaseHandler::writeAttributes(const QXmlAttributes &atts)
     int count = atts.count();
     for (int i = 0; i < count; i++) {
         if (atts.localName(i) == "href") continue;
-        QString name = atts.qName(i);
-        if (name != "id") name.prepend("fb2_");
-        writer().writeAttribute(name, atts.value(i));
+        writer().writeAttribute(atts.qName(i), atts.value(i));
     }
 }
 
@@ -121,7 +119,7 @@ FbReadHandler::RootHandler::RootHandler(FbReadHandler &owner, const QString &nam
 FbXmlHandler::NodeHandler * FbReadHandler::RootHandler::NewTag(const QString &name, const QXmlAttributes &atts)
 {
     switch (toKeyword(name)) {
-        case Body   : return new TextHandler(m_owner, name, atts, "div", name);
+        case Body   : return new TextHandler(m_owner, name, atts, "fb:body");
         case Descr  : return new DescrHandler(m_owner, name, atts);
         case Style  : return new StyleHandler(m_owner, name, atts);
         case Binary : return new BinaryHandler(m_owner, name, atts);
@@ -143,8 +141,7 @@ FbReadHandler::StyleHandler::StyleHandler(FbReadHandler &owner, const QString &n
     : BaseHandler(owner, name)
     , m_empty(true)
 {
-    writer().writeStartElement("div");
-    writer().writeAttribute("class", name);
+    writer().writeStartElement("fb:" + name);
     writeAttributes(atts);
 }
 
@@ -173,8 +170,7 @@ FbReadHandler::HeadHandler::HeadHandler(FbReadHandler &owner, const QString &nam
     : BaseHandler(owner, name)
     , m_empty(true)
 {
-    writer().writeStartElement("div");
-    writer().writeAttribute("class", name);
+    writer().writeStartElement("fb:" + name);
     writeAttributes(atts);
 }
 
@@ -234,7 +230,7 @@ FbXmlHandler::NodeHandler * FbReadHandler::DescrHandler::NewTag(const QString &n
 FbXmlHandler::NodeHandler * FbReadHandler::TitleHandler::NewTag(const QString &name, const QXmlAttributes &atts)
 {
     if (name == "annotation" || name == "history") {
-        return new TextHandler(m_owner, name, atts, "div", name);
+        return new TextHandler(m_owner, name, atts, "fb:" + name);
     }
     return new HeadHandler(m_owner, name, atts);
 }
@@ -244,17 +240,6 @@ FbXmlHandler::NodeHandler * FbReadHandler::TitleHandler::NewTag(const QString &n
 //---------------------------------------------------------------------------
 
 FB2_BEGIN_KEYHASH(FbReadHandler::TextHandler)
-    FB2_KEY( Section , "annotation"    );
-    FB2_KEY( Section , "author"        );
-    FB2_KEY( Section , "cite"          );
-    FB2_KEY( Section , "date"          );
-    FB2_KEY( Section , "epigraph"      );
-    FB2_KEY( Section , "poem"          );
-    FB2_KEY( Section , "section"       );
-    FB2_KEY( Section , "stanza"        );
-    FB2_KEY( Section , "subtitle"      );
-    FB2_KEY( Section , "title"         );
-
     FB2_KEY( Anchor  , "a"             );
     FB2_KEY( Table   , "table"         );
     FB2_KEY( Image   , "image"         );
@@ -272,20 +257,18 @@ FB2_BEGIN_KEYHASH(FbReadHandler::TextHandler)
     FB2_KEY( Code    , "code"          );
 FB2_END_KEYHASH
 
-FbReadHandler::TextHandler::TextHandler(FbReadHandler &owner, const QString &name, const QXmlAttributes &atts, const QString &tag, const QString &style)
+FbReadHandler::TextHandler::TextHandler(FbReadHandler &owner, const QString &name, const QXmlAttributes &atts, const QString &tag)
     : BaseHandler(owner, name)
     , m_parent(NULL)
     , m_tag(tag)
-    , m_style(style)
 {
     Init(atts);
 }
 
-FbReadHandler::TextHandler::TextHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts, const QString &tag, const QString &style)
+FbReadHandler::TextHandler::TextHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts, const QString &tag)
     : BaseHandler(parent->m_owner, name)
     , m_parent(parent)
     , m_tag(tag)
-    , m_style(style)
 {
     Init(atts);
     if (name == "empty-line") {
@@ -298,30 +281,26 @@ void FbReadHandler::TextHandler::Init(const QXmlAttributes &atts)
     if (m_tag.isEmpty()) return;
     writer().writeStartElement(m_tag);
     QString id = Value(atts, "id");
-    if (!m_style.isEmpty()) {
-        writer().writeAttribute("class", m_style);
-    }
     writeAttributes(atts);
 }
 
 FbXmlHandler::NodeHandler * FbReadHandler::TextHandler::NewTag(const QString &name, const QXmlAttributes &atts)
 {
-    QString tag, style;
+    QString tag;
     switch (toKeyword(name)) {
-        case Anchor    : return new AnchorHandler(this, name, atts);
-        case Image     : return new ImageHandler(m_owner, name, atts);
-        case Section   : tag = "div"; style = name; break;
-        case Parag     : tag = "p";   break;
-        case Strong    : tag = "b";   break;
-        case Emphas    : tag = "i";   break;
-        case Strike    : tag = "s";   break;
-        case Code      : tag = "tt";  break;
-        case Sub       : tag = "sub"; break;
-        case Sup       : tag = "sup"; break;
-        case Style     : tag = "span"; break;
-        default: ;
+        case Anchor : return new AnchorHandler(this, name, atts);
+        case Image  : return new ImageHandler(m_owner, name, atts);
+        case Parag  : tag = "p";   break;
+        case Strong : tag = "b";   break;
+        case Emphas : tag = "i";   break;
+        case Strike : tag = "s";   break;
+        case Code   : tag = "tt";  break;
+        case Sub    : tag = "sub"; break;
+        case Sup    : tag = "sup"; break;
+        case Style  : tag = "span"; break;
+        default:    ; tag = "fb:" + name;
     }
-    return new TextHandler(this, name, atts, tag, style);
+    return new TextHandler(this, name, atts, tag);
 }
 
 void FbReadHandler::TextHandler::TxtTag(const QString &text)
@@ -333,7 +312,7 @@ void FbReadHandler::TextHandler::EndTag(const QString &name)
 {
     Q_UNUSED(name);
     if (m_tag.isEmpty()) return;
-    if (m_tag == "div") writer().writeCharacters(" ");
+    if (m_tag.left(3) == "fb:") writer().writeCharacters(" ");
     writer().writeEndElement();
 }
 

+ 2 - 3
source/fb2read.hpp

@@ -136,7 +136,6 @@ private:
     class TextHandler : public BaseHandler
     {
         FB2_BEGIN_KEYLIST
-            Section,
             Anchor,
             Table,
             Image,
@@ -150,8 +149,8 @@ private:
             Code,
        FB2_END_KEYLIST
     public:
-        explicit TextHandler(FbReadHandler &owner, const QString &name, const QXmlAttributes &atts, const QString &tag, const QString &style = QString());
-        explicit TextHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts, const QString &tag, const QString &style = QString());
+        explicit TextHandler(FbReadHandler &owner, const QString &name, const QXmlAttributes &atts, const QString &tag);
+        explicit TextHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts, const QString &tag);
     protected:
         virtual NodeHandler * NewTag(const QString &name, const QXmlAttributes &atts);
         virtual void TxtTag(const QString &text);

+ 1 - 8
source/fb2save.cpp

@@ -295,14 +295,7 @@ void FbSaveHandler::TextHandler::Init(const QXmlAttributes &atts)
     m_writer.writeStartElement(m_tag, m_level);
     int count = atts.count();
     for (int i = 0; i < count; i++) {
-        QString name = atts.qName(i);
-        if (name == "id") {
-            m_writer.writeAttribute(name, atts.value(i));
-        } else if (name == "name") {
-            m_writer.writeAttribute(name, atts.value(i));
-        } else if (name.left(4) == "fb2_") {
-            m_writer.writeAttribute(name.mid(4), atts.value(i));
-        }
+        m_writer.writeAttribute(atts.qName(i), atts.value(i));
     }
 }
 

+ 15 - 0
source/fb2text.cpp

@@ -287,6 +287,20 @@ void FbTextPage::insertDate()
 {
 }
 
+void FbTextPage::insertText()
+{
+    FbTextElement element = current();
+    while (!element.isNull()) {
+        if (element.tagName() == "DIV") {
+            if (element.parent().isBody()) break;
+            element.appendOutside("<p><br></p>");
+            element.nextSibling().select();
+            return;
+        }
+        element = element.parent();
+    }
+}
+
 void FbTextPage::createDiv(const QString &className)
 {
     QString style = className;
@@ -384,6 +398,7 @@ QString FbTextPage::status()
 
 void FbTextPage::loadFinished()
 {
+    mainFrame()->evaluateJavaScript("window.focus()");
     mainFrame()->addToJavaScriptWindowObject("logger", &m_logger);
     FbTextElement element = body().findFirst("div.body");
     if (element.isNull()) element = body();

+ 1 - 0
source/fb2text.hpp

@@ -102,6 +102,7 @@ public slots:
     void insertPoem();
     void insertStanza();
     void insertDate();
+    void insertText();
     void createSection();
     void deleteSection();
     void createTitle();

+ 36 - 25
source/res/style.css

@@ -2,23 +2,23 @@ body {
   font-family: serif;
 }
 
-div.stylesheet{
+fb\:stylesheet{
   display: none;
 }
 
-div.description div {
+fb\:description div {
   display: none;
 }
 
-div.description div.title-info {
+fb\:description fb\:title-info {
   display: block;
 }
 
-div.description div.title-info div {
+fb\:description fb\:title-info div {
   display: none;
 }
 
-div.description div.title-info div.annotation {
+fb\:description fb\:title-info fb\:annotation {
   display: block;
   padding-left: 10;
   padding-right: 10;
@@ -33,7 +33,7 @@ div.description div.title-info div.annotation {
   margin-bottom: 1em;
 }
 
-div.annotation:before {
+fb\:annotation:before {
     color: gray;
     text-align: right;
     content: "<annotation>";
@@ -45,19 +45,19 @@ div.annotation:before {
     margin-bottom: -1em;
 }
 
-div.description div.title-info div.annotation div {
+fb\:description fb\:title-info fb\:annotation div {
   display: block;
 }
 
-div.description div.document-info {
+fb\:description fb\:document-info {
   display: block;
 }
 
-div.description div.document-info div {
+fb\:description fb\:document-info div {
   display: none;
 }
 
-div.description div.document-info div.history {
+fb\:description fb\:document-info fb\:history {
   display: block;
   padding-left: 10;
   padding-right: 10;
@@ -72,7 +72,7 @@ div.description div.document-info div.history {
   margin-bottom: 1em;
 }
 
-div.history:before {
+fb\:history:before {
     color: gray;
     text-align: right;
     content: "<history>";
@@ -84,11 +84,16 @@ div.history:before {
     margin-bottom: -1em;
 }
 
-div.description div.document-info div.history div {
+fb\:description fb\:document-info fb\:history div {
   display: block;
 }
 
-div.section {
+fb\:body {
+  display: block;
+}
+
+fb\:section {
+  display: block;
   border-top: none;
   border-bottom: none; 
   border-left: thin solid green; 
@@ -99,7 +104,8 @@ div.section {
   padding-right: 0;
 }
 
-div.title {
+fb\:title {
+  display: block;
   color: white;
   background: green;
   text-align: center;
@@ -107,11 +113,12 @@ div.title {
   font-size: 120%;
 }
 
-div.section div.title {
+fb\:section fb\:title {
   font-size: 100%;
 }
 
-div.subtitle {
+fb\:subtitle {
+  display: block;
   color: white;
   background: #d8a903;
   text-align: center;
@@ -120,40 +127,44 @@ div.subtitle {
   margin-right: 2%;
 }
 
-div.epigraph {
+fb\:epigraph {
+  display: block;
   border-left: 2 dotted purple;
   margin-left: 15%;
   padding-left: 4;
 }
 
-div.cite {
+fb\:cite {
+  display: block;
   border-left: 2 dotted teal;
   margin-left: 10%;
   padding-left: 4;
 }
 
-div.poem {
+fb\:poem {
+  display: block;
   border-left: thin solid blue;
   margin-left: 5%;
   padding-left: 4;
 }
 
-div.poem div.stanza {
+fb\:poem fb\:stanza {
+  display: block;
   border-left: thin solid blue;
   padding-left: 4;
 }
 
-div.poem div {
+fb\:poem div {
   margin-top: 1em;
   margin-bottom: 1em;
 }
 
-div.poem p {
+fb\:poem p {
   margin-top: 0;
   margin-bottom: 0;
 }
 
-div.body[fb2_name=notes] {
+fb\:body[name=notes] {
   border-top: none;
   border-bottom: none;
   border-left: none;
@@ -164,7 +175,7 @@ div.body[fb2_name=notes] {
   padding-right: 0;
 }
 
-div.body[fb2_name=notes] div[id] div.title {
+fb\:body[name=notes] fb\:section[id] fb\:title {
   font: inherit;
   float: left;
   margin-left: 4;
@@ -173,7 +184,7 @@ div.body[fb2_name=notes] div[id] div.title {
   padding-right: 4;
 }
 
-div.body[fb2_name=notes] div[id] div.title p {
+fb\:body[name=notes] fb\:section[id] fb\:title p {
   margin-top: 0;
   margin-bottom: 0;
 }