fb2code.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Fb2Scintilla::Fb2Scintilla(QWidget *parent) :
  10. QsciScintilla(parent)
  11. {
  12. zoomTo(1);
  13. setUtf8(true);
  14. setCaretLineVisible(true);
  15. setCaretLineBackgroundColor(QColor("gainsboro"));
  16. // setWrapMode(QsciScintilla::WrapWord);
  17. setAutoIndent(true);
  18. setIndentationGuides(true);
  19. //setup autocompletion
  20. setAutoCompletionSource(QsciScintilla::AcsAll);
  21. setAutoCompletionCaseSensitivity(true);
  22. setAutoCompletionReplaceWord(true);
  23. setAutoCompletionShowSingle(true);
  24. setAutoCompletionThreshold(2);
  25. //setup margins
  26. setMarginsBackgroundColor(QColor("gainsboro"));
  27. setMarginLineNumbers(0, true);
  28. setFolding(QsciScintilla::BoxedFoldStyle, 1);
  29. //setup brace matching
  30. setBraceMatching(QsciScintilla::SloppyBraceMatch);
  31. setMatchedBraceBackgroundColor(Qt::yellow);
  32. setUnmatchedBraceForegroundColor(Qt::blue);
  33. // this->setFolding(QsciScintilla::CircledTreeFoldStyle, 1);
  34. this->setIndentation(true,4);
  35. this->setAutoIndent(true);
  36. //setup end-of-line mode
  37. #if defined Q_WS_X11
  38. this->setEolMode(QsciScintilla::EolUnix);
  39. #elif defined Q_WS_WIN
  40. this->setEolMode(QsciScintilla::EolWindows);
  41. #elif defined Q_WS_MAC
  42. this->setEolMode(QsciScintilla::EolMac);
  43. #endif
  44. //setup auto-indentation
  45. this->setAutoIndent(true);
  46. this->setIndentationGuides(true);
  47. this->setIndentationsUseTabs(false);
  48. this->setIndentationWidth(2);
  49. QsciLexerXML * lexer = new QsciLexerXML;
  50. lexer->setFoldPreprocessor(true);
  51. #ifdef Q_WS_WIN
  52. lexer->setFont(QFont("Courier New", 8));
  53. #else
  54. lexer->setFont(QFont("Monospace", 8));
  55. #endif
  56. setLexer(lexer);
  57. connect(this, SIGNAL(linesChanged()), SLOT(linesChanged()));
  58. }
  59. void Fb2Scintilla::linesChanged()
  60. {
  61. QString width = QString().setNum(lines() * 10);
  62. setMarginWidth(0, width);
  63. }
  64. void Fb2Scintilla::load(const QByteArray &array)
  65. {
  66. SendScintilla(SCI_SETTEXT, array.constData());
  67. SendScintilla(SCI_EMPTYUNDOBUFFER);
  68. }