make frameless window optional, add option to not use system menu bar
This commit is contained in:
@@ -290,8 +290,6 @@ Noggit::Noggit(int argc, char *argv[])
|
||||
|
||||
main_window = std::make_unique<noggit::ui::main_window>();
|
||||
|
||||
FramelessWindowsManager::addWindow(main_window.get());
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
main_window->showFullScreen();
|
||||
|
||||
75
src/noggit/ui/FramelessWindow.hpp
Normal file
75
src/noggit/ui/FramelessWindow.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef NOGGIT_FRAMELESSWINDOW_HPP
|
||||
#define NOGGIT_FRAMELESSWINDOW_HPP
|
||||
|
||||
#include <external/framelesshelper/framelesswindowsmanager.h>
|
||||
#include <noggit/ui/font_awesome.hpp>
|
||||
#include <ui_TitleBar.h>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace noggit::ui
|
||||
{
|
||||
template <typename T>
|
||||
Ui::TitleBar* setupFramelessWindow(QWidget* titlebar_target, T* window, QSize minimum_size, QSize maximum_size, bool is_resizeable = true)
|
||||
{
|
||||
|
||||
QSettings settings;
|
||||
if (settings.value("systemWindowFrame", false).toBool())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto titleBarWidget = new Ui::TitleBar;
|
||||
titleBarWidget->setupUi(titlebar_target);
|
||||
titleBarWidget->windowTitle->setText(window->windowTitle());
|
||||
|
||||
titleBarWidget->iconButton->setAccessibleName("titlebar_icon");
|
||||
titleBarWidget->minimizeButton->setIcon(font_awesome_icon(font_awesome::windowminimize));
|
||||
titleBarWidget->minimizeButton->setIconSize(QSize(14, 14));
|
||||
titleBarWidget->minimizeButton->setAccessibleName("titlebar_minimize");
|
||||
titleBarWidget->maximizeButton->setIcon(font_awesome_icon(font_awesome::windowrestore));
|
||||
titleBarWidget->maximizeButton->setAccessibleName("titlebar_maximize");
|
||||
titleBarWidget->maximizeButton->setIconSize(QSize(14, 14));
|
||||
titleBarWidget->closeButton->setIcon(font_awesome_icon(font_awesome::times));
|
||||
titleBarWidget->closeButton->setAccessibleName("titlebar_close");
|
||||
titleBarWidget->closeButton->setIconSize(QSize(16, 16));
|
||||
|
||||
QObject::connect(titleBarWidget->closeButton,
|
||||
&QPushButton::clicked,
|
||||
window,
|
||||
&T::close);
|
||||
|
||||
QObject::connect(titleBarWidget->minimizeButton,
|
||||
&QPushButton::clicked,
|
||||
window,
|
||||
&T::showMinimized);
|
||||
|
||||
QObject::connect(titleBarWidget->maximizeButton,
|
||||
&QPushButton::clicked,
|
||||
[window, titleBarWidget]() {
|
||||
if (window->isMaximized()) {
|
||||
window->showNormal();
|
||||
titleBarWidget->maximizeButton->setToolTip(QObject::tr("Maximize"));
|
||||
} else {
|
||||
window->showMaximized();
|
||||
titleBarWidget->maximizeButton->setToolTip(QObject::tr("Restore"));
|
||||
}
|
||||
});
|
||||
|
||||
FramelessWindowsManager::addWindow(window);
|
||||
|
||||
FramelessWindowsManager::addIgnoreObject(window, titleBarWidget->minimizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(window, titleBarWidget->closeButton);
|
||||
|
||||
FramelessWindowsManager::setResizable(window, is_resizeable);
|
||||
FramelessWindowsManager::setMinimumSize(window, minimum_size);
|
||||
FramelessWindowsManager::setMaximumSize(window, maximum_size);
|
||||
|
||||
return titleBarWidget;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_FRAMELESSWINDOW_HPP
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <noggit/TextureManager.h>
|
||||
#include <util/qt/overload.hpp>
|
||||
#include <noggit/ui/FramelessWindow.hpp>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
@@ -30,16 +31,14 @@ namespace noggit
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
settings::settings(QWidget *parent)
|
||||
: QDialog(parent), _settings(new QSettings(this))
|
||||
settings::settings(QWidget *parent) : QDialog(parent), _settings(new QSettings(this))
|
||||
{
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
|
||||
ui = new Ui::SettingsPanel;
|
||||
ui->setupUi(this);
|
||||
|
||||
Ui::TitleBar titleBarWidget;
|
||||
titleBarWidget.setupUi(ui->titlebar);
|
||||
setupFramelessWindow(ui->titlebar, this, minimumSize(), maximumSize(), false);
|
||||
|
||||
connect(ui->gamePathField, &QLineEdit::textChanged, [&](QString value)
|
||||
{
|
||||
@@ -208,6 +207,8 @@ namespace noggit
|
||||
ui->_adt_unload_dist->setValue(_settings->value("unload_dist", 5).toInt());
|
||||
ui->_adt_unload_check_interval->setValue(_settings->value("unload_interval", 5).toInt());
|
||||
ui->_uid_cb->setChecked(_settings->value("uid_startup_check", true).toBool());
|
||||
ui->_systemWindowFrame->setChecked(_settings->value("systemWindowFrame", false).toBool());
|
||||
ui->_nativeMenubar->setChecked(_settings->value("nativeMenubar", true).toBool());
|
||||
ui->_additional_file_loading_log->setChecked(
|
||||
_settings->value("additional_file_loading_log", false).toBool());
|
||||
ui->_theme->setCurrentText(_settings->value("theme", "Dark").toString());
|
||||
@@ -255,6 +256,8 @@ namespace noggit
|
||||
_settings->setValue("unload_interval", ui->_adt_unload_check_interval->value());
|
||||
_settings->setValue("uid_startup_check", ui->_uid_cb->isChecked());
|
||||
_settings->setValue("additional_file_loading_log", ui->_additional_file_loading_log->isChecked());
|
||||
_settings->setValue("systemWindowFrame", ui->_systemWindowFrame->isChecked());
|
||||
_settings->setValue("nativeMenubar", ui->_nativeMenubar->isChecked());
|
||||
|
||||
#ifdef USE_MYSQL_UID_STORAGE
|
||||
_settings->setValue ("project/mysql/enabled", _mysql_box->isChecked());
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>418</width>
|
||||
<height>618</height>
|
||||
<width>650</width>
|
||||
<height>582</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -18,7 +18,7 @@
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>418</width>
|
||||
<width>650</width>
|
||||
<height>560</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -264,7 +264,7 @@
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_42">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_43">
|
||||
<item>
|
||||
@@ -276,6 +276,42 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="_systemWindowFrame">
|
||||
<property name="toolTip">
|
||||
<string>Turns on default system window frame instead of Noggit's styled one. Requires restart.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>System window frame</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="_nativeMenubar">
|
||||
<property name="toolTip">
|
||||
<string>Moves top menu to system's dedicated space for application menus. Supported by Mac OS and some other platforms. Requires restart.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Native menubar</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>423</width>
|
||||
<width>743</width>
|
||||
<height>38</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -51,6 +51,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="windowTitle">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
@@ -58,7 +68,7 @@
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>262</width>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <noggit/uid_storage.hpp>
|
||||
#include <noggit/Red/MapCreationWizard/Ui/MapCreationWizard.hpp>
|
||||
#include <noggit/ui/font_awesome.hpp>
|
||||
#include <noggit/ui/FramelessWindow.hpp>
|
||||
|
||||
#include <QtGui/QCloseEvent>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
@@ -58,52 +59,21 @@ namespace noggit
|
||||
|
||||
_about = new about(this);
|
||||
|
||||
QWidget *widget = new QWidget(this);
|
||||
Ui::TitleBar titleBarWidget;
|
||||
titleBarWidget.setupUi(widget);
|
||||
_menuBar = menuBar();
|
||||
|
||||
_settings = new settings(this);
|
||||
|
||||
FramelessWindowsManager::addWindow(_settings);
|
||||
QSettings settings;
|
||||
|
||||
_menuBar = menuBar();
|
||||
titleBarWidget.horizontalLayout->insertWidget(1, new QLabel(title.str().c_str(), this));
|
||||
titleBarWidget.horizontalLayout->insertWidget(1, _menuBar);
|
||||
if (!settings.value("systemWindowFrame", false).toBool())
|
||||
{
|
||||
QWidget *widget = new QWidget(this);
|
||||
Ui::TitleBar* titleBarWidget = setupFramelessWindow(widget, this, minimumSize(), maximumSize(), true);
|
||||
titleBarWidget->horizontalLayout->insertWidget(2, _menuBar);
|
||||
setMenuWidget(widget);
|
||||
}
|
||||
|
||||
titleBarWidget.iconButton->setAccessibleName("titlebar_icon");
|
||||
titleBarWidget.minimizeButton->setIcon(font_awesome_icon(font_awesome::windowminimize));
|
||||
titleBarWidget.minimizeButton->setIconSize(QSize(14, 14));
|
||||
titleBarWidget.minimizeButton->setAccessibleName("titlebar_minimize");
|
||||
titleBarWidget.maximizeButton->setIcon(font_awesome_icon(font_awesome::windowrestore));
|
||||
titleBarWidget.maximizeButton->setAccessibleName("titlebar_maximize");
|
||||
titleBarWidget.maximizeButton->setIconSize(QSize(14, 14));
|
||||
titleBarWidget.closeButton->setIcon(font_awesome_icon(font_awesome::times));
|
||||
titleBarWidget.closeButton->setAccessibleName("titlebar_close");
|
||||
titleBarWidget.closeButton->setIconSize(QSize(16, 16));
|
||||
setMenuWidget(widget);
|
||||
|
||||
_menuBar->setNativeMenuBar(false);
|
||||
|
||||
QObject::connect(titleBarWidget.closeButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&QMainWindow::close);
|
||||
|
||||
QObject::connect(titleBarWidget.minimizeButton,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&QMainWindow::showMinimized);
|
||||
|
||||
QObject::connect(titleBarWidget.maximizeButton,
|
||||
&QPushButton::clicked,
|
||||
[this, titleBarWidget]() {
|
||||
if (this->isMaximized()) {
|
||||
this->showNormal();
|
||||
titleBarWidget.maximizeButton->setToolTip(QObject::tr("Maximize"));
|
||||
} else {
|
||||
this->showMaximized();
|
||||
titleBarWidget.maximizeButton->setToolTip(QObject::tr("Restore"));
|
||||
}
|
||||
});
|
||||
_menuBar->setNativeMenuBar(settings.value("nativeMenubar", true).toBool());
|
||||
|
||||
auto file_menu (_menuBar->addMenu ("&Noggit"));
|
||||
|
||||
@@ -134,14 +104,6 @@ namespace noggit
|
||||
|
||||
_menuBar->adjustSize();
|
||||
|
||||
FramelessWindowsManager::addIgnoreObject(this, _menuBar);
|
||||
FramelessWindowsManager::addIgnoreObject(this, titleBarWidget.minimizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(this, titleBarWidget.maximizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(this, titleBarWidget.closeButton);
|
||||
|
||||
FramelessWindowsManager::setResizable(this, true);
|
||||
FramelessWindowsManager::setMinimumSize(this, {1280, 720});
|
||||
|
||||
build_menu();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user