diff options
Diffstat (limited to 'src/platformsupport')
32 files changed, 688 insertions, 287 deletions
diff --git a/src/platformsupport/cglconvenience/cglconvenience.mm b/src/platformsupport/cglconvenience/cglconvenience.mm index a18510a9e2..28cde1264d 100644 --- a/src/platformsupport/cglconvenience/cglconvenience.mm +++ b/src/platformsupport/cglconvenience/cglconvenience.mm @@ -78,22 +78,15 @@ void *qcgl_createNSOpenGLPixelFormat(const QSurfaceFormat &format) if (format.swapBehavior() != QSurfaceFormat::SingleBuffer) attrs.append(NSOpenGLPFADoubleBuffer); -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) { - if (format.profile() == QSurfaceFormat::CoreProfile - && ((format.majorVersion() == 3 && format.minorVersion() >= 2) - || format.majorVersion() > 3)) { - attrs << NSOpenGLPFAOpenGLProfile; - attrs << NSOpenGLProfileVersion3_2Core; - } else { - attrs << NSOpenGLPFAOpenGLProfile; - attrs << NSOpenGLProfileVersionLegacy; - } + if (format.profile() == QSurfaceFormat::CoreProfile + && ((format.majorVersion() == 3 && format.minorVersion() >= 2) + || format.majorVersion() > 3)) { + attrs << NSOpenGLPFAOpenGLProfile; + attrs << NSOpenGLProfileVersion3_2Core; + } else { + attrs << NSOpenGLPFAOpenGLProfile; + attrs << NSOpenGLProfileVersionLegacy; } -#else - if (format.profile() == QSurfaceFormat::CoreProfile) - qWarning("Mac OSX >= 10.7 is needed for OpenGL Core Profile support"); -#endif if (format.depthBufferSize() > 0) attrs << NSOpenGLPFADepthSize << format.depthBufferSize(); diff --git a/src/platformsupport/clipboard/qmacmime.mm b/src/platformsupport/clipboard/qmacmime.mm index f2b9afa2b5..d48da8da15 100644 --- a/src/platformsupport/clipboard/qmacmime.mm +++ b/src/platformsupport/clipboard/qmacmime.mm @@ -43,7 +43,7 @@ #import <AppKit/AppKit.h> #endif -#if defined(Q_OS_IOS) +#if defined(QT_PLATFORM_UIKIT) #import <UIKit/UIKit.h> #endif @@ -520,11 +520,6 @@ QString QMacPasteboardMimeRtfText::mimeFor(QString flav) bool QMacPasteboardMimeRtfText::canConvert(const QString &mime, QString flav) { -#if defined(Q_OS_IOS) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_7_0) - return false; -#endif - return mime == mimeFor(flav); } diff --git a/src/platformsupport/eventdispatchers/eventdispatchers.pri b/src/platformsupport/eventdispatchers/eventdispatchers.pri index a0b37cae1a..6a4689eb19 100644 --- a/src/platformsupport/eventdispatchers/eventdispatchers.pri +++ b/src/platformsupport/eventdispatchers/eventdispatchers.pri @@ -17,6 +17,6 @@ HEADERS +=\ contains(QT_CONFIG, glib) { SOURCES +=$$PWD/qeventdispatcher_glib.cpp HEADERS +=$$PWD/qeventdispatcher_glib_p.h - QMAKE_CXXFLAGS += $$QT_CFLAGS_GLIB - LIBS_PRIVATE += $$QT_LIBS_GLIB + QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_GLIB + LIBS_PRIVATE += $$QMAKE_LIBS_GLIB } diff --git a/src/platformsupport/eventdispatchers/qwindowsguieventdispatcher.cpp b/src/platformsupport/eventdispatchers/qwindowsguieventdispatcher.cpp index 7d49c35d84..de369e0b00 100644 --- a/src/platformsupport/eventdispatchers/qwindowsguieventdispatcher.cpp +++ b/src/platformsupport/eventdispatchers/qwindowsguieventdispatcher.cpp @@ -151,11 +151,10 @@ messageDebugEntries[] = { {WM_IME_ENDCOMPOSITION, "WM_IME_ENDCOMPOSITION", true}, {WM_IME_NOTIFY, "WM_IME_NOTIFY", true}, {WM_IME_REQUEST, "WM_IME_REQUEST", true}, -#if !defined(Q_OS_WINCE) && !defined(QT_NO_SESSIONMANAGER) +#if !defined(QT_NO_SESSIONMANAGER) {WM_QUERYENDSESSION, "WM_QUERYENDSESSION", true}, {WM_ENDSESSION, "WM_ENDSESSION", true}, #endif -#ifndef Q_OS_WINCE {WM_MOUSEACTIVATE,"WM_MOUSEACTIVATE", true}, {WM_CHILDACTIVATE, "WM_CHILDACTIVATE", true}, {WM_PARENTNOTIFY, "WM_PARENTNOTIFY", true}, @@ -181,7 +180,6 @@ messageDebugEntries[] = { {WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN", true}, {WM_DISPLAYCHANGE, "WM_DISPLAYCHANGE", true}, {WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD", true}, -#endif // !Q_OS_WINCE {WM_THEMECHANGED, "WM_THEMECHANGED", true} }; diff --git a/src/platformsupport/fbconvenience/qfbbackingstore.cpp b/src/platformsupport/fbconvenience/qfbbackingstore.cpp index fa1b8d0acd..2cad3441e4 100644 --- a/src/platformsupport/fbconvenience/qfbbackingstore.cpp +++ b/src/platformsupport/fbconvenience/qfbbackingstore.cpp @@ -81,6 +81,12 @@ const QImage QFbBackingStore::image() return mImage; } + +QImage QFbBackingStore::toImage() const +{ + return mImage; +} + void QFbBackingStore::lock() { mImageMutex.lock(); @@ -110,4 +116,3 @@ void QFbBackingStore::endPaint() } QT_END_NAMESPACE - diff --git a/src/platformsupport/fbconvenience/qfbbackingstore_p.h b/src/platformsupport/fbconvenience/qfbbackingstore_p.h index fc06b95475..c8dfe3489c 100644 --- a/src/platformsupport/fbconvenience/qfbbackingstore_p.h +++ b/src/platformsupport/fbconvenience/qfbbackingstore_p.h @@ -72,6 +72,7 @@ public: void resize(const QSize &size, const QRegion ®ion) Q_DECL_OVERRIDE; const QImage image(); + QImage toImage() const override; void lock(); void unlock(); diff --git a/src/platformsupport/fbconvenience/qfbscreen.cpp b/src/platformsupport/fbconvenience/qfbscreen.cpp index 4066743cc2..01de2a59b2 100644 --- a/src/platformsupport/fbconvenience/qfbscreen.cpp +++ b/src/platformsupport/fbconvenience/qfbscreen.cpp @@ -206,15 +206,13 @@ void QFbScreen::generateRects() remainingScreen -= localGeometry; QRegion windowRegion(localGeometry); windowRegion -= remainingScreen; - foreach (const QRect &rect, windowRegion.rects()) { + for (const QRect &rect : windowRegion) mCachedRects += QPair<QRect, int>(rect, i); - } } #endif } - const QVector<QRect> remainingScreenRects = remainingScreen.rects(); - mCachedRects.reserve(mCachedRects.count() + remainingScreenRects.count()); - foreach (const QRect &rect, remainingScreenRects) + mCachedRects.reserve(mCachedRects.count() + remainingScreen.rectCount()); + for (const QRect &rect : remainingScreen) mCachedRects += QPair<QRect, int>(rect, -1); mIsUpToDate = true; } @@ -254,7 +252,7 @@ QRegion QFbScreen::doRedraw() rectRegion -= intersect; // we only expect one rectangle, but defensive coding... - foreach (const QRect &rect, intersect.rects()) { + for (const QRect &rect : intersect) { bool firstLayer = true; if (layer == -1) { mCompositePainter->setCompositionMode(QPainter::CompositionMode_Source); diff --git a/src/platformsupport/fontdatabases/basic/basic.pri b/src/platformsupport/fontdatabases/basic/basic.pri index d70b3b6a1a..52cf771b2a 100644 --- a/src/platformsupport/fontdatabases/basic/basic.pri +++ b/src/platformsupport/fontdatabases/basic/basic.pri @@ -8,6 +8,4 @@ SOURCES += \ $$PWD/qbasicfontdatabase.cpp \ $$QT_SOURCE_TREE/src/gui/text/qfontengine_ft.cpp -CONFIG += opentype - include($$QT_SOURCE_TREE/src/3rdparty/freetype_dependency.pri) diff --git a/src/platformsupport/fontdatabases/mac/coretext.pri b/src/platformsupport/fontdatabases/mac/coretext.pri index ebb64d15b4..272e7591ba 100644 --- a/src/platformsupport/fontdatabases/mac/coretext.pri +++ b/src/platformsupport/fontdatabases/mac/coretext.pri @@ -5,11 +5,10 @@ contains(QT_CONFIG, freetype) { include($$QT_SOURCE_TREE/src/3rdparty/freetype_dependency.pri) HEADERS += $$QT_SOURCE_TREE/src/gui/text/qfontengine_ft_p.h SOURCES += $$QT_SOURCE_TREE/src/gui/text/qfontengine_ft.cpp - CONFIG += opentype } -ios: \ - # On iOS CoreText and CoreGraphics are stand-alone frameworks +uikit: \ + # On iOS/tvOS CoreText and CoreGraphics are stand-alone frameworks LIBS_PRIVATE += -framework CoreText -framework CoreGraphics else: \ # On Mac OS they are part of the ApplicationServices umbrella framework, diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 5be7e3aadc..5fec53d1ed 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -44,7 +44,7 @@ #if defined(Q_OS_OSX) #import <AppKit/AppKit.h> #import <IOKit/graphics/IOGraphicsLib.h> -#elif defined(Q_OS_IOS) +#elif defined(QT_PLATFORM_UIKIT) #import <UIKit/UIFont.h> #endif @@ -191,7 +191,7 @@ static CFArrayRef availableFamilyNames() { #if defined(Q_OS_OSX) return CTFontManagerCopyAvailableFontFamilyNames(); -#elif defined(Q_OS_IOS) +#elif defined(QT_PLATFORM_UIKIT) return (CFArrayRef) [[UIFont familyNames] retain]; #endif } @@ -523,46 +523,37 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo static QHash<QString, QStringList> fallbackLists; if (!family.isEmpty()) { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_8, __IPHONE_6_0) - // CTFontCopyDefaultCascadeListForLanguages is available in the SDK - #if QT_MAC_DEPLOYMENT_TARGET_BELOW(__MAC_10_8, __IPHONE_6_0) - // But we have to feature check at runtime - if (&CTFontCopyDefaultCascadeListForLanguages) - #endif - { - QCFType<CFMutableDictionaryRef> attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, QCFString(family)); - if (QCFType<CTFontDescriptorRef> fontDescriptor = CTFontDescriptorCreateWithAttributes(attributes)) { - if (QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0)) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"]; - - QCFType<CFArrayRef> cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages); - if (cascadeList) { - QStringList fallbackList; - const int numCascades = CFArrayGetCount(cascadeList); - for (int i = 0; i < numCascades; ++i) { - CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i); - QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute); - fallbackList.append(QCFString::toQString(fallbackFamilyName)); - } + QCFType<CFMutableDictionaryRef> attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, QCFString(family)); + if (QCFType<CTFontDescriptorRef> fontDescriptor = CTFontDescriptorCreateWithAttributes(attributes)) { + if (QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0)) { + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"]; + + QCFType<CFArrayRef> cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages); + if (cascadeList) { + QStringList fallbackList; + const int numCascades = CFArrayGetCount(cascadeList); + for (int i = 0; i < numCascades; ++i) { + CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i); + QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute); + fallbackList.append(QCFString::toQString(fallbackFamilyName)); + } #if defined(Q_OS_OSX) - // Since we are only returning a list of default fonts for the current language, we do not - // cover all unicode completely. This was especially an issue for some of the common script - // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk - // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most - // of Unicode 2.1. - if (!fallbackList.contains(QStringLiteral("Arial Unicode MS"))) - fallbackList.append(QStringLiteral("Arial Unicode MS")); + // Since we are only returning a list of default fonts for the current language, we do not + // cover all unicode completely. This was especially an issue for some of the common script + // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk + // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most + // of Unicode 2.1. + if (!fallbackList.contains(QStringLiteral("Arial Unicode MS"))) + fallbackList.append(QStringLiteral("Arial Unicode MS")); #endif - return fallbackList; - } + return fallbackList; } } } -#endif } // We were not able to find a fallback for the specific family, @@ -625,7 +616,6 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo return fallbackLists[styleLookupKey.arg(styleHint)]; } -#if HAVE_CORETEXT static CFArrayRef createDescriptorArrayForFont(CTFontRef font, const QString &fileName = QString()) { CFMutableArrayRef array = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); @@ -643,7 +633,7 @@ static CFArrayRef createDescriptorArrayForFont(CTFontRef font, const QString &fi // QUrl::fromLocalFile() doesn't accept qrc pseudo-paths like ":/fonts/myfont.ttf". // Therefore construct from QString with the qrc:// scheme -> "qrc:///fonts/myfont.ttf". fontURL = QUrl(QStringLiteral("qrc://") + fileName.mid(1)).toCFURL(); - } else if (!fileName.isEmpty()) { + } else { // At this point we hope that filename is in a format that QUrl can handle. fontURL = QUrl::fromLocalFile(fileName).toCFURL(); } @@ -658,104 +648,41 @@ static CFArrayRef createDescriptorArrayForFont(CTFontRef font, const QString &fi CFArrayAppendValue(array, descriptor); return array; } -#endif QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) { QCFType<CFArrayRef> fonts; QStringList families; -#if HAVE_CORETEXT - if (&CTFontManagerRegisterGraphicsFont) { - CFErrorRef error = 0; - if (!fontData.isEmpty()) { - QByteArray* fontDataCopy = new QByteArray(fontData); - QCFType<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(fontDataCopy, - fontDataCopy->constData(), fontDataCopy->size(), releaseFontData); - QCFType<CGFontRef> cgFont = CGFontCreateWithDataProvider(dataProvider); - if (cgFont) { - if (CTFontManagerRegisterGraphicsFont(cgFont, &error)) { - QCFType<CTFontRef> font = CTFontCreateWithGraphicsFont(cgFont, 0.0, NULL, NULL); - fonts = createDescriptorArrayForFont(font + CFErrorRef error = 0; + if (!fontData.isEmpty()) { + QByteArray* fontDataCopy = new QByteArray(fontData); + QCFType<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(fontDataCopy, + fontDataCopy->constData(), fontDataCopy->size(), releaseFontData); + QCFType<CGFontRef> cgFont = CGFontCreateWithDataProvider(dataProvider); + if (cgFont) { + if (CTFontManagerRegisterGraphicsFont(cgFont, &error)) { + QCFType<CTFontRef> font = CTFontCreateWithGraphicsFont(cgFont, 0.0, NULL, NULL); + fonts = createDescriptorArrayForFont(font #ifndef QT_NO_FREETYPE - , m_useFreeType ? fileName : QString() -#endif - ); - m_applicationFonts.append(QVariant::fromValue(QCFType<CGFontRef>::constructFromGet(cgFont))); - } - } - } else { - QCFType<CFURLRef> fontURL = CFURLCreateWithFileSystemPath(NULL, QCFString(fileName), kCFURLPOSIXPathStyle, false); - if (CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error)) { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_6, __IPHONE_7_0) - if (&CTFontManagerCreateFontDescriptorsFromURL) - fonts = CTFontManagerCreateFontDescriptorsFromURL(fontURL); - else + , m_useFreeType ? fileName : QString() #endif - { - // We're limited to a single font per file, unless we dive into the font tables - QCFType<CFMutableDictionaryRef> attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, - &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFDictionaryAddValue(attributes, kCTFontURLAttribute, fontURL); - QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithAttributes(attributes); - QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL); - fonts = createDescriptorArrayForFont(font); - } - - m_applicationFonts.append(QVariant::fromValue(QCFType<CFURLRef>::constructFromGet(fontURL))); + ); + m_applicationFonts.append(QVariant::fromValue(QCFType<CGFontRef>::constructFromGet(cgFont))); } } - - if (error) { - NSLog(@"Unable to register font: %@", error); - CFRelease(error); + } else { + QCFType<CFURLRef> fontURL = CFURLCreateWithFileSystemPath(NULL, QCFString(fileName), kCFURLPOSIXPathStyle, false); + if (CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error)) { + fonts = CTFontManagerCreateFontDescriptorsFromURL(fontURL); + m_applicationFonts.append(QVariant::fromValue(QCFType<CFURLRef>::constructFromGet(fontURL))); } } -#endif -#if HAVE_CORETEXT && HAVE_ATS - else -#endif -#if HAVE_ATS - { - ATSFontContainerRef fontContainer; - OSStatus e; - - if (!fontData.isEmpty()) { - e = ATSFontActivateFromMemory((void *) fontData.constData(), fontData.size(), - kATSFontContextLocal, kATSFontFormatUnspecified, NULL, - kATSOptionFlagsDefault, &fontContainer); - } else { - FSRef ref; - if (FSPathMakeRef(reinterpret_cast<const UInt8 *>(fileName.toUtf8().constData()), - &ref, 0) != noErr) - return QStringList(); - e = ATSFontActivateFromFileReference(&ref, kATSFontContextLocal, kATSFontFormatUnspecified, 0, - kATSOptionFlagsDefault, &fontContainer); - } - - if (e == noErr) { - ItemCount fontCount = 0; - e = ATSFontFindFromContainer(fontContainer, kATSOptionFlagsDefault, 0, 0, &fontCount); - if (e != noErr) - return QStringList(); - - QVarLengthArray<ATSFontRef> containedFonts(fontCount); - e = ATSFontFindFromContainer(fontContainer, kATSOptionFlagsDefault, fontCount, containedFonts.data(), &fontCount); - if (e != noErr) - return QStringList(); - - CFMutableArrayRef fontsArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); - for (int i = 0; i < containedFonts.size(); ++i) { - QCFType<CTFontRef> font = CTFontCreateWithPlatformFont(containedFonts[i], 12.0, NULL, NULL); - CFArrayAppendValue(fontsArray, QCFType<CTFontDescriptorRef>(CTFontCopyFontDescriptor(font))); - } - fonts = fontsArray; - - m_applicationFonts.append(QVariant::fromValue(fontContainer)); - } + if (error) { + NSLog(@"Unable to register font: %@", error); + CFRelease(error); } -#endif if (fonts) { const int numFonts = CFArrayGetCount(fonts); @@ -852,41 +779,39 @@ static CTFontUIFontType fontTypeFromTheme(QPlatformTheme::Font f) static CTFontDescriptorRef fontDescriptorFromTheme(QPlatformTheme::Font f) { -#ifdef Q_OS_IOS - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_7_0) { - // Use Dynamic Type to resolve theme fonts if possible, to get - // correct font sizes and style based on user configuration. - NSString *textStyle = 0; - switch (f) { - case QPlatformTheme::TitleBarFont: - case QPlatformTheme::HeaderViewFont: - textStyle = UIFontTextStyleHeadline; - break; - case QPlatformTheme::MdiSubWindowTitleFont: - textStyle = UIFontTextStyleSubheadline; - break; - case QPlatformTheme::TipLabelFont: - case QPlatformTheme::SmallFont: - textStyle = UIFontTextStyleFootnote; - break; - case QPlatformTheme::MiniFont: - textStyle = UIFontTextStyleCaption2; - break; - case QPlatformTheme::FixedFont: - // Fall back to regular code path, as iOS doesn't provide - // an appropriate text style for this theme font. - break; - default: - textStyle = UIFontTextStyleBody; - break; - } +#if defined(QT_PLATFORM_UIKIT) + // Use Dynamic Type to resolve theme fonts if possible, to get + // correct font sizes and style based on user configuration. + NSString *textStyle = 0; + switch (f) { + case QPlatformTheme::TitleBarFont: + case QPlatformTheme::HeaderViewFont: + textStyle = UIFontTextStyleHeadline; + break; + case QPlatformTheme::MdiSubWindowTitleFont: + textStyle = UIFontTextStyleSubheadline; + break; + case QPlatformTheme::TipLabelFont: + case QPlatformTheme::SmallFont: + textStyle = UIFontTextStyleFootnote; + break; + case QPlatformTheme::MiniFont: + textStyle = UIFontTextStyleCaption2; + break; + case QPlatformTheme::FixedFont: + // Fall back to regular code path, as iOS doesn't provide + // an appropriate text style for this theme font. + break; + default: + textStyle = UIFontTextStyleBody; + break; + } - if (textStyle) { - UIFontDescriptor *desc = [UIFontDescriptor preferredFontDescriptorWithTextStyle:textStyle]; - return static_cast<CTFontDescriptorRef>(CFBridgingRetain(desc)); - } + if (textStyle) { + UIFontDescriptor *desc = [UIFontDescriptor preferredFontDescriptorWithTextStyle:textStyle]; + return static_cast<CTFontDescriptorRef>(CFBridgingRetain(desc)); } -#endif // Q_OS_IOS +#endif // Q_OS_IOS, Q_OS_TVOS // OSX default case and iOS fallback case CTFontUIFontType fontType = fontTypeFromTheme(f); @@ -953,31 +878,15 @@ void QCoreTextFontDatabase::removeApplicationFonts() return; foreach (const QVariant &font, m_applicationFonts) { -#if HAVE_CORETEXT - if (&CTFontManagerUnregisterGraphicsFont && &CTFontManagerUnregisterFontsForURL) { - CFErrorRef error; - if (font.canConvert(qMetaTypeId<QCFType<CGFontRef> >())) { - CTFontManagerUnregisterGraphicsFont(font.value<QCFType<CGFontRef> >(), &error); - } else if (font.canConvert(qMetaTypeId<QCFType<CFURLRef> >())) { - CTFontManagerUnregisterFontsForURL(font.value<QCFType<CFURLRef> >(), kCTFontManagerScopeProcess, &error); - } + CFErrorRef error; + if (font.canConvert(qMetaTypeId<QCFType<CGFontRef> >())) { + CTFontManagerUnregisterGraphicsFont(font.value<QCFType<CGFontRef> >(), &error); + } else if (font.canConvert(qMetaTypeId<QCFType<CFURLRef> >())) { + CTFontManagerUnregisterFontsForURL(font.value<QCFType<CFURLRef> >(), kCTFontManagerScopeProcess, &error); } -#endif -#if HAVE_CORETEXT && HAVE_ATS - else -#endif -#if HAVE_ATS - if (font.canConvert(qMetaTypeId<ATSFontContainerRef>())) { - ATSFontDeactivate(font.value<ATSFontContainerRef>(), 0, kATSOptionFlagsDoNotNotify); - } -#endif } m_applicationFonts.clear(); - -#if HAVE_ATS - ATSFontNotify(kATSFontNotifyActionFontsChanged, 0); -#endif } #ifndef QT_NO_FREETYPE diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h index 2cc6b09a15..1bc3522bda 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h @@ -52,27 +52,20 @@ // #include <qglobal.h> -#define HAVE_CORETEXT QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_8, __IPHONE_4_1) -#define HAVE_ATS QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_5, __IPHONE_NA) #include <qpa/qplatformfontdatabase.h> #include <qpa/qplatformtheme.h> #include <private/qcore_mac_p.h> -#ifndef Q_OS_IOS +#ifdef Q_OS_OSX #include <ApplicationServices/ApplicationServices.h> #else #include <CoreText/CoreText.h> #include <CoreGraphics/CoreGraphics.h> #endif -#if HAVE_CORETEXT Q_DECLARE_METATYPE(QCFType<CGFontRef>); Q_DECLARE_METATYPE(QCFType<CFURLRef>); -#endif -#if HAVE_ATS -Q_DECLARE_METATYPE(ATSFontContainerRef); -#endif QT_BEGIN_NAMESPACE diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index d11676ced7..fbad61af43 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -51,7 +51,7 @@ #import <AppKit/AppKit.h> #endif -#if defined(Q_OS_IOS) && !QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_8_2) +#if defined(QT_PLATFORM_UIKIT) && !QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_8_2) #import <UIKit/UIKit.h> #endif @@ -78,7 +78,7 @@ #define kCTFontWeightBold NSFontWeightBold #define kCTFontWeightHeavy NSFontWeightHeavy #define kCTFontWeightBlack NSFontWeightBlack -#elif defined(Q_OS_IOS) +#elif defined(QT_PLATFORM_UIKIT) #define kCTFontWeightUltraLight UIFontWeightUltraLight #define kCTFontWeightThin UIFontWeightThin #define kCTFontWeightLight UIFontWeightLight @@ -256,6 +256,9 @@ void QCoreTextFontEngine::init() } else avgCharWidth = QFontEngine::averageCharWidth(); + underlineThickness = QFixed::fromReal(CTFontGetUnderlineThickness(ctfont)); + underlinePos = -QFixed::fromReal(CTFontGetUnderlinePosition(ctfont)); + cache_cost = (CTFontGetAscent(ctfont) + CTFontGetDescent(ctfont)) * avgCharWidth.toInt() * 2000; // HACK hb_coretext requires both CTFont and CGFont but user_data is only void* @@ -437,31 +440,25 @@ void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextIt CGContextSetTextDrawingMode(ctx, kCGTextFill); - - QVarLengthArray<CGSize> advances(glyphs.size()); + QVarLengthArray<CGPoint> cgPositions(glyphs.size()); QVarLengthArray<CGGlyph> cgGlyphs(glyphs.size()); - - for (int i = 0; i < glyphs.size() - 1; ++i) { - advances[i].width = (positions[i + 1].x - positions[i].x).toReal(); - advances[i].height = (positions[i + 1].y - positions[i].y).toReal(); + const qreal firstX = positions[0].x.toReal(); + const qreal firstY = positions[0].y.toReal(); + for (int i = 0; i < glyphs.size(); ++i) { + cgPositions[i].x = positions[i].x.toReal() - firstX; + cgPositions[i].y = positions[i].y.toReal() - firstY; cgGlyphs[i] = glyphs[i]; } - advances[glyphs.size() - 1].width = 0; - advances[glyphs.size() - 1].height = 0; - cgGlyphs[glyphs.size() - 1] = glyphs[glyphs.size() - 1]; - CGContextSetFont(ctx, cgFont); //NSLog(@"Font inDraw %@ ctfont %@", CGFontCopyFullName(cgFont), CTFontCopyFamilyName(ctfont)); CGContextSetTextPosition(ctx, positions[0].x.toReal(), positions[0].y.toReal()); - - CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size()); + CTFontDrawGlyphs(ctfont, cgGlyphs.data(), cgPositions.data(), glyphs.size(), ctx); if (synthesisFlags & QFontEngine::SynthesizedBold) { CGContextSetTextPosition(ctx, positions[0].x.toReal() + 0.5 * lineThickness().toReal(), positions[0].y.toReal()); - - CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size()); + CTFontDrawGlyphs(ctfont, cgGlyphs.data(), cgPositions.data(), glyphs.size(), ctx); } CGContextSetTextMatrix(ctx, oldTextMatrix); @@ -606,7 +603,7 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition if (!im.width() || !im.height()) return im; -#ifndef Q_OS_IOS +#ifdef Q_OS_OSX CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); #else CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); @@ -645,14 +642,13 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition CGContextSetTextMatrix(ctx, cgMatrix); CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); CGContextSetTextDrawingMode(ctx, kCGTextFill); - CGContextSetFont(ctx, cgFont); CGContextSetTextPosition(ctx, pos_x, pos_y); - CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &CGSizeZero, 1); + CTFontDrawGlyphs(ctfont, &cgGlyph, &CGPointZero, 1, ctx); if (synthesisFlags & QFontEngine::SynthesizedBold) { CGContextSetTextPosition(ctx, pos_x + 0.5 * lineThickness().toReal(), pos_y); - CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &CGSizeZero, 1); + CTFontDrawGlyphs(ctfont, &cgGlyph, &CGPointZero, 1, ctx); } } else { // CGContextSetTextMatrix does not work with color glyphs, so we use @@ -800,6 +796,16 @@ bool QCoreTextFontEngine::supportsTransformation(const QTransform &transform) co return false; } +QFixed QCoreTextFontEngine::lineThickness() const +{ + return underlineThickness; +} + +QFixed QCoreTextFontEngine::underlinePosition() const +{ + return underlinePos; +} + QFontEngine::Properties QCoreTextFontEngine::properties() const { Properties result; diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 22008162f7..b7c9edc528 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -54,7 +54,7 @@ #include <private/qfontengine_p.h> #include <private/qcore_mac_p.h> -#ifndef Q_OS_IOS +#ifdef Q_OS_OSX #include <ApplicationServices/ApplicationServices.h> #else #include <CoreText/CoreText.h> @@ -92,6 +92,9 @@ public: int synthesized() const Q_DECL_OVERRIDE { return synthesisFlags; } bool supportsSubPixelPositions() const Q_DECL_OVERRIDE { return true; } + QFixed lineThickness() const Q_DECL_OVERRIDE; + QFixed underlinePosition() const Q_DECL_OVERRIDE; + void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight); FaceId faceId() const Q_DECL_OVERRIDE; @@ -126,6 +129,8 @@ private: int synthesisFlags; CGAffineTransform transform; QFixed avgCharWidth; + QFixed underlineThickness; + QFixed underlinePos; QFontEngine::FaceId face_id; mutable bool kerningPairsLoaded; }; diff --git a/src/platformsupport/graphics/qrasterbackingstore.cpp b/src/platformsupport/graphics/qrasterbackingstore.cpp index 3b1a87b8cd..58e811dff1 100644 --- a/src/platformsupport/graphics/qrasterbackingstore.cpp +++ b/src/platformsupport/graphics/qrasterbackingstore.cpp @@ -89,7 +89,7 @@ bool QRasterBackingStore::scroll(const QRegion ®ion, int dx, int dy) const qreal devicePixelRatio = m_image.devicePixelRatio(); const QPoint delta(dx * devicePixelRatio, dy * devicePixelRatio); - foreach (const QRect &rect, region.rects()) + for (const QRect &rect : region) qt_scrollRectInImage(m_image, QRect(rect.topLeft() * devicePixelRatio, rect.size() * devicePixelRatio), delta); return true; @@ -103,7 +103,7 @@ void QRasterBackingStore::beginPaint(const QRegion ®ion) QPainter painter(&m_image); painter.setCompositionMode(QPainter::CompositionMode_Source); const QColor blank = Qt::transparent; - foreach (const QRect &rect, region.rects()) + for (const QRect &rect : region) painter.fillRect(rect, blank); } diff --git a/src/platformsupport/input/evdevtouch/evdevtouch.pri b/src/platformsupport/input/evdevtouch/evdevtouch.pri index c2edc13143..44eb9da113 100644 --- a/src/platformsupport/input/evdevtouch/evdevtouch.pri +++ b/src/platformsupport/input/evdevtouch/evdevtouch.pri @@ -6,6 +6,8 @@ SOURCES += \ $$PWD/qevdevtouchhandler.cpp \ $$PWD/qevdevtouchmanager.cpp +INCLUDEPATH += $$PWD/../shared + contains(QT_CONFIG, libudev) { LIBS_PRIVATE += $$QMAKE_LIBS_LIBUDEV } @@ -14,4 +16,3 @@ contains(QT_CONFIG, mtdev) { CONFIG += link_pkgconfig PKGCONFIG_PRIVATE += mtdev } - diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index 435f411f96..f9e81e840f 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qevdevtouchhandler_p.h" +#include "qtouchoutputmapping_p.h" #include <QStringList> #include <QHash> #include <QSocketNotifier> @@ -116,6 +117,7 @@ public: int findClosestContact(const QHash<int, Contact> &contacts, int x, int y, int *dist); void addTouchPoint(const Contact &contact, Qt::TouchPointStates *combinedStates); void reportPoints(); + void loadMultiScreenMappings(); int hw_range_x_min; int hw_range_x_max; @@ -124,10 +126,12 @@ public: int hw_pressure_min; int hw_pressure_max; QString hw_name; + QString deviceNode; bool m_forceToActiveWindow; bool m_typeB; QTransform m_rotate; bool m_singleTouch; + int m_screenIndex; }; QEvdevTouchScreenData::QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, const QStringList &args) @@ -137,7 +141,8 @@ QEvdevTouchScreenData::QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, co hw_range_x_min(0), hw_range_x_max(0), hw_range_y_min(0), hw_range_y_max(0), hw_pressure_min(0), hw_pressure_max(0), - m_typeB(false), m_singleTouch(false) + m_typeB(false), m_singleTouch(false), + m_screenIndex(-1) { m_forceToActiveWindow = args.contains(QLatin1String("force_window")); } @@ -222,7 +227,9 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const } #endif - qCDebug(qLcEvdevTouch, "evdevtouch: %s: Protocol type %c %s (%s)", qPrintable(device), + d->deviceNode = device; + + qCDebug(qLcEvdevTouch, "evdevtouch: %s: Protocol type %c %s (%s)", qPrintable(d->deviceNode), d->m_typeB ? 'B' : 'A', mtdevStr, d->m_singleTouch ? "single" : "multi"); input_absinfo absInfo; @@ -292,6 +299,14 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const if (inverty) d->m_rotate *= QTransform::fromTranslate(0.5, 0.5).scale(1.0, -1.0).translate(-0.5, -0.5); + QTouchOutputMapping mapping; + if (mapping.load()) { + d->m_screenIndex = mapping.screenIndexForDeviceNode(d->deviceNode); + if (d->m_screenIndex >= 0) + qCDebug(qLcEvdevTouch, "evdevtouch: Mapping device %s to screen index %d", + qPrintable(d->deviceNode), d->m_screenIndex); + } + registerTouchDevice(); } @@ -647,8 +662,23 @@ void QEvdevTouchScreenData::reportPoints() return; winRect = QHighDpi::toNativePixels(win->geometry(), win); } else { - QScreen *primary = QGuiApplication::primaryScreen(); - winRect = QHighDpi::toNativePixels(primary->geometry(), primary); + // Now it becomes tricky. Traditionally we picked the primaryScreen() + // and were done with it. But then, enter multiple screens, and + // suddenly it was all broken. + // + // For now we only support the display configuration of the KMS/DRM + // backends of eglfs. See QTouchOutputMapping. + // + // The good news it that once winRect refers to the correct screen + // geometry in the full virtual desktop space, there is nothing else + // left to do since qguiapp will handle the rest. + QScreen *screen = QGuiApplication::primaryScreen(); + if (m_screenIndex >= 0) { + const QList<QScreen *> screens = QGuiApplication::screens(); + if (m_screenIndex < screens.count()) + screen = screens.at(m_screenIndex); + } + winRect = QHighDpi::toNativePixels(screen->geometry(), screen); } const int hw_w = hw_range_x_max - hw_range_x_min; @@ -679,10 +709,12 @@ void QEvdevTouchScreenData::reportPoints() tp.pressure = (tp.pressure - hw_pressure_min) / qreal(hw_pressure_max - hw_pressure_min); } + // Let qguiapp pick the target window. QWindowSystemInterface::handleTouchEvent(Q_NULLPTR, q->touchDevice(), m_touchPoints); } + QEvdevTouchScreenHandlerThread::QEvdevTouchScreenHandlerThread(const QString &device, const QString &spec, QObject *parent) : QDaemonThread(parent), m_device(device), m_spec(spec), m_handler(Q_NULLPTR), m_touchDeviceRegistered(false) { diff --git a/src/platformsupport/input/input.pri b/src/platformsupport/input/input.pri index 3b9593eb31..5ce9e6844f 100644 --- a/src/platformsupport/input/input.pri +++ b/src/platformsupport/input/input.pri @@ -12,3 +12,7 @@ contains(QT_CONFIG, tslib) { contains(QT_CONFIG, libinput) { include($$PWD/libinput/libinput.pri) } + +contains(QT_CONFIG, evdev)|contains(QT_CONFIG, libinput) { + include($$PWD/shared/shared.pri) +} diff --git a/src/platformsupport/input/libinput/libinput.pri b/src/platformsupport/input/libinput/libinput.pri index 35d962ff3c..aeba6c725a 100644 --- a/src/platformsupport/input/libinput/libinput.pri +++ b/src/platformsupport/input/libinput/libinput.pri @@ -13,6 +13,8 @@ SOURCES += \ INCLUDEPATH += $$QMAKE_INCDIR_LIBUDEV $$QMAKE_INCDIR_LIBINPUT LIBS_PRIVATE += $$QMAKE_LIBS_LIBUDEV $$QMAKE_LIBS_LIBINPUT +INCLUDEPATH += $$PWD/../shared + contains(QT_CONFIG, xkbcommon-evdev) { INCLUDEPATH += $$QMAKE_INCDIR_XKBCOMMON_EVDEV LIBS_PRIVATE += $$QMAKE_LIBS_XKBCOMMON_EVDEV diff --git a/src/platformsupport/input/libinput/qlibinputtouch.cpp b/src/platformsupport/input/libinput/qlibinputtouch.cpp index 0a0e9daccb..42925a18e1 100644 --- a/src/platformsupport/input/libinput/qlibinputtouch.cpp +++ b/src/platformsupport/input/libinput/qlibinputtouch.cpp @@ -41,6 +41,7 @@ #include <libinput.h> #include <QtGui/QGuiApplication> #include <QtGui/QScreen> +#include <QtGui/private/qhighdpiscaling_p.h> QT_BEGIN_NAMESPACE @@ -63,10 +64,14 @@ QLibInputTouch::DeviceState *QLibInputTouch::deviceState(libinput_event_touch *e static inline QPointF getPos(libinput_event_touch *e) { - const QSize screenSize = QGuiApplication::primaryScreen()->geometry().size(); - const double x = libinput_event_touch_get_x_transformed(e, screenSize.width()); - const double y = libinput_event_touch_get_y_transformed(e, screenSize.height()); - return QPointF(x, y); + // TODO Map to correct screen using QTouchOutputMapping. + // Perhaps investigate libinput_device_get_output_name as well. + // For now just use the primary screen. + QScreen *screen = QGuiApplication::primaryScreen(); + const QRect geom = QHighDpi::toNativePixels(screen->geometry(), screen); + const double x = libinput_event_touch_get_x_transformed(e, geom.width()); + const double y = libinput_event_touch_get_y_transformed(e, geom.height()); + return geom.topLeft() + QPointF(x, y); } void QLibInputTouch::registerDevice(libinput_device *dev) diff --git a/src/platformsupport/input/shared/qtouchoutputmapping.cpp b/src/platformsupport/input/shared/qtouchoutputmapping.cpp new file mode 100644 index 0000000000..55c1dc34f4 --- /dev/null +++ b/src/platformsupport/input/shared/qtouchoutputmapping.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins module 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$ +** +****************************************************************************/ + +#include "qtouchoutputmapping_p.h" +#include <QFile> +#include <QVariantMap> +#include <QJsonDocument> +#include <QJsonObject> +#include <QJsonArray> + +QT_BEGIN_NAMESPACE + +bool QTouchOutputMapping::load() +{ + static QByteArray configFile = qgetenv("QT_QPA_EGLFS_KMS_CONFIG"); + if (configFile.isEmpty()) + return false; + + QFile file(QString::fromUtf8(configFile)); + if (!file.open(QFile::ReadOnly)) { + qWarning("touch input support: Failed to open %s", configFile.constData()); + return false; + } + + const QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); + if (!doc.isObject()) { + qWarning("touch input support: Failed to parse %s", configFile.constData()); + return false; + } + + // What we are interested is the virtualIndex and touchDevice properties for + // each element in the outputs array. + const QJsonArray outputs = doc.object().value(QLatin1String("outputs")).toArray(); + for (int i = 0; i < outputs.size(); ++i) { + const QVariantMap output = outputs.at(i).toObject().toVariantMap(); + if (!output.contains(QStringLiteral("touchDevice"))) + continue; + if (!output.contains(QStringLiteral("virtualIndex"))) { + qWarning("evdevtouch: Output %d specifies touchDevice but not virtualIndex, this is wrong", i); + continue; + } + const QString &deviceNode = output.value(QStringLiteral("touchDevice")).toString(); + const int screenIndex = output.value(QStringLiteral("virtualIndex")).toInt(); + m_screenIndexTable.insert(deviceNode, screenIndex); + } + + return true; +} + +int QTouchOutputMapping::screenIndexForDeviceNode(const QString &deviceNode) +{ + return m_screenIndexTable.value(deviceNode, -1); +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/input/shared/qtouchoutputmapping_p.h b/src/platformsupport/input/shared/qtouchoutputmapping_p.h new file mode 100644 index 0000000000..74999d93ce --- /dev/null +++ b/src/platformsupport/input/shared/qtouchoutputmapping_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins module 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$ +** +****************************************************************************/ + +#ifndef QTOUCHOUTPUTMAPPING_P_H +#define QTOUCHOUTPUTMAPPING_P_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 <QString> +#include <QHash> + +QT_BEGIN_NAMESPACE + +class QTouchOutputMapping +{ +public: + bool load(); + int screenIndexForDeviceNode(const QString &deviceNode); + +private: + QHash<QString, int> m_screenIndexTable; +}; + +QT_END_NAMESPACE + +#endif // QTOUCHOUTPUTMAPPING_P_H diff --git a/src/platformsupport/input/shared/shared.pri b/src/platformsupport/input/shared/shared.pri new file mode 100644 index 0000000000..1443235244 --- /dev/null +++ b/src/platformsupport/input/shared/shared.pri @@ -0,0 +1,5 @@ +HEADERS += \ + $$PWD/qtouchoutputmapping_p.h + +SOURCES += \ + $$PWD/qtouchoutputmapping.cpp diff --git a/src/platformsupport/linuxaccessibility/atspiadaptor.cpp b/src/platformsupport/linuxaccessibility/atspiadaptor.cpp index 8366c56a09..f6c126a771 100644 --- a/src/platformsupport/linuxaccessibility/atspiadaptor.cpp +++ b/src/platformsupport/linuxaccessibility/atspiadaptor.cpp @@ -778,9 +778,8 @@ void AtSpiAdaptor::updateEventListeners() QDBusReply<QSpiEventListenerArray> listenersReply = m_dbus->connection().call(m); if (listenersReply.isValid()) { const QSpiEventListenerArray evList = listenersReply.value(); - Q_FOREACH (const QSpiEventListener &ev, evList) { + for (const QSpiEventListener &ev : evList) setBitFlag(ev.eventName); - } m_applicationAdaptor->sendEvents(!evList.isEmpty()); } else { qAtspiDebug("Could not query active accessibility event listeners."); @@ -1508,11 +1507,10 @@ QStringList AtSpiAdaptor::accessibleInterfaces(QAccessibleInterface *interface) QSpiRelationArray AtSpiAdaptor::relationSet(QAccessibleInterface *interface, const QDBusConnection &connection) const { typedef QPair<QAccessibleInterface*, QAccessible::Relation> RelationPair; - QVector<RelationPair> relationInterfaces; - relationInterfaces = interface->relations(); + const QVector<RelationPair> relationInterfaces = interface->relations(); QSpiRelationArray relations; - Q_FOREACH (const RelationPair &pair, relationInterfaces) { + for (const RelationPair &pair : relationInterfaces) { // FIXME: this loop seems a bit strange... "related" always have one item when we check. //And why is it a list, when it always have one item? And it seems to assume that the QAccessible::Relation enum maps directly to AtSpi QSpiObjectReferenceArray related; @@ -1757,24 +1755,20 @@ QSpiActionArray AtSpiAdaptor::getActions(QAccessibleInterface *interface) const QSpiActionArray actions; const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface); actions.reserve(actionNames.size()); - Q_FOREACH (const QString &actionName, actionNames) { + for (const QString &actionName : actionNames) { QSpiAction action; - QStringList keyBindings; action.name = actionName; if (actionInterface) { action.description = actionInterface->localizedActionDescription(actionName); - keyBindings = actionInterface->keyBindingsForAction(actionName); + const QStringList keyBindings = actionInterface->keyBindingsForAction(actionName); + if (!keyBindings.isEmpty()) + action.keyBinding = keyBindings.front(); } else { action.description = qAccessibleLocalizedActionDescription(actionName); } - if (keyBindings.length() > 0) - action.keyBinding = keyBindings[0]; - else - action.keyBinding = QString(); - - actions << action; + actions.append(std::move(action)); } return actions; } diff --git a/src/platformsupport/platformcompositor/qopenglcompositor.cpp b/src/platformsupport/platformcompositor/qopenglcompositor.cpp index 610619a4e4..0f4946f81a 100644 --- a/src/platformsupport/platformcompositor/qopenglcompositor.cpp +++ b/src/platformsupport/platformcompositor/qopenglcompositor.cpp @@ -40,7 +40,6 @@ #include <QtGui/QOpenGLContext> #include <QtGui/QOpenGLFramebufferObject> #include <QtGui/QWindow> -#include <QtGui/QMatrix4x4> #include <qpa/qplatformbackingstore.h> #include "qopenglcompositor_p.h" @@ -78,7 +77,8 @@ static QOpenGLCompositor *compositor = 0; QOpenGLCompositor::QOpenGLCompositor() : m_context(0), - m_targetWindow(0) + m_targetWindow(0), + m_rotation(0) { Q_ASSERT(!compositor); m_updateTimer.setSingleShot(true); @@ -93,10 +93,19 @@ QOpenGLCompositor::~QOpenGLCompositor() compositor = 0; } -void QOpenGLCompositor::setTarget(QOpenGLContext *context, QWindow *targetWindow) +void QOpenGLCompositor::setTarget(QOpenGLContext *context, QWindow *targetWindow, + const QRect &nativeTargetGeometry) { m_context = context; m_targetWindow = targetWindow; + m_nativeTargetGeometry = nativeTargetGeometry; +} + +void QOpenGLCompositor::setRotation(int degrees) +{ + m_rotation = degrees; + m_rotationMatrix.setToIdentity(); + m_rotationMatrix.rotate(degrees, 0, 0, 1); } void QOpenGLCompositor::update() @@ -109,7 +118,7 @@ QImage QOpenGLCompositor::grab() { Q_ASSERT(m_context && m_targetWindow); m_context->makeCurrent(m_targetWindow); - QScopedPointer<QOpenGLFramebufferObject> fbo(new QOpenGLFramebufferObject(m_targetWindow->geometry().size())); + QScopedPointer<QOpenGLFramebufferObject> fbo(new QOpenGLFramebufferObject(m_nativeTargetGeometry.size())); renderAll(fbo.data()); return fbo->toImage(); } @@ -127,9 +136,7 @@ void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo) fbo->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - - const QRect targetWindowRect(QPoint(0, 0), m_targetWindow->geometry().size()); - glViewport(0, 0, targetWindowRect.width(), targetWindowRect.height()); + glViewport(0, 0, m_nativeTargetGeometry.width(), m_nativeTargetGeometry.height()); if (!m_blitter.isCreated()) m_blitter.create(); @@ -181,7 +188,8 @@ static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight) topLeftRect.width(), topLeftRect.height()); } -static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &targetWindowRect, QOpenGLTextureBlitter *blitter) +static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &targetWindowRect, + QOpenGLTextureBlitter *blitter, QMatrix4x4 *rotationMatrix) { const QRect clipRect = textures->clipRect(idx); if (clipRect.isEmpty()) @@ -191,7 +199,10 @@ static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRe const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft()); const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height()); - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(clippedRectInWindow, targetWindowRect); + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(clippedRectInWindow, targetWindowRect); + if (rotationMatrix) + target = *rotationMatrix * target; + const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, rectInWindow.size(), QOpenGLTextureBlitter::OriginBottomLeft); @@ -219,25 +230,29 @@ void QOpenGLCompositor::render(QOpenGLCompositorWindow *window) if (textures->count() > 1 && i == textures->count() - 1) { // Backingstore for a widget with QOpenGLWidget subwidgets blend.set(true); - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); + if (m_rotation) + target = m_rotationMatrix * target; m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); } else if (textures->count() == 1) { // A regular QWidget window const bool translucent = window->sourceWindow()->requestedFormat().alphaBufferSize() > 0; blend.set(translucent); - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); + if (m_rotation) + target = m_rotationMatrix * target; m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); } else if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { // Texture from an FBO belonging to a QOpenGLWidget blend.set(false); - clippedBlit(textures, i, targetWindowRect, &m_blitter); + clippedBlit(textures, i, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); } } for (int i = 0; i < textures->count(); ++i) { if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { blend.set(true); - clippedBlit(textures, i, targetWindowRect, &m_blitter); + clippedBlit(textures, i, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); } } diff --git a/src/platformsupport/platformcompositor/qopenglcompositor_p.h b/src/platformsupport/platformcompositor/qopenglcompositor_p.h index 2c34fba409..dece41f676 100644 --- a/src/platformsupport/platformcompositor/qopenglcompositor_p.h +++ b/src/platformsupport/platformcompositor/qopenglcompositor_p.h @@ -52,7 +52,8 @@ // #include <QtCore/QTimer> -#include <QtGui/private/qopengltextureblitter_p.h> +#include <QtGui/QOpenGLTextureBlitter> +#include <QtGui/QMatrix4x4> QT_BEGIN_NAMESPACE @@ -78,7 +79,8 @@ public: static QOpenGLCompositor *instance(); static void destroy(); - void setTarget(QOpenGLContext *context, QWindow *window); + void setTarget(QOpenGLContext *context, QWindow *window, const QRect &nativeTargetGeometry); + void setRotation(int degrees); QOpenGLContext *context() const { return m_context; } QWindow *targetWindow() const { return m_targetWindow; } @@ -106,6 +108,9 @@ private: QOpenGLContext *m_context; QWindow *m_targetWindow; + QRect m_nativeTargetGeometry; + int m_rotation; + QMatrix4x4 m_rotationMatrix; QTimer m_updateTimer; QOpenGLTextureBlitter m_blitter; QList<QOpenGLCompositorWindow *> m_windows; diff --git a/src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp b/src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp index 7c29be7804..dbaaf524e8 100644 --- a/src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp +++ b/src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp @@ -140,7 +140,7 @@ void QOpenGLCompositorBackingStore::updateTexture() QOpenGLContext *ctx = QOpenGLContext::currentContext(); if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { - foreach (const QRect &rect, m_dirty.rects()) { + for (const QRect &rect : m_dirty) { QRect r = imageRect & rect; glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image.width()); glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y(), r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, @@ -148,7 +148,7 @@ void QOpenGLCompositorBackingStore::updateTexture() glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } } else { - foreach (const QRect &rect, m_dirty.rects()) { + for (const QRect &rect : m_dirty) { // intersect with image rect to be sure QRect r = imageRect & rect; @@ -161,7 +161,7 @@ void QOpenGLCompositorBackingStore::updateTexture() fixed |= r; } - foreach (const QRect &rect, fixed.rects()) { + for (const QRect &rect : fixed) { // if the sub-rect is full-width we can pass the image data directly to // OpenGL instead of copying, since there's no gap between scanlines if (rect.width() == imageRect.width()) { @@ -258,7 +258,7 @@ void QOpenGLCompositorBackingStore::beginPaint(const QRegion ®ion) if (m_image.hasAlphaChannel()) { QPainter p(&m_image); p.setCompositionMode(QPainter::CompositionMode_Source); - foreach (const QRect &r, region.rects()) + for (const QRect &r : region) p.fillRect(r, Qt::transparent); } } diff --git a/src/platformsupport/platformsupport.pro b/src/platformsupport/platformsupport.pro index 60be964b74..9f6f3380e1 100644 --- a/src/platformsupport/platformsupport.pro +++ b/src/platformsupport/platformsupport.pro @@ -29,6 +29,6 @@ include(platformcompositor/platformcompositor.pri) include(dbusmenu/dbusmenu.pri) include(dbustray/dbustray.pri) } -ios: include(graphics/graphics.pri) +uikit: include(graphics/graphics.pri) load(qt_module) diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 9abcd04063..a5001f6e80 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -50,6 +50,7 @@ #include <QtCore/QFile> #include <QtCore/QDebug> #include <QtCore/QHash> +#include <QtCore/QMimeDatabase> #include <QtCore/QLoggingCategory> #include <QtCore/QSettings> #include <QtCore/QVariant> @@ -231,6 +232,28 @@ QVariant QGenericUnixTheme::themeHint(ThemeHint hint) const return QPlatformTheme::themeHint(hint); } +// Helper functions for implementing QPlatformTheme::fileIcon() for XDG icon themes. +static QList<QSize> availableXdgFileIconSizes() +{ + return QIcon::fromTheme(QStringLiteral("inode-directory")).availableSizes(); +} + +static QIcon xdgFileIcon(const QFileInfo &fileInfo) +{ + QMimeDatabase mimeDatabase; + QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileInfo); + if (!mimeType.isValid()) + return QIcon(); + const QString &iconName = mimeType.iconName(); + if (!iconName.isEmpty()) { + const QIcon icon = QIcon::fromTheme(iconName); + if (!icon.isNull()) + return icon; + } + const QString &genericIconName = mimeType.genericIconName(); + return genericIconName.isEmpty() ? QIcon() : QIcon::fromTheme(genericIconName); +} + #ifndef QT_NO_SETTINGS class QKdeThemePrivate : public QPlatformThemePrivate { @@ -506,6 +529,8 @@ QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QVariant(d->iconFallbackThemeName); case QPlatformTheme::IconThemeSearchPaths: return QVariant(d->kdeIconThemeSearchPaths(d->kdeDirs)); + case QPlatformTheme::IconPixmapSizes: + return QVariant::fromValue(availableXdgFileIconSizes()); case QPlatformTheme::StyleNames: return QVariant(d->styleNames); case QPlatformTheme::KeyboardScheme: @@ -520,6 +545,11 @@ QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QPlatformTheme::themeHint(hint); } +QIcon QKdeTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions) const +{ + return xdgFileIcon(fileInfo); +} + const QPalette *QKdeTheme::palette(Palette type) const { Q_D(const QKdeTheme); @@ -657,6 +687,8 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QVariant(QStringLiteral("gnome")); case QPlatformTheme::IconThemeSearchPaths: return QVariant(QGenericUnixTheme::xdgIconThemePaths()); + case QPlatformTheme::IconPixmapSizes: + return QVariant::fromValue(availableXdgFileIconSizes()); case QPlatformTheme::StyleNames: { QStringList styleNames; styleNames << QStringLiteral("fusion") << QStringLiteral("windows"); @@ -666,12 +698,19 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QVariant(int(GnomeKeyboardScheme)); case QPlatformTheme::PasswordMaskCharacter: return QVariant(QChar(0x2022)); + case QPlatformTheme::UiEffects: + return QVariant(int(HoverEffect)); default: break; } return QPlatformTheme::themeHint(hint); } +QIcon QGnomeTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions) const +{ + return xdgFileIcon(fileInfo); +} + const QFont *QGnomeTheme::font(Font type) const { Q_D(const QGnomeTheme); diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h index 952658e130..da13390662 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h @@ -107,6 +107,9 @@ public: static QPlatformTheme *createKdeTheme(); QVariant themeHint(ThemeHint hint) const Q_DECL_OVERRIDE; + QIcon fileIcon(const QFileInfo &fileInfo, + QPlatformTheme::IconOptions iconOptions = 0) const override; + const QPalette *palette(Palette type = SystemPalette) const Q_DECL_OVERRIDE; const QFont *font(Font type) const Q_DECL_OVERRIDE; @@ -129,6 +132,8 @@ class QGnomeTheme : public QPlatformTheme public: QGnomeTheme(); QVariant themeHint(ThemeHint hint) const Q_DECL_OVERRIDE; + QIcon fileIcon(const QFileInfo &fileInfo, + QPlatformTheme::IconOptions = 0) const override; const QFont *font(Font type) const Q_DECL_OVERRIDE; QString standardButtonText(int button) const Q_DECL_OVERRIDE; diff --git a/src/platformsupport/themes/qabstractfileiconengine.cpp b/src/platformsupport/themes/qabstractfileiconengine.cpp new file mode 100644 index 0000000000..19a8eee47b --- /dev/null +++ b/src/platformsupport/themes/qabstractfileiconengine.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins 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$ +** +****************************************************************************/ + +#include "qabstractfileiconengine_p.h" + +#include <qpixmapcache.h> + +QT_BEGIN_NAMESPACE + +/*! + \class QAbstractFileIconEngine + \brief Helper base class for retrieving icons for files for usage by QFileIconProvider and related. + + Reimplement availableSizes() and new virtual filePixmap() and return icons created + with this engine from QPlatformTheme::fileIcon(). + + Note: The class internally caches pixmaps for files by suffix (with the exception + of some files on Windows), but not for directories (since directory icons may have + overlay icons on Windows). You might want to cache pixmaps for directories + in your implementation. + + \since 5.8 + \internal + \sa QFileIconProvider::DontUseCustomDirectoryIcons, QPlatformTheme + \ingroup qpa +*/ +QPixmap QAbstractFileIconEngine::pixmap(const QSize &size, QIcon::Mode mode, + QIcon::State state) +{ + Q_UNUSED(mode); + Q_UNUSED(state); + + if (!size.isValid()) + return QPixmap(); + + QString key = cacheKey(); + if (key.isEmpty()) + return filePixmap(size, mode, state); + + key += QLatin1Char('_'); + key += QString::number(size.width()); + + QPixmap result; + if (!QPixmapCache::find(key, result)) { + result = filePixmap(size, mode, state); + if (!result.isNull()) + QPixmapCache::insert(key, result); + } + + return result; +} + +QSize QAbstractFileIconEngine::actualSize(const QSize &size, QIcon::Mode mode, + QIcon::State state) +{ + const QList<QSize> &sizes = availableSizes(mode, state); + const int numberSizes = sizes.length(); + if (numberSizes == 0) + return QSize(); + + // Find the smallest available size whose area is still larger than the input + // size. Otherwise, use the largest area available size. (We don't assume the + // platform theme sizes are sorted, hence the extra logic.) + const int sizeArea = size.width() * size.height(); + QSize actualSize = sizes.first(); + int actualArea = actualSize.width() * actualSize.height(); + for (int i = 1; i < numberSizes; ++i) { + const QSize &s = sizes.at(i); + const int a = s.width() * s.height(); + if ((sizeArea <= a && a < actualArea) || (actualArea < sizeArea && actualArea < a)) { + actualSize = s; + actualArea = a; + } + } + + if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height())) + actualSize.scale(size, Qt::KeepAspectRatio); + + return actualSize; +} + +/* Reimplement to return a cache key for the entry. An empty result indicates + * the icon should not be cached (for example, directory icons having custom icons). */ +QString QAbstractFileIconEngine::cacheKey() const +{ + if (!m_fileInfo.isFile() || m_fileInfo.isSymLink() || m_fileInfo.isExecutable()) + return QString(); + + const QString &suffix = m_fileInfo.suffix(); + return QLatin1String("qt_.") + + (suffix.isEmpty() ? m_fileInfo.fileName() : suffix); // handle "Makefile" ;) +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/themes/qabstractfileiconengine_p.h b/src/platformsupport/themes/qabstractfileiconengine_p.h new file mode 100644 index 0000000000..ce38cf262e --- /dev/null +++ b/src/platformsupport/themes/qabstractfileiconengine_p.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins 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$ +** +****************************************************************************/ + +#ifndef QABSTRACTFILEICONENGINE_P_H +#define QABSTRACTFILEICONENGINE_P_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 <QtCore/qfileinfo.h> +#include <private/qicon_p.h> +#include <qpa/qplatformtheme.h> + +QT_BEGIN_NAMESPACE + +class QAbstractFileIconEngine : public QPixmapIconEngine +{ +public: + explicit QAbstractFileIconEngine(const QFileInfo &info, QPlatformTheme::IconOptions opts) + : QPixmapIconEngine(), m_fileInfo(info), m_options(opts) {} + + QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State) override; + QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override; + + QFileInfo fileInfo() const { return m_fileInfo; } + QPlatformTheme::IconOptions options() const { return m_options; } + + // Helper to convert a sequence of ints to a list of QSize + template <class It> static QList<QSize> toSizeList(It i1, It i2); + +protected: + virtual QPixmap filePixmap(const QSize &size, QIcon::Mode mode, QIcon::State) = 0; + virtual QString cacheKey() const; + +private: + const QFileInfo m_fileInfo; + const QPlatformTheme::IconOptions m_options; +}; + +template <class It> +inline QList<QSize> QAbstractFileIconEngine::toSizeList(It i1, It i2) +{ + QList<QSize> result; + result.reserve(int(i2 - i1)); + for ( ; i1 != i2; ++i1) + result.append(QSize(*i1, *i1)); + return result; +} + +QT_END_NAMESPACE + +#endif // QABSTRACTFILEICONENGINE_P_H diff --git a/src/platformsupport/themes/themes.pri b/src/platformsupport/themes/themes.pri index adee852626..552973431f 100644 --- a/src/platformsupport/themes/themes.pri +++ b/src/platformsupport/themes/themes.pri @@ -1,3 +1,9 @@ unix:!mac { include($$PWD/genericunix/genericunix.pri) } + +HEADERS += \ + $$PWD/qabstractfileiconengine_p.h + +SOURCES += \ + $$PWD/qabstractfileiconengine.cpp |