2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Use public API to convert QPixmap to NSImage (#75)

This commit is contained in:
ilya-fedin
2020-06-26 18:22:41 +04:00
committed by GitHub
parent edb1ffcea1
commit 368b8139c7
5 changed files with 22 additions and 12 deletions

View File

@@ -42,8 +42,6 @@
#include "facades.h"
#include "app.h"
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
namespace {
//https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/
constexpr auto kIdealIconSize = 36;
@@ -143,7 +141,7 @@ NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size = kIdealIc
const auto instance = icon.instance(QColor(255, 255, 255, 255), 100);
auto pixmap = QPixmap::fromImage(instance);
pixmap.setDevicePixelRatio(cRetinaFactor());
NSImage *image = [qt_mac_create_nsimage(pixmap) autorelease];
NSImage *image = [Platform::ToNSImage(pixmap) autorelease];
[image setSize:NSMakeSize(size, size)];
return image;
}
@@ -163,7 +161,7 @@ NSImage *CreateNSImageFromEmoji(EmojiPtr emoji) {
0,
0);
#endif // OS_MAC_OLD
return [qt_mac_create_nsimage(pixmap) autorelease];
return [Platform::ToNSImage(pixmap) autorelease];
}
int WidthFromString(NSString *s) {
@@ -649,7 +647,7 @@ void AppendEmojiPacks(std::vector<PickerScrubberItem> &to) {
- (void) updateImage:(QPixmap)pixmap {
NSButton *button = self.view;
NSImage *image = [qt_mac_create_nsimage(pixmap) autorelease];
NSImage *image = [Platform::ToNSImage(pixmap) autorelease];
[image setSize:NSMakeSize(kCircleDiameter, kCircleDiameter)];
[button.cell setImage:image];
}
@@ -709,7 +707,7 @@ void AppendEmojiPacks(std::vector<PickerScrubberItem> &to) {
- (void)updateImage {
const auto size = _dimensions
.scaled(kCircleDiameter, kCircleDiameter, Qt::KeepAspectRatio);
_imageView.image = [qt_mac_create_nsimage(
_imageView.image = [Platform::ToNSImage(
_image->pixSingle(
size.width(),
size.height(),

View File

@@ -45,8 +45,6 @@ using Manager = Platform::Notifications::Manager;
} // namespace
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
@interface NotificationDelegate : NSObject<NSUserNotificationCenterDelegate> {
}
@@ -244,7 +242,7 @@ void Manager::Private::showNotification(
auto userpic = peer->isSelf()
? Ui::EmptyUserpic::GenerateSavedMessages(st::notifyMacPhotoSize)
: peer->genUserpic(userpicView, st::notifyMacPhotoSize);
NSImage *img = [qt_mac_create_nsimage(userpic) autorelease];
NSImage *img = [ToNSImage(userpic) autorelease];
[notification setContentImage:img];
}

View File

@@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/platform_specific.h"
#include "platform/mac/specific_mac_p.h"
Q_FORWARD_DECLARE_OBJC_CLASS(NSImage);
namespace Data {
class LocationPoint;
} // namespace Data
@@ -28,6 +30,8 @@ inline QImage GetImageFromClipboard() {
return {};
}
NSImage *ToNSImage(const QPixmap &pixmap);
namespace ThirdParty {
inline void start() {

View File

@@ -266,6 +266,18 @@ bool AutostartSupported() {
return false;
}
NSImage *ToNSImage(const QPixmap &pixmap) {
if (pixmap.isNull())
return 0;
CGImageRef cgimage = pixmap.toImage().toCGImage();
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:cgimage];
NSImage *image = [[NSImage alloc] init];
[image addRepresentation:bitmapRep];
[bitmapRep release];
CFRelease(cgimage);
return image;
}
} // namespace Platform
void psNewVersion() {

View File

@@ -40,8 +40,6 @@ constexpr auto kIgnoreActivationTimeoutMs = 500;
} // namespace
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
using Platform::Q2NSString;
using Platform::NS2QString;
@@ -211,7 +209,7 @@ void SetApplicationIcon(const QIcon &icon) {
if (!icon.isNull()) {
auto pixmap = icon.pixmap(1024, 1024);
pixmap.setDevicePixelRatio(cRetinaFactor());
image = static_cast<NSImage*>(qt_mac_create_nsimage(pixmap));
image = static_cast<NSImage*>(ToNSImage(pixmap));
}
[[NSApplication sharedApplication] setApplicationIconImage:image];
[image release];