summaryrefslogtreecommitdiffstats
path: root/src/designer/src/lib/uilib/resourcebuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/designer/src/lib/uilib/resourcebuilder.cpp')
-rw-r--r--src/designer/src/lib/uilib/resourcebuilder.cpp149
1 files changed, 106 insertions, 43 deletions
diff --git a/src/designer/src/lib/uilib/resourcebuilder.cpp b/src/designer/src/lib/uilib/resourcebuilder.cpp
index 78960fce8..5afd25439 100644
--- a/src/designer/src/lib/uilib/resourcebuilder.cpp
+++ b/src/designer/src/lib/uilib/resourcebuilder.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Designer of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://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 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "resourcebuilder_p.h"
#include "ui4_p.h"
@@ -48,6 +12,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#ifdef QFORMINTERNAL_NAMESPACE
namespace QFormInternal {
#endif
@@ -61,7 +27,8 @@ QResourceBuilder::~QResourceBuilder() = default;
int QResourceBuilder::iconStateFlags(const DomResourceIcon *dpi)
{
int rc = 0;
- if (dpi->hasElementNormalOff())
+ // Fix form files broken by QTBUG-115465
+ if (dpi->hasElementNormalOff() && dpi->elementNormalOff()->text() != "."_L1)
rc |= NormalOff;
if (dpi->hasElementNormalOn())
rc |= NormalOn;
@@ -92,11 +59,17 @@ QVariant QResourceBuilder::loadResource(const QDir &workingDirectory, const DomP
const DomResourceIcon *dpi = property->elementIconSet();
if (!dpi->attributeTheme().isEmpty()) {
const QString theme = dpi->attributeTheme();
+ const qsizetype themeEnum = theme.at(0).isUpper()
+ ? themeIconNames().indexOf(theme) : -1;
+ if (themeEnum != -1) {
+ const auto themeEnumE = static_cast<QIcon::ThemeIcon>(themeEnum);
+ return QVariant::fromValue(QIcon::fromTheme(themeEnumE));
+ }
const bool known = QIcon::hasThemeIcon(theme);
if (themeDebug)
qDebug("Theme %s known %d", qPrintable(theme), known);
if (known)
- return QVariant::fromValue(QIcon::fromTheme(dpi->attributeTheme()));
+ return QVariant::fromValue(QIcon::fromTheme(theme));
} // non-empty theme
if (const int flags = iconStateFlags(dpi)) { // new, post 4.4 format
QIcon icon;
@@ -155,9 +128,9 @@ bool QResourceBuilder::isResourceProperty(const DomProperty *p) const
bool QResourceBuilder::isResourceType(const QVariant &value) const
{
- switch (value.type()) {
- case QVariant::Pixmap:
- case QVariant::Icon:
+ switch (value.metaType().id()) {
+ case QMetaType::QPixmap:
+ case QMetaType::QIcon:
return true;
default:
break;
@@ -165,6 +138,96 @@ bool QResourceBuilder::isResourceType(const QVariant &value) const
return false;
}
+const QStringList &QResourceBuilder::themeIconNames()
+{
+ static const QStringList result = {
+ "AddressBookNew"_L1, "ApplicationExit"_L1, "AppointmentNew"_L1,
+ "CallStart"_L1, "CallStop"_L1, "ContactNew"_L1,
+ "DocumentNew"_L1, "DocumentOpen"_L1, "DocumentOpenRecent"_L1,
+ "DocumentPageSetup"_L1, "DocumentPrint"_L1, "DocumentPrintPreview"_L1,
+ "DocumentProperties"_L1, "DocumentRevert"_L1, "DocumentSave"_L1,
+ "DocumentSaveAs"_L1, "DocumentSend"_L1,
+ "EditClear"_L1, "EditCopy"_L1, "EditCut"_L1, "EditDelete"_L1,
+ "EditFind"_L1, "EditPaste"_L1,
+ "EditRedo"_L1, "EditSelectAll"_L1, "EditUndo"_L1,
+ "FolderNew"_L1,
+ "FormatIndentLess"_L1, "FormatIndentMore"_L1,
+ "FormatJustifyCenter"_L1, "FormatJustifyFill"_L1,
+ "FormatJustifyLeft"_L1, "FormatJustifyRight"_L1,
+ "FormatTextDirectionLtr"_L1, "FormatTextDirectionRtl"_L1,
+ "FormatTextBold"_L1, "FormatTextItalic"_L1,
+ "FormatTextUnderline"_L1, "FormatTextStrikethrough"_L1,
+ "GoDown"_L1, "GoHome"_L1, "GoNext"_L1, "GoPrevious"_L1, "GoUp"_L1,
+ "HelpAbout"_L1, "HelpFaq"_L1,
+ "InsertImage"_L1, "InsertLink"_L1, "InsertText"_L1,
+ "ListAdd"_L1, "ListRemove"_L1,
+ "MailForward"_L1, "MailMarkImportant"_L1, "MailMarkRead"_L1, "MailMarkUnread"_L1,
+ "MailMessageNew"_L1, "MailReplyAll"_L1, "MailReplySender"_L1,
+ "MailSend"_L1,
+ "MediaEject"_L1, "MediaPlaybackPause"_L1, "MediaPlaybackStart"_L1,
+ "MediaPlaybackStop"_L1, "MediaRecord"_L1, "MediaSeekBackward"_L1,
+ "MediaSeekForward"_L1, "MediaSkipBackward"_L1,
+ "MediaSkipForward"_L1,
+ "ObjectRotateLeft"_L1, "ObjectRotateRight"_L1,
+ "ProcessStop"_L1,
+ "SystemLockScreen"_L1, "SystemLogOut"_L1,
+ "SystemSearch"_L1, "SystemReboot"_L1, "SystemShutdown"_L1,
+ "ToolsCheckSpelling"_L1,
+ "ViewFullscreen"_L1, "ViewRefresh"_L1, "ViewRestore"_L1,
+ "WindowClose"_L1, "WindowNew"_L1,
+ "ZoomFitBest"_L1, "ZoomIn"_L1, "ZoomOut"_L1,
+ "AudioCard"_L1, "AudioInputMicrophone"_L1,
+ "Battery"_L1,
+ "CameraPhoto"_L1, "CameraVideo"_L1, "CameraWeb"_L1,
+ "Computer"_L1, "DriveHarddisk"_L1, "DriveOptical"_L1,
+ "InputGaming"_L1, "InputKeyboard"_L1, "InputMouse"_L1,
+ "InputTablet"_L1,
+ "MediaFlash"_L1, "MediaOptical"_L1,
+ "MediaTape"_L1,
+ "MultimediaPlayer"_L1,
+ "NetworkWired"_L1, "NetworkWireless"_L1,
+ "Phone"_L1, "Printer"_L1, "Scanner"_L1, "VideoDisplay"_L1,
+ "AppointmentMissed"_L1, "AppointmentSoon"_L1,
+ "AudioVolumeHigh"_L1, "AudioVolumeLow"_L1, "AudioVolumeMedium"_L1,
+ "AudioVolumeMuted"_L1,
+ "BatteryCaution"_L1, "BatteryLow"_L1,
+ "DialogError"_L1, "DialogInformation"_L1, "DialogPassword"_L1,
+ "DialogQuestion"_L1, "DialogWarning"_L1,
+ "FolderDragAccept"_L1, "FolderOpen"_L1, "FolderVisiting"_L1,
+ "ImageLoading"_L1, "ImageMissing"_L1,
+ "MailAttachment"_L1, "MailUnread"_L1, "MailRead"_L1,
+ "MailReplied"_L1,
+ "MediaPlaylistRepeat"_L1, "MediaPlaylistShuffle"_L1,
+ "NetworkOffline"_L1,
+ "PrinterPrinting"_L1,
+ "SecurityHigh"_L1, "SecurityLow"_L1,
+ "SoftwareUpdateAvailable"_L1, "SoftwareUpdateUrgent"_L1,
+ "SyncError"_L1, "SyncSynchronizing"_L1,
+ "UserAvailable"_L1,
+ "UserOffline"_L1,
+ "WeatherClear"_L1, "WeatherClearNight"_L1, "WeatherFewClouds"_L1,
+ "WeatherFewCloudsNight"_L1, "WeatherFog"_L1, "WeatherShowers"_L1,
+ "WeatherSnow"_L1, "WeatherStorm"_L1
+ };
+
+ return result;
+};
+
+int QResourceBuilder::themeIconIndex(QStringView name)
+{
+ const auto lastQual = name.lastIndexOf("::"_L1);
+ const auto result = lastQual != -1
+ ? themeIconNames().indexOf(name.sliced(lastQual + 2))
+ : themeIconNames().indexOf(name);
+ return int(result);
+}
+
+QString QResourceBuilder::fullyQualifiedThemeIconName(int i)
+{
+ return i >= 0 && i < themeIconNames().size()
+ ? "QIcon::ThemeIcon::"_L1 + themeIconNames().at(i) : QString{};
+}
+
#ifdef QFORMINTERNAL_NAMESPACE
} // namespace QFormInternal
#endif