From 6c3d2105441b3406ec62792f56b0c409b96729a8 Mon Sep 17 00:00:00 2001 From: "S. Razi Alavizadeh" Date: Sun, 20 Jan 2013 01:52:30 +0330 Subject: [PATCH] [Qt5][Windows] Now QupZilla compiles with Qt5 on Windows (msvc). -There are some issues when enabling blur effect! --- src/lib/3rdparty/ecwin7.cpp | 2 +- src/lib/3rdparty/ecwin7.h | 6 ++-- src/lib/3rdparty/qtlockedfile_win.cpp | 8 ++++++ src/lib/3rdparty/qtwin.cpp | 41 +++++++++++++++++++++++---- src/lib/3rdparty/qtwin.h | 5 ++++ src/lib/app/qupzilla.cpp | 13 +++++++++ src/lib/app/qupzilla.h | 4 +++ src/lib/downloads/downloadmanager.cpp | 9 +++++- src/lib/downloads/downloadmanager.h | 4 +++ 9 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/lib/3rdparty/ecwin7.cpp b/src/lib/3rdparty/ecwin7.cpp index 2d124082e..ee921b14c 100644 --- a/src/lib/3rdparty/ecwin7.cpp +++ b/src/lib/3rdparty/ecwin7.cpp @@ -32,7 +32,7 @@ EcWin7::EcWin7() } // Init taskbar communication -void EcWin7::init(WId wid) +void EcWin7::init(HWND wid) { mWindowId = wid; mTaskbarMessageId = RegisterWindowMessage(L"TaskbarButtonCreated"); diff --git a/src/lib/3rdparty/ecwin7.h b/src/lib/3rdparty/ecwin7.h index fc9fda615..5d72ce64a 100644 --- a/src/lib/3rdparty/ecwin7.h +++ b/src/lib/3rdparty/ecwin7.h @@ -27,7 +27,7 @@ // Windows only data definitions #ifdef W7TASKBAR - +#define NOMINMAX #include #include #define CMIC_MASK_ASYNCOK SEE_MASK_ASYNCOK @@ -45,7 +45,7 @@ public: // Initialization methods EcWin7(); - void init(WId wid); + void init(HWND wid); bool winEvent(MSG* message, long* result); // Overlay icon handling @@ -63,7 +63,7 @@ public: void setProgressState(ToolBarProgressState state); private: - WId mWindowId; + HWND mWindowId; UINT mTaskbarMessageId; ITaskbarList3* mTaskbar; HICON mOverlayIcon; diff --git a/src/lib/3rdparty/qtlockedfile_win.cpp b/src/lib/3rdparty/qtlockedfile_win.cpp index bba7c7c5a..bd0f9979d 100644 --- a/src/lib/3rdparty/qtlockedfile_win.cpp +++ b/src/lib/3rdparty/qtlockedfile_win.cpp @@ -66,16 +66,24 @@ Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) Qt::HANDLE mutex; if (doCreate) { +#if (QT_VERSION < 0x050000) QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); }); +#else // QT_WA removed from Qt5: http://qt-project.org/forums/viewthread/22994/#107379 + mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); +#endif if (!mutex) { qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); return 0; } } else { +#if (QT_VERSION < 0x050000) QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); }); +#else // QT_WA removed from Qt5: http://qt-project.org/forums/viewthread/22994/#107379 + mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); +#endif if (!mutex) { if (GetLastError() != ERROR_FILE_NOT_FOUND) { qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); diff --git a/src/lib/3rdparty/qtwin.cpp b/src/lib/3rdparty/qtwin.cpp index 9a63b6a5e..40243e79c 100644 --- a/src/lib/3rdparty/qtwin.cpp +++ b/src/lib/3rdparty/qtwin.cpp @@ -84,7 +84,11 @@ public: void removeWidget(QWidget* widget) { widgets.removeAll(widget); } +#if (QT_VERSION < 0x050000) bool winEvent(MSG* message, long* result); +#else + bool nativeEvent(const QByteArray &eventType, void* _message, long* result); +#endif private: QWidgetList widgets; @@ -93,7 +97,7 @@ private: static bool resolveLibs() { if (!pDwmIsCompositionEnabled) { - QLibrary dwmLib(QString::fromAscii("dwmapi")); + QLibrary dwmLib(QString::fromLatin1("dwmapi")); pDwmIsCompositionEnabled = (PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled"); pDwmExtendFrameIntoClientArea = (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea"); pDwmEnableBlurBehindWindow = (PtrDwmEnableBlurBehindWindow)dwmLib.resolve("DwmEnableBlurBehindWindow"); @@ -164,9 +168,13 @@ bool QtWin::enableBlurBehindWindow(QWidget* widget, bool enable) bb.fEnable = enable; bb.dwFlags = DWM_BB_ENABLE; bb.hRgnBlur = NULL; + widget->setAttribute(Qt::WA_TranslucentBackground, enable); widget->setAttribute(Qt::WA_NoSystemBackground, enable); - hr = pDwmEnableBlurBehindWindow(widget->winId(), &bb); + // Qt5: setting WA_TranslucentBackground without the following line hides the widget!! + widget->setWindowOpacity(1); + + hr = pDwmEnableBlurBehindWindow(hwndOfWidget(widget) , &bb); if (SUCCEEDED(hr)) { result = true; windowNotifier()->addWidget(widget); @@ -202,16 +210,18 @@ bool QtWin::extendFrameIntoClientArea(QWidget* widget, int left, int top, int ri bool result = false; #ifdef Q_OS_WIN if (resolveLibs()) { - QLibrary dwmLib(QString::fromAscii("dwmapi")); + QLibrary dwmLib(QString::fromLatin1("dwmapi")); HRESULT hr = S_OK; MARGINS m = {left, right, top, bottom}; - hr = pDwmExtendFrameIntoClientArea(widget->winId(), &m); + hr = pDwmExtendFrameIntoClientArea(hwndOfWidget(widget), &m); if (SUCCEEDED(hr)) { result = true; windowNotifier()->addWidget(widget); widgetsBlurState.insert(widget, true); } widget->setAttribute(Qt::WA_TranslucentBackground, result); + // Qt5: setting WA_TranslucentBackground without the following line hides the widget!! + widget->setWindowOpacity(1); } #endif return result; @@ -230,7 +240,7 @@ QColor QtWin::colorizationColor() if (resolveLibs()) { DWORD color = 0; BOOL opaque = FALSE; - QLibrary dwmLib(QString::fromAscii("dwmapi")); + QLibrary dwmLib(QString::fromLatin1("dwmapi")); HRESULT hr = S_OK; hr = pDwmGetColorizationColor(&color, &opaque); if (SUCCEEDED(hr)) { @@ -242,6 +252,16 @@ QColor QtWin::colorizationColor() } #ifdef Q_OS_WIN +HWND QtWin::hwndOfWidget(const QWidget* widget) +{ + if (widget) { + return reinterpret_cast(widget->winId()); + } + else { + return 0; + } +} + WindowNotifier* QtWin::windowNotifier() { static WindowNotifier* windowNotifierInstance = 0; @@ -253,8 +273,15 @@ WindowNotifier* QtWin::windowNotifier() /* Notify all enabled windows that the DWM state changed */ +#if (QT_VERSION < 0x050000) bool WindowNotifier::winEvent(MSG* message, long* result) { +#else +bool WindowNotifier::nativeEvent(const QByteArray &eventType, void* _message, long* result) +{ + Q_UNUSED(eventType) + MSG* message = static_cast(_message); +#endif if (message && message->message == WM_DWMCOMPOSITIONCHANGED) { bool compositionEnabled = QtWin::isCompositionEnabled(); foreach(QWidget * widget, widgets) { @@ -270,7 +297,11 @@ bool WindowNotifier::winEvent(MSG* message, long* result) } } } +#if (QT_VERSION < 0x050000) return QWidget::winEvent(message, result); +#else + return QWidget::nativeEvent(eventType, _message, result); +#endif } #ifdef W7API diff --git a/src/lib/3rdparty/qtwin.h b/src/lib/3rdparty/qtwin.h index 24903dfc4..c2b02d915 100644 --- a/src/lib/3rdparty/qtwin.h +++ b/src/lib/3rdparty/qtwin.h @@ -38,6 +38,8 @@ * these functions will simply not do anything. */ #ifdef Q_OS_WIN +// Qt5 compile issue: http://comments.gmane.org/gmane.comp.lib.qt.user/4711 +#define NOMINMAX #ifdef W7API #include #include @@ -62,6 +64,9 @@ public: static QColor colorizationColor(); static void setupJumpList(); +#ifdef Q_OS_WIN + static HWND hwndOfWidget(const QWidget* widget); +#endif private: static WindowNotifier* windowNotifier(); diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index 5621143da..d8030fcc3 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -661,6 +661,8 @@ void QupZilla::loadSettings() m_usingTransparentBackground = true; applyBlurToMainWindow(); + update(); + //install event filter menuBar()->installEventFilter(this); m_navigationBar->installEventFilter(this); @@ -1998,8 +2000,15 @@ void QupZilla::moveToVirtualDesktop(int desktopId) #endif #ifdef Q_OS_WIN +#if (QT_VERSION < 0x050000) bool QupZilla::winEvent(MSG* message, long* result) { +#else +bool QupZilla::nativeEvent(const QByteArray &eventType, void* _message, long* result) +{ + Q_UNUSED(eventType) + MSG* message = static_cast(_message); +#endif if (message && message->message == WM_DWMCOMPOSITIONCHANGED) { Settings settings; settings.beginGroup("Browser-View-Settings"); @@ -2039,7 +2048,11 @@ bool QupZilla::winEvent(MSG* message, long* result) setUpdatesEnabled(true); } } +#if (QT_VERSION < 0x050000) return QMainWindow::winEvent(message, result); +#else + return QMainWindow::nativeEvent(eventType, _message, result); +#endif } void QupZilla::applyBlurToMainWindow(bool force) diff --git a/src/lib/app/qupzilla.h b/src/lib/app/qupzilla.h index 44cb7f6ba..9f1b464b5 100644 --- a/src/lib/app/qupzilla.h +++ b/src/lib/app/qupzilla.h @@ -208,7 +208,11 @@ private: void disconnectObjects(); #ifdef Q_OS_WIN +#if (QT_VERSION < 0x050000) bool winEvent(MSG* message, long* result); +#else + bool nativeEvent(const QByteArray &eventType, void* _message, long* result); +#endif bool eventFilter(QObject* object, QEvent* event); #endif diff --git a/src/lib/downloads/downloadmanager.cpp b/src/lib/downloads/downloadmanager.cpp index 3285212f8..9b6dd89aa 100644 --- a/src/lib/downloads/downloadmanager.cpp +++ b/src/lib/downloads/downloadmanager.cpp @@ -58,7 +58,7 @@ DownloadManager::DownloadManager(QWidget* parent) #ifdef W7TASKBAR if (QtWin::isRunningWindows7()) { - win7.init(this->winId()); + win7.init(QtWin::hwndOfWidget(this)); } #endif } @@ -116,8 +116,15 @@ void DownloadManager::startExternalManager(const QUrl &url) } #ifdef W7TASKBAR +#if (QT_VERSION < 0x050000) bool DownloadManager::winEvent(MSG* message, long* result) { +#else +bool DownloadManager::nativeEvent(const QByteArray &eventType, void* _message, long* result) +{ + Q_UNUSED(eventType) + MSG* message = static_cast(_message); +#endif return win7.winEvent(message, result); } #endif diff --git a/src/lib/downloads/downloadmanager.h b/src/lib/downloads/downloadmanager.h index aadd23778..8fd4a9887 100644 --- a/src/lib/downloads/downloadmanager.h +++ b/src/lib/downloads/downloadmanager.h @@ -80,7 +80,11 @@ public slots: #ifdef W7TASKBAR protected: +#if (QT_VERSION < 0x050000) virtual bool winEvent(MSG* message, long* result); +#else + virtual bool nativeEvent(const QByteArray &eventType, void* _message, long* result); +#endif #endif private slots: