From 2c73823788a363767dbd8a7df355d07e243abcda Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sun, 15 May 2016 13:59:39 -0400 Subject: [PATCH] Prettify dialog to change EditableTexts --- src/Mod/TechDraw/Gui/CMakeLists.txt | 5 + src/Mod/TechDraw/Gui/DlgTemplateField.cpp | 67 +++++++++++++ src/Mod/TechDraw/Gui/DlgTemplateField.h | 54 ++++++++++ src/Mod/TechDraw/Gui/DlgTemplateField.ui | 109 +++++++++++++++++++++ src/Mod/TechDraw/Gui/TemplateTextField.cpp | 20 ++-- 5 files changed, 246 insertions(+), 9 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/DlgTemplateField.cpp create mode 100644 src/Mod/TechDraw/Gui/DlgTemplateField.h create mode 100644 src/Mod/TechDraw/Gui/DlgTemplateField.ui diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index c738f3afbb..d476730242 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -44,6 +44,7 @@ set(TechDrawGui_MOC_HDRS TaskProjGroup.h DlgPrefsTechDrawImp.h TaskLinkDim.h + DlgTemplateField.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -55,6 +56,7 @@ set(TechDrawGui_UIC_SRCS DlgPrefsTechDraw.ui TaskProjGroup.ui TaskLinkDim.ui + DlgTemplateField.ui ) qt4_wrap_ui(TechDrawGui_UIC_HDRS ${TechDrawGui_UIC_SRCS}) @@ -80,6 +82,9 @@ SET(TechDrawGui_SRCS TaskLinkDim.ui TaskLinkDim.cpp TaskLinkDim.h + DlgTemplateField.ui + DlgTemplateField.cpp + DlgTemplateField.h ) SET(TechDrawGuiView_SRCS MDIViewPage.cpp diff --git a/src/Mod/TechDraw/Gui/DlgTemplateField.cpp b/src/Mod/TechDraw/Gui/DlgTemplateField.cpp new file mode 100644 index 0000000000..e8c37e4707 --- /dev/null +++ b/src/Mod/TechDraw/Gui/DlgTemplateField.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (c) 2016 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * 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., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#include "DlgTemplateField.h" + +using namespace TechDrawGui; + +DlgTemplateField::DlgTemplateField( QWidget* parent ) +{ + setupUi(this); +} + +DlgTemplateField::~DlgTemplateField() +{ +} + +void DlgTemplateField::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + retranslateUi(this); + } + else { + QWidget::changeEvent(e); + } +} + +void DlgTemplateField::setFieldName(std::string name) +{ + QString qs = QString::fromStdString(name); + lblName->setText(qs); +} + +void DlgTemplateField::setFieldContent(std::string content) +{ + QString qs = QString::fromStdString(content); + leInput->setText(qs); +} + +std::string DlgTemplateField::getFieldContent() +{ + QString result = leInput->text(); + return result.toUtf8().constData(); +} + +#include "moc_DlgTemplateField.cpp" diff --git a/src/Mod/TechDraw/Gui/DlgTemplateField.h b/src/Mod/TechDraw/Gui/DlgTemplateField.h new file mode 100644 index 0000000000..28e5d3c703 --- /dev/null +++ b/src/Mod/TechDraw/Gui/DlgTemplateField.h @@ -0,0 +1,54 @@ + /************************************************************************** + * Copyright (c) 2016 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * 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., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef DRAWINGGUI_DLGTEMPLATEFIELD_H +#define DRAWINGGUI_DLGTEMPLATEFIELD_H + +#include + +#include "ui_DlgTemplateField.h" + +namespace TechDrawGui { + +class DlgTemplateField : public QDialog, public Ui_dlgTemplateField +{ + Q_OBJECT + +public: + DlgTemplateField( QWidget* parent = 0 ); + ~DlgTemplateField(); + + void setFieldName(std::string name); + void setFieldContent(std::string content); + std::string getFieldContent(); + +public Q_SLOTS: + +protected: + void changeEvent(QEvent *e); + //Ui_dlgTemplateField* ui; +}; + +} // namespace TechDrawGui + +#endif // DRAWINGGUI_DLGTEMPLATEFIELD_H diff --git a/src/Mod/TechDraw/Gui/DlgTemplateField.ui b/src/Mod/TechDraw/Gui/DlgTemplateField.ui new file mode 100644 index 0000000000..918492b436 --- /dev/null +++ b/src/Mod/TechDraw/Gui/DlgTemplateField.ui @@ -0,0 +1,109 @@ + + + TechDrawGui::dlgTemplateField + + + Qt::WindowModal + + + + 0 + 0 + 372 + 173 + + + + Change Editable Field + + + true + + + + + 10 + 130 + 341 + 31 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + 20 + 20 + 331 + 80 + + + + + + + Enter the new value for: + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + + + + + + + bbButtons + accepted() + TechDrawGui::dlgTemplateField + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bbButtons + rejected() + TechDrawGui::dlgTemplateField + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/Mod/TechDraw/Gui/TemplateTextField.cpp b/src/Mod/TechDraw/Gui/TemplateTextField.cpp index 3deded85fa..ed906e2e89 100644 --- a/src/Mod/TechDraw/Gui/TemplateTextField.cpp +++ b/src/Mod/TechDraw/Gui/TemplateTextField.cpp @@ -28,6 +28,7 @@ #endif // #ifndef _PreCmp_ #include "TemplateTextField.h" +#include "DlgTemplateField.h" //#include @@ -48,14 +49,15 @@ TemplateTextField::~TemplateTextField() void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event) { //TODO: Add a command to change template text, and call it from here - bool ok; - QString curStr = QString::fromUtf8(tmplte->EditableTexts[fieldNameStr].c_str()); - QString newStr = QInputDialog::getText(NULL, QObject::tr("Change template text"), - QObject::tr("Enter a new value for ") + - QString::fromUtf8(fieldNameStr.c_str()), - QLineEdit::Normal, curStr, &ok); - if (ok && !newStr.isEmpty()) { - tmplte->EditableTexts.setValue(fieldNameStr, newStr.toUtf8().constData()); + // ...Interpreter....("App.ActiveDocument().%s.%s.setTextField(%s,%s)",pageName,templateName,fieldName,fieldValue) + DlgTemplateField* ui = new DlgTemplateField(nullptr); + ui->setFieldName(fieldNameStr); + ui->setFieldContent(tmplte->EditableTexts[fieldNameStr]); + int uiCode = ui->exec(); + std::string newContent = ""; + if(uiCode == QDialog::Accepted) { + std::string newContent = ui->getFieldContent(); + tmplte->EditableTexts.setValue(fieldNameStr, newContent); } + ui->deleteLater(); } -