Skip to content

Commit

Permalink
fix window title under frameless UI
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Mar 5, 2022
1 parent 24076ed commit 22a10c9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char *argv[])

#ifdef Q_OS_WIN
if(Config().getUseFramelessWindow()){
auto titleBar = new WindowsTitleBar(&w, w.windowTitle(), w.menuBar());
auto titleBar = new WindowsTitleBar(&w, w.menuBar());
// QObject::connect(&w, &ModManager::menuBarChanged, titleBar, &WindowsTitleBar::updateMenuBar);
auto frameless = new FramelessWrapper(nullptr, &w, titleBar);
QObject::connect(&w, &ModManager::closed, frameless, &FramelessWrapper::close);
Expand Down
18 changes: 1 addition & 17 deletions src/ui/framelesswrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "config.hpp"

FramelessWrapper::FramelessWrapper(QWidget *parent, QWidget *widget, QMenuBar *menuBar) :
FramelessWrapper(parent, widget, new WindowsTitleBar(nullptr, widget->windowTitle(), menuBar))
FramelessWrapper(parent, widget, new WindowsTitleBar(widget, menuBar))
{
titleBar_->setParentWidget(this);
}
Expand Down Expand Up @@ -47,22 +47,6 @@ FramelessWrapper::FramelessWrapper(QWidget *parent, QWidget *widget, WindowsTitl
#endif //Q_OS_WIN
}

QWidget *FramelessWrapper::makeFrameless(QMainWindow *window)
{
window->menuBar()->hide();
auto wrapper = new FramelessWrapper(qobject_cast<QWidget *>(window->parent()),
window,
window->menuBar());
return wrapper;
}

QWidget *FramelessWrapper::makeFrameless(QDialog *dialog)
{
auto wrapper = new FramelessWrapper(qobject_cast<QWidget *>(dialog->parent()),
dialog);
return wrapper;
}

void FramelessWrapper::updateBlur()
{
#ifdef Q_OS_WIN
Expand Down
2 changes: 0 additions & 2 deletions src/ui/framelesswrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class FramelessWrapper : public QMainWindow
public:
FramelessWrapper(QWidget *parent, QWidget *widget, QMenuBar *menuBar = nullptr);
FramelessWrapper(QWidget *parent, QWidget *widget, WindowsTitleBar *titleBar);
static QWidget *makeFrameless(QMainWindow *window);
static QWidget *makeFrameless(QDialog *dialog);

private slots:
void updateBlur();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void ModManager::on_action_About_Mod_Manager_triggered()
auto dialog = new AboutDialog(this);
#ifdef Q_OS_WIN
if(config_.getUseFramelessWindow()){
auto frameless = FramelessWrapper::makeFrameless(dialog);
auto frameless = new FramelessWrapper(this, dialog);
frameless->show();
} else
#endif
Expand Down
10 changes: 7 additions & 3 deletions src/ui/windowstitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
#include <dwmapi.h>
#endif

WindowsTitleBar::WindowsTitleBar(QWidget *parent, const QString &title, QMenuBar *menuBar) :
WindowsTitleBar::WindowsTitleBar(QWidget *parent, QMenuBar *menuBar) :
QWidget(parent),
ui(new Ui::WindowsTitleBar),
parentWidget_(parent),
menuBar_(menuBar)
{
ui->setupUi(this);
// setMouseTracking(true);
ui->closeButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarCloseButton));
ui->maxButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarMaxButton));
ui->minButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarMinButton));
ui->titleText->setText(title);
updateMenuBar();
auto updateWindowTitle = [=]{
ui->titleText->setText(parent->windowTitle() + " - " +
qApp->applicationDisplayName());
};
updateWindowTitle();
connect(parent, &QWidget::windowTitleChanged, this, updateWindowTitle);
}

WindowsTitleBar::~WindowsTitleBar()
Expand Down
4 changes: 1 addition & 3 deletions src/ui/windowstitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ class WindowsTitleBar : public QWidget
Q_OBJECT

public:
explicit WindowsTitleBar(QWidget *parent = nullptr, const QString &title = QString(), QMenuBar *menuBar = nullptr);
explicit WindowsTitleBar(QWidget *parent = nullptr, QMenuBar *menuBar = nullptr);
~WindowsTitleBar();

void setIconVisible(bool bl);
void setParentWidget(QWidget *newParentWidget);

#ifdef Q_OS_WIN
bool hitTest(QPoint pos, long *result);
#endif //Q_OS_WIN

public slots:
void updateMenuBar();

void setMaximumed();
void setNormal();

Expand Down

0 comments on commit 22a10c9

Please sign in to comment.