2016-07-19 11:21:29 +08:00
|
|
|
#include "diskpluginitem.h"
|
2016-07-20 14:18:22 +08:00
|
|
|
#include "imageutil.h"
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QDebug>
|
2016-08-15 09:26:45 +08:00
|
|
|
#include <QMouseEvent>
|
2016-08-16 10:48:21 +08:00
|
|
|
#include <QIcon>
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
DiskPluginItem::DiskPluginItem(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
|
|
|
m_displayMode(Dock::Efficient)
|
|
|
|
{
|
2017-03-02 09:41:35 +08:00
|
|
|
// QIcon::setThemeName("deepin");
|
2016-07-19 11:21:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-08-15 09:26:45 +08:00
|
|
|
void DiskPluginItem::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
2016-08-16 10:55:59 +08:00
|
|
|
if (e->button() != Qt::RightButton)
|
|
|
|
return QWidget::mousePressEvent(e);
|
|
|
|
|
2016-08-15 09:26:45 +08:00
|
|
|
const QPoint p(e->pos() - rect().center());
|
|
|
|
if (p.manhattanLength() < std::min(width(), height()) * 0.8 * 0.5)
|
2016-09-22 14:31:38 +08:00
|
|
|
{
|
|
|
|
emit requestContextMenu();
|
2016-08-15 09:26:45 +08:00
|
|
|
return;
|
2016-09-22 14:31:38 +08:00
|
|
|
}
|
2016-08-15 09:26:45 +08:00
|
|
|
|
|
|
|
QWidget::mousePressEvent(e);
|
|
|
|
}
|
|
|
|
|
2016-07-19 11:21:29 +08:00
|
|
|
QSize DiskPluginItem::sizeHint() const
|
|
|
|
{
|
2016-08-09 14:51:03 +08:00
|
|
|
return QSize(26, 26);
|
2016-07-19 11:21:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiskPluginItem::updateIcon()
|
|
|
|
{
|
|
|
|
if (m_displayMode == Dock::Efficient)
|
2016-08-16 10:48:21 +08:00
|
|
|
// m_icon = ImageUtil::loadSvg(":/icons/resources/icon-small.svg", 16);
|
|
|
|
m_icon = QIcon::fromTheme("drive-removable-dock-symbolic").pixmap(16, 16);
|
2016-07-19 11:21:29 +08:00
|
|
|
else
|
2016-08-16 10:48:21 +08:00
|
|
|
// m_icon = ImageUtil::loadSvg(":/icons/resources/icon.svg", std::min(width(), height()) * 0.8);
|
|
|
|
m_icon = QIcon::fromTheme("drive-removable-dock").pixmap(std::min(width(), height()) * 0.8, std::min(width(), height()) * 0.8);
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
update();
|
|
|
|
}
|