language flags are now available for Mac

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent f3cec81b51
commit f2ebb62596
  1. 68
      src/frameworks/UBPlatformUtils_mac.mm

@ -333,6 +333,61 @@ void UBPlatformUtils::setWindowNonActivableFlag(QWidget* widget, bool nonAcivabl
Q_UNUSED(nonAcivable); 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; posy<iconSize; ++posy, data+=iconSize) {
#ifdef __BIG_ENDIAN__
uchar* line = image.scanLine(posy);
memcpy(line, data, iconSize * 4);
#else
uchar* src = (uchar*) data;
uchar* dst = image.scanLine(posy);
for (int posx=0; posx<iconSize; src+=4, dst+=4, ++posx) {
dst[0] = src[3];
dst[1] = src[2];
dst[2] = src[1];
dst[3] = src[0];
}
#endif
}
HUnlock(hRawBitmapData);
DisposeHandle( hRawBitmapData );
// Scale to wanted size
image = image.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
return QPixmap::fromImage(image);
}
QString QStringFromStringRef(CFStringRef stringRef) QString QStringFromStringRef(CFStringRef stringRef)
{ {
@ -446,20 +501,23 @@ void UBPlatformUtils::initializeKeyboardLayouts()
sr = (CFStringRef) TISGetInputSourceProperty(keyLayoutRef, kTISPropertyLocalizedName); sr = (CFStringRef) TISGetInputSourceProperty(keyLayoutRef, kTISPropertyLocalizedName);
QString fullName = QStringFromStringRef(sr); QString fullName = QStringFromStringRef(sr);
CFArrayRef langs = (CFArrayRef) TISGetInputSourceProperty(keyLayoutRef, CFArrayRef langs = (CFArrayRef) TISGetInputSourceProperty(keyLayoutRef, kTISPropertyInputSourceLanguages);
kTISPropertyInputSourceLanguages);
QString name = "??"; QString name = "??";
if (CFArrayGetCount(langs)>0) if (CFArrayGetCount(langs)>0)
{ {
CFStringRef langRef = (CFStringRef)CFArrayGetValueAtIndex(langs, 0); CFStringRef langRef = (CFStringRef)CFArrayGetValueAtIndex(langs, 0);
name = QStringFromStringRef(langRef); name = QStringFromStringRef(langRef);
qDebug() << "name is " + name;
} }
//IconRef iconRef = (IconRef)TISGetInputSourceProperty(kTISPropertyIconRef, //IconRef iconRef = (IconRef)TISGetInputSourceProperty(kTISPropertyIconRef, kTISPropertyInputSourceLanguages);
// 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) if (result.size()==0)

Loading…
Cancel
Save