no message
parent
624f78dc17
commit
b65863da66
33
Qss.cpp
33
Qss.cpp
|
@ -28,6 +28,20 @@
|
||||||
#define QSSDIALOG_SHADOW_WIDTH 12
|
#define QSSDIALOG_SHADOW_WIDTH 12
|
||||||
#define QSSDIALOG_BODER_WIDTH 0
|
#define QSSDIALOG_BODER_WIDTH 0
|
||||||
|
|
||||||
|
static void rangeObjectList(QObject*obj,int indent){
|
||||||
|
QObjectList child = obj->children();
|
||||||
|
QString tmp("");
|
||||||
|
for(int i = 0;i < indent;i++)
|
||||||
|
tmp +=" ";
|
||||||
|
|
||||||
|
for(int i = 0;i < child.size();i++){
|
||||||
|
qDebug()<<tmp + child.at(i)->objectName() + " " + child.at(i)->metaObject()->className();
|
||||||
|
if(child.at(i)->children().size() > 0){
|
||||||
|
rangeObjectList(child.at(i),indent + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QssTtitleBar::QssTtitleBar(QWidget *parent ,
|
QssTtitleBar::QssTtitleBar(QWidget *parent ,
|
||||||
QTitleBar_Type type/* = QTitleBar_Type_Window*/)
|
QTitleBar_Type type/* = QTitleBar_Type_Window*/)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
|
@ -159,8 +173,8 @@ void QssTtitleBar::mouseMoveEvent( QMouseEvent * ev )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPoint globalPt = ev->globalPos();
|
QPoint globalPt = ev->globalPos();
|
||||||
QPoint movePt = globalPt - m_pressedPos;//FrameglobalPos
|
QPoint movePt = globalPt - m_pressedPos;
|
||||||
parentWidget()->move(movePt);//globalPos
|
parentWidget()->move(movePt);
|
||||||
QssMainWindow *parent = static_cast<QssMainWindow*>(parentWidget());
|
QssMainWindow *parent = static_cast<QssMainWindow*>(parentWidget());
|
||||||
if(nullptr != parent){
|
if(nullptr != parent){
|
||||||
parent->DetectDpiChange();
|
parent->DetectDpiChange();
|
||||||
|
@ -256,7 +270,8 @@ void QssMainWindow::DpiChange(qreal dpi)
|
||||||
QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* = 0*/,float scale)
|
QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* = 0*/,float scale)
|
||||||
: QMainWindow(parent, flags),
|
: QMainWindow(parent, flags),
|
||||||
m_mousePressedInBoundy(false),
|
m_mousePressedInBoundy(false),
|
||||||
m_bLeftPress(false)
|
m_bLeftPress(false),
|
||||||
|
m_dpi_ratio(1.0)
|
||||||
{
|
{
|
||||||
QEvent::registerEventType();
|
QEvent::registerEventType();
|
||||||
m_rcValid = QApplication::desktop()->availableGeometry();
|
m_rcValid = QApplication::desktop()->availableGeometry();
|
||||||
|
@ -298,13 +313,13 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
|
||||||
mShadowMask->hide();
|
mShadowMask->hide();
|
||||||
|
|
||||||
int screenNum = qApp->desktop()->screenNumber(this);
|
int screenNum = qApp->desktop()->screenNumber(this);
|
||||||
qDebug()<<"current screen number is "<<screenNum;
|
|
||||||
mCurrentScreen = qApp->screens().at(screenNum);
|
mCurrentScreen = qApp->screens().at(screenNum);
|
||||||
if(nullptr != mCurrentScreen){
|
if(nullptr != mCurrentScreen){
|
||||||
connect(mCurrentScreen,
|
connect(mCurrentScreen,
|
||||||
SIGNAL(physicalDotsPerInchChanged(qreal)),
|
SIGNAL(physicalDotsPerInchChanged(qreal)),
|
||||||
this,SLOT(DpiChange(qreal)));
|
this,SLOT(DpiChange(qreal)));
|
||||||
}
|
}
|
||||||
|
rangeObjectList(this,0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,6 +569,13 @@ void QssMainWindow::onMouseReleaseEvent( QMouseEvent * ev )
|
||||||
m_mousePressedInBoundy = false;
|
m_mousePressedInBoundy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void QssMainWindow::dpiScaleChildren()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void QssMainWindow::showEvent(QShowEvent *ev)
|
void QssMainWindow::showEvent(QShowEvent *ev)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -691,7 +713,7 @@ QssDialog::QssDialog(QWidget *parent)
|
||||||
m_frame = new QFrame(parent);
|
m_frame = new QFrame(parent);
|
||||||
m_frame->setObjectName("dialog");//css
|
m_frame->setObjectName("dialog");//css
|
||||||
m_frame->setAttribute(Qt::WA_TranslucentBackground);
|
m_frame->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
m_frame->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint| Qt::WindowSystemMenuHint/* | Qt::WindowMinimizeButtonHint*/);//Qt::WindowMinimizeButtonHintdialog<EFBFBD><EFBFBD>
|
m_frame->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint| Qt::WindowSystemMenuHint/* | Qt::WindowMinimizeButtonHint*/);//Qt::WindowMinimizeButtonHintdialog
|
||||||
m_frame->setMouseTracking(true);
|
m_frame->setMouseTracking(true);
|
||||||
m_frame->installEventFilter(this);
|
m_frame->installEventFilter(this);
|
||||||
|
|
||||||
|
@ -709,7 +731,6 @@ QssDialog::QssDialog(QWidget *parent)
|
||||||
mShadowMask = new QWidget(this);
|
mShadowMask = new QWidget(this);
|
||||||
mShadowMask->setStyleSheet("QWidget{background-color:rgba(1,1,1,0.3);}");
|
mShadowMask->setStyleSheet("QWidget{background-color:rgba(1,1,1,0.3);}");
|
||||||
mShadowMask->hide();
|
mShadowMask->hide();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QssDialog::~QssDialog()
|
QssDialog::~QssDialog()
|
||||||
|
|
96
Qss.h
96
Qss.h
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "ui_qsstoast.h"
|
#include "ui_qsstoast.h"
|
||||||
#include "ui_process.h"
|
#include "ui_process.h"
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
@ -31,92 +32,7 @@ class QMouseEvent;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef enum{
|
|
||||||
RA_Resize = 1,
|
|
||||||
RA_FixedWidth = 2,
|
|
||||||
RA_FixedHeight = 4,
|
|
||||||
RA_FixedSize = 8,
|
|
||||||
RA_MinimumSize = 16,
|
|
||||||
RA_MinimumHeight = 32,
|
|
||||||
RA_MinimumWidth = 64,
|
|
||||||
RA_MaximumSize = 128,
|
|
||||||
RA_MaximumHeight = 256,
|
|
||||||
RA_MaximumWidth = 512
|
|
||||||
}ReiszeActions ;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_RESIZE() \
|
|
||||||
void resize(int w, int h);void resize(const QSize &); void setFixedHeight(int w); \
|
|
||||||
void setFixedWidth(int w);void setFixedSize(int w, int h);void setFixedSize(const QSize &s); \
|
|
||||||
void setMinimumSize(const QSize &);void setMinimumSize(int minw, int minh); \
|
|
||||||
void setMinimumHeight(int minh);void setMinimumWidth(int minw); \
|
|
||||||
void setMaximumSize(const QSize &);void setMaximumSize(int maxw, int maxh); \
|
|
||||||
void setMaximumHeight(int minh);void setMaximumWidth(int minw);
|
|
||||||
|
|
||||||
// 用宏强制覆盖的方法不使用了,因为QSSMainWindow本身已经在event事件内做处理,每个event都重写了,无需再去覆盖。
|
|
||||||
#define DEFINE_RESIZE(name)\
|
|
||||||
void Qss##name::resize(int w, int h){ m_sizeActions |= RA_Resize; float scale = cale; m_size = QSize(w, h);Q##name::resize(m_size.width() * scale, m_size.height() * scale);}\
|
|
||||||
void Qss##name::resize(const QSize & size){ m_sizeActions |= RA_Resize; float scale = cale;m_size = size;Q##name::resize(m_size * scale);}\
|
|
||||||
void Qss##name::setFixedHeight(int h){m_sizeActions |= RA_FixedHeight;float scale = cale;m_size.setHeight(h);Q##name::setFixedHeight(m_size.height() * scale);}\
|
|
||||||
void Qss##name::setFixedWidth(int w){m_sizeActions |= RA_FixedWidth;float scale = cale;m_size.setWidth(w);Q##name::setFixedWidth(m_size.width() * scale);}\
|
|
||||||
void Qss##name::setFixedSize(int w, int h){m_sizeActions |= RA_FixedSize;float scale = cale; m_size = QSize(w, h); this->m_frame->setFixedSize(m_size.width() * scale, m_size.height() * scale) ; }\
|
|
||||||
void Qss##name::setFixedSize(const QSize & size){m_sizeActions |= RA_FixedSize;float scale = cale; m_size = size; Q##name::setFixedSize(m_size * scale);}\
|
|
||||||
void Qss##name::setMinimumSize(const QSize & size){m_sizeActions |= RA_MinimumSize;float scale = cale;m_minimumSize = size; Q##name::setMinimumSize(m_minimumSize * scale);}\
|
|
||||||
void Qss##name::setMinimumSize(int w, int h){m_sizeActions |= RA_MinimumSize;float scale = cale; m_minimumSize = QSize(w, h); Q##name::setMinimumSize(m_minimumSize.width() * scale, m_minimumSize.height() * scale);}\
|
|
||||||
void Qss##name::setMinimumHeight(int h){m_sizeActions |= RA_MinimumHeight;float scale = cale;m_minimumSize.setHeight(h); Q##name::setMinimumHeight(m_minimumSize.height() * scale);}\
|
|
||||||
void Qss##name::setMinimumWidth(int w){m_sizeActions |= RA_MinimumWidth;float scale = cale; m_minimumSize.setWidth(w); Q##name::setMinimumWidth(m_minimumSize.width() * scale);}\
|
|
||||||
void Qss##name::setMaximumSize(const QSize & size){m_sizeActions |= RA_MaximumSize;float scale = cale; m_maximumSize = size; Q##name::setMaximumSize(m_maximumSize * scale);}\
|
|
||||||
void Qss##name::setMaximumSize(int w, int h){m_sizeActions |= RA_MaximumSize;float scale = cale; m_maximumSize = QSize(w, h); Q##name::setMaximumSize(m_maximumSize.width() * scale, m_maximumSize.height() * scale);}\
|
|
||||||
void Qss##name::setMaximumHeight(int h){m_sizeActions |= RA_MaximumHeight;float scale = cale; m_maximumSize.setHeight(h); Q##name::setMaximumHeight(m_maximumSize.height() * scale);}\
|
|
||||||
void Qss##name::setMaximumWidth(int w){m_sizeActions |= RA_MaximumWidth;float scale = cale; m_maximumSize.setWidth(w); Q##name::setMaximumWidth(m_maximumSize.width() * scale);}
|
|
||||||
|
|
||||||
#define DEFINTE_SCALE_RESIZE(name)\
|
|
||||||
if (m_sizeActions.testFlag(RA_FixedWidth)){Qss##name::setFixedWidth(m_size.width() * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_FixedHeight)){Qss##name::setFixedHeight(m_size.height() * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_FixedSize)){Qss##name::setFixedSize(m_size * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_Resize)){ QSize newSize = m_size * scale;if(minimumSize().width() > newSize.width()){name::setMinimumSize(newSize);}name::resize(newSize);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_MinimumSize)){Qss##name::setMinimumSize(m_minimumSize * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_MinimumHeight)){Qss##name::setMinimumHeight(m_minimumSize.height() * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_MinimumWidth)){Qss##name::setMinimumWidth(m_minimumSize.width() * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_MaximumSize)){Qss##name::setMaximumSize(m_maximumSize * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_MaximumHeight)){Qss##name::setMaximumHeight(m_maximumSize.height() * scale);}\
|
|
||||||
if (m_sizeActions.testFlag(RA_MaximumWidth)){ Qss##name::setMaximumWidth(m_maximumSize.width() * scale); }\
|
|
||||||
cale = scale;
|
|
||||||
|
|
||||||
typedef class ICallDPIChanged
|
|
||||||
{
|
|
||||||
virtual void ScaleChanged(float scale) = 0;
|
|
||||||
virtual WId GetWID() const = 0;
|
|
||||||
virtual void SetScale(float scale) = 0;
|
|
||||||
protected:
|
|
||||||
uint32_t m_sizeActions;
|
|
||||||
float cale = 1;
|
|
||||||
QSize m_size;
|
|
||||||
QSize m_minimumSize;
|
|
||||||
QSize m_maximumSize;
|
|
||||||
}QssCallDpiChanged;
|
|
||||||
|
|
||||||
typedef class IDPIHelper
|
|
||||||
{
|
|
||||||
virtual bool DPIChanged(unsigned short, WId) = 0;
|
|
||||||
virtual void RemoveDPIRecord(WId) = 0;//移除指定native窗体的DPI记录 一般用于native窗体析构时
|
|
||||||
virtual float GetDPIScale(WId) const = 0;
|
|
||||||
virtual float GetOldDPIScale(WId) const = 0;
|
|
||||||
virtual QString GetStyleSheet(WId) const = 0;//获取指定DPI下的样式表
|
|
||||||
virtual float GetScaleNumber(float, WId) const = 0;//获取指定DPI下的数值 缩放后数值
|
|
||||||
virtual QList<WId> GetAllWindowID() const = 0;//获取所有自己加载过皮肤的窗口ID
|
|
||||||
|
|
||||||
//优化接口 主要是为了适配用户主机只有一种DPI时使用
|
|
||||||
virtual bool IsOnlyOneDPI() const = 0;//获取用户主机是否只有一种DPI
|
|
||||||
virtual void RefrushDPIRecords() = 0;//显示器数量发生了变化 刷新历史显示器DPI记录
|
|
||||||
virtual void SetDefaultScale(float scale) = 0;//设置缺省DPI值 当显示器dpi只有一种时刷新
|
|
||||||
virtual float GetDefaultScale() const = 0;//获取缺省DPI缩放值 只有当机器上所有的显示器为统一dpi时起作用
|
|
||||||
}QssDpiHelper;
|
|
||||||
|
|
||||||
IDPIHelper * GetDPIHelper();
|
|
||||||
#define DPIHelper() GetDPIHelper()
|
|
||||||
class QssPushButton : public QPushButton{
|
class QssPushButton : public QPushButton{
|
||||||
public:
|
public:
|
||||||
QssPushButton(QWidget *parent,QString objName);
|
QssPushButton(QWidget *parent,QString objName);
|
||||||
|
@ -209,12 +125,13 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class QssMainWindow : public QMainWindow,ICallDPIChanged
|
class QssMainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnMaxOrRestore(bool max);
|
void OnMaxOrRestore(bool max);
|
||||||
|
void DpiChange(qreal);
|
||||||
public:
|
public:
|
||||||
typedef enum{
|
typedef enum{
|
||||||
EVENT_MOVE = 523,
|
EVENT_MOVE = 523,
|
||||||
|
@ -223,6 +140,7 @@ public:
|
||||||
virtual ~QssMainWindow();
|
virtual ~QssMainWindow();
|
||||||
|
|
||||||
QWidget *TitleBar();
|
QWidget *TitleBar();
|
||||||
|
void DetectDpiChange();
|
||||||
void ShowMask();
|
void ShowMask();
|
||||||
void HideMask();
|
void HideMask();
|
||||||
void show();
|
void show();
|
||||||
|
@ -239,16 +157,15 @@ public:
|
||||||
inline QFrame* frame(){return m_frame;}
|
inline QFrame* frame(){return m_frame;}
|
||||||
int CalCursorCol(QPoint pt); //计算鼠标X的位置
|
int CalCursorCol(QPoint pt); //计算鼠标X的位置
|
||||||
virtual bool eventFilter(QObject * obj, QEvent * ev);
|
virtual bool eventFilter(QObject * obj, QEvent * ev);
|
||||||
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onMouseMoveEvent(QMouseEvent * ev);
|
void onMouseMoveEvent(QMouseEvent * ev);
|
||||||
void onMousePressEvent(QMouseEvent * ev);
|
void onMousePressEvent(QMouseEvent * ev);
|
||||||
void onMouseReleaseEvent(QMouseEvent * ev);
|
void onMouseReleaseEvent(QMouseEvent * ev);
|
||||||
|
void dpiScaleChildren();
|
||||||
protected:
|
protected:
|
||||||
QFrame* m_frame;
|
QFrame* m_frame;
|
||||||
QRect mFrameRect;
|
QRect mFrameRect;
|
||||||
QRect mRect;
|
|
||||||
QRect m_CentralRect;
|
QRect m_CentralRect;
|
||||||
QssTtitleBar* m_titleBar;
|
QssTtitleBar* m_titleBar;
|
||||||
void showEvent(QShowEvent *ev);
|
void showEvent(QShowEvent *ev);
|
||||||
|
@ -271,8 +188,9 @@ private:
|
||||||
bool m_bLeftPress;
|
bool m_bLeftPress;
|
||||||
QRect m_rtPreGeometry;
|
QRect m_rtPreGeometry;
|
||||||
QPoint m_ptViewMousePos;
|
QPoint m_ptViewMousePos;
|
||||||
float m_scale;
|
float m_dpi_ratio;
|
||||||
QWidget *mShadowMask;
|
QWidget *mShadowMask;
|
||||||
|
QScreen *mCurrentScreen;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue