mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-02 07:35:12 +00:00
Use public API to convert QPixmap to NSImage (#75)
This commit is contained in:
@@ -42,8 +42,6 @@
|
|||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
//https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/
|
//https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/
|
||||||
constexpr auto kIdealIconSize = 36;
|
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);
|
const auto instance = icon.instance(QColor(255, 255, 255, 255), 100);
|
||||||
auto pixmap = QPixmap::fromImage(instance);
|
auto pixmap = QPixmap::fromImage(instance);
|
||||||
pixmap.setDevicePixelRatio(cRetinaFactor());
|
pixmap.setDevicePixelRatio(cRetinaFactor());
|
||||||
NSImage *image = [qt_mac_create_nsimage(pixmap) autorelease];
|
NSImage *image = [Platform::ToNSImage(pixmap) autorelease];
|
||||||
[image setSize:NSMakeSize(size, size)];
|
[image setSize:NSMakeSize(size, size)];
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -163,7 +161,7 @@ NSImage *CreateNSImageFromEmoji(EmojiPtr emoji) {
|
|||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
#endif // OS_MAC_OLD
|
#endif // OS_MAC_OLD
|
||||||
return [qt_mac_create_nsimage(pixmap) autorelease];
|
return [Platform::ToNSImage(pixmap) autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
int WidthFromString(NSString *s) {
|
int WidthFromString(NSString *s) {
|
||||||
@@ -649,7 +647,7 @@ void AppendEmojiPacks(std::vector<PickerScrubberItem> &to) {
|
|||||||
|
|
||||||
- (void) updateImage:(QPixmap)pixmap {
|
- (void) updateImage:(QPixmap)pixmap {
|
||||||
NSButton *button = self.view;
|
NSButton *button = self.view;
|
||||||
NSImage *image = [qt_mac_create_nsimage(pixmap) autorelease];
|
NSImage *image = [Platform::ToNSImage(pixmap) autorelease];
|
||||||
[image setSize:NSMakeSize(kCircleDiameter, kCircleDiameter)];
|
[image setSize:NSMakeSize(kCircleDiameter, kCircleDiameter)];
|
||||||
[button.cell setImage:image];
|
[button.cell setImage:image];
|
||||||
}
|
}
|
||||||
@@ -709,7 +707,7 @@ void AppendEmojiPacks(std::vector<PickerScrubberItem> &to) {
|
|||||||
- (void)updateImage {
|
- (void)updateImage {
|
||||||
const auto size = _dimensions
|
const auto size = _dimensions
|
||||||
.scaled(kCircleDiameter, kCircleDiameter, Qt::KeepAspectRatio);
|
.scaled(kCircleDiameter, kCircleDiameter, Qt::KeepAspectRatio);
|
||||||
_imageView.image = [qt_mac_create_nsimage(
|
_imageView.image = [Platform::ToNSImage(
|
||||||
_image->pixSingle(
|
_image->pixSingle(
|
||||||
size.width(),
|
size.width(),
|
||||||
size.height(),
|
size.height(),
|
||||||
|
@@ -45,8 +45,6 @@ using Manager = Platform::Notifications::Manager;
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
|
||||||
|
|
||||||
@interface NotificationDelegate : NSObject<NSUserNotificationCenterDelegate> {
|
@interface NotificationDelegate : NSObject<NSUserNotificationCenterDelegate> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +242,7 @@ void Manager::Private::showNotification(
|
|||||||
auto userpic = peer->isSelf()
|
auto userpic = peer->isSelf()
|
||||||
? Ui::EmptyUserpic::GenerateSavedMessages(st::notifyMacPhotoSize)
|
? Ui::EmptyUserpic::GenerateSavedMessages(st::notifyMacPhotoSize)
|
||||||
: peer->genUserpic(userpicView, st::notifyMacPhotoSize);
|
: peer->genUserpic(userpicView, st::notifyMacPhotoSize);
|
||||||
NSImage *img = [qt_mac_create_nsimage(userpic) autorelease];
|
NSImage *img = [ToNSImage(userpic) autorelease];
|
||||||
[notification setContentImage:img];
|
[notification setContentImage:img];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "platform/mac/specific_mac_p.h"
|
#include "platform/mac/specific_mac_p.h"
|
||||||
|
|
||||||
|
Q_FORWARD_DECLARE_OBJC_CLASS(NSImage);
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
class LocationPoint;
|
class LocationPoint;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
@@ -28,6 +30,8 @@ inline QImage GetImageFromClipboard() {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSImage *ToNSImage(const QPixmap &pixmap);
|
||||||
|
|
||||||
namespace ThirdParty {
|
namespace ThirdParty {
|
||||||
|
|
||||||
inline void start() {
|
inline void start() {
|
||||||
|
@@ -266,6 +266,18 @@ bool AutostartSupported() {
|
|||||||
return false;
|
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
|
} // namespace Platform
|
||||||
|
|
||||||
void psNewVersion() {
|
void psNewVersion() {
|
||||||
|
@@ -40,8 +40,6 @@ constexpr auto kIgnoreActivationTimeoutMs = 500;
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
|
||||||
|
|
||||||
using Platform::Q2NSString;
|
using Platform::Q2NSString;
|
||||||
using Platform::NS2QString;
|
using Platform::NS2QString;
|
||||||
|
|
||||||
@@ -211,7 +209,7 @@ void SetApplicationIcon(const QIcon &icon) {
|
|||||||
if (!icon.isNull()) {
|
if (!icon.isNull()) {
|
||||||
auto pixmap = icon.pixmap(1024, 1024);
|
auto pixmap = icon.pixmap(1024, 1024);
|
||||||
pixmap.setDevicePixelRatio(cRetinaFactor());
|
pixmap.setDevicePixelRatio(cRetinaFactor());
|
||||||
image = static_cast<NSImage*>(qt_mac_create_nsimage(pixmap));
|
image = static_cast<NSImage*>(ToNSImage(pixmap));
|
||||||
}
|
}
|
||||||
[[NSApplication sharedApplication] setApplicationIconImage:image];
|
[[NSApplication sharedApplication] setApplicationIconImage:image];
|
||||||
[image release];
|
[image release];
|
||||||
|
Reference in New Issue
Block a user