瀏覽代碼

Char format

Kandrashin Denis 13 年之前
父節點
當前提交
32d5ee5830
共有 7 個文件被更改,包括 31 次插入38 次删除
  1. 0 2
      source/fb2edit.qrc
  2. 0 15
      source/fb2main.cpp
  3. 0 2
      source/fb2main.h
  4. 29 17
      source/fb2read.cpp
  5. 2 2
      source/fb2read.h
  6. 二進制
      source/images/16x16/format-text-underline.png
  7. 二進制
      source/images/24x24/format-text-underline.png

+ 0 - 2
source/fb2edit.qrc

@@ -17,7 +17,6 @@
         <file>images/16x16/format-text-strikethrough.png</file>
         <file>images/16x16/format-text-subscript.png</file>
         <file>images/16x16/format-text-superscript.png</file>
-        <file>images/16x16/format-text-underline.png</file>
         <file>images/16x16/window-close.png</file>
         <file>images/16x16/zoom-in.png</file>
         <file>images/16x16/zoom-out.png</file>
@@ -38,7 +37,6 @@
         <file>images/24x24/format-text-strikethrough.png</file>
         <file>images/24x24/format-text-subscript.png</file>
         <file>images/24x24/format-text-superscript.png</file>
-        <file>images/24x24/format-text-underline.png</file>
         <file>images/24x24/window-close.png</file>
         <file>images/24x24/zoom-in.png</file>
         <file>images/24x24/zoom-out.png</file>

+ 0 - 15
source/fb2main.cpp

@@ -301,13 +301,6 @@ void MainWindow::createActions()
     menu->addAction(act);
     tool->addAction(act);
 
-    actionTextUnder = act = new QAction(icon("format-text-underline"), tr("Underline"), this);
-    act->setShortcuts(QKeySequence::Underline);
-    act->setCheckable(true);
-    connect(act, SIGNAL(triggered()), SLOT(textUnder()));
-    menu->addAction(act);
-    tool->addAction(act);
-
     actionTextStrike = act = new QAction(icon("format-text-strikethrough"), tr("Strikethrough"), this);
     act->setCheckable(true);
     connect(act, SIGNAL(triggered()), SLOT(textStrike()));
@@ -577,7 +570,6 @@ void MainWindow::currentCharFormatChanged(const QTextCharFormat &format)
     QFont font = format.font();
     actionTextBold   -> setChecked(font.bold());
     actionTextItalic -> setChecked(font.italic());
-    actionTextUnder  -> setChecked(font.underline());
     actionTextStrike -> setChecked(font.strikeOut());
     actionTextSub    -> setChecked(format.verticalAlignment() == QTextCharFormat::AlignSubScript);
     actionTextSup    -> setChecked(format.verticalAlignment() == QTextCharFormat::AlignSuperScript);
@@ -602,13 +594,6 @@ void MainWindow::textBold()
     mergeFormatOnWordOrSelection(fmt);
 }
 
-void MainWindow::textUnder()
-{
-    QTextCharFormat fmt;
-    fmt.setFontUnderline(actionTextUnder->isChecked());
-    mergeFormatOnWordOrSelection(fmt);
-}
-
 void MainWindow::textItalic()
 {
     QTextCharFormat fmt;

+ 0 - 2
source/fb2main.h

@@ -47,7 +47,6 @@ private slots:
     void viewText();
 
     void textBold();
-    void textUnder();
     void textItalic();
     void textStrike();
     void textSub();
@@ -91,7 +90,6 @@ private:
         *actionCopy,
         *actionPaste,
         *actionTextBold,
-        *actionTextUnder,
         *actionTextItalic,
         *actionTextStrike,
         *actionTextSub,

+ 29 - 17
source/fb2read.cpp

@@ -150,6 +150,14 @@ Fb2Handler::RootHandler::RootHandler(QTextDocument &document, const QString &nam
 
 Fb2Handler::RootHandler::~RootHandler()
 {
+    QTextBlockFormat blockFormat;
+    blockFormat.setTopMargin(6);
+    blockFormat.setBottomMargin(6);
+
+    m_cursor1.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
+    m_cursor1.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
+    m_cursor1.mergeBlockFormat(blockFormat);
+
     m_cursor1.endEditBlock();
 }
 
@@ -224,10 +232,6 @@ Fb2Handler::BodyHandler::BodyHandler(Fb2TextCursor &cursor, const QString &name)
     : TextHandler(cursor, name)
     , m_feed(false)
 {
-    QTextBlockFormat blockFormat;
-    blockFormat.setTopMargin(4);
-    blockFormat.setBottomMargin(4);
-    cursor.setBlockFormat(blockFormat);
 }
 
 Fb2Handler::BaseHandler * Fb2Handler::BodyHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
@@ -275,12 +279,6 @@ Fb2Handler::SectionHandler::SectionHandler(TextHandler &parent, const QString &n
     frameFormat.setBottomMargin(4);
     if (name == "title") frameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 80));
     cursor().insertFrame(frameFormat);
-
-    QTextBlockFormat blockFormat;
-    blockFormat.setTopMargin(4);
-    blockFormat.setBottomMargin(4);
-
-    cursor().setBlockFormat(blockFormat);
 }
 
 Fb2Handler::BaseHandler * Fb2Handler::SectionHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
@@ -291,6 +289,7 @@ Fb2Handler::BaseHandler * Fb2Handler::SectionHandler::NewTag(const QString &name
         case Paragraph:
         case Emptyline:
         case Image:
+        case Title:
             if (m_feed) cursor().insertBlock();
             m_feed = true;
             break;
@@ -462,29 +461,42 @@ FB2_BEGIN_KEYHASH(BlockHandler)
     insert("emphasis"      , Emphasis);
     insert("style"         , Style);
     insert("a"             , Anchor);
-    insert("strikethrough" , Strikethrough);
+    insert("strikethrough" , Strike);
     insert("sub"           , Sub);
     insert("sup"           , Sup);
     insert("code"          , Code);
     insert("image"         , Image);
 FB2_END_KEYHASH
 
-Fb2Handler::BlockHandler::BlockHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes)
+Fb2Handler::BlockHandler::BlockHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes, QTextCharFormat * format)
     : TextHandler(parent, name)
 {
     Q_UNUSED(attributes);
-    QTextBlockFormat blockFormat;
-    blockFormat.setTopMargin(6);
-    blockFormat.setBottomMargin(6);
-    cursor().mergeBlockFormat(blockFormat);
+    if (format) cursor().mergeCharFormat(*format);
 }
 
 Fb2Handler::BaseHandler * Fb2Handler::BlockHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
 {
     Q_UNUSED(attributes);
+    QTextCharFormat format;
     switch (toKeyword(name)) {
-        default: return new UnknowHandler(*this, name); break;
+        case Image    : return new ImageHandler(*this, name, attributes);
+        case Strong   : format.setFontWeight(QFont::Bold);  break;
+        case Emphasis : format.setFontItalic(true); break;
+        case Strike   : format.setFontStrikeOut(true); break;
+        case Sub      : format.setVerticalAlignment(QTextCharFormat::AlignSubScript); break;
+        case Sup      : format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); break;
+        case Anchor   : {
+            QString href = Value(attributes, "href");
+            if (!href.isEmpty()) {
+                format.setAnchorHref(href);
+                format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
+            }
+        } break;
+        default:
+            return new UnknowHandler(*this, name); break;
     }
+    return new BlockHandler(*this, name, attributes, &format);
 }
 
 void Fb2Handler::BlockHandler::TxtTag(const QString &text)

+ 2 - 2
source/fb2read.h

@@ -250,14 +250,14 @@ private:
             Emphasis,
             Style,
             Anchor,
-            Strikethrough,
+            Strike,
             Sub,
             Sup,
             Code,
             Image,
         FB2_END_KEYLIST
     public:
-        explicit BlockHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes);
+        explicit BlockHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes, QTextCharFormat *format = NULL);
     protected:
         virtual BaseHandler * NewTag(const QString &name, const QXmlAttributes &attributes);
         virtual void TxtTag(const QString &text);

二進制
source/images/16x16/format-text-underline.png


二進制
source/images/24x24/format-text-underline.png