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"
|
|
|
|
#include "util/themeappicon.h"
|
2016-06-27 20:16:35 +08:00
|
|
|
#include "util/imagefactory.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>
|
|
|
|
|
|
|
|
DCORE_USE_NAMESPACE
|
2016-06-14 16:49:29 +08:00
|
|
|
|
|
|
|
LauncherItem::LauncherItem(QWidget *parent)
|
2016-08-08 09:52:05 +08:00
|
|
|
: DockItem(parent),
|
2016-07-20 11:31:04 +08:00
|
|
|
|
2018-07-02 16:21:43 +08:00
|
|
|
m_tips(new TipsWidget(this))
|
2016-06-14 16:49:29 +08:00
|
|
|
{
|
2016-07-20 15:17:41 +08:00
|
|
|
setAccessibleName("Launcher");
|
2016-07-20 11:31:04 +08:00
|
|
|
m_tips->setVisible(false);
|
2016-07-28 10:59:21 +08:00
|
|
|
m_tips->setObjectName("launcher");
|
2016-07-20 16:30:56 +08:00
|
|
|
m_tips->setText(tr("Launcher"));
|
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)
|
|
|
|
{
|
|
|
|
m_smallIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.7);
|
|
|
|
m_largeIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.9);
|
|
|
|
} else {
|
|
|
|
m_smallIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.6);
|
|
|
|
m_largeIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.8);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-06-28 13:58:41 +08:00
|
|
|
const QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon;
|
|
|
|
|
2017-09-15 10:17:15 +08:00
|
|
|
const auto ratio = qApp->devicePixelRatio();
|
|
|
|
const int iconX = rect().center().x() - pixmap.rect().center().x() / ratio;
|
|
|
|
const int iconY = rect().center().y() - pixmap.rect().center().y() / ratio;
|
|
|
|
|
2018-01-23 13:35:42 +08:00
|
|
|
painter.drawPixmap(iconX, iconY, pixmap);
|
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)
|
|
|
|
{
|
2017-11-15 20:43:26 +08:00
|
|
|
hidePopup();
|
|
|
|
|
2016-09-20 14:55:23 +08:00
|
|
|
if (e->button() == Qt::RightButton/* && !perfectIconRect().contains(e->pos())*/)
|
2016-06-22 11:02:52 +08:00
|
|
|
return QWidget::mousePressEvent(e);
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
if (e->button() != Qt::LeftButton)
|
|
|
|
return;
|
2016-06-14 16:49:29 +08:00
|
|
|
|
|
|
|
QProcess *proc = new QProcess;
|
|
|
|
|
|
|
|
connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
|
|
|
|
|
2018-04-03 20:52:48 +08:00
|
|
|
DDBusSender()
|
|
|
|
.service("com.deepin.dde.Launcher")
|
|
|
|
.interface("com.deepin.dde.Launcher")
|
|
|
|
.path("/com/deepin/dde/Launcher")
|
2018-04-04 10:04:32 +08:00
|
|
|
.method("Toggle")
|
2018-04-03 20:52:48 +08:00
|
|
|
.call();
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
2016-07-20 11:31:04 +08:00
|
|
|
|
|
|
|
QWidget *LauncherItem::popupTips()
|
|
|
|
{
|
|
|
|
return m_tips;
|
|
|
|
}
|