summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-05-22 09:39:52 +0200
committerDavid Faure <david.faure@kdab.com>2015-08-18 12:47:17 +0000
commit4dccb2ca674e9eafca65da0775254932102c7f4b (patch)
tree4cff9d475ae8b281f6a80e6915ee97a119b76662 /src/widgets/widgets
parentba84e346b8a3eba6686fa18e1ef546def98073fa (diff)
Handle action events in QLineEditIconButton.
Ensure QAction::setVisible() is handled and reposition if visibility changes. Task-number: QTBUG-39660 Change-Id: I14f0659aedc8dc89ddef3159d3a500b40b1563ff Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp24
-rw-r--r--src/widgets/widgets/qlineedit_p.h16
2 files changed, 36 insertions, 4 deletions
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 3f768bfbd3..6645a375a7 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -324,6 +324,24 @@ void QLineEditIconButton::paintEvent(QPaintEvent *)
painter.drawPixmap(pixmapRect, iconPixmap);
}
+void QLineEditIconButton::actionEvent(QActionEvent *e)
+{
+ switch (e->type()) {
+ case QEvent::ActionChanged: {
+ const QAction *action = e->action();
+ if (isVisible() != action->isVisible()) {
+ setVisible(action->isVisible());
+ if (QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget()))
+ static_cast<QLineEditPrivate *>(qt_widget_private(le))->positionSideWidgets();
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ QToolButton::actionEvent(e);
+}
+
void QLineEditIconButton::setOpacity(qreal value)
{
if (!qFuzzyCompare(m_opacity, value)) {
@@ -415,12 +433,14 @@ void QLineEditPrivate::positionSideWidgets()
QRect widgetGeometry(QPoint(QLineEditIconButton::IconMargin, (contentRect.height() - iconSize.height()) / 2), iconSize);
foreach (const SideWidgetEntry &e, leftSideWidgetList()) {
e.widget->setGeometry(widgetGeometry);
- widgetGeometry.moveLeft(widgetGeometry.left() + delta);
+ if (e.widget->isVisible())
+ widgetGeometry.moveLeft(widgetGeometry.left() + delta);
}
widgetGeometry.moveLeft(contentRect.width() - iconSize.width() - QLineEditIconButton::IconMargin);
foreach (const SideWidgetEntry &e, rightSideWidgetList()) {
e.widget->setGeometry(widgetGeometry);
- widgetGeometry.moveLeft(widgetGeometry.left() - delta);
+ if (e.widget->isVisible())
+ widgetGeometry.moveLeft(widgetGeometry.left() - delta);
}
}
}
diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h
index 4654262ea7..5a22285149 100644
--- a/src/widgets/widgets/qlineedit_p.h
+++ b/src/widgets/widgets/qlineedit_p.h
@@ -61,6 +61,8 @@
#include "private/qwidgetlinecontrol_p.h"
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
// QLineEditIconButton: This is a simple helper class that represents clickable icons that fade in with text
@@ -81,6 +83,7 @@ public:
#endif
protected:
+ void actionEvent(QActionEvent *e) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private slots:
@@ -226,14 +229,23 @@ private:
mutable QSize m_iconSize;
};
+static bool isSideWidgetVisible(const QLineEditPrivate::SideWidgetEntry &e)
+{
+ return e.widget->isVisible();
+}
+
inline int QLineEditPrivate::effectiveLeftTextMargin() const
{
- return leftTextMargin + leftSideWidgetList().size() * (QLineEditIconButton::IconMargin + iconSize().width());
+ return leftTextMargin + (QLineEditIconButton::IconMargin + iconSize().width())
+ * int(std::count_if(leftSideWidgetList().constBegin(), leftSideWidgetList().constEnd(),
+ isSideWidgetVisible));
}
inline int QLineEditPrivate::effectiveRightTextMargin() const
{
- return rightTextMargin + rightSideWidgetList().size() * (QLineEditIconButton::IconMargin + iconSize().width());
+ return rightTextMargin + (QLineEditIconButton::IconMargin + iconSize().width())
+ * int(std::count_if(rightSideWidgetList().constBegin(), rightSideWidgetList().constEnd(),
+ isSideWidgetVisible));
}
#endif // QT_NO_LINEEDIT