Browse Source

New class: Fb2Scintilla

Kandrashin Denis 13 years ago
parent
commit
812f026433
5 changed files with 89 additions and 61 deletions
  1. 2 0
      fb2edit.pro
  2. 57 0
      source/fb2code.cpp
  3. 21 0
      source/fb2code.h
  4. 9 59
      source/fb2main.cpp
  5. 0 2
      source/fb2main.h

+ 2 - 0
fb2edit.pro

@@ -1,5 +1,6 @@
 HEADERS = \
     source/fb2app.h \
+    source/fb2code.h
     source/fb2head.h \
     source/fb2main.h \
     source/fb2read.h \
@@ -11,6 +12,7 @@ HEADERS = \
 
 SOURCES = \
     source/fb2app.cpp \
+    source/fb2code.cpp \
     source/fb2head.cpp \
     source/fb2main.cpp \
     source/fb2read.cpp \

+ 57 - 0
source/fb2code.cpp

@@ -0,0 +1,57 @@
+#include "fb2code.h"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  http://qtcoder.blogspot.com/2010/10/qscintills.html
+//  http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciScintilla.html
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <Qsci/qscilexerxml.h>
+
+Fb2Scintilla::Fb2Scintilla(QWidget *parent) :
+    QsciScintilla(parent)
+{
+    zoomTo(1);
+    setUtf8(true);
+    setCaretLineVisible(true);
+    setCaretLineBackgroundColor(QColor("gainsboro"));
+    setWrapMode(QsciScintilla::WrapWord);
+
+    setEolMode(QsciScintilla::EolWindows);
+
+    setAutoIndent(true);
+    setIndentationGuides(true);
+
+    setAutoCompletionSource(QsciScintilla::AcsAll);
+    setAutoCompletionCaseSensitivity(true);
+    setAutoCompletionReplaceWord(true);
+    setAutoCompletionShowSingle(true);
+    setAutoCompletionThreshold(2);
+
+    setMarginsBackgroundColor(QColor("gainsboro"));
+    setMarginLineNumbers(0, true);
+    setFolding(QsciScintilla::BoxedFoldStyle, 1);
+
+    setBraceMatching(QsciScintilla::SloppyBraceMatch);
+    setMatchedBraceBackgroundColor(Qt::yellow);
+    setUnmatchedBraceForegroundColor(Qt::blue);
+
+    QFont font("Courier", 10);
+    font.setStyleHint(QFont::TypeWriter);
+
+    QsciLexerXML * lexer = new QsciLexerXML;
+    lexer->setFont(font, -1);
+
+    setBraceMatching(QsciScintilla::SloppyBraceMatch);
+    setLexer(lexer);
+
+    connect(this, SIGNAL(linesChanged()), SLOT(linesChanged()));
+}
+
+void Fb2Scintilla::linesChanged()
+{
+    QString width = QString().setNum(lines() * 10);
+    setMarginWidth(0, width);
+}
+

+ 21 - 0
source/fb2code.h

@@ -0,0 +1,21 @@
+#ifndef FB2CODE_H
+#define FB2CODE_H
+
+#include <Qsci/qsciscintilla.h>
+
+class Fb2Scintilla : public QsciScintilla
+{
+    Q_OBJECT
+public:
+    explicit Fb2Scintilla(QWidget *parent = 0);
+    
+signals:
+
+public slots:
+
+private slots:
+    void linesChanged();
+    
+};
+
+#endif // FB2CODE_H

+ 9 - 59
source/fb2main.cpp

@@ -5,14 +5,12 @@
 #include <QWebFrame>
 
 #include "fb2main.h"
+#include "fb2code.h"
 #include "fb2read.h"
 #include "fb2tree.h"
 #include "fb2view.h"
 #include "fb2head.h"
 
-#include <Qsci/qsciscintilla.h>
-#include <Qsci/qscilexerxml.h>
-
 #define FB2DELETE(p) { if ( (p) != NULL ) { delete p; p = NULL; } }
 
 Fb2MainWindow::Fb2MainWindow()
@@ -33,7 +31,7 @@ Fb2MainWindow::Fb2MainWindow(const QString &filename, ViewMode mode)
         viewText();
         textEdit->load(filename);
     } else {
-        createQsci();
+        viewCode();
         loadXML(filename);
     }
 }
@@ -498,51 +496,6 @@ void Fb2MainWindow::redoChanged()
     actionRedo->setEnabled(textEdit->RedoEnabled());
 }
 
-void Fb2MainWindow::createQsci()
-{
-    //  http://qtcoder.blogspot.com/2010/10/qscintills.html
-    //  http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciScintilla.html
-
-    if (codeEdit) return;
-    codeEdit = new QsciScintilla;
-    codeEdit->zoomTo(1);
-    codeEdit->setUtf8(true);
-    codeEdit->setCaretLineVisible(true);
-    codeEdit->setCaretLineBackgroundColor(QColor("gainsboro"));
-    codeEdit->setWrapMode(QsciScintilla::WrapWord);
-
-    codeEdit->setEolMode(QsciScintilla::EolWindows);
-
-    codeEdit->setAutoIndent(true);
-    codeEdit->setIndentationGuides(true);
-
-    codeEdit->setAutoCompletionSource(QsciScintilla::AcsAll);
-    codeEdit->setAutoCompletionCaseSensitivity(true);
-    codeEdit->setAutoCompletionReplaceWord(true);
-    codeEdit->setAutoCompletionShowSingle(true);
-    codeEdit->setAutoCompletionThreshold(2);
-
-    codeEdit->setMarginsBackgroundColor(QColor("gainsboro"));
-    codeEdit->setMarginLineNumbers(0, true);
-    codeEdit->setFolding(QsciScintilla::BoxedFoldStyle, 1);
-
-    codeEdit->setBraceMatching(QsciScintilla::SloppyBraceMatch);
-    codeEdit->setMatchedBraceBackgroundColor(Qt::yellow);
-    codeEdit->setUnmatchedBraceForegroundColor(Qt::blue);
-
-    QFont font("Courier", 10);
-    font.setStyleHint(QFont::TypeWriter);
-
-    QsciLexerXML * lexer = new QsciLexerXML;
-    lexer->setFont(font, -1);
-
-    codeEdit->setBraceMatching(QsciScintilla::SloppyBraceMatch);
-    codeEdit->setLexer(lexer);
-
-    setCentralWidget(codeEdit);
-    codeEdit->setFocus();
-}
-
 void Fb2MainWindow::createStatusBar()
 {
     statusBar()->showMessage(tr("Ready"));
@@ -654,7 +607,13 @@ void Fb2MainWindow::viewCode()
     FB2DELETE(textEdit);
     FB2DELETE(dockTree);
     FB2DELETE(headTree);
-    createQsci();
+
+    if (!codeEdit) {
+        codeEdit = new Fb2Scintilla;
+    }
+    codeEdit->setText(xml);
+    setCentralWidget(codeEdit);
+    codeEdit->setFocus();
 
     FB2DELETE(toolEdit);
     QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
@@ -671,9 +630,6 @@ void Fb2MainWindow::viewCode()
     tool->addAction(actionZoomOrig);
     tool->setMovable(false);
 
-    connect(codeEdit, SIGNAL(linesChanged()), this, SLOT(linesChanged()));
-    codeEdit->setText(xml);
-
     connect(codeEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
     connect(codeEdit, SIGNAL(textChanged()), this, SLOT(checkScintillaUndo()));
 
@@ -692,12 +648,6 @@ void Fb2MainWindow::viewCode()
     connect(actionZoomOrig, SIGNAL(triggered()), this, SLOT(zoomOrig()));
 }
 
-void Fb2MainWindow::linesChanged()
-{
-    QString width = QString().setNum(codeEdit->lines() * 10);
-    codeEdit->setMarginWidth(0, width);
-}
-
 void Fb2MainWindow::viewText()
 {
     if (centralWidget() == textEdit) return;

+ 0 - 2
source/fb2main.h

@@ -54,7 +54,6 @@ private slots:
     void clipboardDataChanged();
     void loadFinished(bool ok);
     void selectionChanged();
-    void linesChanged();
     void undoChanged();
     void redoChanged();
     void showInspector();
@@ -69,7 +68,6 @@ private:
     void init();
     void createHead();
     void createTree();
-    void createQsci();
     void createActions();
     void createStatusBar();
     void readSettings();