Skip to content

Commit

Permalink
some qt6 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Jul 9, 2024
1 parent eb436b0 commit e44fadf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
3 changes: 0 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, false);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/image/modmanager.png"));
a.setOrganizationName("kaniol");
Expand Down
42 changes: 26 additions & 16 deletions src/ui/framelesswrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QMdiArea>
#include <QPainter>
#include <QPushButton>
#include <QResizeEvent>
#include <QToolButton>
#include <QVBoxLayout>
#ifdef Q_OS_WIN
Expand All @@ -32,6 +33,7 @@ FramelessWrapper::FramelessWrapper(QWidget *widget, QMenuBar *menuBar) :
titleBar_(new WindowsTitleBar(widget, menuBar))
{
titleBar_->setParentWidget(this);
setAttribute(Qt::WA_Hover);

auto w = new QWidget(this);
auto layout = new QVBoxLayout;
Expand Down Expand Up @@ -70,31 +72,36 @@ void FramelessWrapper::updateBlur()
}

#ifdef Q_OS_WIN

#if QT_VERSION_MAJOR == 6
bool FramelessWrapper::nativeEvent(const QByteArray& eventType, void* message, qintptr* result)
#else
bool FramelessWrapper::nativeEvent(const QByteArray &eventType, void *message, long *result)
#endif // QT_VERSION_MAJOR
{
MSG* msg = (MSG*)message;
float boundaryWidth = 4;
// qDebug() << msg->message;

//support highdpi
double dpr = this->devicePixelRatioF();

switch(msg->message){
case WM_NCCALCSIZE:{
NCCALCSIZE_PARAMS& params = *reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam);
if (params.rgrc[0].top != 0)
params.rgrc[0].top -= 1;
if(msg->wParam == FALSE) return false;

*result = WVR_REDRAW;
return true;
}
case WM_NCHITTEST:{
//support highdpi
double dpr = this->devicePixelRatioF();
long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam);
POINT nativeLocalPos{ GET_X_LPARAM(msg->lParam), GET_Y_LPARAM(msg->lParam) };
::ScreenToClient(msg->hwnd, &nativeLocalPos);
auto mousePos = QPoint(nativeLocalPos.x / dpr, nativeLocalPos.y / dpr);

auto mousePos = mapFromGlobal(QPoint(x/dpr,y/dpr));
bool left = mousePos.x() < boundaryWidth;
bool right = mousePos.x() > width() - boundaryWidth;
bool top = mousePos.y() < boundaryWidth;
bool bottom = mousePos.y() > height() - boundaryWidth;

if(left && top)
*result = HTTOPLEFT;
else if(right && top)
Expand All @@ -111,27 +118,30 @@ bool FramelessWrapper::nativeEvent(const QByteArray &eventType, void *message, l
*result = HTTOP;
else if(bottom)
*result = HTBOTTOM;

if(*result) return true;

if (!titleBar_->rect().contains(mousePos)) return false;
*result = HTNOWHERE;
if(!titleBar_->rect().contains(mousePos)) return false;
return titleBar_->hitTest(mousePos, result);
}
case WM_GETMINMAXINFO: {
MINMAXINFO* minmaxInfo = reinterpret_cast<MINMAXINFO*>(msg->lParam);
RECT rect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
if (::IsZoomed(msg->hwnd)) {
RECT frame = { 0, 0, 0, 0 };
AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0);
frame.left = abs(frame.left);
frame.top = abs(frame.bottom);
setContentsMargins(frame.left, frame.top, frame.right, frame.bottom);
int i = abs(minmaxInfo->ptMaxPosition.x / dpr);
setContentsMargins(i, i, i, i);
titleBar_->setMaximumed();
} else{
setContentsMargins(0, 0, 0, 0);
titleBar_->setNormal();
}
*result = ::DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam);
break;
return true;
}
}
return false;
}

#endif //Q_OS_WIN
8 changes: 6 additions & 2 deletions src/ui/framelesswrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ private slots:

protected:
#ifdef Q_OS_WIN
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
#endif //Q_OS_WIN
#if QT_VERSION_MAJOR == 6
virtual bool nativeEvent(const QByteArray& eventType, void* message, qintptr* result) override;
#else
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
#endif // QT_VERSION_MAJOR
#endif // Q_OS_WIN

private:
WindowsTitleBar *titleBar_;
Expand Down
9 changes: 4 additions & 5 deletions src/ui/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void ModManager::paintEvent(QPaintEvent *event[[maybe_unused]])
if(!widget->isVisible()) continue;
auto rect = widget->rect();
rect.translate(widget->pos());
p.fillRect(rect, QBrush(QColor(255, 255, 255, 210)));
p.fillRect(rect, QBrush(QColor(255, 50, 255, 210)));
}
}
#endif //defined (DE_KDE) || defined (Q_OS_WIN)
Expand Down Expand Up @@ -295,16 +295,15 @@ void ModManager::customContextMenuRequested(const QModelIndex &index, const QPoi
connect(menu->addAction(QIcon::fromTheme("entry-edit"), tr("Edit")), &QAction::triggered, this, [=]{
editLocalPath(index.row());
});
auto reloadAction = menu->addAction(QIcon::fromTheme("view-refresh"), tr("Reload"));
auto reloadAction = menu->addAction(QIcon::fromTheme("view-refresh"), tr("Reload"), [=]{
localBrowser->reload();
});
if(localBrowser->isLoading()){
reloadAction->setEnabled(false);
connect(localBrowser, &LocalModBrowser::loadFinished, this, [=]{
reloadAction->setEnabled(true);
});
}
connect(reloadAction, &QAction::triggered, this, [=]{
localBrowser->reload();
});
connect(menu->addAction(QIcon::fromTheme("delete"), tr("Delete")), &QAction::triggered, this, [=]{
if(QMessageBox::No == QMessageBox::question(this, tr("Delete"), tr("Delete this mod path?"))) return;
LocalModPathManager::removePathAt(index.row());
Expand Down
4 changes: 4 additions & 0 deletions src/ui/windowstitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ void WindowsTitleBar::setParentWidget(QWidget *newParentWidget)
}

#ifdef Q_OS_WIN
#if QT_VERSION_MAJOR == 6
bool WindowsTitleBar::hitTest(QPoint pos, qintptr *result)
#else
bool WindowsTitleBar::hitTest(QPoint pos, long *result)
#endif // QT_VERSION_MAJOR
{
QWidget* child = childAt(pos);
if(auto label = qobject_cast<QLabel*>(child); label == ui->icon){
Expand Down
4 changes: 4 additions & 0 deletions src/ui/windowstitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class WindowsTitleBar : public QWidget
void setIconVisible(bool bl);
void setParentWidget(QWidget *newParentWidget);
#ifdef Q_OS_WIN
#if QT_VERSION_MAJOR == 6
bool hitTest(QPoint pos, qintptr *result);
#else
bool hitTest(QPoint pos, long *result);
#endif // QT_VERSION_MAJOR
#endif //Q_OS_WIN

public slots:
Expand Down

0 comments on commit e44fadf

Please sign in to comment.