File indexing completed on 2024-04-14 05:44:27
0001 /* 0002 * SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-only 0005 **/ 0006 0007 #include "verifier.h" 0008 0009 #include "regexphighlighter.h" 0010 0011 Verifier::Verifier(QWidget *parent) 0012 : KTextEdit(parent) 0013 /* QT_ANCHOR_DO_NOT_WORK: ,_current( 0 ) */ 0014 { 0015 setCheckSpellingEnabled(false); 0016 0017 _highlighter = nullptr; 0018 setMinimumSize(1, 1); 0019 } 0020 0021 /** 0022 Update text edit to show matches of regular expression 0023 */ 0024 void Verifier::verify(const QString ®) 0025 { 0026 if (_highlighter) { 0027 _highlighter->setRegExp(reg); 0028 _highlighter->rehighlight(); 0029 } 0030 } 0031 0032 /** 0033 Make the text edit display the text without any matches. 0034 */ 0035 void Verifier::clearRegexp() 0036 { 0037 if (_highlighter) { 0038 _highlighter->setRegExp(QString()); 0039 _highlighter->rehighlight(); 0040 } 0041 } 0042 0043 /** 0044 Set case sensitive matching 0045 */ 0046 void Verifier::setCaseSensitive(bool b) 0047 { 0048 if (_highlighter) { 0049 _highlighter->setCaseSensitive(b); 0050 } 0051 } 0052 0053 /** 0054 set minimal mathcing 0055 */ 0056 void Verifier::setMinimal(bool b) 0057 { 0058 if (_highlighter) { 0059 _highlighter->setMinimal(b); 0060 } 0061 } 0062 0063 // Qt anchors do not work for <pre>...</pre>, thefore scrolling to next/prev match 0064 // do not work. Enable this when they work. 0065 // void Verifier::gotoFirst() 0066 // { 0067 // gotoNum(1); 0068 // } 0069 // 0070 // void Verifier::gotoLast() 0071 // { 0072 // gotoNum( _count-1 ); 0073 // } 0074 // 0075 // void Verifier::gotoPrev() 0076 // { 0077 // gotoNum( _current-1 ); 0078 // } 0079 // 0080 // void Verifier::gotoNext() 0081 // { 0082 // gotoNum( _current+1 ); 0083 // } 0084 // 0085 // void Verifier::gotoNum( int which ) 0086 // { 0087 // QString anchor = QString::fromLatin1("match%1").arg(which); 0088 // scrollToAnchor( anchor ); 0089 // _current = which; 0090 // Q_EMIT currentChanged( _current ); 0091 // Q_EMIT goBackwardPossible( which != 0 ); 0092 // Q_EMIT goForwardPossible( which != _count -1 ); 0093 // } 0094 0095 void Verifier::setHighlighter(RegexpHighlighter *highlighter) 0096 { 0097 if (_highlighter) { 0098 _highlighter->deleteLater(); 0099 } 0100 _highlighter = highlighter; 0101 if (_highlighter) { 0102 setEnabled(true); 0103 } else { 0104 setEnabled(false); 0105 } 0106 } 0107 0108 #include "moc_verifier.cpp"