2023-02-16 13:51:55 +08:00
|
|
|
// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
2022-09-06 11:36:55 +08:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2017-09-18 14:33:44 +08:00
|
|
|
|
2016-06-14 16:49:29 +08:00
|
|
|
#include "launcheritem.h"
|
2020-12-16 17:38:41 +08:00
|
|
|
#include "themeappicon.h"
|
2021-03-12 13:20:13 +08:00
|
|
|
#include "utils.h"
|
2021-12-31 17:27:09 +08:00
|
|
|
#include "../widgets/tipswidget.h"
|
2022-08-19 11:59:01 +00:00
|
|
|
#include "dbusutil.h"
|
2016-06-14 16:49:29 +08:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QProcess>
|
2016-06-15 16:17:51 +08:00
|
|
|
#include <QMouseEvent>
|
2018-10-24 18:09:44 +08:00
|
|
|
#include <QApplication>
|
2019-08-01 15:59:25 +08:00
|
|
|
#include <QGSettings>
|
2023-06-13 15:05:44 +08:00
|
|
|
#include <QtConcurrent>
|
2021-12-31 17:27:09 +08:00
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusPendingCall>
|
|
|
|
#include <DDBusSender>
|
|
|
|
#include <QDBusPendingReply>
|
2018-04-03 20:52:48 +08:00
|
|
|
|
|
|
|
DCORE_USE_NAMESPACE
|
2016-06-14 16:49:29 +08:00
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
LauncherItem::LauncherItem(QWidget *parent)
|
2018-10-22 19:59:07 +08:00
|
|
|
: DockItem(parent)
|
2021-03-20 12:10:45 +08:00
|
|
|
, m_gsettings(Utils::ModuleSettingsPtr("launcher", QByteArray(), this))
|
2016-06-14 16:49:29 +08:00
|
|
|
{
|
2021-03-12 13:20:13 +08:00
|
|
|
if (m_gsettings) {
|
|
|
|
connect(m_gsettings, &QGSettings::changed, this, &LauncherItem::onGSettingsChanged);
|
2021-03-06 17:17:27 +08:00
|
|
|
}
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
|
|
|
|
2021-03-06 18:40:13 +08:00
|
|
|
void LauncherItem::refreshIcon()
|
2017-03-07 17:30:30 +08:00
|
|
|
{
|
|
|
|
const int iconSize = qMin(width(), height());
|
2021-04-22 09:56:28 +08:00
|
|
|
if (DockDisplayMode == Efficient) {
|
2021-04-26 11:28:47 +08:00
|
|
|
ThemeAppIcon::getIcon(m_icon, "deepin-launcher", iconSize * 0.7);
|
2017-03-07 17:30:30 +08:00
|
|
|
} else {
|
2021-04-26 11:28:47 +08:00
|
|
|
ThemeAppIcon::getIcon(m_icon, "deepin-launcher", iconSize * 0.8);
|
2017-03-07 17:30:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-06-14 16:49:29 +08:00
|
|
|
void LauncherItem::paintEvent(QPaintEvent *e)
|
|
|
|
{
|
|
|
|
DockItem::paintEvent(e);
|
|
|
|
|
2016-06-22 15:07:53 +08:00
|
|
|
if (!isVisible())
|
|
|
|
return;
|
|
|
|
|
2016-06-14 16:49:29 +08:00
|
|
|
QPainter painter(this);
|
2016-06-27 20:16:35 +08:00
|
|
|
|
2019-04-23 14:28:09 +08:00
|
|
|
const auto ratio = devicePixelRatioF();
|
2019-10-31 15:38:56 +08:00
|
|
|
const int iconX = rect().center().x() - m_icon.rect().center().x() / ratio;
|
|
|
|
const int iconY = rect().center().y() - m_icon.rect().center().y() / ratio;
|
2017-09-15 10:17:15 +08:00
|
|
|
|
2019-10-31 15:38:56 +08:00
|
|
|
painter.drawPixmap(iconX, iconY, m_icon);
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherItem::resizeEvent(QResizeEvent *e)
|
|
|
|
{
|
|
|
|
DockItem::resizeEvent(e);
|
|
|
|
|
2021-03-06 18:40:13 +08:00
|
|
|
refreshIcon();
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherItem::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-15 20:43:26 +08:00
|
|
|
hidePopup();
|
|
|
|
|
2018-11-13 16:01:36 +08:00
|
|
|
return QWidget::mousePressEvent(e);
|
|
|
|
}
|
2016-06-22 11:02:52 +08:00
|
|
|
|
2018-11-13 16:01:36 +08:00
|
|
|
void LauncherItem::mouseReleaseEvent(QMouseEvent *e)
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
if (e->button() != Qt::LeftButton)
|
|
|
|
return;
|
2023-06-13 15:05:44 +08:00
|
|
|
|
|
|
|
QtConcurrent::run([=] {
|
|
|
|
DDBusSender dbusSender = DDBusSender()
|
2022-08-19 11:59:01 +00:00
|
|
|
.service(launcherService)
|
|
|
|
.path(launcherPath)
|
|
|
|
.interface(launcherInterface);
|
2021-12-31 17:27:09 +08:00
|
|
|
|
2023-06-13 15:05:44 +08:00
|
|
|
QDBusPendingReply<bool> visibleReply = dbusSender.property("Visible").get();
|
|
|
|
if (!visibleReply.value())
|
|
|
|
dbusSender.method("Toggle").call();
|
|
|
|
});
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
2016-07-20 11:31:04 +08:00
|
|
|
|
|
|
|
QWidget *LauncherItem::popupTips()
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-12-31 17:27:09 +08:00
|
|
|
m_tips.reset(new TipsWidget(this));
|
|
|
|
m_tips->setVisible(false);
|
2018-08-27 15:02:34 +08:00
|
|
|
m_tips->setText(tr("Launcher"));
|
2022-01-12 19:58:14 +08:00
|
|
|
m_tips->setObjectName("launcher");
|
2021-12-31 17:27:09 +08:00
|
|
|
return m_tips.get();
|
2016-07-20 11:31:04 +08:00
|
|
|
}
|
2019-08-01 15:59:25 +08:00
|
|
|
|
|
|
|
void LauncherItem::onGSettingsChanged(const QString& key) {
|
|
|
|
if (key != "enable") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
if (m_gsettings && m_gsettings->keys().contains("enable")) {
|
2019-08-01 15:59:25 +08:00
|
|
|
setVisible(m_gsettings->get("enable").toBool());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LauncherItem::checkGSettingsControl() const
|
|
|
|
{
|
2021-03-16 14:13:50 +08:00
|
|
|
return m_gsettings && m_gsettings->keys().contains("control")
|
|
|
|
&& m_gsettings->get("control").toBool();
|
2019-08-01 15:59:25 +08:00
|
|
|
}
|
2021-08-25 21:03:30 +08:00
|
|
|
|
|
|
|
void LauncherItem::showEvent(QShowEvent* event) {
|
|
|
|
QTimer::singleShot(0, this, [=] {
|
|
|
|
onGSettingsChanged("enable");
|
|
|
|
});
|
|
|
|
|
|
|
|
return DockItem::showEvent(event);
|
|
|
|
}
|