mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat(shutdown):change shutdown ui
This commit is contained in:
parent
529f56c357
commit
6a100691a0
@ -30,6 +30,12 @@ namespace Dock {
|
|||||||
#define DOCK_PLUGIN_API_VERSION "1.2.1"
|
#define DOCK_PLUGIN_API_VERSION "1.2.1"
|
||||||
|
|
||||||
#define PROP_DISPLAY_MODE "DisplayMode"
|
#define PROP_DISPLAY_MODE "DisplayMode"
|
||||||
|
|
||||||
|
#define PLUGIN_BACKGROUND_MAX_SIZE 40
|
||||||
|
#define PLUGIN_BACKGROUND_MIN_SIZE 20
|
||||||
|
|
||||||
|
#define PLUGIN_ICON_MAX_SIZE 20
|
||||||
|
#define PLUGIN_ICON_MIN_SIZE 17
|
||||||
///
|
///
|
||||||
/// \brief The DisplayMode enum
|
/// \brief The DisplayMode enum
|
||||||
/// spec dock display mode
|
/// spec dock display mode
|
||||||
|
@ -27,14 +27,23 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
|
#include <DStyle>
|
||||||
|
|
||||||
|
DWIDGET_USE_NAMESPACE;
|
||||||
|
|
||||||
PluginWidget::PluginWidget(QWidget *parent)
|
PluginWidget::PluginWidget(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, m_hover(false)
|
||||||
|
, m_pressed(false)
|
||||||
{
|
{
|
||||||
|
setMouseTracking(true);
|
||||||
|
setMinimumSize(PLUGIN_ICON_MIN_SIZE, PLUGIN_ICON_MIN_SIZE);
|
||||||
|
setMaximumSize(PLUGIN_BACKGROUND_MAX_SIZE, PLUGIN_BACKGROUND_MAX_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize PluginWidget::sizeHint() const
|
QSize PluginWidget::sizeHint() const
|
||||||
{
|
{
|
||||||
return QSize(26, 26);
|
return QSize(PLUGIN_ICON_MIN_SIZE, PLUGIN_ICON_MIN_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginWidget::paintEvent(QPaintEvent *e)
|
void PluginWidget::paintEvent(QPaintEvent *e)
|
||||||
@ -44,18 +53,39 @@ void PluginWidget::paintEvent(QPaintEvent *e)
|
|||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
QString iconName = "system-shutdown";
|
QString iconName = "system-shutdown";
|
||||||
int iconSize;
|
int iconSize;
|
||||||
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
|
||||||
|
|
||||||
if (displayMode == Dock::Efficient) {
|
|
||||||
iconName = iconName + "-symbolic";
|
|
||||||
iconSize = 16;
|
|
||||||
} else {
|
|
||||||
iconSize = std::min(width(), height()) * 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
pixmap = loadSvg(iconName, QSize(iconSize, iconSize));
|
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
|
QColor color = QColor::fromRgb(40, 40, 40);;
|
||||||
|
|
||||||
|
if (m_hover) {
|
||||||
|
color = QColor::fromRgb(60, 60, 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_pressed) {
|
||||||
|
color = QColor::fromRgb(20, 20, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rect().height() > PLUGIN_BACKGROUND_MIN_SIZE) {
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setOpacity(0.5);
|
||||||
|
|
||||||
|
DStyleHelper dstyle(style());
|
||||||
|
const int radius = dstyle.pixelMetric(DStyle::PM_FrameRadius);
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRoundedRect(rect(), radius, radius);
|
||||||
|
painter.fillPath(path, color);
|
||||||
|
|
||||||
|
iconSize = PLUGIN_ICON_MAX_SIZE;
|
||||||
|
} else {
|
||||||
|
iconSize = PLUGIN_ICON_MIN_SIZE;
|
||||||
|
iconName = iconName + "-symbolic";
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setOpacity(1);
|
||||||
|
|
||||||
|
pixmap = loadSvg(iconName, QSize(iconSize, iconSize));
|
||||||
painter.drawPixmap(rect().center() - pixmap.rect().center() / devicePixelRatioF(), pixmap);
|
painter.drawPixmap(rect().center() - pixmap.rect().center() / devicePixelRatioF(), pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,3 +99,52 @@ const QPixmap PluginWidget::loadSvg(const QString &fileName, const QSize &size)
|
|||||||
|
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PluginWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
m_pressed = true;
|
||||||
|
update();
|
||||||
|
|
||||||
|
QWidget::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
m_pressed = false;
|
||||||
|
m_hover = false;
|
||||||
|
update();
|
||||||
|
|
||||||
|
QWidget::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginWidget::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
m_hover = true;
|
||||||
|
QWidget::mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginWidget::leaveEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if (!rect().contains(mapFromGlobal(QCursor::pos()))) {
|
||||||
|
m_hover = false;
|
||||||
|
m_pressed = false;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget::leaveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||||
|
// 保持横纵比
|
||||||
|
if (position == Dock::Bottom || position == Dock::Top) {
|
||||||
|
setMinimumWidth(height());
|
||||||
|
setMinimumHeight(PLUGIN_ICON_MIN_SIZE);
|
||||||
|
} else {
|
||||||
|
setMinimumWidth(PLUGIN_ICON_MIN_SIZE);
|
||||||
|
setMinimumHeight(width());
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
}
|
||||||
|
@ -34,14 +34,21 @@ public:
|
|||||||
explicit PluginWidget(QWidget *parent = 0);
|
explicit PluginWidget(QWidget *parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const override;
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
void leaveEvent(QEvent *event) override;
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QPixmap loadSvg(const QString &fileName, const QSize &size) const;
|
const QPixmap loadSvg(const QString &fileName, const QSize &size) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Dock::DisplayMode m_displayMode;
|
Dock::DisplayMode m_displayMode;
|
||||||
|
bool m_hover;
|
||||||
|
bool m_pressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLUGINWIDGET_H
|
#endif // PLUGINWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user