Browse Source

Rename file: fb2view => fb2text

Kandrashin Denis 13 years ago
parent
commit
3fb0ba08ea

+ 68 - 68
fb2edit.pro

@@ -1,68 +1,68 @@
-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/fb2utils.h \
-    source/fb2save.hpp \
-    source/fb2dlgs.hpp \
-    source/fb2html.h
-
-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/fb2utils.cpp \
-    source/fb2dlgs.cpp \
-    source/fb2html.cpp
-
-RESOURCES = \
-    3rdparty/gnome/gnome.qrc \
-    source/res/fb2edit.qrc \
-    source/js/javascript.qrc \
-    3rdparty/fb2/fb2.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 \
-    source/js/get_location.js \
-    source/js/insert_title.js \
-    CMakeLists.txt
-
-if (unix) {
-
-    DEFINES += FB2_USE_LIBXML2
-    INCLUDEPATH += /usr/include/libxml2
-    LIBS += -lxml2
-
-}
-
-FORMS += \
-    source/fb2find.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/fb2utils.h \
+    source/fb2save.hpp \
+    source/fb2dlgs.hpp \
+    source/fb2html.h \
+    source/fb2text.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/fb2xml.cpp \
+    source/fb2xml2.cpp \
+    source/fb2utils.cpp \
+    source/fb2dlgs.cpp \
+    source/fb2html.cpp \
+    source/fb2text.cpp
+
+RESOURCES = \
+    3rdparty/gnome/gnome.qrc \
+    source/res/fb2edit.qrc \
+    source/js/javascript.qrc \
+    3rdparty/fb2/fb2.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 \
+    source/js/get_location.js \
+    source/js/insert_title.js \
+    CMakeLists.txt
+
+if (unix) {
+
+    DEFINES += FB2_USE_LIBXML2
+    INCLUDEPATH += /usr/include/libxml2
+    LIBS += -lxml2
+
+}
+
+FORMS += \
+    source/fb2find.ui

+ 0 - 98
source/fb2code.cpp

@@ -1,101 +1,6 @@
 #include "fb2code.hpp"
 #include "fb2dlgs.hpp"
 
-#ifdef FB2_USE_SCINTILLA
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//  http://qtcoder.blogspot.com/2010/10/qscintills.html
-//  http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciScintilla.html
-//
-/////////////////////////////////////////////////////////////////////////////
-
-#include <Qsci/qscilexerxml.h>
-#include <QtDebug>
-
-Fb2CodeEdit::Fb2CodeEdit(QWidget *parent) :
-    QsciScintilla(parent)
-{
-    zoomTo(1);
-    setUtf8(true);
-    setCaretLineVisible(true);
-    setCaretLineBackgroundColor(QColor("gainsboro"));
-    setWrapMode(QsciScintilla::WrapWord);
-
-    /*
-    //setup autocompletion
-    setAutoCompletionSource(QsciScintilla::AcsAll);
-    setAutoCompletionCaseSensitivity(true);
-    setAutoCompletionReplaceWord(true);
-    setAutoCompletionShowSingle(true);
-    setAutoCompletionThreshold(2);
-    */
-
-    //setup margins
-    setMarginsBackgroundColor(QColor("gainsboro"));
-    setMarginLineNumbers(0, true);
-    setFolding(QsciScintilla::BoxedFoldStyle, 1);
-
-    //setup brace matching
-    setBraceMatching(QsciScintilla::SloppyBraceMatch);
-    setMatchedBraceBackgroundColor(Qt::yellow);
-    setUnmatchedBraceForegroundColor(Qt::blue);
-
-    //setup end-of-line mode
-    #if defined Q_WS_X11
-    setEolMode(QsciScintilla::EolUnix);
-    #elif defined Q_WS_WIN
-    setEolMode(QsciScintilla::EolWindows);
-    #elif defined Q_WS_MAC
-    setEolMode(QsciScintilla::EolMac);
-    #endif
-
-    //setup auto-indentation
-    setAutoIndent(true);
-    setIndentationGuides(true);
-    setIndentationsUseTabs(false);
-    setIndentationWidth(2);
-
-    QsciLexerXML * lexer = new QsciLexerXML;
-    lexer->setFoldPreprocessor(true);
-
-    #ifdef Q_WS_WIN
-    lexer->setFont(QFont("Courier New", 8));
-    #else
-    lexer->setFont(QFont("Monospace", 8));
-    #endif
-
-    setLexer(lexer);
-
-    connect(this, SIGNAL(linesChanged()), SLOT(linesChanged()));
-}
-
-void Fb2CodeEdit::linesChanged()
-{
-    QString width = QString().setNum(lines() * 10);
-    setMarginWidth(0, width);
-}
-
-void Fb2CodeEdit::load(const QByteArray &array, const QList<int> &folds)
-{
-    SendScintilla(SCI_SETTEXT, array.constData());
-    SendScintilla(SCI_EMPTYUNDOBUFFER);
-    foldAll(false);
-    foldLine(1);
-    for (QList<int>::const_iterator it = folds.constBegin(); it != folds.constEnd(); it++) {
-        foldLine(*it);
-    }
-}
-
-void Fb2CodeEdit::zoomReset()
-{
-    zoomTo(1);
-}
-
-#endif // FB2_USE_SCINTILLA
-
-#ifdef FB2_USE_PLAINTEXT
-
 #include <QXmlInputSource>
 #include <QtGui>
 
@@ -581,6 +486,3 @@ void Fb2CodeEdit::setZoomRatio(qreal ratio)
         setFont(f);
     }
 }
-
-
-#endif // FB2_USE_PLAINTEXT

+ 0 - 32
source/fb2code.hpp

@@ -1,36 +1,6 @@
 #ifndef FB2CODE_H
 #define FB2CODE_H
 
-#ifdef FB2_USE_SCINTILLA
-
-#include <Qsci/qsciscintilla.h>
-#include <QList>
-
-class Fb2CodeEdit : public QsciScintilla
-{
-    Q_OBJECT
-public:
-    explicit Fb2CodeEdit(QWidget *parent = 0);
-    void load(const QByteArray &array, const QList<int> &folds);
-    
-signals:
-
-public slots:
-    void zoomReset();
-
-private slots:
-    void linesChanged();
-
-};
-
-#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>
@@ -170,6 +140,4 @@ private:
     friend class Fb2CodeEdit::LineNumberArea;
 };
 
-#endif // FB2_USE_PLAINTEXT
-
 #endif // FB2CODE_H

+ 1 - 1
source/fb2dlgs.cpp

@@ -1,7 +1,7 @@
 #include "fb2dlgs.hpp"
 #include "fb2code.hpp"
+#include "fb2text.hpp"
 #include "fb2tree.hpp"
-#include "fb2view.hpp"
 #include "fb2utils.h"
 #include "ui_fb2find.h"
 

+ 1 - 1
source/fb2head.cpp

@@ -12,7 +12,7 @@
 #include <QItemDelegate>
 #include <QTreeView>
 
-#include "fb2view.hpp"
+#include "fb2text.hpp"
 #include "fb2utils.h"
 
 //---------------------------------------------------------------------------

+ 49 - 0
source/fb2html.cpp

@@ -1,6 +1,8 @@
 #include "fb2html.h"
 #include "fb2utils.h"
 
+#include "fb2text.hpp"
+
 //---------------------------------------------------------------------------
 //  Fb2TextElement
 //---------------------------------------------------------------------------
@@ -26,3 +28,50 @@ bool Fb2TextElement::isTitle() const
 {
     return tagName() == "DIV" && attribute("class").toLower() == "title";
 }
+
+//---------------------------------------------------------------------------
+//  Fb2AddBodyCmd
+//---------------------------------------------------------------------------
+
+void Fb2AddBodyCmd::undo()
+{
+    m_page.body().lastChild().removeFromDocument();
+    Fb2TextElement(m_page.body().lastChild()).select();
+    m_page.update();
+}
+
+void Fb2AddBodyCmd::redo()
+{
+    m_page.body().appendInside("<div class=body><div class=section><p>text</p></div></div>");
+    Fb2TextElement(m_page.body().lastChild()).select();
+    m_page.update();
+}
+
+//---------------------------------------------------------------------------
+//  Fb2SubtitleCmd
+//---------------------------------------------------------------------------
+
+void Fb2SubtitleCmd::redo()
+{
+    QString html = "<div class=subtitle><p><br/></p></div>";
+    Fb2TextElement element = m_page.element(m_location);
+    if (m_element.isNull()) {
+        element.appendOutside(html);
+    } else {
+        element.appendOutside(m_element);
+    }
+    element = element.nextSibling();
+    m_position = element.location();
+    element.select();
+    m_page.update();
+}
+
+void Fb2SubtitleCmd::undo()
+{
+    Fb2TextElement element = m_page.element(m_position);
+    Fb2TextElement parent = element.parent();
+    m_element = element.takeFromDocument();
+    parent.select();
+    m_page.update();
+}
+

+ 27 - 0
source/fb2html.h

@@ -1,8 +1,11 @@
 #ifndef FB2HTML_H
 #define FB2HTML_H
 
+#include <QUndoCommand>
 #include <QWebElement>
 
+class Fb2TextPage;
+
 class Fb2TextElement : public QWebElement
 {
 public:
@@ -17,4 +20,28 @@ public:
     void select();
 };
 
+class Fb2AddBodyCmd : public QUndoCommand
+{
+public:
+    explicit Fb2AddBodyCmd(Fb2TextPage &page, QUndoCommand *parent = 0) : QUndoCommand(parent), m_page(page) {}
+    virtual void undo();
+    virtual void redo();
+private:
+    Fb2TextPage & m_page;
+};
+
+class Fb2SubtitleCmd : public QUndoCommand
+{
+public:
+    explicit Fb2SubtitleCmd(Fb2TextPage &page, const QString &location, QUndoCommand *parent = 0)
+        : QUndoCommand(parent), m_page(page), m_location(location) {}
+    virtual void undo();
+    virtual void redo();
+private:
+    Fb2TextElement m_element;
+    Fb2TextPage & m_page;
+    QString m_location;
+    QString m_position;
+};
+
 #endif // FB2HTML_H

+ 7 - 4
source/fb2main.cpp

@@ -7,8 +7,8 @@
 #include "fb2code.hpp"
 #include "fb2read.hpp"
 #include "fb2save.hpp"
+#include "fb2text.hpp"
 #include "fb2tree.hpp"
-#include "fb2view.hpp"
 #include "fb2head.hpp"
 #include "fb2utils.h"
 
@@ -329,13 +329,16 @@ void Fb2MainWindow::createActions()
     actionTitle = act = new QAction(tr("&Title"), this);
     menu->addAction(act);
 
-    actionSubtitle = act = new QAction(tr("&Subtitle"), this);
+    actionEpigraph = act = new QAction(tr("&Epigraph"), this);
     menu->addAction(act);
 
-    actionAuthor = act = new QAction(tr("&Author"), this);
+    actionDescr = act = new QAction(tr("&Annotation"), this);
     menu->addAction(act);
 
-    actionDescr = act = new QAction(tr("&Annotation"), this);
+    actionSubtitle = act = new QAction(tr("&Subtitle"), this);
+    menu->addAction(act);
+
+    actionAuthor = act = new QAction(tr("&Author"), this);
     menu->addAction(act);
 
     actionPoem = act = new QAction(tr("&Poem"), this);

+ 1 - 0
source/fb2main.hpp

@@ -112,6 +112,7 @@ private:
         *actionLink,
         *actionBody,
         *actionTitle,
+        *actionEpigraph,
         *actionSubtitle,
         *actionDescr,
         *actionPoem,

+ 1 - 1
source/fb2save.cpp

@@ -2,7 +2,7 @@
 #include <QtDebug>
 
 #include "fb2save.hpp"
-#include "fb2view.hpp"
+#include "fb2text.hpp"
 #include "fb2utils.h"
 
 #include <QAbstractNetworkCache>

+ 3 - 3
source/fb2save.hpp

@@ -1,5 +1,5 @@
-#ifndef Fb2Save_H
-#define Fb2Save_H
+#ifndef FB2SAVE_H
+#define FB2SAVE_H
 
 #include "fb2xml.h"
 #include "fb2temp.hpp"
@@ -188,4 +188,4 @@ private:
     Fb2SaveWriter & m_writer;
 };
 
-#endif // Fb2Save_H
+#endif // FB2SAVE_H

+ 1 - 1
source/fb2temp.cpp

@@ -6,7 +6,7 @@
 #include <QUrl>
 #include <QtDebug>
 
-#include "fb2view.hpp"
+#include "fb2text.hpp"
 
 //---------------------------------------------------------------------------
 //  Fb2TemporaryFile

+ 4 - 66
source/fb2view.cpp → source/fb2text.cpp

@@ -1,4 +1,4 @@
-#include "fb2view.hpp"
+#include "fb2text.hpp"
 #include "fb2dlgs.hpp"
 #include "fb2read.hpp"
 #include "fb2save.hpp"
@@ -104,75 +104,13 @@ Fb2TextElement Fb2TextPage::doc()
     return mainFrame()->documentElement();
 }
 
-class Fb2InsertBodyCommand : public QUndoCommand
-{
-public:
-    explicit Fb2InsertBodyCommand(Fb2TextPage &page, QUndoCommand *parent = 0) : QUndoCommand(parent), m_page(page) {}
-    virtual void undo();
-    virtual void redo();
-private:
-    Fb2TextPage & m_page;
-};
-
-void Fb2InsertBodyCommand::undo()
-{
-    m_page.body().lastChild().removeFromDocument();
-    Fb2TextElement(m_page.body().lastChild()).select();
-    m_page.update();
-}
-
-void Fb2InsertBodyCommand::redo()
-{
-    m_page.body().appendInside("<div class=body><div class=section><p>text</p></div></div>");
-    Fb2TextElement(m_page.body().lastChild()).select();
-    m_page.update();
-}
-
 void Fb2TextPage::insertBody()
 {
-    undoStack()->beginMacro("Insert title");
-    undoStack()->push(new Fb2InsertBodyCommand(*this));
+    undoStack()->beginMacro("Append body");
+    undoStack()->push(new Fb2AddBodyCmd(*this));
     undoStack()->endMacro();
 }
 
-class Fb2InsertSubtitleCmd : public QUndoCommand
-{
-public:
-    explicit Fb2InsertSubtitleCmd(Fb2TextPage &page, const QString &location, QUndoCommand *parent = 0)
-        : QUndoCommand(parent), m_page(page), m_location(location) {}
-    virtual void undo();
-    virtual void redo();
-private:
-    Fb2TextElement m_element;
-    Fb2TextPage & m_page;
-    QString m_location;
-    QString m_position;
-};
-
-void Fb2InsertSubtitleCmd::redo()
-{
-    QString html = "<div class=subtitle><p><br/></p></div>";
-    Fb2TextElement element = m_page.element(m_location);
-    if (m_element.isNull()) {
-        element.appendOutside(html);
-    } else {
-        element.appendOutside(m_element);
-    }
-    element = element.nextSibling();
-    m_position = element.location();
-    element.select();
-    m_page.update();
-}
-
-void Fb2InsertSubtitleCmd::undo()
-{
-    Fb2TextElement element = m_page.element(m_position);
-    Fb2TextElement parent = element.parent();
-    m_element = element.takeFromDocument();
-    parent.select();
-    m_page.update();
-}
-
 void Fb2TextPage::update()
 {
     emit contentsChanged();
@@ -188,7 +126,7 @@ void Fb2TextPage::insertSubtitle()
             Fb2TextElement previous = element.previousSibling();
             if (!previous.isNull()) element = previous;
             undoStack()->beginMacro("Insert subtitle");
-            undoStack()->push(new Fb2InsertSubtitleCmd(*this, element.location()));
+            undoStack()->push(new Fb2SubtitleCmd(*this, element.location()));
             undoStack()->endMacro();
             break;
         }

+ 3 - 3
source/fb2view.hpp → source/fb2text.hpp

@@ -1,5 +1,5 @@
-#ifndef FB2VIEW_H
-#define FB2VIEW_H
+#ifndef FB2TEXT_H
+#define FB2TEXT_H
 
 #include <QFrame>
 #include <QResizeEvent>
@@ -149,4 +149,4 @@ private:
     QDockWidget * dock;
 };
 
-#endif // FB2VIEW_H
+#endif // FB2TEXT_H

+ 1 - 1
source/fb2tree.cpp

@@ -10,8 +10,8 @@
 #include <QTreeView>
 #include <QUrl>
 
+#include "fb2text.hpp"
 #include "fb2utils.h"
-#include "fb2view.hpp"
 
 //---------------------------------------------------------------------------
 //  Fb2TreeItem

+ 3 - 3
source/fb2tree.hpp

@@ -1,5 +1,5 @@
-#ifndef FB2TREE_HPP
-#define FB2TREE_HPP
+#ifndef FB2TREE_H
+#define FB2TREE_H
 
 #include <QAbstractItemModel>
 #include <QMenu>
@@ -166,4 +166,4 @@ protected:
     Fb2TreeView * m_tree;
 };
 
-#endif // FB2TREE_HPP
+#endif // FB2TREE_H

+ 3 - 3
source/fb2utils.h

@@ -1,5 +1,5 @@
-#ifndef FB2TOOL_H
-#define FB2TOOL_H
+#ifndef FB2UTILS_H
+#define FB2UTILS_H
 
 #include <QIcon>
 #include <QString>
@@ -22,4 +22,4 @@ void addTools(QToolBar *tool, QWebView *view);
 
 }
 
-#endif // FB2TOOL_H
+#endif // FB2UTILS_H

+ 116 - 0
source/new_node.ui

@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>318</width>
+    <height>175</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Insert new tag</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
+   <item row="0" column="0">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>TextLabel</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1">
+    <widget class="QComboBox" name="combo">
+     <property name="editable">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="2">
+    <widget class="QLabel" name="text">
+     <property name="minimumSize">
+      <size>
+       <width>300</width>
+       <height>100</height>
+      </size>
+     </property>
+     <property name="styleSheet">
+      <string notr="true">border-style:outset;border-width:1px;border-radius:10px;padding:6px;</string>
+     </property>
+     <property name="text">
+      <string>TextLabel</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0" colspan="2">
+    <widget class="QDialogButtonBox" name="buttons">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttons</sender>
+   <signal>accepted()</signal>
+   <receiver>Dialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttons</sender>
+   <signal>rejected()</signal>
+   <receiver>Dialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>combo</sender>
+   <signal>editTextChanged(QString)</signal>
+   <receiver>Dialog</receiver>
+   <slot>update()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>184</x>
+     <y>18</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>158</x>
+     <y>87</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>