aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2017-03-02 13:27:30 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-03-24 06:34:16 +0000
commitb0d2e6d13358cc30f044504f83bd584606b6c235 (patch)
tree4755424f0682fc5e3050638750fa68e4ea3d148e /src
parent46002360df4e33e07c439d1cd57f3cd39895adcd (diff)
AbstractButton: add support for icons
This patch adds the following properties to AbstractButton: - icon.name - icon.source - icon.width - icon.height - icon.color Derived types implement the behavior behind these properties using the new private IconImage type. [ChangeLog][Controls][AbstractButton] Added support for icons. The following properties are now available for derived types to use: icon.name, icon.source, icon.width, icon.height, icon.color. Task-number: QTBUG-49820 Change-Id: I3b5e4eaac390543deef60883e13539646a6bb060 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/controls/doc/src/includes/qquickicon.qdocinc36
-rw-r--r--src/imports/controls/qtquickcontrols2plugin.cpp2
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp1
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp55
-rw-r--r--src/quicktemplates2/qquickabstractbutton_p.h5
-rw-r--r--src/quicktemplates2/qquickabstractbutton_p_p.h2
6 files changed, 99 insertions, 2 deletions
diff --git a/src/imports/controls/doc/src/includes/qquickicon.qdocinc b/src/imports/controls/doc/src/includes/qquickicon.qdocinc
new file mode 100644
index 00000000..1bfa0119
--- /dev/null
+++ b/src/imports/controls/doc/src/includes/qquickicon.qdocinc
@@ -0,0 +1,36 @@
+//! [grouped-properties]
+\table
+\header
+ \li Name
+ \li Description
+\row
+ \li name
+ \li This property holds the name of the icon to use.
+
+ The icon will be loaded from the platform theme. If the icon is found
+ in the theme, it will always be used; even if \l icon.source is also set.
+ If the icon is not found, \l icon.source will be used instead.
+
+ For more information on theme icons, see \l {QIcon::fromTheme()}.
+\row
+ \li source
+ \li This property holds the name of the icon to use.
+
+ The icon will be loaded as a regular image.
+
+ If \l icon.name is set and refers to a valid theme icon, it will always
+ be used instead of this property.
+\row
+ \li width
+ \li This property holds the width of the icon.
+
+ The icon's width will never exceed this value, though it will
+ shrink when necessary.
+\row
+ \li height
+ \li This property holds the height of the icon.
+
+ The icon's height will never exceed this value, though it will
+ shrink when necessary.
+\endtable
+//! [grouped-properties]
diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp
index 3a131511..084a24ba 100644
--- a/src/imports/controls/qtquickcontrols2plugin.cpp
+++ b/src/imports/controls/qtquickcontrols2plugin.cpp
@@ -153,7 +153,7 @@ void QtQuickControls2Plugin::registerTypes(const char *uri)
qmlRegisterType(selector.select(QStringLiteral("DelayButton.qml")), uri, 2, 2, "DelayButton");
qmlRegisterType(selector.select(QStringLiteral("ScrollView.qml")), uri, 2, 2, "ScrollView");
- // QtQuick.Templates 2.3 (new types and revisions in Qt 5.10)
+ // QtQuick.Controls 2.3 (new types in Qt 5.10)
qmlRegisterType<QQuickIcon>();
}
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index 6816df96..a37fa977 100644
--- a/src/imports/templates/qtquicktemplates2plugin.cpp
+++ b/src/imports/templates/qtquicktemplates2plugin.cpp
@@ -255,6 +255,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
// QtQuick.Templates 2.3 (new types and revisions in Qt 5.10)
qmlRegisterType<QQuickIcon>();
+ qmlRegisterType<QQuickAbstractButton, 3>(uri, 2, 3, "AbstractButton");
}
QT_END_NAMESPACE
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp
index 225ab9ab..0a2c7e6d 100644
--- a/src/quicktemplates2/qquickabstractbutton.cpp
+++ b/src/quicktemplates2/qquickabstractbutton.cpp
@@ -37,6 +37,7 @@
#include "qquickabstractbutton_p.h"
#include "qquickabstractbutton_p_p.h"
#include "qquickbuttongroup_p.h"
+#include "qquickicon_p.h"
#include <QtGui/qstylehints.h>
#include <QtGui/qguiapplication.h>
@@ -63,6 +64,34 @@ static const int AUTO_REPEAT_INTERVAL = 100;
radio buttons and check boxes. As an abstract control, it has no delegate
implementations, leaving them to the types that derive from it.
+ \section1 Button Icons
+
+ AbstractButton provides the following properties through which icons can
+ be set:
+
+ \list
+ \li \l icon.name
+ \li \l icon.source
+ \li \l icon.width
+ \li \l icon.height
+ \li \l icon.color
+ \endlist
+
+ For applications that target platforms that support both
+ \l {QIcon::fromTheme()}{theme icons} and regular icons,
+ both \l icon.name and \l icon.source can be set to ensure that an icon will
+ always be found. If the icon is found in the theme, it will always be used;
+ even if \l icon.source is also set. If the icon is not found,
+ \l icon.source will be used instead.
+
+ Each \l {Styling Qt Quick Controls 2}{style} sets a default size for
+ icons, but it is possible to override this by setting the \l icon.width and
+ \l icon.height properties. The image that is loaded by an icon whose
+ \c width and \c height are not set depends on the type of icon in use. For
+ theme icons, the closest available size will be chosen. For regular icons,
+ the behavior is the same as the \l {Image::}{sourceSize} property of
+ \l Image.
+
\sa ButtonGroup, {Button Controls}
*/
@@ -127,7 +156,8 @@ QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate()
repeatTimer(0),
repeatButton(Qt::NoButton),
indicator(nullptr),
- group(nullptr)
+ group(nullptr),
+ icon(nullptr)
{
}
@@ -559,6 +589,29 @@ void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
}
/*!
+ \qmlpropertygroup QtQuick.Controls::AbstractButton::icon
+ \qmlproperty string QtQuick.Controls::AbstractButton::icon.name
+ \qmlproperty string QtQuick.Controls::AbstractButton::icon.source
+ \qmlproperty int QtQuick.Controls::AbstractButton::icon.width
+ \qmlproperty int QtQuick.Controls::AbstractButton::icon.height
+ \qmlproperty color QtQuick.Controls::AbstractButton::icon.color
+
+ This property group was added in QtQuick.Controls 2.3.
+
+ \include qquickicon.qdocinc grouped-properties
+
+ \sa {Control::}{contentItem}
+*/
+
+QQuickIcon *QQuickAbstractButton::icon() const
+{
+ QQuickAbstractButtonPrivate *d = const_cast<QQuickAbstractButtonPrivate*>(d_func());
+ if (!d->icon)
+ d->icon = new QQuickIcon(const_cast<QQuickAbstractButton*>(this));
+ return d->icon;
+}
+
+/*!
\qmlmethod void QtQuick.Controls::AbstractButton::toggle()
Toggles the checked state of the button.
diff --git a/src/quicktemplates2/qquickabstractbutton_p.h b/src/quicktemplates2/qquickabstractbutton_p.h
index 28a59c00..42af6650 100644
--- a/src/quicktemplates2/qquickabstractbutton_p.h
+++ b/src/quicktemplates2/qquickabstractbutton_p.h
@@ -52,6 +52,8 @@
QT_BEGIN_NAMESPACE
+class QQuickIcon;
+
class QQuickAbstractButtonPrivate;
class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButton : public QQuickControl
@@ -64,6 +66,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButton : public QQuickContr
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL)
Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive NOTIFY autoExclusiveChanged FINAL)
Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL)
+ Q_PROPERTY(QQuickIcon *icon READ icon CONSTANT FINAL REVISION 3)
public:
explicit QQuickAbstractButton(QQuickItem *parent = nullptr);
@@ -94,6 +97,8 @@ public:
QQuickItem *indicator() const;
void setIndicator(QQuickItem *indicator);
+ QQuickIcon *icon() const;
+
public Q_SLOTS:
void toggle();
diff --git a/src/quicktemplates2/qquickabstractbutton_p_p.h b/src/quicktemplates2/qquickabstractbutton_p_p.h
index e27f5c82..388e5517 100644
--- a/src/quicktemplates2/qquickabstractbutton_p_p.h
+++ b/src/quicktemplates2/qquickabstractbutton_p_p.h
@@ -54,6 +54,7 @@
QT_BEGIN_NAMESPACE
class QQuickButtonGroup;
+class QQuickIcon;
class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButtonPrivate : public QQuickControlPrivate
{
@@ -103,6 +104,7 @@ public:
Qt::MouseButton repeatButton;
QQuickItem *indicator;
QQuickButtonGroup *group;
+ QQuickIcon *icon;
};
QT_END_NAMESPACE