refs #347, CMainWindow for frameless main windows

This commit is contained in:
Klaus Basan
2014-11-22 18:51:00 +01:00
committed by Roland Winklmeier
parent facbefeeea
commit 42a4e0b48b
15 changed files with 266 additions and 112 deletions

View File

@@ -0,0 +1,116 @@
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "enableforframelesswindow.h"
#include "blackmisc/icons.h"
#include <QSizeGrip>
#include <QStatusBar>
#include <QPushButton>
using namespace BlackMisc;
namespace BlackGui
{
CEnableForFramelessWindow::CEnableForFramelessWindow(CEnableForFramelessWindow::WindowMode mode, bool isMainApplicationWindow, QWidget *correspondingWidget) :
m_windowMode(mode), m_mainApplicationWindow(isMainApplicationWindow), m_widget(correspondingWidget)
{
Q_ASSERT(correspondingWidget);
this->setWindowAttributes(mode);
}
void CEnableForFramelessWindow::setMode(CEnableForFramelessWindow::WindowMode mode)
{
if (mode == this->m_windowMode) { return; }
this->m_widget->setWindowFlags(modeToWindowFlags(mode));
this->setWindowAttributes(mode);
this->m_widget->show();
this->m_windowMode = mode;
}
void CEnableForFramelessWindow::setFrameless(bool frameless)
{
setMode(frameless ? WindowFrameless : WindowNormal);
}
void CEnableForFramelessWindow::setWindowAttributes(CEnableForFramelessWindow::WindowMode mode)
{
bool frameless = (mode == WindowFrameless);
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
this->m_widget->setAttribute(Qt::WA_NoSystemBackground, frameless);
this->m_widget->setAttribute(Qt::WA_TranslucentBackground, frameless);
this->m_widget->setProperty("frameless", frameless);
}
bool CEnableForFramelessWindow::handleMouseMoveEvent(QMouseEvent *event)
{
Q_ASSERT(this->m_widget);
if (this->m_windowMode == WindowFrameless && event->buttons() & Qt::LeftButton)
{
this->m_widget->move(event->globalPos() - this->m_framelessDragPosition);
event->accept();
return true;
}
return false;
}
bool CEnableForFramelessWindow::handleMousePressEvent(QMouseEvent *event)
{
Q_ASSERT(this->m_widget);
if (this->m_windowMode == WindowFrameless && event->button() == Qt::LeftButton)
{
this->m_framelessDragPosition = event->globalPos() - this->m_widget->frameGeometry().topLeft();
event->accept();
return true;
}
return false;
}
void CEnableForFramelessWindow::addFramelessSizeGrip(QStatusBar *statusBar)
{
if (!statusBar) { return; }
QSizeGrip *grip = new QSizeGrip(this->m_widget);
grip->setObjectName("sg_FramelessSizeGrip");
statusBar->addPermanentWidget(grip);
}
QHBoxLayout *CEnableForFramelessWindow::addFramelessCloseButton(QMenuBar *menuBar)
{
Q_ASSERT(isFrameless());
Q_ASSERT(menuBar);
Q_ASSERT(this->m_widget);
if (!m_framelessCloseButton)
{
m_framelessCloseButton = new QPushButton(this->m_widget);
m_framelessCloseButton->setObjectName("pb_FramelessCloseButton");
m_framelessCloseButton->setIcon(CIcons::close16());
QObject::connect(m_framelessCloseButton, &QPushButton::clicked, this->m_widget, &QWidget::close);
}
QHBoxLayout *menuBarLayout = new QHBoxLayout;
menuBarLayout->setObjectName("hl_MenuBar");
menuBarLayout->addWidget(menuBar, 0, Qt::AlignTop | Qt::AlignLeft);
menuBarLayout->addWidget(m_framelessCloseButton, 0, Qt::AlignTop | Qt::AlignRight);
return menuBarLayout;
}
Qt::WindowFlags CEnableForFramelessWindow::modeToWindowFlags(CEnableForFramelessWindow::WindowMode mode)
{
switch (mode)
{
case WindowFrameless:
return (Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
case WindowNormal:
default:
return (Qt::Tool | Qt::WindowStaysOnTopHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
}
}
} // namespace

View File

@@ -0,0 +1,85 @@
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_ENABLEFORFRAMLESSWINDOW_H
#define BLACKGUI_ENABLEFORFRAMLESSWINDOW_H
#include <QWidget>
#include <QStatusBar>
#include <QMouseEvent>
#include <QPushButton>
#include <QHBoxLayout>
#include <QMenuBar>
namespace BlackGui
{
//! Main window which can be frameless
//! \details QMainWindows cannot be promoted. Hence a derived class does not work properly here.
//! Furthermore frameless functionality is also required for CDockWidgets as well.
class CEnableForFramelessWindow
{
public:
//! Window modes
enum WindowMode
{
WindowFrameless,
WindowNormal
};
//! Constructor
CEnableForFramelessWindow(WindowMode mode, bool isMainApplicationWindow, QWidget *correspondingWidget);
//! Window mode
void setMode(WindowMode mode);
//! Framless
void setFrameless(bool frameless);
//! Frameless?
bool isFrameless() const { return this->m_windowMode == WindowFrameless; }
//! The main application
bool isMainApplicationWindow() const { return m_mainApplicationWindow; }
//! Corresponding QMainWindow
QWidget *getWidget() const { return m_widget; }
protected:
//! Resize grip handle
void addFramelessSizeGrip(QStatusBar *statusBar);
//! Attributes
void setWindowAttributes(WindowMode mode);
//! Close button for frameless windows
QHBoxLayout *addFramelessCloseButton(QMenuBar *menuBar);
//! Translate mode
static Qt::WindowFlags modeToWindowFlags(WindowMode mode);
QPoint m_framelessDragPosition; //!< position, if moving is handled with frameless window */
QPushButton *m_framelessCloseButton = nullptr; //!< close button
WindowMode m_windowMode = WindowNormal; //!< Window mode, \sa WindowMode
bool m_mainApplicationWindow = false; //!< is the main application window (only 1)
QWidget *m_widget = nullptr; //!< corresponding main window or dock widget
//! Mouse press, required for frameless window
bool handleMousePressEvent(QMouseEvent *event);
//! Mouse moving, required for frameless window
bool handleMouseMoveEvent(QMouseEvent *event);
};
} // namespace
#endif // guard

View File

@@ -14,25 +14,23 @@
namespace BlackGui namespace BlackGui
{ {
QMainWindow *CGuiUtility::mainWindow() CEnableForFramelessWindow *CGuiUtility::mainApplicationWindow()
{ {
QWidgetList tlw = topLevelApplicationWidgetsWithName(); QWidgetList tlw = topLevelApplicationWidgetsWithName();
foreach(QWidget * w, tlw) foreach(QWidget * w, tlw)
{ {
QMainWindow *mw = qobject_cast<QMainWindow *>(w); CEnableForFramelessWindow *mw = dynamic_cast<CEnableForFramelessWindow *>(w);
if (!mw) { continue; } if (!mw) { continue; }
QString n = mw->objectName().toLower(); if (mw->isMainApplicationWindow()) return mw;
if (n.contains("main") && n.contains("window")) return mw;
} }
return nullptr; return nullptr;
} }
bool CGuiUtility::isMainWindowFrameless() bool CGuiUtility::isMainWindowFrameless()
{ {
QMainWindow *mw = mainWindow(); CEnableForFramelessWindow *mw = mainApplicationWindow();
Q_ASSERT(mw); // there should be a main window Q_ASSERT(mw); // there should be a main window
if (!mw) return false; return (mw && mw->isFrameless());
return (mw->windowFlags() & Qt::FramelessWindowHint);
} }
QWidgetList CGuiUtility::topLevelApplicationWidgetsWithName() QWidgetList CGuiUtility::topLevelApplicationWidgetsWithName()
@@ -41,7 +39,7 @@ namespace BlackGui
QWidgetList rl; QWidgetList rl;
foreach(QWidget * w, tlw) foreach(QWidget * w, tlw)
{ {
if (w->objectName().isEmpty()) continue; if (w->objectName().isEmpty()) { continue; }
rl.append(w); rl.append(w);
} }
return rl; return rl;
@@ -49,8 +47,8 @@ namespace BlackGui
QPoint CGuiUtility::mainWindowPosition() QPoint CGuiUtility::mainWindowPosition()
{ {
QMainWindow *mw = mainWindow(); CEnableForFramelessWindow *mw = mainApplicationWindow();
return (mw) ? mw->pos() : QPoint(); return (mw) ? mw->getWidget()->pos() : QPoint();
} }
QPoint CGuiUtility::introWindowPosition() QPoint CGuiUtility::introWindowPosition()
@@ -59,7 +57,7 @@ namespace BlackGui
foreach(QWidget * w, tlw) foreach(QWidget * w, tlw)
{ {
QString n = w->objectName().toLower(); QString n = w->objectName().toLower();
if (n.contains("intro")) return w->pos(); if (n.contains("intro")) { return w->pos(); }
} }
return QPoint(0, 0); return QPoint(0, 0);
} }
@@ -73,7 +71,7 @@ namespace BlackGui
QString CGuiUtility::replaceTabCountValue(const QString &oldName, int count) QString CGuiUtility::replaceTabCountValue(const QString &oldName, int count)
{ {
const QString v = QString("(").append(QString::number(count)).append(")"); const QString v = QString("(").append(QString::number(count)).append(")");
if (oldName.isEmpty()) {return v; } if (oldName.isEmpty()) { return v; }
int index = oldName.lastIndexOf('('); int index = oldName.lastIndexOf('(');
if (index == 0) { return v; } if (index == 0) { return v; }
if (index < 0) { return QString(oldName).append(" ").append(v); } if (index < 0) { return QString(oldName).append(" ").append(v); }

View File

@@ -13,7 +13,7 @@
#define BLACKGUI_GUIUTILITY_H #define BLACKGUI_GUIUTILITY_H
#include <QWidgetList> #include <QWidgetList>
#include <QMainWindow> #include "enableforframelesswindow.h"
namespace BlackGui namespace BlackGui
{ {
@@ -24,7 +24,7 @@ namespace BlackGui
public: public:
//! Main application window //! Main application window
static QMainWindow *mainWindow(); static CEnableForFramelessWindow *mainApplicationWindow();
//! Is main window frameless? //! Is main window frameless?
static bool isMainWindowFrameless(); static bool isMainWindowFrameless();

View File

@@ -25,7 +25,8 @@ using namespace BlackMisc;
namespace BlackGui namespace BlackGui
{ {
CInfoArea::CInfoArea(QWidget *parent) : QMainWindow(parent) CInfoArea::CInfoArea(QWidget *parent) :
QMainWindow(parent), CEnableForFramelessWindow(CEnableForFramelessWindow::WindowNormal, false, this)
{ {
this->ps_setInfoAreaFloating(this->m_infoAreaFloating); this->ps_setInfoAreaFloating(this->m_infoAreaFloating);
this->setWindowIcon(CIcons::swift24()); this->setWindowIcon(CIcons::swift24());
@@ -39,7 +40,7 @@ namespace BlackGui
// after(!) GUI is setup // after(!) GUI is setup
if (this->m_dockWidgetInfoAreas.isEmpty()) if (this->m_dockWidgetInfoAreas.isEmpty())
{ {
this->m_dockWidgetInfoAreas = this->initOwnDockWidgetInfoAreas(); this->m_dockWidgetInfoAreas = this->findOwnDockWidgetInfoAreas();
Q_ASSERT(!this->m_dockWidgetInfoAreas.isEmpty()); Q_ASSERT(!this->m_dockWidgetInfoAreas.isEmpty());
} }
@@ -401,13 +402,19 @@ namespace BlackGui
// this completely initializes the tab bar and all docked widgets // this completely initializes the tab bar and all docked widgets
if (init) if (init)
{ {
// float
QPoint offset(i * 25, i * 20); QPoint offset(i * 25, i * 20);
after->setVisible(false); after->setVisible(false);
after->setFloating(true); after->setFloating(true);
after->setOffsetWhenFloating(offset); after->setOffsetWhenFloating(offset);
after->setPreferredSizeWhenFloating(this->getPreferredSizeWhenFloating(i)); QSize floatingSize = this->getPreferredSizeWhenFloating(i);
after->setPreferredSizeWhenFloating(floatingSize);
// dock again
after->setFloating(false); after->setFloating(false);
after->setVisible(true); after->setVisible(true);
// reset floating flag
after->resetWasAlreadyFLoating(); after->resetWasAlreadyFLoating();
} }
else else
@@ -497,7 +504,7 @@ namespace BlackGui
} }
} }
QList<CDockWidgetInfoArea *> CInfoArea::initOwnDockWidgetInfoAreas() QList<CDockWidgetInfoArea *> CInfoArea::findOwnDockWidgetInfoAreas() const
{ {
QList<CDockWidgetInfoArea *> infoAreas = this->findChildren<CDockWidgetInfoArea *>(); QList<CDockWidgetInfoArea *> infoAreas = this->findChildren<CDockWidgetInfoArea *>();
if (infoAreas.isEmpty()) { return infoAreas; } if (infoAreas.isEmpty()) { return infoAreas; }

View File

@@ -13,6 +13,7 @@
#define BLACKGUI_INFOAREA_H #define BLACKGUI_INFOAREA_H
#include "dockwidgetinfoarea.h" #include "dockwidgetinfoarea.h"
#include "enableforframelesswindow.h"
#include <QMainWindow> #include <QMainWindow>
#include <QTabBar> #include <QTabBar>
#include <QPixmap> #include <QPixmap>
@@ -22,7 +23,7 @@ namespace BlackGui
{ {
//! Info area, hosting dockable widgets //! Info area, hosting dockable widgets
//! \sa CDockWidgetInfoArea //! \sa CDockWidgetInfoArea
class CInfoArea : public QMainWindow class CInfoArea : public QMainWindow, CEnableForFramelessWindow
{ {
Q_OBJECT Q_OBJECT
@@ -182,11 +183,11 @@ namespace BlackGui
void setMarginsWhenDocked(int left, int top, int right, int bottom); void setMarginsWhenDocked(int left, int top, int right, int bottom);
//! Nested info areas //! Nested info areas
QList<CInfoArea *> getChildInfoAreas() { return this->findChildren<CInfoArea *>(); } QList<CInfoArea *> getChildInfoAreas() const { return this->findChildren<CInfoArea *>(); }
//! Direct dock widget areas, not the nested dock widget areas //! Direct dock widget areas, not the nested dock widget areas
//! \remarks result stored in m_dockableWidgets //! \remarks result stored in m_dockableWidgets
QList<CDockWidgetInfoArea *> initOwnDockWidgetInfoAreas(); QList<CDockWidgetInfoArea *> findOwnDockWidgetInfoAreas() const;
private slots: private slots:
//! Tab bar has been double clicked //! Tab bar has been double clicked

View File

@@ -11,8 +11,8 @@ Used dynamic properties
mainframeless (infobar.qss) mainframeless (infobar.qss)
**/ **/
/** putting background here works for framed, but not for frameless window **/ /** Main window **/
#MainWindow { QMainWindow {
background-image: url(:/textures/icons/textures/texture-outer.jpg); background-image: url(:/textures/icons/textures/texture-outer.jpg);
background-color: darkslategray; background-color: darkslategray;
} }

View File

@@ -7,21 +7,17 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
#ifndef SAMPLE_GUIMODEENUMS_H #ifndef STDGUI_GUIMODEENUMS_H
#define SAMPLE_GUIMODEENUMS_H #define STDGUI_GUIMODEENUMS_H
//! Modes, how GUI can be started (core/GUI) //! Modes, how GUI can be started (core/GUI)
struct GuiModes { struct GuiModes
{
public: public:
//! Window modes
enum WindowMode {
WindowFrameless,
WindowNormal
};
//! Core runs how and where? //! Core runs how and where?
enum CoreMode { enum CoreMode
{
CoreInGuiProcess, CoreInGuiProcess,
CoreExternal, CoreExternal,
CoreExternalAudioLocal CoreExternalAudioLocal

View File

@@ -33,12 +33,12 @@ CIntroWindow::~CIntroWindow() { }
/* /*
* Window mode * Window mode
*/ */
GuiModes::WindowMode CIntroWindow::getWindowMode() const BlackGui::CEnableForFramelessWindow::WindowMode CIntroWindow::getWindowMode() const
{ {
if (this->ui->rb_WindowFrameless->isChecked()) if (this->ui->rb_WindowFrameless->isChecked())
return GuiModes::WindowFrameless; return BlackGui::CEnableForFramelessWindow::WindowFrameless;
else else
return GuiModes::WindowNormal; return BlackGui::CEnableForFramelessWindow::WindowNormal;
} }
/* /*

View File

@@ -9,10 +9,11 @@
//! \file //! \file
#ifndef SAMPLE_INTROWINDOW_H #ifndef STDGUI_INTROWINDOW_H
#define SAMPLE_INTROWINDOW_H #define STDGUI_INTROWINDOW_H
#include "guimodeenums.h" #include "guimodeenums.h"
#include "blackgui/enableforframelesswindow.h"
#include <QDialog> #include <QDialog>
#include <QScopedPointer> #include <QScopedPointer>
@@ -31,7 +32,7 @@ public:
~CIntroWindow(); ~CIntroWindow();
//! Selected window mode //! Selected window mode
GuiModes::WindowMode getWindowMode() const; BlackGui::CEnableForFramelessWindow::WindowMode getWindowMode() const;
//! Get core mode //! Get core mode
GuiModes::CoreMode getCoreMode() const; GuiModes::CoreMode getCoreMode() const;

View File

@@ -15,6 +15,7 @@
#include "blackcore/context_runtime_config.h" #include "blackcore/context_runtime_config.h"
#include "blacksim/blacksimfreefunctions.h" #include "blacksim/blacksimfreefunctions.h"
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/icons.h" #include "blackmisc/icons.h"
#include "blackmisc/loghandler.h" #include "blackmisc/loghandler.h"
@@ -24,6 +25,8 @@
#include <QPushButton> #include <QPushButton>
using namespace BlackGui; using namespace BlackGui;
using namespace BlackMisc;
using namespace BlackCore;
/*! /*!
* \brief Main * \brief Main
@@ -42,11 +45,11 @@ int main(int argc, char *argv[])
// Translations // Translations
QFile file(":blackmisc/translations/blackmisc_i18n_de.qm"); 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; QTranslator translator;
if (translator.load("blackmisc_i18n_de", ":blackmisc/translations/")) if (translator.load("blackmisc_i18n_de", ":blackmisc/translations/"))
{ {
qDebug() << "Translator loaded"; CLogMessage("swift.standardgui.main").debug() << "Translator loaded";
} }
// application // application
@@ -66,7 +69,7 @@ int main(int argc, char *argv[])
a.setStyleSheet(s); a.setStyleSheet(s);
// modes // modes
GuiModes::WindowMode windowMode; BlackGui::CMainWindow::WindowMode windowMode;
// Dialog to decide external or internal core // Dialog to decide external or internal core
CIntroWindow intro; CIntroWindow intro;

View File

@@ -38,23 +38,13 @@ using namespace BlackMisc::Hardware;
/* /*
* Constructor * Constructor
*/ */
MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : MainWindow::MainWindow(BlackGui::CMainWindow::WindowMode windowMode, QWidget *parent) :
QMainWindow(parent, windowMode == GuiModes::WindowFrameless ? BlackGui::CMainWindow(windowMode, parent),
(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : ui(new Ui::MainWindow)
(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint)),
ui(new Ui::MainWindow),
m_windowMode(windowMode)
{ {
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 // GUI
ui->setupUi(this); ui->setupUi(this);
this->ui->wi_CentralWidgetOutside->setProperty("mainframeless", this->isFrameless());
this->m_compInfoWindow = new CInfoWindowComponent(this); // setupUi has to be first! this->m_compInfoWindow = new CInfoWindowComponent(this); // setupUi has to be first!
} }
@@ -118,29 +108,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
QApplication::exit(); 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 * Set main page
*/ */

View File

@@ -9,8 +9,8 @@
//! \file //! \file
#ifndef SAMPLE_MAINWINDOW_H #ifndef STDGUI_SWIFTGUI_H
#define SAMPLE_MAINWINDOW_H #define STDGUI_SWIFTGUI_H
// clash with struct interface in objbase.h used to happen // clash with struct interface in objbase.h used to happen
#pragma push_macro("interface") #pragma push_macro("interface")
@@ -29,6 +29,7 @@
#include "blackgui/models/userlistmodel.h" #include "blackgui/models/userlistmodel.h"
#include "blackgui/models/statusmessagelistmodel.h" #include "blackgui/models/statusmessagelistmodel.h"
#include "blackgui/models/keyboardkeylistmodel.h" #include "blackgui/models/keyboardkeylistmodel.h"
#include "blackgui/mainwindow.h"
#include "blackgui/managedstatusbar.h" #include "blackgui/managedstatusbar.h"
#include "blackmisc/nwtextmessage.h" #include "blackmisc/nwtextmessage.h"
#include "blackmisc/loghandler.h" #include "blackmisc/loghandler.h"
@@ -44,7 +45,7 @@ namespace Ui { class MainWindow; }
//! swift GUI //! swift GUI
class MainWindow : class MainWindow :
public QMainWindow, public BlackGui::CMainWindow,
public BlackGui::Components::CEnableForRuntime public BlackGui::Components::CEnableForRuntime
{ {
Q_OBJECT Q_OBJECT
@@ -60,7 +61,7 @@ public:
}; };
//! Constructor //! Constructor
explicit MainWindow(GuiModes::WindowMode windowMode, QWidget *parent = nullptr); explicit MainWindow(BlackGui::CMainWindow::WindowMode windowMode, QWidget *parent = nullptr);
//! Destructor //! Destructor
~MainWindow(); ~MainWindow();
@@ -83,18 +84,11 @@ protected:
//! Close event, e.g. when window is closed //! Close event, e.g. when window is closed
void closeEvent(QCloseEvent *event); 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: private:
QScopedPointer<Ui::MainWindow> ui; QScopedPointer<Ui::MainWindow> ui;
bool m_init = false; bool m_init = false;
BlackGui::Components::CInfoWindowComponent *m_compInfoWindow = nullptr; //!< the info window (popup BlackGui::Components::CInfoWindowComponent *m_compInfoWindow = nullptr; //!< the info window (popup
BlackGui::CManagedStatusBar m_statusBar; BlackGui::CManagedStatusBar m_statusBar;
GuiModes::WindowMode m_windowMode = GuiModes::WindowNormal;
BlackInput::IKeyboard *m_keyboard = nullptr; //!< hotkeys BlackInput::IKeyboard *m_keyboard = nullptr; //!< hotkeys
BlackMisc::CLogSubscriber m_logSubscriber { this, &MainWindow::ps_displayStatusMessageInGui }; BlackMisc::CLogSubscriber m_logSubscriber { this, &MainWindow::ps_displayStatusMessageInGui };
@@ -105,12 +99,6 @@ private:
QTimer *m_timerContextWatchdog = nullptr; //!< core available? QTimer *m_timerContextWatchdog = nullptr; //!< core available?
BlackMisc::Aviation::CAircraft m_ownAircraft; //!< own aircraft's state 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 // cockpit
QString m_transponderResetValue; //!< Temp. storage of XPdr mode to reset, req. until timer allows singleShoot with Lambdas 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 QWidget *m_inputFocusedWidget = nullptr; //!< currently used widget for input, mainly used with cockpit

View File

@@ -204,7 +204,7 @@
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>

View File

@@ -48,25 +48,17 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
// with frameless window, we shift menu and statusbar into central widget // with frameless window, we shift menu and statusbar into central widget
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5 // 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; }"); QHBoxLayout *menuBarLayout = this->addFramelessCloseButton(this->ui->mb_MainMenuBar);
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);
this->ui->vl_CentralWidgetOutside->insertLayout(0, menuBarLayout, 0); this->ui->vl_CentralWidgetOutside->insertLayout(0, menuBarLayout, 0);
QSizeGrip *grip = new QSizeGrip(this); // move the status bar intothe frame (otherwise it is dangling outside)
grip->setStyleSheet("margin-right: 25px; background-color: transparent;");
this->ui->sb_MainStatusBar->setParent(this->ui->wi_CentralWidgetOutside); this->ui->sb_MainStatusBar->setParent(this->ui->wi_CentralWidgetOutside);
this->ui->vl_CentralWidgetOutside->addWidget(this->ui->sb_MainStatusBar, 0); this->ui->vl_CentralWidgetOutside->addWidget(this->ui->sb_MainStatusBar, 0);
this->ui->sb_MainStatusBar->addPermanentWidget(grip);
// grip
this->addFramelessSizeGrip(this->ui->sb_MainStatusBar);
} }
// timers // timers