diff --git a/src/Tools/RegExp/CMakeLists.txt b/src/Tools/RegExp/CMakeLists.txt new file mode 100644 index 000000000..0b6b02769 --- /dev/null +++ b/src/Tools/RegExp/CMakeLists.txt @@ -0,0 +1,60 @@ +project(RegExp) +set(APP_VERSION "1.0") + +cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR) + +find_package(Qt4) + +include_directories( + ${QT_INCLUDE_DIR} + ${QT_QTCORE_INCLUDE_DIR} + ${QT_QTGUI_INCLUDE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) +link_directories(${QT_LIBRARY_DIR}) + +add_definitions(-D_UNICODE) + +QT4_WRAP_CPP(RegExp_MOC_SRCS + regexpdialog.h +) + +QT4_WRAP_UI(RegExp_UIC_HDRS + regexpdialog.ui +) + +SET(RegExp_SRCS + ${RegExp_UIC_HDRS} + ${RegExp_MOC_SRCS} + main.cpp + regexpdialog.cpp + regexpdialog.h +) + +if (WIN32) +SET(RegExp_LIBS + debug qtmaind.lib + optimized qtmain.lib +) +endif(WIN32) + +SET(RegExp_LIBS + ${RegExp_LIBS} + ${QT_QTCORE_LIBRARY_DEBUG} + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY_DEBUG} + ${QT_QTGUI_LIBRARY} + ${QT_QTXML_LIBRARY_DEBUG} + ${QT_QTXML_LIBRARY} +) + +add_executable(RegExp WIN32 ${RegExp_SRCS}) + +target_link_libraries(RegExp ${RegExp_LIBS}) + +set_target_properties(RegExp PROPERTIES OUTPUT_NAME "RegExp") +set_target_properties(RegExp PROPERTIES DEBUG_OUTPUT_NAME "RegExpD") +# dirty hack to avoid Debug/Release subdirectory +set_target_properties(RegExp PROPERTIES PREFIX "../") +set_target_properties(RegExp PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) diff --git a/src/Tools/RegExp/RegExp.pro b/src/Tools/RegExp/RegExp.pro index adfe7af6b..e5d89d09a 100644 --- a/src/Tools/RegExp/RegExp.pro +++ b/src/Tools/RegExp/RegExp.pro @@ -1,11 +1,13 @@ ###################################################################### -# Automatically generated by qmake (1.06c) Sat Apr 9 10:49:46 2005 +# Automatically generated by qmake (2.01a) Di 3. Jul 11:56:12 2012 ###################################################################### TEMPLATE = app +TARGET = +DEPENDPATH += . INCLUDEPATH += . # Input HEADERS += regexpdialog.h -INTERFACES += regexpdialogbase.ui +FORMS += regexpdialog.ui SOURCES += main.cpp regexpdialog.cpp diff --git a/src/Tools/RegExp/main.cpp b/src/Tools/RegExp/main.cpp index 57844bfed..456311515 100644 --- a/src/Tools/RegExp/main.cpp +++ b/src/Tools/RegExp/main.cpp @@ -27,13 +27,12 @@ int main( int argc, char** argv ) { - QApplication app( argc, argv ); + QApplication app(argc, argv); - RegExpDialog dialog( 0, 0, TRUE ); - app.setMainWidget(&dialog); + RegExpDialog dialog(0); + app.setActiveWindow(&dialog); + dialog.exec(); - dialog.exec(); - - return 0; + return 0; } diff --git a/src/Tools/RegExp/regexpdialog.cpp b/src/Tools/RegExp/regexpdialog.cpp index 5e35beafe..474bfcb8c 100644 --- a/src/Tools/RegExp/regexpdialog.cpp +++ b/src/Tools/RegExp/regexpdialog.cpp @@ -22,6 +22,7 @@ #include "regexpdialog.h" +#include "ui_regexpdialog.h" #include #include @@ -29,51 +30,54 @@ #include #include -RegExpDialog::RegExpDialog( QWidget* parent, const char* name, bool modal, WFlags f ) - : RegExpDialogBase( parent, name, modal, f ) +RegExpDialog::RegExpDialog(QWidget* parent) + : QDialog(parent), ui(new Ui_RegExpDialog()) { - rxhilighter = new RegExpSyntaxHighlighter( textEdit1 ); + ui->setupUi(this); + rxhilighter = new RegExpSyntaxHighlighter(ui->textEdit1); + + connect(ui->lineEdit1, SIGNAL(textChanged(const QString &)), + this, SLOT(performRegExp())); } RegExpDialog::~RegExpDialog() { + delete ui; } void RegExpDialog::performRegExp() { - QString txt = lineEdit1->text(); - if ( txt.isEmpty() ) - { - rxhilighter->resethighlight(); - return; - } + QString txt = ui->lineEdit1->text(); + if (txt.isEmpty()) { + rxhilighter->resethighlight(); + return; + } - QRegExp rx(txt); - rx.setCaseSensitive( checkBox1->isChecked() ); - rx.setWildcard( checkBox2->isChecked() ); - rx.setMinimal( checkBox3->isChecked() ); + QRegExp rx(txt); + rx.setCaseSensitivity(ui->checkBox1->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive); + rx.setPatternSyntax(ui->checkBox2->isChecked() ? QRegExp::Wildcard : QRegExp::RegExp); + rx.setMinimal(ui->checkBox3->isChecked()); - // evaluate regular expression - textLabel4->setText( rx.errorString() ); - if ( !rx.isValid() ) - { - rxhilighter->resethighlight(); - return; // invalid expression - } + // evaluate regular expression + ui->textLabel4->setText(rx.errorString()); + if (!rx.isValid()) { + rxhilighter->resethighlight(); + return; // invalid expression + } - rxhilighter->highlightMatchedText( rx ); + rxhilighter->highlightMatchedText(rx); } void RegExpDialog::about() { - QString msg = "This is a tool for playing around with regular expressions."; - QMessageBox::information(this, "RegExp Explorer", msg); + QString msg = "This is a tool for playing around with regular expressions."; + QMessageBox::information(this, "RegExp Explorer", msg); } // ------------------------------------------------------------- -RegExpSyntaxHighlighter::RegExpSyntaxHighlighter ( QTextEdit * textEdit ) - : QSyntaxHighlighter( textEdit ) +RegExpSyntaxHighlighter::RegExpSyntaxHighlighter (QTextEdit * textEdit) + : QSyntaxHighlighter(textEdit) { } @@ -81,45 +85,71 @@ RegExpSyntaxHighlighter::~RegExpSyntaxHighlighter() { } +void RegExpSyntaxHighlighter::highlightBlock (const QString & text) +{ + QTextCharFormat regFormat; + regFormat.setForeground(Qt::black); + regFormat.setFontWeight(QFont::Normal); + setFormat(0, text.length(), regFormat); + + if (regexp.isEmpty()) + return; // empty regular expression + + int pos = 0; + int last = -1; + regFormat.setFontWeight(QFont::Bold); + regFormat.setForeground(Qt::blue); + + while ((pos = regexp.indexIn(text, pos)) != -1) { + if (last == pos) + break; + QString sub = text.mid(pos, regexp.matchedLength()); + if (!sub.isEmpty()) { + setFormat(pos, sub.length(), regFormat); + } + + pos += regexp.matchedLength(); + last=pos; + } +} +#if 0 int RegExpSyntaxHighlighter::highlightParagraph ( const QString & text, int /*endStateOfLastPara*/ ) { - // reset format - QFont font = textEdit()->currentFont(); - font.setBold( false ); - setFormat(0, text.length(), font, Qt::black ); + // reset format + QFont font = textEdit()->font(); + font.setBold( false ); + setFormat(0, text.length(), font, Qt::black ); - if ( regexp.isEmpty() ) - return 0; // empty regular expression + if (regexp.isEmpty()) + return 0; // empty regular expression - int pos = 0; - int last = -1; - font.setBold( true ); + int pos = 0; + int last = -1; + font.setBold(true); - while ( (pos = regexp.search(text, pos)) != -1 ) - { - if ( last == pos ) - break; - QString sub = text.mid( pos, regexp.matchedLength()); - if ( !sub.isEmpty() ) - { - setFormat(pos, sub.length(), font, Qt::blue ); + while ( (pos = regexp.indexIn(text, pos)) != -1 ) { + if (last == pos) + break; + QString sub = text.mid( pos, regexp.matchedLength()); + if (!sub.isEmpty()) { + setFormat(pos, sub.length(), font, Qt::blue ); + } + + pos += regexp.matchedLength(); + last=pos; } - pos += regexp.matchedLength(); - last=pos; - } - - return 0; + return 0; } - -void RegExpSyntaxHighlighter::highlightMatchedText( const QRegExp& rx ) +#endif +void RegExpSyntaxHighlighter::highlightMatchedText(const QRegExp& rx) { - regexp = rx; - rehighlight(); + regexp = rx; + rehighlight(); } void RegExpSyntaxHighlighter::resethighlight() { - regexp.setPattern(""); - rehighlight(); + regexp.setPattern(""); + rehighlight(); } diff --git a/src/Tools/RegExp/regexpdialog.h b/src/Tools/RegExp/regexpdialog.h index cc26242f9..70280cb46 100644 --- a/src/Tools/RegExp/regexpdialog.h +++ b/src/Tools/RegExp/regexpdialog.h @@ -24,24 +24,27 @@ #ifndef REG_EXP_DIALOG_H #define REG_EXP_DIALOG_H -#include "regexpdialogbase.h" - +#include #include #include class RegExpSyntaxHighlighter; -class RegExpDialog : public RegExpDialogBase +class Ui_RegExpDialog; +class RegExpDialog : public QDialog { - Q_OBJECT + Q_OBJECT public: - RegExpDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0 ); - ~RegExpDialog(); + RegExpDialog(QWidget* parent = 0); + ~RegExpDialog(); - void about(); + void about(); -protected: - void performRegExp(); - RegExpSyntaxHighlighter* rxhilighter; +protected Q_SLOTS: + void performRegExp(); + +private: + RegExpSyntaxHighlighter* rxhilighter; + Ui_RegExpDialog* ui; }; // ------------------------------------------------------------- @@ -49,15 +52,16 @@ protected: class RegExpSyntaxHighlighter : public QSyntaxHighlighter { public: - RegExpSyntaxHighlighter ( QTextEdit * textEdit ); - ~RegExpSyntaxHighlighter(); + RegExpSyntaxHighlighter (QTextEdit * textEdit); + ~RegExpSyntaxHighlighter(); - int highlightParagraph ( const QString & text, int endStateOfLastPara ); - void highlightMatchedText( const QRegExp& ); - void resethighlight(); + void highlightBlock (const QString & text); + //int highlightParagraph ( const QString & text, int endStateOfLastPara ); + void highlightMatchedText( const QRegExp& ); + void resethighlight(); private: - QRegExp regexp; + QRegExp regexp; }; #endif // REG_EXP_DIALOG_H diff --git a/src/Tools/RegExp/regexpdialog.ui b/src/Tools/RegExp/regexpdialog.ui new file mode 100644 index 000000000..1b11d130f --- /dev/null +++ b/src/Tools/RegExp/regexpdialog.ui @@ -0,0 +1,180 @@ + + + RegExpDialog + + + + 0 + 0 + 519 + 285 + + + + RegExp Explorer + + + true + + + + 10 + + + 6 + + + + + + + + 6 + + + 0 + + + + + Case sensitive + + + true + + + + + + + Wildcard + + + + + + + Minimal + + + true + + + + + + + + + 6 + + + 0 + + + + + Status: + + + + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 80 + 20 + + + + + + + + + + + &Close + + + true + + + true + + + + + + + &Help + + + true + + + + + + + + + Regular Expression: + + + + + + + Text: + + + + + + + + + + + textEdit1 + checkBox1 + checkBox2 + checkBox3 + lineEdit1 + buttonClose + buttonHelp + + + + + buttonClose + clicked() + RegExpDialog + accept() + + + 400 + 263 + + + 312 + 283 + + + + + diff --git a/src/Tools/RegExp/regexpdialogbase.ui b/src/Tools/RegExp/regexpdialogbase.ui deleted file mode 100644 index 5b473e3bb..000000000 --- a/src/Tools/RegExp/regexpdialogbase.ui +++ /dev/null @@ -1,166 +0,0 @@ - - - - - RegExpDialogBase - - - - 0 - 0 - 519 - 285 - - - - RegExp Explorer - - - true - - - - 10 - - - 6 - - - - - - - - 0 - - - 6 - - - - - Case sensitive - - - true - - - - - - - Wildcard - - - - - - - Minimal - - - true - - - - - - - - - 0 - - - 6 - - - - - Status: - - - - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 80 - 20 - - - - - - - - - - - &Close - - - true - - - true - - - - - - - &Help - - - true - - - - - - - - - Regular Expression: - - - - - - - Text: - - - - - - - - - - qPixmapFromMimeSource - - textEdit1 - checkBox1 - checkBox2 - checkBox3 - lineEdit1 - buttonClose - buttonHelp - - - -