1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[Qt5][Windows] Now QupZilla compiles with Qt5 on Windows (msvc).

-There are some issues when enabling blur effect!
This commit is contained in:
S. Razi Alavizadeh 2013-01-20 01:52:30 +03:30
parent 6072b7c4be
commit 6c3d210544
9 changed files with 82 additions and 10 deletions

View File

@ -32,7 +32,7 @@ EcWin7::EcWin7()
} }
// Init taskbar communication // Init taskbar communication
void EcWin7::init(WId wid) void EcWin7::init(HWND wid)
{ {
mWindowId = wid; mWindowId = wid;
mTaskbarMessageId = RegisterWindowMessage(L"TaskbarButtonCreated"); mTaskbarMessageId = RegisterWindowMessage(L"TaskbarButtonCreated");

View File

@ -27,7 +27,7 @@
// Windows only data definitions // Windows only data definitions
#ifdef W7TASKBAR #ifdef W7TASKBAR
#define NOMINMAX
#include <windows.h> #include <windows.h>
#include <initguid.h> #include <initguid.h>
#define CMIC_MASK_ASYNCOK SEE_MASK_ASYNCOK #define CMIC_MASK_ASYNCOK SEE_MASK_ASYNCOK
@ -45,7 +45,7 @@ public:
// Initialization methods // Initialization methods
EcWin7(); EcWin7();
void init(WId wid); void init(HWND wid);
bool winEvent(MSG* message, long* result); bool winEvent(MSG* message, long* result);
// Overlay icon handling // Overlay icon handling
@ -63,7 +63,7 @@ public:
void setProgressState(ToolBarProgressState state); void setProgressState(ToolBarProgressState state);
private: private:
WId mWindowId; HWND mWindowId;
UINT mTaskbarMessageId; UINT mTaskbarMessageId;
ITaskbarList3* mTaskbar; ITaskbarList3* mTaskbar;
HICON mOverlayIcon; HICON mOverlayIcon;

View File

@ -66,16 +66,24 @@ Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate)
Qt::HANDLE mutex; Qt::HANDLE mutex;
if (doCreate) { if (doCreate) {
#if (QT_VERSION < 0x050000)
QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
{ mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); }); { 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) { if (!mutex) {
qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
return 0; return 0;
} }
} }
else { else {
#if (QT_VERSION < 0x050000)
QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); },
{ mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); }); { 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 (!mutex) {
if (GetLastError() != ERROR_FILE_NOT_FOUND) { if (GetLastError() != ERROR_FILE_NOT_FOUND) {
qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); qErrnoWarning("QtLockedFile::lock(): OpenMutex failed");

View File

@ -84,7 +84,11 @@ public:
void removeWidget(QWidget* widget) { void removeWidget(QWidget* widget) {
widgets.removeAll(widget); widgets.removeAll(widget);
} }
#if (QT_VERSION < 0x050000)
bool winEvent(MSG* message, long* result); bool winEvent(MSG* message, long* result);
#else
bool nativeEvent(const QByteArray &eventType, void* _message, long* result);
#endif
private: private:
QWidgetList widgets; QWidgetList widgets;
@ -93,7 +97,7 @@ private:
static bool resolveLibs() static bool resolveLibs()
{ {
if (!pDwmIsCompositionEnabled) { if (!pDwmIsCompositionEnabled) {
QLibrary dwmLib(QString::fromAscii("dwmapi")); QLibrary dwmLib(QString::fromLatin1("dwmapi"));
pDwmIsCompositionEnabled = (PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled"); pDwmIsCompositionEnabled = (PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled");
pDwmExtendFrameIntoClientArea = (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea"); pDwmExtendFrameIntoClientArea = (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea");
pDwmEnableBlurBehindWindow = (PtrDwmEnableBlurBehindWindow)dwmLib.resolve("DwmEnableBlurBehindWindow"); pDwmEnableBlurBehindWindow = (PtrDwmEnableBlurBehindWindow)dwmLib.resolve("DwmEnableBlurBehindWindow");
@ -164,9 +168,13 @@ bool QtWin::enableBlurBehindWindow(QWidget* widget, bool enable)
bb.fEnable = enable; bb.fEnable = enable;
bb.dwFlags = DWM_BB_ENABLE; bb.dwFlags = DWM_BB_ENABLE;
bb.hRgnBlur = NULL; bb.hRgnBlur = NULL;
widget->setAttribute(Qt::WA_TranslucentBackground, enable); widget->setAttribute(Qt::WA_TranslucentBackground, enable);
widget->setAttribute(Qt::WA_NoSystemBackground, 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)) { if (SUCCEEDED(hr)) {
result = true; result = true;
windowNotifier()->addWidget(widget); windowNotifier()->addWidget(widget);
@ -202,16 +210,18 @@ bool QtWin::extendFrameIntoClientArea(QWidget* widget, int left, int top, int ri
bool result = false; bool result = false;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (resolveLibs()) { if (resolveLibs()) {
QLibrary dwmLib(QString::fromAscii("dwmapi")); QLibrary dwmLib(QString::fromLatin1("dwmapi"));
HRESULT hr = S_OK; HRESULT hr = S_OK;
MARGINS m = {left, right, top, bottom}; MARGINS m = {left, right, top, bottom};
hr = pDwmExtendFrameIntoClientArea(widget->winId(), &m); hr = pDwmExtendFrameIntoClientArea(hwndOfWidget(widget), &m);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
result = true; result = true;
windowNotifier()->addWidget(widget); windowNotifier()->addWidget(widget);
widgetsBlurState.insert(widget, true); widgetsBlurState.insert(widget, true);
} }
widget->setAttribute(Qt::WA_TranslucentBackground, result); widget->setAttribute(Qt::WA_TranslucentBackground, result);
// Qt5: setting WA_TranslucentBackground without the following line hides the widget!!
widget->setWindowOpacity(1);
} }
#endif #endif
return result; return result;
@ -230,7 +240,7 @@ QColor QtWin::colorizationColor()
if (resolveLibs()) { if (resolveLibs()) {
DWORD color = 0; DWORD color = 0;
BOOL opaque = FALSE; BOOL opaque = FALSE;
QLibrary dwmLib(QString::fromAscii("dwmapi")); QLibrary dwmLib(QString::fromLatin1("dwmapi"));
HRESULT hr = S_OK; HRESULT hr = S_OK;
hr = pDwmGetColorizationColor(&color, &opaque); hr = pDwmGetColorizationColor(&color, &opaque);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
@ -242,6 +252,16 @@ QColor QtWin::colorizationColor()
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
HWND QtWin::hwndOfWidget(const QWidget* widget)
{
if (widget) {
return reinterpret_cast<HWND>(widget->winId());
}
else {
return 0;
}
}
WindowNotifier* QtWin::windowNotifier() WindowNotifier* QtWin::windowNotifier()
{ {
static WindowNotifier* windowNotifierInstance = 0; static WindowNotifier* windowNotifierInstance = 0;
@ -253,8 +273,15 @@ WindowNotifier* QtWin::windowNotifier()
/* Notify all enabled windows that the DWM state changed */ /* Notify all enabled windows that the DWM state changed */
#if (QT_VERSION < 0x050000)
bool WindowNotifier::winEvent(MSG* message, long* result) 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<MSG*>(_message);
#endif
if (message && message->message == WM_DWMCOMPOSITIONCHANGED) { if (message && message->message == WM_DWMCOMPOSITIONCHANGED) {
bool compositionEnabled = QtWin::isCompositionEnabled(); bool compositionEnabled = QtWin::isCompositionEnabled();
foreach(QWidget * widget, widgets) { foreach(QWidget * widget, widgets) {
@ -270,7 +297,11 @@ bool WindowNotifier::winEvent(MSG* message, long* result)
} }
} }
} }
#if (QT_VERSION < 0x050000)
return QWidget::winEvent(message, result); return QWidget::winEvent(message, result);
#else
return QWidget::nativeEvent(eventType, _message, result);
#endif
} }
#ifdef W7API #ifdef W7API

View File

@ -38,6 +38,8 @@
* these functions will simply not do anything. * these functions will simply not do anything.
*/ */
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Qt5 compile issue: http://comments.gmane.org/gmane.comp.lib.qt.user/4711
#define NOMINMAX
#ifdef W7API #ifdef W7API
#include <ShlObj.h> #include <ShlObj.h>
#include <shlwapi.h> #include <shlwapi.h>
@ -62,6 +64,9 @@ public:
static QColor colorizationColor(); static QColor colorizationColor();
static void setupJumpList(); static void setupJumpList();
#ifdef Q_OS_WIN
static HWND hwndOfWidget(const QWidget* widget);
#endif
private: private:
static WindowNotifier* windowNotifier(); static WindowNotifier* windowNotifier();

View File

@ -661,6 +661,8 @@ void QupZilla::loadSettings()
m_usingTransparentBackground = true; m_usingTransparentBackground = true;
applyBlurToMainWindow(); applyBlurToMainWindow();
update();
//install event filter //install event filter
menuBar()->installEventFilter(this); menuBar()->installEventFilter(this);
m_navigationBar->installEventFilter(this); m_navigationBar->installEventFilter(this);
@ -1998,8 +2000,15 @@ void QupZilla::moveToVirtualDesktop(int desktopId)
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#if (QT_VERSION < 0x050000)
bool QupZilla::winEvent(MSG* message, long* result) 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<MSG*>(_message);
#endif
if (message && message->message == WM_DWMCOMPOSITIONCHANGED) { if (message && message->message == WM_DWMCOMPOSITIONCHANGED) {
Settings settings; Settings settings;
settings.beginGroup("Browser-View-Settings"); settings.beginGroup("Browser-View-Settings");
@ -2039,7 +2048,11 @@ bool QupZilla::winEvent(MSG* message, long* result)
setUpdatesEnabled(true); setUpdatesEnabled(true);
} }
} }
#if (QT_VERSION < 0x050000)
return QMainWindow::winEvent(message, result); return QMainWindow::winEvent(message, result);
#else
return QMainWindow::nativeEvent(eventType, _message, result);
#endif
} }
void QupZilla::applyBlurToMainWindow(bool force) void QupZilla::applyBlurToMainWindow(bool force)

View File

@ -208,7 +208,11 @@ private:
void disconnectObjects(); void disconnectObjects();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#if (QT_VERSION < 0x050000)
bool winEvent(MSG* message, long* result); bool winEvent(MSG* message, long* result);
#else
bool nativeEvent(const QByteArray &eventType, void* _message, long* result);
#endif
bool eventFilter(QObject* object, QEvent* event); bool eventFilter(QObject* object, QEvent* event);
#endif #endif

View File

@ -58,7 +58,7 @@ DownloadManager::DownloadManager(QWidget* parent)
#ifdef W7TASKBAR #ifdef W7TASKBAR
if (QtWin::isRunningWindows7()) { if (QtWin::isRunningWindows7()) {
win7.init(this->winId()); win7.init(QtWin::hwndOfWidget(this));
} }
#endif #endif
} }
@ -116,8 +116,15 @@ void DownloadManager::startExternalManager(const QUrl &url)
} }
#ifdef W7TASKBAR #ifdef W7TASKBAR
#if (QT_VERSION < 0x050000)
bool DownloadManager::winEvent(MSG* message, long* result) 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<MSG*>(_message);
#endif
return win7.winEvent(message, result); return win7.winEvent(message, result);
} }
#endif #endif

View File

@ -80,7 +80,11 @@ public slots:
#ifdef W7TASKBAR #ifdef W7TASKBAR
protected: protected:
#if (QT_VERSION < 0x050000)
virtual bool winEvent(MSG* message, long* result); virtual bool winEvent(MSG* message, long* result);
#else
virtual bool nativeEvent(const QByteArray &eventType, void* _message, long* result);
#endif
#endif #endif
private slots: private slots: