[weather] Show optionally temperature next to icon in compact mode

Summary:
Adds the logic for showing an alternative component for the compact
presentation, where the temperature is shown next to the icon with the
weather status (done in flow of layout).

Adds also the matching configuration logic to allow the user to enable that
alternative display.

BUG:302015
BUG:367751
FIXED-IN: 5.12.0

Reviewers: #plasma, broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9872
parent 01fc5332
......@@ -25,6 +25,13 @@ ConfigModel {
icon: "services"
source: "configWeatherStation.qml"
}
ConfigCategory {
name: i18n("Appearance")
icon: "preferences-desktop-color"
source: "configAppearance.qml"
}
ConfigCategory {
name: i18n("Units")
icon: "preferences-other"
......
......@@ -22,25 +22,52 @@ import QtQuick.Layouts 1.0
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
ColumnLayout {
id: compactRoot
readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical)
readonly property int wantedItemSize: vertical ? width : height
readonly property bool showTemperature: plasmoid.nativeInterface.configuration.showTemperatureInCompactMode
Layout.minimumWidth: vertical ? units.iconSizes.small : wantedItemSize
Layout.minimumHeight: vertical ? wantedItemSize : units.iconSizes.small
Loader {
id: loader
PlasmaCore.IconItem {
anchors.fill: parent
source: currentWeatherIconName
sourceComponent: showTemperature ? iconAndTextComponent : iconComponent
Layout.fillWidth: compactRoot.vertical
Layout.fillHeight: !compactRoot.vertical
Layout.minimumWidth: item.Layout.minimumWidth
Layout.minimumHeight: item.Layout.minimumHeight
MouseArea {
anchors.fill: parent
onClicked: {
plasmoid.expanded = !plasmoid.expanded;
}
}
}
Component {
id: iconComponent
PlasmaCore.IconItem {
readonly property int minIconSize: Math.max((compactRoot.vertical ? compactRoot.width : compactRoot.height), units.iconSizes.small)
source: currentWeatherIconName
// reset implicit size, so layout in free dimension does not stop at the default one
implicitWidth: units.iconSizes.small
implicitHeight: units.iconSizes.small
Layout.minimumWidth: compactRoot.vertical ? units.iconSizes.small : minIconSize
Layout.minimumHeight: compactRoot.vertical ? minIconSize : units.iconSizes.small
}
}
MouseArea {
anchors.fill: parent
Component {
id: iconAndTextComponent
onClicked: {
plasmoid.expanded = !plasmoid.expanded;
IconAndTextItem {
vertical: compactRoot.vertical
iconSource: currentWeatherIconName
text: plasmoid.nativeInterface.panelModel.currentTemperature
}
}
}
/*
* Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
*
* 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 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 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.1
import QtQuick.Layouts 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
GridLayout {
id: iconAndTextRoot
property alias iconSource: icon.source
property alias text: label.text
property bool vertical: false // too bad we cannot make this an enum
property int minimumIconSize: units.iconSizes.small
readonly property int iconSize: iconAndTextRoot.vertical ? width : height
columns: iconAndTextRoot.vertical ? 1 : 2
rows: iconAndTextRoot.vertical ? 2 : 1
columnSpacing: 0
rowSpacing: 0
PlasmaCore.IconItem {
id: icon
readonly property int implicitMinimumIconSize: Math.max(iconSize, minimumIconSize)
// reset implicit size, so layout in free dimension does not stop at the default one
implicitWidth: minimumIconSize
implicitHeight: minimumIconSize
Layout.fillWidth: iconAndTextRoot.vertical
Layout.fillHeight: !iconAndTextRoot.vertical
Layout.minimumWidth: iconAndTextRoot.vertical ? minimumIconSize : implicitMinimumIconSize
Layout.minimumHeight: iconAndTextRoot.vertical ? implicitMinimumIconSize : minimumIconSize
}
Item {
id: text
Layout.fillWidth: iconAndTextRoot.vertical
Layout.fillHeight: !iconAndTextRoot.vertical
Layout.minimumWidth: iconAndTextRoot.vertical ? 0 : sizehelper.paintedWidth
Layout.maximumWidth: iconAndTextRoot.vertical ? Infinity : Layout.minimumWidth
Layout.minimumHeight: iconAndTextRoot.vertical ? sizehelper.paintedHeight : 0
Layout.maximumHeight: iconAndTextRoot.vertical ? Layout.minimumHeight : Infinity
Text {
id: sizehelper
font {
family: label.font.family
weight: label.font.weight
italic: label.font.italic
pixelSize: iconAndTextRoot.vertical ? theme.mSize(theme.defaultFont).height * 2 : 1024 // random "big enough" size - this is used as a max pixelSize by the fontSizeMode
}
minimumPixelSize: theme.mSize(theme.smallestFont).height
fontSizeMode: iconAndTextRoot.vertical ? Text.HorizontalFit : Text.VerticalFit
wrapMode: Text.NoWrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors {
fill: parent
leftMargin: units.smallSpacing
rightMargin: units.smallSpacing
}
visible: false
// pattern to reserve some constant space TODO: improve and take formatting/i18n into account
text: "888.8° X"
}
PlasmaComponents.Label {
id: label
font {
weight: Font.Normal
pixelSize: 1024
pointSize: 0 // we need to unset pointSize otherwise it breaks the Text.Fit size mode
}
minimumPixelSize: theme.mSize(theme.smallestFont).height
fontSizeMode: Text.Fit
wrapMode: Text.NoWrap
height: 0
width: 0
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors {
fill: parent
leftMargin: units.smallSpacing
rightMargin: units.smallSpacing
}
}
}
}
/*
* Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
*
* 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 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 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 1.0 as QtControls
import QtQuick.Layouts 1.0
import org.kde.plasma.private.weather 1.0
ColumnLayout {
id: displayConfigPage
signal configurationChanged
function saveConfig() {
var config = {};
config.showTemperatureInCompactMode = showTemperatureCheckBox.checked;
plasmoid.nativeInterface.saveConfig(config);
plasmoid.nativeInterface.configChanged();
}
Component.onCompleted: {
var config = plasmoid.nativeInterface.configValues();
showTemperatureCheckBox.checked = config.showTemperatureInCompactMode;
}
GridLayout {
columns: 2
QtControls.Label {
Layout.row: 0
Layout.column: 0
Layout.alignment: Qt.AlignRight
text: i18n("Show temperature in compact mode:")
}
QtControls.CheckBox {
id: showTemperatureCheckBox
Layout.row: 0
Layout.column: 1
onCheckedChanged: displayConfigPage.configurationChanged();
}
}
Item { // tighten layout
Layout.fillHeight: true
}
}
......@@ -39,10 +39,12 @@ T clampValue(T value, int decimals)
namespace {
namespace AppletConfigKeys {
inline QString services() { return QStringLiteral("services"); }
inline QString services() { return QStringLiteral("services"); }
inline QString showTemperatureInCompactMode() { return QStringLiteral("showTemperatureInCompactMode"); }
}
namespace StorageConfigKeys {
const char weatherServiceProviders[] = "weatherServiceProviders";
const char weatherServiceProviders[] = "weatherServiceProviders";
const char showTemperatureInCompactMode[] = "showTemperatureInCompactMode";
}
namespace PanelModelKeys {
inline QString location() { return QStringLiteral("location"); }
......@@ -86,6 +88,17 @@ void WeatherApplet::init()
Plasma::WeatherPopupApplet::init();
}
void WeatherApplet::configChanged()
{
Plasma::WeatherPopupApplet::WeatherPopupApplet::configChanged();
KConfigGroup cfg = config();
m_configuration.insert(AppletConfigKeys::showTemperatureInCompactMode(),
cfg.readEntry(StorageConfigKeys::showTemperatureInCompactMode, false));
emit configurationChanged();
}
WeatherApplet::~WeatherApplet()
{
}
......@@ -460,6 +473,7 @@ QVariantMap WeatherApplet::configValues() const
KConfigGroup cfg = this->config();
config.insert(AppletConfigKeys::services(), cfg.readEntry(StorageConfigKeys::weatherServiceProviders, QStringList()));
config.insert(AppletConfigKeys::showTemperatureInCompactMode(), cfg.readEntry(StorageConfigKeys::showTemperatureInCompactMode, false));
return config;
}
......@@ -479,6 +493,10 @@ void WeatherApplet::saveConfig(const QVariantMap& configChanges)
if (it != configChanges.end()) {
cfg.writeEntry(StorageConfigKeys::weatherServiceProviders, it.value().toStringList());
}
it = configChanges.find(AppletConfigKeys::showTemperatureInCompactMode());
if (it != configChanges.end()) {
cfg.writeEntry(StorageConfigKeys::showTemperatureInCompactMode, it.value().toBool());
}
WeatherPopupApplet::saveConfig(configChanges);
}
......
......@@ -31,21 +31,26 @@ class WeatherApplet : public Plasma::WeatherPopupApplet
Q_PROPERTY(QVariantList detailsModel READ detailsModel NOTIFY modelUpdated)
Q_PROPERTY(QVariantList noticesModel READ noticesModel NOTIFY modelUpdated)
Q_PROPERTY(QVariantMap configuration READ configuration NOTIFY configurationChanged FINAL)
public:
WeatherApplet(QObject *parent, const QVariantList &args);
~WeatherApplet() override;
public: // Plasma::Applet API
void init() override;
void configChanged() override;
public:
QVariantMap panelModel() const { return m_panelModel; }
QVariantList fiveDaysModel() const { return m_fiveDaysModel; }
QVariantList detailsModel() const { return m_detailsModel; }
QVariantList noticesModel() const { return m_noticesModel; }
QVariantMap configuration() const { return m_configuration; }
Q_SIGNALS:
void modelUpdated();
void configurationChanged();
public: // WeatherPopupApplet API
QVariantMap configValues() const override;
......@@ -70,6 +75,8 @@ private:
QVariantList m_fiveDaysModel;
QVariantList m_detailsModel;
QVariantList m_noticesModel;
QVariantMap m_configuration;
};
#endif
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