TechDraw - Edit annotations via double-click
This commit is contained in:
committed by
Bernd Hahnebach
parent
78b644e313
commit
bb44a4dd0e
@@ -43,6 +43,7 @@
|
||||
#include <QTextFrame>
|
||||
#include <QTextBlock>
|
||||
#include <QTextCursor>
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
# include <math.h>
|
||||
@@ -80,6 +81,7 @@
|
||||
#include "QGCustomRect.h"
|
||||
|
||||
#include "QGIRichAnno.h"
|
||||
#include "mrichtextedit.h"
|
||||
|
||||
using namespace TechDraw;
|
||||
using namespace TechDrawGui;
|
||||
@@ -360,4 +362,36 @@ double QGIRichAnno::prefPointSize(void)
|
||||
return ptsSize;
|
||||
}
|
||||
|
||||
void QGIRichAnno::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) {
|
||||
Q_UNUSED(event);
|
||||
|
||||
TechDraw::DrawRichAnno *annotation = dynamic_cast<TechDraw::DrawRichAnno *>(getViewObject());
|
||||
if (annotation == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString text = QString::fromUtf8(annotation->AnnoText.getValue());
|
||||
|
||||
QDialog dialog(0);
|
||||
dialog.setWindowTitle(QObject::tr("Rich text editor"));
|
||||
dialog.setMinimumWidth(400);
|
||||
dialog.setMinimumHeight(400);
|
||||
|
||||
MRichTextEdit richEdit(&dialog, text);
|
||||
QGridLayout gridLayout(&dialog);
|
||||
gridLayout.addWidget(&richEdit, 0, 0, 1, 1);
|
||||
|
||||
connect(&richEdit, SIGNAL(saveText(QString)), &dialog, SLOT(accept()));
|
||||
connect(&richEdit, SIGNAL(editorFinished(void)), &dialog, SLOT(reject()));
|
||||
|
||||
if (dialog.exec()) {
|
||||
QString newText = richEdit.toHtml();
|
||||
if (newText != text) {
|
||||
App::GetApplication().setActiveTransaction("Set Rich Annotation Text");
|
||||
annotation->AnnoText.setValue(newText.toStdString());
|
||||
App::GetApplication().closeActiveTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Mod/TechDraw/Gui/moc_QGIRichAnno.cpp>
|
||||
|
||||
@@ -98,6 +98,8 @@ protected:
|
||||
double prefPointSize(void);
|
||||
QFont prefFont(void);
|
||||
|
||||
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
bool m_isExporting;
|
||||
QGCustomText* m_text;
|
||||
bool m_hasHover;
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Gui/Widgets.h>
|
||||
|
||||
|
||||
#include <Mod/TechDraw/App/DrawViewAnnotation.h>
|
||||
#include "Rez.h"
|
||||
@@ -189,4 +191,54 @@ void QGIViewAnnotation::rotateView(void)
|
||||
m_textItem->setRotation(-rot);
|
||||
}
|
||||
|
||||
void QGIViewAnnotation::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
TechDraw::DrawViewAnnotation *annotation = dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject());
|
||||
if (annotation == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::vector<std::string> &values = annotation->Text.getValues();
|
||||
QString text;
|
||||
if (values.size() > 0) {
|
||||
text = QString::fromUtf8(Base::Tools::escapedUnicodeToUtf8(values[0]).c_str());
|
||||
|
||||
for (unsigned int i = 1; i < values.size(); ++i) {
|
||||
text += QChar::fromLatin1('\n');
|
||||
text += QString::fromUtf8(Base::Tools::escapedUnicodeToUtf8(values[i]).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
QDialog dialog(0);
|
||||
dialog.setWindowTitle(tr("Text"));
|
||||
|
||||
Gui::PropertyListEditor editor(&dialog);
|
||||
editor.setPlainText(text);
|
||||
|
||||
QDialogButtonBox buttonBox(&dialog);
|
||||
buttonBox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
QVBoxLayout boxLayout(&dialog);
|
||||
boxLayout.addWidget(&editor);
|
||||
boxLayout.addWidget(&buttonBox);
|
||||
|
||||
connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
||||
connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QString newText = editor.toPlainText();
|
||||
if (newText != text) {
|
||||
QStringList list = newText.split(QChar::fromLatin1('\n'));
|
||||
std::vector<std::string> newValues;
|
||||
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
newValues.push_back(Base::Tools::escapedUnicodeFromUtf8(list[i].toStdString().c_str()));
|
||||
}
|
||||
|
||||
App::GetApplication().setActiveTransaction("Set Annotation Text");
|
||||
annotation->Text.setValues(newValues);
|
||||
App::GetApplication().closeActiveTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ protected:
|
||||
void drawAnnotation();
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
|
||||
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
QGCustomText *m_textItem;
|
||||
QColor m_colNormal;
|
||||
QColor m_colSel;
|
||||
|
||||
@@ -317,6 +317,15 @@ void MRichTextEdit::focusInEvent(QFocusEvent *) {
|
||||
f_textedit->setFocus(Qt::TabFocusReason);
|
||||
}
|
||||
|
||||
void MRichTextEdit::keyPressEvent(QKeyEvent *event) {
|
||||
if (event->key() == Qt::Key_Return && event->modifiers() == Qt::ControlModifier) {
|
||||
onSave();
|
||||
return;
|
||||
}
|
||||
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void MRichTextEdit::textUnderline() {
|
||||
QTextCharFormat fmt;
|
||||
|
||||
@@ -94,6 +94,7 @@ Q_SIGNALS:
|
||||
void list(bool checked, QTextListFormat::Style style);
|
||||
void indent(int delta);
|
||||
void focusInEvent(QFocusEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
bool hasMultipleSizes(void);
|
||||
|
||||
void addFontSize(QString fs);
|
||||
|
||||
Reference in New Issue
Block a user