Skip to content

Commit

Permalink
Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Aug 21, 2014
2 parents 806c857 + 811fb3b commit 317206a
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 274 deletions.
20 changes: 5 additions & 15 deletions src/Mod/Drawing/Gui/DrawingView.cpp
Expand Up @@ -349,21 +349,11 @@ bool DrawingView::onHasMsg(const char* pMsg) const

void DrawingView::onRelabel(Gui::Document *pDoc)
{
if (!bIsPassive) {
// Try to separate document name and object name if there is one
QString cap = windowTitle();
QRegExp rx(QString::fromLatin1(" : (\\w|\\s){1,}(\\[\\*\\]){0,1}$"));
int pos = rx.lastIndexIn(cap);
if (pos != -1) {
cap = QString::fromUtf8(pDoc->getDocument()->Label.getValue());
cap += rx.cap();
setWindowTitle(cap);
}
else {
cap = QString::fromUtf8(pDoc->getDocument()->Label.getValue());
cap = QString::fromAscii("%1[*]").arg(cap);
setWindowTitle(cap);
}
if (!bIsPassive && pDoc) {
QString cap = QString::fromLatin1("%1 : %2[*]")
.arg(QString::fromUtf8(pDoc->getDocument()->Label.getValue()))
.arg(objectName());
setWindowTitle(cap);
}
}

Expand Down
16 changes: 6 additions & 10 deletions src/Mod/Drawing/Gui/ViewProviderPage.cpp
Expand Up @@ -106,12 +106,11 @@ void ViewProviderDrawingPage::updateData(const App::Property* prop)
}
else if (pcObject && prop == &pcObject->Label) {
if (view){
const char* docname = pcObject->getDocument()->Label.getValue();
const char* objname = pcObject->Label.getValue();
QString title = QString::fromAscii("%1 : %2[*]")
.arg(QString::fromUtf8(docname))
.arg(QString::fromUtf8(objname));
view->setWindowTitle(title);
view->setObjectName(QString::fromUtf8(objname));
Gui::Document* doc = Gui::Application::Instance->getDocument
(pcObject->getDocument());
view->onRelabel(doc);
}
}
}
Expand Down Expand Up @@ -147,12 +146,9 @@ DrawingView* ViewProviderDrawingPage::showDrawingView()
view = new DrawingView(doc, Gui::getMainWindow());
view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape"));

const char* docname = pcObject->getDocument()->Label.getValue();
const char* objname = pcObject->Label.getValue();
QString title = QString::fromAscii("%1 : %2[*]")
.arg(QString::fromUtf8(docname))
.arg(QString::fromUtf8(objname));
view->setWindowTitle(title);
view->setObjectName(QString::fromUtf8(objname));
view->onRelabel(doc);
Gui::getMainWindow()->addWindow(view);
}

Expand Down
60 changes: 60 additions & 0 deletions 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)
6 changes: 4 additions & 2 deletions 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
11 changes: 5 additions & 6 deletions src/Tools/RegExp/main.cpp
Expand Up @@ -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;
}

148 changes: 89 additions & 59 deletions src/Tools/RegExp/regexpdialog.cpp
Expand Up @@ -22,104 +22,134 @@


#include "regexpdialog.h"
#include "ui_regexpdialog.h"

#include <qcheckbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qtextedit.h>

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;
}

QRegExp rx(txt);
rx.setCaseSensitive( checkBox1->isChecked() );
rx.setWildcard( checkBox2->isChecked() );
rx.setMinimal( checkBox3->isChecked() );

// evaluate regular expression
textLabel4->setText( rx.errorString() );
if ( !rx.isValid() )
{
rxhilighter->resethighlight();
return; // invalid expression
}

rxhilighter->highlightMatchedText( rx );
QString txt = ui->lineEdit1->text();
if (txt.isEmpty()) {
rxhilighter->resethighlight();
return;
}

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
ui->textLabel4->setText(rx.errorString());
if (!rx.isValid()) {
rxhilighter->resethighlight();
return; // invalid expression
}

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)
{
}

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 );

if ( regexp.isEmpty() )
return 0; // empty regular expression

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 );
// reset format
QFont font = textEdit()->font();
font.setBold( false );
setFormat(0, text.length(), font, Qt::black );

if (regexp.isEmpty())
return 0; // empty regular expression

int pos = 0;
int last = -1;
font.setBold(true);

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();
}

0 comments on commit 317206a

Please sign in to comment.