Skip to content

Commit

Permalink
Update Plasmoids
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkXero-dev committed Oct 9, 2024
1 parent 7d4c247 commit c288c45
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,58 +63,6 @@ let ELEV_UNITS = {



/** Map from Wunderground provided icon codes to opendesktop icon theme descs */
let iconThemeMap = {
0: "weather-storm-symbolic",
1: "weather-storm-symbolic",
2: "weather-storm-symbolic",
3: "weather-storm-symbolic",
4: "weather-storm-symbolic",
5: "weather-snow-rain-symbolic",
6: "weather-snow-rain-symbolic",
7: "weather-freezing-rain-symbolic",
8: "weather-freezing-rain-symbolic",
9: "weather-showers-scattered-symbolic",
10: "weather-freezing-rain-symbolic",
11: "weather-showers-symbolic",
12: "weather-showers-symbolic",
13: "weather-snow-scattered-symbolic",
14: "weather-snow-symbolic",
15: "weather-snow-symbolic",
16: "weather-snow-symbolic",
17: "weather-hail-symbolic",
18: "weather-snow-scattered-symbolic",
19: "weather-many-clouds-wind-symbolic",
20: "weather-fog-symbolic",
21: "weather-fog-symbolic",
22: "weather-fog-symbolic",
23: "weather-clouds-wind-symbolic",
24: "weather-clouds-wind-symbolic",
25: "weather-snow-symbolic",
26: "weather-many-clouds-symbolic",
27: "weather-many-clouds-symbolic",
28: "weather-clouds-symbolic",
29: "weather-clouds-night-symbolic",
30: "weather-few-clouds-symbolic",
31: "weather-clear-night-symbolic",
32: "weather-clear-symbolic",
33: "weather-few-clouds-night-symbolic",
34: "weather-few-clouds-day-symbolic",
35: "weather-freezing-storm-day-symbolic",
36: "weather-clear-symbolic",
37: "weather-storm-day-symbolic",
38: "weather-storm-day-symbolic",
39: "weather-showers-scattered-day-symbolic",
40: "weather-showers-symbolic",
41: "weather-snow-scattered-day-symbolic",
42: "weather-snow-symbolic",
43: "weather-snow-symbolic",
44: "weather-none-available-symbolic",
45: "weather-showers-scattered-night-symbolic",
46: "weather-snow-storm-night-symbolic",
47: "weather-storm-night-symbolic"
}

let severityColorMap = {
1: "#cc3300",
2: "#ff9966",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,59 @@ let ELEV_UNITS = {
FT: 1
}

/** Map from Wunderground provided icon codes to opendesktop icon theme descs */
let iconThemeMap = {
0: "weather-storm-symbolic",
1: "weather-storm-symbolic",
2: "weather-storm-symbolic",
3: "weather-storm-symbolic",
4: "weather-storm-symbolic",
5: "weather-snow-rain-symbolic",
6: "weather-snow-rain-symbolic",
7: "weather-freezing-rain-symbolic",
8: "weather-freezing-rain-symbolic",
9: "weather-showers-scattered-symbolic",
10: "weather-freezing-rain-symbolic",
11: "weather-showers-symbolic",
12: "weather-showers-symbolic",
13: "weather-snow-scattered-symbolic",
14: "weather-snow-symbolic",
15: "weather-snow-symbolic",
16: "weather-snow-symbolic",
17: "weather-hail-symbolic",
18: "weather-snow-scattered-symbolic",
19: "weather-many-clouds-wind-symbolic",
20: "weather-fog-symbolic",
21: "weather-fog-symbolic",
22: "weather-fog-symbolic",
23: "weather-clouds-wind-symbolic",
24: "weather-clouds-wind-symbolic",
25: "weather-snow-symbolic",
26: "weather-many-clouds-symbolic",
27: "weather-many-clouds-symbolic",
28: "weather-clouds-symbolic",
29: "weather-clouds-night-symbolic",
30: "weather-few-clouds-symbolic",
31: "weather-clear-night-symbolic",
32: "weather-clear-symbolic",
33: "weather-few-clouds-night-symbolic",
34: "weather-few-clouds-day-symbolic",
35: "weather-freezing-storm-day-symbolic",
36: "weather-clear-symbolic",
37: "weather-storm-day-symbolic",
38: "weather-storm-day-symbolic",
39: "weather-showers-scattered-day-symbolic",
40: "weather-showers-symbolic",
41: "weather-snow-scattered-day-symbolic",
42: "weather-snow-symbolic",
43: "weather-snow-symbolic",
44: "weather-none-available-symbolic",
45: "weather-showers-scattered-night-symbolic",
46: "weather-snow-storm-night-symbolic",
47: "weather-storm-night-symbolic"
}


/**
* Turn a 1-360° angle into the corresponding part on the compass.
*
Expand Down Expand Up @@ -89,44 +142,6 @@ function windDirToCard(deg) {
}


/**
* Return the filename of the wind barb that should be shown for
* the given windspeed.
*
* @param {number} Wind speed in API units
*
* @retruns {string} Filename
*/
function getWindBarb(windSpeed) {
var speedKts;
if (unitsChoice === UNITS_SYSTEM.METRIC) {
speedKts = kmhToKts(windSpeed);
} else if (unitsChoice === UNITS_SYSTEM.IMPERIAL) {
speedKts = mphToKts(windSpeed);
} else if (unitsChoice === UNITS_SYSTEM.HYBRID) {
speedKts = mphToKts(windSpeed);
} else {
speedKts = kmhToKts(windSpeed);
}

if (within(speedKts, 0, 2.9999)) {
return "0-2";
} else if (within(speedKts, 3, 7.9999)) {
return "3-7";
} else if (within(speedKts, 8, 12.9999)) {
return "8-12";
} else if (within(speedKts, 13, 17.9999)) {
return "13-17";
} else if (within(speedKts, 18, 22.9999)) {
return "18-22";
} else if (within(speedKts, 23, 27.9999)) {
return "23-27";
} else if (within(speedKts, 28, 32.9999)) {
return "28-32";
} else {
return "28-32";
}
}

function cToF(degC) {
return degC * 1.8 + 32;
Expand Down Expand Up @@ -258,7 +273,7 @@ function feelsLike(temp, relHumid, windSpeed) {
*
* @param {number} degF Temp in Fahrenheit
* @param {number} relHumid Percent humidity
* @param {number} windSpeed Speed in m/h
* @param {number} windSpeedMph Speed in m/h
*
* @returns {number} What the air feels like in Fahrenheit
*/
Expand Down Expand Up @@ -436,6 +451,66 @@ function getPressureTrendIcon(code) {
}
}


/**
* Return the filename of the wind barb that should be shown for
* the given windspeed.
*
* @param {number} Wind speed in API units
*
* @retruns {string} Filename
*/
function getWindBarbIcon(windSpeed) {
if (plasmoid.configuration.useSystemThemeIcons) {
return "gnumeric-object-arrow";
}

var speedKts, fileName;
if (unitsChoice === UNITS_SYSTEM.METRIC) {
speedKts = kmhToKts(windSpeed);
} else if (unitsChoice === UNITS_SYSTEM.IMPERIAL) {
speedKts = mphToKts(windSpeed);
} else if (unitsChoice === UNITS_SYSTEM.HYBRID) {
speedKts = mphToKts(windSpeed);
} else {
speedKts = kmhToKts(windSpeed);
}

if (within(speedKts, 0, 2.9999)) {
fileName = "0-2";
} else if (within(speedKts, 3, 7.9999)) {
fileName = "3-7";
} else if (within(speedKts, 8, 12.9999)) {
fileName = "8-12";
} else if (within(speedKts, 13, 17.9999)) {
fileName = "13-17";
} else if (within(speedKts, 18, 22.9999)) {
fileName = "18-22";
} else if (within(speedKts, 23, 27.9999)) {
fileName = "23-27";
} else if (within(speedKts, 28, 32.9999)) {
fileName = "28-32";
} else {
fileName = "28-32";
}

return Qt.resolvedUrl("../icons/wind-barbs/" + fileName + ".svg");
}

/**
* Return the icon representing a weather condition.
*
* @param {number} code Wunderground provided icon code
* @returns {string} Either an opendesktop icon name or path to custom icon
*/
function getConditionIcon(code) {
if (plasmoid.configuration.useSystemThemeIcons) {
return iconThemeMap[code];
} else {
return Qt.resolvedUrl("../icons/" + code + ".svg");
}
}

/**
* Return whether pressure has increased.
* True = increased
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<entry name="tempPointSize" type="Int">
<default>30</default>
</entry>
<entry name="useSystemThemeIcons" type="Bool">
<default>false</default>
</entry>
<entry name="tempAutoColor" type="Bool">
<default>true</default>
</entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,64 @@
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.plasmoid
import org.kde.kirigami as Kirigami
import org.kde.plasma.core as PlasmaCore
import "../code/utils.js" as Utils

ColumnLayout {
Loader {
id: compactRoot

readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical)
readonly property bool vertical: Plasmoid.formFactor == PlasmaCore.Types.Vertical
readonly property bool showTemperature: !inTray

sourceComponent: showTemperature ? iconAndTextComponent : iconComponent

function printDebug(msg) {
if (plasmoid.configuration.logConsole) {
console.log("[debug] [CompactRep.qml] " + msg);
}
}

IconAndTextItem {
vertical: compactRoot.vertical
iconSource: Qt.resolvedUrl("../icons/" + iconCode + ".svg")
text: appState == showDATA ? Utils.currentTempUnit(Utils.toUserTemp(weatherData["details"]["temp"])) : "--- °X"

Layout.fillWidth: compactRoot.vertical
Layout.fillHeight: !compactRoot.vertical
Layout.fillWidth: compactRoot.vertical
Layout.fillHeight: !compactRoot.vertical
Layout.minimumWidth: item.Layout.minimumWidth
Layout.minimumHeight: item.Layout.minimumHeight

MouseArea {
id: compactMouseArea
anchors.fill: parent
MouseArea {
id: compactMouseArea
anchors.fill: parent

hoverEnabled: true
hoverEnabled: true

onClicked: root.expanded = !root.expanded
onClicked: {
root.expanded = !root.expanded;
}
}

// Component {
// id: iconComponent
Component {
id: iconAndTextComponent

// PlasmaCore.SvgItem {
// readonly property int minIconSize: Math.max((compactRoot.vertical ? compactRoot.width : compactRoot.height), Kirigami.Units.iconSizes.small)

// svg: PlasmaCore.Svg {
// id: svg
// imagePath: plasmoid.file("", "icons/" + iconCode + ".svg")
// }
IconAndTextItem {
vertical: compactRoot.vertical
iconSource: Utils.getConditionIcon(iconCode)
text: appState == showDATA ? Utils.currentTempUnit(Utils.toUserTemp(weatherData["details"]["temp"])) : "--- °X"
}
}

// // reset implicit size, so layout in free dimension does not stop at the default one
// implicitWidth: Kirigami.Units.iconSizes.small
// implicitHeight: Kirigami.Units.iconSizes.small
// Layout.minimumWidth: compactRoot.vertical ? Kirigami.Units.iconSizes.small : minIconSize
// Layout.minimumHeight: compactRoot.vertical ? minIconSize : Kirigami.Units.iconSizes.small
// }
// }
Component {
id: iconComponent

// Component {
// id: iconAndTextComponent
Kirigami.Icon {
readonly property int minIconSize: Math.max((compactRoot.vertical ? compactRoot.width : compactRoot.height), Kirigami.Units.iconSizes.small)

// IconAndTextItem {
// vertical: compactRoot.vertical
// iconSource: plasmoid.file("", "icons/" + iconCode + ".svg")
// text: appState == showDATA ? Utils.currentTempUnit(weatherData["details"]["temp"]) : "---.-° X"
// }
// }
source: Utils.getConditionIcon(iconCode)
active: compactMouseArea.containsMouse
// reset implicit size, so layout in free dimension does not stop at the default one
implicitWidth: Kirigami.Units.iconSizes.small
implicitHeight: Kirigami.Units.iconSizes.small
Layout.minimumWidth: compactRoot.vertical ? Kirigami.Units.iconSizes.small : minIconSize
Layout.minimumHeight: compactRoot.vertical ? minIconSize : Kirigami.Units.iconSizes.small
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ GridLayout {
Kirigami.Icon {
id: topPanelIcon

// source: "gnumeric-object-arrow-symbolic"
// new rotation for icons:
// rotation: weatherData["winddir"] - 135

source: Qt.resolvedUrl("../icons/wind-barbs/" + Utils.getWindBarb(weatherData["details"]["windSpeed"])+ ".svg")
source: Utils.getWindBarbIcon(weatherData["details"]["windSpeed"])

color: Kirigami.Theme.textColor
isMask: true

// wind barb icons are 270 degrees deviated from 0 degrees (north)
rotation: weatherData["winddir"] - 270
// themed icons are 135 degrees deviated
rotation: plasmoid.configuration.useSystemThemeIcons ? weatherData["winddir"] - 135 : weatherData["winddir"] - 270


Layout.minimumWidth: Kirigami.Units.iconSizes.large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RowLayout {
Layout.preferredHeight: preferredIconSize
Layout.preferredWidth: preferredIconSize

source: Qt.resolvedUrl("../icons/" + iconCode + ".svg")
source: Utils.getConditionIcon(iconCode)

isMask: true
color: Kirigami.Theme.textColor
Expand Down
Loading

0 comments on commit c288c45

Please sign in to comment.