fb2code.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "fb2code.h"
  2. /////////////////////////////////////////////////////////////////////////////
  3. //
  4. // http://qtcoder.blogspot.com/2010/10/qscintills.html
  5. // http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciScintilla.html
  6. //
  7. /////////////////////////////////////////////////////////////////////////////
  8. #include <Qsci/qscilexerxml.h>
  9. #include <QtDebug>
  10. Fb2Scintilla::Fb2Scintilla(QWidget *parent) :
  11. QsciScintilla(parent)
  12. {
  13. zoomTo(1);
  14. setUtf8(true);
  15. setCaretLineVisible(true);
  16. setCaretLineBackgroundColor(QColor("gainsboro"));
  17. // setWrapMode(QsciScintilla::WrapWord);
  18. setAutoIndent(true);
  19. setIndentationGuides(true);
  20. //setup autocompletion
  21. setAutoCompletionSource(QsciScintilla::AcsAll);
  22. setAutoCompletionCaseSensitivity(true);
  23. setAutoCompletionReplaceWord(true);
  24. setAutoCompletionShowSingle(true);
  25. setAutoCompletionThreshold(2);
  26. //setup margins
  27. setMarginsBackgroundColor(QColor("gainsboro"));
  28. setMarginLineNumbers(0, true);
  29. setFolding(QsciScintilla::BoxedFoldStyle, 1);
  30. //setup brace matching
  31. setBraceMatching(QsciScintilla::SloppyBraceMatch);
  32. setMatchedBraceBackgroundColor(Qt::yellow);
  33. setUnmatchedBraceForegroundColor(Qt::blue);
  34. // this->setFolding(QsciScintilla::CircledTreeFoldStyle, 1);
  35. this->setIndentation(true,4);
  36. this->setAutoIndent(true);
  37. //setup end-of-line mode
  38. #if defined Q_WS_X11
  39. this->setEolMode(QsciScintilla::EolUnix);
  40. #elif defined Q_WS_WIN
  41. this->setEolMode(QsciScintilla::EolWindows);
  42. #elif defined Q_WS_MAC
  43. this->setEolMode(QsciScintilla::EolMac);
  44. #endif
  45. //setup auto-indentation
  46. this->setAutoIndent(true);
  47. this->setIndentationGuides(true);
  48. this->setIndentationsUseTabs(false);
  49. this->setIndentationWidth(2);
  50. QsciLexerXML * lexer = new QsciLexerXML;
  51. lexer->setFoldPreprocessor(true);
  52. #ifdef Q_WS_WIN
  53. lexer->setFont(QFont("Courier New", 8));
  54. #else
  55. lexer->setFont(QFont("Monospace", 8));
  56. #endif
  57. setLexer(lexer);
  58. connect(this, SIGNAL(linesChanged()), SLOT(linesChanged()));
  59. }
  60. void Fb2Scintilla::linesChanged()
  61. {
  62. QString width = QString().setNum(lines() * 10);
  63. setMarginWidth(0, width);
  64. }
  65. void Fb2Scintilla::load(const QByteArray &array, const QList<int> &folds)
  66. {
  67. SendScintilla(SCI_SETTEXT, array.constData());
  68. SendScintilla(SCI_EMPTYUNDOBUFFER);
  69. foldAll(false);
  70. foldLine(1);
  71. for (QList<int>::const_iterator it = folds.constBegin(); it != folds.constEnd(); it++) {
  72. foldLine(*it);
  73. }
  74. }