diff --git a/src/KMultiFormListBox/kmultiformlistbox-multivisible.cpp b/src/KMultiFormListBox/kmultiformlistbox-multivisible.cpp index 71fc874..f26d51b 100644 --- a/src/KMultiFormListBox/kmultiformlistbox-multivisible.cpp +++ b/src/KMultiFormListBox/kmultiformlistbox-multivisible.cpp @@ -1,305 +1,305 @@ /* * 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 "kmultiformlistbox-multivisible.h" #include #include #include #include #include "kmultiformlistboxfactory.h" #include "indexWindow.h" #include "ccp.h" const int indexButtonWidth = 16; const int indexButtonHeight = 12; const uchar indexButtonBits[] = { 0x00, 0x00, 0x00, 0x00, 0x0e, 0x02, 0x04, 0x02, 0x04, 0x02, 0xc4, 0x8a, 0x24, 0x53, 0x14, 0x22, 0x14, 0x22, 0x24, 0x53, 0xce, 0x8a, 0x00, 0x00 }; KMultiFormListBoxMultiVisible::KMultiFormListBoxMultiVisible(KMultiFormListBoxFactory *fact, QWidget *parent) : QScrollArea(parent) { factory = fact; // Initialize the element list elms = new WidgetList(); QWidget *widget = new QWidget(); layout = new QVBoxLayout(widget); layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); setWidget(widget); setWidgetResizable(true); } //---------------------------------------------------------------------- // This function returns a list of the elements in the KMultiFormListBox widget. //---------------------------------------------------------------------- KMultiFormListBoxEntryList KMultiFormListBoxMultiVisible::elements() { KMultiFormListBoxEntryList res; foreach (QWidget *child, *elms) { if (child->objectName() != QStringLiteral("separator")) { res.append((KMultiFormListBoxEntry *)child); } } return res; } //---------------------------------------------------------------------- // This function is called whenever the KMultiFormListBox widget is resized. It is // necessary to ensure that the content of the clipper is resized. //---------------------------------------------------------------------- void KMultiFormListBoxMultiVisible::resizeEvent(QResizeEvent *e) { // The call of the super class ensures that the outer border is updated. QScrollArea::resizeEvent(e); updateClipperContent(); } void KMultiFormListBoxMultiVisible::updateClipperContent() { // Extract the current size of the clipper /* int ClipperWidth = clipper()->size().width(); int ClipperHeight = clipper()->size().height(); // Initialize the calculation of the size of the new clipper. int totalHeight = 0; int maxWidth = ClipperWidth; int count = 0; // calculate the required size. foreach (QWidget *child , *elms) { maxWidth = qMax(maxWidth, child->sizeHint().width()); if ( child->objectName() != "separator" ) { totalHeight += child->sizeHint().height(); count++; } else { totalHeight += child->size().height(); } } // Calculate the extra height for the elements. int extra = 0; if (totalHeight < ClipperHeight && count != 0) { extra = (ClipperHeight - totalHeight) / count; totalHeight = ClipperHeight; } // Now place the elements in the clipper. int yPos = 0; foreach (QWidget *child2 , *elms) { int h; if ( child2->objectName() != "separator" ) { h = child2->sizeHint().height(); h += extra; } else { h = child2->size().height(); } moveChild(child2, 0,yPos); child2->resize(maxWidth,h); yPos += h; } */ // Finally call the resize procedure for the clipper to ensure that the // new sizes is shown properly. //resizeContents(maxWidth, totalHeight); } void KMultiFormListBoxMultiVisible::addElement() { addElement(nullptr); } void KMultiFormListBoxMultiVisible::addElement(KMultiFormListBoxEntry *after) { KMultiFormListBoxEntry *elm = factory->create(widget()); insertElmIntoWidget(elm, after); } void KMultiFormListBoxMultiVisible::append(KMultiFormListBoxEntry *elm) { elm->setParent(widget()); insertElmIntoWidget(elm, nullptr); } void KMultiFormListBoxMultiVisible::delElement(QWidget *elm) { int index = elms->indexOf(elm); QWidget *next = elms->at(index + 1); if (next->objectName() != QStringLiteral("separator")) { elms->removeOne(next); layout->removeWidget(next); } elms->removeOne(elm); layout->removeWidget(elm); updateClipperContent(); } void KMultiFormListBoxMultiVisible::delAnElement() { delElement(elms->at(0)); } void KMultiFormListBoxMultiVisible::insertElmIntoWidget(KMultiFormListBoxEntry *elm, KMultiFormListBoxEntry *after) { // Bind the index button if it exists. if (elm->indexButton()) { elm->indexButton()->setIcon(static_cast(QBitmap::fromData(QSize(indexButtonWidth, indexButtonHeight), indexButtonBits, QImage::Format_MonoLSB))); connect(elm->indexButton(), &QAbstractButton::clicked, elm, &KMultiFormListBoxEntry::acceptIndexButton); - connect(elm, SIGNAL(gotoIndex(KMultiFormListBoxEntry *)), - this, SLOT(showIndexList(KMultiFormListBoxEntry *))); + connect(elm, SIGNAL(gotoIndex(KMultiFormListBoxEntry*)), + this, SLOT(showIndexList(KMultiFormListBoxEntry*))); } // Find the location to insert the new element. int index = elms->count(); if (after) { index = elms->indexOf(after); } // Now show the new element. elms->insert(index, elm); layout->insertWidget(index, elm); elm->show(); ensureWidgetVisible(elm, 0, 0); //addChild(elm,0,0); // updateClipperContent will place the child correctly. QWidget *sep = factory->separator(widget()); if (sep != nullptr) { sep->setObjectName(QStringLiteral("separator")); sep->show(); layout->insertWidget(index + 1, sep); // updateClipperContent will place the child correctly. elms->insert(index + 1, sep); } updateClipperContent(); showWidget(elm); // scroll to show the new widget. // install cut'n'paste functionallity new CCP(this, elm); } //---------------------------------------------------------------------- // This function shows the list of available Idx elements. //---------------------------------------------------------------------- void KMultiFormListBoxMultiVisible::showIndexList(KMultiFormListBoxEntry *elm) { indexWindow *menu = new indexWindow(); // Insert the elements into the menu item. foreach (QWidget *child, *elms) { if (child->objectName() != QStringLiteral("separator")) { QString txt = ((KMultiFormListBoxEntry *)child)->idxString(); menu->insertItem(txt); } } // Calculate the location of the window QPoint start; int width; elm->indexWindowPos(&start, &width); // Show the window. int index = menu->exec(start, width); if (index != -1) { foreach (QWidget *child, *elms) { if (child->objectName() != QLatin1String("separator")) { if (index == 0) { showWidget((KMultiFormListBoxEntry *)child); break; } index--; } } } delete menu; } //---------------------------------------------------------------------- // Scroll to the loaction of the given KMultiFormListBoxEntry element. //---------------------------------------------------------------------- void KMultiFormListBoxMultiVisible::showWidget(KMultiFormListBoxEntry *elm) { ensureWidgetVisible(elm); } void KMultiFormListBoxMultiVisible::cut(KMultiFormListBoxEntry *elm) { if (countElements(elms) == 1) { KMessageBox::information(this, i18n("Due to a bug, it is not possible to remove the last element."), i18n("Internal Error")); return; } QDataStream stream(&clipboard, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_3_1); factory->toStream(elm, stream); delElement(elm); } void KMultiFormListBoxMultiVisible::copy(KMultiFormListBoxEntry *elm) { QDataStream stream(&clipboard, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_3_1); factory->toStream(elm, stream); } void KMultiFormListBoxMultiVisible::paste(KMultiFormListBoxEntry *oldElm) { if (clipboard.isEmpty()) { KMessageBox::information(this, i18n("There is no element on the clipboard to paste in.")); return; } KMultiFormListBoxEntry *newElm = factory->create(widget()); QDataStream stream(&clipboard, QIODevice::ReadOnly); stream.setVersion(QDataStream::Qt_3_1); factory->fromStream(stream, newElm); insertElmIntoWidget(newElm, oldElm); } int KMultiFormListBoxMultiVisible::countElements(WidgetList *elms) { int count = 0; foreach (QWidget *child, *elms) { if (dynamic_cast(child)) { count++; } } return count; } diff --git a/src/KMultiFormListBox/kmultiformlistbox-windowed.cpp b/src/KMultiFormListBox/kmultiformlistbox-windowed.cpp index df4a1d4..d4df1ff 100644 --- a/src/KMultiFormListBox/kmultiformlistbox-windowed.cpp +++ b/src/KMultiFormListBox/kmultiformlistbox-windowed.cpp @@ -1,227 +1,227 @@ /* * 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 "kmultiformlistbox-windowed.h" #include #include #include #include #include #include #include #include "widgetwindow.h" #include "windowlistboxitem.h" KMultiFormListBoxWindowed::KMultiFormListBoxWindowed(KMultiFormListBoxFactory *factory, QWidget *parent, bool showUpDownButtons, bool showHelpButton, const QString &addButtonText) : QWidget(parent) { _layout = new QVBoxLayout(this); QHBoxLayout *innerLayout = new QHBoxLayout(); _layout->addLayout(innerLayout); _listbox = new QListWidget(this); _listbox->setObjectName(QStringLiteral("listbox")); _listbox->setSelectionMode(QAbstractItemView::SingleSelection); innerLayout->addWidget(_listbox); QVBoxLayout *buttons = new QVBoxLayout(); innerLayout->addLayout(buttons); QPushButton *but = new QPushButton(addButtonText, this); but->setObjectName(QStringLiteral("Add Button")); buttons->addWidget(but, 0); connect(but, &QAbstractButton::clicked, this, &KMultiFormListBoxWindowed::addNewElement); but = new QPushButton(i18n("Edit"), this); but->setObjectName(QStringLiteral("Edit Button")); buttons->addWidget(but, 0); connect(but, SIGNAL(clicked()), this, SLOT(slotEditSelected())); - connect(_listbox, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditSelected(QListWidgetItem *))); + connect(_listbox, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotEditSelected(QListWidgetItem*))); _buttonList.append(but); but = new QPushButton(i18n("Delete"), this); but->setObjectName(QStringLiteral("Delete Button")); buttons->addWidget(but, 0); connect(but, &QAbstractButton::clicked, this, &KMultiFormListBoxWindowed::slotDeleteEntry); _buttonList.append(but); but = new QPushButton(i18n("Copy"), this); but->setObjectName(QStringLiteral("Copy Button")); buttons->addWidget(but, 0); connect(but, &QAbstractButton::clicked, this, &KMultiFormListBoxWindowed::slotCopySelected); _buttonList.append(but); if (showUpDownButtons) { but = new QPushButton(i18n("Up"), this); but->setObjectName(QStringLiteral("Up Button")); buttons->addWidget(but, 0); connect(but, &QAbstractButton::clicked, this, &KMultiFormListBoxWindowed::slotMoveItemUp); _buttonList.append(but); but = new QPushButton(i18n("Down"), this); but->setObjectName(QStringLiteral("Down Button")); buttons->addWidget(but, 0); connect(but, &QAbstractButton::clicked, this, &KMultiFormListBoxWindowed::slotMoveItemDown); _buttonList.append(but); } if (showHelpButton) { but = new QPushButton(this); KGuiItem::assign(but, KStandardGuiItem::help()); but->setObjectName(QStringLiteral("Help Button")); buttons->addWidget(but, 0); connect(but, &QAbstractButton::clicked, this, &KMultiFormListBoxWindowed::showHelp); } buttons->addStretch(1); _factory = factory; slotUpdateButtonState(); } KMultiFormListBoxEntryList KMultiFormListBoxWindowed::elements() { KMultiFormListBoxEntryList list; for (int i = 0; i < _listbox->count(); ++i) { WindowListboxItem *item = (WindowListboxItem *)_listbox->item(i); list.append(item->entry()); } return list; } void KMultiFormListBoxWindowed::delElement(QWidget * /*elm*/) { // kDebug() << "KMultiFormListBoxWindowed::delElement NOT YET IMPLEMENTED"; // TODO } void KMultiFormListBoxWindowed::delAnElement() { // kDebug() << "KMultiFormListBoxWindowed::delAnElement NOT YET IMPLEMENTED"; // TODO } void KMultiFormListBoxWindowed::append(KMultiFormListBoxEntry *elm) { (void)new WidgetWindow(_factory, elm, _listbox); slotUpdateButtonState(); } void KMultiFormListBoxWindowed::addNewElement() { // kDebug() << "addNewElement " << _factory << "," << _listbox ; QWidget *widget = new WidgetWindow(_factory, _listbox); widget->show(); connect(widget, SIGNAL(finished()), this, SLOT(slotUpdateButtonState())); } void KMultiFormListBoxWindowed::addElement() { new WidgetWindow(_factory, _listbox); slotUpdateButtonState(); } void KMultiFormListBoxWindowed::slotEditSelected(QListWidgetItem *item) { ((WindowListboxItem *)item)->displayWidget(); } void KMultiFormListBoxWindowed::slotEditSelected() { WindowListboxItem *item = selected(); if (item) { slotEditSelected(item); } } void KMultiFormListBoxWindowed::slotDeleteEntry() { WindowListboxItem *item = selected(); if (item) { int answer = KMessageBox::warningContinueCancel(nullptr, i18n("Delete item \"%1\"?", item->text()), i18n("Delete Item"), KStandardGuiItem::del()); if (answer == KMessageBox::Continue) { delete item; slotUpdateButtonState(); } } } void KMultiFormListBoxWindowed::slotCopySelected() { WindowListboxItem *item = selected(); if (item) { item->cloneItem(); } } WindowListboxItem *KMultiFormListBoxWindowed::selected() { /* int i = _listbox->currentItem(); if (i == -1) { return 0; } else { return (WindowListboxItem *) _listbox->item(i); } */ return (WindowListboxItem *)_listbox->currentItem(); } void KMultiFormListBoxWindowed::slotMoveItemUp() { WindowListboxItem *item = selected(); if (item == nullptr) { return; } int index = _listbox->row(item); if (index != 0) { _listbox->takeItem(index); _listbox->insertItem(index - 1, item); _listbox->setCurrentItem(item); } } void KMultiFormListBoxWindowed::slotMoveItemDown() { WindowListboxItem *item = selected(); if (item == nullptr) { return; } int index = _listbox->row(item); if (index < _listbox->count()) { _listbox->takeItem(index); _listbox->insertItem(index + 1, item); _listbox->setCurrentItem(item); } } void KMultiFormListBoxWindowed::slotUpdateButtonState() { bool on = (_listbox->count() != 0); const int nbButton = _buttonList.count(); for (int i = 0; i < nbButton; i++) { _buttonList.at(i)->setEnabled(on); } } diff --git a/src/kregexpeditorprivate.cpp b/src/kregexpeditorprivate.cpp index 0eb59dc..0ee8e92 100644 --- a/src/kregexpeditorprivate.cpp +++ b/src/kregexpeditorprivate.cpp @@ -1,437 +1,426 @@ /* * 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 "kregexpeditorprivate.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "auxbuttons.h" #include "verifybuttons.h" #include "regexpbuttons.h" #include "userdefinedregexps.h" #include "scrollededitorwindow.h" #include "infopage.h" #include "verifier.h" #include "regexpconverter.h" #include "regexp.h" KRegExpEditorPrivate::KRegExpEditorPrivate(QWidget *parent) : QMainWindow(parent) , _updating(false) , _autoVerify(true) , _matchGreedy(false) { setMinimumSize(730, 300); setWindowFlags(Qt::Widget); // The DockWindows. - _regExpButtons = new RegExpButtons(/*area*/ this, QStringLiteral("KRegExpEditorPrivate::regExpButton")); + _regExpButtons = new RegExpButtons(this, QStringLiteral("RegExpButton")); addToolBar(Qt::TopToolBarArea, _regExpButtons); - _verifyButtons = new VerifyButtons(/*area*/ this, QStringLiteral("KRegExpEditorPrivate::VerifyButtons")); + _verifyButtons = new VerifyButtons(this, QStringLiteral("VerifyButtons")); addToolBar(Qt::TopToolBarArea, _verifyButtons); - _auxButtons = new AuxButtons(/*area*/ this, QStringLiteral("KRegExpEditorPrivate::AuxButtons")); + _auxButtons = new AuxButtons(this, QStringLiteral("AuxButtons")); addToolBar(Qt::TopToolBarArea, _auxButtons); _userRegExps = new UserDefinedRegExps(/*verArea1*/ this, /*"KRegExpEditorPrivate::userRegExps"*/ i18n("Compound regular expression:")); _userRegExps->setWhatsThis(i18n("In this window you will find predefined regular expressions. Both regular expressions " "you have developed and saved, and regular expressions shipped with the system.")); addDockWidget(Qt::LeftDockWidgetArea, _userRegExps); // Editor window _editor = new QSplitter(Qt::Vertical, this); _editor->setObjectName(QStringLiteral("KRegExpEditorPrivate::_editor")); _scrolledEditorWindow = new RegExpScrolledEditorWindow(_editor); _scrolledEditorWindow->setWhatsThis(i18n("In this window you will develop your regular expressions. " "Select one of the actions from the action buttons above, and click the mouse in this " "window to insert the given action.")); _info = new InfoPage(this); _info->setObjectName(QStringLiteral("_info")); _verifier = new Verifier(_editor); connect(_verifier, SIGNAL(textChanged()), this, SLOT(maybeVerify())); _verifier->setWhatsThis(i18n("

Type in some text in this window, and see what the regular expression you have developed matches.

" "

Each second match will be colored in red and each other match will be colored blue, simply so you " "can distinguish them from each other.

" "

If you select part of the regular expression in the editor window, then this part will be " "highlighted - This allows you to debug your regular expressions

")); _editor->hide(); _editor->setSizes(QList() << _editor->height() / 2 << _editor->height() / 2); QWidget *centralWidget = new QWidget(this); QHBoxLayout *layout = new QHBoxLayout(centralWidget); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(_editor); layout->addWidget(_info); setCentralWidget(centralWidget); // Connect the buttons connect(_regExpButtons, SIGNAL(clicked(int)), _scrolledEditorWindow, SLOT(slotInsertRegExp(int))); connect(_regExpButtons, SIGNAL(doSelect()), _scrolledEditorWindow, SLOT(slotDoSelect())); - connect(_userRegExps, SIGNAL(load(RegExp *)), _scrolledEditorWindow, SLOT(slotInsertRegExp(RegExp *))); + connect(_userRegExps, SIGNAL(load(RegExp*)), _scrolledEditorWindow, SLOT(slotInsertRegExp(RegExp*))); connect(_regExpButtons, SIGNAL(clicked(int)), _userRegExps, SLOT(slotUnSelect())); connect(_regExpButtons, SIGNAL(doSelect()), _userRegExps, SLOT(slotUnSelect())); - connect(_userRegExps, SIGNAL(load(RegExp *)), _regExpButtons, SLOT(slotUnSelect())); + connect(_userRegExps, SIGNAL(load(RegExp*)), _regExpButtons, SLOT(slotUnSelect())); connect(_scrolledEditorWindow, SIGNAL(doneEditing()), _regExpButtons, SLOT(slotSelectNewAction())); connect(_scrolledEditorWindow, SIGNAL(doneEditing()), _userRegExps, SLOT(slotSelectNewAction())); connect(_regExpButtons, SIGNAL(clicked(int)), this, SLOT(slotShowEditor())); - connect(_userRegExps, SIGNAL(load(RegExp *)), this, SLOT(slotShowEditor())); + connect(_userRegExps, SIGNAL(load(RegExp*)), this, SLOT(slotShowEditor())); connect(_regExpButtons, SIGNAL(doSelect()), this, SLOT(slotShowEditor())); connect(_scrolledEditorWindow, SIGNAL(savedRegexp()), _userRegExps, SLOT(slotPopulateUserRegexps())); connect(_auxButtons, SIGNAL(undo()), this, SLOT(slotUndo())); connect(_auxButtons, SIGNAL(redo()), this, SLOT(slotRedo())); connect(_auxButtons, SIGNAL(cut()), _scrolledEditorWindow, SLOT(slotCut())); connect(_auxButtons, SIGNAL(copy()), _scrolledEditorWindow, SLOT(slotCopy())); connect(_auxButtons, SIGNAL(paste()), _scrolledEditorWindow, SLOT(slotPaste())); connect(_auxButtons, SIGNAL(save()), _scrolledEditorWindow, SLOT(slotSave())); connect(_verifyButtons, SIGNAL(autoVerify(bool)), this, SLOT(setAutoVerify(bool))); connect(_verifyButtons, SIGNAL(verify()), this, SLOT(doVerify())); - connect(_verifyButtons, SIGNAL(changeSyntax(const QString&)), this, SLOT(setSyntax(const QString&))); + connect(_verifyButtons, SIGNAL(changeSyntax(QString)), this, SLOT(setSyntax(QString))); connect(_verifyButtons, SIGNAL(matchGreedy(bool)), this, SLOT(setMatchGreedy(bool))); connect(this, SIGNAL(canUndo(bool)), _auxButtons, SLOT(slotCanUndo(bool))); connect(this, SIGNAL(canRedo(bool)), _auxButtons, SLOT(slotCanRedo(bool))); connect(_scrolledEditorWindow, SIGNAL(anythingSelected(bool)), _auxButtons, SLOT(slotCanCut(bool))); connect(_scrolledEditorWindow, SIGNAL(anythingSelected(bool)), _auxButtons, SLOT(slotCanCopy(bool))); connect(_scrolledEditorWindow, SIGNAL(anythingOnClipboard(bool)), _auxButtons, SLOT(slotCanPaste(bool))); connect(_scrolledEditorWindow, SIGNAL(canSave(bool)), _auxButtons, SLOT(slotCanSave(bool))); connect(_scrolledEditorWindow, SIGNAL(verifyRegExp()), this, SLOT(maybeVerify())); - connect(_verifyButtons, SIGNAL(loadVerifyText(const QString&)), this, SLOT(setVerifyText(const QString&))); - - // connect( _verifier, SIGNAL( countChanged( int ) ), _verifyButtons, SLOT( setMatchCount( int ) ) ); - - // Qt anchors do not work for
...
, thefore scrolling to next/prev match - // do not work. Enable this when they work. - // connect( _verifyButtons, SIGNAL( gotoFirst() ), _verifier, SLOT( gotoFirst() ) ); - // connect( _verifyButtons, SIGNAL( gotoPrev() ), _verifier, SLOT( gotoPrev() ) ); - // connect( _verifyButtons, SIGNAL( gotoNext() ), _verifier, SLOT( gotoNext() ) ); - // connect( _verifyButtons, SIGNAL( gotoLast() ), _verifier, SLOT( gotoLast() ) ); - // connect( _verifier, SIGNAL( goForwardPossible( bool ) ), _verifyButtons, SLOT( enableForwardButtons( bool ) ) ); - // connect( _verifier, SIGNAL( goBackwardPossible( bool ) ), _verifyButtons, SLOT( enableBackwardButtons( bool ) ) ); + connect(_verifyButtons, SIGNAL(loadVerifyText(QString)), this, SLOT(setVerifyText(QString))); _auxButtons->slotCanPaste(false); _auxButtons->slotCanCut(false); _auxButtons->slotCanCopy(false); _auxButtons->slotCanSave(false); // Line Edit QDockWidget *editDock = new QDockWidget(i18n("ASCII syntax:"), this); editDock->setFeatures(QDockWidget::NoDockWidgetFeatures); addDockWidget(Qt::BottomDockWidgetArea, editDock); QWidget *editDockWidget = new QWidget(editDock); editDock->setWidget(editDockWidget); QHBoxLayout *dockLayout = new QHBoxLayout(editDockWidget); dockLayout->setContentsMargins(0, 0, 0, 0); _regexpEdit = new QLineEdit(editDockWidget); dockLayout->addWidget(_regexpEdit); _regexpEdit->setFocus(Qt::OtherFocusReason); _regexpEdit->setClearButtonEnabled(true); _regexpEdit->setWhatsThis(i18n("

This is the regular expression in ASCII syntax. You are likely only " "to be interested in this if you are a programmer, and need to " "develop a regular expression using QRegExp.

" "

You may develop your regular expression both by using the graphical " "editor, and by typing the regular expression in this line edit.

")); QPixmap pix = KIconLoader::global()->loadIcon(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kregexpeditor/pics/error.png")), KIconLoader::Toolbar); _error = new QLabel(editDockWidget); _error->setPixmap(pix); dockLayout->addWidget(_error); _error->hide(); _timer = new QTimer(this); _timer->setSingleShot(true); connect(_scrolledEditorWindow, SIGNAL(change()), this, SLOT(slotUpdateLineEdit())); - connect(_regexpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotTriggerUpdate())); + connect(_regexpEdit, SIGNAL(textChanged(QString)), this, SLOT(slotTriggerUpdate())); connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout())); // Push an initial empty element on the stack. _undoStack.push(_scrolledEditorWindow->regExp()); (void)new QShortcut(Qt::CTRL + Qt::Key_Z, this, SLOT(slotUndo())); (void)new QShortcut(Qt::CTRL + Qt::Key_R, this, SLOT(slotRedo())); setSyntax(QStringLiteral("Qt")); } KRegExpEditorPrivate::~KRegExpEditorPrivate() { qDeleteAll(_undoStack); qDeleteAll(_redoStack); } QString KRegExpEditorPrivate::regexp() { RegExp *regexp = _scrolledEditorWindow->regExp(); QString res = RegExpConverter::current()->toStr(regexp, false); delete regexp; return res; } void KRegExpEditorPrivate::slotUpdateEditor(const QString &txt) { _updating = true; bool ok; if (!RegExpConverter::current()->canParse()) { // This can happend if the application set a text through the API. //qDebug("cannot parse"); } else { RegExp *result = RegExpConverter::current()->parse(txt, &ok); if (ok) { QList list = _userRegExps->regExps(); foreach (CompoundRegExp *regExp, list) { result->replacePart(regExp); } _scrolledEditorWindow->slotSetRegExp(result); _error->hide(); maybeVerify(); recordUndoInfo(); result->check(_errorMap); } else { _error->show(); if (_autoVerify) { _verifier->clearRegexp(); } } delete result; } _updating = false; } void KRegExpEditorPrivate::slotUpdateLineEdit() { if (_updating) { return; } _updating = true; RegExp *regexp = _scrolledEditorWindow->regExp(); regexp->check(_errorMap); QString str = RegExpConverter::current()->toStr(regexp, false); _regexpEdit->setText(str); delete regexp; recordUndoInfo(); _updating = false; } void KRegExpEditorPrivate::recordUndoInfo() { Q_ASSERT(_updating); // Update undo/redo stacks RegExp *regexp = _scrolledEditorWindow->regExp(); if (regexp->toXmlString() != _undoStack.top()->toXmlString()) { _undoStack.push(regexp); qDeleteAll(_redoStack); _redoStack = QStack(); emitUndoRedoSignals(); } } void KRegExpEditorPrivate::slotRedo() { if (!_redoStack.isEmpty()) { _undoStack.push(_redoStack.pop()); _scrolledEditorWindow->slotSetRegExp(_undoStack.top()); slotUpdateLineEdit(); emitUndoRedoSignals(); maybeVerify(); } } void KRegExpEditorPrivate::slotUndo() { if (_undoStack.count() > 1) { _redoStack.push(_undoStack.pop()); _scrolledEditorWindow->slotSetRegExp(_undoStack.top()); slotUpdateLineEdit(); emitUndoRedoSignals(); maybeVerify(); } } void KRegExpEditorPrivate::slotShowEditor() { _info->hide(); _editor->show(); } void KRegExpEditorPrivate::emitUndoRedoSignals() { Q_EMIT canUndo(_undoStack.count() > 1); Q_EMIT changes(_undoStack.count() > 1); Q_EMIT canRedo(_redoStack.count() > 0); } void KRegExpEditorPrivate::slotSetRegexp(const QString ®exp) { _regexpEdit->setText(regexp); } void KRegExpEditorPrivate::slotTriggerUpdate() { /* ### Guess this timeout value should be configurable somewhere, or (even * better: do some kind of benchmark each time the editor view gets updated * to measure how long it takes on the client system to render the editor * with the current complexity. That way we'd get good response times for * simple regexps, and flicker-free display for complex regexps. * - Frerich */ if (!_updating) { _timer->start(300); slotShowEditor(); } } void KRegExpEditorPrivate::slotTimeout() { slotUpdateEditor(_regexpEdit->text()); } void KRegExpEditorPrivate::setMatchText(const QString &text) { bool autoVerify = _autoVerify; _autoVerify = false; _verifier->setText(text); _autoVerify = autoVerify; } void KRegExpEditorPrivate::maybeVerify() { if (_autoVerify) { doVerify(); } else { _verifyButtons->setMatchCount(-1); } } void KRegExpEditorPrivate::doVerify() { bool autoVerify = _autoVerify; // prevent loop due to verify emit changed, which calls maybeVerify _autoVerify = false; RegExp *regexp = _scrolledEditorWindow->regExp(); _verifier->verify(RegExpConverter::current()->toStr(regexp, true)); delete regexp; _autoVerify = autoVerify; } void KRegExpEditorPrivate::setAutoVerify(bool on) { _autoVerify = on; if (!_autoVerify) { _verifier->clearRegexp(); } else { doVerify(); } } void KRegExpEditorPrivate::setVerifyText(const QString &fileName) { bool autoVerify = _autoVerify; _autoVerify = false; QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { KMessageBox::sorry(nullptr, i18n("Could not open file '%1' for reading", fileName)); } else { QTextStream s(&file); QString txt = s.readAll(); file.close(); RegExp *regexp = _scrolledEditorWindow->regExp(); _verifier->setText(txt); _verifier->verify(RegExpConverter::current()->toStr(regexp, true)); delete regexp; } _autoVerify = autoVerify; } void KRegExpEditorPrivate::setCaseSensitive(bool b) { _verifier->setCaseSensitive(b); } void KRegExpEditorPrivate::setMinimal(bool b) { _verifier->setMinimal(b); } void KRegExpEditorPrivate::setSyntax(const QString &syntax) { RegExpConverter *converter = _verifyButtons->setSyntax(syntax); RegExpConverter::setCurrent(converter); if (converter->canParse()) { _regexpEdit->setReadOnly(false); _regexpEdit->setBackgroundRole(QPalette::Base); } else { _regexpEdit->setReadOnly(true); _regexpEdit->setBackgroundRole(QPalette::Window); } _regExpButtons->setFeatures(converter->features()); _verifier->setHighlighter(converter->highlighter(_verifier)); slotUpdateLineEdit(); } void KRegExpEditorPrivate::showHelp() { _info->show(); _editor->hide(); } void KRegExpEditorPrivate::setAllowNonQtSyntax(bool b) { _verifyButtons->setAllowNonQtSyntax(b); } void KRegExpEditorPrivate::setMatchGreedy(bool b) { _matchGreedy = b; _verifier->setMinimal(!b); doVerify(); } diff --git a/src/textwidget.cpp b/src/textwidget.cpp index ecd5587..c741754 100644 --- a/src/textwidget.cpp +++ b/src/textwidget.cpp @@ -1,142 +1,142 @@ /* * 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 "textwidget.h" #include #include #include #include "textregexp.h" #include "selectablelineedit.h" TextWidget::TextWidget(RegExpEditorWindow *editorWindow, QWidget *parent) : RegExpWidget(editorWindow, parent) { init(QString()); } TextWidget::TextWidget(TextRegExp *regexp, RegExpEditorWindow *editorWindow, QWidget *parent) : RegExpWidget(editorWindow, parent) { init(regexp->text()); } void TextWidget::init(const QString &txt) { QHBoxLayout *lay = new QHBoxLayout(this); _edit = new SelectableLineEdit(this, this, QStringLiteral("TextWidget::edit")); _edit->setDragEnabled(false); //otherwise QLineEdit::mouseMoveEvent will set the cursor over and over again. lay->addWidget(_edit); _edit->setText(txt); connect(_edit, SIGNAL(parentPleaseUpdate()), this, SLOT(slotUpdate())); setFocusProxy(_edit); _edit->installEventFilter(this); - connect(_edit, SIGNAL(textChanged(const QString&)), _editorWindow, SLOT(emitChange())); + connect(_edit, SIGNAL(textChanged(QString)), _editorWindow, SLOT(emitChange())); } void TextWidget::slotUpdate() { // I need to force the parent to repaint, as the size change of this // widget may not be enough for the parent to change size, and in that // case the parent would not repaint, and the text widget would not be // resized. QWidget *p = static_cast(parent()); if (p) { p->repaint(); } _editorWindow->updateContent(this); } void TextWidget::paintEvent(QPaintEvent *e) { RegExpWidget::paintEvent(e); } void TextWidget::selectWidget(bool sel) { _edit->setSelected(sel); } bool TextWidget::updateSelection(bool parentSelected) { bool changed = RegExpWidget::updateSelection(parentSelected); // I need to call this function all the time, else the rubber band will // not be correctly deleted in the line edit. _edit->setSelected(_isSelected); return changed; } void TextWidget::updateAll() { _edit->update(); update(); } void TextWidget::clearSelection() { _isSelected = false; _edit->setSelected(false); } RegExp *TextWidget::regExp() const { return new TextRegExp(isSelected(), _edit->text()); } bool TextWidget::eventFilter(QObject *, QEvent *event) { // This is an event filter (in contrast to methods in SelectableLineEdit), // otherwise lots of functions would need to be exported from TextWidget. if (event->type() == QEvent::MouseButtonRelease) { if (_editorWindow->isInserting()) { if (acceptWidgetInsert(_editorWindow->insertType())) { mouseReleaseEvent(static_cast(event)); } return true; } } else if (event->type() == QEvent::MouseButtonPress) { if (_editorWindow->isInserting()) { return true; } else if (isSelected()) { QMouseEvent *e = static_cast(event); QMouseEvent ev(event->type(), mapTo(_editorWindow, e->pos()), e->button(), e->buttons(), e->modifiers()); QApplication::sendEvent(_editorWindow, &ev); return true; } } else if (event->type() == QEvent::Enter) { if (_editorWindow->isInserting()) { if (acceptWidgetInsert(_editorWindow->insertType())) { _edit->setCursor(Qt::CrossCursor); } else { _edit->setCursor(Qt::ForbiddenCursor); } } else if (isSelected()) { _edit->setCursor(Qt::ArrowCursor); } else { _edit->setCursor(Qt::IBeamCursor); } } else if (event->type() == QEvent::MouseButtonDblClick && _editorWindow->isInserting()) { return true; } return false; } diff --git a/src/userdefinedregexps.cpp b/src/userdefinedregexps.cpp index c5e93e5..c48b229 100644 --- a/src/userdefinedregexps.cpp +++ b/src/userdefinedregexps.cpp @@ -1,274 +1,274 @@ /* * 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 "userdefinedregexps.h" #include #include #include #include #include #include #include #include #include #include #include "widgetfactory.h" #include "compoundregexp.h" UserDefinedRegExps::UserDefinedRegExps(QWidget *parent, const QString &title) : QDockWidget(title, parent) { QWidget *top = new QWidget(this); QVBoxLayout *lay = new QVBoxLayout(top); lay->setContentsMargins(0, 0, 0, 0); //QLabel* label = new QLabel( i18n("Compound regular expression:"), top ); // This is to avoid that the label set the minimum width for the window. //label->setMinimumSize(1,0); //lay->addWidget(label); _userDefined = new QTreeWidget(top /*, "UserDefinedRegExps::_userDefined"*/); //_userDefined->addColumn( QString() ); _userDefined->header()->hide(); _userDefined->setRootIsDecorated(true); _userDefined->setContextMenuPolicy(Qt::CustomContextMenu); lay->addWidget(_userDefined); setWidget(top); slotPopulateUserRegexps(); - connect(_userDefined, SIGNAL(itemClicked(QTreeWidgetItem *,int)), this, SLOT(slotLoad(QTreeWidgetItem *))); - connect(_userDefined, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(slotContextMenuTriggered(const QPoint&))); + connect(_userDefined, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(slotLoad(QTreeWidgetItem*))); + connect(_userDefined, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenuTriggered(QPoint))); } void UserDefinedRegExps::slotPopulateUserRegexps() { _userDefined->clear(); _regExps.clear(); createItems(i18n("User Defined"), WidgetWinItem::path(), true); const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kregexpeditor/predefined/"), QStandardPaths::LocateDirectory); for (QStringList::ConstIterator it1 = dirs.constBegin(); it1 != dirs.constEnd(); ++it1) { QDir dir(*it1, QString(), QDir::Name, QDir::Dirs); QStringList subdirs = dir.entryList(); for (QStringList::iterator it2 = subdirs.begin(); it2 != subdirs.end(); ++it2) { if (*it2 == QStringLiteral(".") || *it2 == QStringLiteral("..")) { continue; } createItems(*it2, *it1 + QLatin1Char('/') + *it2, false); } } } void UserDefinedRegExps::createItems(const QString &_title, const QString &dir, bool usersRegExp) { QString title = _title; if (_title == QLatin1String("general")) { title = i18n("general"); } QTreeWidgetItem *lvItem = new QTreeWidgetItem((QTreeWidget *)nullptr, QStringList(title)); lvItem->setExpanded(true); _userDefined->addTopLevelItem(lvItem); QDir directory(dir); QStringList files = directory.entryList(QStringList(QStringLiteral("*.regexp"))); for (QStringList::Iterator it = files.begin(), total = files.end(); it != total; ++it) { const QString fileName = dir + QLatin1Char('/') + *it; QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { KMessageBox::sorry(this, i18n("Could not open file for reading: %1", fileName)); continue; } QTextStream stream(&file); QString data = stream.readAll(); file.close(); RegExp *regexp = WidgetFactory::createRegExp(data); if (!regexp) { KMessageBox::sorry(this, i18n("File %1 containing user defined regular expression contained an error", fileName)); continue; } new WidgetWinItem(*it, regexp, usersRegExp, lvItem); // Inserth the regexp into the list of compound regexps if (regexp->type() == RegExp::COMPOUND) { CompoundRegExp *cregexp = dynamic_cast(regexp); if (cregexp && cregexp->allowReplace()) { _regExps.append(cregexp); } } } } const QList UserDefinedRegExps::regExps() const { return _regExps; } void UserDefinedRegExps::slotUnSelect() { _userDefined->clearSelection(); } void UserDefinedRegExps::slotLoad(QTreeWidgetItem *item) { if (!item || !dynamic_cast(item)) { // Mouse pressed outside a widget. return; } WidgetWinItem *wwi = dynamic_cast(item); if (wwi) { Q_EMIT load(wwi->regExp()); } } void UserDefinedRegExps::slotContextMenuTriggered(const QPoint &pos) { QMenu menu; QAction *deleteAction = menu.addAction(i18n("Delete"), this, SLOT(slotDeleteUserRegexp())); QAction *renameAction = menu.addAction(i18n("Rename"), this, SLOT(slotRenameUserRegexp())); QTreeWidgetItem *item = _userDefined->itemAt(pos); if (!item || !dynamic_cast(item)) { // menu not selected on an item deleteAction->setEnabled(false); renameAction->setEnabled(false); } else { // Only allow rename and delete of users own regexps. WidgetWinItem *winItem = dynamic_cast(item); if (winItem) { if (!winItem->isUsersRegExp()) { deleteAction->setEnabled(false); renameAction->setEnabled(false); } else { QVariant var = QVariant::fromValue((void *)(winItem)); deleteAction->setData(var); renameAction->setData(var); } } } menu.exec(_userDefined->mapToGlobal(pos)); } void UserDefinedRegExps::slotSelectNewAction() { slotUnSelect(); } void UserDefinedRegExps::slotRenameUserRegexp() { QAction *const action = qobject_cast(sender()); Q_ASSERT(action); WidgetWinItem *winItem = static_cast(action->data().value()); Q_ASSERT(winItem); QString oldName = winItem->name(); QString txt = QInputDialog::getText(this, i18n("Rename Item"), i18n("New name:"), QLineEdit::Normal, oldName); if (!txt.isNull() && oldName != txt) { const QString fileName = WidgetWinItem::path() + QLatin1Char('/') + txt + QStringLiteral(".regexp"); QFileInfo finfo(fileName); if (finfo.exists()) { int answer = KMessageBox::warningYesNo(this, i18n("

Overwrite named regular expression %1?

", txt), QString(), KStandardGuiItem::overwrite(), KGuiItem(i18n("Do Not Overwrite"))); if (answer != KMessageBox::Yes) { return; } // An item with this name already exists. delete winItem; } else { winItem->setName(txt); } QDir dir; dir.remove(fileName); } } void UserDefinedRegExps::slotDeleteUserRegexp() { QAction *const action = qobject_cast(sender()); Q_ASSERT(action); WidgetWinItem *winItem = static_cast(action->data().value()); Q_ASSERT(winItem); QFile file(winItem->fileName()); Q_ASSERT(file.exists()); file.remove(); delete winItem; } WidgetWinItem::WidgetWinItem(const QString &fileName, RegExp *regexp, bool usersRegExp, QTreeWidgetItem *parent) : QTreeWidgetItem(parent) , _regexp(regexp) , _usersRegExp(usersRegExp) { int index = fileName.lastIndexOf(QLatin1String(".regexp")); _name = fileName.left(index); setText(0, _name); } WidgetWinItem::~WidgetWinItem() { delete _regexp; } QString WidgetWinItem::fileName() const { return path() + QLatin1Char('/') + _name + QStringLiteral(".regexp"); } RegExp *WidgetWinItem::regExp() const { return _regexp; } QString WidgetWinItem::name() const { return _name; } void WidgetWinItem::setName(const QString &nm) { _name = nm; setText(0, nm); } QString WidgetWinItem::path() { const QString regexppath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QStringLiteral("KRegExpEditor/"); QDir().mkpath(regexppath); return regexppath; } diff --git a/src/verifybuttons.cpp b/src/verifybuttons.cpp index 6d03057..1161785 100644 --- a/src/verifybuttons.cpp +++ b/src/verifybuttons.cpp @@ -1,209 +1,209 @@ /* * 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 "verifybuttons.h" #include #include #include #include #include #include "qtregexpconverter.h" #include "emacsregexpconverter.h" VerifyButtons::VerifyButtons(QWidget *parent, const QString &name) : QToolBar(name, parent) , _configMenu(nullptr) { _verify = new QToolButton(this); QIcon icon = QIcon::fromTheme(QStringLiteral("tools-check-spelling")); _verify->setIcon(icon); _verify->setToolTip(i18n("Verify regular expression")); _verify->setWhatsThis(i18n("Shows what part of the regular expression is being matched in the verifier window." "(The window below the graphical editor window).")); addWidget(_verify); connect(_verify, SIGNAL(clicked()), this, SIGNAL(verify())); QToolButton *button = new QToolButton(this); button->setIcon(QIcon::fromTheme(QStringLiteral("document-open"))); addWidget(button); connect(button, SIGNAL(clicked()), this, SLOT(loadText())); button->setToolTip(i18n("Load text in the verifier window")); button = new QToolButton(this); button->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); addWidget(button); button->setToolTip(i18n("Verification Settings")); button->setPopupMode(QToolButton::InstantPopup); // It is currently not possible to ask for the paragraph being highlighted, thefore scrolling to next/prev match // do not work. Enable this when they work. // _first = new QToolButton( QString::fromLatin1("<<"), this); // layout->addWidget( _first ); - // connect(_first, SIGNAL(clicked()), this, SIGNAL( gotoFirst())); + // connect(_first, SIGNAL(clicked()), this, SIGNAL(gotoFirst())); // _first->setFixedWidth( 25 ); // // _prev = new QToolButton(QString::fromLatin1("<"), this); // layout->addWidget( _prev ); - // connect(_prev, SIGNAL(clicked()), this, SIGNAL( gotoPrev())); + // connect(_prev, SIGNAL(clicked()), this, SIGNAL(gotoPrev())); // _prev->setFixedWidth( 20 ); // // _next = new QToolButton(QString::fromLatin1(">"), this); // layout->addWidget( _next ); - // connect(_next, SIGNAL(clicked()), this, SIGNAL( gotoNext())); + // connect(_next, SIGNAL(clicked()), this, SIGNAL(gotoNext())); // _next->setFixedWidth( 20 ); // // _last = new QToolButton(QString::fromLatin1(">>"), this); // layout->addWidget( _last ); - // connect(_last, SIGNAL(clicked()), this, SIGNAL( gotoLast())); + // connect(_last, SIGNAL(clicked()), this, SIGNAL(gotoLast())); // _last->setFixedWidth( 25 ); // Same as above // QLabel* label = new QLabel( i18n("Matches: "), this ); // layout->addWidget( label ); // _matches = new QLabel(i18n("-"), this ); // layout->addWidget( _matches ); // QString txt = i18n( "Shows number of times regular expression matches the text in the verifier window"); // label->setToolTip( txt ); // _matches->setToolTip( txt ); _verify->setEnabled(false); // -------------------------------------------------- RegExp Converters // Qt RegExpConverter *converter = new QtRegExpConverter(); _converters.append(qMakePair(converter, static_cast(nullptr))); QString qtConverterName = converter->name(); // Emacs converter = new EmacsRegExpConverter(); _converters.append(qMakePair(converter, static_cast(nullptr))); QString emacsConverterName = converter->name(); // -------------------------------------------------- Initialize the config menu _configMenu = new QMenu(i18n("config menu"), this); // Auto Verify QAction *autoVerify = new QAction(i18n("Verify on the Fly"), this); autoVerify->setCheckable(true); autoVerify->setChecked(true); connect(autoVerify, SIGNAL(toggled(bool)), this, SLOT(updateVerifyButton(bool))); connect(autoVerify, SIGNAL(toggled(bool)), this, SIGNAL(autoVerify(bool))); _configMenu->addAction(autoVerify); autoVerify->setToolTip(i18n("Toggle on-the-fly verification of regular expression")); autoVerify->setWhatsThis(i18n("Enabling this option will make the verifier update for each edit. " "If the verify window contains much text, or if the regular expression is either " "complex or matches a lot of time, this may be very slow.")); QAction *matchGreedy = new QAction(i18n("Match Greedy"), this); matchGreedy->setCheckable(true); matchGreedy->setChecked(false); connect(matchGreedy, SIGNAL(toggled(bool)), this, SIGNAL(matchGreedy(bool))); _configMenu->addAction(matchGreedy); matchGreedy->setToolTip(i18n("Toggle greedy matching when verifying the regular expression.")); matchGreedy->setWhatsThis(i18n("When this option is enabled, the regular expression will be evaluated on a so-called greedy way.")); // RegExp Languages _languages = new QMenu(i18n("RegExp Language"), _configMenu); _configMenu->addMenu(_languages); QActionGroup *grp = new QActionGroup(this); for (QLinkedList< QPair >::Iterator it = _converters.begin(); it != _converters.end(); ++it) { QString name = (*it).first->name(); QAction *action = new QAction(name, this); action->setCheckable(true); grp->addAction(action); (*it).second = action; } _languages->addActions(grp->actions()); - connect(grp, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeSyntax(QAction *))); + connect(grp, SIGNAL(triggered(QAction*)), this, SLOT(slotChangeSyntax(QAction*))); _languages->setEnabled(false); button->setMenu(_configMenu); // Select the Qt converter by default setSyntax(qtConverterName); } void VerifyButtons::updateVerifyButton(bool b) { _verify->setEnabled(!b); } void VerifyButtons::loadText() { const QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(), QString()); if (!fileName.isNull()) { Q_EMIT loadVerifyText(fileName); } } // Qt anchors do not work for
...
, thefore scrolling to next/prev match // do not work. Enable this when they work. // void VerifyButtons::enableBackwardButtons( bool b ) // { // _first->setEnabled( b ); // _prev->setEnabled( b ); // } // // void VerifyButtons::enableForwardButtons( bool b ) // { // _next->setEnabled( b ); // _last->setEnabled( b ); // } void VerifyButtons::setMatchCount(int /*count*/) { // currently this is not possible due to limitation in QSyntaxHighlighter /* if ( count == -1 ) { _matches->setText( QString::fromLatin1("-") ); } else { _matches->setText( QString::number( count ) ); } */ } void VerifyButtons::slotChangeSyntax(QAction *action) { Q_EMIT changeSyntax(action->text()); } RegExpConverter *VerifyButtons::setSyntax(const QString &which) { QString noAmpersand = which; noAmpersand.remove(QLatin1Char('&')); // HACK, can probably be done more cleanly for (QLinkedList< QPair >::Iterator it = _converters.begin(); it != _converters.end(); ++it) { QString name = (*it).first->name(); if (name == noAmpersand) { (*it).second->setChecked(true); return (*it).first; } } qWarning("No such converter: '%s'", qPrintable(noAmpersand)); return nullptr; } void VerifyButtons::setAllowNonQtSyntax(bool b) { _languages->setEnabled(b); }