2
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
5
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "startupitem.h"
21
#include "../../component/myswitcher.h"
22
#include "startupdata.h"
24
#include <QApplication>
29
inline QPixmap getAppIconPix(const QString &iconName, int iconSize)
31
QIcon defaultExecutableIcon = QIcon::fromTheme("application-x-executable");//gnome-mine-application-x-executable
32
if (defaultExecutableIcon.isNull()) {
33
defaultExecutableIcon = QIcon("/usr/share/icons/kylin-icon-theme/48x48/mimetypes/application-x-executable.png");
34
if (defaultExecutableIcon.isNull())
35
defaultExecutableIcon = QIcon(":/res/autostart-default.png");
40
if (iconName.contains("/")) {
41
icon = QIcon(iconName);
44
icon = QIcon::fromTheme(iconName, defaultExecutableIcon);
47
qreal devicePixelRatio = qApp->devicePixelRatio();
49
QPixmap pixmap = icon.pixmap(iconSize * devicePixelRatio, iconSize * devicePixelRatio);
50
pixmap.setDevicePixelRatio(devicePixelRatio);
55
StartupItem::StartupItem(StartupData info, QWidget *parent) : QWidget(parent)
58
item = new QListWidgetItem();
59
// item->setSizeHint(QSize(400, 60));
61
m_layout = new QHBoxLayout();
62
m_leftLayout = new QHBoxLayout();
63
m_switchLayout = new QHBoxLayout();
65
m_appIcon = new QLabel();
66
m_appIcon->setFixedSize(40, 40);
67
m_appIcon->setScaledContents(true);//自动缩放,显示图像大小自动调整为Qlabel大小
68
m_appIcon->setPixmap(getAppIconPix(info.icon, 40));
70
m_appNameLabel = new QLabel();
71
this->setAppName(info.name);
72
m_appDescLabel = new QLabel();
73
m_appDescLabel->setText(info.comment);
75
switcher = new MySwitcher();
76
switcher->setOnStatus(info.enabled);
77
connect(switcher, &MySwitcher::statusChanged, [=] (const bool b) {
78
emit changeStartup(info.exec, b);
81
m_switchLayout->addWidget(switcher, 0, Qt::AlignCenter);
82
m_leftLayout->addWidget(m_appIcon);
84
m_labelWidget = new QWidget();
85
m_labelLayout = new QVBoxLayout(m_labelWidget);
86
m_labelLayout->addWidget(m_appNameLabel);
87
m_labelLayout->addWidget(m_appDescLabel);
88
m_leftLayout->addWidget(m_labelWidget);
90
m_layout->addLayout(m_leftLayout);
91
m_layout->addStretch();
92
m_layout->addLayout(m_switchLayout);
93
m_layout->setContentsMargins(10, 0, 10, 0);
94
this->setLayout(m_layout);
97
void StartupItem::setSwitcherOn(const bool b)
99
switcher->blockSignals(true);
100
switcher->setOnStatus(b);
101
switcher->blockSignals(false);
104
QListWidgetItem* StartupItem::getItem()
109
void StartupItem::setItemHovered()
115
void StartupItem::unsetItemHovered()
121
void StartupItem::setAppName(const QString &name)
124
m_appNameLabel->setText(name);
127
QString StartupItem::getAppName()
129
return this->m_appName;
132
void StartupItem::enterEvent(QEvent *event)
136
QWidget::enterEvent(event);
139
void StartupItem::paintEvent(QPaintEvent *event)
142
QPainter painter(this);
143
painter.setRenderHint(QPainter::Antialiasing, true);
146
path.addRoundedRect(QRectF(rect()), 2, 2);
147
painter.setOpacity(0.1);
148
painter.fillPath(path, QColor("#2bb6ea"));
151
QWidget::paintEvent(event);