From 2bda8f7717adf28da4af0d34fb82f63d2868c31d Mon Sep 17 00:00:00 2001
From: toma
Date: Wed, 25 Nov 2009 17:56:58 +0000
Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
---
kregexpeditor/regexpbuttons.cpp | 217 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 217 insertions(+)
create mode 100644 kregexpeditor/regexpbuttons.cpp
(limited to 'kregexpeditor/regexpbuttons.cpp')
diff --git a/kregexpeditor/regexpbuttons.cpp b/kregexpeditor/regexpbuttons.cpp
new file mode 100644
index 0000000..eae7da0
--- /dev/null
+++ b/kregexpeditor/regexpbuttons.cpp
@@ -0,0 +1,217 @@
+/*
+ * 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.
+ **/
+#ifdef QT_ONLY
+ #include "compat.h"
+ #include "images.h"
+#else
+ #include
+ #include
+ #include
+ #include "regexpbuttons.moc"
+#endif
+
+#include "regexpbuttons.h"
+#include "dcbutton.h"
+#include
+#include
+#include
+#include
+#include
+#include "regexpconverter.h"
+
+RegExpButtons::RegExpButtons( QWidget *parent, const char *name )
+ : QDockWindow( QDockWindow::InDock, parent, name), _keepMode(false)
+{
+ QBoxLayout *layout = boxLayout();
+
+ _grp = new QButtonGroup(this);
+ _grp->hide();
+ _grp->setExclusive( true );
+
+ _mapper = new QSignalMapper( this, "RegExpButtons::_mapper" );
+ connect( _mapper, SIGNAL( mapped(int) ), this, SIGNAL( clicked(int) ) );
+
+ // The "select" button.
+ _selectBut = new QToolButton( this);
+
+#ifdef QT_ONLY
+ QPixmap pix;
+ pix.convertFromImage( qembed_findImage( "select" ) );
+#else
+ QPixmap pix = KGlobal::iconLoader()->loadIcon(locate("data", QString::fromLatin1("kregexpeditor/pics/select.png") ), KIcon::Toolbar );
+#endif
+
+ _selectBut->setPixmap( pix );
+ layout->addWidget( _selectBut );
+ _grp->insert(_selectBut);
+ _selectBut->setToggleButton( true );
+ connect( _selectBut, SIGNAL(clicked()), SIGNAL(doSelect()));
+ connect( _selectBut, SIGNAL(clicked()), this, SLOT(slotSetNonKeepMode()) );
+
+ QToolTip::add( _selectBut, i18n("Selection tool"));
+ QWhatsThis::add( _selectBut, i18n("This will change the state of the editor to selection state."
+ "In this state you will not be inserting regexp items, but instead select them. "
+ "To select a number of items, press down the left mouse button and drag it over the items.
"
+ "When you have selected a number of items, you may use cut/copy/paste. These functions are "
+ "found in the right mouse button menu.
"));
+
+ // Insert buttons.
+ DoubleClickButton* but;
+
+ but = insert(TEXT, "text", i18n("Text"),
+ i18n( "This will insert a text field, where you may write text. The text you write will "
+ "be matched literally. (i.e. you do not need to escape any characters)" ) );
+ layout->addWidget( but );
+
+
+ but = insert(CHARSET, "characters", i18n("A single character specified in a range"),
+ i18n("This will match a single character from a predefined range."
+ "When you insert this widget a dialog box will appear, which lets you specify "
+ "which characters this regexp item will match.
") );
+ layout->addWidget( but );
+
+
+ but = insert(DOT, "anychar", i18n("Any character"),
+ i18n("This will match any single character") );
+ layout->addWidget( but );
+
+
+ but = insert(REPEAT, "repeat", i18n("Repeated content"),
+ i18n("This regexp item will repeat the regexp items it surrounds "
+ "a specified number of times."
+ "The number of times to repeat may be specified using ranges. e.g. You may specify "
+ "that it should match from 2 to 4 times, that it should match exactly 5 times, or "
+ "that it should match at least one time.
"
+ "Examples:
"
+ "If you specify that it should match any time, and the content it surrounds "
+ "is abc, then this regexp item will match the empty string, "
+ "the string abc, the string abcabc, the string abcabcabcabc, "
+ "etc.
") );
+ layout->addWidget( but );
+
+
+ but = insert(ALTN, "altn", i18n("Alternatives"),
+ i18n("This regexp item will match any of its alternatives.
"
+ "You specify alternatives by placing regexp items on top of "
+ "each other inside this widget.") );
+ layout->addWidget( but );
+
+
+ but = insert(COMPOUND, "compound", i18n("Compound regexp"),
+ i18n("This regexp item serves two purposes:"
+ "- It makes it possible for you to collapse a huge regexp item into "
+ "a small box. This makes it easier for you to get an overview of large "
+ "regexp items. This is especially useful if you load a predefined regexp item "
+ "you perhaps don't care about the inner workings of.") );
+ layout->addWidget( but );
+
+
+ but = insert(BEGLINE, "begline", i18n("Beginning of line"),
+ i18n("This will match the beginning of a line.") );
+ layout->addWidget( but );
+
+
+ but = insert(ENDLINE, "endline", i18n("End of line"),
+ i18n("This will match the end of a line.") );
+ layout->addWidget( but );
+
+
+ _wordBoundary = insert(WORDBOUNDARY, "wordboundary", i18n("Word boundary"),
+ i18n("This asserts a word boundary (This part does not actually match any characters)") );
+ layout->addWidget( _wordBoundary );
+
+ _nonWordBoundary = insert(NONWORDBOUNDARY, "nonwordboundary", i18n("Non Word boundary"),
+ i18n("This asserts a non-word boundary "
+ "(This part does not actually match any characters)") );
+ layout->addWidget( _nonWordBoundary );
+
+ _posLookAhead = insert(POSLOOKAHEAD, "poslookahead", i18n("Positive Look Ahead"),
+ i18n("This asserts a regular expression (This part does not actually match any characters). "
+ "You can only use this at the end of a regular expression.") );
+ layout->addWidget( _posLookAhead );
+
+ _negLookAhead = insert(NEGLOOKAHEAD, "neglookahead", i18n("Negative Look Ahead"),
+ i18n("This asserts a regular expression that must not match "
+ "(This part does not actually match any characters). "
+ "You can only use this at the end of a regular expression.") );
+ layout->addWidget( _negLookAhead );
+}
+
+DoubleClickButton* RegExpButtons::insert(RegExpType tp, const char* name, QString tooltip, QString whatsthis)
+{
+#ifdef QT_ONLY
+ QPixmap pix;
+ pix.convertFromImage( qembed_findImage( QString::fromLatin1( name ) ) );
+#else
+ QPixmap pix = KGlobal::iconLoader()->loadIcon(locate("data", QString::fromLatin1("kregexpeditor/pics/")+QString::fromLatin1(name) +
+ QString::fromLatin1(".png") ), KIcon::Toolbar );
+#endif
+
+ DoubleClickButton* but = new DoubleClickButton( pix, this, "RegExpButtons::but");
+
+ _mapper->setMapping( but, tp );
+
+ connect( but, SIGNAL( clicked() ), _mapper, SLOT( map() ) );
+ connect( but, SIGNAL( clicked() ), this, SLOT( slotSetNonKeepMode() ) );
+ connect( but, SIGNAL( doubleClicked() ), this, SLOT( slotSetKeepMode() ) );
+
+ _grp->insert( but );
+ but->setToggleButton( true );
+ QToolTip::add( but, tooltip );
+ QWhatsThis::add( but, whatsthis );
+
+ return but;
+}
+
+void RegExpButtons::slotUnSelect()
+{
+ if ( _grp->selected() ) {
+ QToolButton *pb = static_cast(_grp->selected());
+ if (pb) {
+ pb->setOn( false );
+ }
+ }
+}
+
+void RegExpButtons::slotSetKeepMode( )
+{
+ _keepMode = true;
+}
+
+void RegExpButtons::slotSetNonKeepMode( )
+{
+ _keepMode = false;
+}
+
+void RegExpButtons::slotSelectNewAction()
+{
+ if ( ! _keepMode ) {
+ emit doSelect();
+ _grp->setButton(_grp->id(_selectBut));
+ }
+}
+
+void RegExpButtons::setFeatures( int features )
+{
+ _wordBoundary->setShown( features & RegExpConverter::WordBoundary );
+ _nonWordBoundary->setShown( features & RegExpConverter::NonWordBoundary );
+ _posLookAhead->setShown( features & RegExpConverter::PosLookAhead );
+ _negLookAhead->setShown( features & RegExpConverter::NegLookAhead );
+
+}
+
--
cgit v1.2.3