Prettify dialog to change EditableTexts

This commit is contained in:
WandererFan 2016-05-15 13:59:39 -04:00 committed by wmayer
parent a4061bb6a5
commit 2c73823788
5 changed files with 246 additions and 9 deletions

View File

@ -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

View File

@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
* *
* 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"

View File

@ -0,0 +1,54 @@
/**************************************************************************
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
* *
* 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 <QDialog>
#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

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TechDrawGui::dlgTemplateField</class>
<widget class="QDialog" name="TechDrawGui::dlgTemplateField">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>173</height>
</rect>
</property>
<property name="windowTitle">
<string>Change Editable Field</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<widget class="QDialogButtonBox" name="bbButtons">
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<width>341</width>
<height>31</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>331</width>
<height>80</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lblMsg">
<property name="text">
<string>Enter the new value for: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblName">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leInput"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>bbButtons</sender>
<signal>accepted()</signal>
<receiver>TechDrawGui::dlgTemplateField</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>bbButtons</sender>
<signal>rejected()</signal>
<receiver>TechDrawGui::dlgTemplateField</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -28,6 +28,7 @@
#endif // #ifndef _PreCmp_
#include "TemplateTextField.h"
#include "DlgTemplateField.h"
//#include<QDebug>
@ -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();
}