mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat:ajdust all dock item size
This commit is contained in:
parent
b616162d69
commit
f8af5aaf24
@ -52,11 +52,9 @@ void LauncherItem::refershIcon()
|
||||
const int iconSize = qMin(width(), height());
|
||||
if (DockDisplayMode == Efficient)
|
||||
{
|
||||
m_smallIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.7, devicePixelRatioF());
|
||||
m_largeIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.9, devicePixelRatioF());
|
||||
m_icon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.7, devicePixelRatioF());
|
||||
} else {
|
||||
m_smallIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.6, devicePixelRatioF());
|
||||
m_largeIcon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.8, devicePixelRatioF());
|
||||
m_icon = ThemeAppIcon::getIcon("deepin-launcher", iconSize * 0.8, devicePixelRatioF());
|
||||
}
|
||||
|
||||
update();
|
||||
@ -79,13 +77,11 @@ void LauncherItem::paintEvent(QPaintEvent *e)
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
const QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon;
|
||||
|
||||
const auto ratio = devicePixelRatioF();
|
||||
const int iconX = rect().center().x() - pixmap.rect().center().x() / ratio;
|
||||
const int iconY = rect().center().y() - pixmap.rect().center().y() / ratio;
|
||||
const int iconX = rect().center().x() - m_icon.rect().center().x() / ratio;
|
||||
const int iconY = rect().center().y() - m_icon.rect().center().y() / ratio;
|
||||
|
||||
painter.drawPixmap(iconX, iconY, pixmap);
|
||||
painter.drawPixmap(iconX, iconY, m_icon);
|
||||
}
|
||||
|
||||
void LauncherItem::resizeEvent(QResizeEvent *e)
|
||||
|
@ -36,30 +36,29 @@ class LauncherItem : public DockItem
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LauncherItem(QWidget *parent = 0);
|
||||
explicit LauncherItem(QWidget *parent = nullptr) ;
|
||||
|
||||
inline ItemType itemType() const {return Launcher;}
|
||||
inline ItemType itemType() const override {return Launcher;}
|
||||
|
||||
void refershIcon();
|
||||
void refershIcon() override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
|
||||
QWidget *popupTips();
|
||||
QWidget *popupTips() override;
|
||||
|
||||
void onGSettingsChanged(const QString& key);
|
||||
|
||||
bool checkGSettingsControl() const;
|
||||
|
||||
private:
|
||||
QPixmap m_smallIcon;
|
||||
QPixmap m_largeIcon;
|
||||
QPixmap m_icon;
|
||||
LauncherInter *m_launcherInter;
|
||||
TipsWidget *m_tips;
|
||||
QGSettings* m_gsettings;
|
||||
|
@ -68,8 +68,6 @@ bool TrayPluginItem::eventFilter(QObject *watched, QEvent *e)
|
||||
const QString &propertyName = static_cast<QDynamicPropertyChangeEvent *>(e)->propertyName();
|
||||
if (propertyName == "TrayVisableItemCount") {
|
||||
m_trayVisableItemCount = watched->property("TrayVisableItemCount").toInt();
|
||||
|
||||
qDebug()<<"++++++++++++++++"<<m_trayVisableItemCount;
|
||||
Q_EMIT trayVisableCountChanged(m_trayVisableItemCount);
|
||||
}
|
||||
}
|
||||
|
184
frame/panel/mainpanelcontrol.cpp
Normal file → Executable file
184
frame/panel/mainpanelcontrol.cpp
Normal file → Executable file
@ -26,6 +26,7 @@
|
||||
#include "../item/components/appdrag.h"
|
||||
#include "../item/appitem.h"
|
||||
#include "../item/pluginsitem.h"
|
||||
#include "../item/traypluginitem.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QTimer>
|
||||
@ -38,6 +39,8 @@
|
||||
|
||||
#define SPLITER_SIZE 2
|
||||
#define TRASH_MARGIN 20
|
||||
#define PLUGIN_MAX_SIZE 40
|
||||
#define PLUGIN_MIN_SIZE 20
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
@ -172,6 +175,7 @@ void MainPanelControl::addAppAreaItem(int index, QWidget *wdg)
|
||||
|
||||
void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg)
|
||||
{
|
||||
m_tray = static_cast<TrayPluginItem *>(wdg);
|
||||
m_trayAreaLayout->insertWidget(index, wdg);
|
||||
resizeDockIcon();
|
||||
}
|
||||
@ -472,16 +476,6 @@ 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())));
|
||||
@ -722,72 +716,162 @@ void MainPanelControl::paintEvent(QPaintEvent *event)
|
||||
|
||||
void MainPanelControl::resizeDockIcon()
|
||||
{
|
||||
//计算插件区域的垃圾箱大小
|
||||
int trashWidth = 0;
|
||||
int trashHeight = 0;
|
||||
if (!m_tray)
|
||||
return;
|
||||
|
||||
PluginsItem *timePlugin = nullptr;
|
||||
PluginsItem *trashPlugin = nullptr;
|
||||
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;
|
||||
if (w->pluginName() == "datetime") {
|
||||
timePlugin = w;
|
||||
} else if (w->pluginName() == "trash") {
|
||||
trashPlugin = w;
|
||||
}
|
||||
}
|
||||
//计算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;
|
||||
// 总宽度
|
||||
int totalLength = ((m_position == Position::Top) || (m_position == Position::Bottom)) ? width() : height();
|
||||
// 减去托盘间隔区域
|
||||
totalLength -= (m_tray->trayVisableItemCount() + 1) * 10;
|
||||
// 减去插件间隔
|
||||
totalLength -= (m_pluginLayout->count() + 1) * 10;
|
||||
// 减去3个分割线的宽度
|
||||
totalLength -= 3 * SPLITER_SIZE;
|
||||
|
||||
// 减去时间控件的宽度
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom))
|
||||
totalLength -= (timePlugin ? timePlugin->centralWidget()->sizeHint().width() : 0);
|
||||
else
|
||||
totalLength -= (timePlugin ? timePlugin->centralWidget()->sizeHint().height() : 0);
|
||||
|
||||
if (totalLength < 0)
|
||||
return;
|
||||
|
||||
// 插件的个数(包含托盘和插件,减去时间控件,减去垃圾桶)
|
||||
int pluginCount = m_tray->trayVisableItemCount() + (m_pluginLayout->count() - (timePlugin ? 1 : 0) - (trashPlugin ? 1 : 0));
|
||||
|
||||
// icon个数
|
||||
int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + pluginCount;
|
||||
|
||||
int iconSize = 0;
|
||||
|
||||
// 余数
|
||||
int yu = (totalLength % iconCount);
|
||||
// icon宽度 = (总宽度-余数)/icon个数
|
||||
iconSize = (totalLength - yu) / iconCount;
|
||||
|
||||
if (iconSize < 20 || iconSize > 40) {
|
||||
|
||||
// 减去插件和托盘的宽度
|
||||
if (iconSize < 20)
|
||||
totalLength -= 20 * pluginCount;
|
||||
else
|
||||
totalLength -= 40 * pluginCount;
|
||||
|
||||
iconCount -= pluginCount;
|
||||
|
||||
// 余数
|
||||
int yu = (totalLength % iconCount);
|
||||
// icon宽度 = (总宽度-余数)/icon个数
|
||||
iconSize = (totalLength - yu) / iconCount;
|
||||
}
|
||||
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
if (iconSize >= height()) {
|
||||
calcuDockIconSize(height(), height());
|
||||
calcuDockIconSize(height(), height(), timePlugin, trashPlugin);
|
||||
} else {
|
||||
calcuDockIconSize(iconSize, height());
|
||||
calcuDockIconSize(iconSize, height(), timePlugin, trashPlugin);
|
||||
}
|
||||
} else {
|
||||
if (iconSize >= width()) {
|
||||
calcuDockIconSize(width(), width());
|
||||
calcuDockIconSize(width(), width(), timePlugin, trashPlugin);
|
||||
} else {
|
||||
calcuDockIconSize(width(), iconSize);
|
||||
calcuDockIconSize(width(), iconSize, timePlugin, trashPlugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainPanelControl::calcuDockIconSize(int w, int h)
|
||||
void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *timePlugin, PluginsItem *trashPlugin)
|
||||
{
|
||||
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);
|
||||
}
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
m_fixedSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6));
|
||||
m_appSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6));
|
||||
m_traySpliter->setFixedSize(SPLITER_SIZE, int(w * 0.5));
|
||||
// 垃圾桶
|
||||
if (trashPlugin)
|
||||
trashPlugin->setFixedSize(std::min(w, h - 20), h - 20);
|
||||
|
||||
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;
|
||||
|
||||
for (int i = 0; i < m_appAreaSonLayout->count(); ++ i) {
|
||||
m_appAreaSonLayout->itemAt(i)->widget()->setMaximumWidth(h);
|
||||
}
|
||||
|
||||
} else {
|
||||
m_fixedSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE);
|
||||
m_appSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE);
|
||||
m_traySpliter->setFixedSize(int(h * 0.5), SPLITER_SIZE);
|
||||
// 垃圾桶
|
||||
if (trashPlugin)
|
||||
trashPlugin->setFixedSize(w - 20, std::min(w - 20, h));
|
||||
|
||||
|
||||
for (int i = 0; i < m_appAreaSonLayout->count(); ++ i) {
|
||||
m_appAreaSonLayout->itemAt(i)->widget()->setMaximumHeight(w);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// 插件和托盘
|
||||
|
||||
// 托盘上每个图标大小
|
||||
int tray_item_size = 20;
|
||||
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
w = qBound(20, w, 40);
|
||||
tray_item_size = std::min(w, h - 20);
|
||||
} 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);
|
||||
h = qBound(20, h, 40);
|
||||
tray_item_size = std::min(w - 20, h);
|
||||
}
|
||||
|
||||
if (tray_item_size < 20)
|
||||
return;
|
||||
|
||||
int pluginCount = (m_pluginLayout->count() - (timePlugin ? 1 : 0) - (trashPlugin ? 1 : 0));
|
||||
|
||||
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
||||
m_tray->centralWidget()->setProperty("iconSize", tray_item_size);
|
||||
|
||||
// 插件区域宽度
|
||||
int timeWidth = timePlugin ? timePlugin->centralWidget()->sizeHint().width() + 10 : 0;
|
||||
int trashWidth = trashPlugin ? trashPlugin->width() + 10 : 0;
|
||||
|
||||
m_pluginAreaWidget->setFixedWidth((tray_item_size + 10)*pluginCount + timeWidth + trashWidth + 10);
|
||||
m_pluginAreaWidget->setFixedHeight(h);
|
||||
|
||||
} else {
|
||||
m_tray->centralWidget()->setProperty("iconSize", tray_item_size);
|
||||
|
||||
int timeHeight = timePlugin ? timePlugin->centralWidget()->sizeHint().height() + 10 : 0;
|
||||
int trashHeight = trashPlugin ? trashPlugin->height() + 10 : 0;
|
||||
|
||||
m_pluginAreaWidget->setFixedWidth(w);
|
||||
m_pluginAreaWidget->setFixedHeight((tray_item_size + 10)*pluginCount + timeHeight + trashHeight + 10);
|
||||
}
|
||||
}
|
||||
|
||||
void MainPanelControl::getTrayVisableItemCount()
|
||||
{
|
||||
if (m_trayAreaLayout->count() > 0) {
|
||||
TrayPluginItem *w = static_cast<TrayPluginItem *>(m_trayAreaLayout->itemAt(0)->widget());
|
||||
m_trayIconCount = w->trayVisableItemCount();
|
||||
} else {
|
||||
m_trayIconCount = 0;
|
||||
}
|
||||
|
||||
resizeDockIcon();
|
||||
}
|
||||
|
8
frame/panel/mainpanelcontrol.h
Normal file → Executable file
8
frame/panel/mainpanelcontrol.h
Normal file → Executable file
@ -30,6 +30,9 @@
|
||||
|
||||
using namespace Dock;
|
||||
|
||||
class TrayPluginItem;
|
||||
class PluginsItem;
|
||||
|
||||
class MainPanelDelegate
|
||||
{
|
||||
public:
|
||||
@ -56,6 +59,7 @@ public:
|
||||
void removePluginAreaItem(QWidget *wdg);
|
||||
void setPositonValue(Position position);
|
||||
void setDisplayMode(DisplayMode m_displayMode);
|
||||
void getTrayVisableItemCount();
|
||||
|
||||
MainPanelDelegate *delegate() const;
|
||||
void setDelegate(MainPanelDelegate *delegate);
|
||||
@ -86,7 +90,7 @@ private:
|
||||
void handleDragMove(QDragMoveEvent *e, bool isFilter);
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void resizeDockIcon();
|
||||
void calcuDockIconSize(int w,int h);
|
||||
void calcuDockIconSize(const int w, const int h, PluginsItem *timePlugin = nullptr, PluginsItem *trashPlugin = nullptr);
|
||||
|
||||
public slots:
|
||||
void insertItem(const int index, DockItem *item);
|
||||
@ -115,6 +119,8 @@ private:
|
||||
QLabel *m_appSpliter;
|
||||
QLabel *m_traySpliter;
|
||||
QPoint m_mousePressPos;
|
||||
int m_trayIconCount;
|
||||
TrayPluginItem *m_tray = nullptr;
|
||||
};
|
||||
|
||||
#endif // MAINPANELCONTROL_H
|
||||
|
1
frame/window/mainwindow.cpp
Normal file → Executable file
1
frame/window/mainwindow.cpp
Normal file → Executable file
@ -639,6 +639,7 @@ void MainWindow::updateGeometry()
|
||||
resizeMainPanelWindow();
|
||||
|
||||
m_mainPanel->update();
|
||||
m_mainPanel->getTrayVisableItemCount();
|
||||
}
|
||||
|
||||
void MainWindow::clearStrutPartial()
|
||||
|
@ -43,11 +43,6 @@ NotificationsWidget::NotificationsWidget(QWidget *parent)
|
||||
});
|
||||
}
|
||||
|
||||
QSize NotificationsWidget::sizeHint() const
|
||||
{
|
||||
return QSize(PLUGIN_BACKGROUND_MAX_SIZE, PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
}
|
||||
|
||||
void NotificationsWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
@ -71,15 +66,5 @@ void NotificationsWidget::paintEvent(QPaintEvent *e)
|
||||
|
||||
void NotificationsWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
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(event);
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ public:
|
||||
explicit NotificationsWidget(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
QSize sizeHint() const override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
};
|
||||
|
@ -45,6 +45,8 @@ TrashWidget::TrashWidget(QWidget *parent)
|
||||
setAcceptDrops(true);
|
||||
|
||||
m_defaulticon = QIcon::fromTheme(":/icons/user-trash.svg");
|
||||
|
||||
setMinimumSize(PLUGIN_ICON_MIN_SIZE, PLUGIN_ICON_MIN_SIZE);
|
||||
}
|
||||
|
||||
QWidget *TrashWidget::popupApplet()
|
||||
@ -178,7 +180,17 @@ void TrashWidget::updateIcon()
|
||||
if (displayMode == Dock::Efficient)
|
||||
iconString.append("-symbolic");
|
||||
|
||||
const int size = std::min(width(), height()) * ((Dock::Fashion == qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>()) ? 0.8 : 0.7);
|
||||
int size = std::min(width(), height());
|
||||
if (size < PLUGIN_ICON_MIN_SIZE)
|
||||
size = PLUGIN_ICON_MIN_SIZE;
|
||||
if (size > PLUGIN_BACKGROUND_MAX_SIZE)
|
||||
{
|
||||
size *= ((Dock::Fashion == qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>()) ? 0.8 : 0.7);
|
||||
if(size < PLUGIN_BACKGROUND_MAX_SIZE)
|
||||
size = PLUGIN_BACKGROUND_MAX_SIZE;
|
||||
}
|
||||
|
||||
|
||||
QIcon icon = QIcon::fromTheme(iconString, m_defaulticon);
|
||||
|
||||
const auto ratio = devicePixelRatioF();
|
||||
|
@ -128,22 +128,42 @@ void AbstractContainer::setExpand(const bool expand)
|
||||
// return totalSize();
|
||||
//}
|
||||
|
||||
void AbstractContainer::setItemSize(int itemSize)
|
||||
{
|
||||
m_itemSize = itemSize;
|
||||
|
||||
for (auto w : wrapperList()) {
|
||||
if (dockPosition() == Dock::Top || dockPosition() == Dock::Bottom)
|
||||
w->setFixedSize(m_itemSize, QWIDGETSIZE_MAX);
|
||||
else
|
||||
w->setFixedSize(QWIDGETSIZE_MAX, m_itemSize);
|
||||
}
|
||||
}
|
||||
|
||||
QSize AbstractContainer::totalSize() const
|
||||
{
|
||||
QSize size;
|
||||
|
||||
if (m_dockPosition == Dock::Position::Top || m_dockPosition == Dock::Position::Bottom) {
|
||||
|
||||
int itemSize = qBound(PLUGIN_BACKGROUND_MIN_SIZE, parentWidget()->height(), PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
if (itemSize > m_itemSize)
|
||||
itemSize = m_itemSize;
|
||||
|
||||
size.setWidth(
|
||||
(expand() ? (m_wrapperList.size() * std::min(parentWidget()->height(), PLUGIN_BACKGROUND_MAX_SIZE) // 所有托盘图标
|
||||
(expand() ? (m_wrapperList.size() * itemSize // 所有托盘图标
|
||||
+ m_wrapperList.size() * TraySpace) : 0 // 所有托盘图标之间 + 一个尾部的 space
|
||||
) + TraySpace
|
||||
);
|
||||
size.setHeight(height());
|
||||
} else {
|
||||
int itemSize = qBound(PLUGIN_BACKGROUND_MIN_SIZE, parentWidget()->width(), PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
if (itemSize > m_itemSize)
|
||||
itemSize = m_itemSize;
|
||||
|
||||
size.setWidth(width());
|
||||
size.setHeight(
|
||||
(expand() ? (m_wrapperList.size() * std::min(parentWidget()->width(), PLUGIN_BACKGROUND_MAX_SIZE) // 所有托盘图标
|
||||
(expand() ? (m_wrapperList.size() * itemSize // 所有托盘图标
|
||||
+ m_wrapperList.size() * TraySpace) : 0 // 所有托盘图标之间 + 一个尾部的 space
|
||||
) + TraySpace
|
||||
);
|
||||
@ -314,7 +334,6 @@ void AbstractContainer::paintEvent(QPaintEvent *event)
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
QPainter p(this);
|
||||
// p.fillRect(rect(), Qt::red);
|
||||
}
|
||||
|
||||
void AbstractContainer::onWrapperAttentionhChanged(const bool attention)
|
||||
|
@ -24,8 +24,9 @@ public:
|
||||
virtual void setExpand(const bool expand);
|
||||
virtual QSize totalSize() const;
|
||||
virtual int itemCount();
|
||||
// QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
int itemSize() {return m_itemSize;}
|
||||
void setItemSize(int itemSize);
|
||||
void clearWrapper();
|
||||
void saveCurrentOrderToConfig();
|
||||
bool isEmpty();
|
||||
@ -73,6 +74,7 @@ private:
|
||||
Dock::Position m_dockPosition;
|
||||
|
||||
QSize m_wrapperSize;
|
||||
int m_itemSize = 40;
|
||||
};
|
||||
|
||||
#endif // ABSTRACTCONTAINER_H
|
||||
|
@ -8,14 +8,14 @@ NormalContainer::NormalContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
m_sizeAnimation->setEasingCurve(QEasingCurve::InOutCubic);
|
||||
|
||||
connect(m_sizeAnimation, &QVariantAnimation::valueChanged, [ = ](const QVariant & value) {
|
||||
|
||||
if (m_sizeAnimation->state() != QVariantAnimation::Running)
|
||||
return;
|
||||
|
||||
adjustMaxSize(value.toSize());
|
||||
});
|
||||
|
||||
connect(m_sizeAnimation, &QVariantAnimation::finished, [ = ]() {
|
||||
for (auto w : wrapperList()) {
|
||||
w->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
}
|
||||
|
||||
this->setVisible(expand());
|
||||
});
|
||||
|
||||
@ -70,6 +70,13 @@ void NormalContainer::refreshVisible()
|
||||
{
|
||||
AbstractContainer::refreshVisible();
|
||||
|
||||
for (auto w : wrapperList()) {
|
||||
if (dockPosition() == Dock::Top || dockPosition() == Dock::Bottom)
|
||||
w->setFixedSize(itemSize(), QWIDGETSIZE_MAX);
|
||||
else
|
||||
w->setFixedSize(QWIDGETSIZE_MAX, itemSize());
|
||||
}
|
||||
|
||||
if (isEmpty()) {
|
||||
// set the minimum size to 1 to avoid can not drag back wrappers when
|
||||
// all wrappers has been drag out
|
||||
@ -120,7 +127,7 @@ void NormalContainer::adjustMaxSize(const QSize size)
|
||||
|
||||
int NormalContainer::itemCount()
|
||||
{
|
||||
if(expand())
|
||||
if (expand())
|
||||
return AbstractContainer::itemCount();
|
||||
else
|
||||
return 0;
|
||||
@ -128,18 +135,17 @@ int NormalContainer::itemCount()
|
||||
|
||||
void NormalContainer::setExpand(const bool expand)
|
||||
{
|
||||
int itemSize;
|
||||
|
||||
if (dockPosition() == Dock::Position::Top || dockPosition() == Dock::Position::Bottom)
|
||||
itemSize = std::min(parentWidget()->height(), PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
else
|
||||
itemSize = std::min(parentWidget()->width(), PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
|
||||
for (auto w : wrapperList()) {
|
||||
// reset all tray item attention state
|
||||
w->setAttention(false);
|
||||
|
||||
int itemSize;
|
||||
|
||||
if (dockPosition() == Dock::Position::Top || dockPosition() == Dock::Position::Bottom)
|
||||
itemSize = std::min(parentWidget()->height(), PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
else
|
||||
itemSize = std::min(parentWidget()->width(), PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
|
||||
w->setFixedSize(itemSize, itemSize);
|
||||
// w->setFixedSize(itemSize, itemSize);
|
||||
}
|
||||
|
||||
AbstractContainer::setExpand(expand);
|
||||
|
@ -31,7 +31,6 @@ private:
|
||||
|
||||
private:
|
||||
mutable QVariantAnimation *m_sizeAnimation;
|
||||
|
||||
};
|
||||
|
||||
#endif // NORMALCONTAINER_H
|
||||
|
@ -113,7 +113,11 @@ void FashionTrayControlWidget::paintEvent(QPaintEvent *event)
|
||||
DStyleHelper dstyle(style());
|
||||
const int radius = dstyle.pixelMetric(DStyle::PM_FrameRadius);
|
||||
|
||||
path.addRoundedRect(rect(), radius, radius);
|
||||
int minSize = std::min(width(), height());
|
||||
QRect rc(0, 0, minSize, minSize);
|
||||
rc.moveTo(rect().center() - rc.center());
|
||||
|
||||
path.addRoundedRect(rc, radius, radius);
|
||||
painter.fillPath(path, color);
|
||||
}
|
||||
// reset opacity
|
||||
@ -178,23 +182,8 @@ void FashionTrayControlWidget::leaveEvent(QEvent *event)
|
||||
QWidget::leaveEvent(event);
|
||||
}
|
||||
|
||||
QSize FashionTrayControlWidget::sizeHint() const
|
||||
{
|
||||
return QSize(PLUGIN_BACKGROUND_MAX_SIZE, PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
}
|
||||
|
||||
void FashionTrayControlWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
// 保持横纵比
|
||||
if (position == Dock::Bottom || position == Dock::Top) {
|
||||
setMaximumWidth(height());
|
||||
setMaximumHeight(PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
} else {
|
||||
setMaximumWidth(PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
setMaximumHeight(width());
|
||||
}
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ public:
|
||||
|
||||
bool expanded() const;
|
||||
void setExpanded(const bool &expanded);
|
||||
QSize sizeHint() const override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void expandChanged(const bool expanded);
|
||||
|
@ -42,7 +42,7 @@ FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
m_normalContainer(new NormalContainer(m_trayPlugin)),
|
||||
m_attentionContainer(new AttentionContainer(m_trayPlugin)),
|
||||
m_holdContainer(new HoldContainer(m_trayPlugin))
|
||||
, m_leftSpace(new QWidget)
|
||||
, m_leftSpace(new QWidget)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
@ -54,17 +54,14 @@ FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
m_mainBoxLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mainBoxLayout->setSpacing(0);
|
||||
|
||||
m_leftSpace->setFixedSize(TraySpace, TraySpace);
|
||||
m_leftSpace->setFixedSize(TraySpace, TraySpace);
|
||||
|
||||
m_mainBoxLayout->addWidget(m_leftSpace);
|
||||
m_mainBoxLayout->addWidget(m_leftSpace);
|
||||
m_mainBoxLayout->addWidget(m_normalContainer);
|
||||
m_mainBoxLayout->addWidget(m_controlWidget);
|
||||
m_mainBoxLayout->addWidget(m_holdContainer);
|
||||
m_mainBoxLayout->addWidget(m_attentionContainer);
|
||||
|
||||
m_mainBoxLayout->setAlignment(m_controlWidget, Qt::AlignCenter);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
setLayout(m_mainBoxLayout);
|
||||
|
||||
m_attentionDelayTimer->setInterval(3000);
|
||||
@ -149,6 +146,7 @@ void FashionTrayItem::clearTrayWidgets()
|
||||
|
||||
void FashionTrayItem::setDockPosition(Dock::Position pos)
|
||||
{
|
||||
m_dockpos = pos;
|
||||
m_controlWidget->setDockPostion(pos);
|
||||
SystemTrayItem::setDockPostion(pos);
|
||||
SNITrayWidget::setDockPostion(pos);
|
||||
@ -209,6 +207,7 @@ void FashionTrayItem::hideEvent(QHideEvent *event)
|
||||
|
||||
void FashionTrayItem::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
resizeTray();
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
@ -224,11 +223,6 @@ void FashionTrayItem::dragEnterEvent(QDragEnterEvent *event)
|
||||
QWidget::dragEnterEvent(event);
|
||||
}
|
||||
|
||||
//QSize FashionTrayItem::sizeHint() const
|
||||
//{
|
||||
// return wantedTotalSize();
|
||||
//}
|
||||
|
||||
void FashionTrayItem::init()
|
||||
{
|
||||
qDebug() << "init Fashion mode tray plugin item";
|
||||
@ -237,54 +231,6 @@ void FashionTrayItem::init()
|
||||
onExpandChanged(m_controlWidget->expanded());
|
||||
}
|
||||
|
||||
QSize FashionTrayItem::wantedTotalSize() const
|
||||
{
|
||||
QSize size;
|
||||
const Dock::Position dockPosition = m_trayPlugin->dockPosition();
|
||||
|
||||
if (m_controlWidget->expanded()) {
|
||||
if (dockPosition == Dock::Position::Top || dockPosition == Dock::Position::Bottom) {
|
||||
size.setWidth(
|
||||
SpliterSize * 2 // 两个分隔条
|
||||
+ m_controlWidget->sizeHint().width() // 控制按钮
|
||||
+ m_normalContainer->sizeHint().width() // 普通区域
|
||||
+ m_holdContainer->sizeHint().width() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().width() // 活动区域
|
||||
);
|
||||
size.setHeight(height());
|
||||
} else {
|
||||
size.setWidth(width());
|
||||
size.setHeight(
|
||||
SpliterSize * 2 // 两个分隔条
|
||||
+ m_controlWidget->sizeHint().height()// 控制按钮
|
||||
+ m_normalContainer->sizeHint().height() // 普通区域
|
||||
+ m_holdContainer->sizeHint().height() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().height() // 活动区域
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (dockPosition == Dock::Position::Top || dockPosition == Dock::Position::Bottom) {
|
||||
size.setWidth(
|
||||
SpliterSize * 2 // 两个分隔条
|
||||
+ TrayWidgetWidth // 控制按钮
|
||||
+ m_holdContainer->sizeHint().width() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().width() // 活动区域
|
||||
);
|
||||
size.setHeight(height());
|
||||
} else {
|
||||
size.setWidth(width());
|
||||
size.setHeight(
|
||||
SpliterSize * 2 // 两个分隔条
|
||||
+ TrayWidgetWidth // 控制按钮
|
||||
+ m_holdContainer->sizeHint().height() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().height() // 活动区域
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void FashionTrayItem::onWrapperAttentionChanged(FashionTrayWidgetWrapper *wrapper, const bool attention)
|
||||
{
|
||||
if (m_controlWidget->expanded()) {
|
||||
@ -342,6 +288,8 @@ void FashionTrayItem::requestResize()
|
||||
|
||||
int count = m_normalContainer->itemCount() + m_holdContainer->itemCount() + m_attentionContainer->itemCount();
|
||||
setProperty("TrayVisableItemCount", count + 1); // +1 : m_controlWidget
|
||||
|
||||
resizeTray();
|
||||
}
|
||||
|
||||
void FashionTrayItem::refreshHoldContainerPosition()
|
||||
@ -384,3 +332,42 @@ void FashionTrayItem::onRequireDraggingWrapper()
|
||||
|
||||
container->addDraggingWrapper(draggingWrapper);
|
||||
}
|
||||
|
||||
bool FashionTrayItem::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::DynamicPropertyChange) {
|
||||
const QString &propertyName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
|
||||
if (propertyName == "iconSize") {
|
||||
m_iconSize = property("iconSize").toInt();
|
||||
m_normalContainer->setItemSize(m_iconSize);
|
||||
|
||||
resizeTray();
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void FashionTrayItem::resizeTray()
|
||||
{
|
||||
if (!m_iconSize)
|
||||
return;
|
||||
|
||||
if (m_dockpos == Dock::Position::Top || m_dockpos == Dock::Position::Bottom) {
|
||||
m_holdContainer->setFixedWidth((m_iconSize + TraySpace) * m_holdContainer->itemCount() + TraySpace);
|
||||
m_holdContainer->setFixedHeight(QWIDGETSIZE_MAX);
|
||||
|
||||
m_attentionContainer->setFixedWidth((m_iconSize + TraySpace) * m_attentionContainer->itemCount() + m_attentionContainer->itemCount() ? TraySpace : 0);
|
||||
m_attentionContainer->setFixedHeight(QWIDGETSIZE_MAX);
|
||||
|
||||
m_controlWidget->setFixedSize(m_iconSize, QWIDGETSIZE_MAX);
|
||||
} else {
|
||||
m_holdContainer->setFixedWidth(QWIDGETSIZE_MAX);
|
||||
m_holdContainer->setFixedHeight((m_iconSize + TraySpace) * m_holdContainer->itemCount() + TraySpace);
|
||||
|
||||
m_attentionContainer->setFixedWidth(QWIDGETSIZE_MAX);
|
||||
m_attentionContainer->setFixedHeight((m_iconSize + TraySpace) * m_attentionContainer->itemCount() + m_attentionContainer->itemCount() ? TraySpace : 0);
|
||||
|
||||
m_controlWidget->setFixedSize(QWIDGETSIZE_MAX, m_iconSize);
|
||||
}
|
||||
}
|
||||
|
@ -66,11 +66,11 @@ protected:
|
||||
void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
|
||||
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
|
||||
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
|
||||
// QSize sizeHit() const Q_DECL_OVERRIDE;
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
QSize wantedTotalSize() const;
|
||||
void resizeTray();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onWrapperAttentionChanged(FashionTrayWidgetWrapper *wrapper, const bool attention);
|
||||
@ -94,7 +94,9 @@ private:
|
||||
|
||||
static int TrayWidgetWidth;
|
||||
static int TrayWidgetHeight;
|
||||
QWidget *m_leftSpace;
|
||||
QWidget *m_leftSpace;
|
||||
Dock::Position m_dockpos;
|
||||
int m_iconSize = 40;
|
||||
};
|
||||
|
||||
#endif // FASHIONTRAYITEM_H
|
||||
|
@ -191,11 +191,6 @@ void FashionTrayWidgetWrapper::leaveEvent(QEvent *event)
|
||||
QWidget::leaveEvent(event);
|
||||
}
|
||||
|
||||
QSize FashionTrayWidgetWrapper::sizeHint() const
|
||||
{
|
||||
return QSize(PLUGIN_BACKGROUND_MAX_SIZE, PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
}
|
||||
|
||||
void FashionTrayWidgetWrapper::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
|
@ -40,7 +40,6 @@ public:
|
||||
|
||||
bool attention() const;
|
||||
void setAttention(bool attention);
|
||||
QSize sizeHint() const override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void attentionChanged(const bool attention);
|
||||
|
@ -87,14 +87,6 @@ void IndicatorTrayWidget::sendClick(uint8_t buttonIndex, int x, int y)
|
||||
Q_EMIT clicked(buttonIndex, x, y);
|
||||
}
|
||||
|
||||
QSize IndicatorTrayWidget::sizeHint() const
|
||||
{
|
||||
auto sz = AbstractTrayWidget::sizeHint();
|
||||
sz.setHeight(26);
|
||||
sz.setWidth(26);
|
||||
return sz;
|
||||
}
|
||||
|
||||
void IndicatorTrayWidget::setPixmapData(const QByteArray &data)
|
||||
{
|
||||
auto rawPixmap = QPixmap::fromImage(QImage::fromData(data));
|
||||
|
@ -38,9 +38,6 @@ public:
|
||||
void updateIcon() Q_DECL_OVERRIDE;
|
||||
const QImage trayImage() Q_DECL_OVERRIDE;
|
||||
void sendClick(uint8_t, int, int) Q_DECL_OVERRIDE;
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
static QString toIndicatorKey(const QString &indicatorName) { return QString("indicator:%1").arg(indicatorName); }
|
||||
static bool isIndicatorKey(const QString &itemKey) { return itemKey.startsWith("indicator:"); }
|
||||
|
||||
|
@ -434,11 +434,6 @@ void SNITrayWidget::onSNIStatusChanged(const QString &status)
|
||||
Q_EMIT statusChanged(static_cast<SNITrayWidget::ItemStatus>(ItemStatusList.indexOf(status)));
|
||||
}
|
||||
|
||||
QSize SNITrayWidget::sizeHint() const
|
||||
{
|
||||
return QSize(26, 26);
|
||||
}
|
||||
|
||||
void SNITrayWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
@ -448,9 +443,6 @@ void SNITrayWidget::paintEvent(QPaintEvent *e)
|
||||
QPainter painter;
|
||||
painter.begin(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
#ifdef QT_DEBUG
|
||||
// painter.fillRect(rect(), Qt::red);
|
||||
#endif
|
||||
|
||||
const QRectF &rf = QRect(rect());
|
||||
const QRectF &rfp = QRect(m_pixmap.rect());
|
||||
|
@ -102,7 +102,6 @@ private Q_SLOTS:
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
|
||||
QPixmap newIconPixmap(IconType iconType);
|
||||
|
||||
|
@ -113,11 +113,6 @@ const QImage XEmbedTrayWidget::trayImage()
|
||||
return m_image;
|
||||
}
|
||||
|
||||
QSize XEmbedTrayWidget::sizeHint() const
|
||||
{
|
||||
return QSize(PLUGIN_BACKGROUND_MAX_SIZE, PLUGIN_BACKGROUND_MAX_SIZE);
|
||||
}
|
||||
|
||||
void XEmbedTrayWidget::showEvent(QShowEvent *e)
|
||||
{
|
||||
QWidget::showEvent(e);
|
||||
@ -134,9 +129,6 @@ void XEmbedTrayWidget::paintEvent(QPaintEvent *e)
|
||||
QPainter painter;
|
||||
painter.begin(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
#ifdef QT_DEBUG
|
||||
// painter.fillRect(rect(), Qt::red);
|
||||
#endif
|
||||
|
||||
const QRectF &rf = QRectF(rect());
|
||||
const QRectF &rfp = QRectF(m_image.rect());
|
||||
|
@ -46,7 +46,6 @@ public:
|
||||
static bool isXEmbedKey(const QString &itemKey);
|
||||
|
||||
private:
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
void showEvent(QShowEvent *e) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
||||
@ -54,7 +53,6 @@ private:
|
||||
|
||||
void wrapWindow();
|
||||
void sendHoverEvent();
|
||||
// void hideIcon();
|
||||
void refershIconImage();
|
||||
|
||||
static QString getAppNameForWindow(quint32 winId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user