[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [labplot] src: Hightlight the text field in LabelWidget if wrong latex code was provided.
From:       Alexander Semke <alexander.semke () web ! de>
Date:       2016-10-31 18:06:48
Message-ID: E1c1Gyu-0006jF-BI () code ! kde ! org
[Download RAW message or body]

Git commit 2e2c1f501662640f49d4bb5501267c10f054f209 by Alexander Semke.
Committed on 31/10/2016 at 18:06.
Pushed by asemke into branch 'master'.

Hightlight the text field in LabelWidget if wrong latex code was provided.

M  +10   -6    src/backend/worksheet/TextLabel.cpp
M  +1    -0    src/backend/worksheet/TextLabel.h
M  +18   -0    src/kdefrontend/widgets/LabelWidget.cpp
M  +1    -0    src/kdefrontend/widgets/LabelWidget.h

http://commits.kde.org/labplot/2e2c1f501662640f49d4bb5501267c10f054f209

diff --git a/src/backend/worksheet/TextLabel.cpp \
b/src/backend/worksheet/TextLabel.cpp index 0a6749e..24881a3 100644
--- a/src/backend/worksheet/TextLabel.cpp
+++ b/src/backend/worksheet/TextLabel.cpp
@@ -193,7 +193,6 @@ void TextLabel::setText(const TextWrapper &textWrapper) {
 	Q_D(TextLabel);
 	if ( (textWrapper.text != d->textWrapper.text) || (textWrapper.teXUsed != \
d->textWrapper.teXUsed) )  exec(new TextLabelSetTextCmd(d, textWrapper, i18n("%1: set \
                label text")));
-
 }
 
 STD_SETTER_CMD_IMPL_F_S(TextLabel, SetTeXFontSize, int, teXFontSize, updateText);
@@ -391,7 +390,6 @@ void TextLabelPrivate::updatePosition() {
 		parentRect = scene()->sceneRect();
 	}
 
-
 	if (position.horizontalPosition != TextLabel::hPositionCustom) {
 		if (position.horizontalPosition == TextLabel::hPositionLeft)
 			position.point.setX( parentRect.x() );
@@ -433,11 +431,17 @@ void TextLabelPrivate::updateText() {
 }
 
 void TextLabelPrivate::updateTeXImage() {
-	teXImage = teXImageFutureWatcher.result();
+	QImage resultImage = teXImageFutureWatcher.result();
+	if (!resultImage.isNull()) {
+		teXImage = resultImage;
 
-	//the size of the tex image was most probably changed.
-	//call retransform() to recalculate the position and the bounding box of the label
-	retransform();
+		//the size of the tex image was most probably changed.
+		//call retransform() to recalculate the position and the bounding box of the label
+		retransform();
+		emit q->teXImageUpdated(true);
+	} else {
+		emit q->teXImageUpdated(false);
+	}
 }
 
 bool TextLabelPrivate::swapVisible(bool on) {
diff --git a/src/backend/worksheet/TextLabel.h b/src/backend/worksheet/TextLabel.h
index 2203f50..8056777 100644
--- a/src/backend/worksheet/TextLabel.h
+++ b/src/backend/worksheet/TextLabel.h
@@ -135,6 +135,7 @@ class TextLabel : public WorksheetElement {
 		void rotationAngleChanged(float);
 		void visibleChanged(bool);
 
+		void teXImageUpdated(bool);
 		void changed();
 };
 
diff --git a/src/kdefrontend/widgets/LabelWidget.cpp \
b/src/kdefrontend/widgets/LabelWidget.cpp index 61c8334..b27ec24 100644
--- a/src/kdefrontend/widgets/LabelWidget.cpp
+++ b/src/kdefrontend/widgets/LabelWidget.cpp
@@ -184,6 +184,7 @@ void LabelWidget::setAxes(QList<Axis*> axes) {
 void LabelWidget::initConnections() const {
 	connect( m_label, SIGNAL(textWrapperChanged(TextLabel::TextWrapper)),
 	         this, SLOT(labelTextWrapperChanged(TextLabel::TextWrapper)) );
+	connect( m_label, SIGNAL(teXImageUpdated(bool)), this, \
SLOT(labelTeXImageUpdated(bool)) );  connect( m_label, \
SIGNAL(teXFontSizeChanged(int)),  this, SLOT(labelTeXFontSizeChanged(int)) );
 	connect( m_label, SIGNAL(teXFontColorChanged(QColor)),
@@ -326,6 +327,11 @@ void LabelWidget::teXUsedChanged(bool checked) {
 	else
 		ui.tbTexUsed->setEnabled(true);
 
+	//when swithching to the text mode, set the background color to white just for the \
case the latex code provided by the user +	//in the TeX-mode is not valid and the \
background was set to red (s.a. LabelWidget::labelTeXImageUpdated()) +	if (!checked)
+		ui.teLabel->setStyleSheet("QTextEdit{background: white;}"); //TODO: assign the \
default color for the current style/theme +
 	if (m_initializing)
 		return;
 
@@ -594,6 +600,17 @@ void LabelWidget::labelTextWrapperChanged(const \
TextLabel::TextWrapper& text) {  m_initializing = false;
 }
 
+/*!
+ * \brief Highlights the text field red if wrong latex syntax was used (null image \
was produced) + * or something else went wrong during rendering (\sa \
ExpressionTextEdit::validateExpression()) + */
+void LabelWidget::labelTeXImageUpdated(bool valid) {
+	if (!valid)
+		ui.teLabel->setStyleSheet("QTextEdit{background: red;}");
+	else
+		ui.teLabel->setStyleSheet("QTextEdit{background: white;}"); //TODO: assign the \
default color for the current style/theme +}
+
 void LabelWidget::labelTeXFontSizeChanged(const int size) {
 	m_initializing = true;
 	ui.sbFontSize->setValue(size);
@@ -709,6 +726,7 @@ void LabelWidget::loadConfig(KConfigGroup& group) {
 
 	//Text
 	ui.tbTexUsed->setChecked(group.readEntry("TeXUsed", (bool) \
m_label->text().teXUsed)); +	this->teXUsedChanged(m_label->text().teXUsed);
 	ui.sbFontSize->setValue( group.readEntry("TeXFontSize", m_label->teXFontSize()) );
 	if(m_label->text().teXUsed)
 		ui.kcbFontColor->setColor(group.readEntry("TeXFontColor", \
                m_label->teXFontColor()));
diff --git a/src/kdefrontend/widgets/LabelWidget.h \
b/src/kdefrontend/widgets/LabelWidget.h index 6f47201..36578d6 100644
--- a/src/kdefrontend/widgets/LabelWidget.h
+++ b/src/kdefrontend/widgets/LabelWidget.h
@@ -99,6 +99,7 @@ private slots:
 
 	//SLOTs for changes triggered in TextLabel
 	void labelTextWrapperChanged(const TextLabel::TextWrapper&);
+	void labelTeXImageUpdated(bool);
 	void labelTeXFontSizeChanged(const int);
 	void labelTeXFontColorChanged(const QColor);
 	void labelPositionChanged(const TextLabel::PositionWrapper&);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic