diff --git a/src/app/WeatherForecastDelegate.qml b/src/app/WeatherForecastDelegate.qml index 6e59bc3..db9b74a 100644 --- a/src/app/WeatherForecastDelegate.qml +++ b/src/app/WeatherForecastDelegate.qml @@ -1,74 +1,74 @@ /* Copyright (C) 2018 Volker Krause This program 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 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 Library 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 . */ import QtQuick 2.5 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 as QQC2 import org.kde.kirigami 2.4 as Kirigami import org.kde.itinerary 1.0 import "." as App Kirigami.AbstractCard { id: root property var weatherForecast visible: weatherForecast.valid headerOrientation: Qt.Horizontal - showClickFeedback: true + showClickFeedback: weatherForecast.range > 1 header: Rectangle { id: headerBackground Kirigami.Theme.colorSet: Kirigami.Theme.Complementary Kirigami.Theme.inherit: false color: Kirigami.Theme.backgroundColor implicitWidth: icon.implicitWidth + Kirigami.Units.largeSpacing * 2 Layout.minimumHeight: implicitWidth Layout.fillHeight: true anchors.leftMargin: -root.leftPadding anchors.topMargin: -root.topPadding anchors.bottomMargin: -root.rightPadding Kirigami.Icon { id: icon anchors.fill: parent anchors.margins: Kirigami.Units.largeSpacing source: weatherForecast.symbolIconName } } contentItem: ColumnLayout { Layout.fillWidth: true QQC2.Label { text: i18n("Temperature: %1 °C / %2 °C", weatherForecast.minimumTemperature, weatherForecast.maximumTemperature) color: Kirigami.Theme.textColor Layout.fillWidth: true } QQC2.Label { text: i18n("Precipitation: %1 mm", weatherForecast.precipitation) color: Kirigami.Theme.textColor Layout.fillWidth: true } } Component { id: detailsComponent App.WeatherForecastPage { weatherForecast: root.weatherForecast } } - onClicked: applicationWindow().pageStack.push(detailsComponent); + onClicked: if (weatherForecast.range > 1) { applicationWindow().pageStack.push(detailsComponent); } } diff --git a/src/weather/weatherforecast.h b/src/weather/weatherforecast.h index fed082f..18cd0a2 100644 --- a/src/weather/weatherforecast.h +++ b/src/weather/weatherforecast.h @@ -1,104 +1,105 @@ /* Copyright (C) 2018 Volker Krause This program 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 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 Library 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 . */ #ifndef WEATHERFORECAST_H #define WEATHERFORECAST_H #include #include #include class QDateTime; class WeatherForecastPrivate; class WeatherTile; /** Weather forecast data */ class WeatherForecast { Q_GADGET Q_PROPERTY(bool valid READ isValid CONSTANT) Q_PROPERTY(float minimumTemperature READ minimumTemperature CONSTANT) Q_PROPERTY(float maximumTemperature READ maximumTemperature CONSTANT) Q_PROPERTY(float precipitation READ precipitation CONSTANT) Q_PROPERTY(QString symbolIconName READ symbolIconName CONSTANT) + Q_PROPERTY(int range READ range CONSTANT) public: enum SymbolFlag : uint16_t { None = 0, Clear = 1, LightClouds = 2, Clouds = 4, LightRain = 8, Rain = 16, LightSnow = 32, Snow = 64, Hail = 128, ThunderStorm = 256, Fog = 512, }; /** Weather symbol. * Represented as flags so we can easily merge this for longer time periods. */ Q_DECLARE_FLAGS(SymbolType, SymbolFlag) Q_FLAG(SymbolType) WeatherForecast(); WeatherForecast(const WeatherForecast&); ~WeatherForecast(); WeatherForecast& operator=(const WeatherForecast&); bool isValid() const; /** The time this data is valid for. */ QDateTime dateTime() const; void setDateTime(const QDateTime &dt); /** Temperature range. */ float minimumTemperature() const; void setMinimumTemperature(float t); float maximumTemperature() const; void setMaximumTemperature(float t); /** Precipitation in mm/m². */ float precipitation() const; void setPrecipitation(float precipitation); /** Weather symbol. */ SymbolType symbolType() const; void setSymbolType(SymbolType type); QString symbolIconName() const; /** Merge with @p other. */ void merge(const WeatherForecast &other); // internal for weighting different forecast elements int range() const; void setRange(int hours); // internal for computing the day/night icons WeatherTile tile() const; void setTile(WeatherTile tile); private: QExplicitlySharedDataPointer d; }; Q_DECLARE_METATYPE(WeatherForecast) Q_DECLARE_OPERATORS_FOR_FLAGS(WeatherForecast::SymbolType) #endif // WEATHERFORECAST_H