1
0

fb2code.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "fb2code.hpp"
  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. /*
  19. //setup autocompletion
  20. setAutoCompletionSource(QsciScintilla::AcsAll);
  21. setAutoCompletionCaseSensitivity(true);
  22. setAutoCompletionReplaceWord(true);
  23. setAutoCompletionShowSingle(true);
  24. setAutoCompletionThreshold(2);
  25. */
  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. //setup end-of-line mode
  35. #if defined Q_WS_X11
  36. setEolMode(QsciScintilla::EolUnix);
  37. #elif defined Q_WS_WIN
  38. setEolMode(QsciScintilla::EolWindows);
  39. #elif defined Q_WS_MAC
  40. setEolMode(QsciScintilla::EolMac);
  41. #endif
  42. //setup auto-indentation
  43. setAutoIndent(true);
  44. setIndentationGuides(true);
  45. setIndentationsUseTabs(false);
  46. setIndentationWidth(2);
  47. QsciLexerXML * lexer = new QsciLexerXML;
  48. lexer->setFoldPreprocessor(true);
  49. #ifdef Q_WS_WIN
  50. lexer->setFont(QFont("Courier New", 8));
  51. #else
  52. lexer->setFont(QFont("Monospace", 8));
  53. #endif
  54. setLexer(lexer);
  55. connect(this, SIGNAL(linesChanged()), SLOT(linesChanged()));
  56. }
  57. void Fb2Scintilla::linesChanged()
  58. {
  59. QString width = QString().setNum(lines() * 10);
  60. setMarginWidth(0, width);
  61. }
  62. void Fb2Scintilla::load(const QByteArray &array, const QList<int> &folds)
  63. {
  64. SendScintilla(SCI_SETTEXT, array.constData());
  65. SendScintilla(SCI_EMPTYUNDOBUFFER);
  66. foldAll(false);
  67. foldLine(1);
  68. for (QList<int>::const_iterator it = folds.constBegin(); it != folds.constEnd(); it++) {
  69. foldLine(*it);
  70. }
  71. }