chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -13,9 +13,7 @@
|
||||
#include "ElaTheme.h"
|
||||
#include "ElaWinShadowHelper.h"
|
||||
|
||||
ElaDockWidget::ElaDockWidget(QWidget* parent, Qt::WindowFlags flags)
|
||||
: QDockWidget(parent, flags), d_ptr(new ElaDockWidgetPrivate())
|
||||
{
|
||||
ElaDockWidget::ElaDockWidget(QWidget *parent, Qt::WindowFlags flags) : QDockWidget(parent, flags), d_ptr(new ElaDockWidgetPrivate()) {
|
||||
Q_D(ElaDockWidget);
|
||||
d->q_ptr = this;
|
||||
setObjectName("ElaDockWidget");
|
||||
@@ -32,35 +30,27 @@ ElaDockWidget::ElaDockWidget(QWidget* parent, Qt::WindowFlags flags)
|
||||
update();
|
||||
});
|
||||
connect(this, &ElaDockWidget::topLevelChanged, this, [=](bool topLevel) {
|
||||
if (eApp->getWindowDisplayMode() == ElaApplicationType::WindowDisplayMode::ElaMica)
|
||||
{
|
||||
if (eApp->getWindowDisplayMode() == ElaApplicationType::WindowDisplayMode::ElaMica) {
|
||||
eApp->syncWindowDisplayMode(this, topLevel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ElaDockWidget::ElaDockWidget(const QString& title, QWidget* parent, Qt::WindowFlags flags)
|
||||
: ElaDockWidget(parent, flags)
|
||||
{
|
||||
ElaDockWidget::ElaDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags) : ElaDockWidget(parent, flags) {
|
||||
this->setWindowTitle(title);
|
||||
}
|
||||
|
||||
ElaDockWidget::~ElaDockWidget()
|
||||
{
|
||||
}
|
||||
ElaDockWidget::~ElaDockWidget() {}
|
||||
|
||||
void ElaDockWidget::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaDockWidget::paintEvent(QPaintEvent *event) {
|
||||
Q_D(ElaDockWidget);
|
||||
if (isFloating())
|
||||
{
|
||||
if (isFloating()) {
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setRenderHints(QPainter::Antialiasing);
|
||||
#ifdef Q_OS_WIN
|
||||
// 背景
|
||||
if (d->_windowDisplayMode != ElaApplicationType::WindowDisplayMode::ElaMica)
|
||||
{
|
||||
if (d->_windowDisplayMode != ElaApplicationType::WindowDisplayMode::ElaMica) {
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(ElaThemeColor(d->_themeMode, DialogBase));
|
||||
painter.drawRect(rect());
|
||||
@@ -68,7 +58,8 @@ void ElaDockWidget::paintEvent(QPaintEvent* event)
|
||||
#else
|
||||
// 背景
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(d->_windowDisplayMode == ElaApplicationType::WindowDisplayMode::ElaMica ? Qt::transparent : ElaThemeColor(d->_themeMode, DialogBase));
|
||||
painter.setBrush(d->_windowDisplayMode == ElaApplicationType::WindowDisplayMode::ElaMica ? Qt::transparent
|
||||
: ElaThemeColor(d->_themeMode, DialogBase));
|
||||
QRect foregroundRect(d->_shadowBorderWidth, d->_shadowBorderWidth, width() - 2 * d->_shadowBorderWidth, height() - 2 * d->_shadowBorderWidth);
|
||||
painter.drawRect(rect());
|
||||
#endif
|
||||
@@ -78,133 +69,102 @@ void ElaDockWidget::paintEvent(QPaintEvent* event)
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
bool ElaDockWidget::event(QEvent* event)
|
||||
{
|
||||
bool ElaDockWidget::event(QEvent *event) {
|
||||
Q_D(ElaDockWidget);
|
||||
switch (event->type())
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::Show:
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
HWND hwnd = (HWND)d->_currentWinID;
|
||||
case QEvent::MouseButtonRelease: {
|
||||
HWND hwnd = (HWND)d->_currentWinID;
|
||||
DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME);
|
||||
ElaWinShadowHelper::getInstance()->setWindowShadow(d->_currentWinID);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 3) && QT_VERSION <= QT_VERSION_CHECK(6, 6, 1))
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 3) && QT_VERSION <= QT_VERSION_CHECK(6, 6, 1))
|
||||
bool hasCaption = (style & WS_CAPTION) == WS_CAPTION;
|
||||
if (!hasCaption)
|
||||
{
|
||||
if (!hasCaption) {
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_CAPTION);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return QDockWidget::event(event);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool ElaDockWidget::nativeEvent(const QByteArray& eventType, void* message, qintptr* result)
|
||||
#else
|
||||
bool ElaDockWidget::nativeEvent(const QByteArray& eventType, void* message, long* result)
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool ElaDockWidget::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
|
||||
#else
|
||||
bool ElaDockWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||
#endif
|
||||
{
|
||||
Q_D(ElaDockWidget);
|
||||
if ((eventType != "windows_generic_MSG") || !message)
|
||||
{
|
||||
if ((eventType != "windows_generic_MSG") || !message) {
|
||||
return false;
|
||||
}
|
||||
const auto msg = static_cast<const MSG*>(message);
|
||||
const auto msg = static_cast<const MSG *>(message);
|
||||
const HWND hwnd = msg->hwnd;
|
||||
if (!hwnd || !msg)
|
||||
{
|
||||
if (!hwnd || !msg) {
|
||||
return false;
|
||||
}
|
||||
d->_currentWinID = (qint64)hwnd;
|
||||
const UINT uMsg = msg->message;
|
||||
d->_currentWinID = (qint64)hwnd;
|
||||
const UINT uMsg = msg->message;
|
||||
const WPARAM wParam = msg->wParam;
|
||||
const LPARAM lParam = msg->lParam;
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_WINDOWPOSCHANGING:
|
||||
{
|
||||
WINDOWPOS* wp = reinterpret_cast<WINDOWPOS*>(lParam);
|
||||
if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0)
|
||||
{
|
||||
switch (uMsg) {
|
||||
case WM_WINDOWPOSCHANGING: {
|
||||
WINDOWPOS *wp = reinterpret_cast<WINDOWPOS *>(lParam);
|
||||
if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0) {
|
||||
wp->flags |= SWP_NOCOPYBITS;
|
||||
*result = ::DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case WM_NCACTIVATE:
|
||||
{
|
||||
case WM_NCACTIVATE: {
|
||||
*result = TRUE;
|
||||
return true;
|
||||
}
|
||||
case WM_NCHITTEST:
|
||||
{
|
||||
case WM_NCHITTEST: {
|
||||
POINT nativeLocalPos{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
||||
::ScreenToClient(hwnd, &nativeLocalPos);
|
||||
RECT clientRect{0, 0, 0, 0};
|
||||
::GetClientRect(hwnd, &clientRect);
|
||||
auto clientWidth = clientRect.right - clientRect.left;
|
||||
auto clientWidth = clientRect.right - clientRect.left;
|
||||
auto clientHeight = clientRect.bottom - clientRect.top;
|
||||
bool left = nativeLocalPos.x < d->_margins;
|
||||
bool right = nativeLocalPos.x > clientWidth - d->_margins;
|
||||
bool top = nativeLocalPos.y < d->_margins;
|
||||
bool bottom = nativeLocalPos.y > clientHeight - d->_margins;
|
||||
*result = 0;
|
||||
if (!window()->isFullScreen() && !window()->isMaximized())
|
||||
{
|
||||
if (left && top)
|
||||
{
|
||||
bool left = nativeLocalPos.x < d->_margins;
|
||||
bool right = nativeLocalPos.x > clientWidth - d->_margins;
|
||||
bool top = nativeLocalPos.y < d->_margins;
|
||||
bool bottom = nativeLocalPos.y > clientHeight - d->_margins;
|
||||
*result = 0;
|
||||
if (!window()->isFullScreen() && !window()->isMaximized()) {
|
||||
if (left && top) {
|
||||
*result = HTTOPLEFT;
|
||||
}
|
||||
else if (left && bottom)
|
||||
{
|
||||
} else if (left && bottom) {
|
||||
*result = HTBOTTOMLEFT;
|
||||
}
|
||||
else if (right && top)
|
||||
{
|
||||
} else if (right && top) {
|
||||
*result = HTTOPRIGHT;
|
||||
}
|
||||
else if (right && bottom)
|
||||
{
|
||||
} else if (right && bottom) {
|
||||
*result = HTBOTTOMRIGHT;
|
||||
}
|
||||
else if (left)
|
||||
{
|
||||
} else if (left) {
|
||||
*result = HTLEFT;
|
||||
}
|
||||
else if (right)
|
||||
{
|
||||
} else if (right) {
|
||||
*result = HTRIGHT;
|
||||
}
|
||||
else if (top)
|
||||
{
|
||||
} else if (top) {
|
||||
*result = HTTOP;
|
||||
}
|
||||
else if (bottom)
|
||||
{
|
||||
} else if (bottom) {
|
||||
*result = HTBOTTOM;
|
||||
}
|
||||
}
|
||||
if (0 != *result)
|
||||
{
|
||||
if (0 != *result) {
|
||||
return true;
|
||||
}
|
||||
*result = HTCLIENT;
|
||||
return true;
|
||||
}
|
||||
case WM_NCCALCSIZE:
|
||||
{
|
||||
if (wParam == FALSE)
|
||||
{
|
||||
case WM_NCCALCSIZE: {
|
||||
if (wParam == FALSE) {
|
||||
return false;
|
||||
}
|
||||
*result = 0;
|
||||
|
||||
Reference in New Issue
Block a user