Gui: split icon handling from ExpressionBinding

This commit is contained in:
wmayer
2023-03-08 14:07:10 +01:00
committed by wwmayer
parent baf5a51e1a
commit 296683e113
6 changed files with 46 additions and 32 deletions

View File

@@ -48,9 +48,7 @@ using namespace App;
namespace bp = boost::placeholders;
ExpressionBinding::ExpressionBinding()
: iconLabel(nullptr)
, iconHeight(-1)
, m_autoApply(false)
: m_autoApply(false)
{
}
@@ -190,22 +188,6 @@ bool ExpressionBinding::assignToProperty(const std::string & propName, double va
return true;
}
QPixmap ExpressionBinding::getIcon(const char* name, const QSize& size) const
{
QString key = QString::fromLatin1("%1_%2x%3")
.arg(QString::fromLatin1(name))
.arg(size.width())
.arg(size.height());
QPixmap icon;
if (QPixmapCache::find(key, &icon))
return icon;
icon = BitmapFactory().pixmapFromSvg(name, size);
if (!icon.isNull())
QPixmapCache::insert(key, icon);
return icon;
}
bool ExpressionBinding::apply(const std::string & propName)
{
Q_UNUSED(propName);
@@ -294,7 +276,32 @@ void ExpressionBinding::objectDeleted(const App::DocumentObject& obj)
}
}
void ExpressionBinding::makeLabel(QLineEdit* le)
// ----------------------------------------------------------------------------
ExpressionWidget::ExpressionWidget()
: iconLabel(nullptr)
, iconHeight(-1)
{
}
QPixmap ExpressionWidget::getIcon(const char* name, const QSize& size) const
{
QString key = QString::fromLatin1("%1_%2x%3")
.arg(QString::fromLatin1(name))
.arg(size.width())
.arg(size.height());
QPixmap icon;
if (QPixmapCache::find(key, &icon))
return icon;
icon = BitmapFactory().pixmapFromSvg(name, size);
if (!icon.isNull())
QPixmapCache::insert(key, icon);
return icon;
}
void ExpressionWidget::makeLabel(QLineEdit* le)
{
defaultPalette = le->palette();

View File

@@ -53,8 +53,6 @@ public:
virtual bool apply();
bool hasExpression() const;
QPixmap getIcon(const char *name, const QSize &size) const;
//auto apply means that the python code is issued not only on apply() but
//also on setExpression
bool autoApply() const {return m_autoApply;}
@@ -71,17 +69,11 @@ 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:
ExpressionLabel* iconLabel;
QPalette defaultPalette;
int iconHeight;
void expressionChange(const App::ObjectIdentifier& id);
void objectDeleted(const App::DocumentObject&);
boost::signals2::scoped_connection expressionchanged;
@@ -89,6 +81,21 @@ protected:
bool m_autoApply;
};
class GuiExport ExpressionWidget : public ExpressionBinding
{
public:
ExpressionWidget();
QPixmap getIcon(const char *name, const QSize &size) const;
protected:
void makeLabel(QLineEdit* parent);
protected:
ExpressionLabel* iconLabel;
QPalette defaultPalette;
int iconHeight;
};
}
#endif // EXPRESSIONBINDING_H

View File

@@ -69,7 +69,7 @@ private:
InputField::InputField(QWidget * parent)
: ExpressionLineEdit(parent),
ExpressionBinding(),
ExpressionWidget(),
validInput(true),
actUnitValue(0),
Maximum(DOUBLE_MAX),

View File

@@ -55,7 +55,7 @@ namespace Gui {
* of a spin box.
* \author Jürgen Riegel
*/
class GuiExport InputField : public ExpressionLineEdit, public ExpressionBinding
class GuiExport InputField : public ExpressionLineEdit, public ExpressionWidget
{
Q_OBJECT

View File

@@ -36,7 +36,7 @@ class NumberExpression;
namespace Gui {
class GuiExport ExpressionSpinBox : public ExpressionBinding
class GuiExport ExpressionSpinBox : public ExpressionWidget
{
public:
explicit ExpressionSpinBox(QAbstractSpinBox*);

View File

@@ -572,7 +572,7 @@ private:
* The ExpLineEdit class provides a lineedit that support expressing binding.
* \author realthunder
*/
class GuiExport ExpLineEdit : public QLineEdit, public ExpressionBinding
class GuiExport ExpLineEdit : public QLineEdit, public ExpressionWidget
{
Q_OBJECT