Commit 43a79239 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

fix: image memory usage

Change-Id: I8ba722d89c9a54ec20d25a3d2b7dd3efb20b1dd0
parent 394f74c7
......@@ -137,15 +137,12 @@ typedef NS_ENUM(NSInteger, TagViews) {
-(void) updateView {
const auto& account = accountModel->getAccountInfo(self.selectedAccountID);
QByteArray ba = QByteArray::fromStdString(account.profileInfo.avatar);
QVariant photo = GlobalInstances::pixmapManipulator().personPhoto(ba, nil);
if(QtMac::toNSImage(qvariant_cast<QPixmap>(photo))) {
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:@(account.profileInfo.avatar.c_str()) options:NSDataBase64DecodingIgnoreUnknownCharacters];
NSImage *image = [[NSImage alloc] initWithData:imageData];
if(image) {
[photoView setBordered:NO];
NSImage *image = QtMac::toNSImage(qvariant_cast<QPixmap>(photo));
CGFloat newSize = MIN(image.size.height, image.size.width);
image = [image cropImageToSize:CGSizeMake(newSize, newSize)];
[photoView setImage: [image roundCorners: image.size.height * 0.5]];
[photoView setImage: [image roundCorners: 350]];
[addProfilePhotoImage setHidden:YES];
} else {
[photoView setImage:nil];
......
......@@ -125,15 +125,11 @@ typedef NS_ENUM(NSInteger, TagViews) {
-(void)updateView {
const auto& account = accountModel->getAccountInfo(self.selectedAccountID);
QByteArray ba = QByteArray::fromStdString(account.profileInfo.avatar);
QVariant photo = GlobalInstances::pixmapManipulator().personPhoto(ba, nil);
if(QtMac::toNSImage(qvariant_cast<QPixmap>(photo))) {
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:@(account.profileInfo.avatar.c_str()) options:NSDataBase64DecodingIgnoreUnknownCharacters];
NSImage *image = [[NSImage alloc] initWithData:imageData];
if(image) {
[photoView setBordered:NO];
NSImage *image = QtMac::toNSImage(qvariant_cast<QPixmap>(photo));
CGFloat newSize = MIN(image.size.height, image.size.width);
image = [image cropImageToSize:CGSizeMake(newSize, newSize)];
[photoView setImage: [image roundCorners: image.size.height * 0.5]];
[photoView setImage: [image roundCorners: 350]];
[addProfilePhotoImage setHidden:YES];
} else {
[photoView setImage:nil];
......
......@@ -122,7 +122,11 @@ NSMenuItem* selectedMenuItem;
QObject::connect(accMdl_,
&lrc::api::NewAccountModel::accountStatusChanged,
[self] (const std::string& accountID) {
[self update];
if([self selectedAccount].id == accountID) {
[self update];
return;
}
[self updateMenuItemForAccount:accountID];
});
}
......@@ -148,6 +152,16 @@ NSMenuItem* selectedMenuItem;
}
}
-(void) updateMenuItemForAccount: (const std::string&) accountID {
AccountMenuItemView *itemView =
[accountsMenu itemWithTag:[@(accountID.c_str()) intValue]].view;
if(!itemView) {
return;
}
[self configureView:itemView forAccount:accountID];
}
-(void) updateMenu {
[accountsMenu removeAllItems];
......@@ -195,10 +209,10 @@ NSMenuItem* selectedMenuItem;
[itemView.accountLabel setStringValue:@(account.profileInfo.alias.c_str())];
NSString* userNameString = [self nameForAccount: account];
[itemView.userNameLabel setStringValue:userNameString];
QByteArray ba = QByteArray::fromStdString(account.profileInfo.avatar);
QVariant photo = GlobalInstances::pixmapManipulator().personPhoto(ba, nil);
if(QtMac::toNSImage(qvariant_cast<QPixmap>(photo))) {
[itemView.accountAvatar setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:@(account.profileInfo.avatar.c_str()) options:NSDataBase64DecodingIgnoreUnknownCharacters];
NSImage *image = [[NSImage alloc] initWithData:imageData];
if(image) {
[itemView.accountAvatar setImage: image];
} else {
[itemView.accountAvatar setImage: [NSImage imageNamed:@"default_avatar_overlay.png"]];
}
......@@ -229,12 +243,10 @@ NSMenuItem* selectedMenuItem;
auto& account = [self selectedAccount];
if(account.profileInfo.type == lrc::api::profile::Type::INVALID)
return;
QByteArray ba = QByteArray::fromStdString(account.profileInfo.avatar);
QVariant photo = GlobalInstances::pixmapManipulator().personPhoto(ba, nil);
if(QtMac::toNSImage(qvariant_cast<QPixmap>(photo))) {
[profileImage setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:@(account.profileInfo.avatar.c_str()) options:NSDataBase64DecodingIgnoreUnknownCharacters];
NSImage *image = [[NSImage alloc] initWithData:imageData];
if(image) {
[profileImage setImage: image];
} else {
[profileImage setImage: [NSImage imageNamed:@"default_avatar_overlay.png"]];
}
......
......@@ -42,8 +42,7 @@
}
- (NSImage *) roundCorners:(CGFloat)radius {
NSImage *existingImage = self;
NSSize existingSize = [existingImage size];
NSSize existingSize = [self size];
NSSize newSize = NSMakeSize(existingSize.width, existingSize.height);
NSImage *composedImage = [[NSImage alloc] initWithSize:newSize];
......@@ -55,7 +54,7 @@
[clipPath setWindingRule:NSEvenOddWindingRule];
[clipPath addClip];
[existingImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0, 0, newSize.width, newSize.height) operation:NSCompositeSourceOver fraction:1];
[self drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0, 0, newSize.width, newSize.height) operation:NSCompositeSourceOver fraction:1];
[composedImage unlockFocus];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment