From 913d891b8a7ceeb158b764437c7ba259c76e00e9 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 19 May 2010 21:45:08 +0000 Subject: [PATCH] the widgets that accept input sets their applet status as accepting input as well. it pretty ugly and duplicated code but doing it at this level is the only way to reliably set the proper status svn path=/trunk/KDE/kdelibs/; revision=1128660 --- widgets/combobox.cpp | 30 +++++++++++++++++++++++++++++- widgets/combobox.h | 1 + widgets/lineedit.cpp | 33 +++++++++++++++++++++++++++++++++ widgets/lineedit.h | 2 ++ widgets/spinbox.cpp | 31 +++++++++++++++++++++++++++++++ widgets/spinbox.h | 2 ++ widgets/textedit.cpp | 33 +++++++++++++++++++++++++++++++++ widgets/textedit.h | 2 ++ 8 files changed, 133 insertions(+), 1 deletion(-) diff --git a/widgets/combobox.cpp b/widgets/combobox.cpp index 36ac7dd9a..20c9e254e 100644 --- a/widgets/combobox.cpp +++ b/widgets/combobox.cpp @@ -29,6 +29,7 @@ #include #include +#include "applet.h" #include "theme.h" #include "framesvg.h" #include "animator.h" @@ -268,7 +269,18 @@ void ComboBox::focusInEvent(QFocusEvent *event) void ComboBox::focusOutEvent(QFocusEvent *event) { - QGraphicsProxyWidget::focusInEvent(event); + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::UnknownStatus); + } + QGraphicsProxyWidget::focusOutEvent(event); } void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event) @@ -293,6 +305,22 @@ void ComboBox::changeEvent(QEvent *event) QGraphicsProxyWidget::changeEvent(event); } +void ComboBox::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::AcceptingInputStatus); + } + QGraphicsProxyWidget::mousePressEvent(event); +} + } // namespace Plasma #include diff --git a/widgets/combobox.h b/widgets/combobox.h index 85e40d52e..a1b34a685 100644 --- a/widgets/combobox.h +++ b/widgets/combobox.h @@ -112,6 +112,7 @@ protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void changeEvent(QEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); private: diff --git a/widgets/lineedit.cpp b/widgets/lineedit.cpp index 08578f84f..a467d5ddb 100644 --- a/widgets/lineedit.cpp +++ b/widgets/lineedit.cpp @@ -29,6 +29,7 @@ #include #include +#include "applet.h" #include "theme.h" #include "svg.h" #include "framesvg.h" @@ -179,6 +180,38 @@ void LineEdit::changeEvent(QEvent *event) QGraphicsProxyWidget::changeEvent(event); } +void LineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::AcceptingInputStatus); + } + QGraphicsProxyWidget::mousePressEvent(event); +} + +void LineEdit::focusOutEvent(QFocusEvent *event) +{ + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::UnknownStatus); + } + QGraphicsProxyWidget::focusOutEvent(event); +} + } // namespace Plasma #include diff --git a/widgets/lineedit.h b/widgets/lineedit.h index b6cd06806..1af59a64c 100644 --- a/widgets/lineedit.h +++ b/widgets/lineedit.h @@ -104,6 +104,8 @@ protected: void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void changeEvent(QEvent *event); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void focusOutEvent(QFocusEvent *event); Q_SIGNALS: void editingFinished(); diff --git a/widgets/spinbox.cpp b/widgets/spinbox.cpp index cb9a93a5c..3f9436f1e 100644 --- a/widgets/spinbox.cpp +++ b/widgets/spinbox.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -198,7 +199,37 @@ void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q QGraphicsProxyWidget::paint(painter, option, widget); } +void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::AcceptingInputStatus); + } + QGraphicsProxyWidget::mousePressEvent(event); +} + +void SpinBox::focusOutEvent(QFocusEvent *event) +{ + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::UnknownStatus); + } + QGraphicsProxyWidget::focusOutEvent(event); +} } // namespace Plasma diff --git a/widgets/spinbox.h b/widgets/spinbox.h index 97f25d1a5..fdced70ef 100644 --- a/widgets/spinbox.h +++ b/widgets/spinbox.h @@ -90,6 +90,8 @@ protected: void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void resizeEvent(QGraphicsSceneResizeEvent *event); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void focusOutEvent(QFocusEvent *event); public Q_SLOTS: /** diff --git a/widgets/textedit.cpp b/widgets/textedit.cpp index aefeb46cf..e7e6090ca 100644 --- a/widgets/textedit.cpp +++ b/widgets/textedit.cpp @@ -27,6 +27,7 @@ #include #include +#include "applet.h" #include "theme.h" #include "svg.h" #include "private/style_p.h" @@ -184,6 +185,38 @@ void TextEdit::changeEvent(QEvent *event) QGraphicsProxyWidget::changeEvent(event); } +void TextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::AcceptingInputStatus); + } + QGraphicsProxyWidget::mousePressEvent(event); +} + +void TextEdit::focusOutEvent(QFocusEvent *event) +{ + QGraphicsWidget *widget = parentWidget(); + Plasma::Applet *applet = qobject_cast(widget); + + while (!applet && widget) { + widget = widget->parentWidget(); + applet = qobject_cast(widget); + } + + if (applet) { + applet->setStatus(Plasma::UnknownStatus); + } + QGraphicsProxyWidget::focusOutEvent(event); +} + } // namespace Plasma #include diff --git a/widgets/textedit.h b/widgets/textedit.h index 335a265b7..1c4e4b8f6 100644 --- a/widgets/textedit.h +++ b/widgets/textedit.h @@ -116,6 +116,8 @@ protected: void resizeEvent(QGraphicsSceneResizeEvent *event); void changeEvent(QEvent *event); void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void focusOutEvent(QFocusEvent *event); private: TextEditPrivate * const d;