diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b959884..e9b3199 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,135 +1,137 @@ BISON_TARGET(qregexpparser qregexpparser.y ${CMAKE_CURRENT_BINARY_DIR}/gen_qregexpparser.cc COMPILE_FLAGS "-d -p qregexp") FLEX_TARGET(qregexplexer qregexpparser.l ${CMAKE_CURRENT_BINARY_DIR}/gen_qregexplexer.cpp COMPILE_FLAGS "-Pqregexp") ADD_FLEX_BISON_DEPENDENCY( qregexplexer qregexpparser ) +set_property(SOURCE ${BISON_qregexpparser_OUTPUTS} PROPERTY SKIP_AUTOMOC ON) +set_property(SOURCE ${FLEX_qregexplexer_OUTPUTS} PROPERTY SKIP_AUTOMOC ON) add_subdirectory( predefined ) add_subdirectory( pics ) include_directories( KWidgetStreamer/ KMultiFormListBox/ ) ########### next target ############### set(kregexpeditorcommon_SRCS ${BISON_qregexpparser_OUTPUTS} ${FLEX_qregexplexer_OUTPUTS} altnregexp.cpp altnwidget.cpp auxbuttons.cpp characterswidget.cpp charselector.cpp compoundregexp.cpp compoundwidget.cpp concregexp.cpp concwidget.cpp dcbutton.cpp dotregexp.cpp dragaccepter.cpp regexpeditorwindow.cpp emacsregexpconverter.cpp errormap.cpp infopage.cpp KMultiFormListBox/ccp.cpp KMultiFormListBox/kmultiformlistboxentry.cpp KMultiFormListBox/kmultiformlistbox.cpp KMultiFormListBox/kmultiformlistbox-multivisible.cpp KMultiFormListBox/kmultiformlistboxfactory.cpp KMultiFormListBox/indexWindow.cpp KMultiFormListBox/kmultiformlistbox-windowed.cpp KMultiFormListBox/widgetwindow.cpp KMultiFormListBox/windowlistboxitem.cpp kregexpeditorgui.cpp kregexpeditorguidialog.cpp kregexpeditorprivate.cpp KWidgetStreamer/kwidgetstreamer.cpp limitedcharlineedit.cpp lookaheadregexp.cpp lookaheadwidget.cpp multicontainerwidget.cpp myfontmetrics.cpp positionregexp.cpp qtregexpconverter.cpp qtregexphighlighter.cpp regexpbuttons.cpp regexpconverter.cpp regexp.cpp regexphighlighter.cpp regexpwidget.cpp repeatregexp.cpp repeatwidget.cpp scrollededitorwindow.cpp selectablelineedit.cpp singlecontainerwidget.cpp textrangeregexp.cpp textregexp.cpp textwidget.cpp userdefinedregexps.cpp verifier.cpp verifybuttons.cpp widgetfactory.cpp zerowidgets.cpp ) add_library(kregexpeditorcommon SHARED ${kregexpeditorcommon_SRCS}) target_link_libraries(kregexpeditorcommon KF5::ConfigWidgets KF5::IconThemes KF5::KIOCore KF5::TextWidgets KF5::WidgetsAddons Qt5::Widgets ) set_target_properties(kregexpeditorcommon PROPERTIES VERSION 1.0.0 SOVERSION 1) install(TARGETS kregexpeditorcommon ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) ########### next target ############### set(kregexpeditorgui_PART_SRCS kregexpeditorfactory.cpp ) add_library(kregexpeditorgui MODULE ${kregexpeditorgui_PART_SRCS}) target_link_libraries(kregexpeditorgui KF5::Service kregexpeditorcommon) install(TARGETS kregexpeditorgui DESTINATION ${KDE_INSTALL_PLUGINDIR}) ########### next target ############### set(kregexpeditor_SRCS main.cpp) file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*-apps-kregexpeditor.png") ecm_add_app_icon(kregexpeditor_SRCS ICONS ${ICONS_SRCS}) add_executable(kregexpeditor ${kregexpeditor_SRCS}) target_link_libraries(kregexpeditor KF5::KIOCore Qt5::Widgets kregexpeditorcommon KF5::Crash) install(TARGETS kregexpeditor ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install(FILES org.kde.kregexpeditor.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES kregexpeditorgui.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) install(FILES KMultiFormListBox/kmultiformlistboxentry.h KMultiFormListBox/kmultiformlistbox.h KMultiFormListBox/kmultiformlistboxfactory.h DESTINATION ${KDE_INSTALL_INCLUDEDIR} ) install(FILES KWidgetStreamer/kwidgetstreamer.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}) ecm_install_icons(ICONS 128-apps-kregexpeditor.png 16-apps-kregexpeditor.png 22-apps-kregexpeditor.png 32-apps-kregexpeditor.png 48-apps-kregexpeditor.png 64-apps-kregexpeditor.png DESTINATION ${KDE_INSTALL_ICONDIR} THEME hicolor ) diff --git a/src/KWidgetStreamer/kwidgetstreamer.cpp b/src/KWidgetStreamer/kwidgetstreamer.cpp index 2bed38e..1bd7c9b 100644 --- a/src/KWidgetStreamer/kwidgetstreamer.cpp +++ b/src/KWidgetStreamer/kwidgetstreamer.cpp @@ -1,182 +1,166 @@ /* * Copyright (c) 2002-2003 Jesper K. Pedersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. **/ #include "kwidgetstreamer.h" #include #include #include "kmultiformlistbox.h" void KWidgetStreamer::toStream(const QObject *from, QDataStream &stream) { - if (from->inherits("KMultiFormListBox")) { - // Hmm, we'll trust Qt that this dynamic_cast won't fail! - dynamic_cast(from)->toStream(stream); + const KMultiFormListBox *listBox = qobject_cast(from); + if (listBox) { + listBox->toStream(stream); + return; } propertyToStream(from, stream); } void KWidgetStreamer::fromStream(QDataStream &stream, QObject *to) { - if (to->inherits("KMultiFormListBox")) { - // Hmm, we'll trust Qt that this dynamic_cast won't fail! - dynamic_cast(to)->fromStream(stream); + KMultiFormListBox *listBox = qobject_cast(to); + if (listBox) { + listBox->toStream(stream); + return; } propertyFromStream(stream, to); } void KWidgetStreamer::propertyToStream(const QObject *from, QDataStream &stream) { // Only handle widgets. Alternatives to widgets are layouts, validators, timers, etc. - if (!from->inherits("QWidget")) { + if (!qobject_cast(from)) { return; } // Stream in all the children (if any) const QList children = from->children(); - //unsigned int count; - //stream >> count; if (children.count() > 0) { stream << children.count(); for (int i = 0; i < children.size(); ++i) { toStream(children.at(i), stream); } } else { stream << (unsigned int)0; } // Now stream out properties for (PropertyMapIt mapIt = _map.constBegin(); mapIt != _map.constEnd(); ++mapIt) { QString tp = mapIt.key(); PropertyList list = mapIt.value(); if (from->inherits(tp.toLocal8Bit())) { for (PropertyListIt it = list.begin(); it != list.end(); ++it) { QVariant prop = from->property((*it).toLocal8Bit()); if (!prop.isValid()) { qWarning("Invalid property: %s:%s", qPrintable(tp), qPrintable(*it)); } stream << prop; } } } } void KWidgetStreamer::propertyFromStream(QDataStream &stream, QObject *to) { // Only handle widgets. Alternatives to widgets are layouts, validators, timers, etc. - if (!to->inherits("QWidget")) { + if (!qobject_cast(to)) { return; } // Stream in all the children (if any) const QList children = to->children(); - //const QObjectList* children = to->children(); - - /* unsigned int count; - - stream >> count; - - Q_ASSERT( count == 0 ); - */ for (int i = 0; i < children.size(); ++i) { fromStream(stream, children.at(i)); } // Now stream in properties for (PropertyMapIt mapIt = _map.constBegin(); mapIt != _map.constEnd(); ++mapIt) { QString tp = mapIt.key(); PropertyList list = mapIt.value(); if (to->inherits(tp.toLocal8Bit())) { for (PropertyListIt it = list.begin(); it != list.end(); ++it) { QVariant value; stream >> value; to->setProperty((*it).toLocal8Bit(), value); } } } } KWidgetStreamer::KWidgetStreamer() { - QStringList l; - // QCheckBox - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("checked") << QStringLiteral("tristate"); - _map.insert(QStringLiteral("QCheckBox"), l); + _map.insert(QStringLiteral("QCheckBox"), { + QStringLiteral("enabled"), QStringLiteral("checked"), + QStringLiteral("tristate"), + }); // QComboBox - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("editable") << QStringLiteral("currentItem") - << QStringLiteral("maxCount") << QStringLiteral("insertionPolicy") - << QStringLiteral("autoCompletion"); - _map.insert(QStringLiteral("QComboBox"), l); + _map.insert(QStringLiteral("QComboBox"), { + QStringLiteral("enabled"), QStringLiteral("editable"), + QStringLiteral("currentItem"), QStringLiteral("maxCount"), + QStringLiteral("insertionPolicy"), QStringLiteral("autoCompletion"), + }); // QDial - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("tracking") << QStringLiteral("wrapping") - << QStringLiteral("value"); - _map.insert(QStringLiteral("QDial"), l); + _map.insert(QStringLiteral("QDial"), { + QStringLiteral("enabled"), QStringLiteral("tracking"), + QStringLiteral("wrapping"), QStringLiteral("value"), + }); // QLCDNumber - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("digitCount") << QStringLiteral("mode") - << QStringLiteral("segmentStyle") << QStringLiteral("value"); - _map.insert(QStringLiteral("QLCDNumber"), l); + _map.insert(QStringLiteral("QLCDNumber"), { + QStringLiteral("enabled"), QStringLiteral("digitCount"), + QStringLiteral("mode"), QStringLiteral("segmentStyle"), + QStringLiteral("value"), + }); // QLineEdit - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("text") << QStringLiteral("maxLength") - << QStringLiteral("echoMode") << QStringLiteral("alignment"); - _map.insert(QStringLiteral("QLineEdit"), l); + _map.insert(QStringLiteral("QLineEdit"), { + QStringLiteral("enabled"), QStringLiteral("text"), + QStringLiteral("maxLength"), QStringLiteral("echoMode"), + QStringLiteral("alignment"), + }); // QMultiLineEdit - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("plainText"); - _map.insert(QStringLiteral("QTextEdit"), l); + _map.insert(QStringLiteral("QTextEdit"), { + QStringLiteral("enabled"), QStringLiteral("plainText") + }); // QRadioButton - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("checked"); - _map.insert(QStringLiteral("QRadioButton"), l); + _map.insert(QStringLiteral("QRadioButton"), { + QStringLiteral("enabled"), QStringLiteral("checked") + }); // QSlider - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("value"); - _map.insert(QStringLiteral("QSlider"), l); + _map.insert(QStringLiteral("QSlider"), { + QStringLiteral("enabled"), QStringLiteral("value"), + }); // QSpinBox - l.clear(); - l << QStringLiteral("enabled") - << QStringLiteral("value"); - _map.insert(QStringLiteral("QSpinBox"), l); + _map.insert(QStringLiteral("QSpinBox"), { + QStringLiteral("enabled"), QStringLiteral("value"), + }); } diff --git a/src/characterswidget.cpp b/src/characterswidget.cpp index 0f6dfe5..cf30406 100644 --- a/src/characterswidget.cpp +++ b/src/characterswidget.cpp @@ -1,462 +1,462 @@ /* * Copyright (c) 2002-2003 Jesper K. Pedersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. **/ #include "characterswidget.h" #include #include #include #include #include #include #include #include #include "textrangeregexp.h" #include "charselector.h" #include "myfontmetrics.h" #include "regexpconverter.h" CharacterEdits *CharactersWidget::_configWindow = nullptr; CharactersWidget::CharactersWidget(RegExpEditorWindow *editorWindow, QWidget *parent) : RegExpWidget(editorWindow, parent) { _regexp = new TextRangeRegExp(false /* not used */); } CharactersWidget::CharactersWidget(TextRangeRegExp *regexp, RegExpEditorWindow *editorWindow, QWidget *parent) : RegExpWidget(editorWindow, parent) { _regexp = dynamic_cast(regexp->clone()); Q_ASSERT(_regexp); } CharactersWidget::~CharactersWidget() { delete _regexp; } QSize CharactersWidget::sizeHint() const { QFontMetrics metrics = fontMetrics(); _textSize = HackCalculateFontSize(metrics, title()); // _textSize = metrics.size(0, title()); QSize headerSize = QSize(_textSize.width() + 4 * bdSize, _textSize.height()); _contentSize = HackCalculateFontSize(metrics, text()); // _contentSize = metrics.size(0, text()); return QSize(qMax(headerSize.width(), bdSize + _contentSize.width() + bdSize + 2 * pw), headerSize.height() + bdSize + _contentSize.height() + bdSize + 2 * pw); } void CharactersWidget::paintEvent(QPaintEvent *e) { QSize mySize = sizeHint(); QPainter painter(this); drawPossibleSelection(painter, mySize); int center = _textSize.height() / 2; int offset = 0; // draw the horizontal line and the label painter.drawLine(pw, center, bdSize, center); offset += pw + 2 * bdSize; painter.drawText(offset, 0, _textSize.width(), _textSize.height(), 0, title()); offset += _textSize.width() + bdSize; painter.drawLine(offset, center, mySize.width(), center); // Draw the rest of the lines int y = mySize.width() - pw; int x = mySize.height() - pw; painter.drawLine(0, center, 0, mySize.height()); painter.drawLine(y, center, y, mySize.height()); painter.drawLine(0, x, y, x); // Draw the text painter.drawText(bdSize, bdSize + _textSize.height(), _contentSize.width(), _contentSize.height(), 0, text()); RegExpWidget::paintEvent(e); } RegExp *CharactersWidget::regExp() const { RegExp *r = _regexp->clone(); r->setSelected(isSelected()); return r; } QString CharactersWidget::text() const { QString res = QString(); if (_regexp->wordChar()) { res += i18n("- A word character\n"); } if (_regexp->nonWordChar()) { res += i18n("- A non-word character\n"); } if (_regexp->digit()) { res += i18n("- A digit character\n"); } if (_regexp->nonDigit()) { res += i18n("- A non-digit character\n"); } if (_regexp->space()) { res += i18n("- A space character\n"); } if (_regexp->nonSpace()) { res += i18n("- A non-space character\n"); } // Single characters QStringList chars = _regexp->chars(); if (!chars.isEmpty()) { QString str = chars.join(QStringLiteral(", ")); res += QStringLiteral("- ") + str + QStringLiteral("\n"); } // Ranges characters - foreach (const StringPair &elm, _regexp->range()) { + for (const StringPair &elm : _regexp->range()) { QString fromText = elm.first; QString toText = elm.second; res += i18nc("a range of characters", "- from %1 to %2\n", fromText, toText); } return res.left(res.length() - 1); } QString CharactersWidget::title() const { if (_regexp->negate()) { return i18n("Any Character Except"); } else { return i18n("One of Following Characters"); } } RegExpWidget *CharactersWidget::findWidgetToEdit(QPoint globalPos) { if (QRect(mapToGlobal(QPoint(0, 0)), size()).contains(globalPos)) { return this; } else { return nullptr; } } int CharactersWidget::edit() { if (_configWindow == 0) { QApplication::setOverrideCursor(Qt::WaitCursor); // No parent here, as this window should continue to exists. _configWindow = new CharacterEdits(0); _configWindow->setObjectName(QStringLiteral("CharactersWidget::_configWindow")); QApplication::restoreOverrideCursor(); } _configWindow->move(QCursor::pos() - QPoint(_configWindow->sizeHint().width() / 2, _configWindow->sizeHint().height() / 2)); _configWindow->setRegexp(_regexp); int ret = _configWindow->exec(); if (ret == QDialog::Accepted) { _editorWindow->updateContent(0); update(); } return ret; } void CharacterEdits::addCharacter(const QString &txt) { KMultiFormListBoxEntryList list = _single->elements(); - foreach (KMultiFormListBoxEntry *e, list) { - SingleEntry *entry = dynamic_cast(e); + for (KMultiFormListBoxEntry *e : list) { + SingleEntry *entry = qobject_cast(e); if (entry && entry->isEmpty()) { entry->setText(txt); return; } } SingleEntry *entry = new SingleEntry(_single); entry->setText(txt); _single->append(entry); } void CharacterEdits::addRange(const QString &from, const QString &to) { KMultiFormListBoxEntryList list = _range->elements(); - foreach (KMultiFormListBoxEntry *e, list) { - RangeEntry *entry = dynamic_cast(e); + for (KMultiFormListBoxEntry *e : list) { + RangeEntry *entry = qobject_cast(e); if (entry && entry->isEmpty()) { entry->setFrom(from); entry->setTo(to); return; } } RangeEntry *entry = new RangeEntry(_range); entry->setFrom(from); entry->setTo(to); _range->append(entry); } void CharacterEdits::setRegexp(TextRangeRegExp *regexp) { _regexp = regexp; negate->setChecked(regexp->negate()); digit->setChecked(regexp->digit()); _nonDigit->setChecked(regexp->nonDigit()); space->setChecked(regexp->space()); _nonSpace->setChecked(regexp->nonSpace()); wordChar->setChecked(regexp->wordChar()); _nonWordChar->setChecked(regexp->nonWordChar()); bool enabled = (RegExpConverter::current()->features() & RegExpConverter::CharacterRangeNonItems); _nonWordChar->setEnabled(enabled); _nonDigit->setEnabled(enabled); _nonSpace->setEnabled(enabled); // Characters KMultiFormListBoxEntryList list1 = _single->elements(); - foreach (KMultiFormListBoxEntry *e, list1) { - SingleEntry *entry = dynamic_cast(e); + for (KMultiFormListBoxEntry *e : list1) { + SingleEntry *entry = qobject_cast(e); if (entry) { entry->setText(QString()); } } QStringList list2 = regexp->chars(); for (QStringList::Iterator it2(list2.begin()); it2 != list2.end(); ++it2) { addCharacter(*it2); } // Ranges KMultiFormListBoxEntryList list3 = _range->elements(); - foreach (KMultiFormListBoxEntry *e, list3) { - RangeEntry *entry = dynamic_cast(e); + for (KMultiFormListBoxEntry *e : list3) { + RangeEntry *entry = qobject_cast(e); if (entry) { entry->setFrom(QString()); entry->setTo(QString()); } } - foreach (const StringPair &elm, _regexp->range()) { + for (const StringPair &elm : _regexp->range()) { QString from = elm.first; QString to = elm.second; addRange(from, to); } } CharacterEdits::CharacterEdits(QWidget *parent) : QDialog(parent) { setWindowTitle(i18n("Specify Characters")); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); setObjectName(QStringLiteral("CharacterEdits")); QWidget *top = new QWidget(this); QVBoxLayout *topLayout = new QVBoxLayout(top); topLayout->setMargin(0); mainLayout->addWidget(top); negate = new QCheckBox(i18n("Do not match the characters specified here")); topLayout->addWidget(negate); // The predefined box QGroupBox *predefined = new QGroupBox(i18n("Predefined Character Ranges")); topLayout->addWidget(predefined); QGridLayout *predefinedLayout = new QGridLayout(predefined); wordChar = new QCheckBox(i18n("A word character")); predefinedLayout->addWidget(wordChar, 0, 0); digit = new QCheckBox(i18n("A digit character")); predefinedLayout->addWidget(digit, 0, 1); space = new QCheckBox(i18n("A space character")); predefinedLayout->addWidget(space, 0, 2); _nonWordChar = new QCheckBox(i18n("A non-word character")); predefinedLayout->addWidget(_nonWordChar, 1, 0); _nonDigit = new QCheckBox(i18n("A non-digit character")); predefinedLayout->addWidget(_nonDigit, 1, 1); _nonSpace = new QCheckBox(i18n("A non-space character")); predefinedLayout->addWidget(_nonSpace, 1, 2); // Single characters QGroupBox *singleBox = new QGroupBox(i18n("Single Characters")); QVBoxLayout *groupLayout = new QVBoxLayout(singleBox); topLayout->addWidget(singleBox); _single = new KMultiFormListBox(new SingleFactory(), KMultiFormListBox::MultiVisible); groupLayout->addWidget(_single); _single->addElement(); _single->addElement(); _single->addElement(); QWidget *moreW = new QWidget(); groupLayout->addWidget(moreW); QHBoxLayout *moreLay = new QHBoxLayout(moreW); QPushButton *more = new QPushButton(i18n("More Entries")); moreLay->addWidget(more); moreLay->addStretch(1); moreLay->setMargin(0); connect(more, &QAbstractButton::clicked, _single, &KMultiFormListBox::addElement); // Ranges QGroupBox *rangeBox = new QGroupBox(i18n("Character Ranges")); groupLayout = new QVBoxLayout(rangeBox); topLayout->addWidget(rangeBox); _range = new KMultiFormListBox(new RangeFactory(), KMultiFormListBox::MultiVisible); groupLayout->addWidget(_range); _range->addElement(); _range->addElement(); _range->addElement(); moreW = new QWidget(); groupLayout->addWidget(moreW); moreLay = new QHBoxLayout(moreW); more = new QPushButton(i18n("More Entries")); moreLay->addWidget(more); moreLay->addStretch(1); moreLay->setMargin(0); connect(more, &QAbstractButton::clicked, _range, &KMultiFormListBox::addElement); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); connect(okButton, &QAbstractButton::clicked, this, &CharacterEdits::slotOK); mainLayout->addWidget(buttonBox); } void CharacterEdits::slotOK() { _regexp->setNegate(negate->isChecked()); _regexp->setWordChar(wordChar->isChecked()); _regexp->setNonWordChar(_nonWordChar->isChecked()); _regexp->setDigit(digit->isChecked()); _regexp->setNonDigit(_nonDigit->isChecked()); _regexp->setSpace(space->isChecked()); _regexp->setNonSpace(_nonSpace->isChecked()); // single characters _regexp->clearChars(); KMultiFormListBoxEntryList list = _single->elements(); - foreach (KMultiFormListBoxEntry *e, list) { - SingleEntry *entry = dynamic_cast(e); + for (KMultiFormListBoxEntry *e : list) { + SingleEntry *entry = qobject_cast(e); if (entry && !entry->isEmpty()) { _regexp->addCharacter(entry->text()); } } // Ranges _regexp->clearRange(); list = _range->elements(); - foreach (KMultiFormListBoxEntry *e, list) { - RangeEntry *entry = dynamic_cast(e); + for (KMultiFormListBoxEntry *e : list) { + RangeEntry *entry = qobject_cast(e); if (entry && !entry->isEmpty()) { _regexp->addRange(entry->fromText(), entry->toText()); } } accept(); } SingleEntry::SingleEntry(QWidget *parent) : KMultiFormListBoxEntry(parent) { QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(0); _selector = new CharSelector(this); layout->addWidget(_selector); layout->addStretch(1); } QString SingleEntry::text() const { return _selector->text(); } void SingleEntry::setText(const QString &text) { _selector->setText(text); } bool SingleEntry::isEmpty() const { return _selector->isEmpty(); } RangeEntry::RangeEntry(QWidget *parent) : KMultiFormListBoxEntry(parent) { QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(0); QLabel *label = new QLabel(i18n("From:"), this); _from = new CharSelector(this); layout->addWidget(label); layout->addWidget(_from); layout->addStretch(1); label = new QLabel(i18nc("end of range", "To:"), this); _to = new CharSelector(this); layout->addWidget(label); layout->addWidget(_to); } QString RangeEntry::fromText() const { return _from->text(); } QString RangeEntry::toText() const { return _to->text(); } void RangeEntry::setFrom(const QString &text) { _from->setText(text); } void RangeEntry::setTo(const QString &text) { _to->setText(text); } bool RangeEntry::isEmpty() const { return _from->isEmpty() || _to->isEmpty(); } diff --git a/src/characterswidget.h b/src/characterswidget.h index 5946cf5..52d6c72 100644 --- a/src/characterswidget.h +++ b/src/characterswidget.h @@ -1,155 +1,161 @@ /* * Copyright (c) 2002-2003 Jesper K. Pedersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. **/ #ifndef characterswidget #define characterswidget #include #include "kmultiformlistbox.h" #include "kmultiformlistboxfactory.h" #include "regexpwidget.h" class CharacterEdits; class TextRangeRegExp; class CharSelector; class QCheckBox; /** RegExp widget for charcter ranges. @internal */ class CharactersWidget : public RegExpWidget { + Q_OBJECT + public: CharactersWidget(RegExpEditorWindow *editorWindow, QWidget *parent); CharactersWidget(TextRangeRegExp *regexp, RegExpEditorWindow *editorWindow, QWidget *parent); ~CharactersWidget(); QSize sizeHint() const override; RegExp *regExp() const override; RegExpType type() const override { return CHARSET; } RegExpWidget *findWidgetToEdit(QPoint globalPos) override; int edit() override; protected: void paintEvent(QPaintEvent *event) override; QString text() const; QString title() const; private: TextRangeRegExp *_regexp; static CharacterEdits *_configWindow; mutable QSize _textSize; mutable QSize _contentSize; }; /** @internal */ class SingleEntry : public KMultiFormListBoxEntry { + Q_OBJECT + public: SingleEntry(QWidget *parent); QString text() const; void setText(const QString &text); bool isEmpty() const; private: CharSelector *_selector; }; /** @internal */ class RangeEntry : public KMultiFormListBoxEntry { + Q_OBJECT + public: RangeEntry(QWidget *parent); QString fromText() const; QString toText() const; void setFrom(const QString &text); void setTo(const QString &text); bool isEmpty() const; private: CharSelector *_from, *_to; }; /** @internal */ class SingleFactory : public KMultiFormListBoxFactory { public: KMultiFormListBoxEntry *create(QWidget *parent) override { return new SingleEntry(parent); } QWidget *separator(QWidget *) override { return nullptr; } }; /** @internal */ class RangeFactory : public KMultiFormListBoxFactory { public: KMultiFormListBoxEntry *create(QWidget *parent) override { return new RangeEntry(parent); } QWidget *separator(QWidget *) override { return nullptr; } }; /** @internal */ class CharacterEdits : public QDialog { Q_OBJECT public: explicit CharacterEdits(QWidget *parent = nullptr); public Q_SLOTS: void setRegexp(TextRangeRegExp *regexp); protected Q_SLOTS: void slotOK(); private: QCheckBox *negate, *wordChar, *_nonWordChar, *digit, *_nonDigit, *space, *_nonSpace; KMultiFormListBox *_single, *_range; void addCharacter(const QString &txt); void addRange(const QString &from, const QString &to); TextRangeRegExp *_regexp; }; #endif // characterswidget