diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index c92a6746..17cf3e61 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -33,7 +33,7 @@ void *originalSetSystemUIMode = 0; void UBPlatformUtils::init() { - initializeKeyboardLayouts(); + initializeKeyboardLayouts(); // qwidget_mac.mm qt_mac_set_fullscreen_mode uses kUIModeAllSuppressed which is unfortunate in our case // @@ -333,11 +333,66 @@ void UBPlatformUtils::setWindowNonActivableFlag(QWidget* widget, bool nonAcivabl Q_UNUSED(nonAcivable); } +QPixmap qpixmapFromIconRef(IconRef iconRef, int size) { + OSErr result; + int iconSize; + OSType elementType; + + // Determine elementType and iconSize + if (size <= 16) { + elementType = kSmall32BitData; + iconSize = 16; + } else if (size <= 32) { + elementType = kLarge32BitData; + iconSize = 32; + } else { + elementType = kThumbnail32BitData; + iconSize = 128; + } + + // Get icon into an IconFamily + IconFamilyHandle hIconFamily = 0; + IconRefToIconFamily(iconRef, kSelectorAllAvailableData, &hIconFamily); + + // Extract data + Handle hRawBitmapData = NewHandle(iconSize * iconSize * 4); + result = GetIconFamilyData( hIconFamily, elementType, hRawBitmapData ); + if (result != noErr) { + DisposeHandle(hRawBitmapData); + return QPixmap(); + } + + // Convert data to QImage + QImage image(iconSize, iconSize, QImage::Format_ARGB32); + HLock(hRawBitmapData); + unsigned long* data = (unsigned long*) *hRawBitmapData; + for (int posy=0; posy0) { CFStringRef langRef = (CFStringRef)CFArrayGetValueAtIndex(langs, 0); name = QStringFromStringRef(langRef); + qDebug() << "name is " + name; + } - //IconRef iconRef = (IconRef)TISGetInputSourceProperty(kTISPropertyIconRef, - // kTISPropertyInputSourceLanguages); + //IconRef iconRef = (IconRef)TISGetInputSourceProperty(kTISPropertyIconRef, kTISPropertyInputSourceLanguages); + + const QString resName = ":/images/flags/" + name + ".png"; + QIcon *iconLang = new QIcon(resName); - result.append(new UBKeyboardLocale(fullName, name, ID, NULL, keybt)); + result.append(new UBKeyboardLocale(fullName, name, ID, iconLang, keybt)); } if (result.size()==0)