diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-22 21:58:37 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-22 21:58:45 +0200 |
commit | 2111bf00fef0185d70d3247e74c2c57080711ee0 (patch) | |
tree | 276558c07b3f22e4e5905ab093dc71e02df24fe9 | |
parent | 53f0b43a4bfa65ad62bb0c144bab7236ad322b8c (diff) | |
parent | 881bda9e6ecdd8729edf7df68f94f72f5d7c9042 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: I4f4ab05b2de67cd4b1d29b294b96a8c9ffb964b2
27 files changed, 846 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore index a48134a899..50b53db3f7 100644 --- a/.gitignore +++ b/.gitignore @@ -181,6 +181,8 @@ tests/auto/cmake/build *.exe.embed.manifest *.exe_manifest.rc *.exe_manifest.res +*.appxmanifest +.qmake.winrt_uuid_* # MinGW generated files *.Debug diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index c8dd589673..c8c8f993d3 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -80,7 +80,7 @@ static const int xpmRgbTblSize = 657; static const struct XPMRGBData { uint value; - const char *name; + const char name[21]; } xpmRgbTbl[] = { { QRGB(240,248,255), "aliceblue" }, { QRGB(250,235,215), "antiquewhite" }, diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index c237d80d34..966ab3fcdb 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -60,7 +60,7 @@ using namespace QCss; struct QCssKnownValue { - const char *name; + const char name[28]; quint64 id; }; diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 7bca50325c..d18d432f46 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE // see also tst_qtextdocumentfragment.cpp #define MAX_ENTITY 258 -static const struct QTextHtmlEntity { const char *name; quint16 code; } entities[MAX_ENTITY]= { +static const struct QTextHtmlEntity { const char name[9]; quint16 code; } entities[]= { { "AElig", 0x00c6 }, { "AMP", 38 }, { "Aacute", 0x00c1 }, @@ -320,6 +320,7 @@ static const struct QTextHtmlEntity { const char *name; quint16 code; } entities { "zwj", 0x200d }, { "zwnj", 0x200c } }; +Q_STATIC_ASSERT(MAX_ENTITY == sizeof entities / sizeof *entities); #if defined(Q_CC_MSVC) && _MSC_VER < 1600 bool operator<(const QTextHtmlEntity &entity1, const QTextHtmlEntity &entity2) diff --git a/src/gui/text/qtexthtmlparser_p.h b/src/gui/text/qtexthtmlparser_p.h index 4c0dd967f9..38c9108f75 100644 --- a/src/gui/text/qtexthtmlparser_p.h +++ b/src/gui/text/qtexthtmlparser_p.h @@ -144,7 +144,7 @@ enum QTextHTMLElements { struct QTextHtmlElement { - const char *name; + const char name[11]; QTextHTMLElements id; enum DisplayMode { DisplayBlock, DisplayInline, DisplayTable, DisplayNone } displayMode; }; diff --git a/src/platformheaders/xcbfunctions/qxcbwindowfunctions.h b/src/platformheaders/xcbfunctions/qxcbwindowfunctions.h index 149faadfda..b6c3b1db73 100644 --- a/src/platformheaders/xcbfunctions/qxcbwindowfunctions.h +++ b/src/platformheaders/xcbfunctions/qxcbwindowfunctions.h @@ -75,6 +75,14 @@ public: return QPlatformHeaderHelper::callPlatformFunction<void, SetWmWindowType, QWindow *, WmWindowType>(setWmWindowTypeIdentifier(), window, type); } + typedef void (*SetWmWindowRole)(QWindow *window, const QByteArray &role); + static const QByteArray setWmWindowRoleIdentifier() { return QByteArrayLiteral("XcbSetWmWindowRole"); } + + static void setWmWindowRole(QWindow *window, const QByteArray &role) + { + return QPlatformHeaderHelper::callPlatformFunction<void, SetWmWindowRole, QWindow *, const QByteArray &>(setWmWindowRoleIdentifier(), window, role); + } + typedef void (*SetWmWindowIconText)(QWindow *window, const QString &text); static const QByteArray setWmWindowIconTextIdentifier() { return QByteArrayLiteral("XcbSetWmWindowIconText"); } static void setWmWindowIconText(QWindow *window, const QString &text) diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp index f6d911d646..49eb7cfdec 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp @@ -447,7 +447,7 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::boundingBox(glyph_t g) width, height, advanceWidth, - advanceHeight); + 0); } else { qErrnoWarning("%s: GetDesignGlyphMetrics failed", __FUNCTION__); } diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index ad32e63cad..ad32c046df 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -763,10 +763,11 @@ void QWinRTScreen::addWindow(QWindow *window) { Q_D(QWinRTScreen); qCDebug(lcQpaWindows) << __FUNCTION__ << window; - if (window == topWindow()) + if (window == topWindow() || window->surfaceClass() == QSurface::Offscreen) return; d->visibleWindows.prepend(window); + updateWindowTitle(window->title()); QWindowSystemInterface::handleWindowActivated(window, Qt::OtherFocusReason); handleExpose(); QWindowSystemInterface::flushWindowSystemEvents(); @@ -785,7 +786,7 @@ void QWinRTScreen::removeWindow(QWindow *window) if (!d->visibleWindows.removeAll(window)) return; if (wasTopWindow) - QWindowSystemInterface::handleWindowActivated(window, Qt::OtherFocusReason); + QWindowSystemInterface::handleWindowActivated(Q_NULLPTR, Qt::OtherFocusReason); handleExpose(); QWindowSystemInterface::flushWindowSystemEvents(); #if _MSC_VER >= 1900 && !defined(QT_NO_DRAGANDDROP) @@ -807,6 +808,8 @@ void QWinRTScreen::lower(QWindow *window) const bool wasTopWindow = window == topWindow(); if (wasTopWindow && d->visibleWindows.size() == 1) return; + if (window->surfaceClass() == QSurface::Offscreen) + return; d->visibleWindows.removeAll(window); d->visibleWindows.append(window); if (wasTopWindow) @@ -814,15 +817,10 @@ void QWinRTScreen::lower(QWindow *window) handleExpose(); } -void QWinRTScreen::updateWindowTitle() +void QWinRTScreen::updateWindowTitle(const QString &title) { Q_D(QWinRTScreen); - QWindow *window = topWindow(); - if (!window) - return; - - const QString title = window->title(); HStringReference titleRef(reinterpret_cast<LPCWSTR>(title.utf16()), title.length()); HRESULT hr = d->view->put_Title(titleRef.Get()); RETURN_VOID_IF_FAILED("Unable to set window title"); diff --git a/src/plugins/platforms/winrt/qwinrtscreen.h b/src/plugins/platforms/winrt/qwinrtscreen.h index 5cada9726d..0e753b748b 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.h +++ b/src/plugins/platforms/winrt/qwinrtscreen.h @@ -109,7 +109,7 @@ public: void raise(QWindow *window); void lower(QWindow *window); - void updateWindowTitle(); + void updateWindowTitle(const QString &title); ABI::Windows::UI::Core::ICoreWindow *coreWindow() const; ABI::Windows::UI::Xaml::IDependencyObject *canvas() const; diff --git a/src/plugins/platforms/winrt/qwinrtwindow.cpp b/src/plugins/platforms/winrt/qwinrtwindow.cpp index 606ca22bcd..5b82183d40 100644 --- a/src/plugins/platforms/winrt/qwinrtwindow.cpp +++ b/src/plugins/platforms/winrt/qwinrtwindow.cpp @@ -191,6 +191,8 @@ QWinRTWindow::~QWinRTWindow() }); RETURN_VOID_IF_FAILED("Failed to completely destroy window resources, likely because the application is shutting down"); + d->screen->removeWindow(window()); + if (!d->surface) return; @@ -282,7 +284,9 @@ void QWinRTWindow::setWindowTitle(const QString &title) { Q_D(QWinRTWindow); d->windowTitle = title; - d->screen->updateWindowTitle(); + + if (d->screen->topWindow() == window()) + d->screen->updateWindowTitle(title); } void QWinRTWindow::raise() diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index a8d401e15b..a3e8da7df8 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -364,6 +364,9 @@ QFunctionPointer QXcbNativeInterface::platformFunction(const QByteArray &functio if (function == QXcbWindowFunctions::setWmWindowTypeIdentifier()) return QFunctionPointer(QXcbWindowFunctions::SetWmWindowType(QXcbWindow::setWmWindowTypeStatic)); + if (function == QXcbWindowFunctions::setWmWindowRoleIdentifier()) + return QFunctionPointer(QXcbWindowFunctions::SetWmWindowRole(QXcbWindow::setWmWindowRoleStatic)); + if (function == QXcbWindowFunctions::setWmWindowIconTextIdentifier()) return QFunctionPointer(QXcbWindowFunctions::SetWmWindowIconText(QXcbWindow::setWindowIconTextStatic)); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index a39ff01afd..6dda005bd9 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -304,6 +304,7 @@ static QWindow *childWindowAt(QWindow *win, const QPoint &p) } static const char *wm_window_type_property_id = "_q_xcb_wm_window_type"; +static const char *wm_window_role_property_id = "_q_xcb_wm_window_role"; QXcbWindow::QXcbWindow(QWindow *window) : QPlatformWindow(window) @@ -586,6 +587,11 @@ void QXcbWindow::create() setOpacity(opacity); if (window()->isTopLevel()) setWindowIcon(window()->icon()); + + if (window()->dynamicPropertyNames().contains(wm_window_role_property_id)) { + QByteArray wmWindowRole = window()->property(wm_window_role_property_id).toByteArray(); + setWmWindowRole(wmWindowRole); + } } QXcbWindow::~QXcbWindow() @@ -1720,6 +1726,14 @@ void QXcbWindow::setWindowIconTextStatic(QWindow *window, const QString &text) static_cast<QXcbWindow *>(window->handle())->setWindowIconText(text); } +void QXcbWindow::setWmWindowRoleStatic(QWindow *window, const QByteArray &role) +{ + if (window->handle()) + static_cast<QXcbWindow *>(window->handle())->setWmWindowRole(role); + else + window->setProperty(wm_window_role_property_id, role); +} + uint QXcbWindow::visualIdStatic(QWindow *window) { if (window && window->handle()) @@ -1885,6 +1899,13 @@ void QXcbWindow::setWmWindowType(QXcbWindowFunctions::WmWindowTypes types, Qt::W xcb_flush(xcb_connection()); } +void QXcbWindow::setWmWindowRole(const QByteArray &role) +{ + Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, + atom(QXcbAtom::WM_WINDOW_ROLE), XCB_ATOM_STRING, 8, + role.size(), role.constData())); +} + void QXcbWindow::setParentRelativeBackPixmapStatic(QWindow *window) { if (window->handle()) diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index e7190b1733..f62938ba8a 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -151,10 +151,12 @@ public: void updateNetWmUserTime(xcb_timestamp_t timestamp); static void setWmWindowTypeStatic(QWindow *window, QXcbWindowFunctions::WmWindowTypes windowTypes); + static void setWmWindowRoleStatic(QWindow *window, const QByteArray &role); static uint visualIdStatic(QWindow *window); QXcbWindowFunctions::WmWindowTypes wmWindowTypes() const; void setWmWindowType(QXcbWindowFunctions::WmWindowTypes types, Qt::WindowFlags flags); + void setWmWindowRole(const QByteArray &role); static void setWindowIconTextStatic(QWindow *window, const QString &text); diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 703af6b677..f3aaa7c89d 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -72,6 +72,9 @@ #if defined(HAVE_XCTEST) #include <QtTest/private/qxctestlogger_p.h> #endif +#if defined Q_OS_MACOS +#include <QtTest/private/qtestutil_macos_p.h> +#endif #include <numeric> #include <algorithm> @@ -1648,6 +1651,9 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) #if defined(Q_OS_MACX) bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0); IOPMAssertionID powerID; + + // Don't restore saved window state for auto tests. + QTestPrivate::disableWindowRestore(); #endif #ifndef QT_NO_EXCEPTIONS try { diff --git a/src/testlib/qtestutil_macos.mm b/src/testlib/qtestutil_macos.mm new file mode 100644 index 0000000000..852c9f75f2 --- /dev/null +++ b/src/testlib/qtestutil_macos.mm @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtTest module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtestutil_macos_p.h" + +#import <AppKit/AppKit.h> + +QT_BEGIN_NAMESPACE + +namespace QTestPrivate { + + /*! \internal + + Disables restoration of previously saved window state. This causes tests + to start with a clean slate and prevents the "previous restore failed" + dialog from showing if there was a test crash. + */ + void disableWindowRestore() { + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ApplePersistenceIgnoreState"]; + } +} + +QT_END_NAMESPACE diff --git a/src/testlib/qtestutil_macos_p.h b/src/testlib/qtestutil_macos_p.h new file mode 100644 index 0000000000..85f9ace82f --- /dev/null +++ b/src/testlib/qtestutil_macos_p.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtTest module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTESTUTIL_MACOS_H +#define QTESTUTIL_MACOS_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <qglobal.h> +#import <objc/objc.h> + +QT_BEGIN_NAMESPACE + +namespace QTestPrivate { + void disableWindowRestore(); +} + +QT_END_NAMESPACE + +#endif diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro index 372a69c3ed..b4ac077e86 100644 --- a/src/testlib/testlib.pro +++ b/src/testlib/testlib.pro @@ -77,7 +77,12 @@ wince: LIBS += \ mac { LIBS += -framework Security - osx: LIBS += -framework ApplicationServices -framework IOKit + + macos { + HEADERS += qtestutil_macos_p.h + OBJECTIVE_SOURCES += qtestutil_macos.mm + LIBS += -framework Foundation -framework ApplicationServices -framework IOKit + } # XCTest support (disabled for now) false:!lessThan(QMAKE_XCODE_VERSION, "6.0") { diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 5f8676697d..ba02728d7c 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1482,6 +1482,9 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO data.window_flags = win->flags(); + if (!topData()->role.isNull()) + QXcbWindowFunctions::setWmWindowRole(win, topData()->role.toLatin1()); + QBackingStore *store = q->backingStore(); if (!store) { @@ -6359,13 +6362,11 @@ QString QWidget::windowRole() const */ void QWidget::setWindowRole(const QString &role) { -#if defined(Q_DEAD_CODE_FROM_QT4_X11) Q_D(QWidget); + d->createTLExtra(); d->topData()->role = role; - d->setWindowRole(); -#else - Q_UNUSED(role) -#endif + if (windowHandle()) + QXcbWindowFunctions::setWmWindowRole(windowHandle(), role.toLatin1()); } /*! diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index 4d37c7f682..ac8902c9e6 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -67,7 +67,9 @@ QT_BEGIN_NAMESPACE extern QRegion qt_dirtyRegion(QWidget *); +#ifndef QT_NO_OPENGL Q_GLOBAL_STATIC(QPlatformTextureList, qt_dummy_platformTextureList) +#endif /** * Flushes the contents of the \a backingStore into the screen area of \a widget. diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 44555c3058..5c046d0130 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -210,7 +210,7 @@ enum PseudoElement { struct PseudoElementInfo { QStyle::SubControl subControl; - const char *name; + const char name[19]; }; static const PseudoElementInfo knownPseudoElements[NumPseudoElements] = { @@ -595,7 +595,7 @@ public: Q_DECLARE_TYPEINFO(QRenderRule, Q_MOVABLE_TYPE); /////////////////////////////////////////////////////////////////////////////////////////// -static const char *const knownStyleHints[] = { +static const char knownStyleHints[][45] = { "activate-on-singleclick", "alignment", "arrow-keys-navigate-into-children", diff --git a/tests/manual/cocoa/menurama/main.cpp b/tests/manual/cocoa/menurama/main.cpp new file mode 100644 index 0000000000..98d96b1491 --- /dev/null +++ b/tests/manual/cocoa/menurama/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the qtbase module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "menuramaapplication.h" + +int main(int argc, char *argv[]) +{ + MenuramaApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/tests/manual/cocoa/menurama/mainwindow.cpp b/tests/manual/cocoa/menurama/mainwindow.cpp new file mode 100644 index 0000000000..db8fdafc21 --- /dev/null +++ b/tests/manual/cocoa/menurama/mainwindow.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the qtbase module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "menuramaapplication.h" +#include <QDebug> + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + startTimer(1000); + + connect(ui->menuAfter_aboutToShow, &QMenu::aboutToShow, [=] { + menuApp->populateMenu(ui->menuAfter_aboutToShow, true /*clear*/); + }); + + connect(ui->menuDynamic_Stuff, &QMenu::aboutToShow, [=] { + menuApp->addDynMenu(QLatin1String("Added After aboutToShow()"), ui->menuDynamic_Stuff); + }); + + connect(ui->pushButton, &QPushButton::clicked, [=] { + menuApp->populateMenu(ui->menuOn_Click, true /*clear*/); + }); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::timerEvent(QTimerEvent *) +{ + menuApp->populateMenu(ui->menuPopulated_by_Timer, true /*clear*/); + menuApp->addDynMenu(QLatin1String("Added by Timer"), ui->menuDynamic_Stuff); +} + +void MainWindow::enableStuffMenu(bool enable) +{ + ui->menuStuff->setEnabled(enable); +} + +void MainWindow::on_actionQuit_triggered() +{ + menuApp->exit(); +} diff --git a/tests/manual/cocoa/menurama/mainwindow.h b/tests/manual/cocoa/menurama/mainwindow.h new file mode 100644 index 0000000000..b9cb52d908 --- /dev/null +++ b/tests/manual/cocoa/menurama/mainwindow.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the qtbase module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +protected: + void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE; + +public slots: + void enableStuffMenu(bool enable); + +private slots: + void on_actionQuit_triggered(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/tests/manual/cocoa/menurama/mainwindow.ui b/tests/manual/cocoa/menurama/mainwindow.ui new file mode 100644 index 0000000000..f73b41b861 --- /dev/null +++ b/tests/manual/cocoa/menurama/mainwindow.ui @@ -0,0 +1,289 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>566</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <widget class="QCheckBox" name="checkBox"> + <property name="geometry"> + <rect> + <x>10</x> + <y>40</y> + <width>151</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Enable "Stuff" Menu</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>321</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>The "Help" menu should NOT be visible.</string> + </property> + </widget> + <widget class="QPushButton" name="pushButton"> + <property name="geometry"> + <rect> + <x>10</x> + <y>80</y> + <width>211</width> + <height>32</height> + </rect> + </property> + <property name="text"> + <string>Populate Dynamic Submenu</string> + </property> + </widget> + </widget> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>566</width> + <height>22</height> + </rect> + </property> + <widget class="QMenu" name="menuStuff"> + <property name="title"> + <string>Stuff</string> + </property> + <widget class="QMenu" name="menuSubmenu"> + <property name="title"> + <string>Submenu</string> + </property> + <widget class="QMenu" name="menuMore_Submenu_2"> + <property name="title"> + <string>More Submenu</string> + </property> + <addaction name="actionMOARH"/> + </widget> + <addaction name="actionWith_More_Stuff"/> + <addaction name="menuMore_Submenu_2"/> + </widget> + <widget class="QMenu" name="menuDisabled_Submenu"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="title"> + <string>Disabled Submenu</string> + </property> + <widget class="QMenu" name="menuMore_Submenu"> + <property name="title"> + <string>More Submenu</string> + </property> + <addaction name="actionShould_be_Disabled_Too"/> + </widget> + <addaction name="actionShould_be_Disabled"/> + <addaction name="menuMore_Submenu"/> + </widget> + <addaction name="actionItem"/> + <addaction name="menuSubmenu"/> + <addaction name="actionDisabled_Item"/> + <addaction name="menuDisabled_Submenu"/> + </widget> + <widget class="QMenu" name="menuDisabled_Stuff"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="title"> + <string>Disabled Stuff</string> + </property> + <widget class="QMenu" name="menuSubmenu_2"> + <property name="title"> + <string>Disabled Submenu</string> + </property> + <widget class="QMenu" name="menuSubsubmenu"> + <property name="title"> + <string>Disabled Subsubmenu</string> + </property> + <addaction name="actionWith_its_own_Stuff"/> + </widget> + <addaction name="actionMore_Disabled_Stuff"/> + <addaction name="menuSubsubmenu"/> + </widget> + <addaction name="actionItem_2"/> + <addaction name="menuSubmenu_2"/> + </widget> + <widget class="QMenu" name="menuShould_NOT_Be_Visible"> + <property name="title"> + <string>Should NOT Be Visible</string> + </property> + <addaction name="actionAbout"/> + </widget> + <widget class="QMenu" name="menuHelp"> + <property name="title"> + <string>Help</string> + </property> + <addaction name="actionAbout_Qt"/> + </widget> + <widget class="QMenu" name="menuDynamic_Stuff"> + <property name="title"> + <string>Dynamic Stuff</string> + </property> + <widget class="QMenu" name="menuAfter_aboutToShow"> + <property name="title"> + <string>Populated After aboutToShow()</string> + </property> + </widget> + <widget class="QMenu" name="menuOn_Click"> + <property name="title"> + <string>Click Button to Populate</string> + </property> + </widget> + <widget class="QMenu" name="menuPopulated_by_Timer"> + <property name="title"> + <string>Populated by Timer</string> + </property> + </widget> + <addaction name="menuOn_Click"/> + <addaction name="menuAfter_aboutToShow"/> + <addaction name="menuPopulated_by_Timer"/> + </widget> + <widget class="QMenu" name="menuFile"> + <property name="title"> + <string>File</string> + </property> + <addaction name="actionNew"/> + <addaction name="actionNo_Empty_Spaces_Below"/> + <addaction name="actionQuit"/> + </widget> + <addaction name="menuFile"/> + <addaction name="menuStuff"/> + <addaction name="menuDisabled_Stuff"/> + <addaction name="menuShould_NOT_Be_Visible"/> + <addaction name="menuDynamic_Stuff"/> + <addaction name="menuHelp"/> + </widget> + <widget class="QToolBar" name="mainToolBar"> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + </widget> + <widget class="QStatusBar" name="statusBar"/> + <action name="actionWith_More_Stuff"> + <property name="text"> + <string>With More Stuff</string> + </property> + </action> + <action name="actionDisabled_Item"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Disabled Item</string> + </property> + </action> + <action name="actionItem"> + <property name="text"> + <string>Item</string> + </property> + </action> + <action name="actionShould_be_Disabled"> + <property name="text"> + <string>Should be Disabled</string> + </property> + </action> + <action name="actionShould_be_Disabled_Too"> + <property name="text"> + <string>Should be Disabled Too</string> + </property> + </action> + <action name="actionMOARH"> + <property name="text"> + <string>MOAR!!</string> + </property> + </action> + <action name="actionItem_2"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Disabled Item</string> + </property> + </action> + <action name="actionMore_Disabled_Stuff"> + <property name="text"> + <string>More Disabled Stuff</string> + </property> + </action> + <action name="actionWith_its_own_Stuff"> + <property name="text"> + <string>With its own Disabled Stuff</string> + </property> + </action> + <action name="actionAbout"> + <property name="text"> + <string>About</string> + </property> + </action> + <action name="actionAbout_Qt"> + <property name="text"> + <string>About Qt</string> + </property> + </action> + <action name="actionQuit"> + <property name="text"> + <string>Exit</string> + </property> + </action> + <action name="actionNew"> + <property name="text"> + <string>New...</string> + </property> + </action> + <action name="actionNo_Empty_Spaces_Below"> + <property name="text"> + <string>No Empty Spaces Below</string> + </property> + </action> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections> + <connection> + <sender>checkBox</sender> + <signal>toggled(bool)</signal> + <receiver>MainWindow</receiver> + <slot>enableStuffMenu(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>62</x> + <y>94</y> + </hint> + <hint type="destinationlabel"> + <x>72</x> + <y>73</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>enableStuffMenu(bool)</slot> + </slots> +</ui> diff --git a/tests/manual/cocoa/menurama/menurama.pro b/tests/manual/cocoa/menurama/menurama.pro new file mode 100644 index 0000000000..da6f224e0d --- /dev/null +++ b/tests/manual/cocoa/menurama/menurama.pro @@ -0,0 +1,22 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-08-10T14:21:46 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = Menurama +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + menuramaapplication.cpp + +HEADERS += mainwindow.h \ + menuramaapplication.h + +FORMS += mainwindow.ui diff --git a/tests/manual/cocoa/menurama/menuramaapplication.cpp b/tests/manual/cocoa/menurama/menuramaapplication.cpp new file mode 100644 index 0000000000..534d5fa371 --- /dev/null +++ b/tests/manual/cocoa/menurama/menuramaapplication.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the qtbase module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "menuramaapplication.h" + +MenuramaApplication::MenuramaApplication(int argc, char **argv) + : QApplication (argc, argv) +{ +#if 0 + QMenuBar *mb = new QMenuBar(); + QMenu *menu = mb->addMenu("App Dynamic"); + QMenu *dynMenu = menu->addMenu("After aboutToShow()"); + connect(dynMenu, &QMenu::aboutToShow, [=] { + qDebug() << "aboutToShow(), populating" << dynMenu; + menuApp->populateMenu(dynMenu, true /*clear*/); + }); +#endif +} + +void MenuramaApplication::populateMenu(QMenu *menu, bool clear) +{ + if (clear) + menu->clear(); + + static const char *sym[] = { "Foo", "Bar", "Baz", "Huux" }; + static int id = 0; + for (unsigned i = 0; i < sizeof(sym) / sizeof(sym[0]); i++) + menu->addAction(QStringLiteral("%1 — %2 %3 ") + .arg(menu->title()).arg(sym[i]).arg(id)); + ++id; +} + +void MenuramaApplication::addDynMenu(QLatin1String title, QMenu *parentMenu) +{ + foreach (QAction *a, parentMenu->actions()) + if (a->text() == title) { + parentMenu->removeAction(a); + break; + } + + QMenu *subMenu = new QMenu(title, parentMenu); + populateMenu(subMenu, false /*clear*/); + parentMenu->addMenu(subMenu); +} diff --git a/tests/manual/cocoa/menurama/menuramaapplication.h b/tests/manual/cocoa/menurama/menuramaapplication.h new file mode 100644 index 0000000000..07c8da27a1 --- /dev/null +++ b/tests/manual/cocoa/menurama/menuramaapplication.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the qtbase module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MENURAMAAPPLICATION_H +#define MENURAMAAPPLICATION_H + +#include <QtWidgets> + +#define menuApp (static_cast<MenuramaApplication *>(QCoreApplication::instance())) + +class MenuramaApplication : public QApplication +{ +public: + MenuramaApplication(int argc, char **argv); + void addDynMenu(QLatin1String title, QMenu *parentMenu); + +public slots: + void populateMenu(QMenu *menu, bool clear); +}; + +#endif // MENURAMAAPPLICATION_H |