2017-09-18 14:33:44 +08:00
|
|
|
/*
|
2018-02-07 11:52:47 +08:00
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
2017-09-18 14:33:44 +08:00
|
|
|
*
|
|
|
|
* Author: sbw <sbw@sbw.so>
|
|
|
|
*
|
|
|
|
* Maintainer: sbw <sbw@sbw.so>
|
|
|
|
*
|
|
|
|
* 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 3 of the License, or
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-06-14 16:49:29 +08:00
|
|
|
#include "launcheritem.h"
|
2020-12-16 17:38:41 +08:00
|
|
|
#include "themeappicon.h"
|
|
|
|
#include "imagefactory.h"
|
2021-03-06 17:17:27 +08:00
|
|
|
#include "qgsettingsinterface.h"
|
|
|
|
#include "qgsettingsinterfaceimpl.h"
|
2016-06-14 16:49:29 +08:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QProcess>
|
2016-06-15 16:17:51 +08:00
|
|
|
#include <QMouseEvent>
|
2018-04-03 20:52:48 +08:00
|
|
|
#include <DDBusSender>
|
2018-10-24 18:09:44 +08:00
|
|
|
#include <QApplication>
|
2019-08-01 15:59:25 +08:00
|
|
|
#include <QGSettings>
|
2018-04-03 20:52:48 +08:00
|
|
|
|
|
|
|
DCORE_USE_NAMESPACE
|
2016-06-14 16:49:29 +08:00
|
|
|
|
2021-03-06 17:17:27 +08:00
|
|
|
LauncherItem::LauncherItem(QGSettingsInterface *interface, QWidget *parent)
|
2018-10-22 19:59:07 +08:00
|
|
|
: DockItem(parent)
|
|
|
|
, m_launcherInter(new LauncherInter("com.deepin.dde.Launcher", "/com/deepin/dde/Launcher", QDBusConnection::sessionBus(), this))
|
|
|
|
, m_tips(new TipsWidget(this))
|
2021-03-06 17:17:27 +08:00
|
|
|
, m_gsettings(interface)
|
2016-06-14 16:49:29 +08:00
|
|
|
{
|
2018-10-22 19:59:07 +08:00
|
|
|
m_launcherInter->setSync(true, false);
|
|
|
|
|
2016-07-20 11:31:04 +08:00
|
|
|
m_tips->setVisible(false);
|
2016-07-28 10:59:21 +08:00
|
|
|
m_tips->setObjectName("launcher");
|
2019-08-01 15:59:25 +08:00
|
|
|
|
2021-03-06 17:17:27 +08:00
|
|
|
if (m_gsettings->type() == QGSettingsInterface::REAL) {
|
|
|
|
QGSettingsInterfaceImpl *impl = dynamic_cast<QGSettingsInterfaceImpl *>(m_gsettings);
|
|
|
|
if (!impl)
|
|
|
|
qWarning("Error!");
|
|
|
|
connect(impl->gsettings(), &QGSettings::changed, this, &LauncherItem::onGSettingsChanged);
|
|
|
|
}
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
|
|
|
|
2017-03-07 17:30:30 +08:00
|
|
|
void LauncherItem::refershIcon()
|
|
|
|
{
|
|
|
|
const int iconSize = qMin(width(), height());
|
|
|
|
if (DockDisplayMode == Efficient)
|
|
|
|
{
|
2019-10-31 15:38:56 +08:00
|
|
|
m_icon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.7, devicePixelRatioF());
|
2017-03-07 17:30:30 +08:00
|
|
|
} else {
|
2019-10-31 15:38:56 +08:00
|
|
|
m_icon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.8, devicePixelRatioF());
|
2017-03-07 17:30:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-08-01 15:59:25 +08:00
|
|
|
void LauncherItem::showEvent(QShowEvent* event) {
|
|
|
|
QTimer::singleShot(0, this, [=] {
|
|
|
|
onGSettingsChanged("enable");
|
|
|
|
});
|
|
|
|
|
|
|
|
return DockItem::showEvent(event);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2017-03-07 17:30:30 +08:00
|
|
|
refershIcon();
|
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;
|
2016-06-14 16:49:29 +08:00
|
|
|
|
2018-10-22 19:59:07 +08:00
|
|
|
if (!m_launcherInter->IsVisible()) {
|
|
|
|
m_launcherInter->Show();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-27 15:02:34 +08:00
|
|
|
m_tips->setText(tr("Launcher"));
|
2016-07-20 11:31:04 +08:00
|
|
|
return m_tips;
|
|
|
|
}
|
2019-08-01 15:59:25 +08:00
|
|
|
|
|
|
|
void LauncherItem::onGSettingsChanged(const QString& key) {
|
|
|
|
if (key != "enable") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_gsettings->keys().contains("enable")) {
|
|
|
|
setVisible(m_gsettings->get("enable").toBool());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LauncherItem::checkGSettingsControl() const
|
|
|
|
{
|
|
|
|
return m_gsettings->keys().contains("control")
|
|
|
|
&& m_gsettings->get("control").toBool();
|
|
|
|
}
|