This commit is contained in:
zhuzichu 2023-12-28 12:42:22 +08:00
parent 2cfc73c00b
commit 9adb6b645b
10 changed files with 41 additions and 49 deletions

View File

@ -113,6 +113,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
QGuiApplication::sendEvent(_helper->maximizeButton(),&event); QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
} }
return false; return false;
}else if(uMsg == WM_GETMINMAXINFO){
if(IsZoomed(hwnd)){
RECT frame = {0,0,0,0};
AdjustWindowRectEx(&frame,WS_OVERLAPPEDWINDOW,FALSE,0);
_helper->setOffsetXY(QPoint(floor(abs(frame.left)/_helper->window->devicePixelRatio()),floor(abs(frame.bottom)/_helper->window->devicePixelRatio())));
}else{
_helper->setOffsetXY(QPoint(0,0));
}
} }
return false; return false;
#endif #endif
@ -222,18 +230,26 @@ void FluFramelessHelper::componentComplete(){
o = o->parent(); o = o->parent();
} }
if(!window.isNull()){ if(!window.isNull()){
window->setFlags(Qt::FramelessWindowHint|Qt::Window|Qt::WindowTitleHint|Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
_nativeEvent =new FramelessEventFilter(this); _nativeEvent =new FramelessEventFilter(this);
qApp->installNativeEventFilter(_nativeEvent); qApp->installNativeEventFilter(_nativeEvent);
HWND hwnd = reinterpret_cast<HWND>(window->winId()); HWND hwnd = reinterpret_cast<HWND>(window->winId());
SetWindowPos(hwnd,0,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER); DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
if(resizeable()){
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
}else{
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);
}
showShadow(hwnd); showShadow(hwnd);
#else
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
#endif #endif
_stayTop = QQmlProperty(window,"stayTop"); _stayTop = QQmlProperty(window,"stayTop");
_screen = QQmlProperty(window,"screen");
_offsetXY = QQmlProperty(window,"_offsetXY");
_onStayTopChange(); _onStayTopChange();
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange())); _stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
_screen = QQmlProperty(window,"screen");
_screen.connectNotifySignal(this,SLOT(_onScreenChanged())); _screen.connectNotifySignal(this,SLOT(_onScreenChanged()));
window->installEventFilter(this); window->installEventFilter(this);
} }
@ -278,8 +294,6 @@ void FluFramelessHelper::_onStayTopChange(){
bool isStayTop = _stayTop.read().toBool(); bool isStayTop = _stayTop.read().toBool();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
HWND hwnd = reinterpret_cast<HWND>(window->winId()); HWND hwnd = reinterpret_cast<HWND>(window->winId());
DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE);
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION &~ WS_SYSMENU);
if(isStayTop){ if(isStayTop){
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}else{ }else{
@ -327,6 +341,10 @@ QObject* FluFramelessHelper::maximizeButton(){
return var.value<QObject*>(); return var.value<QObject*>();
} }
void FluFramelessHelper::setOffsetXY(QPoint val){
_offsetXY.write(val);
}
bool FluFramelessHelper::resizeable(){ bool FluFramelessHelper::resizeable(){
return !(window->width() == window->maximumWidth() && window->width() == window->minimumWidth() && window->height() == window->maximumHeight() && window->height() == window->minimumHeight()); return !(window->width() == window->maximumWidth() && window->width() == window->minimumWidth() && window->height() == window->maximumHeight() && window->height() == window->minimumHeight());
} }

View File

@ -39,6 +39,7 @@ public:
bool hoverMaxBtn(); bool hoverMaxBtn();
bool resizeable(); bool resizeable();
QObject* maximizeButton(); QObject* maximizeButton();
void setOffsetXY(QPoint val);
Q_INVOKABLE void showSystemMenu(); Q_INVOKABLE void showSystemMenu();
protected: protected:
bool eventFilter(QObject *obj, QEvent *event) override; bool eventFilter(QObject *obj, QEvent *event) override;
@ -54,6 +55,7 @@ private:
FramelessEventFilter* _nativeEvent = nullptr; FramelessEventFilter* _nativeEvent = nullptr;
QQmlProperty _stayTop; QQmlProperty _stayTop;
QQmlProperty _screen; QQmlProperty _screen;
QQmlProperty _offsetXY;
}; };
#endif // FLUFRAMELESSHELPER_H #endif // FLUFRAMELESSHELPER_H

View File

@ -26,6 +26,7 @@ TextEdit {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
visible: !readOnly
onClicked: control.echoMode !== TextInput.Password && menu.popup() onClicked: control.echoMode !== TextInput.Password && menu.popup()
} }
FluTextBoxMenu{ FluTextBoxMenu{

View File

@ -64,6 +64,7 @@ TextArea{
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
visible: !readOnly
onClicked: control.echoMode !== TextInput.Password && menu.popup() onClicked: control.echoMode !== TextInput.Password && menu.popup()
} }
FluTextBoxMenu{ FluTextBoxMenu{

View File

@ -62,6 +62,7 @@ TextField{
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
visible: !readOnly
onClicked: control.echoMode !== TextInput.Password && menu.popup() onClicked: control.echoMode !== TextInput.Password && menu.popup()
} }
RowLayout{ RowLayout{

View File

@ -53,6 +53,7 @@ Window {
signal showSystemMenu signal showSystemMenu
signal initArgument(var argument) signal initArgument(var argument)
signal firstVisible() signal firstVisible()
property point _offsetXY : Qt.point(0,0)
id:window id:window
color:"transparent" color:"transparent"
Component.onCompleted: { Component.onCompleted: {
@ -175,30 +176,12 @@ Window {
} }
Item{ Item{
id:layout_container id:layout_container
property int offsetX: {
if(window.visibility === Window.Maximized){
var dx = window.x-Screen.virtualX
if(dx<0){
return Math.abs(dx+1)
}
}
return 0
}
property int offsetY: {
if(window.visibility === Window.Maximized){
var dy = window.y-Screen.virtualY
if(dy<0){
return Math.abs(dy+1)
}
}
return 0
}
anchors{ anchors{
fill:parent fill:parent
leftMargin: offsetX leftMargin: _offsetXY.x
rightMargin: offsetX rightMargin: _offsetXY.x
topMargin: offsetY topMargin: _offsetXY.y
bottomMargin: offsetY bottomMargin: _offsetXY.y
} }
onWidthChanged: { onWidthChanged: {
window.appBar.width = width window.appBar.width = width

View File

@ -26,6 +26,7 @@ TextEdit {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
visible: !readOnly
onClicked: control.echoMode !== TextInput.Password && menu.popup() onClicked: control.echoMode !== TextInput.Password && menu.popup()
} }
FluTextBoxMenu{ FluTextBoxMenu{

View File

@ -65,6 +65,7 @@ TextArea{
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
visible: !readOnly
onClicked: control.echoMode !== TextInput.Password && menu.popup() onClicked: control.echoMode !== TextInput.Password && menu.popup()
} }
FluTextBoxMenu{ FluTextBoxMenu{

View File

@ -63,6 +63,7 @@ TextField{
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
visible: !readOnly
onClicked: control.echoMode !== TextInput.Password && menu.popup() onClicked: control.echoMode !== TextInput.Password && menu.popup()
} }
RowLayout{ RowLayout{

View File

@ -52,6 +52,7 @@ Window {
signal showSystemMenu signal showSystemMenu
signal initArgument(var argument) signal initArgument(var argument)
signal firstVisible() signal firstVisible()
property point _offsetXY : Qt.point(0,0)
id:window id:window
color:"transparent" color:"transparent"
Component.onCompleted: { Component.onCompleted: {
@ -174,30 +175,12 @@ Window {
} }
Item{ Item{
id:layout_container id:layout_container
property int offsetX: {
if(window.visibility === Window.Maximized){
var dx = window.x-Screen.virtualX
if(dx<0){
return Math.abs(dx+1)
}
}
return 0
}
property int offsetY: {
if(window.visibility === Window.Maximized){
var dy = window.y-Screen.virtualY
if(dy<0){
return Math.abs(dy+1)
}
}
return 0
}
anchors{ anchors{
fill:parent fill:parent
leftMargin: offsetX leftMargin: _offsetXY.x
rightMargin: offsetX rightMargin: _offsetXY.x
topMargin: offsetY topMargin: _offsetXY.y
bottomMargin: offsetY bottomMargin: _offsetXY.y
} }
onWidthChanged: { onWidthChanged: {
window.appBar.width = width window.appBar.width = width