diff --git a/src/blackgui/enableforframelesswindow.cpp b/src/blackgui/enableforframelesswindow.cpp index 1e6b663ed..cd06388a7 100644 --- a/src/blackgui/enableforframelesswindow.cpp +++ b/src/blackgui/enableforframelesswindow.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include using namespace BlackMisc; @@ -86,24 +87,27 @@ namespace BlackGui CEnableForFramelessWindow::WindowMode CEnableForFramelessWindow::stringToWindowMode(const QString &s) { - QString ws(s.trimmed().toLower()); + const QString ws(s.trimmed().toLower()); if (ws.isEmpty()) { return WindowNormal; } if (ws.contains("frameless") || ws.startsWith("f")) { return WindowFrameless; } if (ws.contains("tool") || ws.startsWith("t")) { return WindowTool; } return WindowNormal; } - QString CEnableForFramelessWindow::windowModeToString(CEnableForFramelessWindow::WindowMode m) + const QString &CEnableForFramelessWindow::windowModeToString(CEnableForFramelessWindow::WindowMode m) { + static const QString n("normal"); + static const QString f("frameless"); + static const QString t("tool"); + switch (m) { - case WindowFrameless: return "frameless"; - case WindowNormal: return "normal"; - case WindowTool: return "tool"; - default: - break; + case WindowFrameless: return f; + case WindowNormal: return n; + case WindowTool: return t; + default: break; } - return "normal"; + return n; } void CEnableForFramelessWindow::windowFlagsChanged() @@ -117,13 +121,15 @@ namespace BlackGui Q_ASSERT_X(!m_framelessPropertyName.isEmpty(), "CEnableForFramelessWindow::setWindowAttributes", "Missing property name"); bool frameless = (mode == WindowFrameless); - // http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5 - m_widget->setAttribute(Qt::WA_NoSystemBackground, frameless); + // http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5 // https://bugreports.qt.io/browse/QTBUG-52206 - if (CGuiUtility::isTopLevelWidget(m_widget)) + // UpdateLayeredWindowIndirect failed for ptDst + if (m_isMainApplicationWindow && CGuiUtility::isTopLevelWindow(m_widget)) { - m_widget->setAttribute(Qt::WA_TranslucentBackground, frameless); + m_widget->setAttribute(Qt::WA_NativeWindow); + m_widget->setAttribute(Qt::WA_NoSystemBackground, frameless); + m_widget->setAttribute(Qt::WA_TranslucentBackground, frameless); // causing QTBUG-52206 } // Qt::WA_PaintOnScreen leads to a warning diff --git a/src/blackgui/enableforframelesswindow.h b/src/blackgui/enableforframelesswindow.h index c058e9bb8..6fb00f7ac 100644 --- a/src/blackgui/enableforframelesswindow.h +++ b/src/blackgui/enableforframelesswindow.h @@ -51,6 +51,15 @@ namespace BlackGui //! \param correspondingWidget the widget representing the window CEnableForFramelessWindow(WindowMode mode, bool isMainApplicationWindow, const char *framelessPropertyname, QWidget *correspondingWidget); + //! Destructor + virtual ~CEnableForFramelessWindow() {} + + //! Copy constructor + CEnableForFramelessWindow(const CEnableForFramelessWindow &) = delete ; + + //! Copy assignment operator + CEnableForFramelessWindow &operator =(const CEnableForFramelessWindow &) = delete; + //! Window mode void setMode(WindowMode mode); @@ -76,7 +85,7 @@ namespace BlackGui static WindowMode stringToWindowMode(const QString &s); //! String to window mode - static QString windowModeToString(WindowMode m); + static const QString &windowModeToString(WindowMode m); protected: QPoint m_framelessDragPosition; //!< position, if moving is handled with frameless window */ diff --git a/src/blackgui/guiutility.cpp b/src/blackgui/guiutility.cpp index e34461591..1648c51d2 100644 --- a/src/blackgui/guiutility.cpp +++ b/src/blackgui/guiutility.cpp @@ -416,9 +416,31 @@ namespace BlackGui bool CGuiUtility::isTopLevelWidget(QWidget *widget) { + if (!widget) { return false; } return QApplication::topLevelWidgets().contains(widget); } + bool CGuiUtility::isTopLevelWindow(QWidget *widget) + { + if (!widget) { return false; } + if (!widget->isWindow()) { return false; } + return QApplication::topLevelWidgets().contains(widget); + } + + bool CGuiUtility::isQMainWindow(QWidget *widget) + { + if (!widget) { return false; } + QMainWindow *mw = qobject_cast(widget); + return mw; + } + + bool CGuiUtility::isDialog(QWidget *widget) + { + if (!widget) { return false; } + QDialog *mw = qobject_cast(widget); + return mw; + } + QGraphicsOpacityEffect *CGuiUtility::fadeInWidget(int durationMs, QWidget *widget, double startValue, double endValue) { // http://stackoverflow.com/questions/19087822/how-to-make-qt-widgets-fade-in-or-fade-out# @@ -543,8 +565,8 @@ namespace BlackGui QWidget *w = CGuiUtility::mainApplicationWidget(); if (!w) { return; } const QSize s = CGuiUtility::desktopSize(); - const int minW = wRatio * s.width(); - const int minH = hRatio * s.height(); + const int minW = qRound(wRatio * s.width()); + const int minH = qRound(hRatio * s.height()); w->setMinimumWidth(qMin(minW, w->minimumWidth())); w->setMinimumHeight(qMin(minH, w->minimumHeight())); } diff --git a/src/blackgui/guiutility.h b/src/blackgui/guiutility.h index 9338f8ac7..9536f888d 100644 --- a/src/blackgui/guiutility.h +++ b/src/blackgui/guiutility.h @@ -147,6 +147,14 @@ namespace BlackGui //! Is top level widget? static bool isTopLevelWidget(QWidget *widget); + //! Is top level window? + static bool isTopLevelWindow(QWidget *widget); + + //! Check window type @{ + static bool isQMainWindow(QWidget *widget); + static bool isDialog(QWidget *widget); + //! @} + //! Fade in a widget static QGraphicsOpacityEffect *fadeInWidget(int durationMs, QWidget *widget, double startValue = 0.0, double endValue = 1.0);