Gui: Change label type to ExpressionLabel in ExpressionBinding
* Add function ExpressionBinding::makeLabel() and use it in subclasses to reduce code duplication
This commit is contained in:
@@ -22,9 +22,12 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QLineEdit>
|
||||
# include <QPixmapCache>
|
||||
# include <QStyle>
|
||||
#endif
|
||||
#include "ExpressionBinding.h"
|
||||
#include "QuantitySpinBox_p.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "Command.h"
|
||||
#include <App/Expression.h>
|
||||
@@ -266,3 +269,21 @@ void ExpressionBinding::objectDeleted(const App::DocumentObject& obj)
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionBinding::makeLabel(QLineEdit* le)
|
||||
{
|
||||
defaultPalette = le->palette();
|
||||
|
||||
/* Icon for f(x) */
|
||||
QFontMetrics fm(le->font());
|
||||
int frameWidth = le->style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
iconHeight = fm.height() - frameWidth;
|
||||
iconLabel = new ExpressionLabel(le);
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; padding-top: %2px; width: %1px; height: %1px }").arg(iconHeight).arg(frameWidth/2));
|
||||
iconLabel->hide();
|
||||
iconLabel->setExpressionText(QString());
|
||||
le->setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconHeight+frameWidth));
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ namespace App {
|
||||
class Expression;
|
||||
}
|
||||
|
||||
class ExpressionLabel;
|
||||
class QLineEdit;
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class GuiExport ExpressionBinding
|
||||
@@ -66,12 +69,14 @@ protected:
|
||||
//gets called when the bound expression is changed, either by this binding or any external action
|
||||
virtual void onChange() {}
|
||||
|
||||
void makeLabel(QLineEdit* parent);
|
||||
|
||||
private:
|
||||
App::ObjectIdentifier path;
|
||||
std::shared_ptr<App::Expression> lastExpression;
|
||||
|
||||
protected:
|
||||
QLabel* iconLabel;
|
||||
ExpressionLabel* iconLabel;
|
||||
QPalette defaultPalette;
|
||||
int iconHeight;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "Command.h"
|
||||
#include "InputField.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "QuantitySpinBox_p.h"
|
||||
#include "propertyeditor/PropertyItem.h"
|
||||
|
||||
using namespace Gui;
|
||||
@@ -78,7 +79,7 @@ InputField::InputField(QWidget * parent)
|
||||
{
|
||||
setValidator(new InputValidator(this));
|
||||
setFocusPolicy(Qt::WheelFocus);
|
||||
iconLabel = new QLabel(this);
|
||||
iconLabel = new ExpressionLabel(this);
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getValidationIcon(":/icons/button_valid.svg", QSize(sizeHint().height(),sizeHint().height()));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
|
||||
@@ -300,20 +300,8 @@ QuantitySpinBox::QuantitySpinBox(QWidget *parent)
|
||||
QObject::connect(this, SIGNAL(editingFinished()),
|
||||
this, SLOT(handlePendingEmit()));
|
||||
|
||||
defaultPalette = lineEdit()->palette();
|
||||
makeLabel(lineEdit());
|
||||
|
||||
/* Icon for f(x) */
|
||||
QFontMetrics fm(lineEdit()->font());
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
iconHeight = fm.height() - frameWidth;
|
||||
iconLabel = new ExpressionLabel(lineEdit());
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; padding-top: %2px; width: %1px; height: %1px }").arg(iconHeight).arg(frameWidth/2));
|
||||
iconLabel->hide();
|
||||
static_cast<ExpressionLabel *>(iconLabel)->setExpressionText(QString());
|
||||
lineEdit()->setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconHeight+frameWidth));
|
||||
// When a style sheet is set the text margins for top/bottom must be set to avoid to squash the widget
|
||||
#ifndef Q_OS_MAC
|
||||
lineEdit()->setTextMargins(0, 2, 0, 2);
|
||||
@@ -448,7 +436,7 @@ void Gui::QuantitySpinBox::onChange()
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -457,7 +445,7 @@ void Gui::QuantitySpinBox::onChange()
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +500,7 @@ void QuantitySpinBox::resizeEvent(QResizeEvent * event)
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -522,7 +510,7 @@ void QuantitySpinBox::resizeEvent(QResizeEvent * event)
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#define QUANTITYSPINBOX_P_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
|
||||
class ExpressionLabel : public QLabel
|
||||
{
|
||||
|
||||
@@ -151,20 +151,7 @@ UIntSpinBox::UIntSpinBox (QWidget* parent)
|
||||
setValue(0);
|
||||
updateValidator();
|
||||
|
||||
defaultPalette = lineEdit()->palette();
|
||||
|
||||
/* Icon for f(x) */
|
||||
QFontMetrics fm(lineEdit()->font());
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
iconHeight = fm.height() - frameWidth;
|
||||
iconLabel = new ExpressionLabel(lineEdit());
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; padding-top: %2px; width: %1px; height: %1px }").arg(iconHeight).arg(frameWidth/2));
|
||||
iconLabel->hide();
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
lineEdit()->setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconHeight+frameWidth));
|
||||
makeLabel(lineEdit());
|
||||
|
||||
QObject::connect(iconLabel, SIGNAL(clicked()), this, SLOT(openFormulaDialog()));
|
||||
}
|
||||
@@ -296,7 +283,7 @@ void UIntSpinBox::onChange() {
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -304,7 +291,7 @@ void UIntSpinBox::onChange() {
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,7 +334,7 @@ void UIntSpinBox::resizeEvent(QResizeEvent * event)
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -357,7 +344,7 @@ void UIntSpinBox::resizeEvent(QResizeEvent * event)
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
@@ -430,23 +417,9 @@ void UIntSpinBox::paintEvent(QPaintEvent*)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IntSpinBox::IntSpinBox(QWidget* parent) : QSpinBox(parent) {
|
||||
|
||||
defaultPalette = lineEdit()->palette();
|
||||
|
||||
/* Icon for f(x) */
|
||||
QFontMetrics fm(lineEdit()->font());
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
iconHeight = fm.height() - frameWidth;
|
||||
iconLabel = new ExpressionLabel(lineEdit());
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; padding-top: %2px; width: %1px; height: %1px }").arg(iconHeight).arg(frameWidth/2));
|
||||
iconLabel->hide();
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
lineEdit()->setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconHeight+frameWidth));
|
||||
|
||||
IntSpinBox::IntSpinBox(QWidget* parent) : QSpinBox(parent)
|
||||
{
|
||||
makeLabel(lineEdit());
|
||||
QObject::connect(iconLabel, SIGNAL(clicked()), this, SLOT(openFormulaDialog()));
|
||||
}
|
||||
|
||||
@@ -506,7 +479,7 @@ void IntSpinBox::onChange() {
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -514,7 +487,7 @@ void IntSpinBox::onChange() {
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,7 +514,7 @@ void IntSpinBox::resizeEvent(QResizeEvent * event)
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -551,7 +524,7 @@ void IntSpinBox::resizeEvent(QResizeEvent * event)
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
@@ -624,23 +597,9 @@ void IntSpinBox::paintEvent(QPaintEvent*)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
DoubleSpinBox::DoubleSpinBox(QWidget* parent): QDoubleSpinBox(parent) {
|
||||
|
||||
defaultPalette = lineEdit()->palette();
|
||||
|
||||
/* Icon for f(x) */
|
||||
QFontMetrics fm(lineEdit()->font());
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
iconHeight = fm.height() - frameWidth;
|
||||
iconLabel = new ExpressionLabel(lineEdit());
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; padding-top: %2px; width: %1px; height: %1px }").arg(iconHeight).arg(frameWidth/2));
|
||||
iconLabel->hide();
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
lineEdit()->setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconHeight+frameWidth));
|
||||
|
||||
DoubleSpinBox::DoubleSpinBox(QWidget* parent): QDoubleSpinBox(parent)
|
||||
{
|
||||
makeLabel(lineEdit());
|
||||
QObject::connect(iconLabel, SIGNAL(clicked()), this, SLOT(openFormulaDialog()));
|
||||
}
|
||||
|
||||
@@ -700,7 +659,7 @@ void DoubleSpinBox::onChange() {
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -708,7 +667,7 @@ void DoubleSpinBox::onChange() {
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -735,7 +694,7 @@ void DoubleSpinBox::resizeEvent(QResizeEvent * event)
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
lineEdit()->setPalette(p);
|
||||
}
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -745,7 +704,7 @@ void DoubleSpinBox::resizeEvent(QResizeEvent * event)
|
||||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
|
||||
@@ -1354,23 +1354,10 @@ void LabelEditor::setInputType(InputType t)
|
||||
ExpLineEdit::ExpLineEdit(QWidget* parent, bool expressionOnly)
|
||||
: QLineEdit(parent), autoClose(expressionOnly)
|
||||
{
|
||||
defaultPalette = palette();
|
||||
|
||||
/* Icon for f(x) */
|
||||
QFontMetrics fm(font());
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
iconHeight = fm.height() - frameWidth;
|
||||
iconLabel = new ExpressionLabel(this);
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; padding-top: %2px; width: %1px; height: %1px }").arg(iconHeight).arg(frameWidth/2));
|
||||
iconLabel->hide();
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconHeight+frameWidth));
|
||||
makeLabel(this);
|
||||
|
||||
QObject::connect(iconLabel, SIGNAL(clicked()), this, SLOT(openFormulaDialog()));
|
||||
if(expressionOnly)
|
||||
if (expressionOnly)
|
||||
QMetaObject::invokeMethod(this, "openFormulaDialog", Qt::QueuedConnection, QGenericReturnArgument());
|
||||
}
|
||||
|
||||
@@ -1383,8 +1370,8 @@ bool ExpLineEdit::apply(const std::string& propName) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ExpLineEdit::bind(const ObjectIdentifier& _path) {
|
||||
@@ -1428,7 +1415,7 @@ void ExpLineEdit::onChange() {
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -1436,7 +1423,7 @@ void ExpLineEdit::onChange() {
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1458,7 +1445,7 @@ void ExpLineEdit::resizeEvent(QResizeEvent * event)
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
iconLabel->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
@@ -1468,7 +1455,7 @@ void ExpLineEdit::resizeEvent(QResizeEvent * event)
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
setPalette(p);
|
||||
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
|
||||
iconLabel->setExpressionText(QString());
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
|
||||
Reference in New Issue
Block a user