mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
#include "diskpluginitem.h"
|
|
#include "imageutil.h"
|
|
|
|
#include <QPainter>
|
|
#include <QDebug>
|
|
#include <QMouseEvent>
|
|
|
|
DiskPluginItem::DiskPluginItem(QWidget *parent)
|
|
: QWidget(parent),
|
|
m_displayMode(Dock::Efficient)
|
|
{
|
|
}
|
|
|
|
void DiskPluginItem::setDockDisplayMode(const Dock::DisplayMode mode)
|
|
{
|
|
m_displayMode = mode;
|
|
|
|
updateIcon();
|
|
}
|
|
|
|
void DiskPluginItem::paintEvent(QPaintEvent *e)
|
|
{
|
|
QWidget::paintEvent(e);
|
|
|
|
QPainter painter(this);
|
|
painter.drawPixmap(rect().center() - m_icon.rect().center(), m_icon);
|
|
}
|
|
|
|
void DiskPluginItem::resizeEvent(QResizeEvent *e)
|
|
{
|
|
QWidget::resizeEvent(e);
|
|
|
|
updateIcon();
|
|
}
|
|
|
|
void DiskPluginItem::mousePressEvent(QMouseEvent *e)
|
|
{
|
|
if (e->button() != Qt::RightButton)
|
|
return QWidget::mousePressEvent(e);
|
|
|
|
const QPoint p(e->pos() - rect().center());
|
|
if (p.manhattanLength() < std::min(width(), height()) * 0.8 * 0.5)
|
|
return;
|
|
|
|
QWidget::mousePressEvent(e);
|
|
}
|
|
|
|
QSize DiskPluginItem::sizeHint() const
|
|
{
|
|
return QSize(26, 26);
|
|
}
|
|
|
|
void DiskPluginItem::updateIcon()
|
|
{
|
|
if (m_displayMode == Dock::Efficient)
|
|
m_icon = ImageUtil::loadSvg(":/icons/resources/icon-small.svg", 16);
|
|
else
|
|
m_icon = ImageUtil::loadSvg(":/icons/resources/icon.svg", std::min(width(), height()) * 0.8);
|
|
|
|
update();
|
|
}
|