Commit b1750c15 authored by Aleksi Suomalainen's avatar Aleksi Suomalainen

[glacier] Checkbox implemented with Switch spec

parent 8c716a0a
/****************************************************************************************
**
** Copyright (C) 2013 Aleksi Suomalainen <suomalainen.aleksi@gmail.com>
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
import QtQuick 2.1
import QtQuick.Controls 1.0 //needed for the Stack attached property
import QtQuick.Controls.Nemo 1.0
import QtQuick.Controls.Styles.Nemo 1.0
Page {
id: root
tools: ToolBarLayoutExample { title: "Switch" }
Column {
spacing: 40
anchors.centerIn: parent
CheckBox {
text: "Test 1: "
}
}
}
...@@ -95,6 +95,10 @@ ApplicationWindow { ...@@ -95,6 +95,10 @@ ApplicationWindow {
title: "Labels" title: "Labels"
page: "content/LabelPage.qml" page: "content/LabelPage.qml"
} }
ListElement {
title: "Switches"
page: "content/CheckboxPage.qml"
}
} }
......
...@@ -19,5 +19,6 @@ ...@@ -19,5 +19,6 @@
<file>content/ToolBarLayoutExample.qml</file> <file>content/ToolBarLayoutExample.qml</file>
<file>content/SpinnerPage.qml</file> <file>content/SpinnerPage.qml</file>
<file>content/LabelPage.qml</file> <file>content/LabelPage.qml</file>
<file>content/CheckboxPage.qml</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -20,7 +20,8 @@ OTHER_FILES += \ ...@@ -20,7 +20,8 @@ OTHER_FILES += \
content/LiveCoding.qml \ content/LiveCoding.qml \
content/ToolBarLayoutExample.qml \ content/ToolBarLayoutExample.qml \
content/SpinnerPage.qml \ content/SpinnerPage.qml \
content/LabelPage.qml content/LabelPage.qml \
content/CheckboxPage.qml
RESOURCES += \ RESOURCES += \
resources.qrc resources.qrc
......
import QtQuick 2.1
import QtQuick.Controls 1.0
CheckBox {
}
...@@ -11,7 +11,8 @@ QML_FILES += \ ...@@ -11,7 +11,8 @@ QML_FILES += \
ApplicationWindow.qml \ ApplicationWindow.qml \
Page.qml \ Page.qml \
Spinner.qml \ Spinner.qml \
Label.qml Label.qml \
Checkbox.qml
OTHER_FILES += qmldir \ OTHER_FILES += qmldir \
$$QML_FILES $$QML_FILES
......
...@@ -13,6 +13,7 @@ ApplicationWindow 1.0 ApplicationWindow.qml ...@@ -13,6 +13,7 @@ ApplicationWindow 1.0 ApplicationWindow.qml
Page 1.0 Page.qml Page 1.0 Page.qml
Spinner 1.0 Spinner.qml Spinner 1.0 Spinner.qml
Label 1.0 Label.qml Label 1.0 Label.qml
CheckBox 1.0 Checkbox.qml
# MIRRORED CONTROLS: # MIRRORED CONTROLS:
# These are the controls that we take directly from official QQC. # These are the controls that we take directly from official QQC.
...@@ -23,7 +24,6 @@ Label 1.0 Label.qml ...@@ -23,7 +24,6 @@ Label 1.0 Label.qml
# case Nemo plugin doesn't provide an overridden component) # case Nemo plugin doesn't provide an overridden component)
# NOTE: "../" here is assumed to be the relative path to the official QQC!! # NOTE: "../" here is assumed to be the relative path to the official QQC!!
CheckBox 1.0 ../CheckBox.qml
ComboBox 1.0 ../ComboBox.qml ComboBox 1.0 ../ComboBox.qml
GroupBox 1.0 ../GroupBox.qml GroupBox 1.0 ../GroupBox.qml
......
/* /****************************************************************************************
* Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com> **
* ** Copyright (C) 2013 Aleksi Suomalainen <suomalainen.aleksi@gmail.com>
* This library is free software; you can redistribute it and/or ** All rights reserved.
* modify it under the terms of the GNU Library General Public **
* License as published by the Free Software Foundation; either ** You may use this file under the terms of BSD license as follows:
* version 2 of the License, or (at your option) any later version. **
* ** Redistribution and use in source and binary forms, with or without
* This library is distributed in the hope that it will be useful, ** modification, are permitted provided that the following conditions are met:
* but WITHOUT ANY WARRANTY; without even the implied warranty of ** * Redistributions of source code must retain the above copyright
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** notice, this list of conditions and the following disclaimer.
* Library General Public License for more details. ** * Redistributions in binary form must reproduce the above copyright
* ** notice, this list of conditions and the following disclaimer in the
* You should have received a copy of the GNU Library General Public License ** documentation and/or other materials provided with the distribution.
* along with this library; see the file COPYING.LIB. If not, write to ** * Neither the name of the author nor the
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ** names of its contributors may be used to endorse or promote products
* Boston, MA 02110-1301, USA. ** derived from this software without specific prior written permission.
*/ **
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Controls.Styles 1.0 import QtQuick.Controls.Styles 1.0
import QtQuick.Controls.Nemo 1.0
//Styles.Nemo provides Theme
import QtQuick.Controls.Styles.Nemo 1.0
CheckBoxStyle { CheckBoxStyle {
indicator: Rectangle {
id: background
color: "transparent"
implicitWidth: 72
implicitHeight: 32
Rectangle {
id: back1
implicitWidth: 72
implicitHeight: 28
color: Theme.checkbox.back1
anchors.centerIn: parent
}
Rectangle {
id: back2
implicitWidth: 72
implicitHeight: 28
color: Theme.checkbox.back2
anchors.centerIn: parent
}
Image {
id: ball
source: "images/switch-ball.png"
anchors.verticalCenter: parent.verticalCenter
}
Connections {
target: control
onCheckedChanged: {
if (control.checked) {
anim1.restart()
} else {
anim2.restart()
}
}
}
SequentialAnimation {
id: anim1
running: false
NumberAnimation {
target: ball
property: "x"
to: 32
duration: 120
}
NumberAnimation {
target: back1
property: "opacity"
to: 1
duration: 60
}
NumberAnimation {
target: back2
property: "opacity"
to: 0
duration: 60
}
}
SequentialAnimation {
id: anim2
running: false
NumberAnimation {
target: ball
property: "x"
to: 0
duration: 120
}
NumberAnimation {
target: back2
property: "opacity"
to: 1
duration: 60
}
NumberAnimation {
target: back1
property: "opacity"
to: 0
duration: 60
}
}
}
label: Label {
text: control.text
}
spacing: 10
} }
...@@ -47,6 +47,7 @@ NemoTheme::NemoTheme(QObject *parent) ...@@ -47,6 +47,7 @@ NemoTheme::NemoTheme(QObject *parent)
, m_page(new NemoThemePage(this)) , m_page(new NemoThemePage(this))
, m_spinner(new NemoThemeSpinner(this)) , m_spinner(new NemoThemeSpinner(this))
, m_label(new NemoThemeLabel(this)) , m_label(new NemoThemeLabel(this))
, m_checkbox(new NemoThemeCheckbox(this))
{ {
loadFromFile(GLACIER_THEME); loadFromFile(GLACIER_THEME);
int id = QFontDatabase::addApplicationFont("/usr/share/fonts/google-opensans/OpenSans-Regular.ttf"); int id = QFontDatabase::addApplicationFont("/usr/share/fonts/google-opensans/OpenSans-Regular.ttf");
...@@ -129,6 +130,11 @@ NemoThemeLabel * NemoTheme::label() const ...@@ -129,6 +130,11 @@ NemoThemeLabel * NemoTheme::label() const
return m_label; return m_label;
} }
NemoThemeCheckbox * NemoTheme::checkbox() const
{
return m_checkbox;
}
QString NemoTheme::fontFamily() const QString NemoTheme::fontFamily() const
{ {
return m_fontFamily; return m_fontFamily;
...@@ -377,4 +383,8 @@ void NemoTheme::loadFromFile(const QString &fileName) ...@@ -377,4 +383,8 @@ void NemoTheme::loadFromFile(const QString &fileName)
// Setting properties for label // Setting properties for label
QJsonObject stylesLabel = styles.value("label").toObject(); QJsonObject stylesLabel = styles.value("label").toObject();
m_label->setColor(jsonToColor(jsonValue(stylesLabel, "color", "label"), defines)); m_label->setColor(jsonToColor(jsonValue(stylesLabel, "color", "label"), defines));
// Setting properties for checkbox
QJsonObject stylesCheckbox = styles.value("checkbox").toObject();
m_checkbox->setBack1(jsonToColor(jsonValue(stylesCheckbox, "back1", "checkbox"), defines));
m_checkbox->setBack2(jsonToColor(jsonValue(stylesCheckbox, "back2", "checkbox"), defines));
} }
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "nemothemepage.h" #include "nemothemepage.h"
#include "nemothemespinner.h" #include "nemothemespinner.h"
#include "nemothemelabel.h" #include "nemothemelabel.h"
#include "nemothemecheckbox.h"
class NemoTheme: public QObject class NemoTheme: public QObject
{ {
...@@ -48,6 +49,7 @@ class NemoTheme: public QObject ...@@ -48,6 +49,7 @@ class NemoTheme: public QObject
Q_PROPERTY(NemoThemePage * page READ page CONSTANT) Q_PROPERTY(NemoThemePage * page READ page CONSTANT)
Q_PROPERTY(NemoThemeSpinner * spinner READ spinner CONSTANT) Q_PROPERTY(NemoThemeSpinner * spinner READ spinner CONSTANT)
Q_PROPERTY(NemoThemeLabel * label READ label CONSTANT) Q_PROPERTY(NemoThemeLabel * label READ label CONSTANT)
Q_PROPERTY(NemoThemeCheckbox * checkbox READ checkbox CONSTANT)
Q_PROPERTY(QString fontFamily READ fontFamily CONSTANT) Q_PROPERTY(QString fontFamily READ fontFamily CONSTANT)
public: public:
explicit NemoTheme(QObject *parent = 0); explicit NemoTheme(QObject *parent = 0);
...@@ -64,6 +66,7 @@ public: ...@@ -64,6 +66,7 @@ public:
NemoThemePage * page() const; NemoThemePage * page() const;
NemoThemeSpinner * spinner() const; NemoThemeSpinner * spinner() const;
NemoThemeLabel * label() const; NemoThemeLabel * label() const;
NemoThemeCheckbox * checkbox() const;
QString fontFamily() const; QString fontFamily() const;
public Q_SLOTS: public Q_SLOTS:
void loadFromFile(const QString &fileName); void loadFromFile(const QString &fileName);
...@@ -82,6 +85,7 @@ private: ...@@ -82,6 +85,7 @@ private:
NemoThemePage * m_page; NemoThemePage * m_page;
NemoThemeSpinner * m_spinner; NemoThemeSpinner * m_spinner;
NemoThemeLabel * m_label; NemoThemeLabel * m_label;
NemoThemeCheckbox * m_checkbox;
QString m_fontFamily; QString m_fontFamily;
}; };
......
/*
* Copyright (C) 2013 Lucien Xu <sfietkonstantin@free.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// This class is autogenerated using themehelper.py
// Any modification done in this file will be overridden
#include "nemothemecheckbox.h"
NemoThemeCheckbox::NemoThemeCheckbox(QObject *parent)
: QObject(parent)
{
}
QColor NemoThemeCheckbox::back1() const
{
return m_back1;
}
void NemoThemeCheckbox::setBack1(const QColor &back1)
{
if (m_back1 != back1) {
m_back1 = back1;
emit back1Changed();
}
}
QColor NemoThemeCheckbox::back2() const
{
return m_back2;
}
void NemoThemeCheckbox::setBack2(const QColor &back2)
{
if (m_back2 != back2) {
m_back2 = back2;
emit back2Changed();
}
}
/*
* Copyright (C) 2013 Lucien Xu <sfietkonstantin@free.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// This class is autogenerated using themehelper.py
// Any modification done in this file will be overridden
#ifndef NEMOTHEMECHECKBOX_H
#define NEMOTHEMECHECKBOX_H
#include <QtCore/QObject>
#include <QtGui/QColor>
class NemoThemeCheckbox: public QObject
{
Q_OBJECT
Q_PROPERTY(QColor back1 READ back1 NOTIFY back1Changed)
Q_PROPERTY(QColor back2 READ back2 NOTIFY back2Changed)
public:
explicit NemoThemeCheckbox(QObject *parent = 0);
QColor back1() const;
void setBack1(const QColor &back1);
QColor back2() const;
void setBack2(const QColor &back2);
Q_SIGNALS:
void back1Changed();
void back2Changed();
private:
QColor m_back1;
QColor m_back2;
};
#endif //NEMOTHEMECHECKBOX_H
...@@ -51,6 +51,7 @@ void QQuickNemoStyleExtensionPlugin::registerTypes(const char *uri) ...@@ -51,6 +51,7 @@ void QQuickNemoStyleExtensionPlugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<NemoThemePageDimmer>(uri, 1, 0, "NemoThemePageDimmer", reason); qmlRegisterUncreatableType<NemoThemePageDimmer>(uri, 1, 0, "NemoThemePageDimmer", reason);
qmlRegisterUncreatableType<NemoThemeSpinner>(uri, 1, 0, "NemoThemeSpinner", reason); qmlRegisterUncreatableType<NemoThemeSpinner>(uri, 1, 0, "NemoThemeSpinner", reason);
qmlRegisterUncreatableType<NemoThemeLabel>(uri, 1, 0, "NemoThemeLabel", reason); qmlRegisterUncreatableType<NemoThemeLabel>(uri, 1, 0, "NemoThemeLabel", reason);
qmlRegisterUncreatableType<NemoThemeCheckbox>(uri, 1, 0, "NemoThemeCheckbox", reason);
qmlRegisterSingletonType<QObject>(uri, 1, 0, "Theme", nemo_theme_provider); qmlRegisterSingletonType<QObject>(uri, 1, 0, "Theme", nemo_theme_provider);
......
...@@ -49,7 +49,8 @@ QML_FILES += \ ...@@ -49,7 +49,8 @@ QML_FILES += \
images/arrow-left@2x.png \ images/arrow-left@2x.png \
images/arrow-right.png \ images/arrow-right.png \
images/arrow-right@2x.png \ images/arrow-right@2x.png \
images/disabled-overlay.png images/disabled-overlay.png \
images/switch-ball.png
OTHER_FILES += qmldir \ OTHER_FILES += qmldir \
themes/Theme1.js \ themes/Theme1.js \
...@@ -84,7 +85,8 @@ HEADERS += \ ...@@ -84,7 +85,8 @@ HEADERS += \
autogenerated/nemothemepage.h \ autogenerated/nemothemepage.h \
autogenerated/nemothemepagedimmer.h \ autogenerated/nemothemepagedimmer.h \
autogenerated/nemothemespinner.h \ autogenerated/nemothemespinner.h \
autogenerated/nemothemelabel.h autogenerated/nemothemelabel.h \
autogenerated/nemothemecheckbox.h
SOURCES += \ SOURCES += \
qquicknemostyleextensionplugin.cpp \ qquicknemostyleextensionplugin.cpp \
...@@ -100,7 +102,8 @@ SOURCES += \ ...@@ -100,7 +102,8 @@ SOURCES += \
autogenerated/nemothemepage.cpp \ autogenerated/nemothemepage.cpp \
autogenerated/nemothemepagedimmer.cpp \ autogenerated/nemothemepagedimmer.cpp \
autogenerated/nemothemespinner.cpp \ autogenerated/nemothemespinner.cpp \
autogenerated/nemothemelabel.cpp autogenerated/nemothemelabel.cpp \
autogenerated/nemothemecheckbox.cpp
INSTALLS += target images qmlfiles themes INSTALLS += target images qmlfiles themes
......
...@@ -57,6 +57,10 @@ ...@@ -57,6 +57,10 @@
}, },
"label": { "label": {
"color": "#ffffff" "color": "#ffffff"
},
"checkbox": {
"back1": "#0091e5",
"back2": "#313131"
} }
} }
} }
...@@ -210,6 +210,19 @@ ...@@ -210,6 +210,19 @@
"type":"QColor" "type":"QColor"
} }
] ]
},
{
"name": "Checkbox",
"properties": [
{
"name": "back1",
"type": "QColor"
},
{
"name": "back2",
"type": "QColor"
}
]
} }
], ],
"properties": [ "properties": [
...@@ -248,6 +261,10 @@ ...@@ -248,6 +261,10 @@
{ {
"name": "label", "name": "label",
"object": "Label" "object": "Label"
},
{
"name": "checkbox",
"object": "Checkbox"
} }
], ],
"font": "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf" "font": "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment