Add tooltip to f(x) when there is no expression

As suggested by @luzpaz, this adds a tooltip to the f(x) icon of all
of the widgets that use it: QuantitySpinBox, UIntSpinBox, IntSpinBox,
DoubleSpinBox, and ExpLineEdit. These five classes are divided across
three files, and all five classes duplicate the same basic code. In the
existing code, no tooltip is shown if there is no expression. If there
is an expression, it (alone) is used as the tooltip.

This commit modifies that behavior to have explanatory text as the
tooltip when there is no expression, and when there is, to prepend a
short string to the beginning.

To reduce further code duplication, this is implemented by adding a new
function to ExpressionLabel allowing the text of the expression to be set.
It checks that text and if it's empty, uses a preset default string as the
tooltip. If there is expression text, it instead prepends another
bit of text to the front and sets the entire expression+prefix as the
tooltip.

TODO: In the future a lot of the preexisting code duplication could be
removed by making the ExpressionLabel class do more internal management
of the expression.

Thanks to @kisolre for the assistance tracking these down, and
suggesting the default text used.
This commit is contained in:
Chris Hennes
2021-02-03 16:12:05 -06:00
committed by wwmayer
parent 8de66e134f
commit b34acb8b31
4 changed files with 38 additions and 20 deletions

View File

@@ -312,6 +312,7 @@ QuantitySpinBox::QuantitySpinBox(QWidget *parent)
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
@@ -447,7 +448,7 @@ void Gui::QuantitySpinBox::onChange()
p.setColor(QPalette::Text, Qt::lightGray);
lineEdit()->setPalette(p);
}
iconLabel->setToolTip(Base::Tools::fromStdString(getExpression()->toString()));
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
}
else {
setReadOnly(false);
@@ -456,7 +457,7 @@ void Gui::QuantitySpinBox::onChange()
QPalette p(lineEdit()->palette());
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
lineEdit()->setPalette(p);
iconLabel->setToolTip(QString());
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
}
}
@@ -511,7 +512,7 @@ void QuantitySpinBox::resizeEvent(QResizeEvent * event)
p.setColor(QPalette::Text, Qt::lightGray);
lineEdit()->setPalette(p);
}
iconLabel->setToolTip(Base::Tools::fromStdString(getExpression()->toString()));
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(Base::Tools::fromStdString(getExpression()->toString()));
}
else {
setReadOnly(false);
@@ -521,7 +522,7 @@ void QuantitySpinBox::resizeEvent(QResizeEvent * event)
QPalette p(lineEdit()->palette());
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
lineEdit()->setPalette(p);
iconLabel->setToolTip(QString());
static_cast<ExpressionLabel*>(iconLabel)->setExpressionText(QString());
}
}
catch (const Base::Exception & e) {