File tree Expand file tree Collapse file tree 6 files changed +54
-10
lines changed
Expand file tree Collapse file tree 6 files changed +54
-10
lines changed Original file line number Diff line number Diff line change @@ -28,12 +28,14 @@ SOURCES += \
2828 main.cpp \
2929 mainwindow.cpp \
3030 logviewer.cpp \
31- finder.cpp
31+ finder.cpp \
32+ highlighter.cpp
3233
3334HEADERS += \
3435 mainwindow.h \
3536 logviewer.h \
36- finder.h
37+ finder.h \
38+ highlighter.h
3739
3840FORMS +=
3941
Original file line number Diff line number Diff line change 11#include " finder.h"
22
33Finder::Finder (QWidget *parent):
4+ QObject(parent),
45 mDockWidget(new QDockWidget(" finder" , parent)),
56 mRootWidget(new QWidget(mDockWidget )),
67 mMainLayout(new QHBoxLayout(mRootWidget )),
Original file line number Diff line number Diff line change 1+ #include " highlighter.h"
2+
3+ Highlighter::Highlighter (QObject *parent):
4+ QObject(parent)
5+ {
6+
7+ }
Original file line number Diff line number Diff line change 1+ #ifndef HIGHLIGHTER_H
2+ #define HIGHLIGHTER_H
3+
4+ #include < QObject>
5+ #include < QSharedPointer>
6+ #include < QSyntaxHighlighter>
7+
8+
9+ class Highlighter : public QObject
10+ {
11+ Q_OBJECT
12+
13+ public:
14+ explicit Highlighter (QObject *parent = nullptr );
15+
16+ QSharedPointer<QSyntaxHighlighter> logHighlighter ();
17+
18+ signals:
19+ void logHighlighterChanged ();
20+
21+ public slots:
22+ };
23+
24+ #endif // HIGHLIGHTER_H
Original file line number Diff line number Diff line change 11#include " logviewer.h"
22
33LogViewer::LogViewer (QWidget *parent):
4+ QObject(parent),
45 mRootWidget(new QWidget(parent)),
56 mRootLayout(new QGridLayout(mRootWidget )),
67 mMainTabWidget(new QTabWidget(mRootWidget )),
@@ -43,15 +44,21 @@ void LogViewer::addViewport(QString title)
4344 this , &LogViewer::highlightCurrentLine);
4445}
4546
46- void LogViewer::setHighlighter (QSyntaxHighlighter * highlighter)
47+ void LogViewer::setHighlighter (QSharedPointer< QSyntaxHighlighter> highlighter)
4748{
49+ Viewport *viewport;
4850 QPlainTextEdit *txtEdit;
4951 QTextDocument *txtDoc;
5052
51- txtEdit = mViewportList ->at (mCurrentIndex )->textEdit ;
53+ if (mCurrentIndex <= 0 ) return ;
54+
55+ viewport = mViewportList ->at (mCurrentIndex );
56+ txtEdit = viewport->textEdit ;
5257 txtDoc = txtEdit->document ();
5358
54- // todo
59+ // remove older and set newer highlighter
60+ viewport->highlighter = highlighter;
61+ highlighter->setDocument (txtDoc);
5562}
5663
5764void LogViewer::find (const QString &exp, const QTextDocument::FindFlags &options, bool regMode)
Original file line number Diff line number Diff line change 2020#include < QTextBlockFormat>
2121#include < QTextBlock>
2222#include < QTextFormat>
23+ #include < QSharedPointer>
2324
2425
2526class LogViewer : public QObject
@@ -29,20 +30,22 @@ class LogViewer : public QObject
2930public:
3031 struct Viewport {
3132 public:
32- Viewport (QString title, QPlainTextEdit *textEdit) {
33- this ->title = title;
34- this ->textEdit = textEdit;
35- }
33+ Viewport (QString title, QPlainTextEdit *textEdit):
34+ title (title),
35+ textEdit (textEdit),
36+ highlighter (nullptr ){}
37+
3638 QString title;
3739 QPlainTextEdit *textEdit;
40+ QSharedPointer<QSyntaxHighlighter> highlighter;
3841 };
3942
4043 LogViewer (QWidget *parent);
4144 virtual ~LogViewer ();
4245
4346 QWidget *rootWidget ();
4447 void addViewport (QString title = " default.txt" );
45- void setHighlighter (QSyntaxHighlighter * highlighter);
48+ void setHighlighter (QSharedPointer< QSyntaxHighlighter> highlighter);
4649
4750public slots:
4851 void find (const QString &exp, const QTextDocument::FindFlags &options, bool regMode);
You can’t perform that action at this time.
0 commit comments