浏览代码

Open file as XML

Kandrashin Denis 13 年之前
父节点
当前提交
0e9abda48a
共有 6 个文件被更改,包括 28 次插入20 次删除
  1. 10 0
      source/fb2code.cpp
  2. 1 2
      source/fb2code.hpp
  3. 1 0
      source/fb2main.cpp
  4. 14 14
      source/fb2tree.cpp
  5. 2 2
      source/fb2tree.hpp
  6. 0 2
      source/fb2view.cpp

+ 10 - 0
source/fb2code.cpp

@@ -96,6 +96,7 @@ void Fb2CodeEdit::zoomReset()
 
 #ifdef FB2_USE_PLAINTEXT
 
+#include <QXmlInputSource>
 #include <QtGui>
 
 static const QColor DEFAULT_SYNTAX_CHAR     = Qt::blue;
@@ -450,6 +451,15 @@ Fb2CodeEdit::Fb2CodeEdit(QWidget *parent) : QPlainTextEdit(parent)
     highlightCurrentLine();
 }
 
+bool Fb2CodeEdit::read(QIODevice *device)
+{
+    QByteArray data = device->readAll();
+    QXmlInputSource source;
+    source.setData(data);
+    setPlainText(source.data());
+    return true;
+}
+
 int Fb2CodeEdit::lineNumberAreaWidth()
 {
     int digits = 1;

+ 1 - 2
source/fb2code.hpp

@@ -114,8 +114,7 @@ public:
 
     QString text() const { return toPlainText(); }
 
-    bool read(QIODevice *device)
-        { Q_UNUSED(device); return true; }
+    bool read(QIODevice *device);
 
     void load(const QByteArray data, const QList<int> folds)
         { setPlainText(QString::fromUtf8(data.data())); }

+ 1 - 0
source/fb2main.cpp

@@ -51,6 +51,7 @@ void Fb2MainWindow::init()
     treeView = NULL;
     headTree = NULL;
     toolEdit = NULL;
+    dockTree = NULL;
     messageEdit = NULL;
 
     readSettings();

+ 14 - 14
source/fb2tree.cpp

@@ -140,17 +140,6 @@ Fb2TreeModel::~Fb2TreeModel()
     if (m_root) delete m_root;
 }
 
-void Fb2TreeModel::expand(QTreeView *view)
-{
-    QModelIndex parent = QModelIndex();
-    int count = rowCount(parent);
-    for (int i = 0; i < count; i++) {
-        QModelIndex child = index(i, 0, parent);
-        Fb2TreeItem *node = item(child);
-        if (node && node->name() == "body") view->expand(child);
-    }
-}
-
 Fb2TreeItem * Fb2TreeModel::item(const QModelIndex &index) const
 {
     if (index.isValid()) {
@@ -203,7 +192,18 @@ QVariant Fb2TreeModel::data(const QModelIndex &index, int role) const
     return i ? i->text() : QVariant();
 }
 
-void Fb2TreeModel::select(const QModelIndex &index)
+void Fb2TreeModel::expandBody(QTreeView *view)
+{
+    QModelIndex parent = QModelIndex();
+    int count = rowCount(parent);
+    for (int i = 0; i < count; i++) {
+        QModelIndex child = index(i, 0, parent);
+        Fb2TreeItem *node = item(child);
+        if (node && node->name() == "body") view->expand(child);
+    }
+}
+
+void Fb2TreeModel::selectText(const QModelIndex &index)
 {
     Fb2TreeItem *node = item(index);
     QWebFrame *frame = m_view.page()->mainFrame();
@@ -277,7 +277,7 @@ void Fb2TreeView::activated(const QModelIndex &index)
     Fb2TreeModel *model = static_cast<Fb2TreeModel*>(this->model());
 
     disconnect(m_view.page(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
-    model->select(index);
+    model->selectText(index);
     connect(m_view.page(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
 }
 
@@ -301,6 +301,6 @@ void Fb2TreeView::updateTree()
 {
     Fb2TreeModel * model = new Fb2TreeModel(m_view, this);
     setModel(model);
-    model->expand(this);
+    model->expandBody(this);
     selectTree();
 }

+ 2 - 2
source/fb2tree.hpp

@@ -75,8 +75,8 @@ public:
     virtual ~Fb2TreeModel();
     QModelIndex index(const QString &location, QModelIndex current) const;
     Fb2WebView & view() { return m_view; }
-    void select(const QModelIndex &index);
-    void expand(QTreeView *view);
+    void selectText(const QModelIndex &index);
+    void expandBody(QTreeView *view);
 
 public:
     virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;

+ 0 - 2
source/fb2view.cpp

@@ -307,8 +307,6 @@ void Fb2WebView::insertNote()
 
 void Fb2WebView::insertLink()
 {
-    Fb2SaveDialog dlg;
-    dlg.exec();
 }
 
 void Fb2WebView::execCommand(const QString &cmd, const QString &arg)