feat(trash):trash start delay

This commit is contained in:
shaojun 2019-09-06 15:28:22 +08:00
parent c112e33bef
commit d53e59a39a
4 changed files with 25 additions and 15 deletions

View File

@ -47,7 +47,7 @@ public:
using DockItem::showContextMenu;
using DockItem::hidePopup;
inline ItemType itemType() const override;
ItemType itemType() const override;
QSize sizeHint() const override;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

View File

@ -33,9 +33,9 @@
DWIDGET_USE_NAMESPACE
TrashPlugin::TrashPlugin(QObject *parent)
: QObject(parent),
m_trashWidget(new TrashWidget),
m_tipsLabel(new QLabel)
: QObject(parent)
, m_trashWidget(nullptr)
, m_tipsLabel(new QLabel)
{
m_tipsLabel->setObjectName("trash");
m_tipsLabel->setStyleSheet("color:white;"
@ -70,6 +70,10 @@ void TrashPlugin::init(PluginProxyInterface *proxyInter)
qApp->setApplicationName(applicationName);
m_proxyInter = proxyInter;
if (!m_trashWidget)
m_trashWidget = new TrashWidget;
// DFMGlobal::instance()->installTranslator();
displayModeChanged(displayMode());
}

View File

@ -35,17 +35,13 @@
#include <QApplication>
TrashWidget::TrashWidget(QWidget *parent)
: QWidget(parent),
m_popupApplet(new PopupControlWidget(this))
: QWidget(parent)
, m_popupApplet(new PopupControlWidget(this))
{
// QIcon::setThemeName("deepin");
m_popupApplet->setVisible(false);
connect(m_popupApplet, &PopupControlWidget::emptyChanged, this, &TrashWidget::updateIcon);
connect(m_popupApplet, &PopupControlWidget::emptyChanged, this, &TrashWidget::updateIconAndRefresh);
updateIcon();
setAcceptDrops(true);
setMinimumSize(PLUGIN_ICON_MIN_SIZE, PLUGIN_ICON_MIN_SIZE);
@ -169,6 +165,9 @@ void TrashWidget::paintEvent(QPaintEvent *e)
QWidget::paintEvent(e);
QPainter painter(this);
updateIcon();
painter.drawPixmap(rect().center() - m_icon.rect().center() / devicePixelRatioF(), m_icon);
}
@ -185,8 +184,6 @@ void TrashWidget::resizeEvent(QResizeEvent *e)
}
QWidget::resizeEvent(e);
updateIcon();
}
void TrashWidget::updateIcon()
@ -202,8 +199,16 @@ void TrashWidget::updateIcon()
const int size = std::min(width(), height()) ;
QIcon icon = QIcon::fromTheme(iconString);
m_icon = icon.pixmap(size * devicePixelRatioF(), size * devicePixelRatioF());
m_icon.setDevicePixelRatio(devicePixelRatioF());
const auto ratio = devicePixelRatioF();
m_icon = icon.pixmap(size * ratio, size * ratio);
m_icon.setDevicePixelRatio(ratio);
}
void TrashWidget::updateIconAndRefresh()
{
updateIcon();
update();
}

View File

@ -48,6 +48,7 @@ public:
int trashItemCount() const;
void invokeMenuItem(const QString &menuId, const bool checked);
void updateIcon();
void updateIconAndRefresh();
signals:
void requestContextMenu() const;