Ref T346, framless window “UpdateLayeredWindowIndirect failed” error preparations

This commit is contained in:
Klaus Basan
2018-09-10 13:36:28 +02:00
parent d2d27a8eac
commit 97cf9f4939
4 changed files with 60 additions and 15 deletions

View File

@@ -28,6 +28,7 @@
#include <QThread>
#include <QVariant>
#include <QWidget>
#include <QMainWindow>
#include <QtGlobal>
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

View File

@@ -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 */

View File

@@ -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<QMainWindow *>(widget);
return mw;
}
bool CGuiUtility::isDialog(QWidget *widget)
{
if (!widget) { return false; }
QDialog *mw = qobject_cast<QDialog *>(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()));
}

View File

@@ -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);