mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 03:10:10 +08:00
update
This commit is contained in:
parent
2cfc73c00b
commit
9adb6b645b
@ -113,6 +113,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
||||
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
|
||||
}
|
||||
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;
|
||||
#endif
|
||||
@ -222,18 +230,26 @@ void FluFramelessHelper::componentComplete(){
|
||||
o = o->parent();
|
||||
}
|
||||
if(!window.isNull()){
|
||||
window->setFlags(Qt::FramelessWindowHint|Qt::Window|Qt::WindowTitleHint|Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint);
|
||||
#ifdef Q_OS_WIN
|
||||
window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
|
||||
_nativeEvent =new FramelessEventFilter(this);
|
||||
qApp->installNativeEventFilter(_nativeEvent);
|
||||
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);
|
||||
#else
|
||||
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
||||
#endif
|
||||
_stayTop = QQmlProperty(window,"stayTop");
|
||||
_screen = QQmlProperty(window,"screen");
|
||||
_offsetXY = QQmlProperty(window,"_offsetXY");
|
||||
_onStayTopChange();
|
||||
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
|
||||
_screen = QQmlProperty(window,"screen");
|
||||
_screen.connectNotifySignal(this,SLOT(_onScreenChanged()));
|
||||
window->installEventFilter(this);
|
||||
}
|
||||
@ -278,8 +294,6 @@ void FluFramelessHelper::_onStayTopChange(){
|
||||
bool isStayTop = _stayTop.read().toBool();
|
||||
#ifdef Q_OS_WIN
|
||||
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){
|
||||
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
}else{
|
||||
@ -327,6 +341,10 @@ QObject* FluFramelessHelper::maximizeButton(){
|
||||
return var.value<QObject*>();
|
||||
}
|
||||
|
||||
void FluFramelessHelper::setOffsetXY(QPoint val){
|
||||
_offsetXY.write(val);
|
||||
}
|
||||
|
||||
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 setOffsetXY(QPoint val);
|
||||
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 _offsetXY;
|
||||
};
|
||||
|
||||
#endif // FLUFRAMELESSHELPER_H
|
||||
|
@ -26,6 +26,7 @@ TextEdit {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.IBeamCursor
|
||||
acceptedButtons: Qt.RightButton
|
||||
visible: !readOnly
|
||||
onClicked: control.echoMode !== TextInput.Password && menu.popup()
|
||||
}
|
||||
FluTextBoxMenu{
|
||||
|
@ -64,6 +64,7 @@ TextArea{
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.IBeamCursor
|
||||
acceptedButtons: Qt.RightButton
|
||||
visible: !readOnly
|
||||
onClicked: control.echoMode !== TextInput.Password && menu.popup()
|
||||
}
|
||||
FluTextBoxMenu{
|
||||
|
@ -62,6 +62,7 @@ TextField{
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.IBeamCursor
|
||||
acceptedButtons: Qt.RightButton
|
||||
visible: !readOnly
|
||||
onClicked: control.echoMode !== TextInput.Password && menu.popup()
|
||||
}
|
||||
RowLayout{
|
||||
|
@ -53,6 +53,7 @@ Window {
|
||||
signal showSystemMenu
|
||||
signal initArgument(var argument)
|
||||
signal firstVisible()
|
||||
property point _offsetXY : Qt.point(0,0)
|
||||
id:window
|
||||
color:"transparent"
|
||||
Component.onCompleted: {
|
||||
@ -175,30 +176,12 @@ Window {
|
||||
}
|
||||
Item{
|
||||
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{
|
||||
fill:parent
|
||||
leftMargin: offsetX
|
||||
rightMargin: offsetX
|
||||
topMargin: offsetY
|
||||
bottomMargin: offsetY
|
||||
leftMargin: _offsetXY.x
|
||||
rightMargin: _offsetXY.x
|
||||
topMargin: _offsetXY.y
|
||||
bottomMargin: _offsetXY.y
|
||||
}
|
||||
onWidthChanged: {
|
||||
window.appBar.width = width
|
||||
|
@ -26,6 +26,7 @@ TextEdit {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.IBeamCursor
|
||||
acceptedButtons: Qt.RightButton
|
||||
visible: !readOnly
|
||||
onClicked: control.echoMode !== TextInput.Password && menu.popup()
|
||||
}
|
||||
FluTextBoxMenu{
|
||||
|
@ -65,6 +65,7 @@ TextArea{
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.IBeamCursor
|
||||
acceptedButtons: Qt.RightButton
|
||||
visible: !readOnly
|
||||
onClicked: control.echoMode !== TextInput.Password && menu.popup()
|
||||
}
|
||||
FluTextBoxMenu{
|
||||
|
@ -63,6 +63,7 @@ TextField{
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.IBeamCursor
|
||||
acceptedButtons: Qt.RightButton
|
||||
visible: !readOnly
|
||||
onClicked: control.echoMode !== TextInput.Password && menu.popup()
|
||||
}
|
||||
RowLayout{
|
||||
|
@ -52,6 +52,7 @@ Window {
|
||||
signal showSystemMenu
|
||||
signal initArgument(var argument)
|
||||
signal firstVisible()
|
||||
property point _offsetXY : Qt.point(0,0)
|
||||
id:window
|
||||
color:"transparent"
|
||||
Component.onCompleted: {
|
||||
@ -174,30 +175,12 @@ Window {
|
||||
}
|
||||
Item{
|
||||
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{
|
||||
fill:parent
|
||||
leftMargin: offsetX
|
||||
rightMargin: offsetX
|
||||
topMargin: offsetY
|
||||
bottomMargin: offsetY
|
||||
leftMargin: _offsetXY.x
|
||||
rightMargin: _offsetXY.x
|
||||
topMargin: _offsetXY.y
|
||||
bottomMargin: _offsetXY.y
|
||||
}
|
||||
onWidthChanged: {
|
||||
window.appBar.width = width
|
||||
|
Loading…
Reference in New Issue
Block a user