diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-21 13:35:11 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-23 15:43:23 +0100 |
commit | 7fbd3cbdadb5bfb509b9bc396d949fe38a067072 (patch) | |
tree | 7d11120d4eb69aaa42039181d3b35a71b8ec0c9e /framework/src | |
parent | 46486a878310df55b686b8fbc2b6aaf35d613da7 (diff) | |
download | kube-7fbd3cbdadb5bfb509b9bc396d949fe38a067072.tar.gz kube-7fbd3cbdadb5bfb509b9bc396d949fe38a067072.zip |
Search in conversationview
...via syntax highligher or search api.
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | framework/src/frameworkplugin.cpp | 2 | ||||
-rw-r--r-- | framework/src/viewhighlighter.cpp | 91 | ||||
-rw-r--r-- | framework/src/viewhighlighter.h | 40 |
4 files changed, 136 insertions, 1 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 97cb453b..f11e6077 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | 1 | ||
2 | find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test WebEngine) | 2 | find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test WebEngine Gui) |
3 | find_package(KF5Mime "4.87.0" CONFIG REQUIRED) | 3 | find_package(KF5Mime "4.87.0" CONFIG REQUIRED) |
4 | find_package(Sink CONFIG REQUIRED) | 4 | find_package(Sink CONFIG REQUIRED) |
5 | find_package(KAsync CONFIG REQUIRED) | 5 | find_package(KAsync CONFIG REQUIRED) |
@@ -48,6 +48,7 @@ add_library(kubeframework SHARED | |||
48 | keyring.cpp | 48 | keyring.cpp |
49 | domainobjectcontroller.cpp | 49 | domainobjectcontroller.cpp |
50 | extensionmodel.cpp | 50 | extensionmodel.cpp |
51 | viewhighlighter.cpp | ||
51 | ) | 52 | ) |
52 | target_link_libraries(kubeframework | 53 | target_link_libraries(kubeframework |
53 | sink | 54 | sink |
@@ -58,6 +59,7 @@ target_link_libraries(kubeframework | |||
58 | Qt5::WebEngineWidgets | 59 | Qt5::WebEngineWidgets |
59 | Qt5::Test | 60 | Qt5::Test |
60 | Qt5::WebEngine | 61 | Qt5::WebEngine |
62 | Qt5::Gui | ||
61 | KF5::Codecs | 63 | KF5::Codecs |
62 | KF5::Contacts | 64 | KF5::Contacts |
63 | KAsync | 65 | KAsync |
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index b0e2f9c9..d512ce10 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp | |||
@@ -42,6 +42,7 @@ | |||
42 | #include "controller.h" | 42 | #include "controller.h" |
43 | #include "domainobjectcontroller.h" | 43 | #include "domainobjectcontroller.h" |
44 | #include "extensionmodel.h" | 44 | #include "extensionmodel.h" |
45 | #include "viewhighlighter.h" | ||
45 | 46 | ||
46 | #include <QtQml> | 47 | #include <QtQml> |
47 | #include <QQuickImageProvider> | 48 | #include <QQuickImageProvider> |
@@ -142,6 +143,7 @@ void FrameworkPlugin::registerTypes (const char *uri) | |||
142 | qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage"); | 143 | qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage"); |
143 | qmlRegisterType<ClipboardProxy>(uri, 1, 0, "Clipboard"); | 144 | qmlRegisterType<ClipboardProxy>(uri, 1, 0, "Clipboard"); |
144 | qmlRegisterType<StartupCheck>(uri, 1, 0, "StartupCheck"); | 145 | qmlRegisterType<StartupCheck>(uri, 1, 0, "StartupCheck"); |
146 | qmlRegisterType<ViewHighlighter>(uri, 1, 0, "ViewHighlighter"); | ||
145 | qmlRegisterSingletonType<WebEngineProfile>(uri, 1, 0, "WebEngineProfile", webengineprofile_singletontype_provider); | 147 | qmlRegisterSingletonType<WebEngineProfile>(uri, 1, 0, "WebEngineProfile", webengineprofile_singletontype_provider); |
146 | qmlRegisterSingletonType<Kube::Keyring>(uri, 1, 0, "Keyring", keyring_singletontype_provider); | 148 | qmlRegisterSingletonType<Kube::Keyring>(uri, 1, 0, "Keyring", keyring_singletontype_provider); |
147 | } | 149 | } |
diff --git a/framework/src/viewhighlighter.cpp b/framework/src/viewhighlighter.cpp new file mode 100644 index 00000000..553646f2 --- /dev/null +++ b/framework/src/viewhighlighter.cpp | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "viewhighlighter.h" | ||
20 | |||
21 | #include <QQuickTextDocument> | ||
22 | #include <QSyntaxHighlighter> | ||
23 | #include <QRegularExpression> | ||
24 | #include <QString> | ||
25 | |||
26 | class SearchHighlighter : public QSyntaxHighlighter | ||
27 | { | ||
28 | Q_OBJECT | ||
29 | |||
30 | public: | ||
31 | SearchHighlighter(QTextDocument *parent = 0) | ||
32 | : QSyntaxHighlighter(parent) | ||
33 | { | ||
34 | } | ||
35 | |||
36 | void setSearchString(const QString &s) | ||
37 | { | ||
38 | mSearchString = s; | ||
39 | rehighlight(); | ||
40 | } | ||
41 | |||
42 | protected: | ||
43 | void highlightBlock(const QString &text) override | ||
44 | { | ||
45 | if (!mSearchString.isEmpty()) { | ||
46 | QTextCharFormat format; | ||
47 | format.setFontWeight(QFont::Bold); | ||
48 | format.setBackground(QColor{"#f67400"}); | ||
49 | |||
50 | QRegularExpression expression(mSearchString, QRegularExpression::CaseInsensitiveOption); | ||
51 | auto i = expression.globalMatch(text); | ||
52 | while (i.hasNext()) { | ||
53 | auto match = i.next(); | ||
54 | setFormat(match.capturedStart(), match.capturedLength(), format); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | } | ||
59 | |||
60 | private: | ||
61 | QString mSearchString; | ||
62 | }; | ||
63 | |||
64 | struct ViewHighlighter::Private { | ||
65 | SearchHighlighter *searchHighligher; | ||
66 | |||
67 | }; | ||
68 | |||
69 | |||
70 | ViewHighlighter::ViewHighlighter(QObject *parent) | ||
71 | : QObject(parent), | ||
72 | d{new Private} | ||
73 | { | ||
74 | |||
75 | } | ||
76 | |||
77 | void ViewHighlighter::setTextDocument(QQuickTextDocument *document) | ||
78 | { | ||
79 | if (document) { | ||
80 | d->searchHighligher = new SearchHighlighter{document->textDocument()}; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | void ViewHighlighter::setSearchString(const QString &s) | ||
85 | { | ||
86 | if (d->searchHighligher) { | ||
87 | d->searchHighligher->setSearchString(s); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | #include "viewhighlighter.moc" | ||
diff --git a/framework/src/viewhighlighter.h b/framework/src/viewhighlighter.h new file mode 100644 index 00000000..00b4d4b6 --- /dev/null +++ b/framework/src/viewhighlighter.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #include <QObject> | ||
21 | #include <QSharedPointer> | ||
22 | |||
23 | class QQuickTextDocument; | ||
24 | |||
25 | class ViewHighlighter : public QObject { | ||
26 | Q_OBJECT | ||
27 | |||
28 | Q_PROPERTY(QString searchString WRITE setSearchString) | ||
29 | Q_PROPERTY(QQuickTextDocument *textDocument WRITE setTextDocument CONSTANT) | ||
30 | |||
31 | public: | ||
32 | ViewHighlighter(QObject *parent = nullptr); | ||
33 | |||
34 | void setTextDocument(QQuickTextDocument *); | ||
35 | void setSearchString(const QString& ); | ||
36 | |||
37 | private: | ||
38 | struct Private; | ||
39 | QSharedPointer<Private> d; | ||
40 | }; | ||