diff options
Diffstat (limited to 'src/controls')
68 files changed, 7885 insertions, 0 deletions
diff --git a/src/controls/controls.pri b/src/controls/controls.pri new file mode 100644 index 00000000..af2b7b8c --- /dev/null +++ b/src/controls/controls.pri @@ -0,0 +1,64 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qquickabstractapplicationwindow_p.h \ + $$PWD/qquickabstractbusyindicator_p.h \ + $$PWD/qquickabstractbutton_p.h \ + $$PWD/qquickabstractbutton_p_p.h \ + $$PWD/qquickabstractcheckable_p.h \ + $$PWD/qquickabstractcheckable_p_p.h \ + $$PWD/qquickabstractcheckbox_p.h \ + $$PWD/qquickabstractcontainer_p.h \ + $$PWD/qquickabstractcontainer_p_p.h \ + $$PWD/qquickabstractframe_p.h \ + $$PWD/qquickabstractgroupbox_p.h \ + $$PWD/qquickabstractpageindicator_p.h \ + $$PWD/qquickabstractprogressbar_p.h \ + $$PWD/qquickabstractradiobutton_p.h \ + $$PWD/qquickabstractscrollbar_p.h \ + $$PWD/qquickabstractscrollindicator_p.h \ + $$PWD/qquickabstractslider_p.h \ + $$PWD/qquickabstractspinbox_p.h \ + $$PWD/qquickabstractstackview_p.h \ + $$PWD/qquickabstractswitch_p.h \ + $$PWD/qquickabstracttabbar_p.h \ + $$PWD/qquickabstracttabbutton_p.h \ + $$PWD/qquickabstracttabview_p.h \ + $$PWD/qquickabstracttextarea_p.h \ + $$PWD/qquickabstracttextfield_p.h \ + $$PWD/qquickabstracttogglebutton_p.h \ + $$PWD/qquickabstracttoolbar_p.h \ + $$PWD/qquickcontrol_p.h \ + $$PWD/qquickcontrol_p_p.h \ + $$PWD/qquickexclusivegroup_p.h \ + $$PWD/qquickpadding_p.h \ + $$PWD/qquickstyle_p.h + +SOURCES += \ + $$PWD/qquickabstractapplicationwindow.cpp \ + $$PWD/qquickabstractbusyindicator.cpp \ + $$PWD/qquickabstractbutton.cpp \ + $$PWD/qquickabstractcheckable.cpp \ + $$PWD/qquickabstractcheckbox.cpp \ + $$PWD/qquickabstractcontainer.cpp \ + $$PWD/qquickabstractframe.cpp \ + $$PWD/qquickabstractgroupbox.cpp \ + $$PWD/qquickabstractpageindicator.cpp \ + $$PWD/qquickabstractprogressbar.cpp \ + $$PWD/qquickabstractradiobutton.cpp \ + $$PWD/qquickabstractscrollbar.cpp \ + $$PWD/qquickabstractscrollindicator.cpp \ + $$PWD/qquickabstractslider.cpp \ + $$PWD/qquickabstractspinbox.cpp \ + $$PWD/qquickabstractstackview.cpp \ + $$PWD/qquickabstractswitch.cpp \ + $$PWD/qquickabstracttabbar.cpp \ + $$PWD/qquickabstracttabbutton.cpp \ + $$PWD/qquickabstracttabview.cpp \ + $$PWD/qquickabstracttextarea.cpp \ + $$PWD/qquickabstracttextfield.cpp \ + $$PWD/qquickabstracttogglebutton.cpp \ + $$PWD/qquickabstracttoolbar.cpp \ + $$PWD/qquickcontrol.cpp \ + $$PWD/qquickexclusivegroup.cpp \ + $$PWD/qquickstyle.cpp diff --git a/src/controls/controls.pro b/src/controls/controls.pro new file mode 100644 index 00000000..c4a1ff87 --- /dev/null +++ b/src/controls/controls.pro @@ -0,0 +1,22 @@ +TARGET = QtQuickControls +MODULE = quickcontrols +CONFIG += internal_module + +QT += quick +QT += core-private gui-private qml-private quick-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +QMAKE_DOCS = $$PWD/doc/qtquickcontrols2.qdocconf + +HEADERS += \ + $$PWD/qtquickcontrolsglobal_p.h + +OTHER_FILES += \ + $$PWD/style.json + +RESOURCES += \ + $$PWD/controls.qrc + +include(controls.pri) +load(qt_module) diff --git a/src/controls/controls.qrc b/src/controls/controls.qrc new file mode 100644 index 00000000..c1dded8a --- /dev/null +++ b/src/controls/controls.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/qtquickcontrols"> + <file>style.json</file> +</qresource> +</RCC> diff --git a/src/controls/doc/qtquickcontrols2.qdocconf b/src/controls/doc/qtquickcontrols2.qdocconf new file mode 100644 index 00000000..993493d5 --- /dev/null +++ b/src/controls/doc/qtquickcontrols2.qdocconf @@ -0,0 +1,42 @@ +include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) + +project = QtQuickControls2 +description = Qt Quick Controls 2 Reference Documentation +version = $QT_VERSION + +qhp.projects = QtQuickControls2 + +qhp.QtQuickControls2.file = qtquickcontrols2.qhp +qhp.QtQuickControls2.namespace = org.qt-project.qtquickcontrols2.$QT_VERSION_TAG +qhp.QtQuickControls2.virtualFolder = qtquickcontrols2 +qhp.QtQuickControls2.indexTitle = Qt Quick Controls 2 +qhp.QtQuickControls2.indexRoot = + +qhp.QtQuickControls2.filterAttributes = qtquickcontrols2 $QT_VERSION qtrefdoc +qhp.QtQuickControls2.customFilters.Qt.name = QtQuickControls2 $QT_VERSION +qhp.QtQuickControls2.customFilters.Qt.filterAttributes = qtquickcontrols2 $QT_VERSION + +qhp.QtQuickControls2.subprojects = qtquickcontrols2qmltypes + +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.title = Controls 2 QML Types +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.indexTitle = Qt Quick Controls 2 QML Types +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.selectors = qmlclass # cannot choose qmltypes from a specific group QTBUG-32985 +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.sortPages = true + +depends = qtcore qtgui qtdoc qtqml qtquick qtquicklayouts qtquickdialogs + +# Specify the install path under QT_INSTALL_EXAMPLES +# Examples will be installed under quick/controls - 'controls' subdirectory +# is given as part of \example commands +exampledirs += ../../../examples/quick/controls +examplesinstallpath = quick/controls + +headerdirs += ../ +sourcedirs += ../ + +imagedirs += images + +navigation.landingpage = "Qt Quick Controls 2" +navigation.qmltypespage = "Qt Quick Controls 2 QML Types" + +tagfile = qtquickcontrols2.tags diff --git a/src/controls/doc/src/qtquickcontrols2-index.qdoc b/src/controls/doc/src/qtquickcontrols2-index.qdoc new file mode 100644 index 00000000..028e4bd4 --- /dev/null +++ b/src/controls/doc/src/qtquickcontrols2-index.qdoc @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page qtquickcontrols2-index.html + \title Qt Quick Controls 2 + + \brief The Qt Quick Controls 2 module provides a set of UI controls for Qt Quick. + + The Qt Quick Controls 2 module provides a set of controls that can be used to + build complete interfaces in Qt Quick. + + The module is new in Qt 5.6. + + Visit the \l{Qt Quick Controls 2 Overview} page to get started. + + \section1 Related information + + \list + \li \l{Qt Quick} + \li \l{Qt Quick Controls 2 Overview} + \li \l{Qt Quick Controls 2 QML Types}{Qt Quick Controls 2 QML Types} + \endlist +*/ diff --git a/src/controls/doc/src/qtquickcontrols2-overview.qdoc b/src/controls/doc/src/qtquickcontrols2-overview.qdoc new file mode 100644 index 00000000..2140aa55 --- /dev/null +++ b/src/controls/doc/src/qtquickcontrols2-overview.qdoc @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page qtquickcontrols2-overview.html + \title Qt Quick Controls 2 Overview + \brief A set of UI controls to create user interfaces in Qt Quick + + The Qt Quick Controls 2 provide a set of UI controls to create user interfaces + in Qt Quick. + + \section1 Getting Started + + TODO + + \section1 Setting Up Controls from C++ + + TODO + + \section2 Using C++ Data From QML + + TODO + + \section2 Deploying Qt Quick Controls 2 + + TODO + + \section1 Related information + + \list + \li \l{Qt Quick} + \li \l{Qt Quick Controls 2} + \endlist +*/ diff --git a/src/controls/doc/src/qtquickcontrols2.qdoc b/src/controls/doc/src/qtquickcontrols2.qdoc new file mode 100644 index 00000000..bb188eac --- /dev/null +++ b/src/controls/doc/src/qtquickcontrols2.qdoc @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmlmodule QtQuick.Controls 2.0 + \title Qt Quick Controls 2 QML Types + \ingroup qmlmodules + \brief Provides QML types for user interfaces. + + The \l{Qt Quick Controls 2} module provides QML types for creating user + interfaces. These QML types work in conjunction with \l{Qt Quick} and + \l{Qt Quick Layouts}. + + The QML types can be imported into your application using the + following import statement in your .qml file. + + \code + import QtQuick.Controls 2.0 + \endcode +*/ diff --git a/src/controls/qquickabstractapplicationwindow.cpp b/src/controls/qquickabstractapplicationwindow.cpp new file mode 100644 index 00000000..f6ad3084 --- /dev/null +++ b/src/controls/qquickabstractapplicationwindow.cpp @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractapplicationwindow_p.h" +#include "qquickstyle_p.h" + +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ApplicationWindow + \inherits Window + \instantiates QQuickAbstractApplicationWindow + \inqmlmodule QtQuick.Controls + \ingroup application + \brief An application window. + + TODO +*/ + +class QQuickAbstractApplicationWindowPrivate : public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickAbstractApplicationWindow) + +public: + QQuickAbstractApplicationWindowPrivate() : contentWidth(0), contentHeight(0), + header(Q_NULLPTR), footer(Q_NULLPTR), style(Q_NULLPTR) { } + + void relayout(); + + void itemImplicitWidthChanged(QQuickItem *item) Q_DECL_OVERRIDE; + void itemImplicitHeightChanged(QQuickItem *item) Q_DECL_OVERRIDE; + + qreal contentWidth; + qreal contentHeight; + QQuickItem *header; + QQuickItem *footer; + mutable QQuickStyle *style; + QQuickAbstractApplicationWindow *q_ptr; +}; + +void QQuickAbstractApplicationWindowPrivate::relayout() +{ + Q_Q(QQuickAbstractApplicationWindow); + QQuickItem *content = q->contentItem(); + qreal hh = header ? header->height() : 0; + qreal fh = footer ? footer->height() : 0; + + content->setY(hh); + content->setHeight(q->height() - hh - fh); + + if (header) + header->setY(-hh); + if (footer) + footer->setY(content->height()); +} + +void QQuickAbstractApplicationWindowPrivate::itemImplicitWidthChanged(QQuickItem *item) +{ + Q_UNUSED(item); + relayout(); +} + +void QQuickAbstractApplicationWindowPrivate::itemImplicitHeightChanged(QQuickItem *item) +{ + Q_UNUSED(item); + relayout(); +} + +QQuickAbstractApplicationWindow::QQuickAbstractApplicationWindow(QWindow *parent) : + QQuickWindowQmlImpl(parent), d_ptr(new QQuickAbstractApplicationWindowPrivate) +{ + d_ptr->q_ptr = this; +} + +QQuickAbstractApplicationWindow::~QQuickAbstractApplicationWindow() +{ + Q_D(QQuickAbstractApplicationWindow); + if (d->header) + QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (d->footer) + QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); +} + +/*! + \qmlproperty Item QtQuickControls2::ApplicationWindow::header + + TODO +*/ +QQuickItem *QQuickAbstractApplicationWindow::header() const +{ + Q_D(const QQuickAbstractApplicationWindow); + return d->header; +} + +void QQuickAbstractApplicationWindow::setHeader(QQuickItem *header) +{ + Q_D(QQuickAbstractApplicationWindow); + if (d->header != header) { + delete d->header; + d->header = header; + if (header) { + header->setParentItem(contentItem()); + QQuickItemPrivate *p = QQuickItemPrivate::get(header); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(header->z())) + header->setZ(1); + } + emit headerChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ApplicationWindow::footer + + TODO +*/ +QQuickItem *QQuickAbstractApplicationWindow::footer() const +{ + Q_D(const QQuickAbstractApplicationWindow); + return d->footer; +} + +void QQuickAbstractApplicationWindow::setFooter(QQuickItem *footer) +{ + Q_D(QQuickAbstractApplicationWindow); + if (d->footer != footer) { + delete d->footer; + d->footer = footer; + if (footer) { + footer->setParentItem(contentItem()); + QQuickItemPrivate *p = QQuickItemPrivate::get(footer); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(footer->z())) + footer->setZ(1); + } + emit footerChanged(); + } +} + +/*! + \qmlproperty Style QtQuickControls2::ApplicationWindow::style + + TODO +*/ +QQuickStyle *QQuickAbstractApplicationWindow::style() const +{ + Q_D(const QQuickAbstractApplicationWindow); + if (!d->style) + d->style = QQuickStyle::instance(qmlEngine(this)); + return d->style; +} + +void QQuickAbstractApplicationWindow::setStyle(QQuickStyle *style) +{ + Q_D(QQuickAbstractApplicationWindow); + if (d->style != style) { + d->style = style; + emit styleChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ApplicationWindow::contentWidth + + TODO +*/ +qreal QQuickAbstractApplicationWindow::contentWidth() const +{ + Q_D(const QQuickAbstractApplicationWindow); + return d->contentWidth; +} + +void QQuickAbstractApplicationWindow::setContentWidth(qreal width) +{ + Q_D(QQuickAbstractApplicationWindow); + if (d->contentWidth != width) { + d->contentWidth = width; + emit contentWidthChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ApplicationWindow::contentHeight + + TODO +*/ +qreal QQuickAbstractApplicationWindow::contentHeight() const +{ + Q_D(const QQuickAbstractApplicationWindow); + return d->contentHeight; +} + +void QQuickAbstractApplicationWindow::setContentHeight(qreal height) +{ + Q_D(QQuickAbstractApplicationWindow); + if (d->contentHeight != height) { + d->contentHeight = height; + emit contentHeightChanged(); + } +} + +void QQuickAbstractApplicationWindow::resizeEvent(QResizeEvent *event) +{ + QQuickWindowQmlImpl::resizeEvent(event); + + Q_D(QQuickAbstractApplicationWindow); + if (d->header) { + QQuickItemPrivate *p = QQuickItemPrivate::get(d->header); + if (!p->widthValid || qFuzzyCompare(d->header->width(), event->oldSize().width())) + d->header->setWidth(width()); + } + if (d->footer) { + QQuickItemPrivate *p = QQuickItemPrivate::get(d->footer); + if (!p->widthValid || qFuzzyCompare(d->footer->width(), event->oldSize().width())) + d->footer->setWidth(width()); + } + d->relayout(); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractapplicationwindow_p.h b/src/controls/qquickabstractapplicationwindow_p.h new file mode 100644 index 00000000..f8f2033a --- /dev/null +++ b/src/controls/qquickabstractapplicationwindow_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTAPPLICATIONWINDOW_P_H +#define QQUICKABSTRACTAPPLICATIONWINDOW_P_H + +#include <QtQuick/private/qquickwindowmodule_p.h> +#include <QtQuickControls/private/qtquickcontrolsglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickStyle; +class QQuickAbstractApplicationWindowPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractApplicationWindow : public QQuickWindowQmlImpl +{ + Q_OBJECT + Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL) + Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) + Q_PROPERTY(QQuickStyle *style READ style WRITE setStyle NOTIFY styleChanged FINAL) + Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL) + Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL) + +public: + explicit QQuickAbstractApplicationWindow(QWindow *parent = Q_NULLPTR); + ~QQuickAbstractApplicationWindow(); + + QQuickItem *header() const; + void setHeader(QQuickItem *header); + + QQuickItem *footer() const; + void setFooter(QQuickItem *footer); + + QQuickStyle *style() const; + void setStyle(QQuickStyle *style); + + qreal contentWidth() const; + void setContentWidth(qreal width); + + qreal contentHeight() const; + void setContentHeight(qreal height); + +Q_SIGNALS: + void headerChanged(); + void footerChanged(); + void styleChanged(); + void contentWidthChanged(); + void contentHeightChanged(); + +protected: + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractApplicationWindow) + Q_DECLARE_PRIVATE(QQuickAbstractApplicationWindow) + QScopedPointer<QQuickAbstractApplicationWindowPrivate> d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTAPPLICATIONWINDOW_P_H diff --git a/src/controls/qquickabstractbusyindicator.cpp b/src/controls/qquickabstractbusyindicator.cpp new file mode 100644 index 00000000..4370668a --- /dev/null +++ b/src/controls/qquickabstractbusyindicator.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractbusyindicator_p.h" +#include "qquickcontrol_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype BusyIndicator + \inherits Control + \instantiates QQuickAbstractBusyIndicator + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A busy indicator. + + TODO +*/ + +class QQuickAbstractBusyIndicatorPrivate : public QQuickControlPrivate +{ +public: + QQuickAbstractBusyIndicatorPrivate() : running(false), indicator(Q_NULLPTR) { } + + bool running; + QQuickItem *indicator; +}; + +QQuickAbstractBusyIndicator::QQuickAbstractBusyIndicator(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractBusyIndicatorPrivate), parent) +{ +} + +/*! + \qmlproperty bool QtQuickControls2::BusyIndicator::running + + TODO +*/ +bool QQuickAbstractBusyIndicator::isRunning() const +{ + Q_D(const QQuickAbstractBusyIndicator); + return d->running; +} + +void QQuickAbstractBusyIndicator::setRunning(bool running) +{ + Q_D(QQuickAbstractBusyIndicator); + if (d->running != running) { + d->running = running; + emit runningChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::BusyIndicator::indicator + + TODO +*/ +QQuickItem *QQuickAbstractBusyIndicator::indicator() const +{ + Q_D(const QQuickAbstractBusyIndicator); + return d->indicator; +} + +void QQuickAbstractBusyIndicator::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickAbstractBusyIndicator); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractbusyindicator_p.h b/src/controls/qquickabstractbusyindicator_p.h new file mode 100644 index 00000000..a99da139 --- /dev/null +++ b/src/controls/qquickabstractbusyindicator_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTBUSYINDICATOR_P_H +#define QQUICKABSTRACTBUSYINDICATOR_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractBusyIndicatorPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractBusyIndicator : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged FINAL) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + +public: + explicit QQuickAbstractBusyIndicator(QQuickItem *parent = Q_NULLPTR); + + bool isRunning() const; + void setRunning(bool running); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + +Q_SIGNALS: + void runningChanged(); + void indicatorChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractBusyIndicator) + Q_DECLARE_PRIVATE(QQuickAbstractBusyIndicator) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTBUSYINDICATOR_P_H diff --git a/src/controls/qquickabstractbutton.cpp b/src/controls/qquickabstractbutton.cpp new file mode 100644 index 00000000..5b207520 --- /dev/null +++ b/src/controls/qquickabstractbutton.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractbutton_p.h" +#include "qquickabstractbutton_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Button + \inherits Control + \instantiates QQuickAbstractButton + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A button control. + + TODO +*/ + +QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() : + pressed(false), label(Q_NULLPTR) +{ +} + +QQuickAbstractButton::QQuickAbstractButton(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractButtonPrivate), parent) +{ + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +QQuickAbstractButton::QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent) : + QQuickControl(dd, parent) +{ + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +/*! + \qmlproperty string QtQuickControls2::Button::text + + TODO +*/ +QString QQuickAbstractButton::text() const +{ + Q_D(const QQuickAbstractButton); + return d->text; +} + +void QQuickAbstractButton::setText(const QString &text) +{ + Q_D(QQuickAbstractButton); + if (d->text != text) { + d->text = text; + emit textChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::Button::pressed + + TODO +*/ +bool QQuickAbstractButton::isPressed() const +{ + Q_D(const QQuickAbstractButton); + return d->pressed; +} + +void QQuickAbstractButton::setPressed(bool pressed) +{ + Q_D(QQuickAbstractButton); + if (d->pressed != pressed) { + d->pressed = pressed; + emit pressedChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Button::label + + TODO +*/ +QQuickItem *QQuickAbstractButton::label() const +{ + Q_D(const QQuickAbstractButton); + return d->label; +} + +void QQuickAbstractButton::setLabel(QQuickItem *label) +{ + Q_D(QQuickAbstractButton); + if (d->label != label) { + delete d->label; + d->label = label; + if (label && !label->parentItem()) + label->setParentItem(this); + emit labelChanged(); + } +} + +void QQuickAbstractButton::focusOutEvent(QFocusEvent *event) +{ + QQuickControl::focusOutEvent(event); + setPressed(false); +} + +void QQuickAbstractButton::keyPressEvent(QKeyEvent *event) +{ + QQuickControl::keyPressEvent(event); + if (event->key() == Qt::Key_Space) { + setPressed(true); + event->accept(); + } +} + +void QQuickAbstractButton::keyReleaseEvent(QKeyEvent *event) +{ + QQuickControl::keyReleaseEvent(event); + if (event->key() == Qt::Key_Space) { + emit clicked(); + setPressed(false); + event->accept(); + } +} + +void QQuickAbstractButton::mousePressEvent(QMouseEvent *event) +{ + QQuickControl::mousePressEvent(event); + setPressed(true); + event->accept(); +} + +void QQuickAbstractButton::mouseMoveEvent(QMouseEvent *event) +{ + QQuickControl::mouseMoveEvent(event); + setPressed(contains(event->pos())); + event->accept(); +} + +void QQuickAbstractButton::mouseReleaseEvent(QMouseEvent *event) +{ + QQuickControl::mouseReleaseEvent(event); + if (contains(event->pos())) + emit clicked(); + setPressed(false); + event->accept(); +} + +void QQuickAbstractButton::mouseUngrabEvent() +{ + QQuickControl::mouseUngrabEvent(); + setPressed(false); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractbutton_p.h b/src/controls/qquickabstractbutton_p.h new file mode 100644 index 00000000..4be68f29 --- /dev/null +++ b/src/controls/qquickabstractbutton_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTBUTTON_P_H +#define QQUICKABSTRACTBUTTON_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractButtonPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractButton : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) + Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) + Q_PROPERTY(QQuickItem *label READ label WRITE setLabel NOTIFY labelChanged FINAL) + +public: + explicit QQuickAbstractButton(QQuickItem *parent = Q_NULLPTR); + + QString text() const; + void setText(const QString &text); + + bool isPressed() const; + void setPressed(bool pressed); + + QQuickItem *label() const; + void setLabel(QQuickItem *label); + +Q_SIGNALS: + void clicked(); + void textChanged(); + void pressedChanged(); + void labelChanged(); + +protected: + QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent); + + void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseUngrabEvent() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractButton) + Q_DECLARE_PRIVATE(QQuickAbstractButton) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTBUTTON_P_H diff --git a/src/controls/qquickabstractbutton_p_p.h b/src/controls/qquickabstractbutton_p_p.h new file mode 100644 index 00000000..fa24543b --- /dev/null +++ b/src/controls/qquickabstractbutton_p_p.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTBUTTON_P_P_H +#define QQUICKABSTRACTBUTTON_P_P_H + +#include <QtQuickControls/private/qquickcontrol_p_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractButtonPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractButton) + +public: + QQuickAbstractButtonPrivate(); + + QString text; + bool pressed; + QQuickItem *label; +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTBUTTON_P_P_H diff --git a/src/controls/qquickabstractcheckable.cpp b/src/controls/qquickabstractcheckable.cpp new file mode 100644 index 00000000..3811ada4 --- /dev/null +++ b/src/controls/qquickabstractcheckable.cpp @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractcheckable_p.h" +#include "qquickabstractcheckable_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Checkable + \inherits Button + \instantiates QQuickAbstractCheckable + \inqmlmodule QtQuick.Controls + \qmlabstract + \internal +*/ + +QQuickAbstractCheckablePrivate::QQuickAbstractCheckablePrivate() : + checked(false), exclusive(false), indicator(Q_NULLPTR), layoutDirection(Qt::LeftToRight) +{ +} + +QQuickAbstractCheckable::QQuickAbstractCheckable(QQuickItem *parent) : + QQuickAbstractButton(*(new QQuickAbstractCheckablePrivate), parent) +{ +} + +QQuickAbstractCheckable::QQuickAbstractCheckable(QQuickAbstractCheckablePrivate &dd, QQuickItem *parent) : + QQuickAbstractButton(dd, parent) +{ +} + +/*! + \qmlproperty bool QtQuickControls2::Checkable::checked + + TODO +*/ +bool QQuickAbstractCheckable::isChecked() const +{ + Q_D(const QQuickAbstractCheckable); + return d->checked; +} + +void QQuickAbstractCheckable::setChecked(bool checked) +{ + Q_D(QQuickAbstractCheckable); + if (d->checked != checked) { + d->checked = checked; + emit checkedChanged(); + } +} + +bool QQuickAbstractCheckable::isExclusive() const +{ + Q_D(const QQuickAbstractCheckable); + return d->exclusive; +} + +void QQuickAbstractCheckable::setExclusive(bool exclusive) +{ + Q_D(QQuickAbstractCheckable); + d->exclusive = exclusive; +} + +/*! + \qmlproperty Item QtQuickControls2::Checkable::indicator + + TODO +*/ +QQuickItem *QQuickAbstractCheckable::indicator() const +{ + Q_D(const QQuickAbstractCheckable); + return d->indicator; +} + +void QQuickAbstractCheckable::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickAbstractCheckable); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator) { + if (!indicator->parentItem()) + indicator->setParentItem(this); + indicator->setAcceptedMouseButtons(Qt::LeftButton); + } + emit indicatorChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::Checkable::layoutDirection + + TODO +*/ +Qt::LayoutDirection QQuickAbstractCheckable::layoutDirection() const +{ + Q_D(const QQuickAbstractCheckable); + return d->layoutDirection; +} + +/*! + \qmlproperty enumeration QtQuickControls2::Checkable::effectiveLayoutDirection + + TODO +*/ +Qt::LayoutDirection QQuickAbstractCheckable::effectiveLayoutDirection() const +{ + Q_D(const QQuickAbstractCheckable); + if (isMirrored()) + return d->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; + return d->layoutDirection; +} + +void QQuickAbstractCheckable::setLayoutDirection(Qt::LayoutDirection direction) +{ + Q_D(QQuickAbstractCheckable); + if (d->layoutDirection != direction) { + d->layoutDirection = direction; + emit layoutDirectionChanged(); + emit effectiveLayoutDirectionChanged(); + } +} + +/*! + \qmlmethod void QtQuickControls2::Checkable::toggle() + + TODO +*/ +void QQuickAbstractCheckable::toggle() +{ + Q_D(QQuickAbstractCheckable); + setChecked(!d->checked); +} + +void QQuickAbstractCheckable::keyReleaseEvent(QKeyEvent *event) +{ + Q_D(QQuickAbstractCheckable); + QQuickAbstractButton::keyReleaseEvent(event); + if (event->key() == Qt::Key_Space) + setChecked(d->exclusive || !d->checked); +} + +void QQuickAbstractCheckable::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractCheckable); + QQuickAbstractButton::mouseReleaseEvent(event); + if (contains(event->pos())) + setChecked(d->exclusive || !d->checked); +} + +void QQuickAbstractCheckable::mirrorChange() +{ + emit effectiveLayoutDirectionChanged(); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractcheckable_p.h b/src/controls/qquickabstractcheckable_p.h new file mode 100644 index 00000000..d82ea213 --- /dev/null +++ b/src/controls/qquickabstractcheckable_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTCHECKABLE_P_H +#define QQUICKABSTRACTCHECKABLE_P_H + +#include <QtQuickControls/private/qquickabstractbutton_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractCheckablePrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractCheckable : public QQuickAbstractButton +{ + Q_OBJECT + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL) + +public: + explicit QQuickAbstractCheckable(QQuickItem *parent = Q_NULLPTR); + + bool isChecked() const; + void setChecked(bool checked); + + bool isExclusive() const; + void setExclusive(bool exclusive); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + + Qt::LayoutDirection layoutDirection() const; + Qt::LayoutDirection effectiveLayoutDirection() const; + void setLayoutDirection(Qt::LayoutDirection direction); + +public Q_SLOTS: + void toggle(); + +Q_SIGNALS: + void checkedChanged(); + void indicatorChanged(); + void layoutDirectionChanged(); + void effectiveLayoutDirectionChanged(); + +protected: + QQuickAbstractCheckable(QQuickAbstractCheckablePrivate &dd, QQuickItem *parent); + + void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + + void mirrorChange() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractCheckable) + Q_DECLARE_PRIVATE(QQuickAbstractCheckable) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTCHECKABLE_P_H diff --git a/src/controls/qquickabstractcheckable_p_p.h b/src/controls/qquickabstractcheckable_p_p.h new file mode 100644 index 00000000..9788bf05 --- /dev/null +++ b/src/controls/qquickabstractcheckable_p_p.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTCHECKABLE_P_P_H +#define QQUICKABSTRACTCHECKABLE_P_P_H + +#include <QtQuickControls/private/qquickabstractbutton_p_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractCheckablePrivate : public QQuickAbstractButtonPrivate +{ +public: + QQuickAbstractCheckablePrivate(); + + bool checked; + bool exclusive; + QQuickItem *indicator; + Qt::LayoutDirection layoutDirection; +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTCHECKABLE_P_P_H diff --git a/src/controls/qquickabstractcheckbox.cpp b/src/controls/qquickabstractcheckbox.cpp new file mode 100644 index 00000000..67d9efab --- /dev/null +++ b/src/controls/qquickabstractcheckbox.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractcheckbox_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype CheckBox + \inherits Checkable + \instantiates QQuickAbstractCheckBox + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A check box control. + + TODO +*/ + +QQuickAbstractCheckBox::QQuickAbstractCheckBox(QQuickItem *parent) : + QQuickAbstractCheckable(parent) +{ +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractcheckbox_p.h b/src/controls/qquickabstractcheckbox_p.h new file mode 100644 index 00000000..e97a1031 --- /dev/null +++ b/src/controls/qquickabstractcheckbox_p.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTCHECKBOX_P_H +#define QQUICKABSTRACTCHECKBOX_P_H + +#include <QtQuickControls/private/qquickabstractcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractCheckBox : public QQuickAbstractCheckable +{ + Q_OBJECT + +public: + explicit QQuickAbstractCheckBox(QQuickItem *parent = Q_NULLPTR); +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTCHECKBOX_P_H diff --git a/src/controls/qquickabstractcontainer.cpp b/src/controls/qquickabstractcontainer.cpp new file mode 100644 index 00000000..b82f951a --- /dev/null +++ b/src/controls/qquickabstractcontainer.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractcontainer_p.h" +#include "qquickabstractcontainer_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Container + \inherits Control + \instantiates QQuickAbstractContainer + \inqmlmodule QtQuick.Controls + \qmlabstract + \internal +*/ + +QQuickAbstractContainerPrivate::QQuickAbstractContainerPrivate() : + contentWidth(0), contentHeight(0), contentItem(Q_NULLPTR) +{ +} + +QQuickAbstractContainer::QQuickAbstractContainer(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractContainerPrivate), parent) +{ +} + +QQuickAbstractContainer::QQuickAbstractContainer(QQuickAbstractContainerPrivate &dd, QQuickItem *parent) : + QQuickControl(dd, parent) +{ +} + +/*! + \qmlproperty real QtQuickControls2::Container::contentWidth + + TODO +*/ +qreal QQuickAbstractContainer::contentWidth() const +{ + Q_D(const QQuickAbstractContainer); + return d->contentWidth; +} + +void QQuickAbstractContainer::setContentWidth(qreal width) +{ + Q_D(QQuickAbstractContainer); + if (d->contentWidth != width) { + d->contentWidth = width; + emit contentWidthChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::Container::contentHeight + + TODO +*/ +qreal QQuickAbstractContainer::contentHeight() const +{ + Q_D(const QQuickAbstractContainer); + return d->contentHeight; +} + +void QQuickAbstractContainer::setContentHeight(qreal height) +{ + Q_D(QQuickAbstractContainer); + if (d->contentHeight != height) { + d->contentHeight = height; + emit contentHeightChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Container::contentItem + + TODO +*/ +QQuickItem *QQuickAbstractContainer::contentItem() const +{ + Q_D(const QQuickAbstractContainer); + return d->contentItem; +} + +void QQuickAbstractContainer::setContentItem(QQuickItem *item) +{ + Q_D(QQuickAbstractContainer); + if (d->contentItem != item) { + delete d->contentItem; + d->contentItem = item; + if (item) { + if (!item->parentItem()) + item->setParentItem(this); + } + emit contentItemChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractcontainer_p.h b/src/controls/qquickabstractcontainer_p.h new file mode 100644 index 00000000..c5accc0e --- /dev/null +++ b/src/controls/qquickabstractcontainer_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTCONTAINER_P_H +#define QQUICKABSTRACTCONTAINER_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractContainerPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractContainer : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL) + Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL) + Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) + +public: + explicit QQuickAbstractContainer(QQuickItem *parent = Q_NULLPTR); + + qreal contentWidth() const; + void setContentWidth(qreal width); + + qreal contentHeight() const; + void setContentHeight(qreal height); + + QQuickItem *contentItem() const; + void setContentItem(QQuickItem *item); + +Q_SIGNALS: + void contentWidthChanged(); + void contentHeightChanged(); + void contentItemChanged(); + +protected: + QQuickAbstractContainer(QQuickAbstractContainerPrivate &dd, QQuickItem *parent); + +private: + Q_DISABLE_COPY(QQuickAbstractContainer) + Q_DECLARE_PRIVATE(QQuickAbstractContainer) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTCONTAINER_P_H diff --git a/src/controls/qquickabstractcontainer_p_p.h b/src/controls/qquickabstractcontainer_p_p.h new file mode 100644 index 00000000..bf2080af --- /dev/null +++ b/src/controls/qquickabstractcontainer_p_p.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTCONTAINER_P_P_H +#define QQUICKABSTRACTCONTAINER_P_P_H + +#include <QtQuickControls/private/qquickcontrol_p_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractContainerPrivate : public QQuickControlPrivate +{ +public: + QQuickAbstractContainerPrivate(); + + qreal contentWidth; + qreal contentHeight; + QQuickItem *contentItem; +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTCONTAINER_P_P_H diff --git a/src/controls/qquickabstractframe.cpp b/src/controls/qquickabstractframe.cpp new file mode 100644 index 00000000..9f8f2aa6 --- /dev/null +++ b/src/controls/qquickabstractframe.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractframe_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Frame + \inherits Container + \instantiates QQuickAbstractFrame + \inqmlmodule QtQuick.Controls + \ingroup containers + \brief A frame control. + + TODO +*/ + +QQuickAbstractFrame::QQuickAbstractFrame(QQuickItem *parent) : + QQuickAbstractContainer(parent) +{ +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractframe_p.h b/src/controls/qquickabstractframe_p.h new file mode 100644 index 00000000..317e2360 --- /dev/null +++ b/src/controls/qquickabstractframe_p.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTFRAME_P_H +#define QQUICKABSTRACTFRAME_P_H + +#include <QtQuickControls/private/qquickabstractcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractFrame : public QQuickAbstractContainer +{ + Q_OBJECT + +public: + explicit QQuickAbstractFrame(QQuickItem *parent = Q_NULLPTR); +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTFRAME_P_H diff --git a/src/controls/qquickabstractgroupbox.cpp b/src/controls/qquickabstractgroupbox.cpp new file mode 100644 index 00000000..8d2f9ec0 --- /dev/null +++ b/src/controls/qquickabstractgroupbox.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractgroupbox_p.h" +#include "qquickabstractcontainer_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype GroupBox + \inherits Container + \instantiates QQuickAbstractGroupBox + \inqmlmodule QtQuick.Controls + \ingroup containers + \brief A group box control. + + TODO +*/ + +class QQuickAbstractGroupBoxPrivate : public QQuickAbstractContainerPrivate +{ +public: + QQuickAbstractGroupBoxPrivate() : label(Q_NULLPTR), frame(Q_NULLPTR) { } + + QString title; + QQuickItem *label; + QQuickItem *frame; +}; + +QQuickAbstractGroupBox::QQuickAbstractGroupBox(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractGroupBoxPrivate), parent) +{ +} + +/*! + \qmlproperty string QtQuickControls2::GroupBox::title + + TODO +*/ +QString QQuickAbstractGroupBox::title() const +{ + Q_D(const QQuickAbstractGroupBox); + return d->title; +} + +void QQuickAbstractGroupBox::setTitle(const QString &title) +{ + Q_D(QQuickAbstractGroupBox); + if (d->title != title) { + d->title = title; + emit titleChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::GroupBox::label + + TODO +*/ +QQuickItem *QQuickAbstractGroupBox::label() const +{ + Q_D(const QQuickAbstractGroupBox); + return d->label; +} + +void QQuickAbstractGroupBox::setLabel(QQuickItem *label) +{ + Q_D(QQuickAbstractGroupBox); + if (d->label != label) { + delete d->label; + d->label = label; + if (label && !label->parentItem()) + label->setParentItem(this); + emit labelChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::GroupBox::frame + + TODO +*/ +QQuickItem *QQuickAbstractGroupBox::frame() const +{ + Q_D(const QQuickAbstractGroupBox); + return d->frame; +} + +void QQuickAbstractGroupBox::setFrame(QQuickItem *frame) +{ + Q_D(QQuickAbstractGroupBox); + if (d->frame != frame) { + delete d->frame; + d->frame = frame; + if (frame && !frame->parentItem()) + frame->setParentItem(this); + emit frameChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractgroupbox_p.h b/src/controls/qquickabstractgroupbox_p.h new file mode 100644 index 00000000..b1118441 --- /dev/null +++ b/src/controls/qquickabstractgroupbox_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTGROUPBOX_P_H +#define QQUICKABSTRACTGROUPBOX_P_H + +#include <QtQuickControls/private/qquickabstractcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractGroupBoxPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractGroupBox : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) + Q_PROPERTY(QQuickItem *label READ label WRITE setLabel NOTIFY labelChanged FINAL) + Q_PROPERTY(QQuickItem *frame READ frame WRITE setFrame NOTIFY frameChanged FINAL) + +public: + explicit QQuickAbstractGroupBox(QQuickItem *parent = Q_NULLPTR); + + QString title() const; + void setTitle(const QString &title); + + QQuickItem *label() const; + void setLabel(QQuickItem *label); + + QQuickItem *frame() const; + void setFrame(QQuickItem *frame); + +Q_SIGNALS: + void titleChanged(); + void labelChanged(); + void frameChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractGroupBox) + Q_DECLARE_PRIVATE(QQuickAbstractGroupBox) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTGROUPBOX_P_H diff --git a/src/controls/qquickabstractpageindicator.cpp b/src/controls/qquickabstractpageindicator.cpp new file mode 100644 index 00000000..ee3b98bd --- /dev/null +++ b/src/controls/qquickabstractpageindicator.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractpageindicator_p.h" +#include "qquickabstractcontainer_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype PageIndicator + \inherits Control + \instantiates QQuickAbstractPageIndicator + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A page indicator. + + TODO +*/ + +class QQuickAbstractPageIndicatorPrivate : public QQuickAbstractContainerPrivate +{ +public: + QQuickAbstractPageIndicatorPrivate() : count(0), currentIndex(0) { } + + int count; + int currentIndex; +}; + +QQuickAbstractPageIndicator::QQuickAbstractPageIndicator(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractPageIndicatorPrivate), parent) +{ +} + +/*! + \qmlproperty int QtQuickControls2::PageIndicator::count + + TODO +*/ +int QQuickAbstractPageIndicator::count() const +{ + Q_D(const QQuickAbstractPageIndicator); + return d->count; +} + +void QQuickAbstractPageIndicator::setCount(int count) +{ + Q_D(QQuickAbstractPageIndicator); + if (d->count != count) { + d->count = count; + emit countChanged(); + } +} + +/*! + \qmlproperty int QtQuickControls2::PageIndicator::currentIndex + + TODO +*/ +int QQuickAbstractPageIndicator::currentIndex() const +{ + Q_D(const QQuickAbstractPageIndicator); + return d->currentIndex; +} + +void QQuickAbstractPageIndicator::setCurrentIndex(int index) +{ + Q_D(QQuickAbstractPageIndicator); + if (d->currentIndex != index) { + d->currentIndex = index; + emit currentIndexChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractpageindicator_p.h b/src/controls/qquickabstractpageindicator_p.h new file mode 100644 index 00000000..aa6888bb --- /dev/null +++ b/src/controls/qquickabstractpageindicator_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTPAGEINDICATOR_P_H +#define QQUICKABSTRACTPAGEINDICATOR_P_H + +#include <QtQuickControls/private/qquickabstractcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractPageIndicatorPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractPageIndicator : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged FINAL) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) + +public: + explicit QQuickAbstractPageIndicator(QQuickItem *parent = Q_NULLPTR); + + int count() const; + void setCount(int count); + + int currentIndex() const; + void setCurrentIndex(int index); + +Q_SIGNALS: + void countChanged(); + void currentIndexChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractPageIndicator) + Q_DECLARE_PRIVATE(QQuickAbstractPageIndicator) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTPAGEINDICATOR_P_H diff --git a/src/controls/qquickabstractprogressbar.cpp b/src/controls/qquickabstractprogressbar.cpp new file mode 100644 index 00000000..7e38b167 --- /dev/null +++ b/src/controls/qquickabstractprogressbar.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractprogressbar_p.h" +#include "qquickcontrol_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ProgressBar + \inherits Control + \instantiates QQuickAbstractProgressBar + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A progress bar. + + TODO +*/ + +class QQuickAbstractProgressBarPrivate : public QQuickControlPrivate +{ +public: + QQuickAbstractProgressBarPrivate() : value(0), indeterminate(false), + layoutDirection(Qt::LeftToRight), indicator(Q_NULLPTR) { } + + qreal value; + bool indeterminate; + Qt::LayoutDirection layoutDirection; + QQuickItem *indicator; +}; + +QQuickAbstractProgressBar::QQuickAbstractProgressBar(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractProgressBarPrivate), parent) +{ +} + +/*! + \qmlproperty real QtQuickControls2::ProgressBar::value + + TODO +*/ +qreal QQuickAbstractProgressBar::value() const +{ + Q_D(const QQuickAbstractProgressBar); + return d->value; +} + +void QQuickAbstractProgressBar::setValue(qreal value) +{ + Q_D(QQuickAbstractProgressBar); + value = qBound(0.0, value, 1.0); + if (!qFuzzyCompare(d->value, value)) { + d->value = value; + emit valueChanged(); + emit visualPositionChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ProgressBar::visualPosition + + TODO +*/ +qreal QQuickAbstractProgressBar::visualPosition() const +{ + Q_D(const QQuickAbstractProgressBar); + if (effectiveLayoutDirection() == Qt::RightToLeft) + return 1.0 - d->value; + return d->value; +} + +/*! + \qmlproperty bool QtQuickControls2::ProgressBar::indeterminate + + TODO +*/ +bool QQuickAbstractProgressBar::isIndeterminate() const +{ + Q_D(const QQuickAbstractProgressBar); + return d->indeterminate; +} + +void QQuickAbstractProgressBar::setIndeterminate(bool indeterminate) +{ + Q_D(QQuickAbstractProgressBar); + if (d->indeterminate != indeterminate) { + d->indeterminate = indeterminate; + emit indeterminateChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::ProgressBar::layoutDirection + + TODO +*/ +Qt::LayoutDirection QQuickAbstractProgressBar::layoutDirection() const +{ + Q_D(const QQuickAbstractProgressBar); + return d->layoutDirection; +} + +/*! + \qmlproperty enumeration QtQuickControls2::ProgressBar::effectiveLayoutDirection + + TODO +*/ +Qt::LayoutDirection QQuickAbstractProgressBar::effectiveLayoutDirection() const +{ + Q_D(const QQuickAbstractProgressBar); + if (isMirrored()) + return d->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; + return d->layoutDirection; +} + +void QQuickAbstractProgressBar::setLayoutDirection(Qt::LayoutDirection direction) +{ + Q_D(QQuickAbstractProgressBar); + if (d->layoutDirection != direction) { + d->layoutDirection = direction; + emit layoutDirectionChanged(); + emit effectiveLayoutDirectionChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ProgressBar::indicator + + TODO +*/ +QQuickItem *QQuickAbstractProgressBar::indicator() const +{ + Q_D(const QQuickAbstractProgressBar); + return d->indicator; +} + +void QQuickAbstractProgressBar::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickAbstractProgressBar); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); + } +} + +void QQuickAbstractProgressBar::mirrorChange() +{ + emit effectiveLayoutDirectionChanged(); + emit visualPositionChanged(); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractprogressbar_p.h b/src/controls/qquickabstractprogressbar_p.h new file mode 100644 index 00000000..8215ad31 --- /dev/null +++ b/src/controls/qquickabstractprogressbar_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTPROGRESSBAR_P_H +#define QQUICKABSTRACTPROGRESSBAR_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractProgressBarPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractProgressBar : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) + Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) + Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate NOTIFY indeterminateChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + +public: + explicit QQuickAbstractProgressBar(QQuickItem *parent = Q_NULLPTR); + + qreal value() const; + void setValue(qreal value); + + qreal visualPosition() const; + + bool isIndeterminate() const; + void setIndeterminate(bool indeterminate); + + Qt::LayoutDirection layoutDirection() const; + Qt::LayoutDirection effectiveLayoutDirection() const; + void setLayoutDirection(Qt::LayoutDirection direction); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + +Q_SIGNALS: + void valueChanged(); + void visualPositionChanged(); + void indeterminateChanged(); + void layoutDirectionChanged(); + void effectiveLayoutDirectionChanged(); + void indicatorChanged(); + +protected: + void mirrorChange() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractProgressBar) + Q_DECLARE_PRIVATE(QQuickAbstractProgressBar) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTPROGRESSBAR_P_H diff --git a/src/controls/qquickabstractradiobutton.cpp b/src/controls/qquickabstractradiobutton.cpp new file mode 100644 index 00000000..75f47ac0 --- /dev/null +++ b/src/controls/qquickabstractradiobutton.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractradiobutton_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype RadioButton + \inherits Checkable + \instantiates QQuickAbstractRadioButton + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A radio button control. + + TODO + + \sa ExclusiveGroup +*/ + +QQuickAbstractRadioButton::QQuickAbstractRadioButton(QQuickItem *parent) : + QQuickAbstractCheckable(parent) +{ + setExclusive(true); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractradiobutton_p.h b/src/controls/qquickabstractradiobutton_p.h new file mode 100644 index 00000000..56d67868 --- /dev/null +++ b/src/controls/qquickabstractradiobutton_p.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTRADIOBUTTON_P_H +#define QQUICKABSTRACTRADIOBUTTON_P_H + +#include <QtQuickControls/private/qquickabstractcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractRadioButton : public QQuickAbstractCheckable +{ + Q_OBJECT + +public: + explicit QQuickAbstractRadioButton(QQuickItem *parent = Q_NULLPTR); +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTRADIOBUTTON_P_H diff --git a/src/controls/qquickabstractscrollbar.cpp b/src/controls/qquickabstractscrollbar.cpp new file mode 100644 index 00000000..09ccace6 --- /dev/null +++ b/src/controls/qquickabstractscrollbar.cpp @@ -0,0 +1,428 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractscrollbar_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquickflickable_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ScrollBar + \inherits Control + \instantiates QQuickAbstractScrollBar + \inqmlmodule QtQuick.Controls + \ingroup indicators + \ingroup sliders + \brief A scroll bar. + + TODO +*/ + +class QQuickAbstractScrollBarPrivate : public QQuickControlPrivate +{ +public: + QQuickAbstractScrollBarPrivate() : size(0), position(0), offset(0), + active(false), pressed(false), moving(false), + orientation(Qt::Vertical), handle(Q_NULLPTR) { } + + static QQuickAbstractScrollBarPrivate *get(QQuickAbstractScrollBar *bar) + { + return bar->d_func(); + } + + qreal size; + qreal position; + qreal offset; + bool active; + bool pressed; + bool moving; + Qt::Orientation orientation; + QQuickItem *handle; +}; + +QQuickAbstractScrollBar::QQuickAbstractScrollBar(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractScrollBarPrivate), parent) +{ + setKeepMouseGrab(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +QQuickScrollBarAttached *QQuickAbstractScrollBar::qmlAttachedProperties(QObject *object) +{ + QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(object); + if (flickable) + return new QQuickScrollBarAttached(flickable); + + qWarning() << "ScrollBar must be attached to a Flickable" << object; + return Q_NULLPTR; +} + +/*! + \qmlproperty real QtQuickControls2::ScrollBar::size + + TODO +*/ +qreal QQuickAbstractScrollBar::size() const +{ + Q_D(const QQuickAbstractScrollBar); + return d->size; +} + +void QQuickAbstractScrollBar::setSize(qreal size) +{ + Q_D(QQuickAbstractScrollBar); + if (!qFuzzyCompare(d->size, size)) { + d->size = size; + emit sizeChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ScrollBar::position + + TODO +*/ +qreal QQuickAbstractScrollBar::position() const +{ + Q_D(const QQuickAbstractScrollBar); + return d->position; +} + +void QQuickAbstractScrollBar::setPosition(qreal position) +{ + Q_D(QQuickAbstractScrollBar); + if (!qFuzzyCompare(d->position, position)) { + d->position = position; + emit positionChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::ScrollBar::active + + TODO +*/ +bool QQuickAbstractScrollBar::isActive() const +{ + Q_D(const QQuickAbstractScrollBar); + return d->active; +} + +void QQuickAbstractScrollBar::setActive(bool active) +{ + Q_D(QQuickAbstractScrollBar); + if (d->active != active) { + d->active = active; + emit activeChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::ScrollBar::pressed + + TODO +*/ +bool QQuickAbstractScrollBar::isPressed() const +{ + Q_D(const QQuickAbstractScrollBar); + return d->pressed; +} + +void QQuickAbstractScrollBar::setPressed(bool pressed) +{ + Q_D(QQuickAbstractScrollBar); + if (d->pressed != pressed) { + d->pressed = pressed; + setActive(d->pressed || d->moving); + emit pressedChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::ScrollBar::orientation + + TODO +*/ +Qt::Orientation QQuickAbstractScrollBar::orientation() const +{ + Q_D(const QQuickAbstractScrollBar); + return d->orientation; +} + +void QQuickAbstractScrollBar::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickAbstractScrollBar); + if (d->orientation != orientation) { + d->orientation = orientation; + emit orientationChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ScrollBar::handle + + TODO +*/ +QQuickItem *QQuickAbstractScrollBar::handle() const +{ + Q_D(const QQuickAbstractScrollBar); + return d->handle; +} + +void QQuickAbstractScrollBar::setHandle(QQuickItem *handle) +{ + Q_D(QQuickAbstractScrollBar); + if (d->handle != handle) { + delete d->handle; + d->handle = handle; + if (handle && !handle->parentItem()) + handle->setParentItem(this); + emit handleChanged(); + } +} + +void QQuickAbstractScrollBar::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractScrollBar); + QQuickControl::mousePressEvent(event); + d->offset = positionAt(event->pos()) - d->position; + if (d->offset < 0 || d->offset > d->size) + d->offset = d->size / 2; + setPressed(true); + event->accept(); +} + +void QQuickAbstractScrollBar::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractScrollBar); + QQuickControl::mouseMoveEvent(event); + setPosition(qBound(0.0, positionAt(event->pos()) - d->offset, 1.0 - d->size)); + event->accept(); +} + +void QQuickAbstractScrollBar::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractScrollBar); + QQuickControl::mouseReleaseEvent(event); + setPosition(qBound(0.0, positionAt(event->pos()) - d->offset, 1.0 - d->size)); + d->offset = 0.0; + setPressed(false); + event->accept(); +} + +qreal QQuickAbstractScrollBar::positionAt(const QPoint &point) const +{ + Q_D(const QQuickAbstractScrollBar); + if (d->orientation == Qt::Horizontal) + return point.x() / width(); + else + return point.y() / height(); +} + +class QQuickScrollBarAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener +{ +public: + QQuickScrollBarAttachedPrivate(QQuickFlickable *flickable) : flickable(flickable), horizontal(Q_NULLPTR), vertical(Q_NULLPTR) { } + + void activateHorizontal(); + void activateVertical(); + void scrollHorizontal(); + void scrollVertical(); + + void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + + QQuickFlickable *flickable; + QQuickAbstractScrollBar *horizontal; + QQuickAbstractScrollBar *vertical; +}; + +void QQuickScrollBarAttachedPrivate::activateHorizontal() +{ + QQuickAbstractScrollBarPrivate *p = QQuickAbstractScrollBarPrivate::get(horizontal); + p->moving = flickable->isMovingHorizontally(); + horizontal->setActive(p->moving || p->pressed); +} + +void QQuickScrollBarAttachedPrivate::activateVertical() +{ + QQuickAbstractScrollBarPrivate *p = QQuickAbstractScrollBarPrivate::get(vertical); + p->moving = flickable->isMovingVertically(); + vertical->setActive(p->moving || p->pressed); +} + +// TODO: QQuickFlickable::maxXYExtent() +class QQuickFriendlyFlickable : public QQuickFlickable +{ + friend class QQuickScrollBarAttachedPrivate; +}; + +void QQuickScrollBarAttachedPrivate::scrollHorizontal() +{ + QQuickFriendlyFlickable *f = reinterpret_cast<QQuickFriendlyFlickable *>(flickable); + + const qreal viewwidth = f->width(); + const qreal maxxextent = -f->maxXExtent() + f->minXExtent(); + qreal cx = horizontal->position() * (maxxextent + viewwidth) - f->minXExtent(); + if (!qIsNaN(cx) && !qFuzzyCompare(cx, flickable->contentX())) + flickable->setContentX(cx); +} + +void QQuickScrollBarAttachedPrivate::scrollVertical() +{ + QQuickFriendlyFlickable *f = reinterpret_cast<QQuickFriendlyFlickable *>(flickable); + + const qreal viewheight = f->height(); + const qreal maxyextent = -f->maxYExtent() + f->minYExtent(); + qreal cy = vertical->position() * (maxyextent + viewheight) - f->minYExtent(); + if (!qIsNaN(cy) && !qFuzzyCompare(cy, flickable->contentY())) + flickable->setContentY(cy); +} + +void QQuickScrollBarAttachedPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_ASSERT(item == flickable); + if (horizontal) { + QQuickItemPrivate *p = QQuickItemPrivate::get(horizontal); + if (!p->widthValid || qFuzzyCompare(horizontal->width(), oldGeometry.width())) + horizontal->setWidth(newGeometry.width()); + if (qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), oldGeometry.height() - horizontal->height())) + horizontal->setY(newGeometry.height() - horizontal->height()); + } + if (vertical) { + QQuickItemPrivate *p = QQuickItemPrivate::get(vertical); + if (!p->heightValid || qFuzzyCompare(vertical->height(), oldGeometry.height())) + vertical->setHeight(newGeometry.height()); + if (!p->isMirrored() && (qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), oldGeometry.width() - vertical->width()))) + vertical->setX(newGeometry.width() - vertical->width()); + } +} + +QQuickScrollBarAttached::QQuickScrollBarAttached(QQuickFlickable *flickable) : + QObject(*(new QQuickScrollBarAttachedPrivate(flickable)), flickable) +{ + Q_D(QQuickScrollBarAttached); + QQuickItemPrivate *p = QQuickItemPrivate::get(flickable); + p->addItemChangeListener(d, QQuickItemPrivate::Geometry); +} + +QQuickAbstractScrollBar *QQuickScrollBarAttached::horizontal() const +{ + Q_D(const QQuickScrollBarAttached); + return d->horizontal; +} + +void QQuickScrollBarAttached::setHorizontal(QQuickAbstractScrollBar *horizontal) +{ + Q_D(QQuickScrollBarAttached); + if (d->horizontal != horizontal) { + if (d->horizontal) { + QObjectPrivate::disconnect(d->horizontal, &QQuickAbstractScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); + } + + d->horizontal = horizontal; + + if (horizontal) { + if (!horizontal->parentItem()) + horizontal->setParentItem(d->flickable); + horizontal->setOrientation(Qt::Horizontal); + + QObjectPrivate::connect(horizontal, &QQuickAbstractScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); + connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); + + horizontal->setSize(area->property("widthRatio").toReal()); + horizontal->setPosition(area->property("xPosition").toReal()); + } + emit horizontalChanged(); + } +} + +QQuickAbstractScrollBar *QQuickScrollBarAttached::vertical() const +{ + Q_D(const QQuickScrollBarAttached); + return d->vertical; +} + +void QQuickScrollBarAttached::setVertical(QQuickAbstractScrollBar *vertical) +{ + Q_D(QQuickScrollBarAttached); + if (d->vertical != vertical) { + if (d->vertical) { + QObjectPrivate::disconnect(d->vertical, &QQuickAbstractScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); + } + + d->vertical = vertical; + + if (vertical) { + if (!vertical->parentItem()) + vertical->setParentItem(d->flickable); + vertical->setOrientation(Qt::Vertical); + + QObjectPrivate::connect(vertical, &QQuickAbstractScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); + connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); + + vertical->setSize(area->property("heightRatio").toReal()); + vertical->setPosition(area->property("yPosition").toReal()); + } + emit verticalChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractscrollbar_p.h b/src/controls/qquickabstractscrollbar_p.h new file mode 100644 index 00000000..ecc0114b --- /dev/null +++ b/src/controls/qquickabstractscrollbar_p.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTSCROLLBAR_P_H +#define QQUICKABSTRACTSCROLLBAR_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickFlickable; +class QQuickScrollBarAttached; +class QQuickAbstractScrollBarPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractScrollBar : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal size READ size NOTIFY sizeChanged FINAL) + Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL) + Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) + +public: + explicit QQuickAbstractScrollBar(QQuickItem *parent = Q_NULLPTR); + + static QQuickScrollBarAttached *qmlAttachedProperties(QObject *object); + + qreal size() const; + qreal position() const; + + bool isActive() const; + void setActive(bool active); + + bool isPressed() const; + void setPressed(bool pressed); + + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + + QQuickItem *handle() const; + void setHandle(QQuickItem *handle); + +public Q_SLOTS: + void setSize(qreal size); + void setPosition(qreal position); + +Q_SIGNALS: + void sizeChanged(); + void positionChanged(); + void activeChanged(); + void pressedChanged(); + void orientationChanged(); + void handleChanged(); + +protected: + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + + virtual qreal positionAt(const QPoint &point) const; + +private: + Q_DISABLE_COPY(QQuickAbstractScrollBar) + Q_DECLARE_PRIVATE(QQuickAbstractScrollBar) +}; + +class QQuickScrollBarAttachedPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickScrollBarAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickAbstractScrollBar *horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged FINAL) + Q_PROPERTY(QQuickAbstractScrollBar *vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL) + +public: + explicit QQuickScrollBarAttached(QQuickFlickable *flickable); + + QQuickAbstractScrollBar *horizontal() const; + void setHorizontal(QQuickAbstractScrollBar *horizontal); + + QQuickAbstractScrollBar *vertical() const; + void setVertical(QQuickAbstractScrollBar *vertical); + +Q_SIGNALS: + void horizontalChanged(); + void verticalChanged(); + +private: + Q_DISABLE_COPY(QQuickScrollBarAttached) + Q_DECLARE_PRIVATE(QQuickScrollBarAttached) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickAbstractScrollBar, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKABSTRACTSCROLLBAR_P_H diff --git a/src/controls/qquickabstractscrollindicator.cpp b/src/controls/qquickabstractscrollindicator.cpp new file mode 100644 index 00000000..a68cc6b4 --- /dev/null +++ b/src/controls/qquickabstractscrollindicator.cpp @@ -0,0 +1,319 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractscrollindicator_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquickflickable_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ScrollIndicator + \inherits Control + \instantiates QQuickAbstractScrollIndicator + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A scroll indicator. + + TODO +*/ + +class QQuickAbstractScrollIndicatorPrivate : public QQuickControlPrivate +{ +public: + QQuickAbstractScrollIndicatorPrivate() : size(0), position(0), + active(false), orientation(Qt::Vertical), indicator(Q_NULLPTR) { } + + qreal size; + qreal position; + bool active; + Qt::Orientation orientation; + QQuickItem *indicator; +}; + +QQuickAbstractScrollIndicator::QQuickAbstractScrollIndicator(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractScrollIndicatorPrivate), parent) +{ +} + +QQuickScrollIndicatorAttached *QQuickAbstractScrollIndicator::qmlAttachedProperties(QObject *object) +{ + QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(object); + if (flickable) + return new QQuickScrollIndicatorAttached(flickable); + + qWarning() << "ScrollIndicator must be attached to a Flickable" << object; + return Q_NULLPTR; +} + +/*! + \qmlproperty real QtQuickControls2::ScrollIndicator::size + + TODO +*/ +qreal QQuickAbstractScrollIndicator::size() const +{ + Q_D(const QQuickAbstractScrollIndicator); + return d->size; +} + +void QQuickAbstractScrollIndicator::setSize(qreal size) +{ + Q_D(QQuickAbstractScrollIndicator); + if (!qFuzzyCompare(d->size, size)) { + d->size = size; + emit sizeChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ScrollIndicator::position + + TODO +*/ +qreal QQuickAbstractScrollIndicator::position() const +{ + Q_D(const QQuickAbstractScrollIndicator); + return d->position; +} + +void QQuickAbstractScrollIndicator::setPosition(qreal position) +{ + Q_D(QQuickAbstractScrollIndicator); + if (!qFuzzyCompare(d->position, position)) { + d->position = position; + emit positionChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::ScrollIndicator::active + + TODO +*/ +bool QQuickAbstractScrollIndicator::isActive() const +{ + Q_D(const QQuickAbstractScrollIndicator); + return d->active; +} + +void QQuickAbstractScrollIndicator::setActive(bool active) +{ + Q_D(QQuickAbstractScrollIndicator); + if (d->active != active) { + d->active = active; + emit activeChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::ScrollIndicator::orientation + + TODO +*/ +Qt::Orientation QQuickAbstractScrollIndicator::orientation() const +{ + Q_D(const QQuickAbstractScrollIndicator); + return d->orientation; +} + +void QQuickAbstractScrollIndicator::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickAbstractScrollIndicator); + if (d->orientation != orientation) { + d->orientation = orientation; + emit orientationChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ScrollIndicator::indicator + + TODO +*/ +QQuickItem *QQuickAbstractScrollIndicator::indicator() const +{ + Q_D(const QQuickAbstractScrollIndicator); + return d->indicator; +} + +void QQuickAbstractScrollIndicator::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickAbstractScrollIndicator); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); + } +} + +class QQuickScrollIndicatorAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener +{ +public: + QQuickScrollIndicatorAttachedPrivate(QQuickFlickable *flickable) : flickable(flickable), horizontal(Q_NULLPTR), vertical(Q_NULLPTR) { } + + void activateHorizontal(); + void activateVertical(); + + void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + + QQuickFlickable *flickable; + QQuickAbstractScrollIndicator *horizontal; + QQuickAbstractScrollIndicator *vertical; +}; + +void QQuickScrollIndicatorAttachedPrivate::activateHorizontal() +{ + horizontal->setActive(flickable->isMovingHorizontally()); +} + +void QQuickScrollIndicatorAttachedPrivate::activateVertical() +{ + vertical->setActive(flickable->isMovingVertically()); +} + +void QQuickScrollIndicatorAttachedPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_ASSERT(item == flickable); + if (horizontal) { + QQuickItemPrivate *p = QQuickItemPrivate::get(horizontal); + if (!p->widthValid || qFuzzyCompare(horizontal->width(), oldGeometry.width())) + horizontal->setWidth(newGeometry.width()); + if (qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), oldGeometry.height() - horizontal->height())) + horizontal->setY(newGeometry.height() - horizontal->height()); + } + if (vertical) { + QQuickItemPrivate *p = QQuickItemPrivate::get(vertical); + if (!p->heightValid || qFuzzyCompare(vertical->height(), oldGeometry.height())) + vertical->setHeight(newGeometry.height()); + if (!p->isMirrored() && (qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), oldGeometry.width() - vertical->width()))) + vertical->setX(newGeometry.width() - vertical->width()); + } +} + +QQuickScrollIndicatorAttached::QQuickScrollIndicatorAttached(QQuickFlickable *flickable) : + QObject(*(new QQuickScrollIndicatorAttachedPrivate(flickable)), flickable) +{ + Q_D(QQuickScrollIndicatorAttached); + QQuickItemPrivate *p = QQuickItemPrivate::get(flickable); + p->addItemChangeListener(d, QQuickItemPrivate::Geometry); +} + +QQuickAbstractScrollIndicator *QQuickScrollIndicatorAttached::horizontal() const +{ + Q_D(const QQuickScrollIndicatorAttached); + return d->horizontal; +} + +void QQuickScrollIndicatorAttached::setHorizontal(QQuickAbstractScrollIndicator *horizontal) +{ + Q_D(QQuickScrollIndicatorAttached); + if (d->horizontal != horizontal) { + if (d->horizontal) { + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); + } + + d->horizontal = horizontal; + + if (horizontal) { + if (!horizontal->parentItem()) + horizontal->setParentItem(d->flickable); + horizontal->setOrientation(Qt::Horizontal); + + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); + connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); + + horizontal->setSize(area->property("widthRatio").toReal()); + horizontal->setPosition(area->property("xPosition").toReal()); + } + emit horizontalChanged(); + } +} + +QQuickAbstractScrollIndicator *QQuickScrollIndicatorAttached::vertical() const +{ + Q_D(const QQuickScrollIndicatorAttached); + return d->vertical; +} + +void QQuickScrollIndicatorAttached::setVertical(QQuickAbstractScrollIndicator *vertical) +{ + Q_D(QQuickScrollIndicatorAttached); + if (d->vertical != vertical) { + if (d->vertical) { + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); + } + + d->vertical = vertical; + + if (vertical) { + if (!vertical->parentItem()) + vertical->setParentItem(d->flickable); + vertical->setOrientation(Qt::Vertical); + + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); + connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); + + vertical->setSize(area->property("heightRatio").toReal()); + vertical->setPosition(area->property("yPosition").toReal()); + } + emit verticalChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractscrollindicator_p.h b/src/controls/qquickabstractscrollindicator_p.h new file mode 100644 index 00000000..a26b650e --- /dev/null +++ b/src/controls/qquickabstractscrollindicator_p.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTSCROLLINDICATOR_P_H +#define QQUICKABSTRACTSCROLLINDICATOR_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickFlickable; +class QQuickScrollIndicatorAttached; +class QQuickAbstractScrollIndicatorPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractScrollIndicator : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal size READ size NOTIFY sizeChanged FINAL) + Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + +public: + explicit QQuickAbstractScrollIndicator(QQuickItem *parent = Q_NULLPTR); + + static QQuickScrollIndicatorAttached *qmlAttachedProperties(QObject *object); + + qreal size() const; + qreal position() const; + + bool isActive() const; + void setActive(bool active); + + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + +public Q_SLOTS: + void setSize(qreal size); + void setPosition(qreal position); + +Q_SIGNALS: + void sizeChanged(); + void positionChanged(); + void activeChanged(); + void orientationChanged(); + void indicatorChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractScrollIndicator) + Q_DECLARE_PRIVATE(QQuickAbstractScrollIndicator) +}; + +class QQuickScrollIndicatorAttachedPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickScrollIndicatorAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickAbstractScrollIndicator *horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged FINAL) + Q_PROPERTY(QQuickAbstractScrollIndicator *vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL) + +public: + explicit QQuickScrollIndicatorAttached(QQuickFlickable *flickable); + + QQuickAbstractScrollIndicator *horizontal() const; + void setHorizontal(QQuickAbstractScrollIndicator *horizontal); + + QQuickAbstractScrollIndicator *vertical() const; + void setVertical(QQuickAbstractScrollIndicator *vertical); + +Q_SIGNALS: + void horizontalChanged(); + void verticalChanged(); + +private: + Q_DISABLE_COPY(QQuickScrollIndicatorAttached) + Q_DECLARE_PRIVATE(QQuickScrollIndicatorAttached) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickAbstractScrollIndicator, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKABSTRACTSCROLLINDICATOR_P_H diff --git a/src/controls/qquickabstractslider.cpp b/src/controls/qquickabstractslider.cpp new file mode 100644 index 00000000..52fa11af --- /dev/null +++ b/src/controls/qquickabstractslider.cpp @@ -0,0 +1,454 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractslider_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquickwindow_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Slider + \inherits Control + \instantiates QQuickAbstractSlider + \inqmlmodule QtQuick.Controls + \ingroup sliders + \brief A slider control. + + TODO +*/ + +class QQuickAbstractSliderPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractSlider) + +public: + QQuickAbstractSliderPrivate() : value(0), position(0), stepSize(0), + pressed(false), orientation(Qt::Horizontal), layoutDirection(Qt::LeftToRight), + snapMode(QQuickAbstractSlider::NoSnap), handle(Q_NULLPTR), track(Q_NULLPTR) { } + + qreal snapPosition(qreal position) const; + qreal positionAt(const QPoint &point) const; + + qreal value; + qreal position; + qreal stepSize; + bool pressed; + QPoint pressPoint; + Qt::Orientation orientation; + Qt::LayoutDirection layoutDirection; + QQuickAbstractSlider::SnapMode snapMode; + QQuickItem *handle; + QQuickItem *track; +}; + +qreal QQuickAbstractSliderPrivate::snapPosition(qreal position) const +{ + if (qFuzzyIsNull(stepSize)) + return position; + return qRound(position / stepSize) * stepSize; +} + +qreal QQuickAbstractSliderPrivate::positionAt(const QPoint &point) const +{ + Q_Q(const QQuickAbstractSlider); + if (orientation == Qt::Horizontal) { + const qreal hw = handle ? handle->width() : 0; + const qreal offset = hw / 2; + const qreal extent = q->width() - hw; + if (!qFuzzyIsNull(extent)) { + const qreal pos = (point.x() - offset) / extent; + if (q->effectiveLayoutDirection() == Qt::RightToLeft) + return 1.0 - pos; + return pos; + } + } else { + const qreal hh = handle ? handle->height() : 0; + const qreal offset = hh / 2; + const qreal extent = q->height() - hh; + if (!qFuzzyIsNull(extent)) + return (point.y() - offset) / extent; + } + return 0; +} + +QQuickAbstractSlider::QQuickAbstractSlider(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractSliderPrivate), parent) +{ + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +/*! + \qmlproperty real QtQuickControls2::Slider::value + + TODO +*/ +qreal QQuickAbstractSlider::value() const +{ + Q_D(const QQuickAbstractSlider); + return d->value; +} + +void QQuickAbstractSlider::setValue(qreal value) +{ + Q_D(QQuickAbstractSlider); + value = qBound(0.0, value, 1.0); + if (!qFuzzyCompare(d->value, value)) { + d->value = value; + setPosition(value); + emit valueChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::Slider::position + + TODO +*/ +qreal QQuickAbstractSlider::position() const +{ + Q_D(const QQuickAbstractSlider); + return d->position; +} + +/*! + \qmlproperty real QtQuickControls2::Slider::visualPosition + + TODO +*/ +qreal QQuickAbstractSlider::visualPosition() const +{ + Q_D(const QQuickAbstractSlider); + if (d->orientation == Qt::Vertical || effectiveLayoutDirection() == Qt::RightToLeft) + return 1.0 - d->position; + return d->position; +} + +void QQuickAbstractSlider::setPosition(qreal position) +{ + Q_D(QQuickAbstractSlider); + position = qBound(0.0, position, 1.0); + if (!qFuzzyCompare(d->position, position)) { + d->position = position; + emit positionChanged(); + emit visualPositionChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::Slider::stepSize + + TODO +*/ +qreal QQuickAbstractSlider::stepSize() const +{ + Q_D(const QQuickAbstractSlider); + return d->stepSize; +} + +void QQuickAbstractSlider::setStepSize(qreal step) +{ + Q_D(QQuickAbstractSlider); + if (!qFuzzyCompare(d->stepSize, step)) { + d->stepSize = step; + emit stepSizeChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::Slider::snapMode + + TODO +*/ +QQuickAbstractSlider::SnapMode QQuickAbstractSlider::snapMode() const +{ + Q_D(const QQuickAbstractSlider); + return d->snapMode; +} + +void QQuickAbstractSlider::setSnapMode(SnapMode mode) +{ + Q_D(QQuickAbstractSlider); + if (d->snapMode != mode) { + d->snapMode = mode; + emit snapModeChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::Slider::pressed + + TODO +*/ +bool QQuickAbstractSlider::isPressed() const +{ + Q_D(const QQuickAbstractSlider); + return d->pressed; +} + +void QQuickAbstractSlider::setPressed(bool pressed) +{ + Q_D(QQuickAbstractSlider); + if (d->pressed != pressed) { + d->pressed = pressed; + emit pressedChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::Slider::orientation + + TODO +*/ +Qt::Orientation QQuickAbstractSlider::orientation() const +{ + Q_D(const QQuickAbstractSlider); + return d->orientation; +} + +void QQuickAbstractSlider::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickAbstractSlider); + if (d->orientation != orientation) { + d->orientation = orientation; + emit orientationChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::Slider::layoutDirection + + TODO +*/ +Qt::LayoutDirection QQuickAbstractSlider::layoutDirection() const +{ + Q_D(const QQuickAbstractSlider); + return d->layoutDirection; +} + +/*! + \qmlproperty enumeration QtQuickControls2::Slider::effectiveLayoutDirection + + TODO +*/ +Qt::LayoutDirection QQuickAbstractSlider::effectiveLayoutDirection() const +{ + Q_D(const QQuickAbstractSlider); + if (isMirrored()) + return d->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; + return d->layoutDirection; +} + +void QQuickAbstractSlider::setLayoutDirection(Qt::LayoutDirection direction) +{ + Q_D(QQuickAbstractSlider); + if (d->layoutDirection != direction) { + d->layoutDirection = direction; + emit layoutDirectionChanged(); + emit effectiveLayoutDirectionChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Slider::handle + + TODO +*/ +QQuickItem *QQuickAbstractSlider::handle() const +{ + Q_D(const QQuickAbstractSlider); + return d->handle; +} + +void QQuickAbstractSlider::setHandle(QQuickItem *handle) +{ + Q_D(QQuickAbstractSlider); + if (d->handle != handle) { + delete d->handle; + d->handle = handle; + if (handle && !handle->parentItem()) + handle->setParentItem(this); + emit handleChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Slider::track + + TODO +*/ +QQuickItem *QQuickAbstractSlider::track() const +{ + Q_D(const QQuickAbstractSlider); + return d->track; +} + +void QQuickAbstractSlider::setTrack(QQuickItem *track) +{ + Q_D(QQuickAbstractSlider); + if (d->track != track) { + delete d->track; + d->track = track; + if (track && !track->parentItem()) + track->setParentItem(this); + emit trackChanged(); + } +} + +/*! + \qmlmethod void QtQuickControls2::Slider::increase() + + TODO +*/ +void QQuickAbstractSlider::increase() +{ + Q_D(QQuickAbstractSlider); + qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; + setValue(d->value + step); +} + +/*! + \qmlmethod void QtQuickControls2::Slider::decrease() + + TODO +*/ +void QQuickAbstractSlider::decrease() +{ + Q_D(QQuickAbstractSlider); + qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; + setValue(d->value - step); +} + +void QQuickAbstractSlider::keyPressEvent(QKeyEvent *event) +{ + Q_D(QQuickAbstractSlider); + QQuickControl::keyPressEvent(event); + if (d->orientation == Qt::Horizontal) { + if (event->key() == Qt::Key_Left) { + setPressed(true); + if (effectiveLayoutDirection() == Qt::RightToLeft) + increase(); + else + decrease(); + event->accept(); + } else if (event->key() == Qt::Key_Right) { + setPressed(true); + if (effectiveLayoutDirection() == Qt::RightToLeft) + decrease(); + else + increase(); + event->accept(); + } + } else { + if (event->key() == Qt::Key_Up) { + setPressed(true); + increase(); + event->accept(); + } else if (event->key() == Qt::Key_Down) { + setPressed(true); + decrease(); + event->accept(); + } + } +} + +void QQuickAbstractSlider::keyReleaseEvent(QKeyEvent *event) +{ + QQuickControl::keyReleaseEvent(event); + setPressed(false); +} + +void QQuickAbstractSlider::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractSlider); + QQuickControl::mousePressEvent(event); + d->pressPoint = event->pos(); + setPressed(true); + event->accept(); +} + +void QQuickAbstractSlider::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractSlider); + QQuickControl::mouseMoveEvent(event); + if (!keepMouseGrab()) { + if (d->orientation == Qt::Horizontal) + setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->pos().x() - d->pressPoint.x(), Qt::XAxis, event)); + else + setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->pos().y() - d->pressPoint.y(), Qt::YAxis, event)); + } + if (keepMouseGrab()) { + qreal pos = d->positionAt(event->pos()); + if (d->snapMode == SnapAlways) + pos = d->snapPosition(pos); + setPosition(pos); + } + event->accept(); +} + +void QQuickAbstractSlider::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractSlider); + QQuickControl::mouseReleaseEvent(event); + d->pressPoint = QPoint(); + if (keepMouseGrab()) { + qreal pos = d->positionAt(event->pos()); + if (d->snapMode != NoSnap) + pos = d->snapPosition(pos); + setValue(pos); + setKeepMouseGrab(false); + } + setPressed(false); + event->accept(); +} + +void QQuickAbstractSlider::mouseUngrabEvent() +{ + Q_D(QQuickAbstractSlider); + QQuickControl::mouseUngrabEvent(); + d->pressPoint = QPoint(); + setPressed(false); +} + +void QQuickAbstractSlider::mirrorChange() +{ + emit effectiveLayoutDirectionChanged(); + emit visualPositionChanged(); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractslider_p.h b/src/controls/qquickabstractslider_p.h new file mode 100644 index 00000000..6b962aca --- /dev/null +++ b/src/controls/qquickabstractslider_p.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTSLIDER_P_H +#define QQUICKABSTRACTSLIDER_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractSliderPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractSlider : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) + Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL) + Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) + Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) + Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL) + Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) + Q_PROPERTY(QQuickItem *track READ track WRITE setTrack NOTIFY trackChanged FINAL) + Q_ENUMS(SnapMode) + +public: + explicit QQuickAbstractSlider(QQuickItem *parent = Q_NULLPTR); + + qreal value() const; + void setValue(qreal value); + + qreal position() const; + qreal visualPosition() const; + void setPosition(qreal position); + + qreal stepSize() const; + void setStepSize(qreal step); + + enum SnapMode { + NoSnap, + SnapAlways, + SnapOnRelease + }; + + SnapMode snapMode() const; + void setSnapMode(SnapMode mode); + + bool isPressed() const; + void setPressed(bool pressed); + + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + + Qt::LayoutDirection layoutDirection() const; + Qt::LayoutDirection effectiveLayoutDirection() const; + void setLayoutDirection(Qt::LayoutDirection direction); + + QQuickItem *handle() const; + void setHandle(QQuickItem *handle); + + QQuickItem *track() const; + void setTrack(QQuickItem *track); + +public Q_SLOTS: + void increase(); + void decrease(); + +Q_SIGNALS: + void valueChanged(); + void positionChanged(); + void visualPositionChanged(); + void stepSizeChanged(); + void snapModeChanged(); + void pressedChanged(); + void orientationChanged(); + void layoutDirectionChanged(); + void effectiveLayoutDirectionChanged(); + void handleChanged(); + void trackChanged(); + +protected: + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseUngrabEvent() Q_DECL_OVERRIDE; + void mirrorChange() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractSlider) + Q_DECLARE_PRIVATE(QQuickAbstractSlider) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTSLIDER_P_H diff --git a/src/controls/qquickabstractspinbox.cpp b/src/controls/qquickabstractspinbox.cpp new file mode 100644 index 00000000..442e479c --- /dev/null +++ b/src/controls/qquickabstractspinbox.cpp @@ -0,0 +1,300 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractspinbox_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquicktextinput_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractSpinBoxPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractSpinBox) + +public: + QQuickAbstractSpinBoxPrivate() : value(0), step(1), input(Q_NULLPTR), validator(Q_NULLPTR), + upButton(Q_NULLPTR), downButton(Q_NULLPTR), pressed(QQuickAbstractSpinBox::None) { } + + void updateText(); + void updateValue(); + + qreal value; + qreal step; + QQuickTextInput *input; + QValidator *validator; + QQuickItem *upButton; + QQuickItem *downButton; + QQuickAbstractSpinBox::SubControl pressed; +}; + +void QQuickAbstractSpinBoxPrivate::updateText() +{ + if (input) { + QString text = QString::number(value); + if (validator) { + validator->fixup(text); + int cursor = input->cursorPosition(); + if (validator->validate(text, cursor) == QValidator::Acceptable) + input->setCursorPosition(cursor); + input->setText(text); + } + } +} + +void QQuickAbstractSpinBoxPrivate::updateValue() +{ + Q_Q(QQuickAbstractSpinBox); + if (validator) { + QString text = input->text(); + validator->fixup(text); + int cursor = input->cursorPosition(); + if (validator->validate(text, cursor) == QValidator::Acceptable) + q->setValue(text.toDouble()); + } +} + +QQuickAbstractSpinBox::QQuickAbstractSpinBox(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractSpinBoxPrivate), parent) +{ + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +qreal QQuickAbstractSpinBox::value() const +{ + Q_D(const QQuickAbstractSpinBox); + return d->value; +} + +void QQuickAbstractSpinBox::setValue(qreal value) +{ + Q_D(QQuickAbstractSpinBox); + if (!qFuzzyCompare(d->value, value)) { + d->value = value; + d->updateText(); + emit valueChanged(); + } +} + +qreal QQuickAbstractSpinBox::step() const +{ + Q_D(const QQuickAbstractSpinBox); + return d->step; +} + +void QQuickAbstractSpinBox::setStep(qreal step) +{ + Q_D(QQuickAbstractSpinBox); + if (!qFuzzyCompare(d->step, step)) { + d->step = step; + emit stepChanged(); + } +} + +QQuickTextInput *QQuickAbstractSpinBox::input() const +{ + Q_D(const QQuickAbstractSpinBox); + return d->input; +} + +void QQuickAbstractSpinBox::setInput(QQuickTextInput *input) +{ + Q_D(QQuickAbstractSpinBox); + if (d->input != input) { + delete d->input; + d->input = input; + if (input) { + if (!input->parentItem()) + input->setParentItem(this); + input->setValidator(d->validator); + input->setFocus(true); + QObjectPrivate::connect(input, &QQuickTextInput::textChanged, d, &QQuickAbstractSpinBoxPrivate::updateValue); + } + emit inputChanged(); + } +} + +QValidator *QQuickAbstractSpinBox::validator() const +{ + Q_D(const QQuickAbstractSpinBox); + return d->validator; +} + +void QQuickAbstractSpinBox::setValidator(QValidator *validator) +{ + Q_D(QQuickAbstractSpinBox); + if (d->validator != validator) { + delete d->validator; + d->validator = validator; + if (d->input) + d->input->setValidator(validator); + emit validatorChanged(); + } +} + +QQuickItem *QQuickAbstractSpinBox::upButton() const +{ + Q_D(const QQuickAbstractSpinBox); + return d->upButton; +} + +void QQuickAbstractSpinBox::setUpButton(QQuickItem *button) +{ + Q_D(QQuickAbstractSpinBox); + if (d->upButton != button) { + delete d->upButton; + d->upButton = button; + if (button && !button->parentItem()) + button->setParentItem(this); + emit upButtonChanged(); + } +} + +QQuickItem *QQuickAbstractSpinBox::downButton() const +{ + Q_D(const QQuickAbstractSpinBox); + return d->downButton; +} + +void QQuickAbstractSpinBox::setDownButton(QQuickItem *button) +{ + Q_D(QQuickAbstractSpinBox); + if (d->downButton != button) { + delete d->downButton; + d->downButton = button; + if (button && !button->parentItem()) + button->setParentItem(this); + emit downButtonChanged(); + } +} + +QQuickAbstractSpinBox::SubControl QQuickAbstractSpinBox::pressed() const +{ + Q_D(const QQuickAbstractSpinBox); + return d->pressed; +} + +void QQuickAbstractSpinBox::setPressed(SubControl control) +{ + Q_D(QQuickAbstractSpinBox); + if (d->pressed != control) { + d->pressed = control; + emit pressedChanged(); + } +} + +void QQuickAbstractSpinBox::increment() +{ + Q_D(QQuickAbstractSpinBox); + setValue(d->value + d->step); +} + +void QQuickAbstractSpinBox::decrement() +{ + Q_D(QQuickAbstractSpinBox); + setValue(d->value - d->step); +} + +void QQuickAbstractSpinBox::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Up: + increment(); + event->accept(); + break; + case Qt::Key_Down: + decrement(); + event->accept(); + break; + default: + event->ignore(); + break; + } +} + +void QQuickAbstractSpinBox::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractSpinBox); + QQuickControl::mousePressEvent(event); + if (d->upButton && d->upButton->contains(mapToItem(d->upButton, event->pos()))) + setPressed(UpButton); + else if (d->downButton && d->downButton->contains(mapToItem(d->downButton, event->pos()))) + setPressed(DownButton); + else + setPressed(None); + event->accept(); +} + +void QQuickAbstractSpinBox::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractSpinBox); + QQuickControl::mouseMoveEvent(event); + if (d->upButton && d->upButton->contains(mapToItem(d->upButton, event->pos()))) + setPressed(UpButton); + else if (d->downButton && d->downButton->contains(mapToItem(d->downButton, event->pos()))) + setPressed(DownButton); + else + setPressed(None); + event->accept(); +} + +void QQuickAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractSpinBox); + QQuickControl::mouseReleaseEvent(event); + if (d->pressed == UpButton) + increment(); + else if (d->pressed == DownButton) + decrement(); + setPressed(None); + event->accept(); +} + +void QQuickAbstractSpinBox::mouseUngrabEvent() +{ + setPressed(None); +} + +void QQuickAbstractSpinBox::componentComplete() +{ + Q_D(QQuickAbstractSpinBox); + QQuickControl::componentComplete(); + d->updateText(); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractspinbox_p.h b/src/controls/qquickabstractspinbox_p.h new file mode 100644 index 00000000..e4585bcb --- /dev/null +++ b/src/controls/qquickabstractspinbox_p.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTSPINBOX_P_H +#define QQUICKABSTRACTSPINBOX_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QValidator; +class QQuickTextInput; +class QQuickAbstractSpinBoxPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractSpinBox : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) + Q_PROPERTY(qreal step READ step WRITE setStep NOTIFY stepChanged FINAL) + Q_PROPERTY(QQuickTextInput *input READ input WRITE setInput NOTIFY inputChanged FINAL) + Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL) + Q_PROPERTY(QQuickItem *upButton READ upButton WRITE setUpButton NOTIFY upButtonChanged FINAL) + Q_PROPERTY(QQuickItem *downButton READ downButton WRITE setDownButton NOTIFY downButtonChanged FINAL) + Q_PROPERTY(SubControl pressed READ pressed WRITE setPressed NOTIFY pressedChanged FINAL) + Q_ENUMS(SubControl) + +public: + explicit QQuickAbstractSpinBox(QQuickItem *parent = Q_NULLPTR); + + qreal value() const; + void setValue(qreal value); + + qreal step() const; + void setStep(qreal step); + + QQuickTextInput *input() const; + void setInput(QQuickTextInput *input); + + QValidator *validator() const; + void setValidator(QValidator *validator); + + QQuickItem *upButton() const; + void setUpButton(QQuickItem *button); + + QQuickItem *downButton() const; + void setDownButton(QQuickItem *button); + + enum SubControl { + None, + UpButton, + DownButton + }; + + SubControl pressed() const; + void setPressed(SubControl control); + +public Q_SLOTS: + void increment(); + void decrement(); + +Q_SIGNALS: + void valueChanged(); + void stepChanged(); + void inputChanged(); + void validatorChanged(); + void upButtonChanged(); + void downButtonChanged(); + void pressedChanged(); + +protected: + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseUngrabEvent() Q_DECL_OVERRIDE; + + void componentComplete() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractSpinBox) + Q_DECLARE_PRIVATE(QQuickAbstractSpinBox) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTSPINBOX_P_H diff --git a/src/controls/qquickabstractstackview.cpp b/src/controls/qquickabstractstackview.cpp new file mode 100644 index 00000000..3775e180 --- /dev/null +++ b/src/controls/qquickabstractstackview.cpp @@ -0,0 +1,352 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractstackview_p.h" +#include "qquickabstractcontainer_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype StackView + \inherits Container + \instantiates QQuickAbstractStackView + \inqmlmodule QtQuick.Controls + \ingroup navigation + \brief A stack view control. + + TODO +*/ + +class QQuickStackElement +{ + QQuickStackElement() : ownItem(false), item(Q_NULLPTR), ownComponent(false), component(Q_NULLPTR) { } + +public: + static QQuickStackElement *fromString(const QString &str, QQmlEngine *engine, QObject *parent) + { + QQuickStackElement *element = new QQuickStackElement; + element->component = new QQmlComponent(engine, QUrl(str), parent); + element->ownComponent = true; + return element; + } + + static QQuickStackElement *fromObject(QObject *object) + { + QQuickStackElement *element = new QQuickStackElement; + element->component = qobject_cast<QQmlComponent *>(object); + element->item = qobject_cast<QQuickItem *>(object); + return element; + } + + bool ownItem; + QQuickItem *item; + + bool ownComponent; + QQmlComponent *component; +}; + +class QQuickAbstractStackViewPrivate : public QQuickAbstractContainerPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractStackView) + +public: + QQuickAbstractStackViewPrivate() : busy(false), depth(0), currentItem(Q_NULLPTR) { } + + void setBusy(bool busy); + void setDepth(int depth); + void setCurrentItem(QQuickItem *item); + + QList<QQuickStackElement *> createElements(const QV4::ScopedValue &value); + QQuickItem *pushElements(const QList<QQuickStackElement *> &elements, QQuickAbstractStackView::Operation operation); + + bool busy; + int depth; + QVariant initialItem; + QQuickItem *currentItem; + QStack<QQuickStackElement *> elements; +}; + +void QQuickAbstractStackViewPrivate::setBusy(bool value) +{ + Q_Q(QQuickAbstractStackView); + if (busy != value) { + busy = value; + emit q->busyChanged(); + } +} + +void QQuickAbstractStackViewPrivate::setDepth(int value) +{ + Q_Q(QQuickAbstractStackView); + if (depth != value) { + depth = value; + emit q->depthChanged(); + } +} + +void QQuickAbstractStackViewPrivate::setCurrentItem(QQuickItem *item) +{ + Q_Q(QQuickAbstractStackView); + if (currentItem != item) { + currentItem = item; + emit q->currentItemChanged(); + } +} + +QList<QQuickStackElement *> QQuickAbstractStackViewPrivate::createElements(const QV4::ScopedValue &value) +{ + Q_Q(QQuickAbstractStackView); + QList<QQuickStackElement *> elements; + if (QV4::String *s = value->asString()) { + qDebug() << "### STRING:" << s->toQString(); + elements += QQuickStackElement::fromString(s->toQString(), qmlEngine(q), q); + } else if (QV4::ArrayObject *a = value->asArrayObject()) { + int len = a->getLength(); + qDebug() << "### ARRAY:" << len; + for (int i = 0; i < len; ++i) { + QV4::Scope scope(a->engine()); + QV4::ScopedValue v(scope, a->getIndexed(i)); + elements += createElements(v); + } + } else if (QV4::QObjectWrapper *o =value->as<QV4::QObjectWrapper>()) { + qDebug() << "### QOBJECT:" << o->object(); + elements += QQuickStackElement::fromObject(o->object()); + } else { + qDebug("### UNKNOWN"); + } + return elements; +} + +QQuickItem *QQuickAbstractStackViewPrivate::pushElements(const QList<QQuickStackElement *> &elems, QQuickAbstractStackView::Operation operation) +{ + Q_Q(QQuickAbstractStackView); + Q_UNUSED(operation); // TODO + if (!elems.isEmpty()) { + foreach (QQuickStackElement *elem, elems) { + elements.push(elem); + } + emit q->depthChanged(); + // TODO: load + return elems.last()->item; + } + return Q_NULLPTR; +} + +QQuickAbstractStackView::QQuickAbstractStackView(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractStackViewPrivate), parent) +{ + setFlag(ItemIsFocusScope); +} + +QQuickAbstractStackView::~QQuickAbstractStackView() +{ + Q_D(QQuickAbstractStackView); + qDeleteAll(d->elements); +} + +/*! + \qmlproperty bool QtQuickControls2::StackView::busy + \readonly + \c true if a transition is running, and \c false otherwise. +*/ +bool QQuickAbstractStackView::busy() const +{ + Q_D(const QQuickAbstractStackView); + return d->busy; +} + +// TODO: remove +void QQuickAbstractStackView::setBusy(bool busy) +{ + Q_D(QQuickAbstractStackView); + d->setBusy(busy); +} + +/*! + \qmlproperty int QtQuickControls2::StackView::depth + \readonly + The number of items currently pushed onto the stack. +*/ +int QQuickAbstractStackView::depth() const +{ + Q_D(const QQuickAbstractStackView); + return d->depth; +} + +// TODO: remove +void QQuickAbstractStackView::setDepth(int depth) +{ + Q_D(QQuickAbstractStackView); + d->setDepth(depth); +} + +/*! + \qmlproperty Item QtQuickControls2::StackView::currentItem + \readonly + The currently top-most item in the stack. +*/ +QQuickItem *QQuickAbstractStackView::currentItem() const +{ + Q_D(const QQuickAbstractStackView); + return d->currentItem; +} + +// TODO: remove +void QQuickAbstractStackView::setCurrentItem(QQuickItem *item) +{ + Q_D(QQuickAbstractStackView); + d->setCurrentItem(item); +} + +QQuickItem *QQuickAbstractStackView::qpush(QQmlV4Function *args) +{ + Q_D(QQuickAbstractStackView); + QV4::ExecutionEngine *v4 = args->v4engine(); + QV4::Scope scope(v4); + + Operation operation = d->elements.isEmpty() ? Immediate : Transition; + QList<QQuickStackElement *> elements; + for (int i = 0; i < args->length(); ++i) { + QV4::ScopedValue value(scope, (*args)[i]); + if (value->isInt32()) + operation = static_cast<Operation>(value->toInt32()); + else + elements += d->createElements(value); + } + return d->pushElements(elements, operation); +} + +QQuickItem *QQuickAbstractStackView::qpop(QQmlV4Function *args) +{ + Q_UNUSED(args); // TODO + return Q_NULLPTR; +} + +void QQuickAbstractStackView::qclear() +{ + // TODO +} + +/*! + \qmlproperty var QtQuickControls2::StackView::initialItem + + The first \l item that should be shown when the StackView is created. + \a initialItem can take same value as the first argument to \l{StackView::push()} + {StackView.push()}. Note that this is just a convenience for writing + \c{Component.onCompleted: stackView.push(myInitialItem)} + + Examples: + + \list + \li initialItem: Qt.resolvedUrl("MyItem.qml") + \li initialItem: myItem + \li initialItem: {"item" : Qt.resolvedUrl("MyRectangle.qml"), "properties" : {"color" : "red"}} + \endlist + \sa push +*/ +QVariant QQuickAbstractStackView::initialItem() const +{ + Q_D(const QQuickAbstractStackView); + return d->initialItem; +} + +void QQuickAbstractStackView::setInitialItem(const QVariant &item) +{ + Q_D(QQuickAbstractStackView); + d->initialItem = item; +} + +void QQuickAbstractStackView::componentComplete() +{ + QQuickAbstractContainer::componentComplete(); + + Q_D(QQuickAbstractStackView); + if (QObject *o = d->initialItem.value<QObject *>()) + d->pushElements(QList<QQuickStackElement *>() << QQuickStackElement::fromObject(o), Immediate); + else if (d->initialItem.canConvert<QString>()) + d->pushElements(QList<QQuickStackElement *>() << QQuickStackElement::fromString(d->initialItem.toString(), qmlEngine(this), this), Immediate); +} + +/*! + \qmltype Stack + \inherits QtObject + \instantiates QQuickStackAttached + \inqmlmodule QtQuick.Controls + \ingroup navigation + \brief TODO + + TODO +*/ + +class QQuickStackAttachedPrivate : public QObjectPrivate +{ +public: + QQuickStackAttachedPrivate() : status(QQuickStackAttached::Inactive) { } + + QQuickStackAttached::Status status; +}; + +QQuickStackAttached::QQuickStackAttached(QObject *parent) : + QObject(*(new QQuickStackAttachedPrivate), parent) +{ +} + +QQuickStackAttached *QQuickStackAttached::qmlAttachedProperties(QObject *object) +{ + return new QQuickStackAttached(object); +} + +/*! + \qmlattachedproperty enumeration QtQuickControls2::Stack::status + + TODO +*/ +QQuickStackAttached::Status QQuickStackAttached::status() const +{ + Q_D(const QQuickStackAttached); + return d->status; +} + +void QQuickStackAttached::setStatus(Status status) +{ + Q_D(QQuickStackAttached); + if (d->status != status) { + d->status = status; + emit statusChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractstackview_p.h b/src/controls/qquickabstractstackview_p.h new file mode 100644 index 00000000..93545cd1 --- /dev/null +++ b/src/controls/qquickabstractstackview_p.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTSTACKVIEW_P_H +#define QQUICKABSTRACTSTACKVIEW_P_H + +#include <QtQuickControls/private/qquickabstractcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class QQmlV4Function; +class QQuickAbstractStackViewPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractStackView : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged FINAL) // TODO: hide setBusy + Q_PROPERTY(int depth READ depth WRITE setDepth NOTIFY depthChanged FINAL) // TODO: hide setDepth + Q_PROPERTY(QQuickItem *currentItem READ currentItem WRITE setCurrentItem NOTIFY currentItemChanged FINAL) // TODO: hide setCurrentItem + Q_PROPERTY(QVariant initialItem READ initialItem WRITE setInitialItem FINAL) + Q_ENUMS(Operation) + +public: + explicit QQuickAbstractStackView(QQuickItem *parent = Q_NULLPTR); + ~QQuickAbstractStackView(); + + bool busy() const; + void setBusy(bool busy); // TODO: hide + + int depth() const; + void setDepth(int depth); // TODO: hide + + QQuickItem *currentItem() const; + void setCurrentItem(QQuickItem *item); // TODO: hide + + QVariant initialItem() const; + void setInitialItem(const QVariant &item); + + enum Operation { + Transition, + Immediate + }; + + Q_INVOKABLE QQuickItem *qpush(QQmlV4Function *args); + Q_INVOKABLE QQuickItem *qpop(QQmlV4Function *args); + +public Q_SLOTS: + void qclear(); + +Q_SIGNALS: + void busyChanged(); + void depthChanged(); + void currentItemChanged(); + +protected: + void componentComplete() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractStackView) + Q_DECLARE_PRIVATE(QQuickAbstractStackView) +}; + +class QQuickStackAttachedPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickStackAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) + Q_ENUMS(Status) + +public: + explicit QQuickStackAttached(QObject *parent = Q_NULLPTR); + + static QQuickStackAttached *qmlAttachedProperties(QObject *object); + + enum Status { + Inactive = 0, + Deactivating = 1, + Activating = 2, + Active = 3 + }; + + Status status() const; + void setStatus(Status status); + +Q_SIGNALS: + void statusChanged(); + +private: + Q_DISABLE_COPY(QQuickStackAttached) + Q_DECLARE_PRIVATE(QQuickStackAttached) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickStackAttached, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKABSTRACTSTACKVIEW_P_H diff --git a/src/controls/qquickabstractswitch.cpp b/src/controls/qquickabstractswitch.cpp new file mode 100644 index 00000000..0251a887 --- /dev/null +++ b/src/controls/qquickabstractswitch.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstractswitch_p.h" +#include "qquickabstractcheckable_p_p.h" + +#include <QtQuick/private/qquickwindow_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Switch + \inherits Checkable + \instantiates QQuickAbstractSwitch + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A switch control. + + TODO +*/ + +class QQuickAbstractSwitchPrivate : public QQuickAbstractCheckablePrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractSwitch) + +public: + QQuickAbstractSwitchPrivate() : position(0) { } + + void updatePosition(); + + qreal position; + QPoint pressPoint; +}; + +void QQuickAbstractSwitchPrivate::updatePosition() +{ + Q_Q(QQuickAbstractSwitch); + q->setPosition(checked ? 1.0 : 0.0); +} + +QQuickAbstractSwitch::QQuickAbstractSwitch(QQuickItem *parent) : + QQuickAbstractCheckable(*(new QQuickAbstractSwitchPrivate), parent) +{ + setFiltersChildMouseEvents(true); + QObjectPrivate::connect(this, &QQuickAbstractCheckable::checkedChanged, d_func(), &QQuickAbstractSwitchPrivate::updatePosition); +} + +/*! + \qmlproperty real QtQuickControls2::Switch::position + + TODO +*/ +qreal QQuickAbstractSwitch::position() const +{ + Q_D(const QQuickAbstractSwitch); + return d->position; +} + +void QQuickAbstractSwitch::setPosition(qreal position) +{ + Q_D(QQuickAbstractSwitch); + position = qBound(0.0, position, 1.0); + if (d->position != position) { + d->position = position; + emit positionChanged(); + emit visualPositionChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::Switch::visualPosition + + TODO +*/ +qreal QQuickAbstractSwitch::visualPosition() const +{ + Q_D(const QQuickAbstractSwitch); + if (isMirrored()) + return 1.0 - d->position; + return d->position; +} + +void QQuickAbstractSwitch::mirrorChange() +{ + QQuickAbstractCheckable::mirrorChange(); + emit visualPositionChanged(); +} + +bool QQuickAbstractSwitch::childMouseEventFilter(QQuickItem *child, QEvent *event) +{ + if (child == indicator()) { + switch (event->type()) { + case QEvent::MouseButtonPress: + return handleMousePressEvent(child, static_cast<QMouseEvent *>(event)); + case QEvent::MouseMove: + return handleMouseMoveEvent(child, static_cast<QMouseEvent *>(event)); + case QEvent::MouseButtonRelease: + return handleMouseReleaseEvent(child, static_cast<QMouseEvent *>(event)); + case QEvent::UngrabMouse: + return handleMouseUngrabEvent(child); + default: + return false; + } + } + return false; +} + +bool QQuickAbstractSwitch::handleMousePressEvent(QQuickItem *child, QMouseEvent *event) +{ + Q_D(QQuickAbstractSwitch); + Q_UNUSED(child); + d->pressPoint = event->pos(); + setPressed(true); + event->accept(); + return true; +} + +bool QQuickAbstractSwitch::handleMouseMoveEvent(QQuickItem *child, QMouseEvent *event) +{ + Q_D(QQuickAbstractSwitch); + if (!child->keepMouseGrab()) + child->setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->pos().x() - d->pressPoint.x(), Qt::XAxis, event)); + if (child->keepMouseGrab()) { + setPosition(positionAt(event->pos())); + event->accept(); + } + return true; +} + +bool QQuickAbstractSwitch::handleMouseReleaseEvent(QQuickItem *child, QMouseEvent *event) +{ + Q_D(QQuickAbstractSwitch); + d->pressPoint = QPoint(); + setPressed(false); + if (child->keepMouseGrab()) { + setChecked(position() > 0.5); + setPosition(isChecked() ? 1.0 : 0.0); + child->setKeepMouseGrab(false); + } else { + emit clicked(); + toggle(); + } + event->accept(); + return true; +} + +bool QQuickAbstractSwitch::handleMouseUngrabEvent(QQuickItem *child) +{ + Q_D(QQuickAbstractSwitch); + Q_UNUSED(child); + d->pressPoint = QPoint(); + setChecked(position() > 0.5); + setPosition(isChecked() ? 1.0 : 0.0); + setPressed(false); + return true; +} + +qreal QQuickAbstractSwitch::positionAt(const QPoint &point) const +{ + qreal pos = point.x() / indicator()->width(); + if (isMirrored()) + return 1.0 - pos; + return pos; +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstractswitch_p.h b/src/controls/qquickabstractswitch_p.h new file mode 100644 index 00000000..7585d80f --- /dev/null +++ b/src/controls/qquickabstractswitch_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTSWITCH_P_H +#define QQUICKABSTRACTSWITCH_P_H + +#include <QtQuickControls/private/qquickabstractcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractSwitchPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractSwitch : public QQuickAbstractCheckable +{ + Q_OBJECT + Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) + Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) + +public: + explicit QQuickAbstractSwitch(QQuickItem *parent = Q_NULLPTR); + + qreal position() const; + void setPosition(qreal position); + + qreal visualPosition() const; + +Q_SIGNALS: + void positionChanged(); + void visualPositionChanged(); + +protected: + void mirrorChange() Q_DECL_OVERRIDE; + bool childMouseEventFilter(QQuickItem *child, QEvent *event) Q_DECL_OVERRIDE; + + bool handleMousePressEvent(QQuickItem *child, QMouseEvent *event); + bool handleMouseMoveEvent(QQuickItem *child, QMouseEvent *event); + bool handleMouseReleaseEvent(QQuickItem *child, QMouseEvent *event); + bool handleMouseUngrabEvent(QQuickItem *child); + + virtual qreal positionAt(const QPoint &point) const; + +private: + Q_DISABLE_COPY(QQuickAbstractSwitch) + Q_DECLARE_PRIVATE(QQuickAbstractSwitch) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTSWITCH_P_H diff --git a/src/controls/qquickabstracttabbar.cpp b/src/controls/qquickabstracttabbar.cpp new file mode 100644 index 00000000..2917a3b7 --- /dev/null +++ b/src/controls/qquickabstracttabbar.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstracttabbar_p.h" +#include "qquickabstractcontainer_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TabBar + \inherits Container + \instantiates QQuickAbstractTabBar + \inqmlmodule QtQuick.Controls + \ingroup tabs + \brief A tab bar control. + + TODO +*/ + +class QQuickAbstractTabBarPrivate : public QQuickAbstractContainerPrivate +{ +public: + QQuickAbstractTabBarPrivate() : currentIndex(0) { } + + int currentIndex; +}; + +QQuickAbstractTabBar::QQuickAbstractTabBar(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractTabBarPrivate), parent) +{ + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); +} + +/*! + \qmlproperty int QtQuickControls2::TabBar::currentIndex + + TODO +*/ +int QQuickAbstractTabBar::currentIndex() const +{ + Q_D(const QQuickAbstractTabBar); + return d->currentIndex; +} + +void QQuickAbstractTabBar::setCurrentIndex(int index) +{ + Q_D(QQuickAbstractTabBar); + if (d->currentIndex != index) { + d->currentIndex = index; + emit currentIndexChanged(index); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstracttabbar_p.h b/src/controls/qquickabstracttabbar_p.h new file mode 100644 index 00000000..30e97959 --- /dev/null +++ b/src/controls/qquickabstracttabbar_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTTABBAR_P_H +#define QQUICKABSTRACTTABBAR_P_H + +#include <QtQuickControls/private/qquickabstractcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractTabBarPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractTabBar : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) + +public: + explicit QQuickAbstractTabBar(QQuickItem *parent = Q_NULLPTR); + + int currentIndex() const; + +public Q_SLOTS: + void setCurrentIndex(int index); + +Q_SIGNALS: + void currentIndexChanged(int index); + +private: + Q_DISABLE_COPY(QQuickAbstractTabBar) + Q_DECLARE_PRIVATE(QQuickAbstractTabBar) + friend class QQuickAbstractTabView; +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTTABBAR_P_H diff --git a/src/controls/qquickabstracttabbutton.cpp b/src/controls/qquickabstracttabbutton.cpp new file mode 100644 index 00000000..df2b2c92 --- /dev/null +++ b/src/controls/qquickabstracttabbutton.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstracttabbutton_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TabButton + \inherits Checkable + \instantiates QQuickAbstractTabButton + \inqmlmodule QtQuick.Controls + \ingroup tabs + \brief A tab button control. + + TODO +*/ + +QQuickAbstractTabButton::QQuickAbstractTabButton(QQuickItem *parent) : + QQuickAbstractCheckable(parent) +{ + setExclusive(true); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstracttabbutton_p.h b/src/controls/qquickabstracttabbutton_p.h new file mode 100644 index 00000000..aeabb608 --- /dev/null +++ b/src/controls/qquickabstracttabbutton_p.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTTABBUTTON_P_H +#define QQUICKABSTRACTTABBUTTON_P_H + +#include <QtQuickControls/private/qquickabstractcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractTabButton : public QQuickAbstractCheckable +{ + Q_OBJECT + +public: + explicit QQuickAbstractTabButton(QQuickItem *parent = Q_NULLPTR); +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTTABBUTTON_P_H diff --git a/src/controls/qquickabstracttabview.cpp b/src/controls/qquickabstracttabview.cpp new file mode 100644 index 00000000..d9ae0090 --- /dev/null +++ b/src/controls/qquickabstracttabview.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstracttabview_p.h" +#include "qquickabstracttabbar_p.h" +#include "qquickabstractcontainer_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TabView + \inherits Container + \instantiates QQuickAbstractTabView + \inqmlmodule QtQuick.Controls + \ingroup tabs + \brief A tab view control. + + TODO +*/ + +class QQuickAbstractTabViewPrivate : public QQuickAbstractContainerPrivate +{ +public: + QQuickAbstractTabViewPrivate() : currentIndex(0), bar(Q_NULLPTR) { } + + int currentIndex; + QQuickAbstractTabBar *bar; +}; + +QQuickAbstractTabView::QQuickAbstractTabView(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractTabViewPrivate), parent) +{ + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); +} + +/*! + \qmlproperty int QtQuickControls2::TabView::currentIndex + + TODO +*/ +int QQuickAbstractTabView::currentIndex() const +{ + Q_D(const QQuickAbstractTabView); + return d->currentIndex; +} + +void QQuickAbstractTabView::setCurrentIndex(int index) +{ + Q_D(QQuickAbstractTabView); + if (d->currentIndex != index) { + d->currentIndex = index; + emit currentIndexChanged(index); + } +} + +/*! + \qmlproperty TabBar QtQuickControls2::TabView::tabBar + + TODO +*/ +QQuickAbstractTabBar *QQuickAbstractTabView::tabBar() const +{ + Q_D(const QQuickAbstractTabView); + return d->bar; +} + +void QQuickAbstractTabView::setTabBar(QQuickAbstractTabBar *bar) +{ + Q_D(QQuickAbstractTabView); + if (d->bar != bar) { + if (d->bar) { + disconnect(this, &QQuickAbstractTabView::currentIndexChanged, d->bar, &QQuickAbstractTabBar::setCurrentIndex); + disconnect(d->bar, &QQuickAbstractTabBar::currentIndexChanged, this, &QQuickAbstractTabView::setCurrentIndex); + if (d->bar->parentItem() == this) + delete d->bar; + } + d->bar = bar; + if (bar) { + connect(this, &QQuickAbstractTabView::currentIndexChanged, d->bar, &QQuickAbstractTabBar::setCurrentIndex); + connect(bar, &QQuickAbstractTabBar::currentIndexChanged, this, &QQuickAbstractTabView::setCurrentIndex); + if (!bar->parentItem()) + bar->setParentItem(this); + + int barIndex = bar->currentIndex(); + if (d->currentIndex != barIndex) { + if (d->currentIndex != -1) + bar->setCurrentIndex(d->currentIndex); + else if (barIndex != -1) + setCurrentIndex(barIndex); + } + } + emit tabBarChanged(); + } +} + +void QQuickAbstractTabView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickAbstractTabView); + QQuickControl::geometryChanged(newGeometry, oldGeometry); + if (d->bar && (!d->bar->widthValid() || qFuzzyCompare(d->bar->width(), oldGeometry.width()))) + d->bar->setWidth(newGeometry.width()); +} + +/*! + \qmltype Tab + \inherits QtObject + \instantiates QQuickTabAttached + \inqmlmodule QtQuick.Controls + \ingroup tabs + \brief TODO + + TODO +*/ + +QQuickTabAttached::QQuickTabAttached(QObject *parent) : + QObject(parent), m_index(-1), m_visible(true), m_view(Q_NULLPTR) +{ +} + +QQuickTabAttached *QQuickTabAttached::qmlAttachedProperties(QObject *object) +{ + return new QQuickTabAttached(object); +} + +/*! + \qmlattachedproperty int QtQuickControls2::Tab::index + + TODO +*/ +int QQuickTabAttached::index() const +{ + return m_index; +} + +void QQuickTabAttached::setIndex(int index) +{ + if (m_index != index) { + m_index = index; + emit indexChanged(); + } +} + +/*! + \qmlattachedproperty string QtQuickControls2::Tab::title + + TODO +*/ +QString QQuickTabAttached::title() const +{ + return m_title; +} + +void QQuickTabAttached::setTitle(const QString &title) +{ + if (m_title != title) { + m_title = title; + emit titleChanged(); + } +} + +/*! + \qmlattachedproperty bool QtQuickControls2::Tab::visible + + TODO +*/ +bool QQuickTabAttached::isVisible() const +{ + return m_visible; +} + +void QQuickTabAttached::setVisible(bool visible) +{ + if (m_visible != visible) { + m_visible = visible; + emit visibleChanged(); + } +} + +/*! + \qmlattachedproperty TabView QtQuickControls2::Tab::view + + TODO +*/ +QQuickAbstractTabView *QQuickTabAttached::view() const +{ + return m_view; +} + +void QQuickTabAttached::setView(QQuickAbstractTabView *view) +{ + if (m_view != view) { + m_view = view; + emit viewChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstracttabview_p.h b/src/controls/qquickabstracttabview_p.h new file mode 100644 index 00000000..e92ce2e5 --- /dev/null +++ b/src/controls/qquickabstracttabview_p.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTTABVIEW_P_H +#define QQUICKABSTRACTTABVIEW_P_H + +#include <QtQuickControls/private/qquickabstractcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractTabBar; +class QQuickAbstractTabViewPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractTabView : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) + Q_PROPERTY(QQuickAbstractTabBar *tabBar READ tabBar WRITE setTabBar NOTIFY tabBarChanged FINAL) + +public: + explicit QQuickAbstractTabView(QQuickItem *parent = Q_NULLPTR); + + int currentIndex() const; + + QQuickAbstractTabBar *tabBar() const; + void setTabBar(QQuickAbstractTabBar *bar); + +public Q_SLOTS: + void setCurrentIndex(int index); + +Q_SIGNALS: + void currentIndexChanged(int index); + void tabBarChanged(); + +protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractTabView) + Q_DECLARE_PRIVATE(QQuickAbstractTabView) +}; + +class Q_QUICKCONTROLS_EXPORT QQuickTabAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged FINAL) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) + Q_PROPERTY(QQuickAbstractTabView *view READ view WRITE setView NOTIFY viewChanged FINAL) + +public: + explicit QQuickTabAttached(QObject *parent = Q_NULLPTR); + + static QQuickTabAttached *qmlAttachedProperties(QObject *object); + + int index() const; + void setIndex(int index); + + QString title() const; + void setTitle(const QString &title); + + bool isVisible() const; + void setVisible(bool visible); + + QQuickAbstractTabView *view() const; + void setView(QQuickAbstractTabView *view); + +Q_SIGNALS: + void indexChanged(); + void titleChanged(); + void visibleChanged(); + void viewChanged(); + +private: + int m_index; + bool m_visible; + QString m_title; + QQuickAbstractTabView *m_view; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickTabAttached, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKABSTRACTTABVIEW_P_H diff --git a/src/controls/qquickabstracttextarea.cpp b/src/controls/qquickabstracttextarea.cpp new file mode 100644 index 00000000..41e24684 --- /dev/null +++ b/src/controls/qquickabstracttextarea.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstracttextarea_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquicktext_p.h> +#include <QtQuick/private/qquicktextedit_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractTextAreaPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractTextArea) + +public: + QQuickAbstractTextAreaPrivate() : edit(Q_NULLPTR), placeholder(Q_NULLPTR) { } + + void updateText(); + + QString text; + QQuickTextEdit *edit; + QQuickText *placeholder; +}; + +void QQuickAbstractTextAreaPrivate::updateText() +{ + Q_Q(QQuickAbstractTextArea); + q->setText(edit->text()); +} + +QQuickAbstractTextArea::QQuickAbstractTextArea(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractTextAreaPrivate), parent) +{ + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); +} + +QString QQuickAbstractTextArea::text() const +{ + Q_D(const QQuickAbstractTextArea); + return d->text; +} + +void QQuickAbstractTextArea::setText(const QString &text) +{ + Q_D(QQuickAbstractTextArea); + if (d->text != text) { + d->text = text; + if (d->edit) + d->edit->setText(text); + emit textChanged(); + } +} + +QQuickTextEdit *QQuickAbstractTextArea::edit() const +{ + Q_D(const QQuickAbstractTextArea); + return d->edit; +} + +void QQuickAbstractTextArea::setEdit(QQuickTextEdit *edit) +{ + Q_D(QQuickAbstractTextArea); + if (d->edit != edit) { + delete d->edit; + d->edit = edit; + if (edit) { + if (!edit->parentItem()) + edit->setParentItem(this); + edit->setText(d->text); + QObjectPrivate::connect(edit, &QQuickTextEdit::textChanged, d, &QQuickAbstractTextAreaPrivate::updateText); + } + emit editChanged(); + } +} + +QQuickText *QQuickAbstractTextArea::placeholder() const +{ + Q_D(const QQuickAbstractTextArea); + return d->placeholder; +} + +void QQuickAbstractTextArea::setPlaceholder(QQuickText *placeholder) +{ + Q_D(QQuickAbstractTextArea); + if (d->placeholder != placeholder) { + delete d->placeholder; + d->placeholder = placeholder; + if (placeholder && !placeholder->parentItem()) + placeholder->setParentItem(this); + emit placeholderChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstracttextarea_p.h b/src/controls/qquickabstracttextarea_p.h new file mode 100644 index 00000000..e5c8d0b7 --- /dev/null +++ b/src/controls/qquickabstracttextarea_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTTEXTAREA_P_H +#define QQUICKABSTRACTTEXTAREA_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickText; +class QQuickTextEdit; +class QQuickAbstractTextAreaPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractTextArea : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) + Q_PROPERTY(QQuickTextEdit *edit READ edit WRITE setEdit NOTIFY editChanged FINAL) + Q_PROPERTY(QQuickText *placeholder READ placeholder WRITE setPlaceholder NOTIFY placeholderChanged FINAL) + +public: + explicit QQuickAbstractTextArea(QQuickItem *parent = Q_NULLPTR); + + QString text() const; + void setText(const QString &text); + + QQuickTextEdit *edit() const; + void setEdit(QQuickTextEdit *edit); + + QQuickText *placeholder() const; + void setPlaceholder(QQuickText *placeholder); + +Q_SIGNALS: + void textChanged(); + void editChanged(); + void placeholderChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractTextArea) + Q_DECLARE_PRIVATE(QQuickAbstractTextArea) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTTEXTAREA_P_H diff --git a/src/controls/qquickabstracttextfield.cpp b/src/controls/qquickabstracttextfield.cpp new file mode 100644 index 00000000..70e53ab3 --- /dev/null +++ b/src/controls/qquickabstracttextfield.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstracttextfield_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquicktext_p.h> +#include <QtQuick/private/qquicktextinput_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractTextFieldPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractTextField) + +public: + QQuickAbstractTextFieldPrivate() : input(Q_NULLPTR), placeholder(Q_NULLPTR) { } + + void updateText(); + + QString text; + QQuickTextInput *input; + QQuickText *placeholder; +}; + + +void QQuickAbstractTextFieldPrivate::updateText() +{ + Q_Q(QQuickAbstractTextField); + q->setText(input->text()); +} + +QQuickAbstractTextField::QQuickAbstractTextField(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractTextFieldPrivate), parent) +{ + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); +} + +QString QQuickAbstractTextField::text() const +{ + Q_D(const QQuickAbstractTextField); + return d->text; +} + +void QQuickAbstractTextField::setText(const QString &text) +{ + Q_D(QQuickAbstractTextField); + if (d->text != text) { + d->text = text; + if (d->input) + d->input->setText(text); + emit textChanged(); + } +} + +QQuickTextInput *QQuickAbstractTextField::input() const +{ + Q_D(const QQuickAbstractTextField); + return d->input; +} + +void QQuickAbstractTextField::setInput(QQuickTextInput *input) +{ + Q_D(QQuickAbstractTextField); + if (d->input != input) { + delete d->input; + d->input = input; + if (input) { + if (!input->parentItem()) + input->setParentItem(this); + input->setText(d->text); + QObjectPrivate::connect(input, &QQuickTextInput::textChanged, d, &QQuickAbstractTextFieldPrivate::updateText); + } + emit inputChanged(); + } +} + +QQuickText *QQuickAbstractTextField::placeholder() const +{ + Q_D(const QQuickAbstractTextField); + return d->placeholder; +} + +void QQuickAbstractTextField::setPlaceholder(QQuickText *placeholder) +{ + Q_D(QQuickAbstractTextField); + if (d->placeholder != placeholder) { + delete d->placeholder; + d->placeholder = placeholder; + if (placeholder && !placeholder->parentItem()) + placeholder->setParentItem(this); + emit placeholderChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstracttextfield_p.h b/src/controls/qquickabstracttextfield_p.h new file mode 100644 index 00000000..d274c43c --- /dev/null +++ b/src/controls/qquickabstracttextfield_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTTEXTFIELD_P_H +#define QQUICKABSTRACTTEXTFIELD_P_H + +#include <QtQuickControls/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickText; +class QQuickTextInput; +class QQuickAbstractTextFieldPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractTextField : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) + Q_PROPERTY(QQuickTextInput *input READ input WRITE setInput NOTIFY inputChanged FINAL) + Q_PROPERTY(QQuickText *placeholder READ placeholder WRITE setPlaceholder NOTIFY placeholderChanged FINAL) + +public: + explicit QQuickAbstractTextField(QQuickItem *parent = Q_NULLPTR); + + QString text() const; + void setText(const QString &text); + + QQuickTextInput *input() const; + void setInput(QQuickTextInput *input); + + QQuickText *placeholder() const; + void setPlaceholder(QQuickText *placeholder); + +Q_SIGNALS: + void textChanged(); + void inputChanged(); + void placeholderChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractTextField) + Q_DECLARE_PRIVATE(QQuickAbstractTextField) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTTEXTFIELD_P_H diff --git a/src/controls/qquickabstracttogglebutton.cpp b/src/controls/qquickabstracttogglebutton.cpp new file mode 100644 index 00000000..663817e0 --- /dev/null +++ b/src/controls/qquickabstracttogglebutton.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstracttogglebutton_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ToggleButton + \inherits Checkable + \instantiates QQuickAbstractToggleButton + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A toggle button control. + + TODO +*/ + +QQuickAbstractToggleButton::QQuickAbstractToggleButton(QQuickItem *parent) : + QQuickAbstractSwitch(parent) +{ +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstracttogglebutton_p.h b/src/controls/qquickabstracttogglebutton_p.h new file mode 100644 index 00000000..d51de56c --- /dev/null +++ b/src/controls/qquickabstracttogglebutton_p.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTTOGGLEBUTTON_P_H +#define QQUICKABSTRACTTOGGLEBUTTON_P_H + +#include <QtQuickControls/private/qquickabstractswitch_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractToggleButton : public QQuickAbstractSwitch +{ + Q_OBJECT + +public: + explicit QQuickAbstractToggleButton(QQuickItem *parent = Q_NULLPTR); +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTTOGGLEBUTTON_P_H diff --git a/src/controls/qquickabstracttoolbar.cpp b/src/controls/qquickabstracttoolbar.cpp new file mode 100644 index 00000000..29119be0 --- /dev/null +++ b/src/controls/qquickabstracttoolbar.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickabstracttoolbar_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ToolBar + \inherits Container + \instantiates QQuickAbstractToolBar + \inqmlmodule QtQuick.Controls + \ingroup containers + \brief A tool bar control. + + TODO +*/ + +QQuickAbstractToolBar::QQuickAbstractToolBar(QQuickItem *parent) : + QQuickAbstractContainer(parent) +{ +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickabstracttoolbar_p.h b/src/controls/qquickabstracttoolbar_p.h new file mode 100644 index 00000000..3a7bb885 --- /dev/null +++ b/src/controls/qquickabstracttoolbar_p.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKABSTRACTTOOLBAR_P_H +#define QQUICKABSTRACTTOOLBAR_P_H + +#include <QtQuickControls/private/qquickabstractcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickAbstractToolBar : public QQuickAbstractContainer +{ + Q_OBJECT + +public: + explicit QQuickAbstractToolBar(QQuickItem *parent = Q_NULLPTR); +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTTOOLBAR_P_H diff --git a/src/controls/qquickcontrol.cpp b/src/controls/qquickcontrol.cpp new file mode 100644 index 00000000..65db0e96 --- /dev/null +++ b/src/controls/qquickcontrol.cpp @@ -0,0 +1,232 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickcontrol_p.h" +#include "qquickcontrol_p_p.h" +#include "qquickabstractapplicationwindow_p.h" +#include <QtCore/qcoreapplication.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Control + \inherits Item + \instantiates QQuickControl + \inqmlmodule QtQuick.Controls + \brief A basic control type. + + TODO +*/ + +QQuickControlPrivate::QQuickControlPrivate() : + style(Q_NULLPTR), attributes(QQuickControl::Attr_Count), background(Q_NULLPTR), padding(Q_NULLPTR) +{ +} + +void QQuickControlPrivate::mirrorChange() +{ + Q_Q(QQuickControl); + q->mirrorChange(); +} + +void QQuickControlPrivate::resolveStyle(QQuickStyle *res) +{ + Q_Q(QQuickControl); + if (!res && q->testAttribute(QQuickControl::Attr_HasStyle)) + return; + + // lookup parent style + if (!res) { + QQuickItem *item = q->parentItem(); + while (!res && item) { + QQuickControl *control = qobject_cast<QQuickControl *>(item); + if (control && control->testAttribute(QQuickControl::Attr_HasStyle)) + res = control->style(); + item = item->parentItem(); + } + } + + // fallback to window or global style + if (!res) { + QQuickAbstractApplicationWindow *aw = qobject_cast<QQuickAbstractApplicationWindow *>(window); + if (aw) + res = aw->style(); + if (!res) + res = QQuickStyle::instance(qmlEngine(q)); + } + + if (style != res) { + style = res; + emit q->styleChanged(); + } +} + +QQuickControl::QQuickControl(QQuickItem *parent) : + QQuickItem(*(new QQuickControlPrivate), parent) +{ +} + +QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent) : + QQuickItem(dd, parent) +{ +} + +/*! + \qmlpropertygroup QtQuickControls2::Control::padding + \qmlproperty real QtQuickControls2::Control::padding.top + \qmlproperty real QtQuickControls2::Control::padding.left + \qmlproperty real QtQuickControls2::Control::padding.right + \qmlproperty real QtQuickControls2::Control::padding.bottom + + This property holds the padding. +*/ +QQuickPadding *QQuickControl::padding() const +{ + Q_D(const QQuickControl); + if (!d->padding) + d->padding = new QQuickPadding(const_cast<QQuickControl *>(this)); + return d->padding; +} + +/*! + \qmlproperty Style QtQuickControls2::Control::style + + This property holds the style. +*/ +QQuickStyle *QQuickControl::style() const +{ + Q_D(const QQuickControl); + if (!d->style) + const_cast<QQuickControl *>(this)->d_func()->resolveStyle(); + return d->style; +} + +void QQuickControl::setStyle(QQuickStyle *style) +{ + Q_D(QQuickControl); + if (d->style != style) { + setAttribute(Attr_HasStyle, style); + d->resolveStyle(style); + + QEvent change(QEvent::StyleChange); + foreach (QQuickControl *control, findChildren<QQuickControl *>()) + QCoreApplication::sendEvent(control, &change); + } +} + +void QQuickControl::resetStyle() +{ + setStyle(Q_NULLPTR); +} + +/*! + \qmlproperty Item QtQuickControls2::Control::background + + This property holds the background item. +*/ +QQuickItem *QQuickControl::background() const +{ + Q_D(const QQuickControl); + return d->background; +} + +void QQuickControl::setBackground(QQuickItem *background) +{ + Q_D(QQuickControl); + if (d->background != background) { + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + } + emit backgroundChanged(); + } +} + +bool QQuickControl::testAttribute(Attribute attribute) const +{ + Q_D(const QQuickControl); + return d->attributes.testBit(attribute); +} + +void QQuickControl::setAttribute(Attribute attribute, bool on) +{ + Q_D(QQuickControl); + d->attributes.setBit(attribute, on); +} + +bool QQuickControl::event(QEvent *event) +{ + Q_D(QQuickControl); + if (event->type() == QEvent::StyleChange) + d->resolveStyle(); + return QQuickItem::event(event); +} + +void QQuickControl::itemChange(ItemChange change, const ItemChangeData &data) +{ + Q_D(QQuickControl); + QQuickItem::itemChange(change, data); + if (change == ItemSceneChange || change == ItemParentHasChanged) + d->resolveStyle(); +} + +void QQuickControl::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickControl); + QQuickItem::geometryChanged(newGeometry, oldGeometry); + if (d->background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(d->background); + if (!p->widthValid || qFuzzyCompare(d->background->width(), oldGeometry.width())) + d->background->setWidth(newGeometry.width()); + if (!p->heightValid || qFuzzyCompare(d->background->height(), oldGeometry.height())) + d->background->setHeight(newGeometry.height()); + } +} + +bool QQuickControl::isMirrored() const +{ + Q_D(const QQuickControl); + return d->isMirrored(); +} + +void QQuickControl::mirrorChange() +{ +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickcontrol_p.h b/src/controls/qquickcontrol_p.h new file mode 100644 index 00000000..48ceedcc --- /dev/null +++ b/src/controls/qquickcontrol_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKCONTROL_P_H +#define QQUICKCONTROL_P_H + +#include <QtQuick/qquickitem.h> +#include <QtQuickControls/private/qtquickcontrolsglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickStyle; +class QQuickPadding; +class QQuickControlPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickControl : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQuickPadding *padding READ padding CONSTANT FINAL) + Q_PROPERTY(QQuickStyle *style READ style WRITE setStyle RESET resetStyle NOTIFY styleChanged FINAL) + Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) + +public: + explicit QQuickControl(QQuickItem *parent = Q_NULLPTR); + + QQuickPadding *padding() const; + + QQuickStyle *style() const; + void setStyle(QQuickStyle *style); + void resetStyle(); + + QQuickItem *background() const; + void setBackground(QQuickItem *background); + + enum Attribute { + Attr_HasStyle = 1, + Attr_Count + }; + + bool testAttribute(Attribute attribute) const; + void setAttribute(Attribute attribute, bool on = true); + +Q_SIGNALS: + void styleChanged(); + void backgroundChanged(); + +protected: + QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent); + + bool event(QEvent *event) Q_DECL_OVERRIDE; + void itemChange(ItemChange, const ItemChangeData &data) Q_DECL_OVERRIDE; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + + bool isMirrored() const; + virtual void mirrorChange(); + +private: + Q_DISABLE_COPY(QQuickControl) + Q_DECLARE_PRIVATE(QQuickControl) +}; + +QT_END_NAMESPACE + +#endif // QQUICKCONTROL_P_H diff --git a/src/controls/qquickcontrol_p_p.h b/src/controls/qquickcontrol_p_p.h new file mode 100644 index 00000000..7ef5dec0 --- /dev/null +++ b/src/controls/qquickcontrol_p_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKCONTROL_P_P_H +#define QQUICKCONTROL_P_P_H + +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuickControls/private/qquickstyle_p.h> +#include <QtQuickControls/private/qquickpadding_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickControlPrivate : public QQuickItemPrivate +{ + Q_DECLARE_PUBLIC(QQuickControl) + +public: + QQuickControlPrivate(); + + void mirrorChange() Q_DECL_OVERRIDE; + + void resolveStyle(QQuickStyle *other = 0); + + QQuickStyle *style; + QBitArray attributes; + QQuickItem *background; + mutable QQuickPadding *padding; +}; + +QT_END_NAMESPACE + +#endif // QQUICKCONTROL_P_P_H diff --git a/src/controls/qquickexclusivegroup.cpp b/src/controls/qquickexclusivegroup.cpp new file mode 100644 index 00000000..325dfe19 --- /dev/null +++ b/src/controls/qquickexclusivegroup.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickexclusivegroup_p.h" +#include <QtCore/private/qobject_p.h> +#include <QtCore/qvariant.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ExclusiveGroup + \inherits QtObject + \instantiates QQuickExclusiveGroup + \inqmlmodule QtQuick.Controls + \ingroup utilities + \brief A non-visual mutually exclusive group of checkable controls. + + TODO +*/ + +class QQuickExclusiveGroupPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QQuickExclusiveGroup) + +public: + QQuickExclusiveGroupPrivate() : current(Q_NULLPTR) { } + + void _q_updateCurrent(); + + QObject *current; +}; + +void QQuickExclusiveGroupPrivate::_q_updateCurrent() +{ + Q_Q(QQuickExclusiveGroup); + QObject *object = q->sender(); + if (object->property("checked").toBool()) + q->setCurrent(object); +} + +QQuickExclusiveGroup::QQuickExclusiveGroup(QObject *parent) + : QObject(*(new QQuickExclusiveGroupPrivate), parent) +{ +} + +/*! + \qmlproperty QtObject QtQuickControls2::ExclusiveGroup::current + + TODO +*/ +QObject *QQuickExclusiveGroup::current() const +{ + Q_D(const QQuickExclusiveGroup); + return d->current; +} + +void QQuickExclusiveGroup::setCurrent(QObject *current) +{ + Q_D(QQuickExclusiveGroup); + if (d->current != current) { + if (d->current) + d->current->setProperty("checked", false); + d->current = current; + if (current) + current->setProperty("checked", true); + emit currentChanged(); + } +} + +/*! + \qmlmethod void QtQuickControls2::ExclusiveGroup::addCheckable(QtObject object) + + TODO +*/ +void QQuickExclusiveGroup::addCheckable(QObject *object) +{ + connect(object, SIGNAL(checkedChanged()), this, SLOT(_q_updateCurrent()), Qt::UniqueConnection); + connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(removeCheckable(QObject*)), Qt::UniqueConnection); + + if (object->property("checked").toBool()) + setCurrent(object); +} + +/*! + \qmlmethod void QtQuickControls2::ExclusiveGroup::removeCheckable(QtObject object) + + TODO +*/ +void QQuickExclusiveGroup::removeCheckable(QObject *object) +{ + Q_D(QQuickExclusiveGroup); + if (object->metaObject()->indexOfProperty("checked") != -1) + disconnect(object, SIGNAL(checkedChanged()), this, SLOT(_q_updateCurrent())); + disconnect(object, SIGNAL(destroyed(QObject*)), this, SLOT(removeCheckable(QObject*))); + + if (d->current == object) + setCurrent(Q_NULLPTR); +} + +/*! + \qmltype Exclusive + \inherits QtObject + \instantiates QQuickExclusive + \inqmlmodule QtQuick.Controls + \ingroup utilities + \brief TODO + + TODO +*/ + +QQuickExclusiveAttached::QQuickExclusiveAttached(QObject *parent) : + QObject(parent), m_group(Q_NULLPTR) +{ +} + +QQuickExclusiveAttached *QQuickExclusiveAttached::qmlAttachedProperties(QObject *object) +{ + return new QQuickExclusiveAttached(object); +} + +/*! + \qmlattachedproperty ExclusiveGroup QtQuickControls2::Exclusive::group + + TODO +*/ +QQuickExclusiveGroup *QQuickExclusiveAttached::group() const +{ + return m_group; +} + +void QQuickExclusiveAttached::setGroup(QQuickExclusiveGroup *group) +{ + if (m_group != group) { + if (m_group) + m_group->removeCheckable(parent()); + m_group = group; + if (m_group) + m_group->addCheckable(parent()); + emit groupChanged(); + } +} + +QT_END_NAMESPACE + +#include "moc_qquickexclusivegroup_p.cpp" diff --git a/src/controls/qquickexclusivegroup_p.h b/src/controls/qquickexclusivegroup_p.h new file mode 100644 index 00000000..d7a561a2 --- /dev/null +++ b/src/controls/qquickexclusivegroup_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKEXCLUSIVEGROUP_P_H +#define QQUICKEXCLUSIVEGROUP_P_H + +#include <QtCore/qobject.h> +#include <QtQuickControls/private/qtquickcontrolsglobal_p.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +class QQuickExclusiveGroupPrivate; + +class Q_QUICKCONTROLS_EXPORT QQuickExclusiveGroup : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject *current READ current WRITE setCurrent NOTIFY currentChanged) + +public: + explicit QQuickExclusiveGroup(QObject *parent = Q_NULLPTR); + + QObject *current() const; + void setCurrent(QObject *current); + +public Q_SLOTS: + void addCheckable(QObject *object); + void removeCheckable(QObject *object); + +Q_SIGNALS: + void currentChanged(); + +private: + Q_DISABLE_COPY(QQuickExclusiveGroup) + Q_DECLARE_PRIVATE(QQuickExclusiveGroup) + + Q_PRIVATE_SLOT(d_func(), void _q_updateCurrent()) +}; + +class Q_QUICKCONTROLS_EXPORT QQuickExclusiveAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickExclusiveGroup *group READ group WRITE setGroup NOTIFY groupChanged FINAL) + +public: + explicit QQuickExclusiveAttached(QObject *parent = Q_NULLPTR); + + static QQuickExclusiveAttached *qmlAttachedProperties(QObject *object); + + QQuickExclusiveGroup *group() const; + void setGroup(QQuickExclusiveGroup *group); + +Q_SIGNALS: + void groupChanged(); + +private: + QQuickExclusiveGroup *m_group; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickExclusiveAttached, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKEXCLUSIVEGROUP_H diff --git a/src/controls/qquickpadding_p.h b/src/controls/qquickpadding_p.h new file mode 100644 index 00000000..22442d16 --- /dev/null +++ b/src/controls/qquickpadding_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKPADDING_P_H +#define QQUICKPADDING_P_H + +#include <QtCore/qobject.h> +#include <QtQuickControls/private/qtquickcontrolsglobal_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS_EXPORT QQuickPadding : public QObject +{ + Q_OBJECT + Q_PROPERTY(qreal left MEMBER left NOTIFY leftChanged) + Q_PROPERTY(qreal top MEMBER top NOTIFY topChanged) + Q_PROPERTY(qreal right MEMBER right NOTIFY rightChanged) + Q_PROPERTY(qreal bottom MEMBER bottom NOTIFY bottomChanged) + +public: + QQuickPadding(QObject *parent = Q_NULLPTR) : QObject(parent), + top(0), left(0), right(0), bottom(0) + { + } + + qreal top; + qreal left; + qreal right; + qreal bottom; + +Q_SIGNALS: + void leftChanged(); + void topChanged(); + void rightChanged(); + void bottomChanged(); +}; + +QT_END_NAMESPACE + +#endif // QQUICKPADDING_P_H diff --git a/src/controls/qquickstyle.cpp b/src/controls/qquickstyle.cpp new file mode 100644 index 00000000..e52e8b3a --- /dev/null +++ b/src/controls/qquickstyle.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickstyle_p.h" +#include <QtCore/qfile.h> +#include <QtCore/qjsondocument.h> +#include <QtCore/qjsonobject.h> +#include <QtCore/qjsonvalue.h> +#include <QtCore/qdebug.h> +#include <QtQml/qqmlengine.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Style + \inherits QtObject + \instantiates QQuickStyle + \inqmlmodule QtQuick.Controls + \ingroup utilities + \brief A style interface. + + TODO +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::accentColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::backgroundColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::focusColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::frameColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::pressColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::selectedTextColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::selectionColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::shadowColor +*/ + +/*! + \qmlproperty color QtQuickControls2::Style::textColor +*/ + +/*! + \qmlproperty int QtQuickControls2::Style::padding +*/ + +/*! + \qmlproperty int QtQuickControls2::Style::roundness +*/ + +/*! + \qmlproperty int QtQuickControls2::Style::spacing +*/ + +/*! + \qmlproperty real QtQuickControls2::Style::disabledOpacity +*/ + +static QColor readColorValue(const QJsonValue &value, const QColor &defaultValue) +{ + if (value.isString()) + return QColor(value.toString()); + return QColor::fromRgba(value.toInt(defaultValue.rgba())); +} + +static double readNumberValue(const QJsonValue &value, double defaultValue) +{ + return value.toDouble(defaultValue); +} + +QQuickStyle::QQuickStyle(QObject *parent) : QObject(parent) +{ + QJsonDocument doc; + + QFile file(QStringLiteral(":/qtquickcontrols/style.json")); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + qDebug() << file.error(); + qWarning() << "QQuickStyle: failed to open ':/qtquickcontrols/style.json': " << qPrintable(file.errorString()); + } else { + QJsonParseError error; + doc = QJsonDocument::fromJson(file.readAll(), &error); + if (error.error != QJsonParseError::NoError) + qWarning() << "QQuickStyle: failed to parse ':/qtquickcontrols/style.json': " << qPrintable(error.errorString()); + } + + QJsonObject style = doc.object(); + accentColor = readColorValue(style.value(QStringLiteral("accentColor")), QColor("#7bc258")); + backgroundColor = readColorValue(style.value(QStringLiteral("backgroundColor")), QColor("#ffffff")); + baseColor = readColorValue(style.value(QStringLiteral("baseColor")), QColor("#eeeeee")); + focusColor = readColorValue(style.value(QStringLiteral("focusColor")), QColor("#45a7d7")); + frameColor = readColorValue(style.value(QStringLiteral("frameColor")), QColor("#bdbebf")); + pressColor = readColorValue(style.value(QStringLiteral("pressColor")), QColor("#33333333")); + selectedTextColor = readColorValue(style.value(QStringLiteral("selectedTextColor")), QColor("#ffffff")); + selectionColor = readColorValue(style.value(QStringLiteral("selectionColor")), QColor("#45a7d7")); + shadowColor = readColorValue(style.value(QStringLiteral("shadowColor")), QColor("#28282a")); + textColor = readColorValue(style.value(QStringLiteral("textColor")), QColor("#26282a")); + padding = readNumberValue(style.value(QStringLiteral("padding")), 6); + roundness = readNumberValue(style.value(QStringLiteral("roundness")), 3); + spacing = readNumberValue(style.value(QStringLiteral("spacing")), 6); + disabledOpacity = readNumberValue(style.value(QStringLiteral("disabledOpacity")), 0.3); +} + +QQuickStyle *QQuickStyle::instance(QQmlEngine *engine) +{ + static QHash<QQmlEngine *, QQuickStyle *> styles; + QHash<QQmlEngine *, QQuickStyle *>::iterator it = styles.find(engine); + if (it == styles.end()) + it = styles.insert(engine, new QQuickStyle(engine)); + return it.value(); +} + +QQuickStyle *QQuickStyle::qmlAttachedProperties(QObject *object) +{ + return instance(qmlEngine(object)); +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickstyle_p.h b/src/controls/qquickstyle_p.h new file mode 100644 index 00000000..d26f2976 --- /dev/null +++ b/src/controls/qquickstyle_p.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKSTYLE_P_H +#define QQUICKSTYLE_P_H + +#include <QtCore/qobject.h> +#include <QtGui/qcolor.h> +#include <QtQuickControls/private/qtquickcontrolsglobal_p.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +class QQmlEngine; +class QJSEngine; + +class Q_QUICKCONTROLS_EXPORT QQuickStyle : public QObject +{ + Q_OBJECT + Q_PROPERTY(QColor accentColor MEMBER accentColor NOTIFY accentColorChanged FINAL) + Q_PROPERTY(QColor backgroundColor MEMBER backgroundColor NOTIFY backgroundColorChanged FINAL) + Q_PROPERTY(QColor baseColor MEMBER baseColor NOTIFY baseColorChanged FINAL) + Q_PROPERTY(QColor focusColor MEMBER focusColor NOTIFY focusColorChanged FINAL) + Q_PROPERTY(QColor frameColor MEMBER frameColor NOTIFY frameColorChanged FINAL) + Q_PROPERTY(QColor pressColor MEMBER pressColor NOTIFY pressColorChanged FINAL) + Q_PROPERTY(QColor selectedTextColor MEMBER selectedTextColor NOTIFY selectedTextColorChanged FINAL) + Q_PROPERTY(QColor selectionColor MEMBER selectionColor NOTIFY selectionColorChanged FINAL) + Q_PROPERTY(QColor shadowColor MEMBER shadowColor NOTIFY shadowColorChanged FINAL) + Q_PROPERTY(QColor textColor MEMBER textColor NOTIFY textColorChanged FINAL) + Q_PROPERTY(int padding MEMBER padding NOTIFY paddingChanged FINAL) + Q_PROPERTY(int roundness MEMBER roundness NOTIFY roundnessChanged FINAL) + Q_PROPERTY(int spacing MEMBER spacing NOTIFY spacingChanged FINAL) + Q_PROPERTY(qreal disabledOpacity MEMBER disabledOpacity NOTIFY disabledOpacityChanged FINAL) + +public: + explicit QQuickStyle(QObject *parent = Q_NULLPTR); + + static QQuickStyle *instance(QQmlEngine *engine); + static QQuickStyle *qmlAttachedProperties(QObject *object); + +Q_SIGNALS: + void accentColorChanged(); + void backgroundColorChanged(); + void baseColorChanged(); + void focusColorChanged(); + void frameColorChanged(); + void pressColorChanged(); + void selectedTextColorChanged(); + void selectionColorChanged(); + void shadowColorChanged(); + void textColorChanged(); + void paddingChanged(); + void roundnessChanged(); + void spacingChanged(); + void disabledOpacityChanged(); + +private: + QColor accentColor; + QColor baseColor; + QColor backgroundColor; + QColor focusColor; + QColor frameColor; + QColor pressColor; + QColor selectedTextColor; + QColor selectionColor; + QColor shadowColor; + QColor textColor; + int padding; + int spacing; + int roundness; + qreal disabledOpacity; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickStyle, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKSTYLE_P_H diff --git a/src/controls/qtquickcontrolsglobal_p.h b/src/controls/qtquickcontrolsglobal_p.h new file mode 100644 index 00000000..3d606db7 --- /dev/null +++ b/src/controls/qtquickcontrolsglobal_p.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTQUICKCONTROLSGLOBAL_P_H +#define QTQUICKCONTROLSGLOBAL_P_H + +#include <QtCore/qglobal.h> + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_QUICKCONTROLS_LIB) +# define Q_QUICKCONTROLS_EXPORT Q_DECL_EXPORT +# else +# define Q_QUICKCONTROLS_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_QUICKCONTROLS_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QTQUICKCONTROLSGLOBAL_P_H diff --git a/src/controls/style.json b/src/controls/style.json new file mode 100644 index 00000000..a1a79969 --- /dev/null +++ b/src/controls/style.json @@ -0,0 +1,16 @@ +{ + "accentColor": "#7bc258", + "backgroundColor": "#ffffff", + "baseColor": "#eeeeee", + "focusColor": "#45a7d7", + "frameColor": "#bdbebf", + "pressColor": "#33333333", + "selectedTextColor": "#ffffff", + "selectionColor": "#45a7d7", + "shadowColor": "#28282a", + "textColor": "#26282a", + "padding": 6, + "roundness": 3, + "disabledOpacity": 0.3, + "spacing": 6 +} |