Browse Source

Simple XML plain text editor with syntax highlight

Kandrashin Denis 13 năm trước cách đây
mục cha
commit
94accf9e83
12 tập tin đã thay đổi với 557 bổ sung120 xóa
  1. 9 6
      CMakeLists.txt
  2. 62 72
      fb2edit.pro
  3. 376 5
      source/fb2code.cpp
  4. 83 9
      source/fb2code.hpp
  5. 5 10
      source/fb2main.cpp
  6. 1 2
      source/fb2main.hpp
  7. 9 9
      source/fb2read.cpp
  8. 2 5
      source/fb2save.cpp
  9. 1 1
      source/fb2view.cpp
  10. 1 1
      source/fb2view.hpp
  11. 4 0
      source/fb2xml2.cpp
  12. 4 0
      source/fb2xml2.h

+ 9 - 6
CMakeLists.txt

@@ -14,12 +14,16 @@ project(fb2edit)
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/cmake)
 
 find_package( Qt4 4.7.0 COMPONENTS QtCore QtGui QtMain QtNetwork QtWebkit QtXml QtXmlPatterns REQUIRED )
-find_package( QScintilla REQUIRED )
-find_package( LibXML2 REQUIRED )
+find_package( QScintilla )
+find_package( LibXML2 )
 
-INCLUDE(${QT_USE_FILE})
-ADD_DEFINITIONS(${QT_DEFINITIONS})
-ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
+include(${QT_USE_FILE})
+add_definitions(${QT_DEFINITIONS})
+add_definitions(${LIBXML2_DEFINITIONS})
+
+if (LIBXML2_FOUND) 
+    add_definitions(-DFB2_USE_LIBXML2)
+endif (LIBXML2_FOUND) 
 
 file( GLOB FB2_HEAD source/*.hpp     )
 file( GLOB FB2_SRCS source/*.cpp     )
@@ -36,7 +40,6 @@ set(CMAKE_IN_SOURCE_BUILD TRUE)
 
 add_definitions(-Wall -g)
 
-include(${QT_USE_FILE})
 qt4_wrap_ui(UI_HEADERS ${FB2_UIS})
 qt4_wrap_cpp(MOC_SRCS ${FB2_HEAD})
 qt4_add_resources(RCC_SRCS ${FB2_RES})

+ 62 - 72
fb2edit.pro

@@ -1,72 +1,62 @@
-HEADERS = \
-    source/fb2xml.h \
-    source/fb2xml2.h \
-    source/fb2app.hpp \
-    source/fb2code.hpp \
-    source/fb2head.hpp \
-    source/fb2main.hpp \
-    source/fb2read.hpp \
-    source/fb2temp.hpp \
-    source/fb2tree.hpp \
-    source/fb2view.hpp \
-    source/fb2note.hpp \
-    source/fb2utils.h \
-    source/fb2save.hpp
-
-SOURCES = \
-    source/fb2app.cpp \
-    source/fb2code.cpp \
-    source/fb2head.cpp \
-    source/fb2main.cpp \
-    source/fb2read.cpp \
-    source/fb2save.cpp \
-    source/fb2temp.cpp \
-    source/fb2tree.cpp \
-    source/fb2view.cpp \
-    source/fb2xml.cpp \
-    source/fb2xml2.cpp \
-    source/fb2note.cpp \
-    source/fb2utils.cpp
-
-RESOURCES = \
-    3rdparty/gnome/gnome.qrc \
-    source/res/fb2edit.qrc \
-    source/js/javascript.qrc
-
-TARGET = fb2edit
-
-TRANSLATIONS = source/ts/ru.ts
-
-VERSION = 0.01.1
-
-QT += xml
-QT += webkit
-QT += network
-
-LIBS += -lqscintilla2
-
-OTHER_FILES += \
-    source/res/style.css \
-    source/res/blank.fb2 \
-    source/js/export.js \
-    source/js/set_cursor.js \
-    source/js/get_status.js
-
-if (win32) {
-
-    INCLUDEPATH += ../libxml2/include
-    INCLUDEPATH += ../iconv/include
-
-    LIBS += -L../libxml2/lib -llibxml2
-    LIBS += -L../iconv/lib -liconv
-    LIBS += -L../zlib/lib -lzlib
-
-} else {
-
-    INCLUDEPATH += /usr/include/libxml2
-    LIBS += -lxml2
-
-}
-
-FORMS += \
-    source/fb2note.ui
+HEADERS = \
+    source/fb2xml.h \
+    source/fb2xml2.h \
+    source/fb2app.hpp \
+    source/fb2code.hpp \
+    source/fb2head.hpp \
+    source/fb2main.hpp \
+    source/fb2read.hpp \
+    source/fb2temp.hpp \
+    source/fb2tree.hpp \
+    source/fb2view.hpp \
+    source/fb2note.hpp \
+    source/fb2utils.h \
+    source/fb2save.hpp
+
+SOURCES = \
+    source/fb2app.cpp \
+    source/fb2code.cpp \
+    source/fb2head.cpp \
+    source/fb2main.cpp \
+    source/fb2read.cpp \
+    source/fb2save.cpp \
+    source/fb2temp.cpp \
+    source/fb2tree.cpp \
+    source/fb2view.cpp \
+    source/fb2xml.cpp \
+    source/fb2xml2.cpp \
+    source/fb2note.cpp \
+    source/fb2utils.cpp
+
+RESOURCES = \
+    3rdparty/gnome/gnome.qrc \
+    source/res/fb2edit.qrc \
+    source/js/javascript.qrc
+
+TARGET = fb2edit
+
+TRANSLATIONS = source/ts/ru.ts
+
+VERSION = 0.01.1
+
+QT += xml
+QT += webkit
+QT += network
+
+OTHER_FILES += \
+    source/res/style.css \
+    source/res/blank.fb2 \
+    source/js/export.js \
+    source/js/set_cursor.js \
+    source/js/get_status.js
+
+if (unix) {
+
+    DEFINES += FB2_USE_LIBXML2
+    INCLUDEPATH += /usr/include/libxml2
+    LIBS += -lxml2
+
+}
+
+FORMS += \
+    source/fb2note.ui

+ 376 - 5
source/fb2code.cpp

@@ -1,6 +1,6 @@
 #include "fb2code.hpp"
 
-#ifdef USE_SCINTILLA
+#ifdef FB2_USE_SCINTILLA
 
 /////////////////////////////////////////////////////////////////////////////
 //
@@ -86,22 +86,363 @@ void Fb2CodeEdit::load(const QByteArray &array, const QList<int> &folds)
     }
 }
 
-#else // USE_SCINTILLA
+void Fb2CodeEdit::zoomReset()
+{
+    if (codeEdit) codeEdit->zoomTo(1);
+}
+
+#endif // FB2_USE_SCINTILLA
+
+#ifdef FB2_USE_PLAINTEXT
 
 #include <QtGui>
 
+static const QColor DEFAULT_SYNTAX_CHAR		= Qt::blue;
+static const QColor DEFAULT_ELEMENT_NAME	= Qt::darkRed;
+static const QColor DEFAULT_COMMENT			= Qt::darkGreen;
+static const QColor DEFAULT_ATTRIBUTE_NAME	= Qt::red;
+static const QColor DEFAULT_ATTRIBUTE_VALUE	= Qt::darkGreen;
+static const QColor DEFAULT_ERROR			= Qt::darkMagenta;
+static const QColor DEFAULT_OTHER			= Qt::black;
+
+// Regular expressions for parsing XML borrowed from:
+// http://www.cs.sfu.ca/~cameron/REX.html
+static const QString EXPR_COMMENT			= "<!--[^-]*-([^-][^-]*-)*->";
+static const QString EXPR_COMMENT_BEGIN		= "<!--";
+static const QString EXPR_COMMENT_END		= "[^-]*-([^-][^-]*-)*->";
+static const QString EXPR_ATTRIBUTE_VALUE	= "\"[^<\"]*\"|'[^<']*'";
+static const QString EXPR_NAME				= "([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*";
+
+Fb2Highlighter::Fb2Highlighter(QObject* parent)
+: QSyntaxHighlighter(parent)
+{
+    init();
+}
+
+Fb2Highlighter::Fb2Highlighter(QTextDocument* parent)
+: QSyntaxHighlighter(parent)
+{
+    init();
+}
+
+Fb2Highlighter::Fb2Highlighter(QTextEdit* parent)
+: QSyntaxHighlighter(parent)
+{
+    init();
+}
+
+Fb2Highlighter::~Fb2Highlighter()
+{
+}
+
+void Fb2Highlighter::init()
+{
+    fmtSyntaxChar.setForeground(DEFAULT_SYNTAX_CHAR);
+    fmtElementName.setForeground(DEFAULT_ELEMENT_NAME);
+    fmtComment.setForeground(DEFAULT_COMMENT);
+    fmtAttributeName.setForeground(DEFAULT_ATTRIBUTE_NAME);
+    fmtAttributeValue.setForeground(DEFAULT_ATTRIBUTE_VALUE);
+    fmtError.setForeground(DEFAULT_ERROR);
+    fmtOther.setForeground(DEFAULT_OTHER);
+}
+
+void Fb2Highlighter::setHighlightColor(HighlightType type, QColor color, bool foreground)
+{
+    QTextCharFormat format;
+    if (foreground)
+        format.setForeground(color);
+    else
+        format.setBackground(color);
+    setHighlightFormat(type, format);
+}
+
+void Fb2Highlighter::setHighlightFormat(HighlightType type, QTextCharFormat format)
+{
+    switch (type)
+    {
+        case SyntaxChar:
+            fmtSyntaxChar = format;
+            break;
+        case ElementName:
+            fmtElementName = format;
+            break;
+        case Comment:
+            fmtComment = format;
+            break;
+        case AttributeName:
+            fmtAttributeName = format;
+            break;
+        case AttributeValue:
+            fmtAttributeValue = format;
+            break;
+        case Error:
+            fmtError = format;
+            break;
+        case Other:
+            fmtOther = format;
+            break;
+    }
+    rehighlight();
+}
+
+void Fb2Highlighter::highlightBlock(const QString& text)
+{
+    int i = 0;
+    int pos = 0;
+    int brackets = 0;
+
+    state = (previousBlockState() == InElement ? ExpectAttributeOrEndOfElement : NoState);
+
+    if (previousBlockState() == InComment)
+    {
+        // search for the end of the comment
+        QRegExp expression(EXPR_COMMENT_END);
+        pos = expression.indexIn(text, i);
+
+        if (pos >= 0)
+        {
+            // end comment found
+            const int iLength = expression.matchedLength();
+            setFormat(0, iLength - 3, fmtComment);
+            setFormat(iLength - 3, 3, fmtSyntaxChar);
+            i += iLength; // skip comment
+        }
+        else
+        {
+            // in comment
+            setFormat(0, text.length(), fmtComment);
+            setCurrentBlockState(InComment);
+            return;
+        }
+    }
+
+    for (; i < text.length(); i++)
+    {
+        switch (text.at(i).toAscii())
+        {
+        case '<':
+            brackets++;
+            if (brackets == 1)
+            {
+                setFormat(i, 1, fmtSyntaxChar);
+                state = ExpectElementNameOrSlash;
+            }
+            else
+            {
+                // wrong bracket nesting
+                setFormat(i, 1, fmtError);
+            }
+            break;
+
+        case '>':
+            brackets--;
+            if (brackets == 0)
+            {
+                setFormat(i, 1, fmtSyntaxChar);
+            }
+            else
+            {
+                // wrong bracket nesting
+                setFormat( i, 1, fmtError);
+            }
+            state = NoState;
+            break;
+
+        case '/':
+            if (state == ExpectElementNameOrSlash)
+            {
+                state = ExpectElementName;
+                setFormat(i, 1, fmtSyntaxChar);
+            }
+            else
+            {
+                if (state == ExpectAttributeOrEndOfElement)
+                {
+                    setFormat(i, 1, fmtSyntaxChar);
+                }
+                else
+                {
+                    processDefaultText(i, text);
+                }
+            }
+            break;
+
+        case '=':
+            if (state == ExpectEqual)
+            {
+                state = ExpectAttributeValue;
+                setFormat(i, 1, fmtOther);
+            }
+            else
+            {
+                processDefaultText(i, text);
+            }
+            break;
+
+        case '\'':
+        case '\"':
+            if (state == ExpectAttributeValue)
+            {
+                // search attribute value
+                QRegExp expression(EXPR_ATTRIBUTE_VALUE);
+                pos = expression.indexIn(text, i);
+
+                if (pos == i) // attribute value found ?
+                {
+                    const int iLength = expression.matchedLength();
+
+                    setFormat(i, 1, fmtOther);
+                    setFormat(i + 1, iLength - 2, fmtAttributeValue);
+                    setFormat(i + iLength - 1, 1, fmtOther);
+
+                    i += iLength - 1; // skip attribute value
+                    state = ExpectAttributeOrEndOfElement;
+                }
+                else
+                {
+                    processDefaultText(i, text);
+                }
+            }
+            else
+            {
+                processDefaultText(i, text);
+            }
+            break;
+
+        case '!':
+            if (state == ExpectElementNameOrSlash)
+            {
+                // search comment
+                QRegExp expression(EXPR_COMMENT);
+                pos = expression.indexIn(text, i - 1);
+
+                if (pos == i - 1) // comment found ?
+                {
+                    const int iLength = expression.matchedLength();
+
+                    setFormat(pos, 4, fmtSyntaxChar);
+                    setFormat(pos + 4, iLength - 7, fmtComment);
+                    setFormat(iLength - 3, 3, fmtSyntaxChar);
+                    i += iLength - 2; // skip comment
+                    state = NoState;
+                    brackets--;
+                }
+                else
+                {
+                    // Try find multiline comment
+                    QRegExp expression(EXPR_COMMENT_BEGIN); // search comment start
+                    pos = expression.indexIn(text, i - 1);
+
+                    //if (pos == i - 1) // comment found ?
+                    if (pos >= i - 1)
+                    {
+                        setFormat(i, 3, fmtSyntaxChar);
+                        setFormat(i + 3, text.length() - i - 3, fmtComment);
+                        setCurrentBlockState(InComment);
+                        return;
+                    }
+                    else
+                    {
+                        processDefaultText(i, text);
+                    }
+                }
+            }
+            else
+            {
+                processDefaultText(i, text);
+            }
+
+            break;
+
+        default:
+            const int iLength = processDefaultText(i, text);
+            if (iLength > 0)
+                i += iLength - 1;
+            break;
+        }
+    }
+
+    if (state == ExpectAttributeOrEndOfElement)
+    {
+        setCurrentBlockState(InElement);
+    }
+}
+
+int Fb2Highlighter::processDefaultText(int i, const QString& text)
+{
+    // length of matched text
+    int iLength = 0;
+
+    switch(state)
+    {
+    case ExpectElementNameOrSlash:
+    case ExpectElementName:
+        {
+            // search element name
+            QRegExp expression(EXPR_NAME);
+            const int pos = expression.indexIn(text, i);
+
+            if (pos == i) // found ?
+            {
+                iLength = expression.matchedLength();
+
+                setFormat(pos, iLength, fmtElementName);
+                state = ExpectAttributeOrEndOfElement;
+            }
+            else
+            {
+                setFormat(i, 1, fmtOther);
+            }
+        }
+        break;
+
+    case ExpectAttributeOrEndOfElement:
+        {
+            // search attribute name
+            QRegExp expression(EXPR_NAME);
+            const int pos = expression.indexIn(text, i);
+
+            if (pos == i) // found ?
+            {
+                iLength = expression.matchedLength();
+
+                setFormat(pos, iLength, fmtAttributeName);
+                state = ExpectEqual;
+            }
+            else
+            {
+                setFormat(i, 1, fmtOther);
+            }
+        }
+        break;
+
+    default:
+        setFormat(i, 1, fmtOther);
+        break;
+    }
+    return iLength;
+}
+
+qreal Fb2CodeEdit::baseFontSize = 10;
+qreal Fb2CodeEdit::zoomRatioMin = 0.2;
+qreal Fb2CodeEdit::zoomRatioMax = 5.0;
+
 Fb2CodeEdit::Fb2CodeEdit(QWidget *parent) : QPlainTextEdit(parent)
 {
     lineNumberArea = new LineNumberArea(this);
+    highlighter = new Fb2Highlighter(this);
+    highlighter->setDocument( document() );
 
     connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
     connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
     connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
 
+    zoomRatio = 1;
+
     #ifdef Q_WS_WIN
-    setFont(QFont("Courier New", 8));
+    setFont(QFont("Courier New", baseFontSize));
     #else
-    setFont(QFont("Monospace", 8));
+    setFont(QFont("Monospace", baseFontSize));
     #endif
 
     updateLineNumberAreaWidth(0);
@@ -190,4 +531,34 @@ void Fb2CodeEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
     }
 }
 
-#endif // USE_SCINTILLA
+void Fb2CodeEdit::zoomIn()
+{
+    qreal ratio = zoomRatio * 1.1;
+    ratio = qMin(ratio, zoomRatioMax);
+    setZoomRatio(ratio);
+}
+
+void Fb2CodeEdit::zoomOut()
+{
+    qreal ratio = zoomRatio / 1.1;
+    ratio = qMax(ratio, zoomRatioMin);
+    setZoomRatio(ratio);
+}
+
+void Fb2CodeEdit::zoomReset()
+{
+    setZoomRatio(1.0);
+}
+
+void Fb2CodeEdit::setZoomRatio(qreal ratio)
+{
+    if (!qFuzzyCompare(1 + zoomRatio, 1 + ratio)) {
+        zoomRatio = ratio;
+        QFont f = font();
+        f.setPointSizeF(baseFontSize * zoomRatio);
+        setFont(f);
+    }
+}
+
+
+#endif // FB2_USE_PLAINTEXT

+ 83 - 9
source/fb2code.hpp

@@ -1,7 +1,7 @@
 #ifndef FB2CODE_H
 #define FB2CODE_H
 
-#ifdef USE_SCINTILLA
+#ifdef FB2_USE_SCINTILLA
 
 #include <Qsci/qsciscintilla.h>
 #include <QList>
@@ -16,19 +16,88 @@ public:
 signals:
 
 public slots:
+    void zoomReset();
 
 private slots:
     void linesChanged();
 
 };
 
-#else // USE_SCINTILLA
+#else // FB2_USE_SCINTILLA
+    #ifndef FB2_USE_PLAINTEXT
+        #define FB2_USE_PLAINTEXT
+    #endif // FB2_USE_PLAINTEXT
+#endif // FB2_USE_SCINTILLA
+
+#ifdef FB2_USE_PLAINTEXT
 
 #include <QByteArray>
 #include <QList>
 #include <QPlainTextEdit>
 #include <QObject>
 
+#include <QSyntaxHighlighter>
+#include <QTextCharFormat>
+#include <QColor>
+#include <QTextEdit>
+
+class Fb2Highlighter : public QSyntaxHighlighter
+{
+public:
+    Fb2Highlighter(QObject* parent);
+    Fb2Highlighter(QTextDocument* parent);
+    Fb2Highlighter(QTextEdit* parent);
+    ~Fb2Highlighter();
+
+    enum HighlightType
+    {
+        SyntaxChar,
+        ElementName,
+        Comment,
+        AttributeName,
+        AttributeValue,
+        Error,
+        Other
+    };
+
+    void setHighlightColor(HighlightType type, QColor color, bool foreground = true);
+    void setHighlightFormat(HighlightType type, QTextCharFormat format);
+
+protected:
+    void highlightBlock(const QString& rstrText);
+    int  processDefaultText(int i, const QString& rstrText);
+
+private:
+    void init();
+
+    QTextCharFormat fmtSyntaxChar;
+    QTextCharFormat fmtElementName;
+    QTextCharFormat fmtComment;
+    QTextCharFormat fmtAttributeName;
+    QTextCharFormat fmtAttributeValue;
+    QTextCharFormat fmtError;
+    QTextCharFormat fmtOther;
+
+    enum ParsingState
+    {
+        NoState = 0,
+        ExpectElementNameOrSlash,
+        ExpectElementName,
+        ExpectAttributeOrEndOfElement,
+        ExpectEqual,
+        ExpectAttributeValue
+    };
+
+    enum BlockState
+    {
+        NoBlock = -1,
+        InComment,
+        InElement
+    };
+
+    ParsingState state;
+};
+
 QT_BEGIN_NAMESPACE
 class QPaintEvent;
 class QResizeEvent;
@@ -36,8 +105,6 @@ class QSize;
 class QWidget;
 QT_END_NAMESPACE
 
-class LineNumberArea;
-
 class Fb2CodeEdit : public QPlainTextEdit
 {
     Q_OBJECT
@@ -59,8 +126,9 @@ public:
     bool isRedoAvailable() { return false; }
 
 public slots:
-    void zoomIn() {}
-    void zoomOut() {}
+    void zoomIn();
+    void zoomOut();
+    void zoomReset();
 
 protected:
     void resizeEvent(QResizeEvent *event);
@@ -85,12 +153,18 @@ private:
 private:
     void lineNumberAreaPaintEvent(QPaintEvent *event);
     int lineNumberAreaWidth();
+    void setZoomRatio(qreal ratio);
+
+private:
+    Fb2Highlighter * highlighter;
     QWidget *lineNumberArea;
+    qreal zoomRatio;
+    static qreal baseFontSize;
+    static qreal zoomRatioMin;
+    static qreal zoomRatioMax;
     friend class Fb2CodeEdit::LineNumberArea;
 };
 
-typedef Fb2CodeEdit Fb2CodeEdit;
-
-#endif // USE_SCINTILLA
+#endif // FB2_USE_PLAINTEXT
 
 #endif // FB2CODE_H

+ 5 - 10
source/fb2main.cpp

@@ -396,7 +396,7 @@ void Fb2MainWindow::createActions()
     act->setShortcuts(QKeySequence::ZoomOut);
     menu->addAction(act);
 
-    actionZoomOrig = act = new QAction(FB2::icon("zoom-original"), tr("Zoom original"), this);
+    actionZoomReset = act = new QAction(FB2::icon("zoom-original"), tr("Zoom original"), this);
     menu->addAction(act);
 
     menu->addSeparator();
@@ -576,11 +576,6 @@ Fb2MainWindow *Fb2MainWindow::findFb2MainWindow(const QString &fileName)
     return 0;
 }
 
-void Fb2MainWindow::zoomOrig()
-{
-    if (codeEdit) codeEdit->zoomTo(1);
-}
-
 void Fb2MainWindow::checkScintillaUndo()
 {
     if (!codeEdit) return;
@@ -623,7 +618,7 @@ void Fb2MainWindow::viewCode()
     tool->addSeparator();
     tool->addAction(actionZoomIn);
     tool->addAction(actionZoomOut);
-    tool->addAction(actionZoomOrig);
+    tool->addAction(actionZoomReset);
     tool->setMovable(false);
 
     connect(codeEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
@@ -641,7 +636,7 @@ void Fb2MainWindow::viewCode()
 
     connect(actionZoomIn, SIGNAL(triggered()), codeEdit, SLOT(zoomIn()));
     connect(actionZoomOut, SIGNAL(triggered()), codeEdit, SLOT(zoomOut()));
-    connect(actionZoomOrig, SIGNAL(triggered()), this, SLOT(zoomOrig()));
+    connect(actionZoomReset, SIGNAL(triggered()), codeEdit, SLOT(zoomReset()));
 }
 
 void Fb2MainWindow::viewText()
@@ -683,7 +678,7 @@ void Fb2MainWindow::viewText()
 
     connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
     connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
-    connect(actionZoomOrig, SIGNAL(triggered()), textEdit, SLOT(zoomOrig()));
+    connect(actionZoomReset, SIGNAL(triggered()), textEdit, SLOT(zoomReset()));
     connect(actionInspect, SIGNAL(triggered()), textEdit, SLOT(showInspector()));
 
     if (!xml.isEmpty()) textEdit->load(curFile, xml);
@@ -706,7 +701,7 @@ void Fb2MainWindow::viewText()
 
     tool->addAction(actionZoomIn);
     tool->addAction(actionZoomOut);
-    tool->addAction(actionZoomOrig);
+    tool->addAction(actionZoomReset);
 }
 
 void Fb2MainWindow::viewHead()

+ 1 - 2
source/fb2main.hpp

@@ -55,7 +55,6 @@ private slots:
     void selectionChanged();
     void undoChanged();
     void redoChanged();
-    void zoomOrig();
     void openSettings();
 
 private:
@@ -117,7 +116,7 @@ private:
         *actionInspect,
         *actionZoomIn,
         *actionZoomOut,
-        *actionZoomOrig
+        *actionZoomReset
     ;
 };
 

+ 9 - 9
source/fb2read.cpp

@@ -35,27 +35,27 @@ void Fb2ReadThread::run()
     if (parse()) emit html(m_filename, m_html);
 }
 
-#ifdef _WIN32
+#ifdef FB2_USE_LIBXML2
 
 bool Fb2ReadThread::parse()
 {
     QXmlStreamWriter writer(&m_html);
     Fb2ReadHandler handler(*this, writer);
-    QXmlSimpleReader reader;
+    XML2::XmlReader reader;
     reader.setContentHandler(&handler);
     reader.setErrorHandler(&handler);
-    QXmlInputSource source;
     if (m_xml.isEmpty()) {
         QFile file(m_filename);
         if (!file.open(QFile::ReadOnly | QFile::Text)) {
             qCritical() << QObject::tr("Cannot read file %1: %2.").arg(m_filename).arg(file.errorString());
             return false;
         }
-        source.setData(file.readAll());
+        return reader.parse(file);
     } else {
+        QXmlInputSource source;
         source.setData(m_xml);
+        return reader.parse(source);
     }
-    return reader.parse(source);
 }
 
 #else
@@ -64,21 +64,21 @@ bool Fb2ReadThread::parse()
 {
     QXmlStreamWriter writer(&m_html);
     Fb2ReadHandler handler(*this, writer);
-    XML2::XmlReader reader;
+    QXmlSimpleReader reader;
     reader.setContentHandler(&handler);
     reader.setErrorHandler(&handler);
+    QXmlInputSource source;
     if (m_xml.isEmpty()) {
         QFile file(m_filename);
         if (!file.open(QFile::ReadOnly | QFile::Text)) {
             qCritical() << QObject::tr("Cannot read file %1: %2.").arg(m_filename).arg(file.errorString());
             return false;
         }
-        return reader.parse(file);
+        source.setData(file.readAll());
     } else {
-        QXmlInputSource source;
         source.setData(m_xml);
-        return reader.parse(source);
     }
+    return reader.parse(source);
 }
 
 #endif

+ 2 - 5
source/fb2save.cpp

@@ -65,9 +65,6 @@ void Fb2SaveDialog::init()
     filters << tr("Any files (*.*)");
     setNameFilters(filters);
 
-    QGridLayout *layout = (QGridLayout*) this->layout();
-    int row = layout->rowCount();
-
     combo = new QComboBox(this);
     foreach (QString codec, codecMap) {
         combo->addItem(codec);
@@ -78,8 +75,8 @@ void Fb2SaveDialog::init()
     label->setText(tr("&Encoding"));
     label->setBuddy(combo);
 
-    layout->addWidget(label, row, 0);
-    layout->addWidget(combo, row, 1);
+    layout()->addWidget(label);
+    layout()->addWidget(combo);
 }
 
 QString Fb2SaveDialog::fileName() const

+ 1 - 1
source/fb2view.cpp

@@ -227,7 +227,7 @@ void Fb2WebView::zoomOut()
     setZoomFactor(zoom * 0.9);
 }
 
-void Fb2WebView::zoomOrig()
+void Fb2WebView::zoomReset()
 {
     setZoomFactor(1);
 }

+ 1 - 1
source/fb2view.hpp

@@ -98,7 +98,7 @@ public slots:
     void insertLink();
     void zoomIn();
     void zoomOut();
-    void zoomOrig();
+    void zoomReset();
 
 private slots:
     void fixContents();

+ 4 - 0
source/fb2xml2.cpp

@@ -1,4 +1,7 @@
 #include "fb2xml2.h"
+
+#ifdef FB2_USE_LIBXML2
+
 #include <cstring>
 #include <libxml/tree.h>
 #include <libxml/parser.h>
@@ -651,3 +654,4 @@ int XmlReaderLocator::lineNumber(void) const
 
 } // namespace XML2
 
+#endif // FB2_USE_LIBXML2

+ 4 - 0
source/fb2xml2.h

@@ -1,6 +1,8 @@
 #ifndef FB2XML2_H
 #define FB2XML2_H
 
+#ifdef FB2_USE_LIBXML2
+
 /////////////////////////////////////////////////////////////////////////////
 //
 //   Append into project file:
@@ -104,4 +106,6 @@ private:
 
 } // namespace XML2
 
+#endif // FB2_USE_LIBXML2
+
 #endif // FB2XML2_H