mirror of https://github.com/procxx/kepka.git
Moved Saved Messages button to subclass.
This commit is contained in:
parent
8099305c53
commit
2f2847bfdf
|
@ -27,8 +27,13 @@
|
||||||
#include "auth_session.h"
|
#include "auth_session.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
#include "ui/empty_userpic.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
//https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/
|
||||||
|
constexpr auto kIdealIconSize = 36;
|
||||||
|
constexpr auto kMaximumIconSize = 44;
|
||||||
|
|
||||||
constexpr auto kSavedMessages = 0x001;
|
constexpr auto kSavedMessages = 0x001;
|
||||||
|
|
||||||
constexpr auto kPlayPause = 0x002;
|
constexpr auto kPlayPause = 0x002;
|
||||||
|
@ -39,6 +44,8 @@ constexpr auto kClosePlayer = 0x005;
|
||||||
constexpr auto kMs = 1000;
|
constexpr auto kMs = 1000;
|
||||||
|
|
||||||
constexpr auto kSongType = AudioMsgId::Type::Song;
|
constexpr auto kSongType = AudioMsgId::Type::Song;
|
||||||
|
|
||||||
|
constexpr auto kSavedMessagesId = 0;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
|
@ -51,6 +58,7 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
@property(nonatomic, assign) PeerData * peer;
|
@property(nonatomic, assign) PeerData * peer;
|
||||||
|
|
||||||
- (id) init:(int)num;
|
- (id) init:(int)num;
|
||||||
|
- (id) initSavedMessages;
|
||||||
- (NSImage *) getPinImage;
|
- (NSImage *) getPinImage;
|
||||||
- (void)buttonActionPin:(NSButton *)sender;
|
- (void)buttonActionPin:(NSButton *)sender;
|
||||||
- (void)updatePeerData;
|
- (void)updatePeerData;
|
||||||
|
@ -60,6 +68,9 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
@implementation PinnedDialogButton : NSCustomTouchBarItem
|
@implementation PinnedDialogButton : NSCustomTouchBarItem
|
||||||
|
|
||||||
- (id) init:(int)num {
|
- (id) init:(int)num {
|
||||||
|
if (num == kSavedMessagesId) {
|
||||||
|
return [self initSavedMessages];
|
||||||
|
}
|
||||||
NSString *identifier = [NSString stringWithFormat:@"%@.pinnedDialog%d", customIDMain, num];
|
NSString *identifier = [NSString stringWithFormat:@"%@.pinnedDialog%d", customIDMain, num];
|
||||||
self = [super initWithIdentifier:identifier];
|
self = [super initWithIdentifier:identifier];
|
||||||
if (!self) {
|
if (!self) {
|
||||||
|
@ -88,6 +99,24 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initSavedMessages {
|
||||||
|
self = [super initWithIdentifier:savedMessages];
|
||||||
|
if (!self) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
self.number = kSavedMessagesId;
|
||||||
|
self.waiting = false;
|
||||||
|
|
||||||
|
NSButton *button = [NSButton buttonWithImage:[self getPinImage] target:self action:@selector(buttonActionPin:)];
|
||||||
|
[button setBordered:NO];
|
||||||
|
[button sizeToFit];
|
||||||
|
[button setHidden:(self.number > Auth().data().pinnedDialogsOrder().size())];
|
||||||
|
self.view = button;
|
||||||
|
self.customizationLabel = @"Saved Messages";
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)updatePeerData {
|
- (void)updatePeerData {
|
||||||
const auto &order = Auth().data().pinnedDialogsOrder();
|
const auto &order = Auth().data().pinnedDialogsOrder();
|
||||||
if (self.number > order.size()) {
|
if (self.number > order.size()) {
|
||||||
|
@ -103,17 +132,29 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
|
|
||||||
- (void)buttonActionPin:(NSButton *)sender {
|
- (void)buttonActionPin:(NSButton *)sender {
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([=] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([=] {
|
||||||
App::main()->choosePeer(self.peer->id, ShowAtUnreadMsgId);
|
App::main()->choosePeer(self.number == kSavedMessagesId
|
||||||
|
? Auth().userPeerId()
|
||||||
|
: self.peer->id, ShowAtUnreadMsgId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (NSImage *) getPinImage {
|
- (NSImage *) getPinImage {
|
||||||
|
if (self.number == kSavedMessagesId) {
|
||||||
|
const int s = kIdealIconSize * cRetinaFactor();
|
||||||
|
auto *pix = new QPixmap(s, s);
|
||||||
|
Painter paint(pix);
|
||||||
|
paint.fillRect(QRectF(0, 0, s, s), QColor(0, 0, 0, 255));
|
||||||
|
|
||||||
|
Ui::EmptyUserpic::PaintSavedMessages(paint, 0, 0, s, s);
|
||||||
|
pix->setDevicePixelRatio(cRetinaFactor());
|
||||||
|
return static_cast<NSImage*>(qt_mac_create_nsimage(*pix));
|
||||||
|
}
|
||||||
if (!self.peer) {
|
if (!self.peer) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
self.waiting = !self.peer->userpicLoaded();
|
self.waiting = !self.peer->userpicLoaded();
|
||||||
auto pixmap = self.peer->genUserpic(20);
|
auto pixmap = self.peer->genUserpic(kIdealIconSize);
|
||||||
pixmap.setDevicePixelRatio(cRetinaFactor());
|
pixmap.setDevicePixelRatio(cRetinaFactor());
|
||||||
return static_cast<NSImage*>(qt_mac_create_nsimage(pixmap));
|
return static_cast<NSImage*>(qt_mac_create_nsimage(pixmap));
|
||||||
}
|
}
|
||||||
|
@ -135,32 +176,32 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
if (self) {
|
if (self) {
|
||||||
self.view = view;
|
self.view = view;
|
||||||
self.touchbarItems = @{
|
self.touchbarItems = @{
|
||||||
savedMessages: [NSMutableDictionary dictionaryWithDictionary:@{
|
// savedMessages: [NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"type": @"button",
|
// @"type": @"button",
|
||||||
@"name": @"Saved Messages",
|
// @"name": @"Saved Messages",
|
||||||
@"cmd": [NSNumber numberWithInt:kSavedMessages],
|
// @"cmd": [NSNumber numberWithInt:kSavedMessages],
|
||||||
@"image": [NSImage imageNamed:NSImageNameTouchBarBookmarksTemplate],
|
// @"image": static_cast<NSImage*>(qt_mac_create_nsimage(*pix)),
|
||||||
}],
|
// }],
|
||||||
pinnedDialog1: [NSMutableDictionary dictionaryWithDictionary:@{
|
pinnedDialog1: [NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"type": @"pinned",
|
@"type": @"pinned",
|
||||||
@"num": @1,
|
@"num": @1,
|
||||||
}],
|
}],
|
||||||
pinnedDialog2: [NSMutableDictionary dictionaryWithDictionary:@{
|
// pinnedDialog2: [NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"type": @"pinned",
|
// @"type": @"pinned",
|
||||||
@"num": @2,
|
// @"num": @2,
|
||||||
}],
|
// }],
|
||||||
pinnedDialog3: [NSMutableDictionary dictionaryWithDictionary:@{
|
// pinnedDialog3: [NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"type": @"pinned",
|
// @"type": @"pinned",
|
||||||
@"num": @3,
|
// @"num": @3,
|
||||||
}],
|
// }],
|
||||||
pinnedDialog4: [NSMutableDictionary dictionaryWithDictionary:@{
|
// pinnedDialog4: [NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"type": @"pinned",
|
// @"type": @"pinned",
|
||||||
@"num": @4,
|
// @"num": @4,
|
||||||
}],
|
// }],
|
||||||
pinnedDialog5: [NSMutableDictionary dictionaryWithDictionary:@{
|
// pinnedDialog5: [NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"type": @"pinned",
|
// @"type": @"pinned",
|
||||||
@"num": @5,
|
// @"num": @5,
|
||||||
}],
|
// }],
|
||||||
seekBar: [NSMutableDictionary dictionaryWithDictionary:@{
|
seekBar: [NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"type": @"slider",
|
@"type": @"slider",
|
||||||
@"name": @"Seek Bar"
|
@"name": @"Seek Bar"
|
||||||
|
@ -248,10 +289,15 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
[self.touchbarItems[identifier] setObject:text forKey:@"view"];
|
[self.touchbarItems[identifier] setObject:text forKey:@"view"];
|
||||||
return item;
|
return item;
|
||||||
} else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"pinned"]) {
|
} else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"pinned"]) {
|
||||||
const auto number = [self.touchbarItems[identifier][@"num"] intValue];
|
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
|
||||||
PinnedDialogButton *item = [[PinnedDialogButton alloc] init:number];
|
NSMutableArray *pins = [[NSMutableArray alloc] init];
|
||||||
NSImage *image = self.touchbarItems[identifier][@"image"];
|
|
||||||
|
|
||||||
|
for (auto i = 0; i <= 5; i++) {
|
||||||
|
[pins addObject:[[PinnedDialogButton alloc] init:i].view];
|
||||||
|
}
|
||||||
|
NSStackView *stackView = [NSStackView stackViewWithViews:[pins copy]];
|
||||||
|
[stackView setSpacing:-15];
|
||||||
|
item.view = stackView;
|
||||||
[self.touchbarItems[identifier] setObject:item.view forKey:@"view"];
|
[self.touchbarItems[identifier] setObject:item.view forKey:@"view"];
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue