Verified Commit a56544a9 authored by Alf Gaida's avatar Alf Gaida

Adding upstream version 0.4.0.

Signed-off-by: Alf Gaida's avatarAlf Gaida <agaida@siduction.org>
parents
project(nm-tray)
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
cmake_policy(SET CMP0071 NEW)
set(NM_TRAY_VERSION "0.3.0")
set(QT_MIN_VERSION "5.4.0")
set(KF5_MIN_VERSION "5.36.0")
set(CMAKE_AUTOMOC on)
set(CMAKE_AUTOUIC on)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS
Widgets
Gui
Network
DBus
LinguistTools
)
find_package(KF5NetworkManagerQt ${KF5_MIN_VERSION} REQUIRED)
include(GNUInstallDirs)
set(TRANSLATION_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
add_definitions(-DQT_NO_SIGNALS_SLOTS_KEYWORDS "-DTRANSLATION_DIR=\"${TRANSLATION_DIR}\"" "-DNM_TRAY_VERSION=\"${NM_TRAY_VERSION}\"")
if (NOT NM_TRAY_XDG_AUTOSTART_DIR)
#Note: we need the default to be /etc... (not the ${CMAKE_INSTALL_PREFIX}/etc)
set(NM_TRAY_XDG_AUTOSTART_DIR "${CMAKE_INSTALL_SYSCONFDIR}/xdg/autostart")
endif ()
message(STATUS "Translations destination dir: ${TRANSLATION_DIR}")
message(STATUS "Autostart .desktop entry destination dir: ${NM_TRAY_XDG_AUTOSTART_DIR}\n (can be overriden by setting the NM_TRAY_XDG_AUTOSTART_DIR cmake variable)")
set(SRCS
src/log.cpp
src/icons.cpp
src/nmmodel.cpp
src/nmproxy.cpp
src/connectioninfo.cpp
src/nmlist.cpp
src/menuview.cpp
src/windowmenu.cpp
src/tray.cpp
src/translate.cpp
src/main.cpp
)
file(GLOB TSS "translations/${PROJECT_NAME}_*.ts")
if (UPDATE_TRANSLATIONS)
message(WARNING "!! Disable updating translation after make (-DUPDATE_TRANSLATIONS=no) to avoid 'make clean' delete them !!")
qt5_create_translation(QMS "translations/${PROJECT_NAME}.ts" ${TSS} "src")
else ()
qt5_add_translation(QMS ${TSS})
endif()
qt5_add_dbus_interface(SRCS
dbus/org.freedesktop.Notifications.xml
dbus/org.freedesktop.Notifications
)
add_executable(nm-tray
${SRCS}
${QMS}
)
set_property(TARGET nm-tray PROPERTY CXX_STANDARD 11)
set_property(TARGET nm-tray PROPERTY CXX_STANDARD_REQUIRED on)
target_link_libraries(nm-tray
Qt5::Widgets
Qt5::Gui
KF5::NetworkManagerQt
)
if (WITH_MODEMMANAGER_SUPPORT)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Xml)
find_package(KF5ModemManagerQt ${KF5_MIN_VERSION} REQUIRED)
target_link_libraries(nm-tray KF5::ModemManagerQt)
endif()
install(TARGETS nm-tray RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" COMPONENT runtime)
install(FILES ${QMS} DESTINATION "${TRANSLATION_DIR}" COMPONENT translations)
install(FILES "resources/nm-tray.desktop" DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications" COMPONENT data)
install(FILES "resources/nm-tray-autostart.desktop" DESTINATION "${NM_TRAY_XDG_AUTOSTART_DIR}" COMPONENT data)
install(FILES "resources/nm-tray.conf" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}" COMPONENT data)
This diff is collapsed.
# nm-tray
**nm-tray** is a simple [NetworkManager](https://wiki.gnome.org/Projects/NetworkManager) front end with information icon residing in system tray (like e.g. nm-applet).
It's a pure Qt application. For interaction with *NetworkManager* it uses API provided by [**KF5::NetworkManagerQt**](https://projects.kde.org/projects/frameworks/networkmanager-qt) -> plain DBus communication.
## License
This software is licensed under [GNU GPLv2 or later](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
## Build example
git clone https://github.com/palinek/nm-tray.git
cd nm-tray
mkdir build
cd build
cmake ..
make
./nm-tray
## Packages
For [arch users](https://www.archlinux.org/) there is an AUR package [nm-tray-git](https://aur.archlinux.org/packages/nm-tray-git/) (thanks to [pmattern](https://github.com/pmattern)).
For [openSUSE users](https://www.opensuse.org/) there is a [package](https://build.opensuse.org/package/show/X11:LXQt:git/nm-tray) in the [X11:LXQt:git](https://build.opensuse.org/project/show/X11:LXQt:git) devel project of OBS.
## Translations
Thanks to [Weblate](https://weblate.org/) anyone can help us to localize nm-tray by using the [hosted weblate service](https://hosted.weblate.org/projects/nm-tray/translations/).
<?xml version="1.0"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Notifications">
<method name="GetServerInformation">
<arg direction="out" type="s" name="name"/>
<arg direction="out" type="s" name="vendor"/>
<arg direction="out" type="s" name="version"/>
<arg direction="out" type="s" name="spec_version"/>
</method>
<method name="CloseNotification">
<arg direction="in" type="u" name="id"/>
</method>
<method name="Notify">
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName.In6"/>
<arg direction="in" type="s" name="app_name"/>
<arg direction="in" type="u" name="replaces_id"/>
<arg direction="in" type="s" name="app_icon"/>
<arg direction="in" type="s" name="summary"/>
<arg direction="in" type="s" name="body"/>
<arg direction="in" type="as" name="actions"/>
<arg direction="in" type="a{sv}" name="hints"/>
<arg direction="in" type="i" name="expire_timeout"/>
<arg direction="out" type="u" name="id"/>
</method>
<method name="GetCapabilities">
<arg direction="out" type="as" name="capabilities"/>
</method>
<signal name="ActionInvoked">
<arg type="u"/>
<arg type="s"/>
</signal>
<signal name="NotificationClosed">
<arg type="u"/>
<arg type="u"/>
</signal>
</interface>
</node>
[Desktop Entry]
Type=Application
Name=nm-tray
TryExec=nm-tray
Exec=nm-tray
NotShowIn=KDE;GNOME;
X-LXQt-Need-Tray=true
[General]
connectionsEditor=xterm, -e, nmtui-edit
enableNotifications=true
[Desktop Entry]
Type=Application
Name=nm-tray
Comment=NetworkManager frontend (tray icon)
Icon=network-transmit
TryExec=nm-tray
Exec=nm-tray
Categories=System;Monitor;Qt;
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2015~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#include "connectioninfo.h"
#include "ui_connectioninfo.h"
#include "nmproxy.h"
#include <QScrollArea>
#include <QLabel>
#include <QItemSelection>
#include <QSortFilterProxyModel>
#include <QTabBar>
ConnectionInfo::ConnectionInfo(NmModel * model, QWidget *parent)
: QDialog{parent}
, ui{new Ui::ConnectionInfo}
, mModel{model}
, mActive{new NmProxy}
, mSorted{new QSortFilterProxyModel}
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
mActive->setNmModel(mModel, NmModel::ActiveConnectionType);
mSorted->setSortCaseSensitivity(Qt::CaseInsensitive);
mSorted->sort(0);
mSorted->setSourceModel(mActive.data());
for (int i = 0, row_cnt = mSorted->rowCount(); i < row_cnt; ++i)
{
addTab(mSorted->index(i, 0));
}
connect(mSorted.data(), &QAbstractItemModel::rowsInserted, [this] (QModelIndex const & parent, int first, int last) {
ui->tabWidget->setUpdatesEnabled(false);
for (int i = first; i <= last; ++i)
addTab(mSorted->index(i, 0, parent));
ui->tabWidget->setUpdatesEnabled(true);
});
connect(mSorted.data(), &QAbstractItemModel::rowsAboutToBeRemoved, [this] (QModelIndex const & parent, int first, int last) {
ui->tabWidget->setUpdatesEnabled(false);
for (int i = first; i <= last; ++i)
removeTab(mSorted->index(i, 0, parent));
ui->tabWidget->setUpdatesEnabled(true);
});
connect(mSorted.data(), &QAbstractItemModel::dataChanged, [this] (const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & /*roles*/) {
ui->tabWidget->setUpdatesEnabled(false);
for (auto const & i : QItemSelection{topLeft, bottomRight}.indexes())
changeTab(i);
ui->tabWidget->setUpdatesEnabled(true);
});
}
ConnectionInfo::~ConnectionInfo()
{
}
void ConnectionInfo::addTab(QModelIndex const & index)
{
QScrollArea * content = new QScrollArea;
QLabel * l = new QLabel{mSorted->data(index, NmModel::ActiveConnectionInfoRole).toString()};
content->setWidget(l);
//QTabWidget takes ownership of the page (if we will not take it back)
ui->tabWidget->insertTab(index.row(), content, mSorted->data(index, NmModel::IconRole).value<QIcon>(), mSorted->data(index, NmModel::NameRole).toString());
}
void ConnectionInfo::removeTab(QModelIndex const & index)
{
const int i = index.row();
QWidget * w = ui->tabWidget->widget(i);
ui->tabWidget->removeTab(i);
w->deleteLater();
}
void ConnectionInfo::changeTab(QModelIndex const & index)
{
const int i = index.row();
QScrollArea * content = qobject_cast<QScrollArea *>(ui->tabWidget->widget(i));
Q_ASSERT(nullptr != content);
// Note: the text is HTML formatted and the QLabel probably creates some DOM internal represntation.
// Should the DOM structure change, the QLabel will not update correctly upon the plain setText()
content->setWidget(new QLabel{mSorted->data(index, NmModel::ActiveConnectionInfoRole).toString()});
ui->tabWidget->tabBar()->setTabText(i, mSorted->data(index, NmModel::NameRole).toString());
ui->tabWidget->tabBar()->setTabIcon(i, mSorted->data(index, NmModel::IconRole).value<QIcon>());
}
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2015~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#ifndef CONNECTIONINFO_H
#define CONNECTIONINFO_H
#include <QDialog>
namespace Ui {
class ConnectionInfo;
}
class NmModel;
class NmProxy;
class QSortFilterProxyModel;
class ConnectionInfo : public QDialog
{
Q_OBJECT
public:
explicit ConnectionInfo(NmModel * model, QWidget *parent = nullptr);
~ConnectionInfo();
private:
void addTab(QModelIndex const & index);
void removeTab(QModelIndex const & index);
void changeTab(QModelIndex const & index);
private:
QScopedPointer<Ui::ConnectionInfo> ui;
NmModel * mModel;
QScopedPointer<NmProxy> mActive;
QScopedPointer<QSortFilterProxyModel> mSorted;
};
#endif // CONNECTIONINFO_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConnectionInfo</class>
<widget class="QDialog" name="ConnectionInfo">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>570</width>
<height>614</height>
</rect>
</property>
<property name="windowTitle">
<string>Connection information</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>-1</number>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2015~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#include "icons.h"
#include <QStringList>
#include <QDebug>
namespace icons
{
QIcon getIcon(Icon ico)
{
static const QStringList i_empty;
QStringList const * icon_names = &i_empty;
switch (ico)
{
case NETWORK_OFFLINE:
static const QStringList i_network_offline = { QStringLiteral("network-offline-symbolic") };
icon_names = &i_network_offline;
break;
case NETWORK_WIRED:
static const QStringList i_network_wired = { QStringLiteral("network-wired-symbolic") };
icon_names = &i_network_wired;
break;
case NETWORK_WIRED_DISCONNECTED:
static const QStringList i_network_wired_disconnected = { QStringLiteral("network-wired-disconnected-symbolic") };
icon_names = &i_network_wired_disconnected;
break;
case NETWORK_WIFI_DISCONNECTED:
static const QStringList i_wifi_disconnected = { QStringLiteral("network-wireless-disconnected-symbolic") };
icon_names = &i_wifi_disconnected;
break;
case NETWORK_WIFI_ACQUIRING:
static const QStringList i_wifi_acquiring = { QStringLiteral("network-wireless-acquiring-symbolic") };
icon_names = &i_wifi_acquiring;
break;
case NETWORK_WIFI_NONE:
static const QStringList i_wifi_none = { QStringLiteral("network-wireless-signal-none-symbolic"), QStringLiteral("network-wireless-connected-00-symbolic") };
icon_names = &i_wifi_none;
break;
case NETWORK_WIFI_WEAK:
static const QStringList i_wifi_weak = { QStringLiteral("network-wireless-signal-weak-symbolic"), QStringLiteral("network-wireless-connected-25-symbolic") };
icon_names = &i_wifi_weak;
break;
case NETWORK_WIFI_OK:
static const QStringList i_wifi_ok = { QStringLiteral("network-wireless-signal-ok-symbolic"), QStringLiteral("network-wireless-connected-50-symbolic") };
icon_names = &i_wifi_ok;
break;
case NETWORK_WIFI_GOOD:
static const QStringList i_wifi_good = { QStringLiteral("network-wireless-signal-good-symbolic"), QStringLiteral("network-wireless-connected-75-symbolic") };
icon_names = &i_wifi_good;
break;
case NETWORK_WIFI_EXCELENT:
static const QStringList i_wifi_excelent = { QStringLiteral("network-wireless-signal-excellent-symbolic"), QStringLiteral("network-wireless-connected-100-symbolic") };
icon_names = &i_wifi_excelent;
break;
case NETWORK_VPN:
static const QStringList i_network_vpn = { QStringLiteral("network-vpn") };
icon_names = &i_network_vpn;
break;
case SECURITY_LOW:
static const QStringList i_security_low = { QStringLiteral("security-low-symbolic") };
icon_names = &i_security_low;
break;
case SECURITY_HIGH:
static const QStringList i_security_high = { QStringLiteral("security-high-symbolic") };
icon_names = &i_security_high;
break;
case PREFERENCES_NETWORK:
static const QStringList i_preferences_network = { QStringLiteral("preferences-system-network") };
icon_names = &i_preferences_network;
break;
};
for (auto const & name : *icon_names)
{
QIcon icon{QIcon::fromTheme(name)};
if (!icon.isNull())
return icon;
}
//TODO: fallback!?!
return QIcon::fromTheme(QStringLiteral("network-transmit"));
}
Icon wifiSignalIcon(const int signal)
{
if (0 >= signal)
return icons::NETWORK_WIFI_NONE;
else if (25 >= signal)
return icons::NETWORK_WIFI_WEAK;
else if (50 >= signal)
return icons::NETWORK_WIFI_OK;
else if (75 >= signal)
return icons::NETWORK_WIFI_GOOD;
else
return icons::NETWORK_WIFI_EXCELENT;
}
}
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2015~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#if !defined(ICONS_H)
#define ICONS_H
#include <QIcon>
namespace icons
{
enum Icon {
NETWORK_OFFLINE
, NETWORK_WIRED
, NETWORK_WIRED_DISCONNECTED
, NETWORK_WIFI_ACQUIRING
, NETWORK_WIFI_NONE
, NETWORK_WIFI_WEAK
, NETWORK_WIFI_OK
, NETWORK_WIFI_GOOD
, NETWORK_WIFI_EXCELENT
, NETWORK_WIFI_DISCONNECTED
, NETWORK_VPN
, SECURITY_LOW
, SECURITY_HIGH
, PREFERENCES_NETWORK
};
QIcon getIcon(Icon ico);
Icon wifiSignalIcon(const int signal);
}
#endif
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2015~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#include "log.h"
#include <QtGlobal>
#if defined(NDEBUG)
Q_LOGGING_CATEGORY(NM_TRAY, "nm-tray", QtInfoMsg)
#else
Q_LOGGING_CATEGORY(NM_TRAY, "nm-tray")
#endif
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2015~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#if !defined(LOG_H)
#define LOG_H
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(NM_TRAY)
#endif //LOG_H
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2015~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#include <QApplication>
#include "tray.h"
#include "icons.h"
int main(int argc, char * argv[])
{
QApplication app{argc, argv};
app.setOrganizationName(QStringLiteral("nm-tray"));
app.setApplicationName(QStringLiteral("nm-tray"));
app.setWindowIcon(icons::getIcon(icons::PREFERENCES_NETWORK));
app.setQuitOnLastWindowClosed(false);
Tray tray;
return app.exec();
}
/*COPYRIGHT_HEADER
This file is a part of nm-tray.
Copyright (c)
2016~now Palo Kisa <palo.kisa@gmail.com>
nm-tray 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
COPYRIGHT_HEADER*/
#include "menuview.h"
#include "nmmodel.h"
#include <QSortFilterProxyModel>
#include <QScrollBar>
#include <QProxyStyle>
#include <QStyledItemDelegate>
#include <QApplication>
#include <QPainter>
#include <QDebug>
namespace
{
class SingleActivateStyle : public QProxyStyle
{
public:
using QProxyStyle::QProxyStyle;
virtual int styleHint(StyleHint hint, const QStyleOption * option = 0, const QWidget * widget = 0, QStyleHintReturn * returnData = 0) const override
{
if(hint == QStyle::SH_ItemView_ActivateItemOnSingleClick)
return 1;
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
};
class MultiIconDelegate : public QStyledItemDelegate
{
public:
using QStyledItemDelegate::QStyledItemDelegate;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
Q_ASSERT(index.isValid());
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
//add the security overlay icon
QIcon sec_icon = qvariant_cast<QIcon>(index.data(NmModel::IconSecurityRole));
if (!sec_icon.isNull())
{
QPixmap res_pixmap = opt.icon.pixmap(opt.decorationSize);
QPainter p{&res_pixmap};
QSize sec_size = res_pixmap.size();
sec_size /= 2;
QPoint sec_pos = res_pixmap.rect().bottomRight();
sec_pos -= QPoint{sec_size.width(), sec_size.height()};
p.drawPixmap(sec_pos, sec_icon.pixmap(sec_size));
opt.icon = QIcon{res_pixmap};
}
QStyle *style = option.widget ? option.widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, option.widget);
}
};