aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/news.dox8
-rw-r--r--src/corelib/widgets/core/mwidget.h3
-rw-r--r--src/corelib/widgets/core/mwidgetcontroller.cpp9
-rw-r--r--src/corelib/widgets/core/mwidgetcontroller.h37
-rw-r--r--src/corelib/widgets/core/mwidgetview.cpp19
-rw-r--r--src/corelib/widgets/mwidgetmodel.h1
6 files changed, 63 insertions, 14 deletions
diff --git a/doc/src/news.dox b/doc/src/news.dox
index 52d23afc..334f7047 100644
--- a/doc/src/news.dox
+++ b/doc/src/news.dox
@@ -1,5 +1,13 @@
/*! \page news What's New in MeeGo Touch
+\section v02037 0.20.37
+
+\subsection New
+- MWidgetController::setStyleName can now be used for associating a style with a widget (like setObjectName)
+
+\subsection Deprecated
+- MWindow::setObjectName and MWidgetController:setObjectname overloaded methods, use MWidgetController::setStyleName instead.
+
\section v02036 0.20.36
\subsection New
diff --git a/src/corelib/widgets/core/mwidget.h b/src/corelib/widgets/core/mwidget.h
index ee97d973..57a6f631 100644
--- a/src/corelib/widgets/core/mwidget.h
+++ b/src/corelib/widgets/core/mwidget.h
@@ -128,7 +128,6 @@ public:
}
/*! \reimp_end */
-
public Q_SLOTS:
/*! \reimp */
/** Hide the non-virtual QObject::setObjectName() with this virtual function to catch calls to
@@ -143,6 +142,8 @@ public Q_SLOTS:
* QGraphicsWidget *label = new MLabel("Hello"); label->setObjectName("hello");
* \endcode
* Would not update the CSS style correctly.
+ *
+ * \deprecated Use MWidgetController:setStyleName instead.
*/
virtual void setObjectName(const QString &name);
diff --git a/src/corelib/widgets/core/mwidgetcontroller.cpp b/src/corelib/widgets/core/mwidgetcontroller.cpp
index 9916e3ce..1cbaf290 100644
--- a/src/corelib/widgets/core/mwidgetcontroller.cpp
+++ b/src/corelib/widgets/core/mwidgetcontroller.cpp
@@ -511,6 +511,11 @@ void MWidgetController::setObjectName(const QString &name)
model()->setObjectName(name);
}
+void MWidgetController::setStyleName(const QString &name)
+{
+ model()->setStyleName(name);
+}
+
QSizeF MWidgetController::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
Q_D(const MWidgetController);
@@ -588,6 +593,10 @@ void MWidgetController::changeEvent(QEvent *event)
}
}
+const QString &MWidgetController::styleName() const
+{
+ return model()->styleName();
+}
bool MWidgetController::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
{
diff --git a/src/corelib/widgets/core/mwidgetcontroller.h b/src/corelib/widgets/core/mwidgetcontroller.h
index d223cdec..915958e7 100644
--- a/src/corelib/widgets/core/mwidgetcontroller.h
+++ b/src/corelib/widgets/core/mwidgetcontroller.h
@@ -54,6 +54,7 @@ class M_EXPORT MWidgetController : public MWidget
Q_PROPERTY(MTheme::ViewType viewType READ viewType WRITE setViewType)
Q_PROPERTY(bool active READ isActive WRITE setActive)
+ Q_PROPERTY(QString styleName READ styleName WRITE setStyleName)
public:
/*!
@@ -146,6 +147,11 @@ public:
virtual void changeEvent(QEvent *event);
//! \reimp_end
+ /*!
+ Returns the style name of the widget.
+ */
+ const QString &styleName() const;
+
public Q_SLOTS:
/*!
Set the view type of the widget.
@@ -181,15 +187,6 @@ public Q_SLOTS:
style of the widget view. The object name is used by the theme system to select a style with
a matching ID.
- An example of setting the object name:
- \code
- mywidget->setObjectname("warning");
- \endcode
- In a CSS file you can then specify a style for this particular widget:
- \code
- #warning { background-color: #FF0000; }
- \endcode
-
Warning: Since QObject::setObjectName() is non-virtual, code like:
\code
MLabel *label = new MLabel("Hello");
@@ -203,9 +200,31 @@ public Q_SLOTS:
Would not update the CSS style correctly.
Note that multiple objects can have the same name, and consequently the same style.
+
+ \deprecated Use setStyleName() to set the style name of the widget.
*/
virtual void setObjectName(const QString &name);
+ /*!
+ Set the style name to \a name.
+
+ This function sets the style name property of the widget to \a name and reloads the
+ style of the widget view. The style name is used to select a style with a matching
+ name from the theme.
+
+ An example of setting the object name:
+ \code
+ mywidget->setStyleName("warning");
+ \endcode
+ In a CSS file you can then specify a style for this particular widget:
+ \code
+ #warning { background-color: #FF0000; }
+ \endcode
+
+ \sa styleName()
+ */
+ void setStyleName(const QString &name);
+
protected Q_SLOTS:
/*!
Notification of model data modifications.
diff --git a/src/corelib/widgets/core/mwidgetview.cpp b/src/corelib/widgets/core/mwidgetview.cpp
index c7318f7e..572787c7 100644
--- a/src/corelib/widgets/core/mwidgetview.cpp
+++ b/src/corelib/widgets/core/mwidgetview.cpp
@@ -147,7 +147,12 @@ void MWidgetView::setModel(MWidgetModel *model)
if (styleType == MWidgetController::defaultType)
styleType.clear();
- d->styleContainer->initialize(d->model->objectName(), styleType, parent);
+ QString styleName;
+ if (d->model->styleName().isNull())
+ styleName = d->model->objectName(); // fallback to old behavior
+ else
+ styleName = d->model->styleName();
+ d->styleContainer->initialize(styleName, styleType, parent);
if (d->controller->isActive()) {
setActive(true);
@@ -168,9 +173,15 @@ void MWidgetView::updateData(const QList<const char *>& modifications)
{
const char *member;
foreach(member, modifications) {
- if (member == MWidgetModel::ObjectName) {
- // object name has changed, we need to update style
- style().setObjectName(model()->objectName());
+ if (member == MWidgetModel::ObjectName ||
+ member == MWidgetModel::StyleName) {
+ // style name has changed, we need to update the style
+ QString styleName(QString::null);
+ if (model()->styleName().isNull())
+ styleName = model()->objectName(); // fallback to old behavior
+ else
+ styleName = model()->styleName();
+ style().setObjectName(styleName);
// TODO: to be removed
applyStyle();
} else if (member == MWidgetModel::ViewType) {
diff --git a/src/corelib/widgets/mwidgetmodel.h b/src/corelib/widgets/mwidgetmodel.h
index 105755d6..7a107587 100644
--- a/src/corelib/widgets/mwidgetmodel.h
+++ b/src/corelib/widgets/mwidgetmodel.h
@@ -112,6 +112,7 @@ class M_EXPORT MWidgetModel : public QObject
Q_OBJECT
M_MODEL_WITH_PRIVATE(MWidgetModel)
M_MODEL_PROPERTY(QString, objectName, ObjectName, true, QString::null)
+ M_MODEL_PROPERTY(QString, styleName, StyleName, true, QString::null)
M_MODEL_PROPERTY(MTheme::ViewType, viewType, ViewType, true, MWidgetController::defaultType)
M_MODEL_PROPERTY(QPointF, position, Position, true, QPointF(0.0, 0.0))
M_MODEL_PROPERTY(QSizeF, size, Size, true, QSizeF(0.0, 0.0))