Commit 7e5e9f34 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

[weather applet] Add option to display temp/wind/pressure/hum in tooltip

parent 63bdc63f
......@@ -25,7 +25,8 @@ import org.kde.plasma.core 2.0 as PlasmaCore
ColumnLayout {
id: compactRoot
property var model: []
property var generalModel
property var observationModel
readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical)
readonly property bool showTemperature: plasmoid.nativeInterface.temperatureShownInCompactMode &&
......@@ -55,7 +56,7 @@ ColumnLayout {
PlasmaCore.IconItem {
readonly property int minIconSize: Math.max((compactRoot.vertical ? compactRoot.width : compactRoot.height), units.iconSizes.small)
source: currentWeatherIconName
source: generalModel.currentConditionIconName
// reset implicit size, so layout in free dimension does not stop at the default one
implicitWidth: units.iconSizes.small
implicitHeight: units.iconSizes.small
......@@ -69,8 +70,8 @@ ColumnLayout {
IconAndTextItem {
vertical: compactRoot.vertical
iconSource: currentWeatherIconName
text: model.currentTemperature
iconSource: generalModel.currentConditionIconName
text: observationModel.temperature
}
}
}
......@@ -27,7 +27,8 @@ ColumnLayout {
Layout.margins: units.smallSpacing
property alias model: topPanel.model
property alias generalModel: topPanel.generalModel
property alias observationModel: topPanel.observationModel
TopPanel {
id: topPanel
......@@ -38,14 +39,14 @@ ColumnLayout {
SwitchPanel {
Layout.fillWidth: true
forecastViewTitle: model.forecastTitle
forecastViewTitle: generalModel.forecastTitle
forecastModel: root.forecastModel
detailsModel: root.detailsModel
noticesModel: root.noticesModel
}
PlasmaComponents.Label {
readonly property string creditUrl: model.creditUrl
readonly property string creditUrl: generalModel.creditUrl
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
......@@ -60,7 +61,7 @@ ColumnLayout {
textFormat: Text.StyledText
text: {
var result = model.courtesy;
var result = generalModel.courtesy;
if (creditUrl) {
result = "<a href=\"" + creditUrl + "\">" + result + "</a>";
}
......
......@@ -24,7 +24,8 @@ import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
PlasmaCore.FrameSvgItem {
property var model
property var generalModel
property var observationModel
implicitWidth: contentLayout.implicitWidth
implicitHeight: contentLayout.implicitHeight
......@@ -36,7 +37,7 @@ PlasmaCore.FrameSvgItem {
Layout.maximumHeight: contentLayout.Layout.maximumHeight + margins.top + margins.bottom
Layout.maximumWidth: contentLayout.Layout.maximumWidth + margins.left + margins.right
visible: !!model.location
visible: !!generalModel.location
imagePath: "widgets/frame"
prefix: "plain"
......@@ -67,7 +68,7 @@ PlasmaCore.FrameSvgItem {
Layout.preferredHeight: units.iconSizes.huge
Layout.preferredWidth: units.iconSizes.huge
source: model.currentConditionIcon
source: generalModel.currentConditionIconName
}
PlasmaExtras.Heading {
......@@ -82,7 +83,7 @@ PlasmaCore.FrameSvgItem {
elide: Text.ElideRight
wrapMode: Text.NoWrap
text: model.location
text: generalModel.location
PlasmaCore.ToolTipArea {
id: locationToolTip
......@@ -100,7 +101,7 @@ PlasmaCore.FrameSvgItem {
Layout.column: 1
Layout.preferredWidth: implicitWidth
text: model.currentConditions
text: observationModel.conditions
}
PlasmaExtras.Heading {
......@@ -114,7 +115,7 @@ PlasmaCore.FrameSvgItem {
level: 2
wrapMode: Text.NoWrap
text: model.currentTemperature
text: observationModel.temperature
}
PlasmaComponents.Label {
......@@ -126,7 +127,7 @@ PlasmaCore.FrameSvgItem {
Layout.preferredWidth: implicitWidth
text: {
var low = model.currentDayLowTemperature, high = model.currentDayHighTemperature;
var low = generalModel.currentDayLowTemperature, high = generalModel.currentDayHighTemperature;
if (!!low && !!high) {
return i18nc("High & Low temperature", "H: %1 L: %2", high, low);
}
......
......@@ -16,6 +16,7 @@
*/
import QtQuick 2.0
import QtQuick.Controls 1.4 as QtControls1
import QtQuick.Controls 2.2 as QtControls
import QtQuick.Layouts 1.3
......@@ -25,14 +26,19 @@ import org.kde.plasma.private.weather 1.0
ColumnLayout {
id: displayConfigPage
readonly property bool canShowTemperature: !plasmoid.nativeInterface.needsToBeSquare
readonly property bool canShowMoreInCompactMode: !plasmoid.nativeInterface.needsToBeSquare
signal configurationChanged
function saveConfig() {
var config = {};
config.showTemperatureInCompactMode = showTemperatureCheckBox.checked;
config.showTemperatureInTooltip = showTemperatureInTooltipCheckBox.checked;
config.showWindInTooltip = showWindInTooltipCheckBox.checked;
config.showPressureInTooltip = showPressureInTooltipCheckBox.checked;
config.showHumidityInTooltip = showHumidityInTooltipCheckBox.checked;
config.showTemperatureInCompactMode = showTemperatureInCompactModeCheckBox.checked;
plasmoid.nativeInterface.saveConfig(config);
plasmoid.nativeInterface.configChanged();
......@@ -41,29 +47,116 @@ ColumnLayout {
Component.onCompleted: {
var config = plasmoid.nativeInterface.configValues();
showTemperatureCheckBox.checked = config.showTemperatureInCompactMode;
showTemperatureInTooltipCheckBox.checked = config.showTemperatureInTooltip;
showWindInTooltipCheckBox.checked = config.showWindInTooltip;
showPressureInTooltipCheckBox.checked = config.showPressureInTooltip;
showHumidityInTooltipCheckBox.checked = config.showHumidityInTooltip;
showTemperatureInCompactModeCheckBox.checked = config.showTemperatureInCompactMode;
}
GridLayout {
columns: 2
QtControls1.GroupBox {
Layout.fillWidth: true
flat: true
title: i18nc("@title:group", "Tooltip")
GridLayout {
columns: 2
QtControls.Label {
Layout.row: 0
Layout.column: 0
Layout.alignment: Qt.AlignRight
text: i18nc("@label", "Show temperature:")
}
QtControls.CheckBox {
id: showTemperatureInTooltipCheckBox
Layout.row: 0
Layout.column: 1
onCheckedChanged: displayConfigPage.configurationChanged();
}
QtControls.Label {
Layout.row: 1
Layout.column: 0
Layout.alignment: Qt.AlignRight
text: i18nc("@label", "Show wind:")
}
QtControls.CheckBox {
id: showWindInTooltipCheckBox
Layout.row: 1
Layout.column: 1
onCheckedChanged: displayConfigPage.configurationChanged();
}
QtControls.Label {
Layout.row: 0
Layout.column: 0
Layout.alignment: Qt.AlignRight
enabled: canShowTemperature
text: i18nc("@label", "Show temperature in compact mode:")
QtControls.Label {
Layout.row: 2
Layout.column: 0
Layout.alignment: Qt.AlignRight
text: i18nc("@label", "Show pressure:")
}
QtControls.CheckBox {
id: showPressureInTooltipCheckBox
Layout.row: 2
Layout.column: 1
onCheckedChanged: displayConfigPage.configurationChanged();
}
QtControls.Label {
Layout.row: 3
Layout.column: 0
Layout.alignment: Qt.AlignRight
text: i18nc("@label", "Show humidity:")
}
QtControls.CheckBox {
id: showHumidityInTooltipCheckBox
Layout.row: 3
Layout.column: 1
onCheckedChanged: displayConfigPage.configurationChanged();
}
}
}
QtControls1.GroupBox {
Layout.fillWidth: true
flat: true
title: i18nc("@title:group", "Compact Mode")
GridLayout {
columns: 2
QtControls.Label {
Layout.row: 0
Layout.column: 0
Layout.alignment: Qt.AlignRight
enabled: canShowMoreInCompactMode
text: i18nc("@label", "Show temperature:")
}
QtControls.CheckBox {
id: showTemperatureCheckBox
QtControls.CheckBox {
id: showTemperatureInCompactModeCheckBox
Layout.row: 0
Layout.column: 1
enabled: canShowTemperature
Layout.row: 0
Layout.column: 1
enabled: canShowMoreInCompactMode
onCheckedChanged: displayConfigPage.configurationChanged();
onCheckedChanged: displayConfigPage.configurationChanged();
}
}
}
......
......@@ -33,12 +33,91 @@ Item {
readonly property int displayVisibilityUnit: plasmoid.nativeInterface.displayVisibilityUnit
property bool connectingToSource: false
readonly property string currentWeatherIconName: !panelModel.location ? "weather-none-available" : panelModel.currentConditionIcon
readonly property bool needsConfiguration: !panelModel.location && !connectingToSource
readonly property bool needsConfiguration: !generalModel.location && !connectingToSource
readonly property int invalidUnit: -1 //TODO: make KUnitConversion::InvalidUnit usable here
readonly property var panelModel: {
// model providing final display strings for observation properties
readonly property var observationModel: {
var model = {};
var data = weatherDataSource.currentData;
var reportTemperatureUnit = (data && data["Temperature Unit"]) || invalidUnit;
var reportPressureUnit = (data && data["Pressure Unit"]) || invalidUnit;
var reportVisibilityUnit = (data && data["Visibility Unit"]) || invalidUnit;
var reportWindSpeedUnit = (data && data["Wind Speed Unit"]) || invalidUnit;
model["conditions"] = (data && data["Current Conditions"]) || "";
var conditionIconName = (data && data["Condition Icon"]) || null;
model["conditionIconName"] = conditionIconName ? Util.existingWeatherIconName(conditionIconName) : "weather-none-available";
var temperature = (data && data["Temperature"]) || null;
model["temperature"] = temperature !== null ? Util.temperatureToDisplayString(displayTemperatureUnit, temperature, reportTemperatureUnit) : "";
var windchill = (data && data["Windchill"]) || null;
// Use temperature unit to convert windchill temperature
// we only show degrees symbol not actual temperature unit
model["windchill"] = windchill !== null ?
Util.temperatureToDisplayString(displayTemperatureUnit, windchill, reportTemperatureUnit, false, true) :
"";
var humidex = (data && data["Humidex"]) || null;
// TODO: this seems wrong, does the humidex have temperature as units?
// Use temperature unit to convert humidex temperature
// we only show degrees symbol not actual temperature unit
model["humidex"] = humidex !== null ?
Util.temperatureToDisplayString(displayTemperatureUnit, humidex, reportTemperatureUnit, false, true) :
"";
var dewpoint = (data && data["Dewpoint"]) || null;
model["dewpoint"] = dewpoint !== null ?
Util.temperatureToDisplayString(displayTemperatureUnit, dewpoint, reportTemperatureUnit) : "";
var pressure = (data && data["Pressure"]) || null;
model["pressure"] = pressure ?
Util.valueToDisplayString(displayPressureUnit, pressure, reportPressureUnit, 2) : "";
var pressureTendency = (data && data["Pressure Tendency"]) || null;
model["pressureTendency"] = pressureTendency ? i18nc("pressure tendency", pressureTendency) : "";
var visibility = (data && data["Visibility"]) || null;
model["visibility"] = visibility ?
((reportVisibilityUnit !== invalidUnit) ?
Util.valueToDisplayString(displayVisibilityUnit, visibility, reportVisibilityUnit, 1) : visibility) :
"";
var humidity = (data && data["Humidity"]) || null;
model["humidity"] = humidity ? Util.percentToDisplayString(humidity) : "";
// TODO: missing check for windDirection validness
var windDirection = (data && data["Wind Direction"]) || null;
var windSpeed = (data && data["Wind Speed"]) || null;
var windSpeedText;
if (windSpeed !== null && windSpeed !== "") {
var windSpeedNumeric = (typeof windSpeed !== 'number') ? parseFloat(windSpeed) : windSpeed;
if (!isNaN(windSpeedNumeric)) {
if (windSpeedNumeric !== 0) {
windSpeedText = Util.valueToDisplayString(displaySpeedUnit, windSpeedNumeric, reportWindSpeedUnit, 1);
} else {
windSpeedText = i18nc("Wind condition", "Calm");
}
} else {
// TODO: i18n?
windSpeedText = windSpeed;
}
}
model["windSpeed"] = windSpeedText || "";
model["windDirectionId"] = windDirection || "";
model["windDirection"] = windDirection ? i18nc("wind direction", windDirection) : "";
var windGust = (data && data["Wind Gust"]) || null;
model["windGust"] = windGust ? Util.valueToDisplayString(displaySpeedUnit, windGust, reportWindSpeedUnit, 1) : "";
return model;
}
readonly property var generalModel: {
var model = {};
var data = weatherDataSource.currentData;
......@@ -49,8 +128,6 @@ Item {
model["courtesy"] = (data && data["Credit"]) || "";
model["creditUrl"] = (data && data["Credit Url"]) || "";
model["currentConditions"] = (data && data["Current Conditions"]) || "";
var forecastDayCount = parseInt((data && data["Total Weather Days"]) || "");
var forecastTitle;
if (!isNaN(forecastDayCount) && forecastDayCount > 0) {
......@@ -58,23 +135,18 @@ Item {
}
model["forecastTitle"] = forecastTitle || "";
var conditionIconName = (data && data["Condition Icon"]) || null;
var weatherIconName;
var conditionIconName = observationModel.conditionIconName;
if (!conditionIconName ||
conditionIconName === "weather-none-available") {
// try icon from current weather forecast
if (todayForecastTokens.length === 6 && todayForecastTokens[1] !== "N/U") {
weatherIconName = Util.existingWeatherIconName(todayForecastTokens[1]);
conditionIconName = Util.existingWeatherIconName(todayForecastTokens[1]);
} else {
weatherIconName = "weather-none-available";
conditionIconName = "weather-none-available";
}
} else {
weatherIconName = Util.existingWeatherIconName(conditionIconName);
}
model["currentConditionIcon"] = weatherIconName;
var temperature = (data && data["Temperature"]) || null;
model["currentTemperature"] = temperature !== null ? Util.temperatureToDisplayString(displayTemperatureUnit, temperature, reportTemperatureUnit) : "";
model["currentConditionIconName"] = conditionIconName;
var currentDayLowTemperature;
var currentDayHighTemperature;
......@@ -97,105 +169,52 @@ Item {
readonly property var detailsModel: {
var model = [];
var data = weatherDataSource.currentData;
var reportTemperatureUnit = (data && data["Temperature Unit"]) || invalidUnit;
var windChill = (data && data["Windchill"]) || null;
if (windChill) {
// Use temperature unit to convert windchill temperature
// we only show degrees symbol not actual temperature unit
var windChillString = Util.temperatureToDisplayString(displayTemperatureUnit, windChill, reportTemperatureUnit, false, true);
model.push({ "text": i18n("Windchill: %1", windChillString) });
if (observationModel.windchill) {
model.push({ "text": i18n("Windchill: %1", observationModel.windchill) });
};
var humidex = (data && data["Humidex"]) || null;
if (humidex) {
// TODO: this seems wrong, does the humidex have temperature as units?
// Use temperature unit to convert humidex temperature
// we only show degrees symbol not actual temperature unit
var humidexString = Util.temperatureToDisplayString(displayTemperatureUnit, humidex, reportTemperatureUnit, false, true);
model.push({ "text": i18n("Humidex: %1", humidexString) });
if (observationModel.humidex) {
model.push({ "text": i18n("Humidex: %1", observationModel.humidex) });
}
var dewpoint = (data && data["Dewpoint"]) || null;
if (dewpoint) {
var dewpointString = Util.temperatureToDisplayString(displayTemperatureUnit, dewpoint, reportTemperatureUnit);
model.push({ "text": i18nc("ground temperature", "Dewpoint: %1", dewpointString) });
if (observationModel.dewpoint) {
model.push({ "text": i18nc("ground temperature", "Dewpoint: %1", observationModel.dewpoint) });
}
var pressure = (data && data["Pressure"]) || null;
if (pressure) {
var reportPressureUnit = data["Pressure Unit"] || invalidUnit;
var pressureText = Util.valueToDisplayString(displayPressureUnit, pressure, reportPressureUnit, 2);
pressureText = i18n("Pressure: %1", pressureText);
model.push({ "text": pressureText });
if (observationModel.pressure) {
model.push({ "text": i18n("Pressure: %1", observationModel.pressure) });
}
var pressureTendency = (data && data["Pressure Tendency"]) || null;
if (pressureTendency) {
var i18nPressureTendency = i18nc("pressure tendency", pressureTendency);
i18nPressureTendency = i18nc("pressure tendency, rising/falling/steady",
"Pressure Tendency: %1", i18nPressureTendency);
model.push({ "text": i18nPressureTendency });
if (observationModel.pressureTendency) {
model.push({ "text": i18nc("pressure tendency, rising/falling/steady",
"Pressure Tendency: %1", observationModel.pressureTendency) });
}
var visibility = (data && data["Visibility"]) || null;
if (visibility) {
var visibilityText;
var reportVisibilityUnit = data["Visibility Unit"] || invalidUnit;
if (reportVisibilityUnit !== invalidUnit) {
visibilityText = Util.valueToDisplayString(displayVisibilityUnit, visibility, reportVisibilityUnit, 1);
visibilityText = i18n("Visibility: %1", visibilityText);
} else {
visibilityText = i18n("Visibility: %1", visibility);
}
model.push({ "text": visibilityText });
if (observationModel.visibility) {
model.push({ "text": i18n("Visibility: %1", observationModel.visibility) });
}
var humidity = (data && data["Humidity"]) || null;
if (humidity) {
var humidityString = Util.percentToDisplayString(humidity);
model.push({ "text": i18n("Humidity: %1", humidityString) });
if (observationModel.humidity) {
model.push({ "text": i18n("Humidity: %1", observationModel.humidity) });
}
var reportWindSpeedUnit = (data && data["Wind Speed Unit"]) || invalidUnit;
var windSpeed = (data && data["Wind Speed"]) || null;
if (windSpeed !== null && windSpeed !== "") {
// TODO: missing check for windDirection validness
var windDirection = data["Wind Direction"] || null;
if (observationModel.windSpeed) {
var windSpeedText;
var windSpeedNumeric = (typeof windSpeed !== 'number') ? parseFloat(windSpeed) : windSpeed;
if (!isNaN(windSpeedNumeric)) {
if (windSpeedNumeric !== 0) {
windSpeedText = Util.valueToDisplayString(displaySpeedUnit, windSpeedNumeric, reportWindSpeedUnit, 1);
var i18nWindDirection = i18nc("wind direction", windDirection);
windSpeedText = i18nc("wind direction, speed","%1 %2", i18nWindDirection, windSpeedText);
} else {
windSpeedText = i18nc("Wind condition", "Calm");
}
if (observationModel.windDirection) {
windSpeedText = i18nc("winddirection windspeed","%1 %2", observationModel.windDirection, observationModel.windSpeed);
} else {
windSpeedText = windSpeed;
windSpeedText = observationModel.windSpeed;
}
model.push({
"icon": windDirection,
"icon": observationModel.windDirectionId,
"text": windSpeedText
});
}
var windGust = (data && data["Wind Gust"]) || null;
if (windGust) {
var windGustString = Util.valueToDisplayString(displaySpeedUnit, windGust, reportWindSpeedUnit, 1);
model.push({ "text": i18n("Wind Gust: %1", windGustString) });
if (observationModel.windGust) {
model.push({ "text": i18n("Wind Gust: %1",observationModel. windGust) });
}
return model;
......@@ -358,26 +377,53 @@ Item {
// workaround for now to ensure "Please configure" tooltip
// TODO: remove when configurationRequired works
Plasmoid.icon: needsConfiguration ? "configure" : currentWeatherIconName
Plasmoid.toolTipMainText: needsConfiguration ? i18nc("@info:tooltip", "Please configure") : panelModel.location
Plasmoid.icon: needsConfiguration ? "configure" : generalModel.currentConditionIconName
Plasmoid.toolTipMainText: needsConfiguration ? i18nc("@info:tooltip", "Please configure") : generalModel.location
Plasmoid.toolTipSubText: {
if (!panelModel.location) {
if (!generalModel.location) {
return "";
}
if (panelModel.currentConditions && panelModel.currentTemperature) {
return i18nc("%1 is the weather condition, %2 is the temperature, both come from the weather provider",
"%1 %2", panelModel.currentConditions, panelModel.currentTemperature);
var tooltips = [];
var temperature = plasmoid.nativeInterface.temperatureShownInTooltip ? observationModel.temperature : null;
if (observationModel.conditions && temperature) {
tooltips.push(i18nc("weather condition + temperature",
"%1 %2", observationModel.conditions, temperature));
} else if (observationModel.conditions || temperature) {
tooltips.push(observationModel.conditions || temperature);
}
if (plasmoid.nativeInterface.windShownInTooltip) {
if (observationModel.windGust) {
tooltips.push(i18nc("winddirection windspeed (windgust)", "%1 %2 (%3)",
observationModel.windDirection, observationModel.windSpeed, observationModel.windGust));
} else {