• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: 提交

MUtilities development repository


Commit MetaInfo

修订版c7a859c64cc0e87f694ca8663f4fe86de1aafabb (tree)
时间2017-01-07 07:10:01
作者jbuonagurio <jbuonagurio@expo...>
CommiterLoRd_MuldeR

Log Message

Added Qt5 support, contributed by John Buonagurio <jbuonagurio@exponent.com>.

更改概述

差异

--- a/README.html
+++ b/README.html
@@ -102,18 +102,28 @@ You should have received a copy of the GNU Lesser General Public
102102 License along with this library; if not, write to the Free Software
103103 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</code></pre>
104104 <h1 id="acknowledgement"><span class="header-section-number">6</span> Acknowledgement</h1>
105+<p>The following people have contributed in the development of the MUtilities library:</p>
106+<ul>
107+<li><strong>John Buonagurio &lt;<script type="text/javascript">
108+<!--
109+h='&#x65;&#120;&#112;&#x6f;&#110;&#x65;&#110;&#116;&#46;&#x63;&#x6f;&#x6d;';a='&#64;';n='&#106;&#98;&#x75;&#x6f;&#110;&#x61;&#x67;&#x75;&#114;&#x69;&#x6f;';e=n+a+h;
110+document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>');
111+// -->
112+</script><noscript>&#106;&#98;&#x75;&#x6f;&#110;&#x61;&#x67;&#x75;&#114;&#x69;&#x6f;&#32;&#x61;&#116;&#32;&#x65;&#120;&#112;&#x6f;&#110;&#x65;&#110;&#116;&#32;&#100;&#x6f;&#116;&#32;&#x63;&#x6f;&#x6d;</noscript>&gt;</strong><br />
113+Support for Qt5</li>
114+</ul>
105115 <p>The following third-party code is used in the MUtilities library:</p>
106116 <ul>
107117 <li><p><strong>Keccak/SHA-3 Reference Implementation</strong><br />
108118 Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer<br />
109119 No Copyright / Dedicated to the Public Domain</p></li>
110120 <li><p><strong>Natural Order String Comparison</strong><br />
111-Copyright (C) 2000, 2004 by Martin Pool <script type="text/javascript">
121+Copyright (C) 2000, 2004 by Martin Pool &lt;<script type="text/javascript">
112122 <!--
113123 h='&#x73;&#x6f;&#x75;&#114;&#x63;&#x65;&#102;&#114;&#x6f;&#x67;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#x6d;&#98;&#112;';e=n+a+h;
114124 document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>');
115125 // -->
116-</script><noscript>&#x6d;&#98;&#112;&#32;&#x61;&#116;&#32;&#x73;&#x6f;&#x75;&#114;&#x63;&#x65;&#102;&#114;&#x6f;&#x67;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript><br />
126+</script><noscript>&#x6d;&#98;&#112;&#32;&#x61;&#116;&#32;&#x73;&#x6f;&#x75;&#114;&#x63;&#x65;&#102;&#114;&#x6f;&#x67;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript>&gt;<br />
117127 Released under the zlib License</p></li>
118128 <li><p><strong>Adler-32 Checksum Algorithm (from zlib)</strong><br />
119129 Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler<br />
--- a/README.md
+++ b/README.md
@@ -70,6 +70,11 @@ This library is free software. It is released under the terms of the [*GNU Lesse
7070
7171 # Acknowledgement
7272
73+The following people have contributed in the development of the MUtilities library:
74+
75+* **John Buonagurio &lt;<jbuonagurio@exponent.com>&gt;**
76+ Support for Qt5
77+
7378 The following third-party code is used in the MUtilities library:
7479
7580 * **Keccak/SHA-3 Reference Implementation**
@@ -77,7 +82,7 @@ The following third-party code is used in the MUtilities library:
7782 No Copyright / Dedicated to the Public Domain
7883
7984 * **Natural Order String Comparison**
80- Copyright (C) 2000, 2004 by Martin Pool <mbp@sourcefrog.net>
85+ Copyright (C) 2000, 2004 by Martin Pool &lt;<mbp@sourcefrog.net>&gt;
8186 Released under the zlib License
8287
8388 * **Adler-32 Checksum Algorithm (from zlib)**
--- a/include/MUtils/OSSupport.h
+++ b/include/MUtils/OSSupport.h
@@ -28,6 +28,7 @@
2828 #include <QString>
2929 #include <QMap>
3030 #include <QDate>
31+#include <QWidget>
3132
3233 //Forward declaration
3334 class QFile;
--- a/src/GUI.cpp
+++ b/src/GUI.cpp
@@ -92,7 +92,7 @@ namespace MUtils
9292 QObject(parent),
9393 m_hIcon(hIcon)
9494 {
95- SendMessage(parent->winId(), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon));
95+ SendMessage(reinterpret_cast<HWND>(parent->winId()), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon));
9696 }
9797
9898 virtual ~WindowIconHelper(void)
@@ -115,7 +115,7 @@ bool MUtils::GUI::set_window_icon(QWidget *const window, const QIcon &icon, cons
115115 if((!icon.isNull()) && window->winId())
116116 {
117117 const int extend = (bIsBigIcon ? 32 : 16);
118- if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, extend, extend))
118+ if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(&icon, extend, extend))
119119 {
120120 new Internal::WindowIconHelper(window, hIcon, bIsBigIcon); /*will be free'd using QObject parent mechanism*/
121121 return true;
--- a/src/GUI_Win32.cpp
+++ b/src/GUI_Win32.cpp
@@ -88,7 +88,7 @@ bool MUtils::GUI::sysmenu_append(const QWidget *win, const unsigned int identifi
8888 {
8989 bool ok = false;
9090
91- if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE))
91+ if(HMENU hMenu = GetSystemMenu(reinterpret_cast<HWND>(win->winId()), FALSE))
9292 {
9393 ok = (AppendMenuW(hMenu, MF_SEPARATOR, 0, 0) == TRUE);
9494 ok = (AppendMenuW(hMenu, MF_STRING, identifier, MUTILS_WCHR(text)) == TRUE);
@@ -101,7 +101,7 @@ bool MUtils::GUI::sysmenu_update(const QWidget *win, const unsigned int identifi
101101 {
102102 bool ok = false;
103103
104- if(HMENU hMenu = ::GetSystemMenu(win->winId(), FALSE))
104+ if(HMENU hMenu = ::GetSystemMenu(reinterpret_cast<HWND>(win->winId()), FALSE))
105105 {
106106 ok = (ModifyMenu(hMenu, identifier, MF_STRING | MF_BYCOMMAND, identifier, MUTILS_WCHR(text)) == TRUE);
107107 }
@@ -121,7 +121,7 @@ bool MUtils::GUI::enable_close_button(const QWidget *win, const bool &bEnable)
121121 {
122122 bool ok = false;
123123
124- if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE))
124+ if(HMENU hMenu = GetSystemMenu(reinterpret_cast<HWND>(win->winId()), FALSE))
125125 {
126126 ok = (EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (bEnable ? MF_ENABLED : MF_GRAYED)) == TRUE);
127127 }
@@ -156,8 +156,8 @@ bool MUtils::GUI::bring_to_front(const QWidget *window)
156156 {
157157 for(int i = 0; (i < 5) && (!ret); i++)
158158 {
159- ret = (SetForegroundWindow(window->winId()) != FALSE);
160- SwitchToThisWindow(window->winId(), TRUE);
159+ ret = (SetForegroundWindow(reinterpret_cast<HWND>(window->winId())) != FALSE);
160+ SwitchToThisWindow(reinterpret_cast<HWND>(window->winId()), TRUE);
161161 }
162162 LockSetForegroundWindow(LSFW_LOCK);
163163 }
@@ -204,7 +204,7 @@ bool MUtils::GUI::sheet_of_glass(QWidget *const window)
204204
205205 //Enable the "sheet of glass" effect on this window
206206 MARGINS margins = {-1, -1, -1, -1};
207- if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(window->winId(), &margins))
207+ if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(reinterpret_cast<HWND>(window->winId()), &margins))
208208 {
209209 qWarning("DwmExtendFrameIntoClientArea function has failed! (error %d)", hr);
210210 return false;
@@ -215,7 +215,7 @@ bool MUtils::GUI::sheet_of_glass(QWidget *const window)
215215 memset(&bb, 0, sizeof(DWM_BLURBEHIND));
216216 bb.fEnable = TRUE;
217217 bb.dwFlags = DWM_BB_ENABLE;
218- if(HRESULT hr = dwmEnableBlurBehindWindowFun(window->winId(), &bb))
218+ if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast<HWND>(window->winId()), &bb))
219219 {
220220 qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
221221 return false;
@@ -258,7 +258,7 @@ bool MUtils::GUI::sheet_of_glass_update(QWidget *const window)
258258 memset(&bb, 0, sizeof(DWM_BLURBEHIND));
259259 bb.fEnable = TRUE;
260260 bb.dwFlags = DWM_BB_ENABLE;
261- if(HRESULT hr = dwmEnableBlurBehindWindowFun(window->winId(), &bb))
261+ if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast<HWND>(window->winId()), &bb))
262262 {
263263 qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
264264 return false;
--- a/src/OSSupport_Win32.cpp
+++ b/src/OSSupport_Win32.cpp
@@ -1236,7 +1236,7 @@ bool MUtils::OS::free_diskspace(const QString &path, quint64 &freeSpace)
12361236
12371237 bool MUtils::OS::shell_open(const QWidget *parent, const QString &url, const QString &parameters, const QString &directory, const bool explore)
12381238 {
1239- return ((int) ShellExecuteW((parent ? parent->winId() : NULL), (explore ? L"explore" : L"open"), MUTILS_WCHR(url), ((!parameters.isEmpty()) ? MUTILS_WCHR(parameters) : NULL), ((!directory.isEmpty()) ? MUTILS_WCHR(directory) : NULL), SW_SHOW)) > 32;
1239+ return ((int) ShellExecuteW((parent ? reinterpret_cast<HWND>(parent->winId()) : NULL), (explore ? L"explore" : L"open"), MUTILS_WCHR(url), ((!parameters.isEmpty()) ? MUTILS_WCHR(parameters) : NULL), ((!directory.isEmpty()) ? MUTILS_WCHR(directory) : NULL), SW_SHOW)) > 32;
12401240 }
12411241
12421242 bool MUtils::OS::shell_open(const QWidget *parent, const QString &url, const bool explore)
--- a/src/Startup.cpp
+++ b/src/Startup.cpp
@@ -37,6 +37,9 @@
3737 #include <QFont>
3838 #include <QMessageBox>
3939 #include <QtPlugin>
40+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
41+#include <QAbstractNativeEventFilter>
42+#endif
4043
4144 //CRT
4245 #include <string.h>
@@ -96,25 +99,58 @@ namespace MUtils
9699 // MESSAGE HANDLER
97100 ///////////////////////////////////////////////////////////////////////////////
98101
102+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
99103 static void qt_message_handler(QtMsgType type, const char *const msg)
100104 {
101- if((!msg) || (!(msg[0])))
105+ if (msg && msg[0])
102106 {
103- return;
107+ MUtils::Terminal::write(type, msg);
108+ if ((type == QtCriticalMsg) || (type == QtFatalMsg))
109+ {
110+ MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg)));
111+ }
104112 }
105-
106- MUtils::Terminal::write(type, msg);
107-
108- if((type == QtCriticalMsg) || (type == QtFatalMsg))
113+}
114+#else
115+#define qInstallMsgHandler(X) qInstallMessageHandler((X))
116+static void qt_message_handler(QtMsgType type, const QMessageLogContext&, const QString &msg)
117+{
118+ if (!msg.isEmpty())
109119 {
110- MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg)));
120+ MUtils::Terminal::write(type, msg.toUtf8().constData());
121+ if ((type == QtCriticalMsg) || (type == QtFatalMsg))
122+ {
123+ MUtils::OS::fatal_exit(MUTILS_WCHR(msg));
124+ }
111125 }
112126 }
127+#endif
113128
129+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
114130 static bool qt_event_filter(void *message, long *result)
115131 {
116132 return MUtils::OS::handle_os_message(message, result);
117133 }
134+#else
135+namespace MUtils
136+{
137+ namespace Startup
138+ {
139+ namespace Internal
140+ {
141+ class NativeEventFilter : public QAbstractNativeEventFilter
142+ {
143+ public:
144+ bool nativeEventFilter(const QByteArray&, void *message, long *result) Q_DECL_OVERRIDE
145+ {
146+ return MUtils::OS::handle_os_message(message, result);
147+ };
148+ };
149+ }
150+ }
151+}
152+static QScopedPointer<MUtils::Startup::Internal::NativeEventFilter> qt_event_filter;
153+#endif
118154
119155 ///////////////////////////////////////////////////////////////////////////////
120156 // STARTUP FUNCTION
@@ -229,7 +265,7 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &
229265 //Check Qt version
230266 #ifdef QT_BUILD_KEY
231267 qDebug("Using Qt v%s [%s], %s, %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"), QLibraryInfo::buildKey().toLatin1().constData());
232- qDebug("Compiled with Qt v%s [%s], %s\n", QT_VERSION_STR, QT_PACKAGEDATE_STR, QT_BUILD_KEY);
268+ qDebug("Compiled with Qt v%s, %s\n", QT_VERSION_STR, QT_BUILD_KEY);
233269 if(_stricmp(qVersion(), QT_VERSION_STR))
234270 {
235271 qFatal("%s", QApplication::tr("Executable '%1' requires Qt v%2, but found Qt v%3.").arg(executableName, QString::fromLatin1(QT_VERSION_STR), QString::fromLatin1(qVersion())).toLatin1().constData());
@@ -242,7 +278,7 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &
242278 }
243279 #else
244280 qDebug("Using Qt v%s [%s], %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"));
245- qDebug("Compiled with Qt v%s [%s]\n", QT_VERSION_STR, QT_PACKAGEDATE_STR);
281+ qDebug("Compiled with Qt v%s\n", QT_VERSION_STR);
246282 #endif
247283
248284 //Check the Windows version
@@ -298,7 +334,12 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &
298334 application->setApplicationName(appName);
299335 application->setOrganizationName("LoRd_MuldeR");
300336 application->setOrganizationDomain("mulder.at.gg");
337+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
301338 application->setEventFilter(qt_event_filter);
339+#else
340+ qt_event_filter.reset(new Internal::NativeEventFilter);
341+ application->installNativeEventFilter(qt_event_filter.data());
342+#endif
302343
303344 //Check for supported image formats
304345 QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
--- a/src/Taskbar7_Win32.cpp
+++ b/src/Taskbar7_Win32.cpp
@@ -25,9 +25,15 @@
2525 #include <MUtils/OSSupport.h>
2626 #include <MUtils/Exception.h>
2727
28+//Internal
29+#include "Utils_Win32.h"
30+
2831 //Qt
2932 #include <QWidget>
3033 #include <QIcon>
34+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
35+#include <QtWinExtras>
36+#endif
3137
3238 //Windows includes
3339 #define NOMINMAX
@@ -153,15 +159,15 @@ bool MUtils::Taskbar7::setOverlayIcon(const QIcon *const icon, const QString &in
153159 HRESULT result = HRESULT(-1);
154160 if(icon)
155161 {
156- if(const HICON hIcon = icon->pixmap(16,16).toWinHICON())
162+ if(const HICON hIcon = (HICON)MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16))
157163 {
158- result = p->taskbarList->SetOverlayIcon(m_window->winId(), hIcon, MUTILS_WCHR(info));
164+ result = p->taskbarList->SetOverlayIcon(reinterpret_cast<HWND>(m_window->winId()), hIcon, MUTILS_WCHR(info));
159165 DestroyIcon(hIcon);
160166 }
161167 }
162168 else
163169 {
164- result = p->taskbarList->SetOverlayIcon(m_window->winId(), NULL, MUTILS_WCHR(info));
170+ result = p->taskbarList->SetOverlayIcon(reinterpret_cast<HWND>(m_window->winId()), NULL, MUTILS_WCHR(info));
165171 }
166172 return SUCCEEDED(result);
167173 }
--- a/src/Terminal_Win32.cpp
+++ b/src/Terminal_Win32.cpp
@@ -419,7 +419,7 @@ void MUtils::Terminal::set_icon(const QIcon &icon)
419419
420420 if(g_terminal_attached && (!(icon.isNull() || MUtils::OS::running_on_wine())))
421421 {
422- if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16))
422+ if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(&icon, 16, 16))
423423 {
424424 typedef BOOL(__stdcall *SetConsoleIconFun)(HICON);
425425 bool success = false;
--- a/src/Utils_Win32.cpp
+++ b/src/Utils_Win32.cpp
@@ -25,6 +25,7 @@
2525 #ifndef _INC_WINDOWS
2626 #define WIN32_LEAN_AND_MEAN 1
2727 #include <Windows.h>
28+#include <ObjIdl.h> // required by QWinMime in QtWinExtras
2829 #endif //_INC_WINDOWS
2930
3031 //Qt
@@ -33,19 +34,29 @@
3334 #include <QReadWriteLock>
3435 #include <QLibrary>
3536 #include <QHash>
37+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
38+#include <QtWinExtras>
39+#endif
40+
41+//Qt5 support
42+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
43+#define PIXMAP2HICON(X) QtWin::toHICON((X))
44+#else
45+#define PIXMAP2HICON(X) (X).toWinHICON()
46+#endif
3647
3748 ///////////////////////////////////////////////////////////////////////////////
3849 // QICON TO HICON
3950 ///////////////////////////////////////////////////////////////////////////////
4051
41-uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon &icon, const int w, const int h)
52+uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon *const icon, const int w, const int h)
4253 {
43- if(!icon.isNull())
54+ if(!icon->isNull())
4455 {
45- QPixmap pixmap = icon.pixmap(w, h);
56+ QPixmap pixmap = icon->pixmap(w, h);
4657 if(!pixmap.isNull())
4758 {
48- return (uintptr_t) pixmap.toWinHICON();
59+ return (uintptr_t) PIXMAP2HICON(pixmap);
4960 }
5061 }
5162 return NULL;
--- a/src/Utils_Win32.h
+++ b/src/Utils_Win32.h
@@ -29,7 +29,7 @@ namespace MUtils
2929 {
3030 namespace Win32Utils
3131 {
32- uintptr_t qicon_to_hicon(const QIcon &icon, const int w, const int h);
32+ uintptr_t qicon_to_hicon(const QIcon *const icon, const int w, const int h);
3333 const uintptr_t &resolve_helper(const QString &libraryName, const QString &functionName);
3434
3535 template<class T>
Show on old repository browser