mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat(dock): change the lohic for dock icon‘s size
This commit is contained in:
parent
d8c0188dfc
commit
d325a98a2b
@ -361,7 +361,6 @@ bool PluginsItem::checkGSettingsControl() const
|
||||
|
||||
void PluginsItem::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
setMinimumSize(m_centralWidget->minimumSize());
|
||||
setMaximumSize(m_centralWidget->maximumSize());
|
||||
return DockItem::resizeEvent(event);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "../item/placeholderitem.h"
|
||||
#include "../item/components/appdrag.h"
|
||||
#include "../item/appitem.h"
|
||||
#include "../item/pluginsitem.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QTimer>
|
||||
@ -36,6 +37,7 @@
|
||||
#include <DWindowManagerHelper>
|
||||
|
||||
#define SPLITER_SIZE 2
|
||||
#define TRASH_MARGIN 20
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
@ -66,6 +68,7 @@ MainPanelControl::MainPanelControl(QWidget *parent)
|
||||
|
||||
m_appAreaWidget->installEventFilter(this);
|
||||
m_appAreaSonWidget->installEventFilter(this);
|
||||
m_trayAreaWidget->installEventFilter(this);
|
||||
}
|
||||
|
||||
MainPanelControl::~MainPanelControl()
|
||||
@ -153,41 +156,31 @@ void MainPanelControl::updateMainPanelLayout()
|
||||
m_trayAreaLayout->setContentsMargins(10, 0, 10, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainPanelControl::addFixedAreaItem(int index, QWidget *wdg)
|
||||
{
|
||||
m_fixedAreaLayout->insertWidget(index, wdg);
|
||||
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
wdg->setMaximumSize(height(), height());
|
||||
} else {
|
||||
wdg->setMaximumSize(width(), width());
|
||||
}
|
||||
resizeDockIcon();
|
||||
}
|
||||
|
||||
void MainPanelControl::addAppAreaItem(int index, QWidget *wdg)
|
||||
{
|
||||
m_appAreaSonLayout->insertWidget(index, wdg);
|
||||
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
wdg->setMaximumSize(height(), height());
|
||||
} else {
|
||||
wdg->setMaximumSize(width(), width());
|
||||
}
|
||||
resizeDockIcon();
|
||||
}
|
||||
|
||||
void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg)
|
||||
{
|
||||
m_trayAreaLayout->insertWidget(index, wdg);
|
||||
resizeDockIcon();
|
||||
}
|
||||
|
||||
void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg)
|
||||
{
|
||||
m_pluginLayout->insertWidget(index, wdg);
|
||||
resizeDockIcon();
|
||||
QTimer::singleShot(50, this, [ = ] {m_pluginAreaWidget->adjustSize();});
|
||||
|
||||
}
|
||||
|
||||
void MainPanelControl::removeFixedAreaItem(QWidget *wdg)
|
||||
@ -212,28 +205,7 @@ void MainPanelControl::removePluginAreaItem(QWidget *wdg)
|
||||
|
||||
void MainPanelControl::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
for (int i = 0; i < m_appAreaSonLayout->count(); ++i) {
|
||||
QWidget *w = m_appAreaSonLayout->itemAt(i)->widget();
|
||||
if (w) {
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
w->setMaximumSize(height(), height());
|
||||
} else {
|
||||
w->setMaximumSize(width(), width());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_fixedAreaLayout->count(); ++i) {
|
||||
QWidget *w = m_fixedAreaLayout->itemAt(i)->widget();
|
||||
if (w) {
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
w->setMaximumSize(height(), height());
|
||||
} else {
|
||||
w->setMaximumSize(width(), width());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resizeDockIcon();
|
||||
return QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
@ -481,38 +453,8 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event)
|
||||
if (watched == m_appAreaSonWidget) {
|
||||
if (event->type() == QEvent::LayoutRequest) {
|
||||
m_appAreaSonWidget->adjustSize();
|
||||
resizeDockIcon();
|
||||
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
m_fixedSpliter->setFixedSize(SPLITER_SIZE, height() * 0.6);
|
||||
m_appSpliter->setFixedSize(SPLITER_SIZE, height() * 0.6);
|
||||
m_traySpliter->setFixedSize(SPLITER_SIZE, height() * 0.5);
|
||||
} else {
|
||||
m_fixedSpliter->setFixedSize(width() * 0.6, SPLITER_SIZE);
|
||||
m_appSpliter->setFixedSize(width() * 0.6, SPLITER_SIZE);
|
||||
m_traySpliter->setFixedSize(width() * 0.5, SPLITER_SIZE);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_appAreaSonLayout->count(); ++i) {
|
||||
QWidget *w = m_appAreaSonLayout->itemAt(i)->widget();
|
||||
if (w) {
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
w->setMaximumSize(height(), height());
|
||||
} else {
|
||||
w->setMaximumSize(width(), width());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_fixedAreaLayout->count(); ++i) {
|
||||
QWidget *w = m_fixedAreaLayout->itemAt(i)->widget();
|
||||
if (w) {
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
w->setMaximumSize(height(), height());
|
||||
} else {
|
||||
w->setMaximumSize(width(), width());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
moveAppSonWidget();
|
||||
}
|
||||
@ -530,6 +472,16 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event)
|
||||
moveAppSonWidget();
|
||||
}
|
||||
|
||||
if (watched == m_trayAreaWidget) {
|
||||
if (event->type() == QEvent::Resize) {
|
||||
resizeDockIcon();
|
||||
}
|
||||
}
|
||||
|
||||
if (watched == m_trayAreaWidget) {
|
||||
if (event->type() == QEvent::Resize) {
|
||||
}
|
||||
}
|
||||
if (m_appDragWidget && watched == static_cast<QGraphicsView *>(m_appDragWidget)->viewport()) {
|
||||
QDropEvent *e = static_cast<QDropEvent *>(event);
|
||||
bool isContains = rect().contains(mapFromGlobal(m_appDragWidget->mapToGlobal(e->pos())));
|
||||
@ -767,3 +719,75 @@ void MainPanelControl::paintEvent(QPaintEvent *event)
|
||||
painter.fillRect(m_appSpliter->geometry(), color);
|
||||
painter.fillRect(m_traySpliter->geometry(), color);
|
||||
}
|
||||
|
||||
void MainPanelControl::resizeDockIcon()
|
||||
{
|
||||
//计算插件区域的垃圾箱大小
|
||||
int trashWidth = 0;
|
||||
int trashHeight = 0;
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
||||
PluginsItem *w = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget());
|
||||
if (w->pluginName() == "trash") {
|
||||
trashWidth = w->width();
|
||||
trashHeight = w->height();
|
||||
break;
|
||||
}
|
||||
}
|
||||
//计算luancher 和 APP 区域大小
|
||||
int iconWidgetwidth = 0;
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
iconWidgetwidth = this->width() - m_trayAreaWidget->width() - (m_pluginAreaWidget->width() - trashHeight);
|
||||
} else {
|
||||
iconWidgetwidth = this->height() - m_trayAreaWidget->height() - (m_pluginAreaWidget->height() - trashWidth);
|
||||
}
|
||||
|
||||
//计算每一个icon的大小
|
||||
float iconSize = (iconWidgetwidth) / (m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + 1) - 1;
|
||||
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
if (iconSize >= height()) {
|
||||
calcuDockIconSize(height(), height());
|
||||
} else {
|
||||
calcuDockIconSize(iconSize, height());
|
||||
}
|
||||
} else {
|
||||
if (iconSize >= width()) {
|
||||
calcuDockIconSize(width(), width());
|
||||
} else {
|
||||
calcuDockIconSize(width(), iconSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainPanelControl::calcuDockIconSize(int w, int h)
|
||||
{
|
||||
for (int i = 0; i < m_fixedAreaLayout->count(); ++ i) {
|
||||
m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(w, h);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_appAreaSonLayout->count(); ++ i) {
|
||||
m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(w, h);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
||||
PluginsItem *p = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget());
|
||||
if (p->pluginName() == "trash") {
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
p->setFixedSize(w, h - TRASH_MARGIN);
|
||||
} else {
|
||||
p->setFixedSize(w - TRASH_MARGIN, h);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
m_fixedSpliter->setFixedSize(SPLITER_SIZE, w * 0.6);
|
||||
m_appSpliter->setFixedSize(SPLITER_SIZE, w * 0.6);
|
||||
m_traySpliter->setFixedSize(SPLITER_SIZE, w * 0.5);
|
||||
} else {
|
||||
m_fixedSpliter->setFixedSize(h * 0.6, SPLITER_SIZE);
|
||||
m_appSpliter->setFixedSize(h * 0.6, SPLITER_SIZE);
|
||||
m_traySpliter->setFixedSize(h * 0.5, SPLITER_SIZE);
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,8 @@ private:
|
||||
void moveItem(DockItem *sourceItem, DockItem *targetItem);
|
||||
void handleDragMove(QDragMoveEvent *e, bool isFilter);
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void resizeDockIcon();
|
||||
void calcuDockIconSize(int w,int h);
|
||||
|
||||
public slots:
|
||||
void insertItem(const int index, DockItem *item);
|
||||
@ -102,6 +104,7 @@ private:
|
||||
QBoxLayout *m_pluginLayout;
|
||||
QWidget *m_appAreaSonWidget;
|
||||
QBoxLayout *m_appAreaSonLayout;
|
||||
QBoxLayout *m_appAreaLayout;
|
||||
Position m_position;
|
||||
QPointer<PlaceholderItem> m_placeholderItem;
|
||||
MainPanelDelegate *m_delegate;
|
||||
|
@ -29,7 +29,6 @@
|
||||
MultitaskingWidget::MultitaskingWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
m_icon = QIcon::fromTheme(":/icons/deepin-multitasking-view.svg");
|
||||
}
|
||||
|
||||
@ -38,11 +37,6 @@ void MultitaskingWidget::refreshIcon()
|
||||
update();
|
||||
}
|
||||
|
||||
QSize MultitaskingWidget::sizeHint() const
|
||||
{
|
||||
return QSize(16, 16);
|
||||
}
|
||||
|
||||
void MultitaskingWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
@ -63,18 +57,3 @@ void MultitaskingWidget::paintEvent(QPaintEvent *e)
|
||||
const QRectF &rfp = QRectF(icon.rect());
|
||||
painter.drawPixmap(rf.center() - rfp.center() / ratio, icon);
|
||||
}
|
||||
|
||||
void MultitaskingWidget::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,12 @@ class MultitaskingWidget : public QWidget
|
||||
public:
|
||||
explicit MultitaskingWidget(QWidget *parent = 0);
|
||||
void refreshIcon();
|
||||
QSize sizeHint() const override;
|
||||
|
||||
signals:
|
||||
void requestContextMenu(const QString &itemKey) const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
ShowDesktopWidget::ShowDesktopWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
void ShowDesktopWidget::refreshIcon()
|
||||
@ -37,11 +36,6 @@ void ShowDesktopWidget::refreshIcon()
|
||||
update();
|
||||
}
|
||||
|
||||
QSize ShowDesktopWidget::sizeHint() const
|
||||
{
|
||||
return QSize(16, 16);
|
||||
}
|
||||
|
||||
void ShowDesktopWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
@ -62,18 +56,3 @@ void ShowDesktopWidget::paintEvent(QPaintEvent *e)
|
||||
const QRectF &rfp = QRectF(icon.rect());
|
||||
painter.drawPixmap(rf.center() - rfp.center() / ratio, icon);
|
||||
}
|
||||
|
||||
void ShowDesktopWidget::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);
|
||||
}
|
||||
|
@ -31,14 +31,12 @@ class ShowDesktopWidget : public QWidget
|
||||
public:
|
||||
explicit ShowDesktopWidget(QWidget *parent = 0);
|
||||
void refreshIcon();
|
||||
QSize sizeHint() const override;
|
||||
|
||||
signals:
|
||||
void requestContextMenu(const QString &itemKey) const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // SHOWDESKTOPWIDGET_H
|
||||
|
@ -44,8 +44,6 @@ TrashWidget::TrashWidget(QWidget *parent)
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
setMinimumSize(PLUGIN_ICON_MIN_SIZE, PLUGIN_ICON_MIN_SIZE);
|
||||
|
||||
m_defaulticon = QIcon::fromTheme(":/icons/user-trash.svg");
|
||||
}
|
||||
|
||||
@ -54,14 +52,6 @@ QWidget *TrashWidget::popupApplet()
|
||||
return m_popupApplet;
|
||||
}
|
||||
|
||||
QSize TrashWidget::sizeHint() const
|
||||
{
|
||||
int w = std::min(width(), DOCK_MAX_SIZE);
|
||||
int h = std::min(height(), DOCK_MAX_SIZE);
|
||||
int size = std::max(w, h);
|
||||
return QSize(size, size);
|
||||
}
|
||||
|
||||
const QString TrashWidget::contextMenu() const
|
||||
{
|
||||
QList<QVariant> items;
|
||||
@ -177,21 +167,6 @@ void TrashWidget::paintEvent(QPaintEvent *e)
|
||||
painter.drawPixmap(rf.center() - rfp.center() / devicePixelRatioF(), m_icon);
|
||||
}
|
||||
|
||||
void TrashWidget::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
// 保持横纵比
|
||||
if (position == Dock::Bottom || position == Dock::Top) {
|
||||
setMaximumWidth(height());
|
||||
setMaximumHeight(QWIDGETSIZE_MAX);
|
||||
} else {
|
||||
setMaximumHeight(width());
|
||||
setMaximumWidth(QWIDGETSIZE_MAX);
|
||||
}
|
||||
|
||||
QWidget::resizeEvent(e);
|
||||
}
|
||||
|
||||
void TrashWidget::updateIcon()
|
||||
{
|
||||
// Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||
@ -203,11 +178,10 @@ void TrashWidget::updateIcon()
|
||||
if (displayMode == Dock::Efficient)
|
||||
iconString.append("-symbolic");
|
||||
|
||||
const int size = std::min(width(), height()) ;
|
||||
const int size = std::min(width(), height()) * ((Dock::Fashion == qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>()) ? 0.8 : 0.7);
|
||||
QIcon icon = QIcon::fromTheme(iconString, m_defaulticon);
|
||||
|
||||
const auto ratio = devicePixelRatioF();
|
||||
|
||||
m_icon = icon.pixmap(size * ratio, size * ratio);
|
||||
m_icon.setDevicePixelRatio(ratio);
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ public:
|
||||
|
||||
QWidget *popupApplet();
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
const QString contextMenu() const;
|
||||
int trashItemCount() const;
|
||||
void invokeMenuItem(const QString &menuId, const bool checked);
|
||||
@ -59,7 +58,6 @@ protected:
|
||||
void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;
|
||||
void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
|
||||
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
|
||||
|
||||
private slots:
|
||||
void removeApp(const QString &appKey);
|
||||
|
Loading…
x
Reference in New Issue
Block a user