From 8b2a1ec43134e191a5f9bb08a73f1a694d52927d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 30 Jan 2015 20:57:40 +0100 Subject: Import the Qt Quick Controls 2 prototype Change-Id: Ib8c0c4160958e5cfea29a6e9df1b3f1fb19715fc Reviewed-by: Jari-Pekka Nurmi --- src/calendar/calendar.pri | 19 + src/calendar/calendar.pro | 14 + src/calendar/qquickabstractcalendarview.cpp | 255 ++++++ src/calendar/qquickabstractcalendarview_p.h | 101 +++ src/calendar/qquickabstractdayofweekrow.cpp | 87 ++ src/calendar/qquickabstractdayofweekrow_p.h | 73 ++ src/calendar/qquickabstractweeknumbercolumn.cpp | 113 +++ src/calendar/qquickabstractweeknumbercolumn_p.h | 83 ++ src/calendar/qquickcalendarmodel.cpp | 195 +++++ src/calendar/qquickcalendarmodel_p.h | 96 +++ src/calendar/qquickdayofweekmodel.cpp | 123 +++ src/calendar/qquickdayofweekmodel_p.h | 83 ++ src/calendar/qquickmonthmodel.cpp | 224 +++++ src/calendar/qquickmonthmodel_p.h | 102 +++ src/calendar/qquickweeknumbermodel.cpp | 182 ++++ src/calendar/qquickweeknumbermodel_p.h | 91 ++ src/calendar/qtquickcalendarglobal_p.h | 56 ++ src/controls/controls.pri | 64 ++ src/controls/controls.pro | 22 + src/controls/controls.qrc | 5 + src/controls/doc/qtquickcontrols2.qdocconf | 42 + src/controls/doc/src/qtquickcontrols2-index.qdoc | 48 ++ .../doc/src/qtquickcontrols2-overview.qdoc | 58 ++ src/controls/doc/src/qtquickcontrols2.qdoc | 44 + src/controls/qquickabstractapplicationwindow.cpp | 256 ++++++ src/controls/qquickabstractapplicationwindow_p.h | 94 ++ src/controls/qquickabstractbusyindicator.cpp | 110 +++ src/controls/qquickabstractbusyindicator_p.h | 72 ++ src/controls/qquickabstractbutton.cpp | 189 ++++ src/controls/qquickabstractbutton_p.h | 89 ++ src/controls/qquickabstractbutton_p_p.h | 58 ++ src/controls/qquickabstractcheckable.cpp | 190 ++++ src/controls/qquickabstractcheckable_p.h | 94 ++ src/controls/qquickabstractcheckable_p_p.h | 57 ++ src/controls/qquickabstractcheckbox.cpp | 57 ++ src/controls/qquickabstractcheckbox_p.h | 54 ++ src/controls/qquickabstractcontainer.cpp | 131 +++ src/controls/qquickabstractcontainer_p.h | 80 ++ src/controls/qquickabstractcontainer_p_p.h | 56 ++ src/controls/qquickabstractframe.cpp | 57 ++ src/controls/qquickabstractframe_p.h | 54 ++ src/controls/qquickabstractgroupbox.cpp | 134 +++ src/controls/qquickabstractgroupbox_p.h | 77 ++ src/controls/qquickabstractpageindicator.cpp | 107 +++ src/controls/qquickabstractpageindicator_p.h | 72 ++ src/controls/qquickabstractprogressbar.cpp | 188 ++++ src/controls/qquickabstractprogressbar_p.h | 92 ++ src/controls/qquickabstractradiobutton.cpp | 60 ++ src/controls/qquickabstractradiobutton_p.h | 54 ++ src/controls/qquickabstractscrollbar.cpp | 428 +++++++++ src/controls/qquickabstractscrollbar_p.h | 132 +++ src/controls/qquickabstractscrollindicator.cpp | 319 +++++++ src/controls/qquickabstractscrollindicator_p.h | 120 +++ src/controls/qquickabstractslider.cpp | 454 ++++++++++ src/controls/qquickabstractslider_p.h | 133 +++ src/controls/qquickabstractspinbox.cpp | 300 +++++++ src/controls/qquickabstractspinbox_p.h | 119 +++ src/controls/qquickabstractstackview.cpp | 352 ++++++++ src/controls/qquickabstractstackview_p.h | 131 +++ src/controls/qquickabstractswitch.cpp | 199 +++++ src/controls/qquickabstractswitch_p.h | 82 ++ src/controls/qquickabstracttabbar.cpp | 88 ++ src/controls/qquickabstracttabbar_p.h | 70 ++ src/controls/qquickabstracttabbutton.cpp | 58 ++ src/controls/qquickabstracttabbutton_p.h | 54 ++ src/controls/qquickabstracttabview.cpp | 231 +++++ src/controls/qquickabstracttabview_p.h | 118 +++ src/controls/qquickabstracttextarea.cpp | 129 +++ src/controls/qquickabstracttextarea_p.h | 79 ++ src/controls/qquickabstracttextfield.cpp | 130 +++ src/controls/qquickabstracttextfield_p.h | 79 ++ src/controls/qquickabstracttogglebutton.cpp | 57 ++ src/controls/qquickabstracttogglebutton_p.h | 54 ++ src/controls/qquickabstracttoolbar.cpp | 57 ++ src/controls/qquickabstracttoolbar_p.h | 54 ++ src/controls/qquickcontrol.cpp | 232 +++++ src/controls/qquickcontrol_p.h | 97 +++ src/controls/qquickcontrol_p_p.h | 65 ++ src/controls/qquickexclusivegroup.cpp | 178 ++++ src/controls/qquickexclusivegroup_p.h | 97 +++ src/controls/qquickpadding_p.h | 73 ++ src/controls/qquickstyle.cpp | 168 ++++ src/controls/qquickstyle_p.h | 111 +++ src/controls/qtquickcontrolsglobal_p.h | 56 ++ src/controls/style.json | 16 + src/extras/extras.pri | 9 + src/extras/extras.pro | 14 + src/extras/qquickabstractdrawer.cpp | 388 +++++++++ src/extras/qquickabstractdrawer_p.h | 102 +++ src/extras/qquickabstractsplitview.cpp | 97 +++ src/extras/qquickabstractsplitview_p.h | 79 ++ src/extras/qtquickextrasglobal_p.h | 56 ++ src/imports/calendar/CalendarDelegate.qml | 60 ++ src/imports/calendar/CalendarView.qml | 78 ++ src/imports/calendar/DayOfWeekRow.qml | 75 ++ src/imports/calendar/WeekNumberColumn.qml | 75 ++ src/imports/calendar/calendar.pro | 21 + src/imports/calendar/qmldir | 7 + src/imports/calendar/qtquickcalendar2plugin.cpp | 71 ++ src/imports/controls/ApplicationWindow.qml | 55 ++ src/imports/controls/BusyIndicator.qml | 80 ++ src/imports/controls/Button.qml | 78 ++ src/imports/controls/CheckBox.qml | 101 +++ src/imports/controls/Frame.qml | 68 ++ src/imports/controls/GroupBox.qml | 89 ++ src/imports/controls/Label.qml | 47 + src/imports/controls/PageIndicator.qml | 81 ++ src/imports/controls/ProgressBar.qml | 101 +++ src/imports/controls/RadioButton.qml | 102 +++ src/imports/controls/ScrollBar.qml | 84 ++ src/imports/controls/ScrollIndicator.qml | 84 ++ src/imports/controls/Slider.qml | 104 +++ src/imports/controls/SpinBox.qml | 132 +++ src/imports/controls/StackView.js | 63 ++ src/imports/controls/StackView.qml | 954 +++++++++++++++++++++ src/imports/controls/StackViewDelegate.qml | 142 +++ src/imports/controls/StackViewTransition.qml | 56 ++ src/imports/controls/Switch.qml | 111 +++ src/imports/controls/TabBar.qml | 120 +++ src/imports/controls/TabButton.qml | 75 ++ src/imports/controls/TabView.qml | 96 +++ src/imports/controls/TextArea.qml | 78 ++ src/imports/controls/TextField.qml | 90 ++ src/imports/controls/ToggleButton.qml | 110 +++ src/imports/controls/ToolBar.qml | 67 ++ src/imports/controls/ToolButton.qml | 76 ++ src/imports/controls/controls.pro | 47 + src/imports/controls/images/spinner_large.png | Bin 0 -> 15085 bytes src/imports/controls/images/spinner_medium.png | Bin 0 -> 5934 bytes src/imports/controls/images/spinner_small.png | Bin 0 -> 4582 bytes src/imports/controls/qmldir | 29 + src/imports/controls/qtquickcontrols2plugin.cpp | 128 +++ src/imports/controls/qtquickcontrols2plugin.qrc | 7 + src/imports/extras/Drawer.qml | 56 ++ src/imports/extras/SplitView.qml | 556 ++++++++++++ src/imports/extras/extras.pro | 19 + src/imports/extras/qmldir | 5 + src/imports/extras/qtquickextras2plugin.cpp | 61 ++ src/imports/imports.pro | 5 + src/src.pro | 10 + 140 files changed, 15081 insertions(+) create mode 100644 src/calendar/calendar.pri create mode 100644 src/calendar/calendar.pro create mode 100644 src/calendar/qquickabstractcalendarview.cpp create mode 100644 src/calendar/qquickabstractcalendarview_p.h create mode 100644 src/calendar/qquickabstractdayofweekrow.cpp create mode 100644 src/calendar/qquickabstractdayofweekrow_p.h create mode 100644 src/calendar/qquickabstractweeknumbercolumn.cpp create mode 100644 src/calendar/qquickabstractweeknumbercolumn_p.h create mode 100644 src/calendar/qquickcalendarmodel.cpp create mode 100644 src/calendar/qquickcalendarmodel_p.h create mode 100644 src/calendar/qquickdayofweekmodel.cpp create mode 100644 src/calendar/qquickdayofweekmodel_p.h create mode 100644 src/calendar/qquickmonthmodel.cpp create mode 100644 src/calendar/qquickmonthmodel_p.h create mode 100644 src/calendar/qquickweeknumbermodel.cpp create mode 100644 src/calendar/qquickweeknumbermodel_p.h create mode 100644 src/calendar/qtquickcalendarglobal_p.h create mode 100644 src/controls/controls.pri create mode 100644 src/controls/controls.pro create mode 100644 src/controls/controls.qrc create mode 100644 src/controls/doc/qtquickcontrols2.qdocconf create mode 100644 src/controls/doc/src/qtquickcontrols2-index.qdoc create mode 100644 src/controls/doc/src/qtquickcontrols2-overview.qdoc create mode 100644 src/controls/doc/src/qtquickcontrols2.qdoc create mode 100644 src/controls/qquickabstractapplicationwindow.cpp create mode 100644 src/controls/qquickabstractapplicationwindow_p.h create mode 100644 src/controls/qquickabstractbusyindicator.cpp create mode 100644 src/controls/qquickabstractbusyindicator_p.h create mode 100644 src/controls/qquickabstractbutton.cpp create mode 100644 src/controls/qquickabstractbutton_p.h create mode 100644 src/controls/qquickabstractbutton_p_p.h create mode 100644 src/controls/qquickabstractcheckable.cpp create mode 100644 src/controls/qquickabstractcheckable_p.h create mode 100644 src/controls/qquickabstractcheckable_p_p.h create mode 100644 src/controls/qquickabstractcheckbox.cpp create mode 100644 src/controls/qquickabstractcheckbox_p.h create mode 100644 src/controls/qquickabstractcontainer.cpp create mode 100644 src/controls/qquickabstractcontainer_p.h create mode 100644 src/controls/qquickabstractcontainer_p_p.h create mode 100644 src/controls/qquickabstractframe.cpp create mode 100644 src/controls/qquickabstractframe_p.h create mode 100644 src/controls/qquickabstractgroupbox.cpp create mode 100644 src/controls/qquickabstractgroupbox_p.h create mode 100644 src/controls/qquickabstractpageindicator.cpp create mode 100644 src/controls/qquickabstractpageindicator_p.h create mode 100644 src/controls/qquickabstractprogressbar.cpp create mode 100644 src/controls/qquickabstractprogressbar_p.h create mode 100644 src/controls/qquickabstractradiobutton.cpp create mode 100644 src/controls/qquickabstractradiobutton_p.h create mode 100644 src/controls/qquickabstractscrollbar.cpp create mode 100644 src/controls/qquickabstractscrollbar_p.h create mode 100644 src/controls/qquickabstractscrollindicator.cpp create mode 100644 src/controls/qquickabstractscrollindicator_p.h create mode 100644 src/controls/qquickabstractslider.cpp create mode 100644 src/controls/qquickabstractslider_p.h create mode 100644 src/controls/qquickabstractspinbox.cpp create mode 100644 src/controls/qquickabstractspinbox_p.h create mode 100644 src/controls/qquickabstractstackview.cpp create mode 100644 src/controls/qquickabstractstackview_p.h create mode 100644 src/controls/qquickabstractswitch.cpp create mode 100644 src/controls/qquickabstractswitch_p.h create mode 100644 src/controls/qquickabstracttabbar.cpp create mode 100644 src/controls/qquickabstracttabbar_p.h create mode 100644 src/controls/qquickabstracttabbutton.cpp create mode 100644 src/controls/qquickabstracttabbutton_p.h create mode 100644 src/controls/qquickabstracttabview.cpp create mode 100644 src/controls/qquickabstracttabview_p.h create mode 100644 src/controls/qquickabstracttextarea.cpp create mode 100644 src/controls/qquickabstracttextarea_p.h create mode 100644 src/controls/qquickabstracttextfield.cpp create mode 100644 src/controls/qquickabstracttextfield_p.h create mode 100644 src/controls/qquickabstracttogglebutton.cpp create mode 100644 src/controls/qquickabstracttogglebutton_p.h create mode 100644 src/controls/qquickabstracttoolbar.cpp create mode 100644 src/controls/qquickabstracttoolbar_p.h create mode 100644 src/controls/qquickcontrol.cpp create mode 100644 src/controls/qquickcontrol_p.h create mode 100644 src/controls/qquickcontrol_p_p.h create mode 100644 src/controls/qquickexclusivegroup.cpp create mode 100644 src/controls/qquickexclusivegroup_p.h create mode 100644 src/controls/qquickpadding_p.h create mode 100644 src/controls/qquickstyle.cpp create mode 100644 src/controls/qquickstyle_p.h create mode 100644 src/controls/qtquickcontrolsglobal_p.h create mode 100644 src/controls/style.json create mode 100644 src/extras/extras.pri create mode 100644 src/extras/extras.pro create mode 100644 src/extras/qquickabstractdrawer.cpp create mode 100644 src/extras/qquickabstractdrawer_p.h create mode 100644 src/extras/qquickabstractsplitview.cpp create mode 100644 src/extras/qquickabstractsplitview_p.h create mode 100644 src/extras/qtquickextrasglobal_p.h create mode 100644 src/imports/calendar/CalendarDelegate.qml create mode 100644 src/imports/calendar/CalendarView.qml create mode 100644 src/imports/calendar/DayOfWeekRow.qml create mode 100644 src/imports/calendar/WeekNumberColumn.qml create mode 100644 src/imports/calendar/calendar.pro create mode 100644 src/imports/calendar/qmldir create mode 100644 src/imports/calendar/qtquickcalendar2plugin.cpp create mode 100644 src/imports/controls/ApplicationWindow.qml create mode 100644 src/imports/controls/BusyIndicator.qml create mode 100644 src/imports/controls/Button.qml create mode 100644 src/imports/controls/CheckBox.qml create mode 100644 src/imports/controls/Frame.qml create mode 100644 src/imports/controls/GroupBox.qml create mode 100644 src/imports/controls/Label.qml create mode 100644 src/imports/controls/PageIndicator.qml create mode 100644 src/imports/controls/ProgressBar.qml create mode 100644 src/imports/controls/RadioButton.qml create mode 100644 src/imports/controls/ScrollBar.qml create mode 100644 src/imports/controls/ScrollIndicator.qml create mode 100644 src/imports/controls/Slider.qml create mode 100644 src/imports/controls/SpinBox.qml create mode 100644 src/imports/controls/StackView.js create mode 100644 src/imports/controls/StackView.qml create mode 100644 src/imports/controls/StackViewDelegate.qml create mode 100644 src/imports/controls/StackViewTransition.qml create mode 100644 src/imports/controls/Switch.qml create mode 100644 src/imports/controls/TabBar.qml create mode 100644 src/imports/controls/TabButton.qml create mode 100644 src/imports/controls/TabView.qml create mode 100644 src/imports/controls/TextArea.qml create mode 100644 src/imports/controls/TextField.qml create mode 100644 src/imports/controls/ToggleButton.qml create mode 100644 src/imports/controls/ToolBar.qml create mode 100644 src/imports/controls/ToolButton.qml create mode 100644 src/imports/controls/controls.pro create mode 100644 src/imports/controls/images/spinner_large.png create mode 100644 src/imports/controls/images/spinner_medium.png create mode 100644 src/imports/controls/images/spinner_small.png create mode 100644 src/imports/controls/qmldir create mode 100644 src/imports/controls/qtquickcontrols2plugin.cpp create mode 100644 src/imports/controls/qtquickcontrols2plugin.qrc create mode 100644 src/imports/extras/Drawer.qml create mode 100644 src/imports/extras/SplitView.qml create mode 100644 src/imports/extras/extras.pro create mode 100644 src/imports/extras/qmldir create mode 100644 src/imports/extras/qtquickextras2plugin.cpp create mode 100644 src/imports/imports.pro create mode 100644 src/src.pro (limited to 'src') diff --git a/src/calendar/calendar.pri b/src/calendar/calendar.pri new file mode 100644 index 00000000..67267388 --- /dev/null +++ b/src/calendar/calendar.pri @@ -0,0 +1,19 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qquickabstractcalendarview_p.h \ + $$PWD/qquickabstractdayofweekrow_p.h \ + $$PWD/qquickabstractweeknumbercolumn_p.h \ + $$PWD/qquickcalendarmodel_p.h \ + $$PWD/qquickdayofweekmodel_p.h \ + $$PWD/qquickmonthmodel_p.h \ + $$PWD/qquickweeknumbermodel_p.h + +SOURCES += \ + $$PWD/qquickabstractcalendarview.cpp \ + $$PWD/qquickabstractdayofweekrow.cpp \ + $$PWD/qquickabstractweeknumbercolumn.cpp \ + $$PWD/qquickcalendarmodel.cpp \ + $$PWD/qquickdayofweekmodel.cpp \ + $$PWD/qquickmonthmodel.cpp \ + $$PWD/qquickweeknumbermodel.cpp diff --git a/src/calendar/calendar.pro b/src/calendar/calendar.pro new file mode 100644 index 00000000..e1f3af78 --- /dev/null +++ b/src/calendar/calendar.pro @@ -0,0 +1,14 @@ +TARGET = QtQuickCalendar +MODULE = quickcalendar +CONFIG += internal_module + +QT += quick +QT += core-private gui-private qml-private quick-private quickcontrols-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +HEADERS += \ + $$PWD/qtquickcalendarglobal_p.h + +include(calendar.pri) +load(qt_module) diff --git a/src/calendar/qquickabstractcalendarview.cpp b/src/calendar/qquickabstractcalendarview.cpp new file mode 100644 index 00000000..c076cc0c --- /dev/null +++ b/src/calendar/qquickabstractcalendarview.cpp @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 "qquickabstractcalendarview_p.h" +#include "qquickmonthmodel_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractCalendarViewPrivate : public QQuickAbstractContainerPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractCalendarView) + +public: + QQuickAbstractCalendarViewPrivate() : pressTimer(0), pressedItem(Q_NULLPTR), model(Q_NULLPTR) { } + + QQuickItem *cellAt(const QPoint &pos) const; + QDate dateOf(QQuickItem *cell) const; + + void updatePress(const QPoint &pos); + void clearPress(bool clicked); + + static void setContextProperty(QQuickItem *item, const QString &name, const QVariant &value); + + QString title; + QVariant source; + QDate pressedDate; + int pressTimer; + QQuickItem *pressedItem; + QQuickMonthModel *model; +}; + +QQuickItem *QQuickAbstractCalendarViewPrivate::cellAt(const QPoint &pos) const +{ + Q_Q(const QQuickAbstractCalendarView); + if (contentItem) { + QPointF mapped = q->mapToItem(contentItem, pos); + return contentItem->childAt(mapped.x(), mapped.y()); + } + return Q_NULLPTR; +} + +QDate QQuickAbstractCalendarViewPrivate::dateOf(QQuickItem *cell) const +{ + if (contentItem) + return model->dateAt(contentItem->childItems().indexOf(cell)); + return QDate(); +} + +void QQuickAbstractCalendarViewPrivate::updatePress(const QPoint &pos) +{ + Q_Q(QQuickAbstractCalendarView); + clearPress(false); + pressedItem = cellAt(pos); + setContextProperty(pressedItem, QStringLiteral("pressed"), true); + pressedDate = dateOf(pressedItem); + if (pressedDate.isValid()) + emit q->pressed(pressedDate); +} + +void QQuickAbstractCalendarViewPrivate::clearPress(bool clicked) +{ + Q_Q(QQuickAbstractCalendarView); + setContextProperty(pressedItem, QStringLiteral("pressed"), false); + if (pressedDate.isValid()) { + emit q->released(pressedDate); + if (clicked) + emit q->clicked(pressedDate); + } + pressedDate = QDate(); + pressedItem = Q_NULLPTR; +} + +void QQuickAbstractCalendarViewPrivate::setContextProperty(QQuickItem *item, const QString &name, const QVariant &value) +{ + QQmlContext *context = qmlContext(item); + if (context && context->isValid()) { + context = context->parentContext(); + if (context && context->isValid()) + context->setContextProperty(name, value); + } +} + +QQuickAbstractCalendarView::QQuickAbstractCalendarView(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractCalendarViewPrivate), parent) +{ + Q_D(QQuickAbstractCalendarView); + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); + + d->model = new QQuickMonthModel(this); + d->source = QVariant::fromValue(d->model); + connect(d->model, &QQuickMonthModel::monthChanged, this, &QQuickAbstractCalendarView::monthChanged); + connect(d->model, &QQuickMonthModel::yearChanged, this, &QQuickAbstractCalendarView::yearChanged); + connect(d->model, &QQuickMonthModel::localeChanged, this, &QQuickAbstractCalendarView::localeChanged); + connect(d->model, &QQuickMonthModel::titleChanged, this, &QQuickAbstractCalendarView::titleChanged); +} + +int QQuickAbstractCalendarView::month() const +{ + Q_D(const QQuickAbstractCalendarView); + return d->model->month(); +} + +void QQuickAbstractCalendarView::setMonth(int month) +{ + Q_D(QQuickAbstractCalendarView); + d->model->setMonth(month); +} + +int QQuickAbstractCalendarView::year() const +{ + Q_D(const QQuickAbstractCalendarView); + return d->model->year(); +} + +void QQuickAbstractCalendarView::setYear(int year) +{ + Q_D(QQuickAbstractCalendarView); + d->model->setYear(year); +} + +QLocale QQuickAbstractCalendarView::locale() const +{ + Q_D(const QQuickAbstractCalendarView); + return d->model->locale(); +} + +void QQuickAbstractCalendarView::setLocale(const QLocale &locale) +{ + Q_D(QQuickAbstractCalendarView); + d->model->setLocale(locale); +} + +QVariant QQuickAbstractCalendarView::source() const +{ + Q_D(const QQuickAbstractCalendarView); + return d->source; +} + +void QQuickAbstractCalendarView::setSource(const QVariant &source) +{ + Q_D(QQuickAbstractCalendarView); + if (d->source != source) { + d->source = source; + emit sourceChanged(); + } +} + +QString QQuickAbstractCalendarView::title() const +{ + Q_D(const QQuickAbstractCalendarView); + if (d->title.isNull()) + return d->model->title(); + return d->title; +} + +void QQuickAbstractCalendarView::setTitle(const QString &title) +{ + Q_D(QQuickAbstractCalendarView); + if (d->title != title) { + d->title = title; + emit titleChanged(); + } +} + +void QQuickAbstractCalendarView::componentComplete() +{ + Q_D(QQuickAbstractCalendarView); + QQuickAbstractContainer::componentComplete(); + if (d->contentItem) { + foreach (QQuickItem *child, d->contentItem->childItems()) { + if (!child->inherits("QQuickRepeater")) + d->setContextProperty(child, QStringLiteral("pressed"), false); + } + } +} + +void QQuickAbstractCalendarView::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractCalendarView); + d->updatePress(event->pos()); + if (d->pressedDate.isValid()) + d->pressTimer = startTimer(qGuiApp->styleHints()->mousePressAndHoldInterval()); + event->accept(); +} + +void QQuickAbstractCalendarView::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractCalendarView); + d->updatePress(event->pos()); + event->accept(); +} + +void QQuickAbstractCalendarView::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractCalendarView); + d->clearPress(true); + event->accept(); +} + +void QQuickAbstractCalendarView::mouseUngrabEvent() +{ + Q_D(QQuickAbstractCalendarView); + d->clearPress(false); +} + +void QQuickAbstractCalendarView::timerEvent(QTimerEvent *event) +{ + Q_D(QQuickAbstractCalendarView); + if (event->timerId() == d->pressTimer) { + if (d->pressedDate.isValid()) + emit pressAndHold(d->pressedDate); + killTimer(d->pressTimer); + } +} + +QT_END_NAMESPACE diff --git a/src/calendar/qquickabstractcalendarview_p.h b/src/calendar/qquickabstractcalendarview_p.h new file mode 100644 index 00000000..ac55b234 --- /dev/null +++ b/src/calendar/qquickabstractcalendarview_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 QQUICKABSTRACTCALENDARVIEW_P_H +#define QQUICKABSTRACTCALENDARVIEW_P_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractCalendarViewPrivate; + +class Q_QUICKCALENDAR_EXPORT QQuickAbstractCalendarView : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged FINAL) + Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged FINAL) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) + Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) + +public: + explicit QQuickAbstractCalendarView(QQuickItem *parent = Q_NULLPTR); + + int month() const; + void setMonth(int month); + + int year() const; + void setYear(int year); + + QLocale locale() const; + void setLocale(const QLocale &locale); + + QVariant source() const; + void setSource(const QVariant &source); + + QString title() const; + void setTitle(const QString &title); + +Q_SIGNALS: + void monthChanged(); + void yearChanged(); + void localeChanged(); + void sourceChanged(); + void titleChanged(); + + void pressed(const QDate &date); + void released(const QDate &date); + void clicked(const QDate &date); + void pressAndHold(const QDate &date); + +protected: + void componentComplete() 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 timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractCalendarView) + Q_DECLARE_PRIVATE(QQuickAbstractCalendarView) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTCALENDARVIEW_P_H diff --git a/src/calendar/qquickabstractdayofweekrow.cpp b/src/calendar/qquickabstractdayofweekrow.cpp new file mode 100644 index 00000000..0d2830de --- /dev/null +++ b/src/calendar/qquickabstractdayofweekrow.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 "qquickabstractdayofweekrow_p.h" +#include "qquickdayofweekmodel_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractDayOfWeekRowPrivate : public QQuickAbstractContainerPrivate +{ +public: + QVariant source; + QQuickDayOfWeekModel *model; +}; + +QQuickAbstractDayOfWeekRow::QQuickAbstractDayOfWeekRow(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractDayOfWeekRowPrivate), parent) +{ + Q_D(QQuickAbstractDayOfWeekRow); + d->model = new QQuickDayOfWeekModel(this); + d->source = QVariant::fromValue(d->model); + connect(d->model, &QQuickDayOfWeekModel::localeChanged, this, &QQuickAbstractDayOfWeekRow::localeChanged); +} + +QLocale QQuickAbstractDayOfWeekRow::locale() const +{ + Q_D(const QQuickAbstractDayOfWeekRow); + return d->model->locale(); +} + +void QQuickAbstractDayOfWeekRow::setLocale(const QLocale &locale) +{ + Q_D(QQuickAbstractDayOfWeekRow); + d->model->setLocale(locale); +} + +QVariant QQuickAbstractDayOfWeekRow::source() const +{ + Q_D(const QQuickAbstractDayOfWeekRow); + return d->source; +} + +void QQuickAbstractDayOfWeekRow::setSource(const QVariant &source) +{ + Q_D(QQuickAbstractDayOfWeekRow); + if (d->source != source) { + d->source = source; + emit sourceChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/calendar/qquickabstractdayofweekrow_p.h b/src/calendar/qquickabstractdayofweekrow_p.h new file mode 100644 index 00000000..68dbe6fa --- /dev/null +++ b/src/calendar/qquickabstractdayofweekrow_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 Calendar 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 QQUICKABSTRACTDAYOFWEEKROW_P_H +#define QQUICKABSTRACTDAYOFWEEKROW_P_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractDayOfWeekRowPrivate; + +class Q_QUICKCALENDAR_EXPORT QQuickAbstractDayOfWeekRow : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) + Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) + +public: + explicit QQuickAbstractDayOfWeekRow(QQuickItem *parent = Q_NULLPTR); + + QLocale locale() const; + void setLocale(const QLocale &locale); + + QVariant source() const; + void setSource(const QVariant &source); + +Q_SIGNALS: + void localeChanged(); + void sourceChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractDayOfWeekRow) + Q_DECLARE_PRIVATE(QQuickAbstractDayOfWeekRow) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTDAYOFWEEKROW_P_H diff --git a/src/calendar/qquickabstractweeknumbercolumn.cpp b/src/calendar/qquickabstractweeknumbercolumn.cpp new file mode 100644 index 00000000..9357c0cf --- /dev/null +++ b/src/calendar/qquickabstractweeknumbercolumn.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 "qquickabstractweeknumbercolumn_p.h" +#include "qquickweeknumbermodel_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractWeekNumberColumnPrivate : public QQuickAbstractContainerPrivate +{ +public: + QVariant source; + QQuickWeekNumberModel *model; +}; + +QQuickAbstractWeekNumberColumn::QQuickAbstractWeekNumberColumn(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractWeekNumberColumnPrivate), parent) +{ + Q_D(QQuickAbstractWeekNumberColumn); + d->model = new QQuickWeekNumberModel(this); + d->source = QVariant::fromValue(d->model); + connect(d->model, &QQuickWeekNumberModel::monthChanged, this, &QQuickAbstractWeekNumberColumn::monthChanged); + connect(d->model, &QQuickWeekNumberModel::yearChanged, this, &QQuickAbstractWeekNumberColumn::yearChanged); + connect(d->model, &QQuickWeekNumberModel::localeChanged, this, &QQuickAbstractWeekNumberColumn::localeChanged); +} + +int QQuickAbstractWeekNumberColumn::month() const +{ + Q_D(const QQuickAbstractWeekNumberColumn); + return d->model->month(); +} + +void QQuickAbstractWeekNumberColumn::setMonth(int month) +{ + Q_D(QQuickAbstractWeekNumberColumn); + d->model->setMonth(month); +} + +int QQuickAbstractWeekNumberColumn::year() const +{ + Q_D(const QQuickAbstractWeekNumberColumn); + return d->model->year(); +} + +void QQuickAbstractWeekNumberColumn::setYear(int year) +{ + Q_D(QQuickAbstractWeekNumberColumn); + d->model->setYear(year); +} + +QLocale QQuickAbstractWeekNumberColumn::locale() const +{ + Q_D(const QQuickAbstractWeekNumberColumn); + return d->model->locale(); +} + +void QQuickAbstractWeekNumberColumn::setLocale(const QLocale &locale) +{ + Q_D(QQuickAbstractWeekNumberColumn); + d->model->setLocale(locale); +} + +QVariant QQuickAbstractWeekNumberColumn::source() const +{ + Q_D(const QQuickAbstractWeekNumberColumn); + return d->source; +} + +void QQuickAbstractWeekNumberColumn::setSource(const QVariant &source) +{ + Q_D(QQuickAbstractWeekNumberColumn); + if (d->source != source) { + d->source = source; + emit sourceChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/calendar/qquickabstractweeknumbercolumn_p.h b/src/calendar/qquickabstractweeknumbercolumn_p.h new file mode 100644 index 00000000..ab5ec096 --- /dev/null +++ b/src/calendar/qquickabstractweeknumbercolumn_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 QQUICKABSTRACTWEEKNUMBERCOLUMN_P_H +#define QQUICKABSTRACTWEEKNUMBERCOLUMN_P_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractWeekNumberColumnPrivate; + +class Q_QUICKCALENDAR_EXPORT QQuickAbstractWeekNumberColumn : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged FINAL) + Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged FINAL) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) + Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) + +public: + explicit QQuickAbstractWeekNumberColumn(QQuickItem *parent = Q_NULLPTR); + + int month() const; + void setMonth(int month); + + int year() const; + void setYear(int year); + + QLocale locale() const; + void setLocale(const QLocale &locale); + + QVariant source() const; + void setSource(const QVariant &source); + +Q_SIGNALS: + void monthChanged(); + void yearChanged(); + void localeChanged(); + void sourceChanged(); + +private: + Q_DISABLE_COPY(QQuickAbstractWeekNumberColumn) + Q_DECLARE_PRIVATE(QQuickAbstractWeekNumberColumn) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTWEEKNUMBERCOLUMN_P_H diff --git a/src/calendar/qquickcalendarmodel.cpp b/src/calendar/qquickcalendarmodel.cpp new file mode 100644 index 00000000..c1386ed0 --- /dev/null +++ b/src/calendar/qquickcalendarmodel.cpp @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 "qquickcalendarmodel_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QQuickCalendarModelPrivate : public QAbstractItemModelPrivate +{ + Q_DECLARE_PUBLIC(QQuickCalendarModel) + +public: + QQuickCalendarModelPrivate() : complete(false), + from(1,1,1), to(275759, 9, 25), count(0) + { + } + + static int getCount(const QDate& from, const QDate &to); + + void populate(const QDate &from, const QDate &to, bool force = false); + + bool complete; + QDate from; + QDate to; + int count; +}; + +int QQuickCalendarModelPrivate::getCount(const QDate& from, const QDate &to) +{ + QDate f(from.year(), from.month(), 1); + QDate t(to.year(), to.month(), to.daysInMonth()); + QDate r = QDate(1, 1, 1).addDays(f.daysTo(t)); + int years = r.year() - 1; + int months = r.month() - 1; + return 12 * years + months + (r.day() / t.day()); +} + +void QQuickCalendarModelPrivate::populate(const QDate &f, const QDate &t, bool force) +{ + Q_Q(QQuickCalendarModel); + if (!force && f == from && t == to) + return; + + int c = getCount(from, to); + if (c != count) { + q->beginResetModel(); + count = c; + q->endResetModel(); + emit q->countChanged(); + } else { + emit q->dataChanged(q->index(0, 0), q->index(c - 1, 0)); + } +} + +QQuickCalendarModel::QQuickCalendarModel(QObject *parent) : + QAbstractListModel(*(new QQuickCalendarModelPrivate), parent) +{ +} + +QDate QQuickCalendarModel::from() const +{ + Q_D(const QQuickCalendarModel); + return d->from; +} + +void QQuickCalendarModel::setFrom(const QDate &from) +{ + Q_D(QQuickCalendarModel); + if (d->from != from) { + if (d->complete) + d->populate(from, d->to); + d->from = from; + emit fromChanged(); + } +} + +QDate QQuickCalendarModel::to() const +{ + Q_D(const QQuickCalendarModel); + return d->to; +} + +void QQuickCalendarModel::setTo(const QDate &to) +{ + Q_D(QQuickCalendarModel); + if (d->to != to) { + if (d->complete) + d->populate(d->from, to); + d->to = to; + emit fromChanged(); + } +} + +int QQuickCalendarModel::monthAt(int index) const +{ + Q_D(const QQuickCalendarModel); + return d->from.addMonths(index).month(); +} + +int QQuickCalendarModel::yearAt(int index) const +{ + Q_D(const QQuickCalendarModel); + return d->from.addMonths(index).year(); +} + +int QQuickCalendarModel::indexOf(const QDate &date) const +{ + return indexOf(date.year(), date.month()); +} + +int QQuickCalendarModel::indexOf(int year, int month) const +{ + Q_D(const QQuickCalendarModel); + return d->getCount(d->from, QDate(year, month, 1)) - 1; +} + +QVariant QQuickCalendarModel::data(const QModelIndex &index, int role) const +{ + Q_D(const QQuickCalendarModel); + if (index.isValid() && index.row() < d->count) { + switch (role) { + case MonthRole: + return monthAt(index.row()); + case YearRole: + return yearAt(index.row()); + default: + break; + } + } + return QVariant(); +} + +int QQuickCalendarModel::rowCount(const QModelIndex &parent) const +{ + Q_D(const QQuickCalendarModel); + if (!parent.isValid()) + return d->count; + return 0; +} + +QHash QQuickCalendarModel::roleNames() const +{ + QHash roles; + roles[MonthRole] = QByteArrayLiteral("month"); + roles[YearRole] = QByteArrayLiteral("year"); + return roles; +} + +void QQuickCalendarModel::classBegin() +{ +} + +void QQuickCalendarModel::componentComplete() +{ + Q_D(QQuickCalendarModel); + d->complete = true; + d->populate(d->from, d->to, true); +} + +QT_END_NAMESPACE diff --git a/src/calendar/qquickcalendarmodel_p.h b/src/calendar/qquickcalendarmodel_p.h new file mode 100644 index 00000000..e5a650f8 --- /dev/null +++ b/src/calendar/qquickcalendarmodel_p.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 QQUICKCALENDARMODEL_P_H +#define QQUICKCALENDARMODEL_P_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickCalendarModelPrivate; + +class Q_QUICKCALENDAR_EXPORT QQuickCalendarModel : public QAbstractListModel, public QQmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QQmlParserStatus) + Q_PROPERTY(QDate from READ from WRITE setFrom NOTIFY fromChanged FINAL) + Q_PROPERTY(QDate to READ to WRITE setTo NOTIFY toChanged FINAL) + Q_PROPERTY(int count READ rowCount NOTIFY countChanged) + +public: + explicit QQuickCalendarModel(QObject *parent = Q_NULLPTR); + + QDate from() const; + void setFrom(const QDate &from); + + QDate to() const; + void setTo(const QDate &to); + + Q_INVOKABLE int monthAt(int index) const; + Q_INVOKABLE int yearAt(int index) const; + Q_INVOKABLE int indexOf(const QDate &date) const; + Q_INVOKABLE int indexOf(int year, int month) const; + + enum { + MonthRole, + YearRole + }; + + QHash roleNames() const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + +Q_SIGNALS: + void fromChanged(); + void toChanged(); + void countChanged(); + +protected: + void classBegin() Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickCalendarModel) + Q_DECLARE_PRIVATE(QQuickCalendarModel) +}; + +QT_END_NAMESPACE + +#endif // QQUICKCALENDARMODEL_P_H diff --git a/src/calendar/qquickdayofweekmodel.cpp b/src/calendar/qquickdayofweekmodel.cpp new file mode 100644 index 00000000..7f75f784 --- /dev/null +++ b/src/calendar/qquickdayofweekmodel.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 "qquickdayofweekmodel_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QQuickDayOfWeekModelPrivate : public QAbstractItemModelPrivate +{ + Q_DECLARE_PUBLIC(QQuickDayOfWeekModel) + +public: + QLocale locale; +}; + +QQuickDayOfWeekModel::QQuickDayOfWeekModel(QObject *parent) : + QAbstractListModel(*(new QQuickDayOfWeekModelPrivate), parent) +{ +} + +QLocale QQuickDayOfWeekModel::locale() const +{ + Q_D(const QQuickDayOfWeekModel); + return d->locale; +} + +void QQuickDayOfWeekModel::setLocale(const QLocale &locale) +{ + Q_D(QQuickDayOfWeekModel); + if (d->locale != locale) { + bool changed = d->locale.firstDayOfWeek() != locale.firstDayOfWeek(); + d->locale = locale; + emit localeChanged(); + if (changed) + emit dataChanged(index(0, 0), index(6, 0)); + } +} + +int QQuickDayOfWeekModel::dayAt(int index) const +{ + Q_D(const QQuickDayOfWeekModel); + int day = d->locale.firstDayOfWeek() + index; + if (day > 7) + day -= 7; + if (day == 7) + day = 0; // Qt::Sunday = 7, but Sunday is 0 in JS Date + return day; +} + +QVariant QQuickDayOfWeekModel::data(const QModelIndex &index, int role) const +{ + Q_D(const QQuickDayOfWeekModel); + if (index.isValid() && index.row() < 7) { + int day = dayAt(index.row()); + switch (role) { + case DayRole: + return day; + case LongNameRole: + return d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::LongFormat); + case ShortNameRole: + return d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::ShortFormat); + case NarrowNameRole: + return d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::NarrowFormat); + default: + break; + } + } + return QVariant(); +} + +int QQuickDayOfWeekModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return 7; +} + +QHash QQuickDayOfWeekModel::roleNames() const +{ + QHash roles; + roles[DayRole] = QByteArrayLiteral("day"); + roles[LongNameRole] = QByteArrayLiteral("longName"); + roles[ShortNameRole] = QByteArrayLiteral("shortName"); + roles[NarrowNameRole] = QByteArrayLiteral("narrowName"); + return roles; +} + +QT_END_NAMESPACE diff --git a/src/calendar/qquickdayofweekmodel_p.h b/src/calendar/qquickdayofweekmodel_p.h new file mode 100644 index 00000000..776444a3 --- /dev/null +++ b/src/calendar/qquickdayofweekmodel_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 QQUICKDAYOFWEEKMODEL_P_H +#define QQUICKDAYOFWEEKMODEL_P_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickDayOfWeekModelPrivate; + +class Q_QUICKCALENDAR_EXPORT QQuickDayOfWeekModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) + Q_PROPERTY(int count READ rowCount CONSTANT FINAL) + +public: + explicit QQuickDayOfWeekModel(QObject *parent = Q_NULLPTR); + + QLocale locale() const; + void setLocale(const QLocale &locale); + + Q_INVOKABLE int dayAt(int index) const; + + enum { + DayRole = Qt::UserRole + 1, + LongNameRole, + ShortNameRole, + NarrowNameRole + }; + + QHash roleNames() const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + +Q_SIGNALS: + void localeChanged(); + +private: + Q_DISABLE_COPY(QQuickDayOfWeekModel) + Q_DECLARE_PRIVATE(QQuickDayOfWeekModel) +}; + +QT_END_NAMESPACE + +#endif // QQUICKDAYOFWEEKMODEL_P_H diff --git a/src/calendar/qquickmonthmodel.cpp b/src/calendar/qquickmonthmodel.cpp new file mode 100644 index 00000000..61185d57 --- /dev/null +++ b/src/calendar/qquickmonthmodel.cpp @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 "qquickmonthmodel_p.h" + +#include + +namespace { + static const int daysInAWeek = 7; + static const int weeksOnACalendarMonth = 6; + static const int daysOnACalendarMonth = daysInAWeek * weeksOnACalendarMonth; +} + +QT_BEGIN_NAMESPACE + +class QQuickMonthModelPrivate : public QAbstractItemModelPrivate +{ + Q_DECLARE_PUBLIC(QQuickMonthModel) + +public: + QQuickMonthModelPrivate() : dates(daysOnACalendarMonth) + { + QDate date = QDate::currentDate(); + month = date.month(); + year = date.year(); + } + + bool populate(int month, int year, const QLocale &locale, bool force = false); + + int month; + int year; + QString title; + QLocale locale; + QVector dates; +}; + +bool QQuickMonthModelPrivate::populate(int m, int y, const QLocale &l, bool force) +{ + Q_Q(QQuickMonthModel); + if (!force && m == month && y == year && l.firstDayOfWeek() == locale.firstDayOfWeek()) + return false; + + // The actual first (1st) day of the month. + QDate firstDayOfMonthDate(y, m, 1); + int difference = ((firstDayOfMonthDate.dayOfWeek() - l.firstDayOfWeek()) + 7) % 7; + // The first day to display should never be the 1st of the month, as we want some days from + // the previous month to be visible. + if (difference == 0) + difference += 7; + QDate firstDateToDisplay = firstDayOfMonthDate.addDays(-difference); + + for (int i = 0; i < daysOnACalendarMonth; ++i) + dates[i] = firstDateToDisplay.addDays(i); + + q->setTitle(l.standaloneMonthName(m) + QStringLiteral(" ") + QString::number(y)); + + return true; +} + +QQuickMonthModel::QQuickMonthModel(QObject *parent) : + QAbstractListModel(*(new QQuickMonthModelPrivate), parent) +{ + Q_D(QQuickMonthModel); + d->populate(d->month, d->year, d->locale, true); +} + +int QQuickMonthModel::month() const +{ + Q_D(const QQuickMonthModel); + return d->month; +} + +void QQuickMonthModel::setMonth(int month) +{ + Q_D(QQuickMonthModel); + if (d->month != month) { + if (d->populate(month, d->year, d->locale)) + emit dataChanged(index(0, 0), index(daysOnACalendarMonth - 1, 0)); + d->month = month; + emit monthChanged(); + } +} + +int QQuickMonthModel::year() const +{ + Q_D(const QQuickMonthModel); + return d->year; +} + +void QQuickMonthModel::setYear(int year) +{ + Q_D(QQuickMonthModel); + if (d->year != year) { + if (d->populate(d->month, year, d->locale)) + emit dataChanged(index(0, 0), index(daysOnACalendarMonth - 1, 0)); + d->year = year; + emit yearChanged(); + } +} + +QLocale QQuickMonthModel::locale() const +{ + Q_D(const QQuickMonthModel); + return d->locale; +} + +void QQuickMonthModel::setLocale(const QLocale &locale) +{ + Q_D(QQuickMonthModel); + if (d->locale != locale) { + if (d->populate(d->month, d->year, locale)) + emit dataChanged(index(0, 0), index(daysOnACalendarMonth - 1, 0)); + d->locale = locale; + emit localeChanged(); + } +} + +QString QQuickMonthModel::title() const +{ + Q_D(const QQuickMonthModel); + return d->title; +} + +void QQuickMonthModel::setTitle(const QString &title) +{ + Q_D(QQuickMonthModel); + if (d->title != title) { + d->title = title; + emit titleChanged(); + } +} + +QDate QQuickMonthModel::dateAt(int index) const +{ + Q_D(const QQuickMonthModel); + return d->dates.value(index); +} + +int QQuickMonthModel::indexOf(const QDate &date) const +{ + Q_D(const QQuickMonthModel); + if (date < d->dates.first() || date > d->dates.last()) + return -1; + return qMax(qint64(0), d->dates.first().daysTo(date)); +} + +QVariant QQuickMonthModel::data(const QModelIndex &index, int role) const +{ + Q_D(const QQuickMonthModel); + if (index.isValid() && index.row() < daysOnACalendarMonth) { + const QDate date = d->dates.at(index.row()); + switch (role) { + case DateRole: + return date; + case DayRole: + return date.day(); + case TodayRole: + return date == QDate::currentDate(); + case WeekNumberRole: + return date.weekNumber(); + case MonthRole: + return date.month(); + case YearRole: + return date.year(); + default: + break; + } + } + return QVariant(); +} + +int QQuickMonthModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return daysOnACalendarMonth; +} + +QHash QQuickMonthModel::roleNames() const +{ + QHash roles; + roles[DateRole] = QByteArrayLiteral("date"); + roles[DayRole] = QByteArrayLiteral("day"); + roles[TodayRole] = QByteArrayLiteral("today"); + roles[WeekNumberRole] = QByteArrayLiteral("weekNumber"); + roles[MonthRole] = QByteArrayLiteral("month"); + roles[YearRole] = QByteArrayLiteral("year"); + return roles; +} + +QT_END_NAMESPACE diff --git a/src/calendar/qquickmonthmodel_p.h b/src/calendar/qquickmonthmodel_p.h new file mode 100644 index 00000000..22720cc8 --- /dev/null +++ b/src/calendar/qquickmonthmodel_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 QQUICKMONTHMODEL_P_H +#define QQUICKMONTHMODEL_P_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickMonthModelPrivate; + +class Q_QUICKCALENDAR_EXPORT QQuickMonthModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged FINAL) + Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged FINAL) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) + Q_PROPERTY(int count READ rowCount CONSTANT FINAL) + +public: + explicit QQuickMonthModel(QObject *parent = Q_NULLPTR); + + int month() const; + void setMonth(int month); + + int year() const; + void setYear(int year); + + QLocale locale() const; + void setLocale(const QLocale &locale); + + QString title() const; + void setTitle(const QString &title); + + Q_INVOKABLE QDate dateAt(int index) const; + Q_INVOKABLE int indexOf(const QDate &date) const; + + enum { + DateRole = Qt::UserRole + 1, + DayRole, + TodayRole, + WeekNumberRole, + MonthRole, + YearRole + }; + + QHash roleNames() const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + +Q_SIGNALS: + void monthChanged(); + void yearChanged(); + void localeChanged(); + void titleChanged(); + +private: + Q_DISABLE_COPY(QQuickMonthModel) + Q_DECLARE_PRIVATE(QQuickMonthModel) +}; + +QT_END_NAMESPACE + +#endif // QQUICKMONTHMODEL_P_H diff --git a/src/calendar/qquickweeknumbermodel.cpp b/src/calendar/qquickweeknumbermodel.cpp new file mode 100644 index 00000000..34d66202 --- /dev/null +++ b/src/calendar/qquickweeknumbermodel.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 "qquickweeknumbermodel_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickWeekNumberModelPrivate : public QAbstractItemModelPrivate +{ + Q_DECLARE_PUBLIC(QQuickWeekNumberModel) + +public: + QQuickWeekNumberModelPrivate() + { + QDate date = QDate::currentDate(); + month = date.month(); + year = date.year(); + first = calculateFirst(month, year, locale); + } + + void init(int month, int year, const QLocale &locale = QLocale()); + static int calculateFirst(int month, int year, const QLocale &locale); + + int month; + int year; + int first; + QLocale locale; +}; + +void QQuickWeekNumberModelPrivate::init(int m, int y, const QLocale &l) +{ + Q_Q(QQuickWeekNumberModel); + if (m == month && y == year && l.firstDayOfWeek() == locale.firstDayOfWeek()) + return; + + first = calculateFirst(m, y, l); + + emit q->dataChanged(q->index(0, 0), q->index(5, 0)); +} + +int QQuickWeekNumberModelPrivate::calculateFirst(int month, int year, const QLocale &locale) +{ + // The actual first (1st) day of the month. + QDate firstDayOfMonthDate(year, month, 1); + int difference = ((firstDayOfMonthDate.dayOfWeek() - locale.firstDayOfWeek()) + 7) % 7; + // The first day to display should never be the 1st of the month, as we want some days from + // the previous month to be visible. + if (difference == 0) + difference += 7; + return firstDayOfMonthDate.addDays(-difference).weekNumber(); +} + +QQuickWeekNumberModel::QQuickWeekNumberModel(QObject *parent) : + QAbstractListModel(*(new QQuickWeekNumberModelPrivate), parent) +{ +} + +int QQuickWeekNumberModel::month() const +{ + Q_D(const QQuickWeekNumberModel); + return d->month; +} + +void QQuickWeekNumberModel::setMonth(int month) +{ + Q_D(QQuickWeekNumberModel); + if (d->month != month) { + d->init(month, d->year, d->locale); + d->month = month; + emit monthChanged(); + } +} + +int QQuickWeekNumberModel::year() const +{ + Q_D(const QQuickWeekNumberModel); + return d->year; +} + +void QQuickWeekNumberModel::setYear(int year) +{ + Q_D(QQuickWeekNumberModel); + if (d->year != year) { + d->init(d->month, year, d->locale); + d->year = year; + emit yearChanged(); + } +} + +QLocale QQuickWeekNumberModel::locale() const +{ + Q_D(const QQuickWeekNumberModel); + return d->locale; +} + +void QQuickWeekNumberModel::setLocale(const QLocale &locale) +{ + Q_D(QQuickWeekNumberModel); + if (d->locale != locale) { + d->init(d->month, d->year, locale); + d->locale = locale; + emit localeChanged(); + } +} + +int QQuickWeekNumberModel::weekNumberAt(int index) const +{ + Q_D(const QQuickWeekNumberModel); + if (index < 0 || index > 5) + return -1; + return d->first + index; +} + +int QQuickWeekNumberModel::indexOf(int weekNumber) const +{ + Q_D(const QQuickWeekNumberModel); + if (weekNumber < d->first || weekNumber > d->first + 6) + return -1; + return weekNumber - d->first; +} + +QVariant QQuickWeekNumberModel::data(const QModelIndex &index, int role) const +{ + if (role == WeekNumberRole) { + int weekNumber = weekNumberAt(index.row()); + if (weekNumber != -1) + return weekNumber; + } + return QVariant(); +} + +int QQuickWeekNumberModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return 6; +} + +QHash QQuickWeekNumberModel::roleNames() const +{ + QHash roles; + roles[WeekNumberRole] = QByteArrayLiteral("weekNumber"); + return roles; +} + +QT_END_NAMESPACE diff --git a/src/calendar/qquickweeknumbermodel_p.h b/src/calendar/qquickweeknumbermodel_p.h new file mode 100644 index 00000000..d64da352 --- /dev/null +++ b/src/calendar/qquickweeknumbermodel_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 QQUICKWEEKNUMBERMODEL_P_H +#define QQUICKWEEKNUMBERMODEL_P_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickWeekNumberModelPrivate; + +class Q_QUICKCALENDAR_EXPORT QQuickWeekNumberModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged FINAL) + Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged FINAL) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) + Q_PROPERTY(int count READ rowCount CONSTANT FINAL) + +public: + explicit QQuickWeekNumberModel(QObject *parent = Q_NULLPTR); + + int month() const; + void setMonth(int month); + + int year() const; + void setYear(int year); + + QLocale locale() const; + void setLocale(const QLocale &locale); + + Q_INVOKABLE int weekNumberAt(int index) const; + Q_INVOKABLE int indexOf(int weekNumber) const; + + enum { + WeekNumberRole = Qt::UserRole + 1 + }; + + QHash roleNames() const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + +Q_SIGNALS: + void monthChanged(); + void yearChanged(); + void localeChanged(); + +private: + Q_DISABLE_COPY(QQuickWeekNumberModel) + Q_DECLARE_PRIVATE(QQuickWeekNumberModel) +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEEKNUMBERMODEL_P_H diff --git a/src/calendar/qtquickcalendarglobal_p.h b/src/calendar/qtquickcalendarglobal_p.h new file mode 100644 index 00000000..8f04361e --- /dev/null +++ b/src/calendar/qtquickcalendarglobal_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 Calendar 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 QTQUICKCALENDARGLOBAL_P_H +#define QTQUICKCALENDARGLOBAL_P_H + +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_QUICKCALENDAR_LIB) +# define Q_QUICKCALENDAR_EXPORT Q_DECL_EXPORT +# else +# define Q_QUICKCALENDAR_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_QUICKCALENDAR_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QTQUICKCALENDARGLOBAL_P_H 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 @@ + + + style.json + + 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 +#include + +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 +#include + +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 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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 +#include + +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(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(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(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(); + 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(); + 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(); + 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(); + 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 + +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 +#include + +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(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(); + 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(); + 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(); + 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(); + 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 + +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 + +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 + +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 + +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 + +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(object); + element->item = qobject_cast(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 createElements(const QV4::ScopedValue &value); + QQuickItem *pushElements(const QList &elements, QQuickAbstractStackView::Operation operation); + + bool busy; + int depth; + QVariant initialItem; + QQuickItem *currentItem; + QStack 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 QQuickAbstractStackViewPrivate::createElements(const QV4::ScopedValue &value) +{ + Q_Q(QQuickAbstractStackView); + QList 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()) { + qDebug() << "### QOBJECT:" << o->object(); + elements += QQuickStackElement::fromObject(o->object()); + } else { + qDebug("### UNKNOWN"); + } + return elements; +} + +QQuickItem *QQuickAbstractStackViewPrivate::pushElements(const QList &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 elements; + for (int i = 0; i < args->length(); ++i) { + QV4::ScopedValue value(scope, (*args)[i]); + if (value->isInt32()) + operation = static_cast(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()) + d->pushElements(QList() << QQuickStackElement::fromObject(o), Immediate); + else if (d->initialItem.canConvert()) + d->pushElements(QList() << 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 + +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 + +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(event)); + case QEvent::MouseMove: + return handleMouseMoveEvent(child, static_cast(event)); + case QEvent::MouseButtonRelease: + return handleMouseReleaseEvent(child, static_cast(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 + +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 + +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 + +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 + +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 +#include + +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 + +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 +#include + +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 + +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 + +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 + +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 + +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(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(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(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(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()) + 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 +#include + +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 +#include +#include + +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 +#include + +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 +#include +#include + +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 +#include + +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 +#include +#include +#include +#include +#include + +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 styles; + QHash::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 +#include +#include +#include + +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 + +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 +} diff --git a/src/extras/extras.pri b/src/extras/extras.pri new file mode 100644 index 00000000..6b97f98c --- /dev/null +++ b/src/extras/extras.pri @@ -0,0 +1,9 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qquickabstractdrawer_p.h \ + $$PWD/qquickabstractsplitview_p.h + +SOURCES += \ + $$PWD/qquickabstractdrawer.cpp \ + $$PWD/qquickabstractsplitview.cpp diff --git a/src/extras/extras.pro b/src/extras/extras.pro new file mode 100644 index 00000000..70ebcfcc --- /dev/null +++ b/src/extras/extras.pro @@ -0,0 +1,14 @@ +TARGET = QtQuickExtras +MODULE = quickextras +CONFIG += internal_module + +QT += quick +QT += core-private gui-private qml-private quick-private quickcontrols-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +HEADERS += \ + $$PWD/qtquickextrasglobal_p.h + +include(extras.pri) +load(qt_module) diff --git a/src/extras/qquickabstractdrawer.cpp b/src/extras/qquickabstractdrawer.cpp new file mode 100644 index 00000000..d25a7f0d --- /dev/null +++ b/src/extras/qquickabstractdrawer.cpp @@ -0,0 +1,388 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 "qquickabstractdrawer_p.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractDrawerPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractDrawer) + +public: + QQuickAbstractDrawerPrivate() : edge(Qt::LeftEdge), offset(0), position(0), + content(Q_NULLPTR), animation(Q_NULLPTR) { } + + void updateContent(); + bool handleMousePressEvent(QQuickItem *item, QMouseEvent *event); + bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event); + bool handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event); + + Qt::Edge edge; + qreal offset; + qreal position; + QPointF pressPoint; + QQuickItem *content; + QQuickPropertyAnimation *animation; +}; + +void QQuickAbstractDrawerPrivate::updateContent() +{ + Q_Q(QQuickAbstractDrawer); + if (!content) + return; + + switch (edge) { + case Qt::LeftEdge: + content->setX((position - 1.0) * content->width()); + break; + case Qt::RightEdge: + content->setX(q->width() + - position * content->width()); + break; + case Qt::TopEdge: + content->setY((position - 1.0) * content->height()); + break; + case Qt::BottomEdge: + content->setY(q->height() + - position * content->height()); + break; + } +} + +bool QQuickAbstractDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *event) +{ + Q_Q(QQuickAbstractDrawer); + pressPoint = q->mapFromItem(item, event->pos()); + + if (qFuzzyIsNull(position)) { + // only accept pressing at drag margins when fully closed + switch (edge) { + case Qt::LeftEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(event->x(), Qt::XAxis, event)); + break; + case Qt::RightEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(q->width() - event->x(), Qt::XAxis, event)); + break; + case Qt::TopEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(event->y(), Qt::YAxis, event)); + break; + case Qt::BottomEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(q->height() - event->y(), Qt::YAxis, event)); + break; + } + offset = 0; + } else { + event->accept(); + offset = q->positionAt(pressPoint) - position; + } + + return item == q; +} + +bool QQuickAbstractDrawerPrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event) +{ + Q_Q(QQuickAbstractDrawer); + QPointF movePoint = q->mapFromItem(item, event->pos()); + + if (!q->keepMouseGrab()) { + bool overThreshold = false; + if (edge == Qt::LeftEdge || edge == Qt::RightEdge) + overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event); + else + overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event); + + if (window && overThreshold) { + QQuickItem *grabber = q->window()->mouseGrabberItem(); + if (!grabber || !grabber->keepMouseGrab()) { + q->grabMouse(); + q->setKeepMouseGrab(overThreshold); + } + } + } + + if (q->keepMouseGrab()) + q->setPosition(q->positionAt(event->pos()) - offset); + event->accept(); + + return q->keepMouseGrab(); +} + +bool QQuickAbstractDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event) +{ + Q_Q(QQuickAbstractDrawer); + bool wasGrabbed = q->keepMouseGrab(); + if (wasGrabbed) { +// int startDragVelocity = QGuiApplication::styleHints()->startDragVelocity(); +// if (startDragVelocity && QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity) { +// QVector2D velocity = QGuiApplicationPrivate::mouseEventVelocity(event); +// qreal vel = (edge == Qt::LeftEdge || edge == Qt::RightEdge) ? velocity.x() : velocity.y(); +// qDebug() << vel << "vs." << startDragVelocity; +// } + if (position < 0.3) { + q->close(); + } else if (position > 0.7) { + q->open(); + } else { + switch (edge) { + case Qt::LeftEdge: + if (event->x() - pressPoint.x() > 0) + q->open(); + else + q->close(); + break; + case Qt::RightEdge: + if (event->x() - pressPoint.x() < 0) + q->open(); + else + q->close(); + break; + case Qt::TopEdge: + if (event->y() - pressPoint.y() > 0) + q->open(); + else + q->close(); + break; + case Qt::BottomEdge: + if (event->y() - pressPoint.y() < 0) + q->open(); + else + q->close(); + break; + } + } + q->setKeepMouseGrab(false); + } else { + if (item == q) + emit q->clicked(); + } + pressPoint = QPoint(); + event->accept(); + return wasGrabbed; +} + +QQuickAbstractDrawer::QQuickAbstractDrawer(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractDrawerPrivate), parent) +{ + setZ(1); + setFiltersChildMouseEvents(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +Qt::Edge QQuickAbstractDrawer::edge() const +{ + Q_D(const QQuickAbstractDrawer); + return d->edge; +} + +void QQuickAbstractDrawer::setEdge(Qt::Edge edge) +{ + Q_D(QQuickAbstractDrawer); + if (d->edge != edge) { + d->edge = edge; + if (isComponentComplete()) + d->updateContent(); + emit edgeChanged(); + } +} + +qreal QQuickAbstractDrawer::position() const +{ + Q_D(const QQuickAbstractDrawer); + return d->position; +} + +void QQuickAbstractDrawer::setPosition(qreal position) +{ + Q_D(QQuickAbstractDrawer); + position = qBound(0.0, position, 1.0); + if (!qFuzzyCompare(d->position, position)) { + d->position = position; + if (isComponentComplete()) + d->updateContent(); + emit positionChanged(); + } +} + +QQuickItem *QQuickAbstractDrawer::contentItem() const +{ + Q_D(const QQuickAbstractDrawer); + return d->content; +} + +void QQuickAbstractDrawer::setContentItem(QQuickItem *item) +{ + Q_D(QQuickAbstractDrawer); + if (d->content != item) { + delete d->content; + d->content = item; + if (item) + item->setParentItem(this); + if (isComponentComplete()) + d->updateContent(); + emit contentItemChanged(); + } +} + +QQuickPropertyAnimation *QQuickAbstractDrawer::animation() const +{ + Q_D(const QQuickAbstractDrawer); + return d->animation; +} + +void QQuickAbstractDrawer::setAnimation(QQuickPropertyAnimation *animation) +{ + Q_D(QQuickAbstractDrawer); + if (d->animation != animation) { + delete d->animation; + d->animation = animation; + if (animation) { + animation->setTargetObject(this); + animation->setProperty(QStringLiteral("position")); + } + emit animationChanged(); + } +} + +void QQuickAbstractDrawer::open() +{ + Q_D(QQuickAbstractDrawer); + if (d->animation) { + d->animation->stop(); + d->animation->setFrom(d->position); + d->animation->setTo(1.0); + d->animation->start(); + } else { + setPosition(1.0); + } +} + +void QQuickAbstractDrawer::close() +{ + Q_D(QQuickAbstractDrawer); + if (d->animation) { + d->animation->stop(); + d->animation->setFrom(d->position); + d->animation->setTo(0.0); + d->animation->start(); + } else { + setPosition(0.0); + } +} + +bool QQuickAbstractDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event) +{ + Q_D(QQuickAbstractDrawer); + switch (event->type()) { + case QEvent::MouseButtonPress: + return d->handleMousePressEvent(child, static_cast(event)); + case QEvent::MouseMove: + return d->handleMouseMoveEvent(child, static_cast(event)); + case QEvent::MouseButtonRelease: + return d->handleMouseReleaseEvent(child, static_cast(event)); + default: + return false; + } +} + +void QQuickAbstractDrawer::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractDrawer); + QQuickControl::mousePressEvent(event); + d->handleMousePressEvent(this, event); +} + +void QQuickAbstractDrawer::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractDrawer); + QQuickControl::mouseMoveEvent(event); + d->handleMouseMoveEvent(this, event); +} + +void QQuickAbstractDrawer::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractDrawer); + QQuickControl::mouseReleaseEvent(event); + d->handleMouseReleaseEvent(this, event); +} + +void QQuickAbstractDrawer::mouseUngrabEvent() +{ + Q_D(QQuickAbstractDrawer); + QQuickControl::mouseUngrabEvent(); + d->pressPoint = QPoint(); +} + +void QQuickAbstractDrawer::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickAbstractDrawer); + QQuickControl::geometryChanged(newGeometry, oldGeometry); + if (isComponentComplete()) + d->updateContent(); +} + +void QQuickAbstractDrawer::componentComplete() +{ + Q_D(QQuickAbstractDrawer); + QQuickControl::componentComplete(); + d->updateContent(); +} + +qreal QQuickAbstractDrawer::positionAt(const QPointF &point) const +{ + Q_D(const QQuickAbstractDrawer); + if (!d->content) + return 0.0; + + switch (d->edge) { + case Qt::TopEdge: + return point.y() / d->content->height(); + case Qt::LeftEdge: + return point.x() / d->content->width(); + case Qt::RightEdge: + return (width() - point.x()) / d->content->width(); + case Qt::BottomEdge: + return (height() - point.y()) / d->content->height(); + default: + return 0; + } +} + +QT_END_NAMESPACE diff --git a/src/extras/qquickabstractdrawer_p.h b/src/extras/qquickabstractdrawer_p.h new file mode 100644 index 00000000..5c9d44ec --- /dev/null +++ b/src/extras/qquickabstractdrawer_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 QQUICKABSTRACTDRAWER_P_H +#define QQUICKABSTRACTDRAWER_P_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickPropertyAnimation; +class QQuickAbstractDrawerPrivate; + +class Q_QUICKEXTRAS_EXPORT QQuickAbstractDrawer : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged FINAL) + Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) + Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) + // TODO: make this a proper transition + Q_PROPERTY(QQuickPropertyAnimation *animation READ animation WRITE setAnimation NOTIFY animationChanged FINAL) + Q_CLASSINFO("DefaultProperty", "contentItem") + +public: + explicit QQuickAbstractDrawer(QQuickItem *parent = Q_NULLPTR); + + Qt::Edge edge() const; + void setEdge(Qt::Edge edge); + + qreal position() const; + void setPosition(qreal position); + + QQuickItem *contentItem() const; + void setContentItem(QQuickItem *item); + + QQuickPropertyAnimation *animation() const; + void setAnimation(QQuickPropertyAnimation *animation); + +public Q_SLOTS: + void open(); + void close(); + +Q_SIGNALS: + void clicked(); + void edgeChanged(); + void positionChanged(); + void contentItemChanged(); + void animationChanged(); + +protected: + bool childMouseEventFilter(QQuickItem *child, QEvent *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 geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + + virtual qreal positionAt(const QPointF &point) const; + +private: + Q_DISABLE_COPY(QQuickAbstractDrawer) + Q_DECLARE_PRIVATE(QQuickAbstractDrawer) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTDRAWER_P_H diff --git a/src/extras/qquickabstractsplitview.cpp b/src/extras/qquickabstractsplitview.cpp new file mode 100644 index 00000000..cf20945e --- /dev/null +++ b/src/extras/qquickabstractsplitview.cpp @@ -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 Extras 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 "qquickabstractsplitview_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractSplitViewPrivate : public QQuickAbstractContainerPrivate +{ +public: + QQuickAbstractSplitViewPrivate() : orientation(Qt::Horizontal) { } + + bool resizing; + Qt::Orientation orientation; +}; + +QQuickAbstractSplitView::QQuickAbstractSplitView(QQuickItem *parent) : + QQuickAbstractContainer(*(new QQuickAbstractSplitViewPrivate), parent) +{ +} + +Qt::Orientation QQuickAbstractSplitView::orientation() const +{ + Q_D(const QQuickAbstractSplitView); + return d->orientation; +} + +void QQuickAbstractSplitView::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickAbstractSplitView); + if (d->orientation != orientation) { + d->orientation = orientation; + emit orientationChanged(); + } +} + +bool QQuickAbstractSplitView::isResizing() const +{ + Q_D(const QQuickAbstractSplitView); + return d->resizing; +} + +void QQuickAbstractSplitView::setResizing(bool resizing) +{ + Q_D(QQuickAbstractSplitView); + if (d->resizing != resizing) { + d->resizing = resizing; + emit resizingChanged(); + } +} + +void QQuickAbstractSplitView::addItem(QQuickItem *item) +{ + // TODO + Q_UNUSED(item); +} + +void QQuickAbstractSplitView::componentComplete() +{ +} + +QT_END_NAMESPACE diff --git a/src/extras/qquickabstractsplitview_p.h b/src/extras/qquickabstractsplitview_p.h new file mode 100644 index 00000000..e8bad706 --- /dev/null +++ b/src/extras/qquickabstractsplitview_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 Extras 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 QQUICKABSTRACTSPLITVIEW_P_H +#define QQUICKABSTRACTSPLITVIEW_P_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickAbstractSplitViewPrivate; + +class Q_QUICKEXTRAS_EXPORT QQuickAbstractSplitView : public QQuickAbstractContainer +{ + Q_OBJECT + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(bool resizing READ isResizing NOTIFY resizingChanged FINAL) + +public: + explicit QQuickAbstractSplitView(QQuickItem *parent = Q_NULLPTR); + + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + + bool isResizing() const; + void setResizing(bool resizing); + +public Q_SLOTS: + void addItem(QQuickItem *item); + +Q_SIGNALS: + void orientationChanged(); + void resizingChanged(); + +protected: + void componentComplete() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractSplitView) + Q_DECLARE_PRIVATE(QQuickAbstractSplitView) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTSPLITVIEW_P_H diff --git a/src/extras/qtquickextrasglobal_p.h b/src/extras/qtquickextrasglobal_p.h new file mode 100644 index 00000000..d0922dca --- /dev/null +++ b/src/extras/qtquickextrasglobal_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 Extras 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 QTQUICKEXTRASGLOBAL_P_H +#define QTQUICKEXTRASGLOBAL_P_H + +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_QUICKEXTRAS_LIB) +# define Q_QUICKEXTRAS_EXPORT Q_DECL_EXPORT +# else +# define Q_QUICKEXTRAS_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_QUICKEXTRAS_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QTQUICKEXTRASGLOBAL_P_H diff --git a/src/imports/calendar/CalendarDelegate.qml b/src/imports/calendar/CalendarDelegate.qml new file mode 100644 index 00000000..a6b000b7 --- /dev/null +++ b/src/imports/calendar/CalendarDelegate.qml @@ -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 Calendar 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 +import QtQuick.Calendar 2.0 + +Item { + property alias text: label.text + property alias color: label.color + property real padding + + implicitWidth: label.implicitWidth * 3 + implicitHeight: label.implicitHeight * 3 + + Text { + id: label + x: padding + y: padding + width: parent.width - 2 * padding + height: parent.height - 2 * padding + minimumPointSize: 8 + fontSizeMode: Text.Fit + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } +} diff --git a/src/imports/calendar/CalendarView.qml b/src/imports/calendar/CalendarView.qml new file mode 100644 index 00000000..ce6e9908 --- /dev/null +++ b/src/imports/calendar/CalendarView.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 +import QtQuick.Calendar 2.0 + +AbstractCalendarView { + id: control + + property Component delegate: CalendarDelegate { + width: grid.width ? grid.width / 7 : implicitWidth + height: grid.height ? grid.height / 6 : implicitHeight + opacity: model.month === control.month ? 1 : 0 + color: model.today ? style.accentColor : style.textColor + text: model.day + padding: style.padding + } + + contentWidth: grid.implicitWidth + contentHeight: grid.implicitHeight + + implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + padding.top + padding.bottom) + + Accessible.name: title + + contentItem: Grid { + id: grid + + rows: 6 + columns: 7 + + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + Repeater { + id: repeater + model: control.source + delegate: control.delegate + } + } +} diff --git a/src/imports/calendar/DayOfWeekRow.qml b/src/imports/calendar/DayOfWeekRow.qml new file mode 100644 index 00000000..5a33b5ee --- /dev/null +++ b/src/imports/calendar/DayOfWeekRow.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 +import QtQuick.Calendar 2.0 + +AbstractDayOfWeekRow { + id: control + + property Component delegate: Text { + text: model.shortName + font.bold: true + color: control.style.textColor + width: row.width ? row.width / 7 : implicitWidth + height: row.height ? row.height : implicitHeight + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + contentWidth: row.implicitWidth + contentHeight: row.implicitHeight + + implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + padding.top + padding.bottom) + + padding { top: style.padding; bottom: style.padding } + + contentItem: Row { + id: row + + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + Repeater { + model: control.source + delegate: control.delegate + } + } +} diff --git a/src/imports/calendar/WeekNumberColumn.qml b/src/imports/calendar/WeekNumberColumn.qml new file mode 100644 index 00000000..e2d1f63c --- /dev/null +++ b/src/imports/calendar/WeekNumberColumn.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 +import QtQuick.Calendar 2.0 + +AbstractWeekNumberColumn { + id: control + + property Component delegate: Text { + text: model.weekNumber + font.bold: true + color: control.style.textColor + width: column.width ? column.width : implicitWidth + height: column.height ? column.height / 6 : implicitHeight + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + contentWidth: column.implicitWidth + contentHeight: column.implicitHeight + + implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + padding.top + padding.bottom) + + padding { left: style.padding; right: style.padding } + + contentItem: Column { + id: column + + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + Repeater { + model: control.source + delegate: control.delegate + } + } +} diff --git a/src/imports/calendar/calendar.pro b/src/imports/calendar/calendar.pro new file mode 100644 index 00000000..625be272 --- /dev/null +++ b/src/imports/calendar/calendar.pro @@ -0,0 +1,21 @@ +TARGET = qtquickcalendar2plugin +TARGETPATH = QtQuick/Calendar.2 +IMPORT_VERSION = 2.0 + +QT += qml quick +QT += core-private gui-private qml-private quick-private quickcontrols-private quickcalendar-private + +OTHER_FILES += \ + qmldir + +QML_FILES = \ + CalendarDelegate.qml \ + CalendarView.qml \ + DayOfWeekRow.qml \ + WeekNumberColumn.qml + +SOURCES += \ + $$PWD/qtquickcalendar2plugin.cpp + +CONFIG += no_cxx_module +load(qml_plugin) diff --git a/src/imports/calendar/qmldir b/src/imports/calendar/qmldir new file mode 100644 index 00000000..af87241f --- /dev/null +++ b/src/imports/calendar/qmldir @@ -0,0 +1,7 @@ +module QtQuick.Calendar +plugin qtquickcalendar2plugin +classname QtQuickCalendar2Plugin +CalendarDelegate 2.0 CalendarDelegate.qml +CalendarView 2.0 CalendarView.qml +DayOfWeekRow 2.0 DayOfWeekRow.qml +WeekNumberColumn 2.0 WeekNumberColumn.qml diff --git a/src/imports/calendar/qtquickcalendar2plugin.cpp b/src/imports/calendar/qtquickcalendar2plugin.cpp new file mode 100644 index 00000000..8e84e094 --- /dev/null +++ b/src/imports/calendar/qtquickcalendar2plugin.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Calendar 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 + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QtQuickCalendar2Plugin: public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") + +public: + void registerTypes(const char *uri); +}; + +void QtQuickCalendar2Plugin::registerTypes(const char *uri) +{ + qmlRegisterType(uri, 2, 0, "AbstractCalendarView"); + qmlRegisterType(uri, 2, 0, "AbstractDayOfWeekRow"); + qmlRegisterType(uri, 2, 0, "AbstractWeekNumberColumn"); + qmlRegisterType(uri, 2, 0, "CalendarModel"); + qmlRegisterType(uri, 2, 0, "DayOfWeekModel"); + qmlRegisterType(uri, 2, 0, "MonthModel"); + qmlRegisterType(uri, 2, 0, "WeekNumberModel"); +} + +QT_END_NAMESPACE + +#include "qtquickcalendar2plugin.moc" diff --git a/src/imports/controls/ApplicationWindow.qml b/src/imports/controls/ApplicationWindow.qml new file mode 100644 index 00000000..036630e4 --- /dev/null +++ b/src/imports/controls/ApplicationWindow.qml @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Window 2.2 +import QtQuick.Controls 2.0 + +AbstractApplicationWindow { + id: window + + color: style.backgroundColor + flags: Qt.Window | Qt.WindowFullscreenButtonHint + + contentWidth: contentItem.children.length === 1 ? contentItem.children[0].implicitWidth : 0 + contentHeight: contentItem.children.length === 1 ? contentItem.children[0].implicitHeight : 0 + + minimumWidth: Math.max(contentWidth, + (header ? header.implicitWidth : 0), + (footer ? footer.implicitWidth : 0)) + minimumHeight: contentHeight + (header ? header.implicitHeight : 0) + + (footer ? footer.implicitHeight : 0) +} diff --git a/src/imports/controls/BusyIndicator.qml b/src/imports/controls/BusyIndicator.qml new file mode 100644 index 00000000..09abd9dc --- /dev/null +++ b/src/imports/controls/BusyIndicator.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractBusyIndicator { + id: control + + implicitWidth: indicator.implicitWidth + padding.left + padding.right + implicitHeight: indicator.implicitHeight + padding.top + padding.bottom + + Accessible.role: Accessible.Indicator + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + indicator: Item { + id: delegate + implicitWidth: 48 + implicitHeight: 48 + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: parent.width + height: parent.height + + opacity: control.running ? 1 : 0 + Behavior on opacity { OpacityAnimator { duration: 250 } } + + Image { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: Math.min(parent.width, parent.height) + height: width + source: width <= 32 ? "qrc:/images/spinner_small.png" : + width >= 48 ? "qrc:/images/spinner_large.png" : + "qrc:/images/spinner_medium.png" + + RotationAnimator on rotation { + duration: 800 + loops: Animation.Infinite + from: 0 + to: 360 + running: control.visible && (control.running || delegate.opacity > 0) + } + } + } +} diff --git a/src/imports/controls/Button.qml b/src/imports/controls/Button.qml new file mode 100644 index 00000000..8ec7065b --- /dev/null +++ b/src/imports/controls/Button.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + label ? label.implicitWidth + padding.left + padding.right : 0) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + label ? label.implicitHeight + padding.top + padding.bottom : 0) + + Accessible.name: text + Accessible.pressed: pressed + Accessible.role: Accessible.Button + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + label: Text { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + text: control.text + color: control.style.selectedTextColor + elide: Text.ElideRight + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + implicitWidth: 26 + implicitHeight: 26 + + radius: style.roundness + opacity: control.enabled ? 1.0 : style.disabledOpacity + color: Qt.tint(Qt.tint(style.accentColor, + control.activeFocus ? style.focusColor : "transparent"), + control.pressed ? style.pressColor : "transparent") + } +} diff --git a/src/imports/controls/CheckBox.qml b/src/imports/controls/CheckBox.qml new file mode 100644 index 00000000..6bc8f473 --- /dev/null +++ b/src/imports/controls/CheckBox.qml @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractCheckBox { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + (label ? label.implicitWidth : 0) + + (indicator ? indicator.implicitWidth : 0) + + (label && indicator ? style.spacing : 0) + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + Math.max(label ? label.implicitHeight : 0, + indicator ? indicator.implicitHeight : 0) + padding.top + padding.bottom) + + Accessible.name: text + Accessible.checked: checked + Accessible.pressed: pressed + Accessible.role: Accessible.CheckBox + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + indicator: Rectangle { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + implicitWidth: 20 + implicitHeight: 20 + x: text ? (mirror ? parent.width - width - padding.right : padding.left) : (parent.width - width) / 2 + y: (parent.height - height) / 2 + + radius: style.roundness + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? style.focusColor : style.frameColor + opacity: enabled ? 1.0 : style.disabledOpacity + color: style.backgroundColor + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 12 + height: 12 + color: Qt.tint(Qt.tint(control.checked ? style.accentColor : style.baseColor, + control.checked && control.activeFocus ? style.focusColor : "transparent"), + control.pressed ? style.pressColor : "transparent") + border.width: control.checked || control.pressed ? 0 : 1 + border.color: style.frameColor + } + } + + label: Text { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + x: mirror ? padding.left : (indicator.x + indicator.width + control.style.spacing) + y: padding.top + width: parent.width - indicator.width - control.style.spacing - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + text: control.text + color: control.style.textColor + elide: Text.ElideRight + visible: control.text + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + } +} diff --git a/src/imports/controls/Frame.qml b/src/imports/controls/Frame.qml new file mode 100644 index 00000000..62582263 --- /dev/null +++ b/src/imports/controls/Frame.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractFrame { + id: control + + default property alias data: content.data + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentHeight + padding.top + padding.bottom) + + contentWidth: content.children.length === 1 ? content.children[0].implicitWidth : 0 + contentHeight: content.children.length === 1 ? content.children[0].implicitHeight : 0 + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + contentItem: Item { + id: content + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + } + + background: Rectangle { + color: "transparent" + radius: style.roundness + border.color: style.frameColor + } +} diff --git a/src/imports/controls/GroupBox.qml b/src/imports/controls/GroupBox.qml new file mode 100644 index 00000000..39e45adb --- /dev/null +++ b/src/imports/controls/GroupBox.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractGroupBox { + id: control + + default property alias data: content.data + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentHeight + padding.top + padding.bottom) + + contentWidth: content.children.length === 1 ? content.children[0].implicitWidth : 0 + contentHeight: content.children.length === 1 ? content.children[0].implicitHeight : 0 + + padding { + top: style.padding + (label && title ? label.implicitHeight + style.spacing : 0) + left: style.padding + right: style.padding + bottom: style.padding + } + + contentItem: Item { + id: content + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + } + + label: Text { + x: padding.left + width: parent.width - padding.left - padding.right + + text: control.title + color: control.style.textColor + elide: Text.ElideRight + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + } + + frame: Rectangle { + y: padding.top - style.padding + width: parent.width + height: parent.height - padding.top + style.padding + + color: "transparent" + radius: style.roundness + border.color: style.frameColor + } +} diff --git a/src/imports/controls/Label.qml b/src/imports/controls/Label.qml new file mode 100644 index 00000000..872cb978 --- /dev/null +++ b/src/imports/controls/Label.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +Text { + id: control + + // TODO: color: style.textColor + + Accessible.name: text + Accessible.role: Accessible.StaticText +} diff --git a/src/imports/controls/PageIndicator.qml b/src/imports/controls/PageIndicator.qml new file mode 100644 index 00000000..db6dbdde --- /dev/null +++ b/src/imports/controls/PageIndicator.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractPageIndicator { + id: control + + property alias spacing: row.spacing + + property Component delegate: Rectangle { + implicitWidth: 8 + implicitHeight: 8 + + radius: width / 2 + color: style.shadowColor // TODO + + opacity: index === currentIndex ? 0.75 : 0.25 + Behavior on opacity { OpacityAnimator { duration: 100 } } + } + + Accessible.role: Accessible.Indicator + + contentWidth: row.implicitWidth + contentHeight: row.implicitHeight + + implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + padding.top + padding.bottom) + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + contentItem: Row { + id: row + + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + spacing: style.spacing + + Repeater { + model: control.count + delegate: control.delegate + } + } +} diff --git a/src/imports/controls/ProgressBar.qml b/src/imports/controls/ProgressBar.qml new file mode 100644 index 00000000..8e6342ee --- /dev/null +++ b/src/imports/controls/ProgressBar.qml @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractProgressBar { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + indicator ? indicator.implicitWidth : 0) + padding.left + padding.right + implicitHeight: Math.max(background ? background.implicitHeight : 0, + indicator ? indicator.implicitHeight : 0) + padding.top + padding.bottom + + Accessible.role: Accessible.ProgressBar + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + indicator: Item { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + scale: control.effectiveLayoutDirection === Qt.RightToLeft ? -1 : 1 + + Repeater { + model: indeterminate ? 2 : 1 + + Rectangle { + property real offset: indeterminate ? 0 : control.value + + x: 2 + (indeterminate ? offset * parent.width - 4 : 0) + y: (parent.height - height) / 2 + width: offset * (parent.width - x) - 2 + height: 2 + + color: style.accentColor + radius: style.roundness + + SequentialAnimation on offset { + loops: Animation.Infinite + running: indeterminate && visible + PauseAnimation { duration: index ? 520 : 0 } + NumberAnimation { + easing.type: Easing.OutCubic + duration: 1240 + from: 0 + to: 1 + } + PauseAnimation { duration: index ? 0 : 520 } + } + } + } + } + + background: Rectangle { + implicitWidth: 120 + implicitHeight: 6 + x: padding.left + y: (parent.height - height) / 2 + width: parent.width - padding.left - padding.bottom + height: 6 + + radius: style.roundness + border.color: style.frameColor + color: "transparent" + } +} diff --git a/src/imports/controls/RadioButton.qml b/src/imports/controls/RadioButton.qml new file mode 100644 index 00000000..919ab947 --- /dev/null +++ b/src/imports/controls/RadioButton.qml @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractRadioButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + (label ? label.implicitWidth : 0) + + (indicator ? indicator.implicitWidth : 0) + + (label && indicator ? style.spacing : 0) + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + Math.max(label ? label.implicitHeight : 0, + indicator ? indicator.implicitHeight : 0) + padding.top + padding.bottom) + + Accessible.name: text + Accessible.checked: checked + Accessible.pressed: pressed + Accessible.role: Accessible.RadioButton + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + indicator: Rectangle { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + implicitWidth: 20 + implicitHeight: 20 + x: text ? (mirror ? parent.width - width - padding.right : padding.left) : (parent.width - width) / 2 + y: (parent.height - height) / 2 + + radius: width / 2 + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? style.focusColor : style.frameColor + opacity: enabled ? 1.0 : style.disabledOpacity + color: style.backgroundColor + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 12 + height: 12 + radius: width / 2 + color: Qt.tint(Qt.tint(control.checked ? style.accentColor : style.baseColor, + control.checked && control.activeFocus ? style.focusColor : "transparent"), + control.pressed ? style.pressColor : "transparent") + border.width: control.checked || control.pressed ? 0 : 1 + border.color: style.frameColor + } + } + + label: Text { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + x: mirror ? padding.left : (indicator.x + indicator.width + control.style.spacing) + y: padding.top + width: parent.width - indicator.width - control.style.spacing - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + text: control.text + color: control.style.textColor + elide: Text.ElideRight + visible: control.text + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + } +} diff --git a/src/imports/controls/ScrollBar.qml b/src/imports/controls/ScrollBar.qml new file mode 100644 index 00000000..83e8ac6b --- /dev/null +++ b/src/imports/controls/ScrollBar.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractScrollBar { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + handle.implicitWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + handle.implicitHeight + padding.top + padding.bottom) + + Accessible.pressed: pressed + Accessible.role: Accessible.ScrollBar + + padding { top: 2; left: 2; right: 2; bottom: 2 } + + handle: Rectangle { + id: handle + + implicitWidth: 6 + implicitHeight: 6 + + radius: width / 2 + color: control.pressed ? style.shadowColor : style.frameColor + visible: control.size < 1.0 + opacity: 0.0 + + readonly property bool horizontal: control.orientation === Qt.Horizontal + x: padding.left + (horizontal ? control.position * control.width : 0) + y: padding.top + (horizontal ? 0 : control.position * control.height) + width: horizontal ? control.size * control.width - padding.left - padding.right : implicitWidth + height: horizontal ? implicitHeight : control.size * control.height - padding.top - padding.bottom + + states: State { + name: "active" + when: control.active + PropertyChanges { target: handle; opacity: 1.0 - style.disabledOpacity } + } + + transitions: Transition { + from: "active" + SequentialAnimation { + PauseAnimation { duration: 450 } + NumberAnimation { target: handle; duration: 200; property: "opacity"; to: 0.0 } + } + } + } +} diff --git a/src/imports/controls/ScrollIndicator.qml b/src/imports/controls/ScrollIndicator.qml new file mode 100644 index 00000000..7a4bbba6 --- /dev/null +++ b/src/imports/controls/ScrollIndicator.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractScrollIndicator { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + indicator.implicitWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + indicator.implicitHeight + padding.top + padding.bottom) + + Accessible.role: Accessible.Indicator + + padding { top: 2; left: 2; right: 2; bottom: 2 } + + indicator: Rectangle { + id: indicator + + implicitWidth: 2 + implicitHeight: 2 + + color: style.frameColor + visible: control.size < 1.0 + opacity: 0.0 + + readonly property bool horizontal: control.orientation === Qt.Horizontal + x: padding.left + (horizontal ? control.position * control.width : 0) + y: padding.top + (horizontal ? 0 : control.position * control.height) + width: horizontal ? control.size * control.width - padding.left - padding.right : implicitWidth + height: horizontal ? implicitHeight : control.size * control.height - padding.top - padding.bottom + + states: State { + name: "active" + when: control.active + PropertyChanges { target: indicator; opacity: 1.0 - style.disabledOpacity } + } + + transitions: [ + Transition { + from: "active" + SequentialAnimation { + PauseAnimation { duration: 450 } + NumberAnimation { target: indicator; duration: 200; property: "opacity"; to: 0.0 } + } + } + ] + } +} diff --git a/src/imports/controls/Slider.qml b/src/imports/controls/Slider.qml new file mode 100644 index 00000000..fc6abc60 --- /dev/null +++ b/src/imports/controls/Slider.qml @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractSlider { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + Math.max(track ? track.implicitWidth : 0, + handle ? handle.implicitWidth : 0) + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + Math.max(track ? track.implicitHeight : 0, + handle ? handle.implicitHeight : 0) + padding.top + padding.bottom) + + Accessible.pressed: pressed + Accessible.role: Accessible.Slider + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + handle: Rectangle { + implicitWidth: 20 + implicitHeight: 20 + radius: width / 2 + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? style.focusColor : style.frameColor + color: style.backgroundColor + + readonly property bool horizontal: control.orientation === Qt.Horizontal + x: horizontal ? control.visualPosition * (control.width - width) : (control.width - width) / 2 + y: horizontal ? (control.height - height) / 2 : control.visualPosition * (control.height - height) + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 12 + height: 12 + radius: width / 2 + + color: Qt.tint(Qt.tint(style.accentColor, + control.activeFocus ? style.focusColor : "transparent"), + control.pressed ? style.pressColor : "transparent") + } + } + + track: Rectangle { + readonly property bool horizontal: control.orientation === Qt.Horizontal + implicitWidth: horizontal ? 120 : 6 + implicitHeight: horizontal ? 6 : 120 + x: horizontal ? padding.left : (control.width - width) / 2 + y: horizontal ? (control.height - height) / 2 : padding.top + width: horizontal ? parent.width - padding.left - padding.right : implicitWidth + height: horizontal ? implicitHeight : parent.height - padding.top - padding.bottom + + radius: style.roundness + border.color: style.frameColor + color: style.backgroundColor + scale: control.effectiveLayoutDirection === Qt.RightToLeft ? -1 : 1 + + Rectangle { + x: 2 + y: 2 + width: control.position * parent.width - 4 + height: 2 + + color: style.accentColor + radius: style.roundness + } + } +} diff --git a/src/imports/controls/SpinBox.qml b/src/imports/controls/SpinBox.qml new file mode 100644 index 00000000..cf11cfdb --- /dev/null +++ b/src/imports/controls/SpinBox.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractSpinBox { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + (upButton ? upButton.implicitWidth : 0) + + (downButton ? downButton.implicitWidth : 0) + + (input ? input.implicitWidth : 0) + style.padding * 2) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + (upButton ? upButton.implicitHeight : 0), + (downButton ? downButton.implicitHeight : 0), + (input ? input.implicitHeight : 0) + style.padding * 2) + + Accessible.role: Accessible.SpinBox + + input: TextInput { + x: upButton.width + width: parent.width - upButton.width - downButton.width + height: parent.height + + color: style.textColor + selectionColor: style.selectionColor + selectedTextColor: style.selectedTextColor + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignVCenter + Keys.forwardTo: control + } + + validator: IntValidator { } + + upButton: Item { + implicitWidth: 26 + height: parent.height + x: parent.width - width + + opacity: enabled ? 1.0 : style.disabledOpacity + clip: true + Rectangle { + x: -radius + width: parent.width + radius + height: parent.height + radius: style.roundness + color: Qt.tint(Qt.tint(style.accentColor, + control.activeFocus ? style.focusColor : "transparent"), + pressed === AbstractSpinBox.UpButton ? style.pressColor : "transparent") + } + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: parent.width / 3 + height: 2 + color: control.style.selectedTextColor + } + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 2 + height: parent.height / 3 + color: control.style.selectedTextColor + } + } + + downButton: Item { + implicitWidth: 26 + height: parent.height + + opacity: enabled ? 1.0 : style.disabledOpacity + clip: true + Rectangle { + width: parent.width + radius + height: parent.height + radius: style.roundness + color: Qt.tint(Qt.tint(style.accentColor, + control.activeFocus ? style.focusColor : "transparent"), + pressed === AbstractSpinBox.DownButton ? style.pressColor : "transparent") + } + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: parent.width / 3 + height: 2 + color: control.style.selectedTextColor + } + } + + background: Rectangle { + implicitWidth: 120 + radius: style.roundness + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? style.focusColor : style.frameColor + opacity: enabled ? 1.0 : style.disabledOpacity + color: input.acceptableInput ? "white" : "lightpink" + } +} diff --git a/src/imports/controls/StackView.js b/src/imports/controls/StackView.js new file mode 100644 index 00000000..37e2066d --- /dev/null +++ b/src/imports/controls/StackView.js @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +var stackView = []; + +function push(p) +{ + if (!p) + return + stackView.push(p) + __depth++ + return p +} + +function pop() +{ + if (stackView.length === 0) + return null + var p = stackView.pop() + __depth-- + return p +} + +function current() +{ + if (stackView.length === 0) + return null + return stackView[stackView.length-1] +} + diff --git a/src/imports/controls/StackView.qml b/src/imports/controls/StackView.qml new file mode 100644 index 00000000..2c75f063 --- /dev/null +++ b/src/imports/controls/StackView.qml @@ -0,0 +1,954 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtQuick.Controls 2.0 +import "StackView.js" as JSArray + +/*! + \qmltype StackView + \inherits Item + \ingroup views + \inqmlmodule QtQuick.Controls + \since 5.1 + + \brief Provides a stack-based navigation model. + + \image stackview.png + + StackView implements a stack-based navigation model, which can be used + with a set of interlinked information pages. Items are pushed onto the stack + as the user navigates deeper into the material, and popped off again when he + chooses to go back. + + The \l{Qt Quick Controls - Touch Gallery}{touch gallery} example is a good + starting point to understand how StackView works. The following snippet + from the example shows how it can be used: + + \qml + StackView { + id: stack + initialItem: view + + Component { + id: view + + MouseArea { + Text { + text: stack.depth + anchors.centerIn: parent + } + onClicked: stack.push(view) + } + } + } + \endqml + + \section1 Using StackView in an Application + Using the StackView in the application is typically a simple matter of adding + the StackView as a child of a Window. The stack is usually anchored to the + edges of the window, except at the top or bottom where it might be anchored + to a status bar, or some other similar UI component. The stack can then be + used by invoking its navigation methods. The first item to show in the StackView + is commonly loaded assigning it to \l initialItem. + + \note Items pushed onto the stack view have \l{Supported Attached Properties}{Stack attached properties}. + + \section1 Basic Navigation + There are three primary navigation operations in StackView: push(), pop(), and + replace (replace by specifying argument \c replace to push()). + These correspond to classic stack operations where "push" adds an item to the + top of a stack, "pop" removes the top item from the stack, and "replace" is like a + pop followed by a push in that it replaces the topmost item on the stack with + a new item (but the applied transtition might be different). The topmost item + in the stack corresponds to the one that is \l{StackView::currentItem} {currently} + visible on the screen. That means that "push" is the logical equivalent of navigating + forward or deeper into the application, "pop" is the equivalent of navigating back, + and "replace" is the equivalent of replacing the current item. + + Sometimes it is necessary to go back more than a single step in the stack, for + example, to return to a "main" item or some kind of section item in the application. + For this use case, it is possible to specify an item as a parameter for pop(). + This is called an "unwind" operation as the stack gets unwound to the specified item. + If the item is not found then the stack unwinds until there is only a single item in + the stack, which becomes the current item. To explicitly unwind to the bottom + of the stack it is recommended to use \l{pop()} {pop(null)}, though technically any + non-existent item will do. + + Given the stack [A, B, C]: + + \list + \li \l{push()}{push(D)} => [A, B, C, D] - "push" transition animation between C and D + \li pop() => [A, B] - "pop" transition animation between C and B + \li \l{push()}{push(D, replace)} => [A, B, D] - "replace" transition between C and D + \li \l{pop()}{pop(A)} => [A] - "pop" transition between C and A + \endlist + + \note Note that when the stack is empty, a push() will not perform a + transition animation because there is nothing to transition from (typically during + application start-up). A pop() on a stack with depth 1 or 0 is a no-operation. + If removing all items from the stack is needed, a separate function clear() is + available. + + Calling push() returns the item that was pushed onto the stack. + Calling pop() returns the item that was popped off the stack. When pop() is + called in an unwind operation the top-most item (the first item that was + popped, which will also be the one transitioning out) is returned. + + \section1 Deep Linking + \e{Deep linking} means launching an application into a particular state. For example, + a newspaper application could be launched into showing a particular article, + bypassing the front item (and possibly a section item) that would normally have + to be navigated through to get to the article concerned. In terms of StackView, deep + linking means the ability to modify the state of the stack, so much so that it is + possible to push a set of items to the top of the stack, or to completely reset + the stack to a given state. + + The API for deep linking in StackView is the same as for basic navigation. Pushing + an array instead of a single item, will involve that all the items in that array will + be pushed onto the stack. The transition animation, however, will be conducted as + if only the last item in the array was pushed onto the stack. The normal semantics + of push() apply for deep linking, meaning that push() adds whatever is pushed onto + the stack. Note also that only the last item of the array will be loaded. + The rest will be lazy-loaded as needed when entering the screen upon subsequent + calls to pop (or when requesting the item by using \a get). + + This gives us the following result, given the stack [A, B, C]: + + \list + \li \l{push()}{push([D, E, F])} => [A, B, C, D, E, F] - "push" transition animation between C and F + \li \l{push()}{push([D, E, F], replace)} => [A, B, D, E, F] - "replace" transition animation between C and F + \li clear(); \l{push()}{push([D, E, F])} => [D, E, F] - no transition animation (since the stack was empty) + \endlist + + \section1 Pushing items + + An item pushed onto the StackView can be either an Item, a URL, a string + with a URL, or a Component. To push it, assign it to a property "item" + inside a property list, and send it as an argument to \l{StackView::push}{push}: + + \code + stackView.push({item: yourItem}) + \endcode + + The list can contain several properties that control how the item should be pushed: + \list + \li \c item: this property is required, and holds the item to be pushed. + \li \c properties: a list of QML properties to be assigned to the item upon push. These + properties will be copied into the item at load time, or when the item will become + the current item (normally upon push). + \li \c immediate: set this property to \c true to skip transition effects. When pushing + an array, this property only needs to be set on the first element to make the + whole operation immediate. + \li \c replace: set this property to replace the current item on the stack. When pushing + an array, you only need to set this property on the first element to replace + as many elements on the stack as inside the array. + \li \c destroyOnPop: set this boolean to true if StackView needs to destroy the item when + it is popped off the stack. By default (if \a destroyOnPop is not specified), StackView + will destroy items pushed as components or URLs. Items not destroyed will be re-parented + back to the original parents they had before being pushed onto the stack and hidden. + If you need to set this property, do it with care, so that items are not leaked. + \endlist + + If the only argument needed is "item", the following short-hand notation can be applied: + + \code + stackView.push(yourItem) + \endcode + + You can push several items in one go by using an array of property lists. This is + optimizing compared to pushing items one by one, since StackView then can load only the + last item in the list. The rest will be loaded as they are about to become + the current item (which happens when the stack is popped). The following example shows how + to push an array of items: + + \code + stackView.push([{item: yourItem1}, {item: yourItem2}]) + \endcode + + If an inline item is pushed, the item is temporarily re-parented into the StackView. When the item + is later popped off, it gets re-parented back to its original owner again. + If, however, an item is pushed as a component or a URL, the actual item will be created as an + item from that component. This happens automatically when the item is about to become the current + item in the stack. Ownership of the item will then normally be taken by the StackView. It will as + such automatically destroy the item when it is later popped off. The component that declared the item, by + contrast, remains in the ownership of the application and is not destroyed by the stack. + This can be overridden by explicitly setting \c{destroyOnPop} in the list of arguments given to push. + + If the \c properties to be pushed are specified, they will be copied into the item at loading time + (in case of a component or URL), or when the item will become the current item (in case of an inline + item). The following example shows how this can be done: + + \code + stackView.push({item: someItem, properties: {fgcolor: "red", bgcolor: "blue"}}) + \endcode + + + \note Note that if an item is declared inside another item, and if that parent gets destroyed, + (even if a component was used), that child item will also be destroyed. + This follows normal Qt parent-child destruction rules, but sometimes comes as a surprise + for developers. + + \section1 Lifecycle + An item's lifecycle in the StackView can have the following transitions: + \list 1 + \li instantiation + \li inactive + \li activating + \li active + \li deactivating + \li inactive + \li destruction + \endlist + + It can move any number of times between inactive and active. When an item is activated, + it's visible on the screen and is considered to be the current item. An item + in a StackView that is not visible is not activated, even if the item is currently the + top-most item in the stack. When the stack becomes visible, the item that is top-most gets + activated. Likewise if the stack is then hidden, the topmost item would be deactivated. + Popping the item off the top of the stack at this point would not result in further + deactivation since the item is not active. + + There is an attached \l{Stack::status}{Stack.status} property that tracks the lifecycle. The + status values list is an enumeration with values \c Stack.Inactive, \c Stack.Activating, + \c Stack.Active and \c Stack.Deactivating. Combined with the normal \c Component.onComplete and + \c Component.onDestruction signals the entire lifecycle is thus: + + \list + \li Created: Component.onCompleted() + \li Activating: Stack.onStatusChanged (Stack.status is Stack.Activating) + \li Acivated: Stack.onStatusChanged (Stack.status is Stack.Active) + \li Deactivating: Stack.onStatusChanged (Stack.status is Stack.Deactivating) + \li Deactivated: Stack.onStatusChanged (Stack.status is Stack.Inactive) + \li Destruction: Component.onDestruction() + \endlist + + \section1 Finding items + Sometimes it is necessary to search for an item, for example, in order to unwind the stack to + an item to which the application does not have a reference. This is facilitated using a + function find() in StackView. The find() function takes a callback function as its + only argument. The callback gets invoked for each item in the stack (starting at the top). + If the callback returns true, then it signals that a match has been found and the find() + function returns that item. If the callback fails to return true (no match is found), + then find() returns \c null. + + The code below searches for an item in the stack that has a name "order_id" and then unwinds to + that item. Note that since find() returns \c {null} if no item is found, and since pop unwinds to + the bottom of the stack if null is given as the target item, the code works well even in + case no matching item is found. + + \code + stackView.pop(stackView.find(function(item) { + return item.name == "order_id"; + })); + \endcode + + You can also get to an item in the stack using \l {get()}{get(index)}. You should use + this function if your item depends on another item in the stack, as the function will + ensure that the item at the given index gets loaded before it is returned. + + \code + previousItem = stackView.get(myItem.Stack.index - 1)); + \endcode + + \section1 Transitions + + A transition is performed whenever a item is pushed or popped, and consists of + two items: enterItem and exitItem. The StackView itself will never move items + around, but instead delegate the job to an external animation set provided + by the style or the application developer. How items should visually enter and leave the stack + (and the geometry they should end up with) is therefore completely controlled from the outside. + + When the transition starts, the StackView will search for a transition that + matches the operation executed. There are three transitions to choose + from: pushTransition, popTransition, and replaceTransition. Each implements how + enterItem should animate in, and exitItem out. The transitions are + collected inside a StackViewDelegate object assigned to + \l {StackView::delegate}{delegate}. By default, popTransition and + replaceTransition will be the same as pushTransition, unless you set them + to something else. + + A simple fade transition could be implemented as: + + \qml + StackView { + delegate: StackViewDelegate { + function transitionFinished(properties) + { + properties.exitItem.opacity = 1 + } + + pushTransition: StackViewTransition { + PropertyAnimation { + target: enterItem + property: "opacity" + from: 0 + to: 1 + } + PropertyAnimation { + target: exitItem + property: "opacity" + from: 1 + to: 0 + } + } + } + } + \endqml + + PushTransition needs to inherit from StackViewTransition, which is a ParallelAnimation that + contains the properties \c enterItem and \c exitItem. You set the target of your + inner animations to those items. Since the same items instance can be pushed several + times to a StackView, you should always override + \l {StackViewDelegate::transitionFinished()}{StackViewDelegate.transitionFinished()}. + Implement this function to reset any properties animated on the exitItem so that later + transitions can expect the items to be in a default state. + + A more complex example could look like the following. Here, the items are lying on the side before + being rotated to an upright position: + + \qml + StackView { + delegate: StackViewDelegate { + function transitionFinished(properties) + { + properties.exitItem.x = 0 + properties.exitItem.rotation = 0 + } + + pushTransition: StackViewTransition { + SequentialAnimation { + ScriptAction { + script: enterItem.rotation = 90 + } + PropertyAnimation { + target: enterItem + property: "x" + from: enterItem.width + to: 0 + } + PropertyAnimation { + target: enterItem + property: "rotation" + from: 90 + to: 0 + } + } + PropertyAnimation { + target: exitItem + property: "x" + from: 0 + to: -exitItem.width + } + } + } + } + \endqml + + \section2 Advanced usage + + When the StackView needs a new transition, it first calls + \l {StackViewDelegate::getTransition()}{StackViewDelegate.getTransition()}. + The base implementation of this function just looks for a property named \c properties.name inside + itself (root), which is how it finds \c {property Component pushTransition} in the examples above. + + \code + function getTransition(properties) + { + return root[properties.name] + } + \endcode + + You can override this function for your delegate if you need extra logic to decide which + transition to return. You could for example introspect the items, and return different animations + depending on the their internal state. StackView will expect you to return a Component that + contains a StackViewTransition, or a StackViewTransition directly. The former is easier, as StackView will + then create the transition and later destroy it when it's done, while avoiding any sideeffects + caused by the transition being alive long after it has run. Returning a StackViewTransition directly + can be useful if you need to write some sort of transition caching for performance reasons. + As an optimization, you can also return \c null to signal that you just want to show/hide the items + immediately without creating or running any transitions. You can also override this function if + you need to alter the items in any way before the transition starts. + + \c properties contains the properties that will be assigned to the StackViewTransition before + it runs. In fact, you can add more properties to this object during the call + if you need to initialize additional properties of your custom StackViewTransition when the returned + component is instantiated. + + The following example shows how you can decide which animation to use during runtime : + + \qml + StackViewDelegate { + function getTransition(properties) + { + return (properties.enterItem.Stack.index % 2) ? horizontalTransition : verticalTransition + } + + function transitionFinished(properties) + { + properties.exitItem.x = 0 + properties.exitItem.y = 0 + } + + property Component horizontalTransition: StackViewTransition { + PropertyAnimation { + target: enterItem + property: "x" + from: target.width + to: 0 + duration: 300 + } + PropertyAnimation { + target: exitItem + property: "x" + from: 0 + to: target.width + duration: 300 + } + } + + property Component verticalTransition: StackViewTransition { + PropertyAnimation { + target: enterItem + property: "y" + from: target.height + to: 0 + duration: 300 + } + PropertyAnimation { + target: exitItem + property: "y" + from: 0 + to: target.height + duration: 300 + } + } + } + \endqml + + \section1 Supported Attached Properties + + Items in a StackView support these attached properties: + \list + \li \l{Stack::index}{Stack.index} - Contains the index of the item inside the StackView + \li \l{Stack::view}{Stack.view} - Contains the StackView the item is in + \li \l{Stack::status}{Stack.status} - Contains the status of the item + \endlist +*/ + +AbstractStackView { + id: root + + depth: root.__depth + currentItem: root.__currentItem + initialItem: null + busy: __currentTransition !== null + + /*! The transitions to use when pushing or popping items. + For better understanding on how to apply custom transitions, read \l{Transitions}. + \sa {Stack::transitions}{Stack.transitions} */ + property StackViewDelegate delegate: StackViewDelegate {} + + /*! Pushes an item onto the stack. The function takes a property list as argument, which + should contain one or more of the following properties: + \list + \li \c item: this property is required, and holds the item you want to push. + \li \c properties: a list of QML properties that should be assigned + to the item upon push. These properties will be copied into the item when it is + loaded (in case of a component or URL), or when it becomes the current item for the + first time (normally upon push). + \li \c immediate: set this property to \c true to skip transition effects. When pushing + an array, you only need to set this property on the first element to make the + whole operation immediate. + \li \c replace: set this property to replace the current item on the stack. When pushing + an array, you only need to set this property on the first element to replace + as many elements on the stack as inside the array. + \li \c destroyOnPop: set this property to specify if the item needs to be destroyed + when its popped off the stack. By default (if \a destroyOnPop is not specified), + StackView will destroy items pushed as components or URLs. Items + not destroyed will be re-parented to the original parents they had before being + pushed onto the stack, and hidden. If you need to set this property, do it with + care, so that items are not leaked. + \endlist + + You can also push an array of items (property lists) if you need to push several items + in one go. A transition will then only occur between the current item and the last + item in the list. Loading the other items will be deferred until needed. + + Examples: + \list + \li stackView.push({item:anItem}) + \li stackView.push({item:aURL, immediate: true, replace: true}) + \li stackView.push({item:aRectangle, properties:{color:"red"}}) + \li stackView.push({item:aComponent, properties:{color:"red"}}) + \li stackView.push({item:aComponent.createObject(), destroyOnPop:true}) + \li stackView.push([{item:anitem, immediate:true}, {item:aURL}]) + \endlist + + \note Note: if the only argument needed is "item", you can apply the following short- + hand notation: \c{stackView.push(anItem)}. + + Returns the item that became current. + + \sa initialItem + \sa {Pushing items} + */ + function push(item) { + // Note: we support two different APIs in this function; The old meego API, and + // the new "property list" API. Hence the reason for hiding the fact that you + // can pass more arguments than shown in the signature: + if (__recursionGuard(true)) + return + var properties = arguments[1] + var immediate = arguments[2] + var replace = arguments[3] + var arrayPushed = (item instanceof Array) + var firstItem = arrayPushed ? item[0] : item + immediate = (immediate || JSArray.stackView.length === 0) + + if (firstItem && firstItem.item && firstItem.hasOwnProperty("x") === false) { + // Property list API used: + immediate = immediate || firstItem.immediate + replace = replace || firstItem.replace + } + + // Create, and push, a new javascript object, called "element", onto the stack. + // This element contains all the information necessary to construct the item, and + // will, after loaded, also contain the loaded item: + if (arrayPushed) { + if (item.length === 0) + return + var outElement = replace ? JSArray.pop() : JSArray.current() + for (var i=0; i 1 && item !== undefined && item !== inElement.item) { + // Pop from the top until we find 'item', and return the corresponding + // element. Skip all non-loaded items (except the first), since no one + // has any references to such items anyway: + while (__depth > 1 && !JSArray.current().loaded) + JSArray.pop() + inElement = JSArray.current() + while (__depth > 1 && item !== inElement.item) { + JSArray.pop() + __cleanup(inElement) + while (__depth > 1 && !JSArray.current().loaded) + JSArray.pop() + inElement = JSArray.current() + } + } + + var transition = { + inElement: inElement, + outElement: outElement, + immediate: immediate, + replace: false, + push: false + } + __performTransition(transition) + __recursionGuard(false) + return outElement.item; + } + + /*! Remove all items from the stack. No animations will be applied. */ + function clear() { + if (__recursionGuard(true)) + return + if (__currentTransition) + __currentTransition.animation.complete() + __currentItem = null + var count = __depth + for (var i=0; i=0; --i) { + var element = JSArray.stackView[i]; + if (onlySearchLoadedItems !== true) + __loadElement(element) + else if (!element.item) + continue + if (func(element.item, i)) + return element.item + } + return null; + } + + /*! Returns the item at position \a index in + the stack. If \a dontLoad is true, the + item will not be forced to load (and \c null + will be returned if not yet loaded) */ + function get(index, dontLoad) + { + if (index < 0 || index >= JSArray.stackView.length) + return null + var element = JSArray.stackView[index] + if (dontLoad !== true) { + __loadElement(element) + return element.item + } else if (element.item) { + return element.item + } else { + return null + } + } + + /*! Immediately completes any ongoing transition. + /sa Animation.complete + */ + function completeTransition() + { + if (__recursionGuard(true)) + return + if (__currentTransition) + __currentTransition.animation.complete() + __recursionGuard(false) + } + + /********* DEPRECATED API *********/ + + /*! \internal + \deprecated Use Push() instead */ + function replace(item, properties, immediate) { + push(item, properties, immediate, true) + } + + /********* PRIVATE API *********/ + + /*! \internal The currently top-most item on the stack. */ + property Item __currentItem: null + /*! \internal The number of items currently pushed onto the stack. */ + property int __depth: 0 + /*! \internal Stores the transition info while a transition is ongoing */ + property var __currentTransition: null + /*! \internal Stops the user from pushing items while preparing a transition */ + property bool __guard: false + + Component.onCompleted: { + if (initialItem) + push(initialItem) + } + + Component.onDestruction: { + if (__currentTransition) + __currentTransition.animation.complete() + __currentItem = null + } + + /*! \internal */ + function __recursionGuard(use) + { + if (use && __guard) { + console.warn("Warning: StackView: You cannot push/pop recursively!") + console.trace() + return true + } + __guard = use + } + + /*! \internal */ + function __loadElement(element) + { + if (element.loaded) { + if (!element.item) { + element.item = invalidItemReplacement.createObject(root) + element.item.text = "\nError: The item has been deleted outside StackView!" + } + return + } + if (!element.itemComponent) { + element.item = invalidItemReplacement.createObject(root) + element.item.text = "\nError: Invalid item (item was 'null'). " + + "This might indicate that the item was deleted outside StackView!" + return + } + + var comp = __resolveComponent(element.itemComponent, element) + + // Assign properties to item: + if (!element.properties) + element.properties = {} + + if (comp.hasOwnProperty("createObject")) { + if (comp.status === Component.Error) { + element.item = invalidItemReplacement.createObject(root) + element.item.text = "\nError: Could not load: " + comp.errorString() + } else { + element.item = comp.createObject(root, element.properties) + // Destroy items we create unless the user specified something else: + if (!element.hasOwnProperty("destroyOnPop")) + element.destroyOnPop = true + } + } else { + // comp is already an Item, so just re-parent it into the StackView: + element.item = comp + element.originalParent = parent + element.item.parent = root + for (var prop in element.properties) { + if (element.item.hasOwnProperty(prop)) + element.item[prop] = element.properties[prop]; + } + // Do not destroy items we didn't create, unless the user specified something else: + if (!element.hasOwnProperty("destroyOnPop")) + element.destroyOnPop = false + } + +//TODO element.item.Stack.__index = element.index +//TODO element.item.Stack.__view = root + // Let item fill all available space by default: + element.item.width = Qt.binding(function() { return root.width }) + element.item.height = Qt.binding(function() { return root.height }) + element.loaded = true + } + + /*! \internal */ + function __resolveComponent(unknownObjectType, element) + { + // We need this extra resolve function since we don't really + // know what kind of object the user pushed. So we try to + // figure it out by inspecting the object: + if (unknownObjectType.hasOwnProperty("createObject")) { + return unknownObjectType + } else if (typeof unknownObjectType == "string") { + return Qt.createComponent(unknownObjectType) + } else if (unknownObjectType.hasOwnProperty("x")) { + return unknownObjectType + } else if (unknownObjectType.hasOwnProperty("item")) { + // INVARIANT: user pushed a JS-object + element.properties = unknownObjectType.properties + if (!unknownObjectType.item) + unknownObjectType.item = invalidItemReplacement + if (unknownObjectType.hasOwnProperty("destroyOnPop")) + element.destroyOnPop = unknownObjectType.destroyOnPop + return __resolveComponent(unknownObjectType.item, element) + } else { + // We cannot determine the type, so assume its a URL: + return Qt.createComponent(unknownObjectType) + } + } + + /*! \internal */ + function __cleanup(element) { + // INVARIANT: element has been removed from JSArray. Destroy its + // item, or re-parent it back to the parent it had before it was pushed: + var item = element.item + if (element.destroyOnPop) { + item.destroy() + } else { + // Mark the item as no longer part of the StackView. It + // might reenter on pop if pushed several times: + item.visible = false + __setStatus(item, Stack.Inactive) +//TODO item.Stack.__view = null +//TODO item.Stack.__index = -1 + if (element.originalParent) + item.parent = element.originalParent + } + } + + /*! \internal */ + function __setStatus(item, status) { + item.Stack.status = status + } + + /*! \internal */ + function __performTransition(transition) + { + // Animate item in "outElement" out, and item in "inElement" in. Set a guard to protect + // the user from pushing new items on signals that will fire while preparing for the transition + // (e.g Stack.onCompleted, Stack.onStatusChanged, Stack.onIndexChanged etc). Otherwise, we will enter + // this function several times, which causes the items to be updated half-way. + if (__currentTransition) + __currentTransition.animation.complete() + __loadElement(transition.inElement) + + transition.name = transition.replace ? "replaceTransition" : (transition.push ? "pushTransition" : "popTransition") + var enterItem = transition.inElement.item + transition.enterItem = enterItem + + // Since an item can be pushed several times, we need to update its properties: + enterItem.parent = root +//TODO enterItem.Stack.__view = root +//TODO enterItem.Stack.__index = transition.inElement.index + __currentItem = enterItem + + if (!transition.outElement) { + // A transition consists of two items, but we got just one. So just show the item: + enterItem.visible = true + __setStatus(enterItem, Stack.Activating) + __setStatus(enterItem, Stack.Active) + return + } + + var exitItem = transition.outElement.item + transition.exitItem = exitItem + if (enterItem === exitItem) + return + + if (root.delegate) { + transition.properties = { + "name":transition.name, + "enterItem":transition.enterItem, + "exitItem":transition.exitItem, + "immediate":transition.immediate } + var anim = root.delegate.getTransition(transition.properties) + if (anim.createObject) { + anim = anim.createObject(null, transition.properties) + anim.runningChanged.connect(function(){ if (anim.running === false) anim.destroy() }) + } + transition.animation = anim + } + + if (!transition.animation) { + console.warn("Warning: StackView: no", transition.name, "found!") + return + } + if (enterItem.anchors.fill || exitItem.anchors.fill) + console.warn("Warning: StackView: cannot transition an item that is anchored!") + + __currentTransition = transition + __setStatus(exitItem, Stack.Deactivating) + enterItem.visible = true + __setStatus(enterItem, Stack.Activating) + transition.animation.runningChanged.connect(animationFinished) + transition.animation.start() + // NB! For empty animations, "animationFinished" is already + // executed at this point, leaving __animation === null: + if (transition.immediate === true && transition.animation) + transition.animation.complete() + } + + /*! \internal */ + function animationFinished() + { + if (!__currentTransition || __currentTransition.animation.running) + return + + __currentTransition.animation.runningChanged.disconnect(animationFinished) + __currentTransition.exitItem.visible = false + __setStatus(__currentTransition.exitItem, Stack.Inactive); + __setStatus(__currentTransition.enterItem, Stack.Active); + __currentTransition.properties.animation = __currentTransition.animation + root.delegate.transitionFinished(__currentTransition.properties) + + if (!__currentTransition.push || __currentTransition.replace) + __cleanup(__currentTransition.outElement) + + __currentTransition = null + } + + /*! \internal */ + property Component invalidItemReplacement: Component { + Text { + width: parent.width + height: parent.height + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + } + } +} diff --git a/src/imports/controls/StackViewDelegate.qml b/src/imports/controls/StackViewDelegate.qml new file mode 100644 index 00000000..2d4355bd --- /dev/null +++ b/src/imports/controls/StackViewDelegate.qml @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.2 + +/*! + \qmltype StackViewDelegate + \inqmlmodule QtQuick.Controls + \since 5.1 + + \brief A delegate used by StackView for loading transitions. + + See the documentation for the \l {StackView} component. + +*/ +QtObject { + id: root + + property bool horizontal: true + + function getTransition(properties) + { + return root[horizontal ? "horizontalSlide" : "verticalSlide"][properties.name] + } + + function transitionFinished(properties) + { + properties.exitItem.x = 0 + properties.exitItem.y = 0 + } + + property QtObject horizontalSlide: QtObject { + property Component pushTransition: StackViewTransition { + PropertyAnimation { + target: enterItem + property: "x" + from: target.width + to: 0 + duration: 400 + easing.type: Easing.OutCubic + } + PropertyAnimation { + target: exitItem + property: "x" + from: 0 + to: -target.width + duration: 400 + easing.type: Easing.OutCubic + } + } + + property Component popTransition: StackViewTransition { + PropertyAnimation { + target: enterItem + property: "x" + from: -target.width + to: 0 + duration: 400 + easing.type: Easing.OutCubic + } + PropertyAnimation { + target: exitItem + property: "x" + from: 0 + to: target.width + duration: 400 + easing.type: Easing.OutCubic + } + } + property Component replaceTransition: pushTransition + } + + property QtObject verticalSlide: QtObject { + property Component pushTransition: StackViewTransition { + PropertyAnimation { + target: enterItem + property: "y" + from: target.height + to: 0 + duration: 300 + } + PropertyAnimation { + target: exitItem + property: "y" + from: 0 + to: -target.height + duration: 300 + } + } + + property Component popTransition: StackViewTransition { + PropertyAnimation { + target: enterItem + property: "y" + from: -target.height + to: 0 + duration: 300 + } + PropertyAnimation { + target: exitItem + property: "y" + from: 0 + to: target.height + duration: 300 + } + property Component replaceTransition: pushTransition + } + } +} diff --git a/src/imports/controls/StackViewTransition.qml b/src/imports/controls/StackViewTransition.qml new file mode 100644 index 00000000..f057791c --- /dev/null +++ b/src/imports/controls/StackViewTransition.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.2 + +ParallelAnimation { + id: root + /*! The name of the animation that is running. Can be one of the following: + \list + \li 'PushTransition' + \li 'PopTransition' + \li 'ReplaceTransition' + \endlist + */ + property string name + /*! The page that is transitioning in. */ + property Item enterItem + /*! The page that is transitioning out */ + property Item exitItem + /*! Set to \c true if the transition is told to + fast-forward directly to its end-state */ + property bool immediate +} diff --git a/src/imports/controls/Switch.qml b/src/imports/controls/Switch.qml new file mode 100644 index 00000000..51768cc6 --- /dev/null +++ b/src/imports/controls/Switch.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractSwitch { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + (label ? label.implicitWidth : 0) + + (indicator ? indicator.implicitWidth : 0) + + (label && indicator ? style.spacing : 0) + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + Math.max(label ? label.implicitHeight : 0, + indicator ? indicator.implicitHeight : 0) + padding.top + padding.bottom) + + Accessible.name: text + Accessible.checkable: true + Accessible.checked: checked + Accessible.pressed: pressed + Accessible.role: Accessible.Button // TODO: Switch? + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + indicator: Rectangle { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + implicitWidth: 36 + implicitHeight: 20 + x: text ? (mirror ? parent.width - width - padding.right : padding.left) : (parent.width - width) / 2 + y: (parent.height - height) / 2 + + radius: 10 + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? style.focusColor : style.frameColor + opacity: enabled ? 1.0 : style.disabledOpacity + color: style.backgroundColor + + Rectangle { + width: 12 + height: 12 + radius: 6 + + color: Qt.tint(Qt.tint(control.checked ? style.accentColor : style.baseColor, + control.checked && control.activeFocus ? style.focusColor : "transparent"), + control.pressed ? style.pressColor : "transparent") + border.width: control.checked || control.pressed ? 0 : 1 + border.color: style.frameColor + + x: Math.max(4, Math.min(parent.width - width - 4, + control.visualPosition * parent.width - (width / 2))) + y: (parent.height - height) / 2 + + Behavior on x { + enabled: !control.pressed + SmoothedAnimation { velocity: 200 } + } + } + } + + label: Text { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + x: mirror ? padding.left : (indicator.x + indicator.width + control.style.spacing) + y: padding.top + width: parent.width - indicator.width - control.style.spacing - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + text: control.text + color: control.style.textColor + elide: Text.ElideRight + visible: control.text + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + } +} diff --git a/src/imports/controls/TabBar.qml b/src/imports/controls/TabBar.qml new file mode 100644 index 00000000..fa6faea9 --- /dev/null +++ b/src/imports/controls/TabBar.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractTabBar { + id: control + + property list items + readonly property int count: items.length + property alias highlight: listView.highlight + property alias spacing: listView.spacing + + property Component delegate: TabButton { + width: (listView.width - Math.max(0, count - 1) * spacing) / count + } + + contentWidth: listView.contentWidth + contentHeight: listView.contentHeight + + implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + padding.top + padding.bottom) + + Accessible.role: Accessible.PageTabList + + ExclusiveGroup { + id: group + } + + contentItem: ListView { + id: listView + + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + spacing: 1 + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + snapMode: ListView.SnapToItem + + model: control.items + currentIndex: control.currentIndex + + delegate: Loader { + sourceComponent: control.delegate + visible: modelData.Tab.visible + Binding { target: item; property: "Exclusive.group"; value: group } + Binding { target: item; property: "text"; value: modelData.Tab.title } + Binding { target: item; property: "checked"; value: control.currentIndex === index } + Connections { target: item; onClicked: control.currentIndex = index } + } + + property bool completed: false + Component.onCompleted: completed = true + + highlightMoveDuration: completed ? 250 : 0 + highlightResizeDuration: 0 + highlightFollowsCurrentItem: true + highlight: Item { + z: 2 + Rectangle { + height: 4 + width: parent.width + y: parent.height - height + color: style.accentColor + } + } + } + + background: Rectangle { + implicitWidth: 26 + implicitHeight: 26 + width: listView.width + border.color: style.backgroundColor + border.width: 8 + color: listView.count > 1 ? style.frameColor : style.backgroundColor + Rectangle { + y: parent.height - height + width: parent.width + height: 1 + color: style.frameColor + } + } +} diff --git a/src/imports/controls/TabButton.qml b/src/imports/controls/TabButton.qml new file mode 100644 index 00000000..3676a4bc --- /dev/null +++ b/src/imports/controls/TabButton.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractTabButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + label ? label.implicitWidth + padding.left + padding.right : 0) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + label ? label.implicitHeight + padding.top + padding.bottom : 0) + + Accessible.name: text + Accessible.pressed: pressed + Accessible.selected: checked + Accessible.role: Accessible.PageTab + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + label: Text { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + text: control.text + font.pointSize: 10 + elide: Text.ElideRight + color: control.pressed ? control.style.accentColor : control.style.textColor + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + height: parent.height - 1 + implicitHeight: 26 + color: style.backgroundColor + } +} diff --git a/src/imports/controls/TabView.qml b/src/imports/controls/TabView.qml new file mode 100644 index 00000000..db61675b --- /dev/null +++ b/src/imports/controls/TabView.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 +import QtQml.Models 2.1 + +AbstractTabView { + id: control + + default property alias items: listView.items + readonly property alias currentItem: listView.currentItem + property alias spacing: listView.spacing + property alias count: listView.count + + contentWidth: listView.implicitWidth + contentHeight: listView.contentHeight + + implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + padding.top + padding.bottom) + + padding.top: tabBar && tabBar.parent === control ? tabBar.height : 0 + + tabBar: TabBar { } + + Accessible.role: Accessible.PageTabList + + Binding { target: tabBar; property: "items"; value: control.items } + + contentItem: ListView { + id: listView + + property list items + + Binding { target: control; property: "currentIndex"; value: listView.currentIndex } + Binding { target: listView; property: "currentIndex"; value: control.currentIndex } + + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + orientation: Qt.Horizontal + snapMode: ListView.SnapOneItem + boundsBehavior: Flickable.StopAtBounds + highlightRangeMode: ListView.StrictlyEnforceRange + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightMoveDuration: 250 + + model: items + + delegate: Item { + id: delegate + width: listView.width + height: listView.height + visible: modelData.Tab.visible + Binding { target: modelData; property: "parent"; value: delegate } + Binding { target: modelData; property: "Tab.index"; value: index } + Binding { target: modelData; property: "Tab.view"; value: control } + } + } +} diff --git a/src/imports/controls/TextArea.qml b/src/imports/controls/TextArea.qml new file mode 100644 index 00000000..e88fafc8 --- /dev/null +++ b/src/imports/controls/TextArea.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractTextArea { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + Math.max(edit ? edit.implicitWidth : 0, + placeholder ? placeholder.implicitWidth : 0) + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + Math.max(edit ? edit.implicitHeight : 0, + placeholder ? placeholder.implicitHeight : 0) + padding.top + padding.bottom) + + Accessible.name: text + Accessible.multiLine: true + Accessible.role: Accessible.EditableText + Accessible.readOnly: !edit || edit.readOnly + Accessible.description: placeholder ? placeholder.text : "" + + edit: TextEdit { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + color: style.textColor + selectionColor: style.selectionColor + selectedTextColor: style.selectedTextColor + Keys.forwardTo: control + } + + placeholder: Text { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + color: control.style.textColor + opacity: control.style.disabledOpacity + visible: edit ? !edit.length : !control.text + } +} diff --git a/src/imports/controls/TextField.qml b/src/imports/controls/TextField.qml new file mode 100644 index 00000000..b303b05d --- /dev/null +++ b/src/imports/controls/TextField.qml @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractTextField { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + Math.max(input ? input.implicitWidth : 0, + placeholder ? placeholder.implicitWidth : 0) + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + Math.max(input ? input.implicitHeight : 0, + placeholder ? placeholder.implicitHeight : 0) + padding.top + padding.bottom) + + Accessible.name: text + Accessible.role: Accessible.EditableText + Accessible.readOnly: !input || input.readOnly + Accessible.description: placeholder ? placeholder.text : "" + Accessible.passwordEdit: !!input && (input.echoMode == TextInput.Password || + input.echoMode === TextInput.PasswordEchoOnEdit) + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + input: TextInput { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + color: style.textColor + selectionColor: style.selectionColor + selectedTextColor: style.selectedTextColor + verticalAlignment: TextInput.AlignVCenter + Keys.forwardTo: control + } + + placeholder: Text { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + color: control.style.textColor + opacity: control.style.disabledOpacity + visible: input ? !input.displayText : !control.text + } + + background: Rectangle { + implicitWidth: 120 // TODO + radius: style.roundness + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? style.focusColor : style.frameColor + opacity: enabled ? 1.0 : style.disabledOpacity + } +} diff --git a/src/imports/controls/ToggleButton.qml b/src/imports/controls/ToggleButton.qml new file mode 100644 index 00000000..102c752f --- /dev/null +++ b/src/imports/controls/ToggleButton.qml @@ -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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractToggleButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + (label ? label.implicitWidth : 0) + + (indicator ? indicator.implicitWidth : 0) + + (label && indicator ? style.spacing : 0) + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + Math.max(label ? label.implicitHeight : 0, + indicator ? indicator.implicitHeight : 0) + padding.top + padding.bottom) + + Accessible.name: text + Accessible.checkable: true + Accessible.checked: checked + Accessible.pressed: pressed + Accessible.role: Accessible.Button + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + indicator: Rectangle { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + implicitWidth: 36 + implicitHeight: 20 + x: text ? (mirror ? parent.width - width - padding.right : padding.left) : (parent.width - width) / 2 + y: (parent.height - height) / 2 + + radius: style.roundness + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? style.focusColor : style.frameColor + opacity: enabled ? 1.0 : style.disabledOpacity + color: style.backgroundColor + + Rectangle { + width: 12 + height: 12 + + color: Qt.tint(Qt.tint(control.checked ? style.accentColor : style.baseColor, + control.checked && control.activeFocus ? style.focusColor : "transparent"), + control.pressed ? style.pressColor : "transparent") + border.width: control.checked || control.pressed ? 0 : 1 + border.color: style.frameColor + + x: Math.max(4, Math.min(parent.width - width - 4, + control.visualPosition * parent.width - (width / 2))) + y: (parent.height - height) / 2 + + Behavior on x { + enabled: !control.pressed + SmoothedAnimation { velocity: 200 } + } + } + } + + label: Text { + readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft + + x: mirror ? padding.left : (indicator.x + indicator.width + control.style.spacing) + y: padding.top + width: parent.width - indicator.width - control.style.spacing - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + text: control.text + color: control.style.textColor + elide: Text.ElideRight + visible: control.text + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + } +} diff --git a/src/imports/controls/ToolBar.qml b/src/imports/controls/ToolBar.qml new file mode 100644 index 00000000..87ada6c9 --- /dev/null +++ b/src/imports/controls/ToolBar.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractToolBar { + id: control + + default property alias data: content.data + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentWidth + padding.left + padding.right) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentHeight + padding.top + padding.bottom) + + contentWidth: content.children.length === 1 ? content.children[0].implicitWidth : 0 + contentHeight: content.children.length === 1 ? content.children[0].implicitHeight : 0 + + Accessible.role: Accessible.ToolBar + + contentItem: Item { + id: content + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + } + + background: Rectangle { + implicitHeight: 26 + color: style.baseColor + } +} diff --git a/src/imports/controls/ToolButton.qml b/src/imports/controls/ToolButton.qml new file mode 100644 index 00000000..c5171c45 --- /dev/null +++ b/src/imports/controls/ToolButton.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +AbstractButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + label ? label.implicitWidth + padding.left + padding.right : 0) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + label ? label.implicitHeight + padding.top + padding.bottom : 0) + + Accessible.name: text + Accessible.pressed: pressed + Accessible.role: Accessible.Button + + padding { top: style.padding; left: style.padding; right: style.padding; bottom: style.padding } + + label: Text { + x: padding.left + y: padding.top + width: parent.width - padding.left - padding.right + height: parent.height - padding.top - padding.bottom + + text: control.text + color: control.style.textColor + elide: Text.ElideRight + opacity: enabled ? 1.0 : control.style.disabledOpacity + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + implicitWidth: 26 + implicitHeight: 26 + + opacity: style.disabledOpacity + color: style.frameColor + visible: control.pressed + } +} diff --git a/src/imports/controls/controls.pro b/src/imports/controls/controls.pro new file mode 100644 index 00000000..d9de2bf9 --- /dev/null +++ b/src/imports/controls/controls.pro @@ -0,0 +1,47 @@ +TARGET = qtquickcontrols2plugin +TARGETPATH = QtQuick/Controls.2 +IMPORT_VERSION = 2.0 + +QT += qml quick +QT += core-private gui-private qml-private quick-private quickcontrols-private + +OTHER_FILES += \ + qmldir + +QML_FILES = \ + ApplicationWindow.qml \ + BusyIndicator.qml \ + Button.qml \ + CheckBox.qml \ + Frame.qml \ + GroupBox.qml \ + Label.qml \ + PageIndicator.qml \ + ProgressBar.qml \ + RadioButton.qml \ + ScrollBar.qml \ + ScrollIndicator.qml \ + Slider.qml \ + SpinBox.qml \ + StackView.js \ + StackView.qml \ + StackViewDelegate.qml \ + StackViewTransition.qml \ + Switch.qml \ + TabBar.qml \ + TabButton.qml \ + TabView.qml \ + TextArea.qml \ + TextField.qml \ + ToggleButton.qml \ + ToolBar.qml \ + ToolButton.qml + +SOURCES += \ + $$PWD/qtquickcontrols2plugin.cpp + +RESOURCES += \ + $$PWD/qtquickcontrols2plugin.qrc + +CONFIG += no_cxx_module +load(qml_plugin) diff --git a/src/imports/controls/images/spinner_large.png b/src/imports/controls/images/spinner_large.png new file mode 100644 index 00000000..bfd1b637 Binary files /dev/null and b/src/imports/controls/images/spinner_large.png differ diff --git a/src/imports/controls/images/spinner_medium.png b/src/imports/controls/images/spinner_medium.png new file mode 100644 index 00000000..41409d45 Binary files /dev/null and b/src/imports/controls/images/spinner_medium.png differ diff --git a/src/imports/controls/images/spinner_small.png b/src/imports/controls/images/spinner_small.png new file mode 100644 index 00000000..2f6048e4 Binary files /dev/null and b/src/imports/controls/images/spinner_small.png differ diff --git a/src/imports/controls/qmldir b/src/imports/controls/qmldir new file mode 100644 index 00000000..fcd8700d --- /dev/null +++ b/src/imports/controls/qmldir @@ -0,0 +1,29 @@ +module QtQuick.Controls +plugin qtquickcontrols2plugin +classname QtQuickControls2Plugin +ApplicationWindow 2.0 ApplicationWindow.qml +BusyIndicator 2.0 BusyIndicator.qml +Button 2.0 Button.qml +CheckBox 2.0 CheckBox.qml +Frame 2.0 Frame.qml +GroupBox 2.0 GroupBox.qml +Label 2.0 Label.qml +PageIndicator 2.0 PageIndicator.qml +ProgressBar 2.0 ProgressBar.qml +RadioButton 2.0 RadioButton.qml +ScrollBar 2.0 ScrollBar.qml +ScrollIndicator 2.0 ScrollIndicator.qml +Slider 2.0 Slider.qml +SpinBox 2.0 SpinBox.qml +StackView 2.0 StackView.qml +StackViewDelegate 2.0 StackViewDelegate.qml +StackViewTransition 2.0 StackViewTransition.qml +Switch 2.0 Switch.qml +TabBar 2.0 TabBar.qml +TabButton 2.0 TabButton.qml +TabView 2.0 TabView.qml +TextArea 2.0 TextArea.qml +TextField 2.0 TextField.qml +ToggleButton 2.0 ToggleButton.qml +ToolBar 2.0 ToolBar.qml +ToolButton 2.0 ToolButton.qml diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp new file mode 100644 index 00000000..84a02f54 --- /dev/null +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +void initResources() +{ + Q_INIT_RESOURCE(qtquickcontrols2plugin); +} + +QT_BEGIN_NAMESPACE + +class QtQuickControls2Plugin: public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") + +public: + void registerTypes(const char *uri); + void initializeEngine(QQmlEngine *engine, const char *uri); +}; + +void QtQuickControls2Plugin::registerTypes(const char *uri) +{ + qmlRegisterType(uri, 2, 0, "AbstractApplicationWindow"); + qmlRegisterType(uri, 2, 0, "AbstractBusyIndicator"); + qmlRegisterType(uri, 2, 0, "AbstractButton"); + qmlRegisterType(uri, 2, 0, "AbstractCheckBox"); + qmlRegisterType(uri, 2, 0, "AbstractFrame"); + qmlRegisterType(uri, 2, 0, "AbstractGroupBox"); + qmlRegisterType(uri, 2, 0, "AbstractPageIndicator"); + qmlRegisterType(uri, 2, 0, "AbstractProgressBar"); + qmlRegisterType(uri, 2, 0, "AbstractRadioButton"); + qmlRegisterType(uri, 2, 0, "AbstractScrollBar"); + qmlRegisterType(uri, 2, 0, "AbstractScrollIndicator"); + qmlRegisterType(uri, 2, 0, "AbstractSlider"); + qmlRegisterType(uri, 2, 0, "AbstractSpinBox"); + qmlRegisterType(uri, 2, 0, "AbstractStackView"); + qmlRegisterType(uri, 2, 0, "AbstractSwitch"); + qmlRegisterType(uri, 2, 0, "AbstractTabBar"); + qmlRegisterType(uri, 2, 0, "AbstractTabButton"); + qmlRegisterType(uri, 2, 0, "AbstractTabView"); + qmlRegisterType(uri, 2, 0, "AbstractTextArea"); + qmlRegisterType(uri, 2, 0, "AbstractTextField"); + qmlRegisterType(uri, 2, 0, "AbstractToggleButton"); + qmlRegisterType(uri, 2, 0, "AbstractToolBar"); + + qmlRegisterUncreatableType(uri, 2, 0, "Exclusive", "Exclusive is an attached property"); + qmlRegisterUncreatableType(uri, 2, 0, "Stack", "Stack is an attached property"); + qmlRegisterUncreatableType(uri, 2, 0, "Tab", "Tab is an attached property"); + + qmlRegisterType(uri, 2, 0, "Control"); + qmlRegisterType(uri, 2, 0, "ExclusiveGroup"); + qmlRegisterType(uri, 2, 0, "Padding"); + qmlRegisterType(uri, 2, 0, "Style"); +} + +void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *uri) +{ + Q_UNUSED(engine); + Q_UNUSED(uri); + initResources(); +} + +QT_END_NAMESPACE + +#include "qtquickcontrols2plugin.moc" diff --git a/src/imports/controls/qtquickcontrols2plugin.qrc b/src/imports/controls/qtquickcontrols2plugin.qrc new file mode 100644 index 00000000..544c42f5 --- /dev/null +++ b/src/imports/controls/qtquickcontrols2plugin.qrc @@ -0,0 +1,7 @@ + + + images/spinner_small.png + images/spinner_medium.png + images/spinner_large.png + + diff --git a/src/imports/extras/Drawer.qml b/src/imports/extras/Drawer.qml new file mode 100644 index 00000000..6a5a9950 --- /dev/null +++ b/src/imports/extras/Drawer.qml @@ -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 Extras 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$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 +import QtQuick.Extras 2.0 + +AbstractDrawer { + id: control + + width: parent.width // TODO: Window.width + height: parent.height // TODO: Window.height + + background: Rectangle { + color: style.shadowColor + opacity: position * style.disabledOpacity + } + + // TODO: make this a proper transition + animation: SmoothedAnimation { + velocity: 5 + } +} diff --git a/src/imports/extras/SplitView.qml b/src/imports/extras/SplitView.qml new file mode 100644 index 00000000..56eb56f4 --- /dev/null +++ b/src/imports/extras/SplitView.qml @@ -0,0 +1,556 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Layouts 1.0 +import QtQuick.Controls.Private 1.0 as Private +import QtQuick.Window 2.1 + +/*! + \qmltype SplitView + \inqmlmodule QtQuick.Controls + \since 5.1 + \ingroup views + \brief Lays out items with a draggable splitter between each item. + + \image splitview.png + + SplitView is a control that lays out items horizontally or + vertically with a draggable splitter between each item. + + There will always be one (and only one) item in the SplitView that has \l{Layout::fillWidth}{Layout.fillWidth} + set to \c true (or \l{Layout::fillHeight}{Layout.fillHeight}, if orientation is Qt.Vertical). This means that the + item will get all leftover space when other items have been laid out. + By default, the last visible child of the SplitView will have this set, but + it can be changed by explicitly setting fillWidth to \c true on another item. + As the fillWidth item will automatically be resized to fit the extra space, explicit assignments + to width and height will be ignored (but \l{Layout::minimumWidth}{Layout.minimumWidth} and + \l{Layout::maximumWidth}{Layout.maximumWidth} will still be respected). + + A handle can belong to the item either on the left or top side, or on the right or bottom side: + \list + \li If the fillWidth item is to the right: the handle belongs to the left item. + \li if the fillWidth item is on the left: the handle belongs to the right item. + \endlist + + This will again control which item gets resized when the user drags a handle, + and which handle gets hidden when an item is told to hide. + + SplitView supports setting attached Layout properties on child items, which + means that you can set the following attached properties for each child: + \list + \li \l{Layout::minimumWidth}{Layout.minimumWidth} + \li \l{Layout::minimumHeight}{Layout.minimumHeight} + \li \l{Layout::maximumWidth}{Layout.maximumWidth} + \li \l{Layout::maximumHeight}{Layout.maximumHeight} + \li \l{Layout::fillWidth}{Layout.fillWidth} (\c true for only one child) + \li \l{Layout::fillHeight}{Layout.fillHeight} (\c true for only one child) + \endlist + + \note Please import QtQuick.Layout 1.0 in your QML file in order to use the Layout + attached properties inside SplitView. + + Example: + + To create a SplitView with three items, and let the center item get superfluous space, one + could do the following: + + \qml + SplitView { + anchors.fill: parent + orientation: Qt.Horizontal + + Rectangle { + width: 200 + Layout.maximumWidth: 400 + color: "lightblue" + Text { + text: "View 1" + anchors.centerIn: parent + } + } + Rectangle { + id: centerItem + Layout.minimumWidth: 50 + Layout.fillWidth: true + color: "lightgray" + Text { + text: "View 2" + anchors.centerIn: parent + } + } + Rectangle { + width: 200 + color: "lightgreen" + Text { + text: "View 3" + anchors.centerIn: parent + } + } + } + + \endqml +*/ + +Item { + id: root + + /*! + \qmlproperty enumeration SplitView::orientation + + This property holds the orientation of the SplitView. + The value can be either \c Qt.Horizontal or \c Qt.Vertical. + The default value is \c Qt.Horizontal. + */ + property int orientation: Qt.Horizontal + + /*! + This property holds the delegate that will be instantiated between each + child item. Inside the delegate the following properties are available: + + \table + \row \li readonly property bool styleData.index \li Specifies the index of the splitter handle. The handle + between the first and the second item will get index 0, + the next handle index 1 etc. + \row \li readonly property bool styleData.hovered \li The handle is being hovered. + \row \li readonly property bool styleData.pressed \li The handle is being pressed. + \row \li readonly property bool styleData.resizing \li The handle is being dragged. + \endtable + +*/ + property Component handleDelegate: Rectangle { + width: 1 + height: 1 + color: Qt.darker(pal.window, 1.5) + } + + /*! + This property is \c true when the user is resizing any of the items by + dragging on the splitter handles. + */ + property bool resizing: false + + /*! \internal */ + default property alias __contents: contents.data + /*! \internal */ + property alias __items: splitterItems.children + /*! \internal */ + property alias __handles: splitterHandles.children + + clip: true + Component.onCompleted: d.init() + onWidthChanged: d.updateLayout() + onHeightChanged: d.updateLayout() + onOrientationChanged: d.changeOrientation() + + /*! Add an item to the end of the view. + \since QtQuick.Controls 1.3 */ + function addItem(item) { + d.updateLayoutGuard = true + + d.addItem_impl(item) + + d.calculateImplicitSize() + d.updateLayoutGuard = false + d.updateFillIndex() + } + + SystemPalette { id: pal } + + QtObject { + id: d + + readonly property string leftMargin: horizontal ? "leftMargin" : "topMargin" + readonly property string topMargin: horizontal ? "topMargin" : "leftMargin" + readonly property string rightMargin: horizontal ? "rightMargin" : "bottomMargin" + + property bool horizontal: orientation == Qt.Horizontal + readonly property string minimum: horizontal ? "minimumWidth" : "minimumHeight" + readonly property string maximum: horizontal ? "maximumWidth" : "maximumHeight" + readonly property string otherMinimum: horizontal ? "minimumHeight" : "minimumWidth" + readonly property string otherMaximum: horizontal ? "maximumHeight" : "maximumWidth" + readonly property string offset: horizontal ? "x" : "y" + readonly property string otherOffset: horizontal ? "y" : "x" + readonly property string size: horizontal ? "width" : "height" + readonly property string otherSize: horizontal ? "height" : "width" + readonly property string implicitSize: horizontal ? "implicitWidth" : "implicitHeight" + readonly property string implicitOtherSize: horizontal ? "implicitHeight" : "implicitWidth" + + property int fillIndex: -1 + property bool updateLayoutGuard: true + + function extraMarginSize(item, other) { + if (typeof(other) === 'undefined') + other = false; + if (other === horizontal) + // vertical + return item.Layout.topMargin + item.Layout.bottomMargin + return item.Layout.leftMargin + item.Layout.rightMargin + } + + function addItem_impl(item) + { + // temporarily set fillIndex to new item + fillIndex = __items.length + if (splitterItems.children.length > 0) + handleLoader.createObject(splitterHandles, {"__handleIndex":splitterItems.children.length - 1}) + + item.parent = splitterItems + + // should match disconnections in Component.onDestruction + item.widthChanged.connect(d.updateLayout) + item.heightChanged.connect(d.updateLayout) + item.Layout.maximumWidthChanged.connect(d.updateLayout) + item.Layout.minimumWidthChanged.connect(d.updateLayout) + item.Layout.maximumHeightChanged.connect(d.updateLayout) + item.Layout.minimumHeightChanged.connect(d.updateLayout) + item.Layout.leftMarginChanged.connect(d.updateLayout) + item.Layout.topMarginChanged.connect(d.updateLayout) + item.Layout.rightMarginChanged.connect(d.updateLayout) + item.Layout.bottomMarginChanged.connect(d.updateLayout) + item.visibleChanged.connect(d.updateFillIndex) + item.Layout.fillWidthChanged.connect(d.updateFillIndex) + item.Layout.fillHeightChanged.connect(d.updateFillIndex) + } + + function init() + { + for (var i=0; i<__contents.length; ++i) { + var item = __contents[i]; + if (!item.hasOwnProperty("x")) + continue + addItem_impl(item) + i-- // item was removed from list + } + + d.calculateImplicitSize() + d.updateLayoutGuard = false + d.updateFillIndex() + } + + function updateFillIndex() + { + if (lastItem.visible !== root.visible) + return + var policy = (root.orientation === Qt.Horizontal) ? "fillWidth" : "fillHeight" + for (var i=0; i<__items.length-1; ++i) { + if (__items[i].Layout[policy] === true) + break; + } + + d.fillIndex = i + d.updateLayout() + } + + function changeOrientation() + { + if (__items.length == 0) + return; + d.updateLayoutGuard = true + + // Swap width/height for items and handles: + for (var i=0; i<__items.length; ++i) { + var item = __items[i] + var tmp = item.x + item.x = item.y + item.y = tmp + tmp = item.width + item.width = item.height + item.height = tmp + + var handle = __handles[i] + if (handle) { + tmp = handle.x + handle.x = handle.y + handle.y = handle.x + tmp = handle.width + handle.width = handle.height + handle.height = tmp + } + } + + // Change d.horizontal explicit, since the binding will change too late: + d.horizontal = orientation == Qt.Horizontal + d.updateLayoutGuard = false + d.updateFillIndex() + } + + function calculateImplicitSize() + { + var implicitSize = 0 + var implicitOtherSize = 0 + + for (var i=0; i<__items.length; ++i) { + var item = __items[i]; + implicitSize += clampedMinMax(item[d.size], item.Layout[minimum], item.Layout[maximum]) + extraMarginSize(item) + var os = clampedMinMax(item[otherSize], item.Layout[otherMinimum], item.Layout[otherMaximum]) + implicitOtherSize = Math.max(implicitOtherSize, os) + + var handle = __handles[i] + if (handle) + implicitSize += handle[d.size] //### Can handles have margins?? + } + + root[d.implicitSize] = implicitSize + root[d.implicitOtherSize] = implicitOtherSize + extraMarginSize(item, true) + } + + function clampedMinMax(value, minimum, maximum) + { + if (value < minimum) + value = minimum + if (value > maximum) + value = maximum + return value + } + + function accumulatedSize(firstIndex, lastIndex, includeFillItemMinimum) + { + // Go through items and handles, and + // calculate their accummulated width. + var w = 0 + for (var i=firstIndex; i __handleIndex) + visible: __items[__handleIndex + (resizeLeftItem ? 0 : 1)].visible + sourceComponent: handleDelegate + onWidthChanged: d.updateLayout() + onHeightChanged: d.updateLayout() + onXChanged: moveHandle() + onYChanged: moveHandle() + + MouseArea { + id: mouseArea + anchors.fill: parent + property real defaultMargin: Private.Settings.hasTouchScreen ? Screen.pixelDensity * 3.5 : 2 + anchors.leftMargin: (parent.width <= 1) ? -defaultMargin : 0 + anchors.rightMargin: (parent.width <= 1) ? -defaultMargin : 0 + anchors.topMargin: (parent.height <= 1) ? -defaultMargin : 0 + anchors.bottomMargin: (parent.height <= 1) ? -defaultMargin : 0 + hoverEnabled: true + drag.threshold: 0 + drag.target: parent + drag.axis: root.orientation === Qt.Horizontal ? Drag.XAxis : Drag.YAxis + cursorShape: root.orientation === Qt.Horizontal ? Qt.SplitHCursor : Qt.SplitVCursor + } + + function moveHandle() { + // Moving the handle means resizing an item. Which one, + // left or right, depends on where the fillItem is. + // 'updateLayout' will be overridden in case new width violates max/min. + // 'updateLayout' will be triggered when an item changes width. + if (d.updateLayoutGuard) + return + + var leftHandle, leftItem, rightItem, rightHandle + var leftEdge, rightEdge, newWidth, leftStopX, rightStopX + var i + + if (resizeLeftItem) { + // Ensure that the handle is not crossing other handles. So + // find the first visible handle to the left to determine the left edge: + leftEdge = 0 + for (i=__handleIndex-1; i>=0; --i) { + leftHandle = __handles[i] + if (leftHandle.visible) { + leftEdge = leftHandle[d.offset] + leftHandle[d.size] + break; + } + } + + // Ensure: leftStopX >= itemHandle[d.offset] >= rightStopX + var min = d.accumulatedSize(__handleIndex+1, __items.length, true) + rightStopX = root[d.size] - min - itemHandle[d.size] + leftStopX = Math.max(leftEdge, itemHandle[d.offset]) + itemHandle[d.offset] = Math.min(rightStopX, Math.max(leftStopX, itemHandle[d.offset])) + + newWidth = itemHandle[d.offset] - leftEdge + leftItem = __items[__handleIndex] + // The next line will trigger 'updateLayout': + leftItem[d.size] = newWidth + } else { + // Resize item to the right. + // Ensure that the handle is not crossing other handles. So + // find the first visible handle to the right to determine the right edge: + rightEdge = root[d.size] + for (i=__handleIndex+1; i<__handles.length; ++i) { + rightHandle = __handles[i] + if (rightHandle.visible) { + rightEdge = rightHandle[d.offset] + break; + } + } + + // Ensure: leftStopX <= itemHandle[d.offset] <= rightStopX + min = d.accumulatedSize(0, __handleIndex+1, true) + leftStopX = min - itemHandle[d.size] + rightStopX = Math.min((rightEdge - itemHandle[d.size]), itemHandle[d.offset]) + itemHandle[d.offset] = Math.max(leftStopX, Math.min(itemHandle[d.offset], rightStopX)) + + newWidth = rightEdge - (itemHandle[d.offset] + itemHandle[d.size]) + rightItem = __items[__handleIndex+1] + // The next line will trigger 'updateLayout': + rightItem[d.size] = newWidth + } + } + } + } + + Item { + id: contents + visible: false + anchors.fill: parent + } + Item { + id: splitterItems + anchors.fill: parent + } + Item { + id: splitterHandles + anchors.fill: parent + } + + Item { + id: lastItem + onVisibleChanged: d.updateFillIndex() + } + + Component.onDestruction: { + for (var i=0; i + +#include +#include + +QT_BEGIN_NAMESPACE + +class QtQuickExtras2Plugin: public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") + +public: + void registerTypes(const char *uri); +}; + +void QtQuickExtras2Plugin::registerTypes(const char *uri) +{ + qmlRegisterType(uri, 2, 0, "AbstractDrawer"); + qmlRegisterType(uri, 2, 0, "AbstractSplitView"); +} + +QT_END_NAMESPACE + +#include "qtquickextras2plugin.moc" diff --git a/src/imports/imports.pro b/src/imports/imports.pro new file mode 100644 index 00000000..d141f378 --- /dev/null +++ b/src/imports/imports.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs +SUBDIRS += \ + controls \ + calendar \ + extras diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 00000000..9ad5f141 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs +SUBDIRS += \ + controls \ + calendar \ + extras \ + imports + +calendar.depends = controls +extras.depends = controls +imports.depends = controls calendar extras -- cgit v1.2.3