Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions plugin-networkmonitor/lxqtnetworkmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
* END_COMMON_COPYRIGHT_HEADER */

#include "lxqtnetworkmonitor.h"
#include "lxqtnetworkmonitorconfiguration.h"
#include "../panel/ilxqtpanelplugin.h"
#include "../panel/pluginsettings.h"

#include <QEvent>
#include <QIcon>
#include <QPainter>
#include <QPixmap>
#include <QLinearGradient>
Expand Down Expand Up @@ -185,6 +186,7 @@ bool LXQtNetworkMonitor::event(QEvent *event)

void LXQtNetworkMonitor::settingsChanged()
{
m_preferSystemIcons = mPlugin->settings()->value(QStringLiteral("preferSystemIcons"), true).toBool();
m_iconIndex = mPlugin->settings()->value(QStringLiteral("icon"), 1).toInt();
m_interface = mPlugin->settings()->value(QStringLiteral("interface")).toString();
if (m_interface.isEmpty())
Expand All @@ -199,7 +201,11 @@ void LXQtNetworkMonitor::settingsChanged()
m_interface = QString(QLatin1String(stats[0].interface_name));
}

loadPixmap(QStringLiteral("error"));
if (!m_iconState.isEmpty())
loadPixmap(m_iconState);
else
loadPixmap(QStringLiteral("error"));
update();
}

void LXQtNetworkMonitor::realign()
Expand All @@ -213,7 +219,18 @@ void LXQtNetworkMonitor::loadPixmap(const QString &state)
{
m_iconState = state;
const int size = mPlugin->panel()->iconSize();
m_pic = QPixmap(iconName(state)).scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (m_preferSystemIcons)
{
const QString themeName = QStringLiteral("network-%1").arg(state);
if (QIcon::hasThemeIcon(themeName))
m_pic = QIcon::fromTheme(themeName).pixmap(QSize(size, size));
else
m_pic = QPixmap(iconName(state)).scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
else
{
m_pic = QPixmap(iconName(state)).scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
m_stuff.setMinimumWidth(size + 2);
m_stuff.setMinimumHeight(size + 2);
}
Expand Down
1 change: 1 addition & 0 deletions plugin-networkmonitor/lxqtnetworkmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class LXQtNetworkMonitor: public QFrame
QStringList m_iconList;

int m_iconIndex;
bool m_preferSystemIcons = true;

QString m_interface;
QPixmap m_pic;
Expand Down
11 changes: 11 additions & 0 deletions plugin-networkmonitor/lxqtnetworkmonitorconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <algorithm>

#include <QCheckBox>
#include <QPushButton>

extern "C" {
Expand All @@ -55,6 +56,11 @@ LXQtNetworkMonitorConfiguration::LXQtNetworkMonitorConfiguration(PluginSettings
if (auto btn = ui->buttons->button(QDialogButtonBox::Close))
btn->setDefault(true);

connect(ui->preferSystemIconsCB, &QCheckBox::toggled, this, [this](bool checked) {
ui->iconLabel->setEnabled(!checked);
ui->iconCB->setEnabled(!checked);
saveSettings();
});
connect(ui->iconCB, &QComboBox::currentIndexChanged, this, &LXQtNetworkMonitorConfiguration::saveSettings);
connect(ui->interfaceCB, &QComboBox::currentIndexChanged, this, &LXQtNetworkMonitorConfiguration::saveSettings);

Expand All @@ -70,6 +76,7 @@ void LXQtNetworkMonitorConfiguration::saveSettings()
{
if (!mLockSettingChanges)
{
settings().setValue(QStringLiteral("preferSystemIcons"), ui->preferSystemIconsCB->isChecked());
settings().setValue(QStringLiteral("icon"), ui->iconCB->currentIndex());
settings().setValue(QStringLiteral("interface"), ui->interfaceCB->currentText());
}
Expand All @@ -79,6 +86,10 @@ void LXQtNetworkMonitorConfiguration::loadSettings()
{
mLockSettingChanges = true;

const bool preferSystemIcons = settings().value(QStringLiteral("preferSystemIcons"), true).toBool();
ui->preferSystemIconsCB->setChecked(preferSystemIcons);
ui->iconLabel->setEnabled(!preferSystemIcons);
ui->iconCB->setEnabled(!preferSystemIcons);
ui->iconCB->setCurrentIndex(settings().value(QStringLiteral("icon"), 1).toInt());

int count;
Expand Down
18 changes: 14 additions & 4 deletions plugin-networkmonitor/lxqtnetworkmonitorconfiguration.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@
<string>General</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="preferSystemIconsCB">
<property name="text">
<string>Prefer system icons</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="iconLabel">
<property name="text">
<string>Icon</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QComboBox" name="iconCB">
<item>
<property name="text">
Expand Down Expand Up @@ -67,14 +77,14 @@
</item>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="interfaceLabel">
<property name="text">
<string>Interface</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="interfaceCB">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand Down