fb2code.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef FB2CODE_H
  2. #define FB2CODE_H
  3. #ifdef USE_SCINTILLA
  4. #include <Qsci/qsciscintilla.h>
  5. #include <QList>
  6. class Fb2CodeEdit : public QsciScintilla
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit Fb2CodeEdit(QWidget *parent = 0);
  11. void load(const QByteArray &array, const QList<int> &folds);
  12. signals:
  13. public slots:
  14. private slots:
  15. void linesChanged();
  16. };
  17. #else // USE_SCINTILLA
  18. #include <QByteArray>
  19. #include <QList>
  20. #include <QPlainTextEdit>
  21. #include <QObject>
  22. QT_BEGIN_NAMESPACE
  23. class QPaintEvent;
  24. class QResizeEvent;
  25. class QSize;
  26. class QWidget;
  27. QT_END_NAMESPACE
  28. class LineNumberArea;
  29. class Fb2CodeEdit : public QPlainTextEdit
  30. {
  31. Q_OBJECT
  32. public:
  33. Fb2CodeEdit(QWidget *parent = 0);
  34. QString text() const { return toPlainText(); }
  35. bool read(QIODevice *device) { return true; }
  36. void zoomTo ( int size ) {}
  37. void load(const QByteArray data, const QList<int> folds)
  38. { setPlainText(QString::fromUtf8(data.data())); }
  39. bool isUndoAvailable() { return false; }
  40. bool isRedoAvailable() { return false; }
  41. public slots:
  42. void zoomIn() {}
  43. void zoomOut() {}
  44. protected:
  45. void resizeEvent(QResizeEvent *event);
  46. private slots:
  47. void updateLineNumberAreaWidth(int newBlockCount);
  48. void highlightCurrentLine();
  49. void updateLineNumberArea(const QRect &, int);
  50. private:
  51. class LineNumberArea : public QWidget
  52. {
  53. public:
  54. LineNumberArea(Fb2CodeEdit *parent) : QWidget(parent) { editor = parent; }
  55. QSize sizeHint() const { return QSize(editor->lineNumberAreaWidth(), 0); }
  56. protected:
  57. void paintEvent(QPaintEvent *event) { editor->lineNumberAreaPaintEvent(event); }
  58. private:
  59. Fb2CodeEdit *editor;
  60. };
  61. private:
  62. void lineNumberAreaPaintEvent(QPaintEvent *event);
  63. int lineNumberAreaWidth();
  64. QWidget *lineNumberArea;
  65. friend class Fb2CodeEdit::LineNumberArea;
  66. };
  67. typedef Fb2CodeEdit Fb2CodeEdit;
  68. #endif // USE_SCINTILLA
  69. #endif // FB2CODE_H