mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
refs #347, CMainWindow for frameless main windows
This commit is contained in:
committed by
Roland Winklmeier
parent
facbefeeea
commit
42a4e0b48b
@@ -7,21 +7,17 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SAMPLE_GUIMODEENUMS_H
|
||||
#define SAMPLE_GUIMODEENUMS_H
|
||||
#ifndef STDGUI_GUIMODEENUMS_H
|
||||
#define STDGUI_GUIMODEENUMS_H
|
||||
|
||||
|
||||
//! Modes, how GUI can be started (core/GUI)
|
||||
struct GuiModes {
|
||||
|
||||
struct GuiModes
|
||||
{
|
||||
public:
|
||||
//! Window modes
|
||||
enum WindowMode {
|
||||
WindowFrameless,
|
||||
WindowNormal
|
||||
};
|
||||
|
||||
//! Core runs how and where?
|
||||
enum CoreMode {
|
||||
enum CoreMode
|
||||
{
|
||||
CoreInGuiProcess,
|
||||
CoreExternal,
|
||||
CoreExternalAudioLocal
|
||||
|
||||
@@ -33,12 +33,12 @@ CIntroWindow::~CIntroWindow() { }
|
||||
/*
|
||||
* Window mode
|
||||
*/
|
||||
GuiModes::WindowMode CIntroWindow::getWindowMode() const
|
||||
BlackGui::CEnableForFramelessWindow::WindowMode CIntroWindow::getWindowMode() const
|
||||
{
|
||||
if (this->ui->rb_WindowFrameless->isChecked())
|
||||
return GuiModes::WindowFrameless;
|
||||
return BlackGui::CEnableForFramelessWindow::WindowFrameless;
|
||||
else
|
||||
return GuiModes::WindowNormal;
|
||||
return BlackGui::CEnableForFramelessWindow::WindowNormal;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef SAMPLE_INTROWINDOW_H
|
||||
#define SAMPLE_INTROWINDOW_H
|
||||
#ifndef STDGUI_INTROWINDOW_H
|
||||
#define STDGUI_INTROWINDOW_H
|
||||
|
||||
#include "guimodeenums.h"
|
||||
#include "blackgui/enableforframelesswindow.h"
|
||||
#include <QDialog>
|
||||
#include <QScopedPointer>
|
||||
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
~CIntroWindow();
|
||||
|
||||
//! Selected window mode
|
||||
GuiModes::WindowMode getWindowMode() const;
|
||||
BlackGui::CEnableForFramelessWindow::WindowMode getWindowMode() const;
|
||||
|
||||
//! Get core mode
|
||||
GuiModes::CoreMode getCoreMode() const;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "blackcore/context_runtime_config.h"
|
||||
#include "blacksim/blacksimfreefunctions.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
|
||||
@@ -24,6 +25,8 @@
|
||||
#include <QPushButton>
|
||||
|
||||
using namespace BlackGui;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackCore;
|
||||
|
||||
/*!
|
||||
* \brief Main
|
||||
@@ -42,11 +45,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Translations
|
||||
QFile file(":blackmisc/translations/blackmisc_i18n_de.qm");
|
||||
qDebug() << (file.exists() ? "Found translations in resources" : "No translations in resources");
|
||||
CLogMessage("swift.standardgui.main").debug() << (file.exists() ? "Found translations in resources" : "No translations in resources");
|
||||
QTranslator translator;
|
||||
if (translator.load("blackmisc_i18n_de", ":blackmisc/translations/"))
|
||||
{
|
||||
qDebug() << "Translator loaded";
|
||||
CLogMessage("swift.standardgui.main").debug() << "Translator loaded";
|
||||
}
|
||||
|
||||
// application
|
||||
@@ -66,7 +69,7 @@ int main(int argc, char *argv[])
|
||||
a.setStyleSheet(s);
|
||||
|
||||
// modes
|
||||
GuiModes::WindowMode windowMode;
|
||||
BlackGui::CMainWindow::WindowMode windowMode;
|
||||
|
||||
// Dialog to decide external or internal core
|
||||
CIntroWindow intro;
|
||||
|
||||
@@ -38,23 +38,13 @@ using namespace BlackMisc::Hardware;
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) :
|
||||
QMainWindow(parent, windowMode == GuiModes::WindowFrameless ?
|
||||
(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) :
|
||||
(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint)),
|
||||
ui(new Ui::MainWindow),
|
||||
m_windowMode(windowMode)
|
||||
MainWindow::MainWindow(BlackGui::CMainWindow::WindowMode windowMode, QWidget *parent) :
|
||||
BlackGui::CMainWindow(windowMode, parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
if (windowMode == GuiModes::WindowFrameless)
|
||||
{
|
||||
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
|
||||
this->setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
// this->setAttribute(Qt::WA_PaintOnScreen);
|
||||
}
|
||||
|
||||
// GUI
|
||||
ui->setupUi(this);
|
||||
this->ui->wi_CentralWidgetOutside->setProperty("mainframeless", this->isFrameless());
|
||||
this->m_compInfoWindow = new CInfoWindowComponent(this); // setupUi has to be first!
|
||||
}
|
||||
|
||||
@@ -118,29 +108,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
QApplication::exit();
|
||||
}
|
||||
|
||||
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
// this->ui->fr_PseudoWindowBar->geometry().contains(event->pos())
|
||||
if (this->m_windowMode == GuiModes::WindowFrameless && event->buttons() & Qt::LeftButton)
|
||||
{
|
||||
move(event->globalPos() - this->m_dragPosition);
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->m_windowMode == GuiModes::WindowFrameless && event->button() == Qt::LeftButton)
|
||||
{
|
||||
this->m_dragPosition = event->globalPos() - this->frameGeometry().topLeft();
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set main page
|
||||
*/
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef SAMPLE_MAINWINDOW_H
|
||||
#define SAMPLE_MAINWINDOW_H
|
||||
#ifndef STDGUI_SWIFTGUI_H
|
||||
#define STDGUI_SWIFTGUI_H
|
||||
|
||||
// clash with struct interface in objbase.h used to happen
|
||||
#pragma push_macro("interface")
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "blackgui/models/userlistmodel.h"
|
||||
#include "blackgui/models/statusmessagelistmodel.h"
|
||||
#include "blackgui/models/keyboardkeylistmodel.h"
|
||||
#include "blackgui/mainwindow.h"
|
||||
#include "blackgui/managedstatusbar.h"
|
||||
#include "blackmisc/nwtextmessage.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
@@ -44,7 +45,7 @@ namespace Ui { class MainWindow; }
|
||||
|
||||
//! swift GUI
|
||||
class MainWindow :
|
||||
public QMainWindow,
|
||||
public BlackGui::CMainWindow,
|
||||
public BlackGui::Components::CEnableForRuntime
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -60,7 +61,7 @@ public:
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
explicit MainWindow(GuiModes::WindowMode windowMode, QWidget *parent = nullptr);
|
||||
explicit MainWindow(BlackGui::CMainWindow::WindowMode windowMode, QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~MainWindow();
|
||||
@@ -83,18 +84,11 @@ protected:
|
||||
//! Close event, e.g. when window is closed
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
//! Mouse moving, required for frameless window
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
//! Mouse press, required for frameless window
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::MainWindow> ui;
|
||||
bool m_init = false;
|
||||
BlackGui::Components::CInfoWindowComponent *m_compInfoWindow = nullptr; //!< the info window (popup
|
||||
BlackGui::CManagedStatusBar m_statusBar;
|
||||
GuiModes::WindowMode m_windowMode = GuiModes::WindowNormal;
|
||||
BlackInput::IKeyboard *m_keyboard = nullptr; //!< hotkeys
|
||||
BlackMisc::CLogSubscriber m_logSubscriber { this, &MainWindow::ps_displayStatusMessageInGui };
|
||||
|
||||
@@ -105,12 +99,6 @@ private:
|
||||
QTimer *m_timerContextWatchdog = nullptr; //!< core available?
|
||||
BlackMisc::Aviation::CAircraft m_ownAircraft; //!< own aircraft's state
|
||||
|
||||
// frameless window
|
||||
QPoint m_dragPosition; /*!< position, if moving is handled with frameless window */
|
||||
|
||||
// context menus
|
||||
QMenu *m_contextMenuStatusMessageList = nullptr; /*!< context menu for status message list */
|
||||
|
||||
// cockpit
|
||||
QString m_transponderResetValue; //!< Temp. storage of XPdr mode to reset, req. until timer allows singleShoot with Lambdas
|
||||
QWidget *m_inputFocusedWidget = nullptr; //!< currently used widget for input, mainly used with cockpit
|
||||
|
||||
@@ -204,7 +204,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
||||
@@ -48,25 +48,17 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
|
||||
|
||||
// with frameless window, we shift menu and statusbar into central widget
|
||||
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
|
||||
if (this->m_windowMode == GuiModes::WindowFrameless)
|
||||
if (this->isFrameless())
|
||||
{
|
||||
this->ui->wi_CentralWidgetOutside->setStyleSheet("#wi_CentralWidgetOutside {border: 2px solid green; border-radius: 20px; }");
|
||||
this->ui->vl_CentralWidgetOutside->setContentsMargins(8, 8, 8, 8);
|
||||
|
||||
QHBoxLayout *menuBarLayout = new QHBoxLayout();
|
||||
QPushButton *closeIcon = new QPushButton(this);
|
||||
closeIcon->setStyleSheet("margin: 0; padding: 0; background: transparent;");
|
||||
closeIcon->setIcon(CIcons::close16());
|
||||
QObject::connect(closeIcon, &QPushButton::clicked, this, &QMainWindow::close);
|
||||
menuBarLayout->addWidget(this->ui->mb_MainMenuBar, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
menuBarLayout->addWidget(closeIcon, 0, Qt::AlignTop | Qt::AlignRight);
|
||||
QHBoxLayout *menuBarLayout = this->addFramelessCloseButton(this->ui->mb_MainMenuBar);
|
||||
this->ui->vl_CentralWidgetOutside->insertLayout(0, menuBarLayout, 0);
|
||||
|
||||
QSizeGrip *grip = new QSizeGrip(this);
|
||||
grip->setStyleSheet("margin-right: 25px; background-color: transparent;");
|
||||
// move the status bar intothe frame (otherwise it is dangling outside)
|
||||
this->ui->sb_MainStatusBar->setParent(this->ui->wi_CentralWidgetOutside);
|
||||
this->ui->vl_CentralWidgetOutside->addWidget(this->ui->sb_MainStatusBar, 0);
|
||||
this->ui->sb_MainStatusBar->addPermanentWidget(grip);
|
||||
|
||||
// grip
|
||||
this->addFramelessSizeGrip(this->ui->sb_MainStatusBar);
|
||||
}
|
||||
|
||||
// timers
|
||||
|
||||
Reference in New Issue
Block a user