feat: auto adjust the icon size of fashion system tray

Change-Id: Ia0d32d4df3d7299a422c001d8c5b98b1f824f298
This commit is contained in:
listenerri 2018-11-07 16:19:57 +08:00
parent 084477f208
commit 598978d350
Notes: gerrit 2018-11-08 15:09:20 +08:00
Verified+1: <jenkins@deepin.com>
Verified+1: zhaofangfangdeepin <zhaofangfang@linuxdeepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Thu, 08 Nov 2018 15:09:19 +0800
Reviewed-on: https://cr.deepin.io/39555
Project: dde/dde-dock
Branch: refs/heads/master
5 changed files with 80 additions and 10 deletions

View File

@ -28,6 +28,12 @@ SystemTrayPluginItem::SystemTrayPluginItem(PluginsItemInterface * const pluginIn
{
}
void SystemTrayPluginItem::setSuggestIconSize(QSize size)
{
// invoke the method "setSuggestIconSize" of FashionTrayItem class
QMetaObject::invokeMethod(centralWidget(), "setSuggestIconSize", Qt::QueuedConnection, Q_ARG(QSize, size));
}
bool SystemTrayPluginItem::eventFilter(QObject *watched, QEvent *e)
{
// 时尚模式下

View File

@ -33,6 +33,8 @@ public:
inline ItemType itemType() const Q_DECL_OVERRIDE {return ItemType::SystemTrayPlugin;}
void setSuggestIconSize(QSize size);
Q_SIGNALS:
void fashionSystemTraySizeChanged(const QSize &systemTraySize) const;

View File

@ -31,6 +31,8 @@
#include <window/mainwindow.h>
#include <item/systemtraypluginitem.h>
static DockItem *DraggingItem = nullptr;
static PlaceholderItem *RequestDockItem = nullptr;
@ -375,7 +377,12 @@ void MainPanel::adjustItemSize()
int totalWidth = 0;
int totalHeight = 0;
const auto &itemList = m_itemController->itemList();
const QSize &fashionSystemTraySize = DockSettings::Instance().fashionSystemTraySize();
// FSTray: FashionSystemTray
const QSize &FSTrayTotalSize = DockSettings::Instance().fashionSystemTraySize(); // the total size of FSTray
SystemTrayPluginItem *FSTrayItem = nullptr; // the FSTray item object
QSize FSTraySuggestIconSize = itemSize; // the suggested size of FStray icons
for (auto item : itemList)
{
const auto itemType = item->itemType();
@ -402,16 +409,17 @@ void MainPanel::adjustItemSize()
if (m_displayMode == Fashion) {
// 特殊处理时尚模式下的托盘插件
if (item->itemType() == DockItem::SystemTrayPlugin) {
FSTrayItem = static_cast<SystemTrayPluginItem *>(item.data());
if (m_position == Dock::Top || m_position == Dock::Bottom) {
item->setFixedWidth(fashionSystemTraySize.width());
item->setFixedWidth(FSTrayTotalSize.width());
item->setFixedHeight(itemSize.height());
totalWidth += fashionSystemTraySize.width();
totalWidth += FSTrayTotalSize.width();
totalHeight += itemSize.height();
} else {
item->setFixedWidth(itemSize.width());
item->setFixedHeight(fashionSystemTraySize.height());
item->setFixedHeight(FSTrayTotalSize.height());
totalWidth += itemSize.width();
totalHeight += fashionSystemTraySize.height();
totalHeight += FSTrayTotalSize.height();
}
} else {
item->setFixedSize(itemSize);
@ -471,8 +479,12 @@ void MainPanel::adjustItemSize()
}
// abort adjust.
if (containsCompletely)
if (containsCompletely) {
if (FSTrayItem) {
FSTrayItem->setSuggestIconSize(FSTraySuggestIconSize);
}
return;
}
// now, we need to decrease item size to fit panel size
int overflow;
@ -504,11 +516,23 @@ void MainPanel::adjustItemSize()
continue;
}
if (itemType == DockItem::SystemTrayPlugin) {
if (m_displayMode == Dock::Fashion) {
switch (m_position) {
case Dock::Top:
case Dock::Bottom:
FSTraySuggestIconSize.setWidth(itemSize.width() - decrease);
break;
case Dock::Left:
case Dock::Right:
FSTraySuggestIconSize.setHeight(itemSize.height() - decrease);
break;
}
}
continue;
}
switch (m_position)
{
switch (m_position) {
case Dock::Top:
case Dock::Bottom:
item->setFixedWidth(item->width() - decrease - bool(extraDecrease));
@ -524,6 +548,10 @@ void MainPanel::adjustItemSize()
--extraDecrease;
}
if (FSTrayItem) {
FSTrayItem->setSuggestIconSize(FSTraySuggestIconSize);
}
// ensure all extra space assigned
Q_ASSERT(extraDecrease == 0);
}

View File

@ -27,8 +27,11 @@
#define SpliterSize 2
#define TraySpace 10
#define TrayWidgetWidth 28
#define TrayWidgetHeight 28
#define TrayWidgetWidthMin 24
#define TrayWidgetHeightMin 24
int FashionTrayItem::TrayWidgetWidth = TrayWidgetWidthMin;
int FashionTrayItem::TrayWidgetHeight = TrayWidgetHeightMin;
FashionTrayItem::FashionTrayItem(Dock::Position pos, QWidget *parent)
: QWidget(parent),
@ -200,6 +203,33 @@ void FashionTrayItem::onTrayListExpandChanged(const bool expand)
requestResize();
}
// used by QMetaObject::invokeMethod in SystemTrayPluginItem / MainPanel
void FashionTrayItem::setSuggestIconSize(QSize size)
{
size = size * 0.6;
int length = qMin(size.width(), size.height());
// 设置最小值
// length = qMax(length, TrayWidgetWidthMin);
if (length == TrayWidgetWidth || length == TrayWidgetHeight) {
return;
}
TrayWidgetWidth = length;
TrayWidgetHeight = length;
QSize newSize(length, length);
m_controlWidget->setFixedSize(newSize);
for (auto wrapper : m_trayWidgetWrapperMap.values()) {
wrapper->setFixedSize(newSize);
}
requestResize();
}
void FashionTrayItem::showEvent(QShowEvent *event)
{
requestResize();

View File

@ -49,6 +49,7 @@ public:
public slots:
void onTrayListExpandChanged(const bool expand);
void setSuggestIconSize(QSize size);
protected:
void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
@ -79,6 +80,9 @@ private:
FashionTrayWidgetWrapper *m_currentAttentionTray;
Dock::Position m_dockPosistion;
static int TrayWidgetWidth;
static int TrayWidgetHeight;
};
#endif // FASHIONTRAYITEM_H