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>
|
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
|
|
|
|
|
|
|
m_tips(new QLabel(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-07-20 11:31:04 +08:00
|
|
|
m_tips->setStyleSheet("color:white;"
|
|
|
|
"padding:5px 10px;");
|
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;
|
|
|
|
|
|
|
|
if (m_hover)
|
|
|
|
painter.drawPixmap(rect().center() - pixmap.rect().center(), ImageFactory::lighterEffect(pixmap));
|
2016-08-19 10:19:38 +08:00
|
|
|
else
|
|
|
|
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherItem::resizeEvent(QResizeEvent *e)
|
|
|
|
{
|
|
|
|
DockItem::resizeEvent(e);
|
|
|
|
|
2016-06-23 14:28:47 +08:00
|
|
|
const int iconSize = qMin(width(), height());
|
2016-07-11 17:17:32 +08:00
|
|
|
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);
|
|
|
|
}
|
2016-06-14 16:49:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherItem::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
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
|
|
|
|
2017-03-06 09:45:38 +08:00
|
|
|
// hide the tips window, because this window activate event will trigger dde-launcher auto-hide
|
|
|
|
hidePopup();
|
|
|
|
|
2016-06-14 16:49:29 +08:00
|
|
|
QProcess *proc = new QProcess;
|
|
|
|
|
|
|
|
connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
|
|
|
|
|
|
|
|
QStringList args = QStringList() << "--print-reply"
|
|
|
|
<< "--dest=com.deepin.dde.Launcher"
|
|
|
|
<< "/com/deepin/dde/Launcher"
|
|
|
|
<< "com.deepin.dde.Launcher.Toggle";
|
|
|
|
|
|
|
|
proc->start("dbus-send", args);
|
|
|
|
}
|
2016-07-20 11:31:04 +08:00
|
|
|
|
|
|
|
QWidget *LauncherItem::popupTips()
|
|
|
|
{
|
|
|
|
return m_tips;
|
|
|
|
}
|