mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-26 21:37:04 +08:00
update
This commit is contained in:
parent
99ff310448
commit
42f0987e73
@ -98,6 +98,20 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
||||
}
|
||||
return false;
|
||||
}else if(uMsg == WM_NCCALCSIZE){
|
||||
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
|
||||
const LONG originalTop = clientRect->top;
|
||||
const LONG originalLeft = clientRect->left;
|
||||
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
|
||||
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
|
||||
*result = hitTestResult;
|
||||
return true;
|
||||
}
|
||||
if(IsZoomed(hwnd)){
|
||||
_helper->setOriginalPos(QPoint(originalLeft,originalTop));
|
||||
}else{
|
||||
_helper->setOriginalPos({});
|
||||
}
|
||||
clientRect->top = originalTop;
|
||||
*result = WVR_REDRAW;
|
||||
return true;
|
||||
}else if(uMsg == WM_NCPAINT){
|
||||
@ -243,7 +257,7 @@ void FluFramelessHelper::componentComplete(){
|
||||
}
|
||||
if(!window.isNull()){
|
||||
#ifdef Q_OS_WIN
|
||||
window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
|
||||
// window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
|
||||
_nativeEvent =new FramelessEventFilter(this);
|
||||
qApp->installNativeEventFilter(_nativeEvent);
|
||||
HWND hwnd = reinterpret_cast<HWND>(window->winId());
|
||||
@ -254,12 +268,12 @@ void FluFramelessHelper::componentComplete(){
|
||||
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);
|
||||
}
|
||||
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
||||
showShadow(hwnd);
|
||||
#else
|
||||
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
||||
#endif
|
||||
_stayTop = QQmlProperty(window,"stayTop");
|
||||
_screen = QQmlProperty(window,"screen");
|
||||
_originalPos = QQmlProperty(window,"_originalPos");
|
||||
_onStayTopChange();
|
||||
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
|
||||
_screen.connectNotifySignal(this,SLOT(_onScreenChanged()));
|
||||
@ -353,6 +367,10 @@ QObject* FluFramelessHelper::maximizeButton(){
|
||||
return var.value<QObject*>();
|
||||
}
|
||||
|
||||
void FluFramelessHelper::setOriginalPos(QVariant pos){
|
||||
_originalPos.write(pos);
|
||||
}
|
||||
|
||||
bool FluFramelessHelper::resizeable(){
|
||||
return !(window->width() == window->maximumWidth() && window->width() == window->minimumWidth() && window->height() == window->maximumHeight() && window->height() == window->minimumHeight());
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
bool hoverMaxBtn();
|
||||
bool resizeable();
|
||||
QObject* maximizeButton();
|
||||
void setOriginalPos(QVariant pos);
|
||||
Q_INVOKABLE void showSystemMenu();
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
@ -54,6 +55,7 @@ private:
|
||||
FramelessEventFilter* _nativeEvent = nullptr;
|
||||
QQmlProperty _stayTop;
|
||||
QQmlProperty _screen;
|
||||
QQmlProperty _originalPos;
|
||||
};
|
||||
|
||||
#endif // FLUFRAMELESSHELPER_H
|
||||
|
@ -54,6 +54,7 @@ Window {
|
||||
signal initArgument(var argument)
|
||||
signal firstVisible()
|
||||
property point _offsetXY : Qt.point(0,0)
|
||||
property var _originalPos
|
||||
id:window
|
||||
color:"transparent"
|
||||
Component.onCompleted: {
|
||||
@ -73,12 +74,12 @@ Window {
|
||||
Component.onDestruction: {
|
||||
lifecycle.onDestruction()
|
||||
}
|
||||
onVisibilityChanged: {
|
||||
if(visibility === Window.Maximized || visibility === Window.FullScreen){
|
||||
var dx = window.x-Screen.virtualX
|
||||
var dy = window.y-Screen.virtualY
|
||||
on_OriginalPosChanged: {
|
||||
if(_originalPos){
|
||||
var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio
|
||||
var dy = _originalPos.y - screen.virtualY/screen.devicePixelRatio
|
||||
if(dx<0 && dy<0){
|
||||
_offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1))
|
||||
_offsetXY = Qt.point(Math.abs(dx),Math.abs(dy))
|
||||
}else{
|
||||
_offsetXY = Qt.point(0,0)
|
||||
}
|
||||
@ -191,10 +192,7 @@ Window {
|
||||
id:layout_container
|
||||
anchors{
|
||||
fill:parent
|
||||
leftMargin: _offsetXY.x
|
||||
rightMargin: _offsetXY.x
|
||||
topMargin: _offsetXY.y
|
||||
bottomMargin: _offsetXY.y
|
||||
topMargin: _offsetXY.x
|
||||
}
|
||||
onWidthChanged: {
|
||||
window.appBar.width = width
|
||||
|
@ -53,6 +53,7 @@ Window {
|
||||
signal initArgument(var argument)
|
||||
signal firstVisible()
|
||||
property point _offsetXY : Qt.point(0,0)
|
||||
property var _originalPos
|
||||
id:window
|
||||
color:"transparent"
|
||||
Component.onCompleted: {
|
||||
@ -72,12 +73,12 @@ Window {
|
||||
Component.onDestruction: {
|
||||
lifecycle.onDestruction()
|
||||
}
|
||||
onVisibilityChanged: {
|
||||
if(visibility === Window.Maximized || visibility === Window.FullScreen){
|
||||
var dx = window.x-Screen.virtualX
|
||||
var dy = window.y-Screen.virtualY
|
||||
on_OriginalPosChanged: {
|
||||
if(_originalPos){
|
||||
var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio
|
||||
var dy = _originalPos.y - screen.virtualY/screen.devicePixelRatio
|
||||
if(dx<0 && dy<0){
|
||||
_offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1))
|
||||
_offsetXY = Qt.point(Math.abs(dx),Math.abs(dy))
|
||||
}else{
|
||||
_offsetXY = Qt.point(0,0)
|
||||
}
|
||||
@ -190,10 +191,7 @@ Window {
|
||||
id:layout_container
|
||||
anchors{
|
||||
fill:parent
|
||||
leftMargin: _offsetXY.x
|
||||
rightMargin: _offsetXY.x
|
||||
topMargin: _offsetXY.y
|
||||
bottomMargin: _offsetXY.y
|
||||
topMargin: _offsetXY.x
|
||||
}
|
||||
onWidthChanged: {
|
||||
window.appBar.width = width
|
||||
|
Loading…
Reference in New Issue
Block a user