summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qlineedit.cpp1
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp59
-rw-r--r--src/widgets/widgets/qlineedit_p.h15
-rw-r--r--src/widgets/widgets/qmenubar.cpp55
-rw-r--r--src/widgets/widgets/qmenubar_p.h3
5 files changed, 84 insertions, 49 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 7ccf28034b..56965923b7 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -2188,7 +2188,6 @@ void QLineEdit::changeEvent(QEvent *ev)
d->control->setPasswordCharacter(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this));
d->control->setPasswordMaskDelay(style()->styleHint(QStyle::SH_LineEdit_PasswordMaskDelay, &opt, this));
}
- d->m_iconSize = QSize();
update();
break;
case QEvent::LayoutDirectionChange:
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 3d8a854753..7da1d911ee 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -320,6 +320,12 @@ QLineEditIconButton::QLineEditIconButton(QWidget *parent)
setFocusPolicy(Qt::NoFocus);
}
+QLineEditPrivate *QLineEditIconButton::lineEditPrivate() const
+{
+ QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget());
+ return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : Q_NULLPTR;
+}
+
void QLineEditIconButton::paintEvent(QPaintEvent *)
{
QPainter painter(this);
@@ -331,7 +337,9 @@ void QLineEditIconButton::paintEvent(QPaintEvent *)
QIcon::Mode state = QIcon::Disabled;
if (isEnabled())
state = isDown() ? QIcon::Selected : QIcon::Normal;
- const QSize iconSize(IconButtonSize, IconButtonSize);
+ const QLineEditPrivate *lep = lineEditPrivate();
+ const int iconWidth = lep ? lep->sideWidgetParameters().iconSize : 16;
+ const QSize iconSize(iconWidth, iconWidth);
const QPixmap iconPixmap = icon().pixmap(window, iconSize, state, QIcon::Off);
QRect pixmapRect = QRect(QPoint(0, 0), iconSize);
pixmapRect.moveCenter(rect().center());
@@ -346,8 +354,8 @@ void QLineEditIconButton::actionEvent(QActionEvent *e)
const QAction *action = e->action();
if (isVisibleTo(parentWidget()) != action->isVisible()) {
setVisible(action->isVisible());
- if (QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget()))
- static_cast<QLineEditPrivate *>(qt_widget_private(le))->positionSideWidgets();
+ if (QLineEditPrivate *lep = lineEditPrivate())
+ lep->positionSideWidgets();
}
}
break;
@@ -413,11 +421,15 @@ void QLineEditPrivate::_q_clearButtonClicked()
}
}
-QSize QLineEditPrivate::iconSize() const
+QLineEditPrivate::SideWidgetParameters QLineEditPrivate::sideWidgetParameters() const
{
- if (!m_iconSize.isValid()) // This might require style-specific handling (pixel metric).
- m_iconSize = QSize(QLineEditIconButton::IconButtonSize + 6, QLineEditIconButton::IconButtonSize + 2);
- return m_iconSize;
+ Q_Q(const QLineEdit);
+ SideWidgetParameters result;
+ result.iconSize = q->height() < 34 ? 16 : 32;
+ result.margin = result.iconSize / 4;
+ result.widgetWidth = result.iconSize + 6;
+ result.widgetHeight = result.iconSize + 2;
+ return result;
}
QIcon QLineEditPrivate::clearButtonIcon() const
@@ -443,15 +455,16 @@ void QLineEditPrivate::positionSideWidgets()
Q_Q(QLineEdit);
if (hasSideWidgets()) {
const QRect contentRect = q->rect();
- const QSize iconSize = QLineEditPrivate::iconSize();
- const int delta = QLineEditIconButton::IconMargin + iconSize.width();
- QRect widgetGeometry(QPoint(QLineEditIconButton::IconMargin, (contentRect.height() - iconSize.height()) / 2), iconSize);
+ const SideWidgetParameters p = sideWidgetParameters();
+ const int delta = p.margin + p.widgetWidth;
+ QRect widgetGeometry(QPoint(p.margin, (contentRect.height() - p.widgetHeight) / 2),
+ QSize(p.widgetWidth, p.widgetHeight));
for (const SideWidgetEntry &e : leftSideWidgetList()) {
e.widget->setGeometry(widgetGeometry);
if (e.action->isVisible())
widgetGeometry.moveLeft(widgetGeometry.left() + delta);
}
- widgetGeometry.moveLeft(contentRect.width() - iconSize.width() - QLineEditIconButton::IconMargin);
+ widgetGeometry.moveLeft(contentRect.width() - p.widgetWidth - p.margin);
for (const SideWidgetEntry &e : rightSideWidgetList()) {
e.widget->setGeometry(widgetGeometry);
if (e.action->isVisible())
@@ -539,18 +552,26 @@ static bool isSideWidgetVisible(const QLineEditPrivate::SideWidgetEntry &e)
int QLineEditPrivate::effectiveLeftTextMargin() const
{
- const auto &list = leftSideWidgetList();
- return leftTextMargin + (QLineEditIconButton::IconMargin + iconSize().width())
- * int(std::count_if(list.begin(), list.end(),
- isSideWidgetVisible));
+ int result = leftTextMargin;
+ if (!leftSideWidgetList().empty()) {
+ const SideWidgetParameters p = sideWidgetParameters();
+ result += (p.margin + p.widgetWidth)
+ * int(std::count_if(leftSideWidgetList().begin(), leftSideWidgetList().end(),
+ isSideWidgetVisible));
+ }
+ return result;
}
int QLineEditPrivate::effectiveRightTextMargin() const
{
- const auto &list = rightSideWidgetList();
- return rightTextMargin + (QLineEditIconButton::IconMargin + iconSize().width())
- * int(std::count_if(list.begin(), list.end(),
- isSideWidgetVisible));
+ int result = rightTextMargin;
+ if (!rightSideWidgetList().empty()) {
+ const SideWidgetParameters p = sideWidgetParameters();
+ result += (p.margin + p.widgetWidth)
+ * int(std::count_if(rightSideWidgetList().begin(), rightSideWidgetList().end(),
+ isSideWidgetVisible));
+ }
+ return result;
}
diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h
index 12a4299204..a14cd66398 100644
--- a/src/widgets/widgets/qlineedit_p.h
+++ b/src/widgets/widgets/qlineedit_p.h
@@ -71,6 +71,8 @@
QT_BEGIN_NAMESPACE
+class QLineEditPrivate;
+
// QLineEditIconButton: This is a simple helper class that represents clickable icons that fade in with text
class Q_AUTOTEST_EXPORT QLineEditIconButton : public QToolButton
@@ -78,8 +80,6 @@ class Q_AUTOTEST_EXPORT QLineEditIconButton : public QToolButton
Q_OBJECT
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
public:
- enum { IconMargin = 4, IconButtonSize = 16 };
-
explicit QLineEditIconButton(QWidget *parent = 0);
qreal opacity() const { return m_opacity; }
@@ -99,6 +99,7 @@ private:
#ifndef QT_NO_ANIMATION
void startOpacityAnimation(qreal endValue);
#endif
+ QLineEditPrivate *lineEditPrivate() const;
qreal m_opacity;
};
@@ -122,6 +123,13 @@ public:
};
typedef std::vector<SideWidgetEntry> SideWidgetEntryList;
+ struct SideWidgetParameters {
+ int iconSize;
+ int widgetWidth;
+ int widgetHeight;
+ int margin;
+ };
+
QLineEditPrivate()
: control(0), frame(1), contextMenuEnabled(1), cursorVisible(0),
dragEnabled(0), clickCausedFocus(0), hscroll(0), vscroll(0),
@@ -212,7 +220,7 @@ public:
QWidget *addAction(QAction *newAction, QAction *before, QLineEdit::ActionPosition, int flags = 0);
void removeAction(QAction *action);
- QSize iconSize() const;
+ SideWidgetParameters sideWidgetParameters() const;
QIcon clearButtonIcon() const;
void setClearButtonEnabled(bool enabled);
void positionSideWidgets();
@@ -233,7 +241,6 @@ private:
SideWidgetEntryList leadingSideWidgets;
SideWidgetEntryList trailingSideWidgets;
int lastTextSize;
- mutable QSize m_iconSize;
};
Q_DECLARE_TYPEINFO(QLineEditPrivate::SideWidgetEntry, Q_PRIMITIVE_TYPE);
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index 85d0c54357..bf523a3a70 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -712,7 +712,6 @@ void QMenuBarPrivate::init()
}
#endif
q->setBackgroundRole(QPalette::Button);
- oldWindow = oldParent = 0;
handleReparent();
q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q));
@@ -1343,30 +1342,41 @@ void QMenuBarPrivate::handleReparent()
{
Q_Q(QMenuBar);
QWidget *newParent = q->parentWidget();
- //Note: if parent is reparented, then window may change even if parent doesn't
- // we need to install an event filter on parent, and remove the old one
-
- if (oldParent != newParent) {
- if (oldParent)
- oldParent->removeEventFilter(q);
- if (newParent)
- newParent->installEventFilter(q);
+ //Note: if parent is reparented, then window may change even if parent doesn't.
+ // We need to install an avent filter on each parent up to the parent that is
+ // also a window (for shortcuts)
+ QWidget *newWindow = newParent ? newParent->window() : Q_NULLPTR;
+
+ QVector<QPointer<QWidget> > newParents;
+ // Remove event filters on ex-parents, keep them on still-parents
+ // The parents are always ordered in the vector
+ foreach (const QPointer<QWidget> &w, oldParents) {
+ if (w) {
+ if (newParent == w) {
+ newParents.append(w);
+ if (newParent != newWindow) //stop at the window
+ newParent = newParent->parentWidget();
+ } else {
+ w->removeEventFilter(q);
+ }
+ }
}
- //we also need event filter on top-level (for shortcuts)
- QWidget *newWindow = newParent ? newParent->window() : 0;
-
- if (oldWindow != newWindow) {
- if (oldParent && oldParent != oldWindow)
- oldWindow->removeEventFilter(q);
-
- if (newParent && newParent != newWindow)
- newWindow->installEventFilter(q);
+ // At this point, newParent is the next one to be added to newParents
+ while (newParent && newParent != newWindow) {
+ //install event filters all the way up to (excluding) the window
+ newParents.append(newParent);
+ newParent->installEventFilter(q);
+ newParent = newParent->parentWidget();
}
- oldParent = newParent;
- oldWindow = newWindow;
+ if (newParent && newWindow) {
+ // Install the event filter on the window
+ newParents.append(newParent);
+ newParent->installEventFilter(q);
+ }
+ oldParents = newParents;
if (platformMenuBar) {
if (newWindow) {
@@ -1478,10 +1488,9 @@ bool QMenuBar::event(QEvent *e)
bool QMenuBar::eventFilter(QObject *object, QEvent *event)
{
Q_D(QMenuBar);
- if (object == parent() && object) {
- if (event->type() == QEvent::ParentChange) //GrandparentChange
+ if (object && (event->type() == QEvent::ParentChange)) //GrandparentChange
d->handleReparent();
- }
+
if (object == d->leftWidget || object == d->rightWidget) {
switch (event->type()) {
case QEvent::ShowToParent:
diff --git a/src/widgets/widgets/qmenubar_p.h b/src/widgets/widgets/qmenubar_p.h
index 05b1878c20..c88e4af836 100644
--- a/src/widgets/widgets/qmenubar_p.h
+++ b/src/widgets/widgets/qmenubar_p.h
@@ -134,8 +134,7 @@ public:
// reparenting
void handleReparent();
- QWidget *oldParent;
- QWidget *oldWindow;
+ QVector<QPointer<QWidget> > oldParents;
QList<QAction*> hiddenActions;
//default action