dde-dock/frame/window/components/slidercontainer.h
donghualin 3824e9d9bb fix: 修复快捷设置面板的图标在高缩放率下显示模糊
带背景的圆底图标不再通过自动创建,因为无法控制周边的锯齿,统一在paintEvent函数中进行绘制。修改滑动条统一通过代理来进行绘制

Log:
Influence: 屏幕设置高缩放率,任务栏特效模式下,查看快捷面板图标是否正常显示
Bug: https://pms.uniontech.com/task-view-149623.html
Change-Id: I825e38a9ae8c5a4252be840193e44393ac129201
2022-06-20 13:41:10 +08:00

111 lines
3.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
*
* Author: donghualin <donghualin@uniontech.com>
*
* Maintainer: donghualin <donghualin@uniontech.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 SLIDERCONTAINER_H
#define SLIDERCONTAINER_H
#include <DSlider>
#include <QProxyStyle>
#include <QTimer>
class QLabel;
class SliderProxyStyle;
class SliderIconWidget;
/**
* @brief 滚动条的类的封装封装这个类的原因是为了方便设置左右图标dtk中的对应的DSlider类也有这个功能
* 但是只能简单的设置左右图标,对于右边图标有阴影的,需要外部提供一个带阴影图标,但是如果由外部来提供,
* 通过QPixmap绘制的带阴影的图标无法消除锯齿即使通过反走样也不行因此在此处封装这个类
*/
class SliderContainer : public QWidget
{
Q_OBJECT
public:
enum IconPosition {
LeftIcon = 0,
RightIcon
};
struct SliderData {
QSize iconSize; // 图标尺寸
QSize shadowSize; // 阴影尺寸
QIcon icon; // 图标
int space; // 间距
};
public:
explicit SliderContainer(QWidget *parent);
~SliderContainer() override;
void setTitle(const QString &text);
void updateSlider(const IconPosition &iconPosition, const SliderData &sliderData);
void setIcon(const IconPosition &iconPosition, const QIcon &icon);
QSlider *slider();
Q_SIGNALS:
void iconClicked(const IconPosition &);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
QSize getSuitableSize(const QSize &iconSize, const QSize &bgSize);
private:
SliderIconWidget *m_leftIconWidget;
QSlider *m_slider;
QLabel *m_titleLabel;
SliderIconWidget *m_rightIconWidget;
QWidget *m_spaceLeftWidget;
QWidget *m_spaceRightWidget;
};
/**
* @brief 用来设置滚动条的样式
* @param drawSpecial: true
*/
class SliderProxyStyle : public QProxyStyle
{
Q_OBJECT
public:
enum StyleType {
RoundHandler = 0, // 绘制那种黑色圆底滑动条
Normal // 绘制那种通用的滑动条
};
public:
explicit SliderProxyStyle(StyleType drawSpecial = RoundHandler, QStyle *style = nullptr);
~SliderProxyStyle() override;
protected:
void drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = nullptr) const override;
private:
void drawNormalSlider(QPainter *painter, QRect rectGroove, QRect rectHandle, QWidget *wigdet) const;
void drawRoundSlider(QPainter *painter, QRect rectGroove, QRect rectHandle) const;
private:
StyleType m_drawSpecial;
};
#endif // VOLUMESLIDER_H