forked from github_mirror/framelesshelper
parent
0debbb890f
commit
ff10ae21f4
|
@ -73,6 +73,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||||
|
|
||||||
connect(ui->customizeTitleBarCB, &QCheckBox::stateChanged, this, [this](int state) {
|
connect(ui->customizeTitleBarCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||||
const bool enable = state == Qt::Checked;
|
const bool enable = state == Qt::Checked;
|
||||||
|
ui->windowFrameCB->setEnabled(enable);
|
||||||
WinNativeEventFilter::updateQtFrame(windowHandle(),
|
WinNativeEventFilter::updateQtFrame(windowHandle(),
|
||||||
enable ? WinNativeEventFilter::getSystemMetric(
|
enable ? WinNativeEventFilter::getSystemMetric(
|
||||||
getRawHandle(this),
|
getRawHandle(this),
|
||||||
|
@ -81,7 +82,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||||
ui->titleBarWidget->setVisible(enable);
|
ui->titleBarWidget->setVisible(enable);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
qunsetenv(useNativeTitleBar);
|
qunsetenv(useNativeTitleBar);
|
||||||
} else if (state == Qt::Unchecked) {
|
} else {
|
||||||
qputenv(useNativeTitleBar, "1");
|
qputenv(useNativeTitleBar, "1");
|
||||||
}
|
}
|
||||||
updateWindow(this);
|
updateWindow(this);
|
||||||
|
@ -89,7 +90,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||||
connect(ui->windowFrameCB, &QCheckBox::stateChanged, this, [this](int state) {
|
connect(ui->windowFrameCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||||
if (state == Qt::Checked) {
|
if (state == Qt::Checked) {
|
||||||
qunsetenv(preserveWindowFrame);
|
qunsetenv(preserveWindowFrame);
|
||||||
} else if (state == Qt::Unchecked) {
|
} else {
|
||||||
qputenv(preserveWindowFrame, "1");
|
qputenv(preserveWindowFrame, "1");
|
||||||
}
|
}
|
||||||
updateWindow(this);
|
updateWindow(this);
|
||||||
|
@ -98,17 +99,28 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||||
const bool enable = state == Qt::Checked;
|
const bool enable = state == Qt::Checked;
|
||||||
QPalette palette = {};
|
QPalette palette = {};
|
||||||
// Choose the gradient color you like.
|
// Choose the gradient color you like.
|
||||||
palette.setColor(QPalette::Window, QColor(255, 255, 255, 235));
|
palette.setColor(QPalette::Window, QColor(255, 255, 255, 220));
|
||||||
setPalette(enable ? palette : QPalette());
|
setPalette(enable ? palette : QPalette());
|
||||||
WinNativeEventFilter::setBlurEffectEnabled(getRawHandle(this), enable);
|
WinNativeEventFilter::setBlurEffectEnabled(getRawHandle(this), enable);
|
||||||
updateWindow(this);
|
updateWindow(this);
|
||||||
});
|
});
|
||||||
connect(ui->resizableCB, &QCheckBox::stateChanged, this, [this](int state) {
|
connect(ui->resizableCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||||
|
const bool enable = state == Qt::Checked;
|
||||||
|
ui->maximizeButton->setEnabled(enable);
|
||||||
const auto data = WinNativeEventFilter::windowData(this);
|
const auto data = WinNativeEventFilter::windowData(this);
|
||||||
if (data) {
|
if (data) {
|
||||||
data->fixedSize = state == Qt::Unchecked;
|
data->fixedSize = !enable;
|
||||||
updateWindow(this);
|
updateWindow(this);
|
||||||
}
|
}
|
||||||
|
if (!ui->customizeTitleBarCB->isChecked()) {
|
||||||
|
if (enable) {
|
||||||
|
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);
|
||||||
|
} else {
|
||||||
|
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
|
||||||
|
}
|
||||||
|
show();
|
||||||
|
WinNativeEventFilter::setWindowResizable(getRawHandle(this), enable);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QStyleOption option;
|
QStyleOption option;
|
||||||
|
|
|
@ -2397,3 +2397,20 @@ void WinNativeEventFilter::updateFrameMargins(void *handle)
|
||||||
UpdateFrameMarginsForWindow(hwnd);
|
UpdateFrameMarginsForWindow(hwnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WinNativeEventFilter::setWindowResizable(void *handle, const bool resizable)
|
||||||
|
{
|
||||||
|
Q_ASSERT(handle);
|
||||||
|
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||||
|
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||||
|
const auto originalStyle = WNEF_EXECUTE_WINAPI_RETURN(GetWindowLongPtrW, 0, hwnd, GWL_STYLE);
|
||||||
|
const auto diffStyle = WS_MAXIMIZEBOX | WS_THICKFRAME;
|
||||||
|
const auto resizableStyle = originalStyle | diffStyle;
|
||||||
|
const auto fixedSizeStyle = originalStyle & ~diffStyle;
|
||||||
|
WNEF_EXECUTE_WINAPI(SetWindowLongPtrW,
|
||||||
|
hwnd,
|
||||||
|
GWL_STYLE,
|
||||||
|
resizable ? resizableStyle : fixedSizeStyle)
|
||||||
|
updateWindow(hwnd, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -146,6 +146,9 @@ public:
|
||||||
// Thin wrapper of DwmExtendFrameIntoClientArea().
|
// Thin wrapper of DwmExtendFrameIntoClientArea().
|
||||||
static void updateFrameMargins(void *handle /* HWND */);
|
static void updateFrameMargins(void *handle /* HWND */);
|
||||||
|
|
||||||
|
// Helper function.
|
||||||
|
static void setWindowResizable(void *handle /* HWND */, const bool resizable = true);
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
/// CORE FUNCTION - THE SOUL OF THIS CODE
|
/// CORE FUNCTION - THE SOUL OF THIS CODE
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue