dde-dock/frame/window/tray/tray_delegate.h
donghualin 1172b54b9f fix: 修复托盘区域调整尺寸的时候托盘图标不居中的问题
修改delegate类的sizeHint方法的返回值,在主窗体尺寸发生变化的时候,发送delegate的sizeHintChanged信号来保证sizeHint方法能实时调用

Log:
Influence: 任务栏上下调整尺寸的时候观察托盘图标的位置变化
Task: https://pms.uniontech.com/task-view-110311.html
Change-Id: I86b6bdc0fb991ff0a2674b0fa799add4b536a6bf
2022-05-25 09:46:10 +08:00

70 lines
2.2 KiB
C++

/*
* Copyright (C) 2018 ~ 2025 Deepin Technology Co., Ltd.
*
* Author: fanpengcheng <fanpengcheng_cm@deepin.com>
*
* Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRAYDELEGATE_H
#define TRAYDELEGATE_H
#include "constants.h"
#include <QStyledItemDelegate>
#define ITEM_SIZE 30
// 托盘图标固定16个像素
#define ICON_SIZE 16
#define ITEM_SPACING 5
struct WinInfo;
class ExpandIconWidget;
class QListView;
class TrayDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit TrayDelegate(QListView *view, QObject *parent = nullptr);
void setPositon(Dock::Position position);
Q_SIGNALS:
void removeRow(const QModelIndex &) const;
void visibleChanged(const QModelIndex &, bool) const;
void requestDrag(bool) const;
private Q_SLOTS:
void onRequestDrag(bool on);
protected:
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setEditorData(QWidget *editor, const QModelIndex &index) const override ;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private:
ExpandIconWidget *expandWidget();
bool isPopupTray() const;
private:
Dock::Position m_position;
QListView *m_listView;
};
#endif // TRAYDELEGATE_H