summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm66
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm34
-rw-r--r--src/plugins/platforms/ios/qiosapplicationdelegate.mm4
-rw-r--r--src/plugins/platforms/ios/qiosdocumentpickercontroller.mm62
-rw-r--r--src/plugins/platforms/ios/qiosfiledialog.mm10
-rw-r--r--src/plugins/platforms/wayland/qwaylandinputcontext.cpp10
-rw-r--r--src/plugins/platforms/windows/qwindowsscreen.cpp2
-rw-r--r--src/plugins/platforms/windows/qwindowstheme.cpp2
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp4
-rw-r--r--src/plugins/platforms/windows/qwindowswindowclassdescription.cpp10
-rw-r--r--src/plugins/platforms/windows/qwindowswindowclassdescription.h3
-rw-r--r--src/plugins/platforms/windows/qwindowswindowclassregistry.cpp13
-rw-r--r--src/plugins/styles/modernwindows/qwindows11style.cpp79
-rw-r--r--src/plugins/styles/modernwindows/qwindows11style_p.h2
14 files changed, 203 insertions, 98 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
index 7644867700a..7ca3e61dfa5 100644
--- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
+++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
@@ -25,6 +25,8 @@
#include <qpa/qwindowsysteminterface.h>
#include <qwindowdefs.h>
+#include <QtCore/private/qdarwinsecurityscopedfileengine_p.h>
+
QT_USE_NAMESPACE
@implementation QCocoaApplicationDelegate {
@@ -194,6 +196,23 @@ QT_USE_NAMESPACE
QCocoaMenuBar::insertWindowMenu();
}
+/*!
+ Tells the delegate to open the specified files
+
+ Sent by the system when the user drags a file to the app's icon
+ in places like Finder or the Dock, or opens a file via the "Open
+ With" menu in Finder.
+
+ These actions can happen when the application is not running,
+ in which case the call comes in between willFinishLaunching
+ and didFinishLaunching. In this case we don't pass on the
+ incoming file paths as file open events, as the paths are
+ also part of the command line arguments, and Qt applications
+ normally expect to handle file opening via those.
+
+ \note The app must register itself as a handler for each file
+ type via the CFBundleDocumentTypes key in the Info.plist.
+ */
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
{
Q_UNUSED(filenames);
@@ -209,7 +228,10 @@ QT_USE_NAMESPACE
if (qApp->arguments().contains(qtFileName))
continue;
}
- QWindowSystemInterface::handleFileOpenEvent(qtFileName);
+ QUrl url = qt_apple_urlFromPossiblySecurityScopedURL([NSURL fileURLWithPath:fileName]);
+ QWindowSystemInterface::handleFileOpenEvent(url);
+ // FIXME: We're supposed to call [NSApp replyToOpenOrPrint:] here, but we
+ // don't know if the open operation succeeded, failed, or was cancelled.
}
if ([reflectionDelegate respondsToSelector:_cmd])
@@ -262,6 +284,17 @@ QT_USE_NAMESPACE
}
}
+/*!
+ Returns a Boolean value that indicates if the app responds
+ to reopen AppleEvents.
+
+ These events are sent whenever the Finder reactivates an already
+ running application because someone double-clicked it again or used
+ the dock to activate it.
+
+ We pass the activation on to Qt, and return YES, to let AppKit
+ follow its normal flow.
+ */
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
{
if ([reflectionDelegate respondsToSelector:_cmd])
@@ -309,6 +342,25 @@ QT_USE_NAMESPACE
[self doesNotRecognizeSelector:invocationSelector];
}
+/*!
+ Callback for when the application is asked to pick up a user activity
+ from another app (also known as Handoff, which is part of the bigger
+ Continuity story for Apple operating systems).
+
+ This is normally managed by two apps by the same vendor explicitly
+ initiating a custom NSUserActivity and picking it up in another app
+ on the same or another device, which we don't have APIs for.
+
+ This is also how the system supports Universal Links, where a web page
+ can deep-link into an app. In this case the app needs to claim and
+ validate an associated domain. The resulting link will be delivered
+ as a special NSUserActivityTypeBrowsingWeb activity type, which we
+ treat as QDesktopServices::handleUrl().
+
+ Finally, for NS/UIDocument based apps (which Qt is not), the system
+ automatically handles document hand-off if the application includes
+ the NSUbiquitousDocumentUserActivityType key in its Info.plist.
+ */
- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void(^)(NSArray<id<NSUserActivityRestoring>> *restorableObjects))restorationHandler
{
@@ -331,6 +383,18 @@ QT_USE_NAMESPACE
return NO;
}
+/*!
+ Callback for when the app is asked to open custom URL schemes.
+
+ We register a handler for events of type kInternetEventClass with the
+ NSAppleEventManager during application start.
+
+ The application must include the schemes in the CFBundleURLTypes
+ key of the Info.plist.
+
+ \note This callback is not used for http/https URLs, see
+ continueUserActivity above for how we handle that.
+ */
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
Q_UNUSED(replyEvent);
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index 4c4e5fac962..a79682e4e14 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -19,6 +19,7 @@
#include <QtCore/qregularexpression.h>
#include <QtCore/qpointer.h>
#include <QtCore/private/qcore_mac_p.h>
+#include <QtCore/private/qdarwinsecurityscopedfileengine_p.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/private/qguiapplication_p.h>
@@ -395,14 +396,15 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
{
if (auto *openPanel = openpanel_cast(m_panel)) {
QList<QUrl> result;
- for (NSURL *url in openPanel.URLs) {
- QString path = QString::fromNSString(url.path).normalized(QString::NormalizationForm_C);
- result << QUrl::fromLocalFile(path);
- }
+ for (NSURL *url in openPanel.URLs)
+ result << qt_apple_urlFromPossiblySecurityScopedURL(url);
return result;
} else {
- QString filename = QString::fromNSString(m_panel.URL.path).normalized(QString::NormalizationForm_C);
- QFileInfo fileInfo(filename);
+ QUrl result = qt_apple_urlFromPossiblySecurityScopedURL(m_panel.URL);
+ if (qt_apple_isSandboxed())
+ return { result }; // Can't tweak suffix
+
+ QFileInfo fileInfo(result.toLocalFile());
if (fileInfo.suffix().isEmpty() && ![self fileInfoMatchesCurrentNameFilter:fileInfo]) {
// We end up in this situation if we accept a file name without extension
@@ -733,6 +735,26 @@ bool QCocoaFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModalit
return false;
}
+ if (qt_apple_isSandboxed()) {
+ static bool canRead = qt_mac_processHasEntitlement(
+ u"com.apple.security.files.user-selected.read-only"_s);
+ static bool canReadWrite = qt_mac_processHasEntitlement(
+ u"com.apple.security.files.user-selected.read-write"_s);
+
+ if (options()->acceptMode() == QFileDialogOptions::AcceptSave
+ && !canReadWrite) {
+ qWarning() << "Sandboxed application is missing user-selected files"
+ << "read-write entitlement. Falling back to non-native dialog";
+ return false;
+ }
+
+ if (!canReadWrite && !canRead) {
+ qWarning() << "Sandboxed application is missing user-selected files"
+ << "entitlement. Falling back to non-native dialog";
+ return false;
+ }
+ }
+
createNSOpenSavePanelDelegate();
return [m_delegate showPanel:windowModality withParent:parent];
diff --git a/src/plugins/platforms/ios/qiosapplicationdelegate.mm b/src/plugins/platforms/ios/qiosapplicationdelegate.mm
index 380c5a588e6..7cbb4fc40f5 100644
--- a/src/plugins/platforms/ios/qiosapplicationdelegate.mm
+++ b/src/plugins/platforms/ios/qiosapplicationdelegate.mm
@@ -16,6 +16,8 @@
#include <QtCore/QtCore>
+#include <QtCore/private/qdarwinsecurityscopedfileengine_p.h>
+
@interface QIOSWindowSceneDelegate : NSObject<UIWindowSceneDelegate>
@property (nullable, nonatomic, strong) UIWindow *window;
@end
@@ -112,7 +114,7 @@
QIOSServices *iosServices = static_cast<QIOSServices *>(iosIntegration->services());
for (UIOpenURLContext *urlContext in URLContexts) {
- QUrl url = QUrl::fromNSURL(urlContext.URL);
+ QUrl url = qt_apple_urlFromPossiblySecurityScopedURL(urlContext.URL);
if (url.isLocalFile())
QWindowSystemInterface::handleFileOpenEvent(url);
else
diff --git a/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm b/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm
index c173aa426fc..57a5e100c9e 100644
--- a/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm
+++ b/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm
@@ -8,6 +8,7 @@
#include "qiosdocumentpickercontroller.h"
#include <QtCore/qpointer.h>
+#include <QtCore/private/qdarwinsecurityscopedfileengine_p.h>
@implementation QIOSDocumentPickerController {
QPointer<QIOSFileDialog> m_fileDialog;
@@ -17,9 +18,11 @@
{
NSMutableArray <UTType *> *docTypes = [[[NSMutableArray alloc] init] autorelease];
- QStringList nameFilters = fileDialog->options()->nameFilters();
- if (!nameFilters.isEmpty() && (fileDialog->options()->fileMode() != QFileDialogOptions::Directory
- || fileDialog->options()->fileMode() != QFileDialogOptions::DirectoryOnly))
+ const auto options = fileDialog->options();
+
+ const QStringList nameFilters = options->nameFilters();
+ if (!nameFilters.isEmpty() && (options->fileMode() != QFileDialogOptions::Directory
+ || options->fileMode() != QFileDialogOptions::DirectoryOnly))
{
QStringList results;
for (const QString &filter : nameFilters)
@@ -28,21 +31,8 @@
docTypes = [self computeAllowedFileTypes:results];
}
- // FIXME: Handle security scoped URLs instead of copying resource
- bool asCopy = [&]{
- switch (fileDialog->options()->fileMode()) {
- case QFileDialogOptions::AnyFile:
- case QFileDialogOptions::ExistingFile:
- case QFileDialogOptions::ExistingFiles:
- return true;
- default:
- // Folders can't be imported
- return false;
- }
- }();
-
if (!docTypes.count) {
- switch (fileDialog->options()->fileMode()) {
+ switch (options->fileMode()) {
case QFileDialogOptions::AnyFile:
case QFileDialogOptions::ExistingFile:
case QFileDialogOptions::ExistingFiles:
@@ -58,17 +48,39 @@
}
}
- if (self = [super initForOpeningContentTypes:docTypes asCopy:asCopy]) {
- m_fileDialog = fileDialog;
- self.modalPresentationStyle = UIModalPresentationFormSheet;
- self.delegate = self;
- self.presentationController.delegate = self;
+ if (options->acceptMode() == QFileDialogOptions::AcceptSave) {
+ auto selectedUrls = options->initiallySelectedFiles();
+ auto suggestedFileName = !selectedUrls.isEmpty() ? selectedUrls.first().fileName() : "Untitled";
- if (m_fileDialog->options()->fileMode() == QFileDialogOptions::ExistingFiles)
+ // Create an empty dummy file, so that the export dialog will allow us
+ // to choose the export destination, which we are then given access to
+ // write to.
+ NSURL *dummyExportFile = [NSFileManager.defaultManager.temporaryDirectory
+ URLByAppendingPathComponent:suggestedFileName.toNSString()];
+ [NSFileManager.defaultManager createFileAtPath:dummyExportFile.path contents:nil attributes:nil];
+
+ if (!(self = [super initForExportingURLs:@[dummyExportFile]]))
+ return nil;
+
+ // Note, we don't set the directoryURL, as if the directory can't be
+ // accessed, or written to, the file dialog is shown but is empty.
+ // FIXME: See comment below for open dialogs as well
+ } else {
+ if (!(self = [super initForOpeningContentTypes:docTypes asCopy:NO]))
+ return nil;
+
+ if (options->fileMode() == QFileDialogOptions::ExistingFiles)
self.allowsMultipleSelection = YES;
- self.directoryURL = m_fileDialog->options()->initialDirectory().toNSURL();
+ // FIXME: This doesn't seem to have any effect
+ self.directoryURL = options->initialDirectory().toNSURL();
}
+
+ m_fileDialog = fileDialog;
+ self.modalPresentationStyle = UIModalPresentationFormSheet;
+ self.delegate = self;
+ self.presentationController.delegate = self;
+
return self;
}
@@ -81,7 +93,7 @@
QList<QUrl> files;
for (NSURL* url in urls)
- files.append(QUrl::fromNSURL(url));
+ files.append(qt_apple_urlFromPossiblySecurityScopedURL(url));
m_fileDialog->selectedFilesChanged(files);
emit m_fileDialog->accept();
diff --git a/src/plugins/platforms/ios/qiosfiledialog.mm b/src/plugins/platforms/ios/qiosfiledialog.mm
index b7d3e488bbb..6e7c10117ed 100644
--- a/src/plugins/platforms/ios/qiosfiledialog.mm
+++ b/src/plugins/platforms/ios/qiosfiledialog.mm
@@ -49,14 +49,10 @@ bool QIOSFileDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality window
// when converted to QUrl, it becames a scheme.
const QString scheme = initialDir.scheme();
- if (acceptOpen) {
- if (directory.startsWith("assets-library:"_L1) || scheme == "assets-library"_L1)
- return showImagePickerDialog(parent);
- else
- return showNativeDocumentPickerDialog(parent);
- }
+ if (acceptOpen && (directory.startsWith("assets-library:"_L1) || scheme == "assets-library"_L1))
+ return showImagePickerDialog(parent);
- return false;
+ return showNativeDocumentPickerDialog(parent);
}
void QIOSFileDialog::showImagePickerDialog_helper(QWindow *parent)
diff --git a/src/plugins/platforms/wayland/qwaylandinputcontext.cpp b/src/plugins/platforms/wayland/qwaylandinputcontext.cpp
index 5ab285ad97d..0ccc4dba57a 100644
--- a/src/plugins/platforms/wayland/qwaylandinputcontext.cpp
+++ b/src/plugins/platforms/wayland/qwaylandinputcontext.cpp
@@ -192,12 +192,10 @@ void QWaylandInputContext::setFocusObject(QObject *object)
if (window && window->handle()) {
if (mCurrentWindow.data() != window) {
if (!inputMethodAccepted()) {
- if (mCurrentWindow) {
- auto *surface = static_cast<QWaylandWindow *>(mCurrentWindow->handle())->wlSurface();
- if (surface)
- inputInterface->disableSurface(surface);
- mCurrentWindow.clear();
- }
+ auto *surface = static_cast<QWaylandWindow *>(window->handle())->wlSurface();
+ if (surface)
+ inputInterface->disableSurface(surface);
+ mCurrentWindow.clear();
} else {
auto *surface = static_cast<QWaylandWindow *>(window->handle())->wlSurface();
if (surface) {
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index 2bd2f0c9e3d..0236669d6fb 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -704,7 +704,7 @@ void QWindowsScreenManager::initialize()
qCDebug(lcQpaScreen) << "Initializing screen manager";
auto className = QWindowsWindowClassRegistry::instance()->registerWindowClass(
- QLatin1String("ScreenChangeObserverWindow"),
+ "ScreenChangeObserverWindow"_L1,
qDisplayChangeObserverWndProc);
// HWND_MESSAGE windows do not get WM_DISPLAYCHANGE, so we need to create
diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp
index d132bbb6130..b9f60f7713c 100644
--- a/src/plugins/platforms/windows/qwindowstheme.cpp
+++ b/src/plugins/platforms/windows/qwindowstheme.cpp
@@ -549,7 +549,7 @@ QWindowsTheme::QWindowsTheme()
refreshIconPixmapSizes();
auto className = QWindowsWindowClassRegistry::instance()->registerWindowClass(
- QLatin1String("ThemeChangeObserverWindow"),
+ "ThemeChangeObserverWindow"_L1,
qThemeChangeObserverWndProc);
// HWND_MESSAGE windows do not get the required theme events,
// so we use a real top-level window that we never show.
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index ed391009423..b77e985c965 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -61,6 +61,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
using QWindowCreationContextPtr = QSharedPointer<QWindowCreationContext>;
enum {
@@ -889,7 +891,7 @@ QWindowsWindowData
const QString windowClassName = QWindowsWindowClassRegistry::instance()->registerWindowClass(w);
QWindowsWindowClassDescription windowTitlebarDescription;
- windowTitlebarDescription.name = QStringLiteral("_q_titlebar");
+ windowTitlebarDescription.name = "_q_titlebar"_L1;
windowTitlebarDescription.style = CS_VREDRAW | CS_HREDRAW;
windowTitlebarDescription.shouldAddPrefix = false;
const QString windowTitlebarName = QWindowsWindowClassRegistry::instance()->registerWindowClass(windowTitlebarDescription);
diff --git a/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp b/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp
index 63e16260b62..e2e46a7b215 100644
--- a/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp
+++ b/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp
@@ -75,4 +75,14 @@ QWindowsWindowClassDescription QWindowsWindowClassDescription::fromWindow(const
return description;
}
+QDebug operator<<(QDebug dbg, const QWindowsWindowClassDescription &description)
+{
+ dbg << description.name
+ << " style=0x" << Qt::hex << description.style << Qt::dec
+ << " brush=" << description.brush
+ << " hasIcon=" << description.hasIcon;
+
+ return dbg;
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/windows/qwindowswindowclassdescription.h b/src/plugins/platforms/windows/qwindowswindowclassdescription.h
index 9423abf9d2d..3acca65b8a2 100644
--- a/src/plugins/platforms/windows/qwindowswindowclassdescription.h
+++ b/src/plugins/platforms/windows/qwindowswindowclassdescription.h
@@ -23,6 +23,9 @@ struct QWindowsWindowClassDescription
HBRUSH brush{ nullptr };
bool hasIcon{ false };
bool shouldAddPrefix{ true };
+
+private:
+ friend QDebug operator<<(QDebug dbg, const QWindowsWindowClassDescription &description);
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp b/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp
index c330720a09c..19694eab330 100644
--- a/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp
+++ b/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp
@@ -110,13 +110,13 @@ QString QWindowsWindowClassRegistry::registerWindowClass(const QWindowsWindowCla
wc.lpszClassName = reinterpret_cast<LPCWSTR>(className.utf16());
ATOM atom = RegisterClassEx(&wc);
if (!atom)
- qErrnoWarning("QApplication::regClass: Registering window class '%s' failed.",
- qPrintable(className));
+ qCWarning(lcQpaWindowClass) << "Failed to register window class" << className
+ << "(" << qt_error_string(-1) << ")";
m_registeredWindowClassNames.insert(className);
- qCDebug(lcQpaWindowClass).nospace() << __FUNCTION__ << ' ' << className
- << " style=0x" << Qt::hex << description.style << Qt::dec
- << " brush=" << description.brush << " icon=" << description.hasIcon << " atom=" << atom;
+
+ qCDebug(lcQpaWindowClass).nospace() << __FUNCTION__ << ' ' << className << ' ' << description << " atom=" << atom;
+
return className;
}
@@ -136,7 +136,8 @@ void QWindowsWindowClassRegistry::unregisterWindowClasses()
for (const QString &name : std::as_const(m_registeredWindowClassNames)) {
if (!UnregisterClass(reinterpret_cast<LPCWSTR>(name.utf16()), appInstance) && QWindowsContext::verbose)
- qErrnoWarning("UnregisterClass failed for '%s'", qPrintable(name));
+ qCWarning(lcQpaWindowClass) << "Failed to unregister window class" << name
+ << "(" << qt_error_string(-1) << ")";
}
m_registeredWindowClassNames.clear();
}
diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp
index bf4b3c6a9bc..13682256370 100644
--- a/src/plugins/styles/modernwindows/qwindows11style.cpp
+++ b/src/plugins/styles/modernwindows/qwindows11style.cpp
@@ -24,6 +24,7 @@
#if QT_CONFIG(mdiarea)
#include <QtWidgets/qmdiarea.h>
#endif
+#include <QtWidgets/qplaintextedit.h>
#include <QtWidgets/qtextedit.h>
#include <QtWidgets/qtreeview.h>
#if QT_CONFIG(datetimeedit)
@@ -68,6 +69,10 @@ inline bool isAutoRaise(const QStyleOption *option)
{
return option->state.testFlag(QStyle::State_AutoRaise);
}
+inline bool hasFocus(const QStyleOption *option)
+{
+ return option->state.testFlag(QStyle::State_HasFocus);
+}
enum class ControlState { Normal, Hover, Pressed, Disabled };
inline ControlState calcControlState(const QStyleOption *option)
{
@@ -124,7 +129,7 @@ static constexpr int percentToAlpha(double percent)
return qRound(percent * 255. / 100.);
}
-static constexpr std::array<QColor, 33> WINUI3ColorsLight {
+static constexpr std::array<QColor, 34> WINUI3ColorsLight {
QColor(0x00,0x00,0x00,percentToAlpha(3.73)), // subtleHighlightColor (fillSubtleSecondary)
QColor(0x00,0x00,0x00,percentToAlpha(2.41)), // subtlePressedColor (fillSubtleTertiary)
QColor(0x00,0x00,0x00,0x0F), //frameColorLight
@@ -143,6 +148,7 @@ static constexpr std::array<QColor, 33> WINUI3ColorsLight {
QColor(0xF9,0xF9,0xF9,percentToAlpha(50)), // fillControlSecondary
QColor(0xF9,0xF9,0xF9,percentToAlpha(30)), // fillControlTertiary
QColor(0xF9,0xF9,0xF9,percentToAlpha(30)), // fillControlDisabled
+ QColor(0xFF,0xFF,0xFF,percentToAlpha(100)), // fillControlInputActive
QColor(0x00,0x00,0x00,percentToAlpha(2.41)), // fillControlAltSecondary
QColor(0x00,0x00,0x00,percentToAlpha(5.78)), // fillControlAltTertiary
QColor(0x00,0x00,0x00,percentToAlpha(9.24)), // fillControlAltQuarternary
@@ -160,7 +166,7 @@ static constexpr std::array<QColor, 33> WINUI3ColorsLight {
QColor(0x00,0x00,0x00,percentToAlpha(8.03)), // dividerStrokeDefault
};
-static constexpr std::array<QColor, 33> WINUI3ColorsDark {
+static constexpr std::array<QColor, 34> WINUI3ColorsDark {
QColor(0xFF,0xFF,0xFF,percentToAlpha(6.05)), // subtleHighlightColor (fillSubtleSecondary)
QColor(0xFF,0xFF,0xFF,percentToAlpha(4.19)), // subtlePressedColor (fillSubtleTertiary)
QColor(0xFF,0xFF,0xFF,0x12), //frameColorLight
@@ -179,6 +185,7 @@ static constexpr std::array<QColor, 33> WINUI3ColorsDark {
QColor(0xFF,0xFF,0xFF,percentToAlpha(8.37)), // fillControlSecondary
QColor(0xFF,0xFF,0xFF,percentToAlpha(3.26)), // fillControlTertiary
QColor(0xFF,0xFF,0xFF,percentToAlpha(4.19)), // fillControlDisabled
+ QColor(0x1E,0x1E,0x1E,percentToAlpha(70)), // fillControlInputActive
QColor(0x00,0x00,0x00,percentToAlpha(10.0)), // fillControlAltDefault
QColor(0xFF,0xFF,0xFF,percentToAlpha(4.19)), // fillControlAltSecondary
QColor(0xFF,0xFF,0xFF,percentToAlpha(6.98)), // fillControlAltTertiafillCy
@@ -196,7 +203,7 @@ static constexpr std::array<QColor, 33> WINUI3ColorsDark {
QColor(0xFF,0xFF,0xFF,percentToAlpha(8.37)), // dividerStrokeDefault
};
-static constexpr std::array<std::array<QColor,33>, 2> WINUI3Colors {
+static constexpr std::array<std::array<QColor,34>, 2> WINUI3Colors {
WINUI3ColorsLight,
WINUI3ColorsDark
};
@@ -989,16 +996,9 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
case PE_PanelLineEdit:
if (const auto *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
const auto frameRect = QRectF(option->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
- drawRoundedRect(painter, frameRect, Qt::NoPen, option->palette.brush(QPalette::Base));
-
+ drawRoundedRect(painter, frameRect, Qt::NoPen, inputFillBrush(option, widget));
if (panel->lineWidth > 0)
proxy()->drawPrimitive(PE_FrameLineEdit, panel, painter, widget);
-
- const bool isMouseOver = state & State_MouseOver;
- const bool hasFocus = state & State_HasFocus;
- const bool isEnabled = state & State_Enabled;
- if (isMouseOver && isEnabled && hasFocus && !highContrastTheme)
- drawRoundedRect(painter, frameRect, Qt::NoPen, winUI3Color(subtleHighlightColor));
}
break;
case PE_FrameLineEdit: {
@@ -1027,7 +1027,9 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
if (frame->frameShape == QFrame::NoFrame)
break;
- drawLineEditFrame(painter, rect, option, qobject_cast<const QTextEdit *>(widget) != nullptr);
+ const bool isEditable = qobject_cast<const QTextEdit *>(widget) != nullptr
+ || qobject_cast<const QPlainTextEdit *>(widget) != nullptr;
+ drawLineEditFrame(painter, rect, option, isEditable);
}
break;
}
@@ -1452,36 +1454,10 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
#endif // QT_CONFIG(progressbar)
case CE_PushButtonLabel:
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
- using namespace StyleOptionHelper;
- const bool isEnabled = !isDisabled(option);
-
- QRect textRect = btn->rect.marginsRemoved(QMargins(contentHMargin, 0, contentHMargin, 0));
- int tf = Qt::AlignCenter | Qt::TextShowMnemonic;
- if (!proxy()->styleHint(SH_UnderlineShortcut, btn, widget))
- tf |= Qt::TextHideMnemonic;
-
- if (!btn->icon.isNull()) {
- //Center both icon and text
- QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
- if (mode == QIcon::Normal && btn->state & State_HasFocus)
- mode = QIcon::Active;
- QIcon::State state = isChecked(btn) ? QIcon::On : QIcon::Off;
-
- int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint()
-
- QRect iconRect = QRect(textRect.x(), textRect.y(), btn->iconSize.width(), textRect.height());
- QRect vIconRect = visualRect(btn->direction, btn->rect, iconRect);
- textRect.setLeft(textRect.left() + iconRect.width() + iconSpacing);
-
- if (isChecked(btn) || isPressed(btn))
- vIconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, option, widget),
- proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
- btn->icon.paint(painter, vIconRect, Qt::AlignCenter, mode, state);
- }
-
- auto vTextRect = visualRect(btn->direction, btn->rect, textRect);
- painter->setPen(controlTextColor(option));
- proxy()->drawItemText(painter, vTextRect, tf, option->palette, isEnabled, btn->text);
+ QStyleOptionButton btnCopy(*btn);
+ btnCopy.rect = btn->rect.marginsRemoved(QMargins(contentHMargin, 0, contentHMargin, 0));
+ btnCopy.palette.setBrush(QPalette::ButtonText, controlTextColor(option));
+ QCommonStyle::drawControl(element, &btnCopy, painter, widget);
}
break;
case CE_PushButtonBevel:
@@ -2625,7 +2601,7 @@ QIcon QWindows11Style::standardIcon(StandardPixmap standardIcon,
switch (standardIcon) {
case SP_LineEditClearButton: {
if (d->m_lineEditClearButton.isNull()) {
- auto e = new WinFontIconEngine(Clear.at(0), d->assetFont);
+ auto e = new WinFontIconEngine(Clear, d->assetFont);
d->m_lineEditClearButton = QIcon(e);
}
return d->m_lineEditClearButton;
@@ -2697,6 +2673,23 @@ QBrush QWindows11Style::controlFillBrush(const QStyleOption *option, ControlType
return winUI3Color(colorEnums[int(controlType)][int(state)]);
}
+QBrush QWindows11Style::inputFillBrush(const QStyleOption *option, const QWidget *widget) const
+{
+ // slightly different states than in controlFillBrush
+ using namespace StyleOptionHelper;
+ const auto role = widget ? widget->backgroundRole() : QPalette::Window;
+ if (option->palette.isBrushSet(QPalette::Current, role))
+ return option->palette.button();
+
+ if (isDisabled(option))
+ return winUI3Color(fillControlDisabled);
+ if (hasFocus(option))
+ return winUI3Color(fillControlInputActive);
+ if (isHover(option))
+ return winUI3Color(fillControlSecondary);
+ return winUI3Color(fillControlDefault);
+}
+
QColor QWindows11Style::controlTextColor(const QStyleOption *option, QPalette::ColorRole role) const
{
using namespace StyleOptionHelper;
diff --git a/src/plugins/styles/modernwindows/qwindows11style_p.h b/src/plugins/styles/modernwindows/qwindows11style_p.h
index a51a93ddd9b..96c2c4136e0 100644
--- a/src/plugins/styles/modernwindows/qwindows11style_p.h
+++ b/src/plugins/styles/modernwindows/qwindows11style_p.h
@@ -42,6 +42,7 @@ enum WINUI3Color {
fillControlSecondary, // button hover color (alpha)
fillControlTertiary, // button pressed color (alpha)
fillControlDisabled, // button disabled color (alpha)
+ fillControlInputActive, // input active
fillControlAltSecondary, // checkbox/RadioButton default color (alpha)
fillControlAltTertiary, // checkbox/RadioButton hover color (alpha)
fillControlAltQuarternary, // checkbox/RadioButton pressed color (alpha)
@@ -101,6 +102,7 @@ private:
ControlAlt
};
QBrush controlFillBrush(const QStyleOption *option, ControlType controlType) const;
+ QBrush inputFillBrush(const QStyleOption *option, const QWidget *widget) const;
// ControlType::ControlAlt can be mapped to QPalette directly
QColor controlTextColor(const QStyleOption *option,
QPalette::ColorRole role = QPalette::ButtonText) const;