2020-03-14 22:27:32 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
2020-02-22 11:22:50 +08:00
|
|
|
|
*
|
2020-03-14 22:27:32 +08:00
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2.1, or (at your option)
|
|
|
|
|
|
* any later version.
|
2020-02-22 11:22:50 +08:00
|
|
|
|
*
|
2020-03-14 22:27:32 +08:00
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
2020-02-22 11:22:50 +08:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2020-03-14 22:27:32 +08:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
2020-02-22 11:22:50 +08:00
|
|
|
|
*
|
2020-03-14 22:27:32 +08:00
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
|
|
|
|
|
#include "ukuitaskwidget.h"
|
|
|
|
|
|
#include "ukuitaskgroup.h"
|
|
|
|
|
|
#include "ukuitaskbar.h"
|
|
|
|
|
|
|
|
|
|
|
|
//#include <UKUi/Settings>
|
|
|
|
|
|
#include "../panel/common/ukuisettings.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
|
|
#include <QPainter>
|
2020-06-11 15:53:10 +08:00
|
|
|
|
#include <QPainterPath>
|
2020-02-22 11:22:50 +08:00
|
|
|
|
#include <QDrag>
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
#include <QMimeData>
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
|
|
#include <QStylePainter>
|
|
|
|
|
|
#include <QStyleOptionToolButton>
|
|
|
|
|
|
#include <QDesktopWidget>
|
2020-08-03 20:26:54 +08:00
|
|
|
|
#include <QScreen>
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
|
|
|
|
|
#include "ukuitaskgroup.h"
|
|
|
|
|
|
#include "ukuitaskbar.h"
|
|
|
|
|
|
#include "ukuitaskclosebutton.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <KWindowSystem/KWindowSystem>
|
|
|
|
|
|
// Necessary for closeApplication()
|
|
|
|
|
|
#include <KWindowSystem/NETWM>
|
|
|
|
|
|
#include <QtX11Extras/QX11Info>
|
|
|
|
|
|
|
|
|
|
|
|
bool UKUITaskWidget::sDraggging = false;
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
//void LeftAlignedTextStyle::drawItemText(QPainter * painter, const QRect & rect, int flags
|
|
|
|
|
|
// , const QPalette & pal, bool enabled, const QString & text
|
|
|
|
|
|
// , QPalette::ColorRole textRole) const
|
|
|
|
|
|
//{
|
|
|
|
|
|
// QString txt = QFontMetrics(painter->font()).elidedText(text, Qt::ElideRight, rect.width());
|
|
|
|
|
|
// return QProxyStyle::drawItemText(painter, rect, (flags & ~Qt::AlignHCenter) | Qt::AlignLeft, pal, enabled, txt, textRole);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
UKUITaskWidget::UKUITaskWidget(const WId window, UKUITaskBar * taskbar, QWidget *parent) :
|
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
|
mWindow(window),
|
|
|
|
|
|
mUrgencyHint(false),
|
|
|
|
|
|
mOrigin(Qt::TopLeftCorner),
|
|
|
|
|
|
mDrawPixmap(false),
|
|
|
|
|
|
mParentTaskBar(taskbar),
|
|
|
|
|
|
mPlugin(mParentTaskBar->plugin()),
|
|
|
|
|
|
mDNDTimer(new QTimer(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_ASSERT(taskbar);
|
|
|
|
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
|
|
|
|
setMinimumWidth(1);
|
|
|
|
|
|
setMinimumHeight(1);
|
|
|
|
|
|
setAcceptDrops(true);
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// QPixmap closePix = style()->standardPixmap(QStyle::SP_TitleBarCloseButton);
|
2020-03-01 22:46:04 +08:00
|
|
|
|
status=NORMAL;
|
2020-02-28 10:33:28 +08:00
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
|
|
|
|
|
|
setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
|
|
|
|
|
//for layout
|
|
|
|
|
|
mCloseBtn = new UKUITaskCloseButton(mWindow, this);
|
2020-06-10 20:17:51 +08:00
|
|
|
|
// mCloseBtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
|
2020-04-15 14:44:22 +08:00
|
|
|
|
mCloseBtn->setIconSize(QSize(19,19));
|
2020-04-17 15:21:37 +08:00
|
|
|
|
mCloseBtn->setFixedSize(QSize(19,19));
|
2020-12-03 17:14:17 +08:00
|
|
|
|
mTitleLabel = new QLabel(this);
|
2020-04-06 14:19:43 +08:00
|
|
|
|
mTitleLabel->setMargin(0);
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// mTitleLabel->setContentsMargins(0,0,0,10);
|
|
|
|
|
|
// mTitleLabel->adjustSize();
|
|
|
|
|
|
// mTitleLabel->setStyleSheet("QLabel{background-color: red;}");
|
2020-08-03 20:26:54 +08:00
|
|
|
|
|
2020-12-03 17:14:17 +08:00
|
|
|
|
mThumbnailLabel = new QLabel(this);
|
|
|
|
|
|
mAppIcon = new QLabel(this);
|
|
|
|
|
|
mVWindowsLayout = new QVBoxLayout(this);
|
|
|
|
|
|
mTopBarLayout = new QHBoxLayout(this);
|
2020-04-06 14:19:43 +08:00
|
|
|
|
mTopBarLayout->setContentsMargins(0,0,0,0);
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// mTopBarLayout->setAlignment(Qt::AlignVCenter);
|
|
|
|
|
|
// mTopBarLayout->setDirection(QBoxLayout::LeftToRight);
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
2020-04-06 14:19:43 +08:00
|
|
|
|
mTitleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
2020-02-22 11:22:50 +08:00
|
|
|
|
mAppIcon->setAlignment(Qt::AlignLeft);
|
|
|
|
|
|
mAppIcon->setScaledContents(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 自动缩放图片
|
|
|
|
|
|
// titleLabel->setScaledContents(true);
|
2020-03-07 15:23:28 +08:00
|
|
|
|
mThumbnailLabel->setScaledContents(true);
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置控件缩放方式
|
|
|
|
|
|
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
|
sizePolicy.setHorizontalPolicy(QSizePolicy::Expanding);
|
|
|
|
|
|
mTitleLabel->setSizePolicy(sizePolicy);
|
|
|
|
|
|
mAppIcon->setSizePolicy(sizePolicy);
|
|
|
|
|
|
sizePolicy.setVerticalPolicy(QSizePolicy::Expanding);
|
|
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// mTitleLabel->setAttribute(Qt::WA_TranslucentBackground, true);
|
|
|
|
|
|
// mAppIcon->setAttribute(Qt::WA_TranslucentBackground, true);
|
|
|
|
|
|
// mAppIcon->resize(QSize(32,32));
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置控件最大尺寸
|
2020-04-06 14:19:43 +08:00
|
|
|
|
//mTitleLabel->setFixedHeight(32);
|
2020-02-22 11:22:50 +08:00
|
|
|
|
mTitleLabel->setMinimumWidth(1);
|
|
|
|
|
|
mThumbnailLabel->setMinimumSize(QSize(1, 1));
|
|
|
|
|
|
|
|
|
|
|
|
mTitleLabel->setContentsMargins(0, 0, 5, 0);
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// mTopBarLayout->setSpacing(5);
|
2020-04-06 14:19:43 +08:00
|
|
|
|
mTopBarLayout->addWidget(mAppIcon, 0, Qt::AlignLeft | Qt::AlignVCenter);
|
2020-08-03 20:26:54 +08:00
|
|
|
|
mTopBarLayout->addWidget(mTitleLabel, 10, Qt::AlignLeft);
|
2020-12-07 20:16:01 +08:00
|
|
|
|
mTopBarLayout->addWidget(mCloseBtn, 0, Qt::AlignRight);
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// mTopBarLayout->addStretch();
|
|
|
|
|
|
// mTopBarLayout->addWidget(mCloseBtn, 0, Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
|
// mVWindowsLayout->setAlignment(Qt::AlignCenter);
|
2020-12-07 20:16:01 +08:00
|
|
|
|
mVWindowsLayout->addLayout(mTopBarLayout);
|
2020-08-26 15:44:10 +08:00
|
|
|
|
mVWindowsLayout->addWidget(mThumbnailLabel, Qt::AlignCenter, Qt::AlignCenter);
|
2020-07-30 21:07:36 +08:00
|
|
|
|
mVWindowsLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
2020-02-22 11:22:50 +08:00
|
|
|
|
this->setLayout(mVWindowsLayout);
|
|
|
|
|
|
updateText();
|
|
|
|
|
|
updateIcon();
|
|
|
|
|
|
mDNDTimer->setSingleShot(true);
|
|
|
|
|
|
mDNDTimer->setInterval(700);
|
|
|
|
|
|
connect(mDNDTimer, SIGNAL(timeout()), this, SLOT(activateWithDraggable()));
|
|
|
|
|
|
connect(UKUi::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(updateIcon()));
|
|
|
|
|
|
connect(mParentTaskBar, &UKUITaskBar::iconByClassChanged, this, &UKUITaskWidget::updateIcon);
|
|
|
|
|
|
connect(mCloseBtn, SIGNAL(sigClicked()), this, SLOT(closeApplication()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
UKUITaskWidget::~UKUITaskWidget()
|
|
|
|
|
|
{
|
2020-12-03 17:14:17 +08:00
|
|
|
|
this->deleteLater();
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::updateText()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowInfo info(mWindow, NET::WMVisibleName | NET::WMName);
|
|
|
|
|
|
QString title = info.visibleName().isEmpty() ? info.name() : info.visibleName();
|
|
|
|
|
|
mTitleLabel->setText(title);
|
2020-03-14 11:26:29 +08:00
|
|
|
|
QPalette pa;
|
|
|
|
|
|
pa.setColor(QPalette::WindowText,Qt::white);
|
|
|
|
|
|
mTitleLabel->setPalette(pa);
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// setText(title.replace("&", "&&"));
|
|
|
|
|
|
// setToolTip(title);
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::updateIcon()
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon ico;
|
|
|
|
|
|
if (mParentTaskBar->isIconByClass())
|
|
|
|
|
|
{
|
2020-08-17 14:43:42 +08:00
|
|
|
|
ico = QIcon::fromTheme(QString::fromUtf8(KWindowInfo{mWindow, 0, NET::WM2WindowClass}.windowClassClass()).toLower());
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (ico.isNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
ico = KWindowSystem::icon(mWindow);
|
|
|
|
|
|
}
|
2020-05-09 11:13:39 +08:00
|
|
|
|
mAppIcon->setPixmap(ico.pixmap(QSize(19,19)));
|
2020-04-20 16:16:56 +08:00
|
|
|
|
setPixmap(KWindowSystem::icon(mWindow));
|
|
|
|
|
|
// mPixmap = ico.pixmap(QSize(64,64);
|
2020-02-22 11:22:50 +08:00
|
|
|
|
//mAppIcon->setWindowIcon(ico.isNull() ? XdgIcon::defaultApplicationIcon() : ico);
|
|
|
|
|
|
//setIcon(ico.isNull() ? XdgIcon::defaultApplicationIcon() : ico);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-20 16:16:56 +08:00
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setPixmap(QPixmap _pixmap)
|
|
|
|
|
|
{
|
|
|
|
|
|
mPixmap = _pixmap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap UKUITaskWidget::getPixmap()
|
|
|
|
|
|
{
|
|
|
|
|
|
return mPixmap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 11:22:50 +08:00
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::refreshIconGeometry(QRect const & geom)
|
|
|
|
|
|
{
|
|
|
|
|
|
NETWinInfo info(QX11Info::connection(),
|
|
|
|
|
|
windowId(),
|
|
|
|
|
|
(WId) QX11Info::appRootWindow(),
|
|
|
|
|
|
NET::WMIconGeometry,
|
|
|
|
|
|
0);
|
|
|
|
|
|
NETRect const curr = info.iconGeometry();
|
|
|
|
|
|
if (curr.pos.x != geom.x() || curr.pos.y != geom.y()
|
|
|
|
|
|
|| curr.size.width != geom.width() || curr.size.height != geom.height())
|
|
|
|
|
|
{
|
|
|
|
|
|
NETRect nrect;
|
|
|
|
|
|
nrect.pos.x = geom.x();
|
|
|
|
|
|
nrect.pos.y = geom.y();
|
|
|
|
|
|
nrect.size.height = geom.height();
|
|
|
|
|
|
nrect.size.width = geom.width();
|
|
|
|
|
|
info.setIconGeometry(nrect);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
// It must be here otherwise dragLeaveEvent and dragMoveEvent won't be called
|
|
|
|
|
|
// on the other hand drop and dragmove events of parent widget won't be called
|
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
|
if (event->mimeData()->hasFormat(mimeDataFormat()))
|
|
|
|
|
|
{
|
|
|
|
|
|
emit dragging(event->source(), event->pos());
|
|
|
|
|
|
setAttribute(Qt::WA_UnderMouse, false);
|
|
|
|
|
|
} else
|
|
|
|
|
|
{
|
|
|
|
|
|
mDNDTimer->start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget::dragEnterEvent(event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::dragMoveEvent(QDragMoveEvent * event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (event->mimeData()->hasFormat(mimeDataFormat()))
|
|
|
|
|
|
{
|
|
|
|
|
|
emit dragging(event->source(), event->pos());
|
|
|
|
|
|
setAttribute(Qt::WA_UnderMouse, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::dragLeaveEvent(QDragLeaveEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
mDNDTimer->stop();
|
|
|
|
|
|
QWidget::dragLeaveEvent(event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::dropEvent(QDropEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
mDNDTimer->stop();
|
|
|
|
|
|
if (event->mimeData()->hasFormat(mimeDataFormat()))
|
|
|
|
|
|
{
|
|
|
|
|
|
emit dropped(event->source(), event->pos());
|
|
|
|
|
|
setAttribute(Qt::WA_UnderMouse, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
QWidget::dropEvent(event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::mousePressEvent(QMouseEvent* event)
|
|
|
|
|
|
{
|
|
|
|
|
|
const Qt::MouseButton b = event->button();
|
|
|
|
|
|
|
|
|
|
|
|
if (Qt::LeftButton == b)
|
2020-02-28 10:33:28 +08:00
|
|
|
|
{
|
2020-02-22 11:22:50 +08:00
|
|
|
|
mDragStartPosition = event->pos();
|
2020-02-28 10:33:28 +08:00
|
|
|
|
}
|
2020-03-05 15:38:47 +08:00
|
|
|
|
else if (Qt::MidButton == b && parentTaskBar()->closeOnMiddleClick())
|
|
|
|
|
|
closeApplication();
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
|
|
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
|
|
{
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// if (isChecked())
|
|
|
|
|
|
// minimizeApplication();
|
|
|
|
|
|
// else
|
|
|
|
|
|
raiseApplication();
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
2020-03-01 22:46:04 +08:00
|
|
|
|
status = NORMAL;
|
2020-02-28 10:33:28 +08:00
|
|
|
|
update();
|
2020-02-22 11:22:50 +08:00
|
|
|
|
QWidget::mouseReleaseEvent(event);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
2020-03-01 22:46:04 +08:00
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::enterEvent(QEvent *)
|
|
|
|
|
|
{
|
|
|
|
|
|
status = HOVER;
|
|
|
|
|
|
repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::leaveEvent(QEvent *)
|
|
|
|
|
|
{
|
|
|
|
|
|
status = NORMAL;
|
2020-04-15 14:44:22 +08:00
|
|
|
|
repaint();
|
2020-03-01 22:46:04 +08:00
|
|
|
|
}
|
2020-02-22 11:22:50 +08:00
|
|
|
|
QMimeData * UKUITaskWidget::mimeData()
|
|
|
|
|
|
{
|
|
|
|
|
|
QMimeData *mimedata = new QMimeData;
|
|
|
|
|
|
QByteArray ba;
|
|
|
|
|
|
QDataStream stream(&ba,QIODevice::WriteOnly);
|
|
|
|
|
|
stream << (qlonglong)(mWindow);
|
|
|
|
|
|
mimedata->setData(mimeDataFormat(), ba);
|
|
|
|
|
|
return mimedata;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-31 11:27:57 +08:00
|
|
|
|
void UKUITaskWidget::closeGroup() {
|
|
|
|
|
|
printf("\n....\n");
|
|
|
|
|
|
emit closeSigtoGroup();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
QMenu * menu = new QMenu(tr("Widget"));
|
|
|
|
|
|
menu->setAttribute(Qt::WA_DeleteOnClose);
|
2021-01-30 18:21:51 +08:00
|
|
|
|
/* 对应预览图右键功能 关闭 还原 最大化 最小化 置顶 取消置顶*/
|
2020-10-31 11:27:57 +08:00
|
|
|
|
QAction *close = menu->addAction(QIcon::fromTheme("window-close-symbolic"), tr("close"));
|
|
|
|
|
|
QAction *restore = menu->addAction(QIcon::fromTheme("window-restore-symbolic"), tr("restore"));
|
|
|
|
|
|
|
|
|
|
|
|
QAction *maxim = menu->addAction(QIcon::fromTheme("window-maximize-symbolic"), tr("maximaze"));
|
|
|
|
|
|
|
|
|
|
|
|
QAction *minim = menu->addAction(QIcon::fromTheme("window-minimize-symbolic"), tr("minimize"));
|
2021-01-30 18:21:51 +08:00
|
|
|
|
QAction *above = menu->addAction(QIcon::fromTheme("ukui-fixed"), tr("above"));
|
|
|
|
|
|
QAction *clear = menu->addAction(QIcon::fromTheme("ukui-unfixed"), tr("clear"));
|
|
|
|
|
|
|
2020-11-16 14:47:40 +08:00
|
|
|
|
connect(close, SIGNAL(triggered()), this, SLOT(closeApplication()));
|
2020-11-20 09:24:49 +08:00
|
|
|
|
connect(restore, SIGNAL(triggered()), this, SLOT(deMaximizeApplication()));
|
2020-10-31 11:27:57 +08:00
|
|
|
|
connect(maxim, SIGNAL(triggered()), this, SLOT(maximizeApplication()));
|
|
|
|
|
|
connect(minim, SIGNAL(triggered()), this, SLOT(minimizeApplication()));
|
2021-01-30 18:21:51 +08:00
|
|
|
|
connect(above, SIGNAL(triggered()), this, SLOT(setWindowKeepAbove()));
|
|
|
|
|
|
connect(clear, SIGNAL(triggered()), this, SLOT(setWindowStatusClear()));
|
2020-10-31 11:27:57 +08:00
|
|
|
|
connect(menu, &QMenu::aboutToHide, [this] {
|
|
|
|
|
|
emit closeSigtoPop();
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2021-03-05 20:31:37 +08:00
|
|
|
|
KWindowInfo info(mWindow, NET::WMState);
|
2021-05-25 10:05:05 +08:00
|
|
|
|
above->setEnabled(!(info.state() & NET::KeepAbove));
|
|
|
|
|
|
clear->setEnabled(info.state() & NET::KeepAbove);
|
2020-10-31 11:27:57 +08:00
|
|
|
|
menu->setGeometry(plugin()->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), menu->sizeHint()));
|
|
|
|
|
|
plugin()->willShowWindow(menu);
|
|
|
|
|
|
menu->show();
|
|
|
|
|
|
}
|
2020-02-22 11:22:50 +08:00
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
bool UKUITaskWidget::isApplicationHidden() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowInfo info(mWindow, NET::WMState);
|
|
|
|
|
|
return (info.state() & NET::Hidden);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-31 11:27:57 +08:00
|
|
|
|
|
2020-02-22 11:22:50 +08:00
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
bool UKUITaskWidget::isApplicationActive() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return KWindowSystem::activeWindow() == mWindow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::activateWithDraggable()
|
|
|
|
|
|
{
|
|
|
|
|
|
// raise app in any time when there is a drag
|
|
|
|
|
|
// in progress to allow drop it into an app
|
|
|
|
|
|
raiseApplication();
|
|
|
|
|
|
KWindowSystem::forceActiveWindow(mWindow);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::raiseApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowInfo info(mWindow, NET::WMDesktop | NET::WMState | NET::XAWMState);
|
|
|
|
|
|
if (parentTaskBar()->raiseOnCurrentDesktop() && info.isMinimized())
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowSystem::setOnDesktop(mWindow, KWindowSystem::currentDesktop());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int winDesktop = info.desktop();
|
|
|
|
|
|
if (KWindowSystem::currentDesktop() != winDesktop)
|
|
|
|
|
|
KWindowSystem::setCurrentDesktop(winDesktop);
|
|
|
|
|
|
}
|
|
|
|
|
|
KWindowSystem::activateWindow(mWindow);
|
2020-03-31 14:14:54 +08:00
|
|
|
|
emit windowMaximize();
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
|
|
|
|
|
setUrgencyHint(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::minimizeApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowSystem::minimizeWindow(mWindow);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::maximizeApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
QAction* act = qobject_cast<QAction*>(sender());
|
|
|
|
|
|
if (!act)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
int state = act->data().toInt();
|
|
|
|
|
|
switch (state)
|
|
|
|
|
|
{
|
2020-04-15 14:44:22 +08:00
|
|
|
|
case NET::MaxHoriz:
|
|
|
|
|
|
KWindowSystem::setState(mWindow, NET::MaxHoriz);
|
|
|
|
|
|
break;
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
case NET::MaxVert:
|
|
|
|
|
|
KWindowSystem::setState(mWindow, NET::MaxVert);
|
|
|
|
|
|
break;
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
default:
|
|
|
|
|
|
KWindowSystem::setState(mWindow, NET::Max);
|
|
|
|
|
|
break;
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isApplicationActive())
|
|
|
|
|
|
raiseApplication();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::deMaximizeApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowSystem::clearState(mWindow, NET::Max);
|
|
|
|
|
|
|
|
|
|
|
|
if (!isApplicationActive())
|
|
|
|
|
|
raiseApplication();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-30 18:21:51 +08:00
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setWindowKeepAbove()
|
|
|
|
|
|
{
|
2021-05-25 10:05:05 +08:00
|
|
|
|
if (!isApplicationActive())
|
|
|
|
|
|
raiseApplication();
|
2021-01-30 18:21:51 +08:00
|
|
|
|
KWindowSystem::setState(mWindow, NET::KeepAbove);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setWindowStatusClear()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowSystem::clearState(mWindow, NET::KeepAbove);
|
|
|
|
|
|
}
|
2020-02-22 11:22:50 +08:00
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::shadeApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowSystem::setState(mWindow, NET::Shaded);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::unShadeApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowSystem::clearState(mWindow, NET::Shaded);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
2020-12-03 17:14:17 +08:00
|
|
|
|
//void UKUITaskWidget::priv_closeApplication() {
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
2020-02-22 11:22:50 +08:00
|
|
|
|
void UKUITaskWidget::closeApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
// FIXME: Why there is no such thing in KWindowSystem??
|
|
|
|
|
|
NETRootInfo(QX11Info::connection(), NET::CloseWindow).closeWindowRequest(mWindow);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::setApplicationLayer()
|
|
|
|
|
|
{
|
|
|
|
|
|
QAction* act = qobject_cast<QAction*>(sender());
|
|
|
|
|
|
if (!act)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
int layer = act->data().toInt();
|
|
|
|
|
|
switch(layer)
|
|
|
|
|
|
{
|
2020-04-15 14:44:22 +08:00
|
|
|
|
case NET::KeepAbove:
|
|
|
|
|
|
KWindowSystem::clearState(mWindow, NET::KeepBelow);
|
|
|
|
|
|
KWindowSystem::setState(mWindow, NET::KeepAbove);
|
|
|
|
|
|
break;
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
case NET::KeepBelow:
|
|
|
|
|
|
KWindowSystem::clearState(mWindow, NET::KeepAbove);
|
|
|
|
|
|
KWindowSystem::setState(mWindow, NET::KeepBelow);
|
|
|
|
|
|
break;
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
default:
|
|
|
|
|
|
KWindowSystem::clearState(mWindow, NET::KeepBelow);
|
|
|
|
|
|
KWindowSystem::clearState(mWindow, NET::KeepAbove);
|
|
|
|
|
|
break;
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::moveApplicationToDesktop()
|
|
|
|
|
|
{
|
|
|
|
|
|
QAction* act = qobject_cast<QAction*>(sender());
|
|
|
|
|
|
if (!act)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
|
|
int desk = act->data().toInt(&ok);
|
|
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
KWindowSystem::setOnDesktop(mWindow, desk);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::moveApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowInfo info(mWindow, NET::WMDesktop);
|
|
|
|
|
|
if (!info.isOnCurrentDesktop())
|
|
|
|
|
|
KWindowSystem::setCurrentDesktop(info.desktop());
|
|
|
|
|
|
if (isMinimized())
|
|
|
|
|
|
KWindowSystem::unminimizeWindow(mWindow);
|
|
|
|
|
|
KWindowSystem::forceActiveWindow(mWindow);
|
|
|
|
|
|
const QRect& g = KWindowInfo(mWindow, NET::WMGeometry).geometry();
|
|
|
|
|
|
int X = g.center().x();
|
|
|
|
|
|
int Y = g.center().y();
|
|
|
|
|
|
QCursor::setPos(X, Y);
|
|
|
|
|
|
NETRootInfo(QX11Info::connection(), NET::WMMoveResize).moveResizeRequest(mWindow, X, Y, NET::Move);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::resizeApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
KWindowInfo info(mWindow, NET::WMDesktop);
|
|
|
|
|
|
if (!info.isOnCurrentDesktop())
|
|
|
|
|
|
KWindowSystem::setCurrentDesktop(info.desktop());
|
|
|
|
|
|
if (isMinimized())
|
|
|
|
|
|
KWindowSystem::unminimizeWindow(mWindow);
|
|
|
|
|
|
KWindowSystem::forceActiveWindow(mWindow);
|
|
|
|
|
|
const QRect& g = KWindowInfo(mWindow, NET::WMGeometry).geometry();
|
|
|
|
|
|
int X = g.bottomRight().x();
|
|
|
|
|
|
int Y = g.bottomRight().y();
|
|
|
|
|
|
QCursor::setPos(X, Y);
|
|
|
|
|
|
NETRootInfo(QX11Info::connection(), NET::WMMoveResize).moveResizeRequest(mWindow, X, Y, NET::BottomRight);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
void UKUITaskWidget::setUrgencyHint(bool set)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mUrgencyHint == set)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!set)
|
|
|
|
|
|
KWindowSystem::demandAttention(mWindow, false);
|
|
|
|
|
|
|
|
|
|
|
|
mUrgencyHint = set;
|
|
|
|
|
|
setProperty("urgent", set);
|
|
|
|
|
|
style()->unpolish(this);
|
|
|
|
|
|
style()->polish(this);
|
|
|
|
|
|
update();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
bool UKUITaskWidget::isOnDesktop(int desktop) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return KWindowInfo(mWindow, NET::WMDesktop).isOnDesktop(desktop);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool UKUITaskWidget::isOnCurrentScreen() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return QApplication::desktop()->screenGeometry(parentTaskBar()).intersects(KWindowInfo(mWindow, NET::WMFrameExtents).frameGeometry());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool UKUITaskWidget::isMinimized() const
|
|
|
|
|
|
{
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// return KWindowInfo(mWindow,NET::WMState | NET::XAWMState).isMinimized();
|
2020-05-19 13:50:18 +08:00
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,7,0))
|
2020-06-18 14:52:48 +08:00
|
|
|
|
return NET::Focused == (KWindowInfo(mWindow,NET::WMState).state()&NET::Focused);
|
|
|
|
|
|
#else
|
|
|
|
|
|
return isApplicationActive();
|
2020-05-19 13:50:18 +08:00
|
|
|
|
#endif
|
2020-04-09 14:20:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool UKUITaskWidget::isFocusState() const
|
|
|
|
|
|
{
|
|
|
|
|
|
qDebug()<<"KWindowInfo(mWindow,NET::WMState).state():"<<KWindowInfo(mWindow,NET::WMState).state();
|
2020-05-19 13:50:18 +08:00
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,7,0))
|
2020-04-09 14:20:44 +08:00
|
|
|
|
return NET::Focused == (KWindowInfo(mWindow,NET::WMState).state()&NET::Focused);
|
2020-06-18 14:52:48 +08:00
|
|
|
|
#else
|
|
|
|
|
|
return isApplicationActive();
|
2020-05-19 13:50:18 +08:00
|
|
|
|
#endif
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Qt::Corner UKUITaskWidget::origin() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return mOrigin;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setOrigin(Qt::Corner newOrigin)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mOrigin != newOrigin)
|
|
|
|
|
|
{
|
|
|
|
|
|
mOrigin = newOrigin;
|
|
|
|
|
|
update();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setAutoRotation(bool value, IUKUIPanel::Position position)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (position)
|
|
|
|
|
|
{
|
|
|
|
|
|
case IUKUIPanel::PositionTop:
|
|
|
|
|
|
case IUKUIPanel::PositionBottom:
|
|
|
|
|
|
setOrigin(Qt::TopLeftCorner);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case IUKUIPanel::PositionLeft:
|
|
|
|
|
|
setOrigin(Qt::BottomLeftCorner);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case IUKUIPanel::PositionRight:
|
|
|
|
|
|
setOrigin(Qt::TopRightCorner);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
setOrigin(Qt::TopLeftCorner);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::paintEvent(QPaintEvent *event)
|
|
|
|
|
|
{
|
2020-02-28 10:33:28 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
/*旧的设置预览三态的方式,注释掉的原因是其未能设置阴影*/
|
|
|
|
|
|
#if 0
|
2020-02-28 10:33:28 +08:00
|
|
|
|
QStyleOption opt;
|
|
|
|
|
|
opt.init(this);
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
|
|
|
|
|
|
|
switch(status)
|
2020-04-15 14:44:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
case NORMAL:
|
|
|
|
|
|
{
|
|
|
|
|
|
p.setBrush(QBrush(QColor(0x13,0x14,0x14,0xb2)));
|
|
|
|
|
|
p.setPen(Qt::black);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case HOVER:
|
|
|
|
|
|
{
|
|
|
|
|
|
// p.setBrush(QBrush(QColor(0xFF,0xFF,0xFF,0x19)));
|
|
|
|
|
|
p.setBrush(QBrush(QColor(0x13,0x14,0x14,0x19)));
|
|
|
|
|
|
p.setPen(Qt::black);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case PRESS:
|
|
|
|
|
|
{
|
|
|
|
|
|
p.setBrush(QBrush(QColor(0xFF,0xFF,0xFF,0x19)));
|
|
|
|
|
|
p.setPen(Qt::white);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-02-28 10:33:28 +08:00
|
|
|
|
p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
2020-03-01 22:46:04 +08:00
|
|
|
|
p.drawRoundedRect(opt.rect,6,6);
|
2020-02-28 10:33:28 +08:00
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 预览图的设置阴影的方式与其他控件有所不同
|
|
|
|
|
|
* 由于涉及到UKUITaskWidget 中心是一张截图
|
|
|
|
|
|
* 此处设置阴影的方式不是一种通用的方式
|
|
|
|
|
|
* tr:
|
|
|
|
|
|
* The way of setting shadow in preview image is different from other controls
|
|
|
|
|
|
* As it involves UKUITaskWidget center is a screenshot
|
|
|
|
|
|
* The way to set the shadow here is not a general way
|
|
|
|
|
|
*/
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
QPainterPath rectPath;
|
|
|
|
|
|
rectPath.addRoundedRect(this->rect(),6,6);
|
|
|
|
|
|
// 画一个黑底
|
|
|
|
|
|
QPixmap pixmap(this->rect().size());
|
|
|
|
|
|
pixmap.fill(Qt::transparent);
|
|
|
|
|
|
QPainter pixmapPainter(&pixmap);
|
|
|
|
|
|
pixmapPainter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
|
|
|
|
pixmapPainter.drawPath(rectPath);
|
|
|
|
|
|
pixmapPainter.end();
|
|
|
|
|
|
|
|
|
|
|
|
// 模糊这个黑底
|
|
|
|
|
|
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
|
|
|
|
|
QImage img = pixmap.toImage();
|
|
|
|
|
|
qt_blurImage(img, 10, false, false);
|
|
|
|
|
|
|
|
|
|
|
|
// 挖掉中心
|
|
|
|
|
|
pixmap = QPixmap::fromImage(img);
|
|
|
|
|
|
QPainter pixmapPainter2(&pixmap);
|
|
|
|
|
|
pixmapPainter2.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear);
|
|
|
|
|
|
/*在Qt中定义了一个常量,用于设置透明的颜色,即Qt::transparent,表示RGBA值为(0,0,0,0)的透明色。*/
|
|
|
|
|
|
// pixmapPainter2.setPen(Qt::transparent);
|
|
|
|
|
|
// pixmapPainter2.setBrush(Qt::transparent);
|
|
|
|
|
|
pixmapPainter2.drawPath(rectPath);
|
|
|
|
|
|
|
|
|
|
|
|
// 绘制阴影
|
|
|
|
|
|
p.drawPixmap(this->rect(), pixmap, pixmap.rect());
|
|
|
|
|
|
|
|
|
|
|
|
// 绘制底色
|
|
|
|
|
|
p.save();
|
|
|
|
|
|
switch(status)
|
|
|
|
|
|
{
|
|
|
|
|
|
case NORMAL:
|
|
|
|
|
|
{
|
|
|
|
|
|
p.fillPath(rectPath, QColor(0x13,0x14,0x14,0xb2));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case HOVER:
|
|
|
|
|
|
{
|
|
|
|
|
|
p.fillPath(rectPath, QColor(0x13,0x14,0x14,0x66));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case PRESS:
|
|
|
|
|
|
{
|
|
|
|
|
|
p.fillPath(rectPath, QColor(0xFF,0xFF,0xFF,0x19));
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
p.restore();
|
|
|
|
|
|
#endif
|
2020-02-22 11:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-28 10:33:28 +08:00
|
|
|
|
|
2020-02-22 11:22:50 +08:00
|
|
|
|
bool UKUITaskWidget::hasDragAndDropHover() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return mDNDTimer->isActive();
|
|
|
|
|
|
}
|
2020-04-15 14:44:22 +08:00
|
|
|
|
void UKUITaskWidget::updateTitle()
|
|
|
|
|
|
{
|
|
|
|
|
|
updateText();
|
|
|
|
|
|
}
|
2020-02-22 11:22:50 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
void UKUITaskWidget::setThumbNail(QPixmap _pixmap)
|
|
|
|
|
|
{
|
|
|
|
|
|
mThumbnailLabel->setPixmap(_pixmap);
|
|
|
|
|
|
}
|
2020-04-06 14:19:43 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
void UKUITaskWidget::removeThumbNail()
|
|
|
|
|
|
{
|
2020-04-06 14:19:43 +08:00
|
|
|
|
if(mThumbnailLabel)
|
|
|
|
|
|
{
|
|
|
|
|
|
mVWindowsLayout->removeWidget(mThumbnailLabel);
|
|
|
|
|
|
mThumbnailLabel->setParent(NULL);
|
|
|
|
|
|
mThumbnailLabel->deleteLater();
|
|
|
|
|
|
mThumbnailLabel = NULL;
|
|
|
|
|
|
}
|
2020-04-15 14:44:22 +08:00
|
|
|
|
}
|
2020-04-06 14:19:43 +08:00
|
|
|
|
|
2020-04-15 14:44:22 +08:00
|
|
|
|
void UKUITaskWidget::addThumbNail()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!mThumbnailLabel)
|
|
|
|
|
|
{
|
2020-12-03 17:14:17 +08:00
|
|
|
|
mThumbnailLabel = new QLabel(this);
|
2020-04-06 14:19:43 +08:00
|
|
|
|
mThumbnailLabel->setScaledContents(true);
|
|
|
|
|
|
mThumbnailLabel->setMinimumSize(QSize(1, 1));
|
2020-04-15 14:44:22 +08:00
|
|
|
|
// mVWindowsLayout->addLayout(mTopBarLayout, 100);
|
2020-12-07 20:30:34 +08:00
|
|
|
|
mVWindowsLayout->addWidget(mThumbnailLabel, 0, Qt::AlignCenter);
|
2020-04-15 14:44:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-03 20:26:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setTitleFixedWidth(int size)
|
|
|
|
|
|
{
|
|
|
|
|
|
mTitleLabel->setFixedWidth(size);
|
|
|
|
|
|
mTitleLabel->adjustSize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int UKUITaskWidget::getWidth()
|
|
|
|
|
|
{
|
|
|
|
|
|
return mTitleLabel->width();
|
|
|
|
|
|
}
|
2020-08-26 15:44:10 +08:00
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setThumbFixedSize(int w) {
|
|
|
|
|
|
this->mThumbnailLabel->setFixedWidth(w);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setThumbMaximumSize(int w) {
|
|
|
|
|
|
this->mThumbnailLabel->setMaximumWidth(w);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UKUITaskWidget::setThumbScale(bool val) {
|
|
|
|
|
|
this->mThumbnailLabel->setScaledContents(val);
|
|
|
|
|
|
}
|