mirror of https://github.com/cutefishos/settings
Add datetime module
parent
4686831caf
commit
bdfb797c41
@ -0,0 +1,42 @@
|
||||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.freedesktop.timedate1">
|
||||
<property name="Timezone" type="s" access="read">
|
||||
</property>
|
||||
<property name="LocalRTC" type="b" access="read">
|
||||
</property>
|
||||
<property name="CanNTP" type="b" access="read">
|
||||
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
|
||||
</property>
|
||||
<property name="NTP" type="b" access="read">
|
||||
</property>
|
||||
<property name="NTPSynchronized" type="b" access="read">
|
||||
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
|
||||
</property>
|
||||
<property name="TimeUSec" type="t" access="read">
|
||||
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
|
||||
</property>
|
||||
<property name="RTCTimeUSec" type="t" access="read">
|
||||
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
|
||||
</property>
|
||||
<method name="SetTime">
|
||||
<arg type="x" direction="in"/>
|
||||
<arg type="b" direction="in"/>
|
||||
<arg type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="SetTimezone">
|
||||
<arg type="s" direction="in"/>
|
||||
<arg type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="SetLocalRTC">
|
||||
<arg type="b" direction="in"/>
|
||||
<arg type="b" direction="in"/>
|
||||
<arg type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="SetNTP">
|
||||
<arg type="b" direction="in"/>
|
||||
<arg type="b" direction="in"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -m -p timedated_interface /home/cutefish/CutefishOS/settings/src/datetime/org.freedesktop.timedate1.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
|
||||
#include "timedated_interface.h"
|
||||
|
||||
/*
|
||||
* Implementation of interface class OrgFreedesktopTimedate1Interface
|
||||
*/
|
||||
|
||||
OrgFreedesktopTimedate1Interface::OrgFreedesktopTimedate1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
|
||||
: QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
|
||||
{
|
||||
}
|
||||
|
||||
OrgFreedesktopTimedate1Interface::~OrgFreedesktopTimedate1Interface()
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -m -p timedated_interface /home/cutefish/CutefishOS/settings/src/datetime/org.freedesktop.timedate1.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#ifndef TIMEDATED_INTERFACE_H
|
||||
#define TIMEDATED_INTERFACE_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
/*
|
||||
* Proxy class for interface org.freedesktop.timedate1
|
||||
*/
|
||||
class OrgFreedesktopTimedate1Interface: public QDBusAbstractInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static inline const char *staticInterfaceName()
|
||||
{ return "org.freedesktop.timedate1"; }
|
||||
|
||||
public:
|
||||
OrgFreedesktopTimedate1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);
|
||||
|
||||
~OrgFreedesktopTimedate1Interface();
|
||||
|
||||
Q_PROPERTY(bool CanNTP READ canNTP)
|
||||
inline bool canNTP() const
|
||||
{ return qvariant_cast< bool >(property("CanNTP")); }
|
||||
|
||||
Q_PROPERTY(bool LocalRTC READ localRTC)
|
||||
inline bool localRTC() const
|
||||
{ return qvariant_cast< bool >(property("LocalRTC")); }
|
||||
|
||||
Q_PROPERTY(bool NTP READ nTP)
|
||||
inline bool nTP() const
|
||||
{ return qvariant_cast< bool >(property("NTP")); }
|
||||
|
||||
Q_PROPERTY(bool NTPSynchronized READ nTPSynchronized)
|
||||
inline bool nTPSynchronized() const
|
||||
{ return qvariant_cast< bool >(property("NTPSynchronized")); }
|
||||
|
||||
Q_PROPERTY(qulonglong RTCTimeUSec READ rTCTimeUSec)
|
||||
inline qulonglong rTCTimeUSec() const
|
||||
{ return qvariant_cast< qulonglong >(property("RTCTimeUSec")); }
|
||||
|
||||
Q_PROPERTY(qulonglong TimeUSec READ timeUSec)
|
||||
inline qulonglong timeUSec() const
|
||||
{ return qvariant_cast< qulonglong >(property("TimeUSec")); }
|
||||
|
||||
Q_PROPERTY(QString Timezone READ timezone)
|
||||
inline QString timezone() const
|
||||
{ return qvariant_cast< QString >(property("Timezone")); }
|
||||
|
||||
public Q_SLOTS: // METHODS
|
||||
inline QDBusPendingReply<> SetLocalRTC(bool in0, bool in1, bool in2)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1) << QVariant::fromValue(in2);
|
||||
return asyncCallWithArgumentList(QStringLiteral("SetLocalRTC"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> SetNTP(bool in0, bool in1)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1);
|
||||
return asyncCallWithArgumentList(QStringLiteral("SetNTP"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> SetTime(qlonglong in0, bool in1, bool in2)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1) << QVariant::fromValue(in2);
|
||||
return asyncCallWithArgumentList(QStringLiteral("SetTime"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> SetTimezone(const QString &in0, bool in1)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1);
|
||||
return asyncCallWithArgumentList(QStringLiteral("SetTimezone"), argumentList);
|
||||
}
|
||||
|
||||
Q_SIGNALS: // SIGNALS
|
||||
};
|
||||
|
||||
namespace org {
|
||||
namespace freedesktop {
|
||||
typedef ::OrgFreedesktopTimedate1Interface timedate1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,17 @@
|
||||
#ifndef TIMEZONEDATA_H
|
||||
#define TIMEZONEDATA_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class TimeZoneData
|
||||
{
|
||||
public:
|
||||
QString id;
|
||||
QString region;
|
||||
QString city;
|
||||
QString comment;
|
||||
bool checked;
|
||||
int offsetFromUtc;
|
||||
};
|
||||
|
||||
#endif // TIMEZONEDATA_H
|
||||
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: Reion Wong <reionwong@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "timezonemap.h"
|
||||
#include "timedated_interface.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QTimeZone>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
// gnome-control-center: cc-timezone-map.c
|
||||
static double radians(double degrees) {
|
||||
return (degrees / 360.0) * M_PI * 2;
|
||||
}
|
||||
|
||||
static double convert_latitude_to_y(double latitude) {
|
||||
const double bottom_lat = -59;
|
||||
const double top_lat = 81;
|
||||
const double full_range = 4.6068250867599998;
|
||||
double top_per, y, top_offset, map_range;
|
||||
|
||||
top_per = top_lat / 180.0;
|
||||
y = 1.25 * log(tan(M_PI_4 + 0.4 * radians(latitude)));
|
||||
top_offset = full_range * top_per;
|
||||
map_range = fabs(1.25 * log(tan(M_PI_4 + 0.4 * radians(bottom_lat))) - top_offset);
|
||||
y = fabs(y - top_offset);
|
||||
y = y / map_range;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static double convert_longitude_to_x(double longitude) {
|
||||
const double xdeg_offset = -6;
|
||||
return ((180.0 + longitude) / 360.0 + xdeg_offset / 180.0);
|
||||
}
|
||||
|
||||
// Parse latitude and longitude of the zone's principal location.
|
||||
// See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
||||
// |pos| is in ISO 6709 sign-degrees-minutes-seconds format,
|
||||
// either +-DDMM+-DDDMM or +-DDMMSS+-DDDMMSS.
|
||||
// |digits| 2 for latitude, 3 for longitude.
|
||||
double convert_pos(const QString &pos, int digits) {
|
||||
if (pos.length() < 4 || digits > 9) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const QString integer = pos.left(digits + 1);
|
||||
const QString fraction = pos.mid(digits + 1);
|
||||
const double t1 = integer.toDouble();
|
||||
const double t2 = fraction.toDouble();
|
||||
if (t1 > 0.0) {
|
||||
return t1 + t2 / pow(10.0, fraction.length());
|
||||
} else {
|
||||
return t1 - t2 / pow(10.0, fraction.length());
|
||||
}
|
||||
}
|
||||
|
||||
TimeZoneMap::TimeZoneMap(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
initDatas();
|
||||
}
|
||||
|
||||
void TimeZoneMap::clicked(int x, int y, int width, int height)
|
||||
{
|
||||
double minimum_distance = width * width + height * height;
|
||||
int nearest_zone_index = -1;
|
||||
|
||||
QList<TimeZoneItem *> items;
|
||||
|
||||
for (int i = 0; i < m_list.size(); ++i) {
|
||||
TimeZoneItem *item = m_list.at(i);
|
||||
const double point_x = convert_longitude_to_x(item->longitude) * width;
|
||||
const double point_y = convert_latitude_to_y(item->latitude) * height;
|
||||
const double dx = point_x - x;
|
||||
const double dy = point_y - y;
|
||||
const double distance = dx * dx + dy * dy;
|
||||
|
||||
if (distance < minimum_distance) {
|
||||
minimum_distance = distance;
|
||||
nearest_zone_index = i;
|
||||
}
|
||||
|
||||
if (distance <= 20) {
|
||||
items << item;
|
||||
}
|
||||
}
|
||||
|
||||
if (items.isEmpty() && nearest_zone_index != -1) {
|
||||
items.append(m_list.at(nearest_zone_index));
|
||||
}
|
||||
|
||||
m_currentList.clear();
|
||||
for (TimeZoneItem *item : items) {
|
||||
m_currentList.append(item->timeZone);
|
||||
}
|
||||
|
||||
std::sort(m_currentList.begin(), m_currentList.end());
|
||||
|
||||
emit availableListChanged();
|
||||
}
|
||||
|
||||
void TimeZoneMap::setTimeZone(QString value)
|
||||
{
|
||||
OrgFreedesktopTimedate1Interface timedateIface(QStringLiteral("org.freedesktop.timedate1"),
|
||||
QStringLiteral("/org/freedesktop/timedate1"),
|
||||
QDBusConnection::systemBus());
|
||||
|
||||
timedateIface.SetTimezone(value, true);
|
||||
m_currentTimeZone = QTimeZone(value.toLatin1()).id();
|
||||
emit currentTimeZoneChanged();
|
||||
}
|
||||
|
||||
QString TimeZoneMap::currentTimeZone() const
|
||||
{
|
||||
return m_currentTimeZone;
|
||||
}
|
||||
|
||||
QStringList TimeZoneMap::availableList()
|
||||
{
|
||||
return m_currentList;
|
||||
}
|
||||
|
||||
void TimeZoneMap::initDatas()
|
||||
{
|
||||
QFile zoneTab("/usr/share/zoneinfo/zone.tab");
|
||||
if (!zoneTab.open(QIODevice::ReadOnly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto lines = QString::fromUtf8(zoneTab.readAll()).split(QLatin1Char('\n'));
|
||||
for (const QString &line : lines) {
|
||||
if (line.startsWith('#'))
|
||||
continue;
|
||||
|
||||
const QStringList parts = line.split('\t');
|
||||
if (parts.size() < 3)
|
||||
continue;
|
||||
|
||||
const QString coordinates = parts.at(1);
|
||||
int index = coordinates.indexOf('+', 3);
|
||||
if (index == -1) {
|
||||
index = coordinates.indexOf('-', 3);
|
||||
}
|
||||
|
||||
const double latitude = convert_pos(coordinates.left(index), 2);
|
||||
const double longitude = convert_pos(coordinates.mid(index), 3);
|
||||
|
||||
TimeZoneItem *item = new TimeZoneItem;
|
||||
item->country = parts.at(0);
|
||||
item->timeZone = parts.at(2);
|
||||
item->latitude = latitude;
|
||||
item->longitude = longitude;
|
||||
m_list.append(item);
|
||||
}
|
||||
std::sort(m_list.begin(), m_list.end());
|
||||
|
||||
// currentTimeZoneChanged
|
||||
m_currentTimeZone = QTimeZone(QTimeZone::systemTimeZoneId()).id();
|
||||
emit currentTimeZoneChanged();
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: revenmartin <revenmartin@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TIMEZONEMAP_H
|
||||
#define TIMEZONEMAP_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class TimeZoneItem {
|
||||
public:
|
||||
QString country;
|
||||
QString timeZone;
|
||||
double latitude;
|
||||
double longitude;
|
||||
};
|
||||
|
||||
class TimeZoneMap : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QStringList availableList READ availableList NOTIFY availableListChanged)
|
||||
Q_PROPERTY(QString currentTimeZone READ currentTimeZone NOTIFY currentTimeZoneChanged)
|
||||
|
||||
public:
|
||||
explicit TimeZoneMap(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void clicked(int x, int y, int width, int height);
|
||||
Q_INVOKABLE void setTimeZone(QString value);
|
||||
|
||||
QString currentTimeZone() const;
|
||||
QStringList availableList();
|
||||
|
||||
signals:
|
||||
void availableListChanged();
|
||||
void currentTimeZoneChanged();
|
||||
|
||||
private:
|
||||
void initDatas();
|
||||
|
||||
private:
|
||||
QList<TimeZoneItem *> m_list;
|
||||
QString m_currentTimeZone;
|
||||
QStringList m_currentList;
|
||||
};
|
||||
|
||||
#endif // TIMEZONEMAP_H
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 149 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 149 KiB |
@ -0,0 +1,9 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">.ColorScheme-Text { color:#363636; }</style>
|
||||
</defs>
|
||||
<g transform="scale(.036093)" fill="#fff">
|
||||
<path d="m221.65 0c-122.21 0-221.65 99.433-221.65 221.65s99.433 221.65 221.65 221.65 221.65-99.433 221.65-221.65-99.433-221.65-221.65-221.65zm0 415.59c-106.94 0-193.94-87-193.94-193.94s87-193.94 193.94-193.94 193.94 87 193.94 193.94-87 193.94-193.94 193.94z"/>
|
||||
<path d="m235.5 83.118h-27.706v144.26l87.176 87.176 19.589-19.589-79.059-79.059z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 617 B |
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: revenmartin <revenmartin@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import FishUI 1.0 as FishUI
|
||||
import Cutefish.Settings 1.0
|
||||
import "../"
|
||||
|
||||
ItemPage {
|
||||
headerTitle: qsTr("Date & Time")
|
||||
|
||||
TimeZoneDialog {
|
||||
id: timeZoneDialog
|
||||
}
|
||||
|
||||
TimeZoneMap {
|
||||
id: timeZoneMap
|
||||
}
|
||||
|
||||
Scrollable {
|
||||
anchors.fill: parent
|
||||
contentHeight: layout.implicitHeight
|
||||
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
anchors.fill: parent
|
||||
|
||||
StandardButton {
|
||||
Layout.fillWidth: true
|
||||
text: ""
|
||||
onClicked: timeZoneDialog.visibility = "Maximized"
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: FishUI.Units.largeSpacing
|
||||
anchors.rightMargin: FishUI.Units.largeSpacing
|
||||
|
||||
Label {
|
||||
text: qsTr("Time Zone")
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Label {
|
||||
text: timeZoneMap.currentTimeZone
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: Reion Wong <reionwong@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Window 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import FishUI 1.0 as FishUI
|
||||
|
||||
FishUI.Window {
|
||||
id: control
|
||||
title: "Hello World"
|
||||
width: 900
|
||||
height: 600
|
||||
visible: false
|
||||
|
||||
background.opacity: 0.5
|
||||
contentTopMargin: 0
|
||||
|
||||
onWidthChanged: control.reset()
|
||||
onHeightChanged: control.reset()
|
||||
|
||||
function reset() {
|
||||
_popupItem.opacity = 0
|
||||
dot.visible = false
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
if (!visible)
|
||||
control.reset()
|
||||
}
|
||||
|
||||
FishUI.WindowBlur {
|
||||
view: control
|
||||
geometry: Qt.rect(control.x, control.y, control.width, control.height)
|
||||
windowRadius: control.background.radius
|
||||
enabled: true
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
onPressed: {
|
||||
if (_popupItem.opacity === 1) {
|
||||
control.reset()
|
||||
return
|
||||
}
|
||||
|
||||
timeZoneMap.clicked(mouse.x, mouse.y, control.width, control.height)
|
||||
_popupItem.x = mouse.x
|
||||
_popupItem.y = mouse.y
|
||||
_popupItem.opacity = 1
|
||||
dot.show(mouse.x, mouse.y)
|
||||
}
|
||||
}
|
||||
|
||||
Image {
|
||||
anchors.fill: parent
|
||||
source: FishUI.Theme.darkMode ? "qrc:/images/dark/world.svg" : "qrc:/images/light/world.svg"
|
||||
sourceSize: Qt.size(width, height)
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: dot
|
||||
width: 20
|
||||
height: 20
|
||||
radius: height / 2
|
||||
color: FishUI.Theme.highlightColor
|
||||
z: 99
|
||||
visible: false
|
||||
border.width: 5
|
||||
border.color: Qt.rgba(FishUI.Theme.highlightColor.r,
|
||||
FishUI.Theme.highlightColor.g,
|
||||
FishUI.Theme.highlightColor.b, 0.5)
|
||||
|
||||
function show(x, y) {
|
||||
dot.x = x - dot.width / 2
|
||||
dot.y = y - dot.height / 2
|
||||
dot.visible = true
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: _popupItem
|
||||
width: 200
|
||||
height: _popupLayout.implicitHeight + FishUI.Units.largeSpacing
|
||||
z: 100
|
||||
|
||||
opacity: _view.count > 0 ? 1.0 : 0.0
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation { duration: 200 }
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: FishUI.Theme.secondBackgroundColor
|
||||
radius: FishUI.Theme.mediumRadius
|
||||
border.width: 1
|
||||
border.color: Qt.rgba(FishUI.Theme.textColor.r,
|
||||
FishUI.Theme.textColor.g,
|
||||
FishUI.Theme.textColor.b, 0.2)
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: _popupLayout
|
||||
anchors.fill: parent
|
||||
anchors.margins: FishUI.Units.smallSpacing
|
||||
|
||||
ListView {
|
||||
id: _view
|
||||
clip: true
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: itemSize * _view.count
|
||||
model: timeZoneMap.availableList
|
||||
|
||||
property int itemSize: 30
|
||||
|
||||
delegate: Item {
|
||||
id: _item
|
||||
width: ListView.view.width
|
||||
height: _view.itemSize
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: FishUI.Theme.mediumRadius
|
||||
color: FishUI.Theme.highlightColor
|
||||
visible: index === _view.currentIndex
|
||||
opacity: 0.8
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 2
|
||||
onClicked: _view.currentIndex = index
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
|
||||
Label {
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
elide: Label.ElideRight
|
||||
text: modelData
|
||||
color: index === _view.currentIndex ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
Layout.preferredHeight: _view.itemSize
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Set")
|
||||
onClicked: {
|
||||
_popupItem.opacity = 0
|
||||
timeZoneMap.setTimeZone(timeZoneMap.availableList[_view.currentIndex])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
#ifndef TIMEZONEDATA_H
|
||||
#define TIMEZONEDATA_H
|
||||
|
||||
#endif // TIMEZONEDATA_H
|
||||
Loading…
Reference in New Issue