mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
add trash item icon
Change-Id: Ib9975be9506460bcb7e18fcc701449197e546a76
This commit is contained in:
parent
d971572654
commit
73507e904d
Notes:
Deepin Code Review
2016-08-08 08:31:41 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Mon, 08 Aug 2016 08:31:41 +0000 Reviewed-on: https://cr.deepin.io/14978 Project: dde/dde-dock Branch: refs/heads/master
@ -34,7 +34,7 @@ void DiskPluginItem::resizeEvent(QResizeEvent *e)
|
||||
|
||||
QSize DiskPluginItem::sizeHint() const
|
||||
{
|
||||
return QSize(24, 24);
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
void DiskPluginItem::updateIcon()
|
||||
|
@ -11,7 +11,7 @@ DeviceItem::DeviceItem(const QUuid &deviceUuid)
|
||||
|
||||
QSize DeviceItem::sizeHint() const
|
||||
{
|
||||
return QSize(24, 24);
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
const QUuid DeviceItem::uuid() const
|
||||
|
@ -15,7 +15,7 @@ PluginWidget::PluginWidget(QWidget *parent)
|
||||
|
||||
QSize PluginWidget::sizeHint() const
|
||||
{
|
||||
return QSize(24, 24);
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
void PluginWidget::paintEvent(QPaintEvent *e)
|
||||
|
@ -13,7 +13,7 @@ PowerStatusWidget::PowerStatusWidget(QWidget *parent)
|
||||
|
||||
QSize PowerStatusWidget::sizeHint() const
|
||||
{
|
||||
return QSize(24, 24);
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
void PowerStatusWidget::paintEvent(QPaintEvent *e)
|
||||
|
@ -24,7 +24,7 @@ QWidget *SoundItem::popupApplet()
|
||||
|
||||
QSize SoundItem::sizeHint() const
|
||||
{
|
||||
return QSize(24, 24);
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
void SoundItem::resizeEvent(QResizeEvent *e)
|
||||
|
@ -44,7 +44,7 @@ const QImage TrayWidget::trayImage() const
|
||||
|
||||
QSize TrayWidget::sizeHint() const
|
||||
{
|
||||
return QSize(24, 24);
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
void TrayWidget::paintEvent(QPaintEvent *e)
|
||||
|
@ -7,11 +7,13 @@
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
const QString TrashDir = QDir::homePath() + "/.local/share/Trash/files";
|
||||
const QString TrashDir = QDir::homePath() + "/.local/share/Trash";
|
||||
|
||||
PopupControlWidget::PopupControlWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_empty(false),
|
||||
|
||||
m_openBtn(new DLinkButton(tr("Run"), this)),
|
||||
m_clearBtn(new DLinkButton(tr("Empty"), this)),
|
||||
|
||||
@ -30,7 +32,8 @@ PopupControlWidget::PopupControlWidget(QWidget *parent)
|
||||
setLayout(centeralLayout);
|
||||
setObjectName("trash");
|
||||
setFixedWidth(80);
|
||||
setFixedHeight(60);
|
||||
|
||||
trashStatusChanged();
|
||||
}
|
||||
|
||||
bool PopupControlWidget::empty() const
|
||||
@ -38,6 +41,11 @@ bool PopupControlWidget::empty() const
|
||||
return m_empty;
|
||||
}
|
||||
|
||||
QSize PopupControlWidget::sizeHint() const
|
||||
{
|
||||
return QSize(width(), m_empty ? 30 : 60);
|
||||
}
|
||||
|
||||
void PopupControlWidget::openTrashFloder()
|
||||
{
|
||||
QProcess *proc = new QProcess;
|
||||
@ -68,6 +76,10 @@ void PopupControlWidget::trashStatusChanged()
|
||||
if (m_empty == empty)
|
||||
return;
|
||||
|
||||
m_clearBtn->setVisible(!empty);
|
||||
m_empty = empty;
|
||||
|
||||
setFixedHeight(sizeHint().height());
|
||||
|
||||
emit emptyChanged(m_empty);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public:
|
||||
explicit PopupControlWidget(QWidget *parent = 0);
|
||||
|
||||
bool empty() const;
|
||||
QSize sizeHint() const;
|
||||
|
||||
signals:
|
||||
void emptyChanged(const bool empty) const;
|
||||
|
@ -1,7 +1,10 @@
|
||||
|
||||
#include "constants.h"
|
||||
#include "trashwidget.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
#include <QApplication>
|
||||
|
||||
TrashWidget::TrashWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
@ -11,6 +14,10 @@ TrashWidget::TrashWidget(QWidget *parent)
|
||||
QIcon::setThemeName("deepin");
|
||||
|
||||
m_popupApplet->setVisible(false);
|
||||
|
||||
connect(m_popupApplet, &PopupControlWidget::emptyChanged, this, &TrashWidget::updateIcon);
|
||||
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
QWidget *TrashWidget::popupApplet()
|
||||
@ -18,14 +25,37 @@ QWidget *TrashWidget::popupApplet()
|
||||
return m_popupApplet;
|
||||
}
|
||||
|
||||
QSize TrashWidget::sizeHint() const
|
||||
{
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
void TrashWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QWidget::paintEvent(e);
|
||||
|
||||
const int size = std::min(width(), height()) * 0.8;
|
||||
QIcon icon = QIcon::fromTheme("user-trash");
|
||||
QPixmap pixmap = icon.pixmap(size, size);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
||||
painter.drawPixmap(rect().center() - m_icon.rect().center(), m_icon);
|
||||
}
|
||||
|
||||
void TrashWidget::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void TrashWidget::updateIcon()
|
||||
{
|
||||
QString iconString = "user-trash";
|
||||
if (!m_popupApplet->empty())
|
||||
iconString.append("-full");
|
||||
if (qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>() == Dock::Efficient)
|
||||
iconString.append("-symbolic");
|
||||
|
||||
const int size = std::min(width(), height()) * 0.8;
|
||||
QIcon icon = QIcon::fromTheme(iconString);
|
||||
m_icon = icon.pixmap(size, size);
|
||||
|
||||
update();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "popupcontrolwidget.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPixmap>
|
||||
|
||||
class TrashWidget : public QWidget
|
||||
{
|
||||
@ -14,11 +15,19 @@ public:
|
||||
|
||||
QWidget *popupApplet();
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
|
||||
private slots:
|
||||
void updateIcon();
|
||||
|
||||
private:
|
||||
PopupControlWidget *m_popupApplet;
|
||||
|
||||
QPixmap m_icon;
|
||||
};
|
||||
|
||||
#endif // TRASHWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user