From 1a86c65b44f04af6964fa24f5ac47e62f05a4788 Mon Sep 17 00:00:00 2001 From: SweetPPro Date: Sun, 13 Aug 2023 21:37:42 +0200 Subject: [PATCH] fix: missing priority icon in torrent cell (#5856) * regression fix: missing priority icon in torrent cell Fix #5826 (regression from #5147) - autolayout alternative to #5846 * Update TorrentCell.mm * Update SmallTorrentCell.mm --- macosx/Base.lproj/MainMenu.xib | 102 ++++++++++++++++++++++++--------- macosx/SmallTorrentCell.h | 4 ++ macosx/SmallTorrentCell.mm | 21 +++++++ macosx/TorrentCell.h | 4 ++ macosx/TorrentCell.mm | 21 +++++++ 5 files changed, 125 insertions(+), 27 deletions(-) diff --git a/macosx/Base.lproj/MainMenu.xib b/macosx/Base.lproj/MainMenu.xib index 0ea595860..bacb0c91b 100644 --- a/macosx/Base.lproj/MainMenu.xib +++ b/macosx/Base.lproj/MainMenu.xib @@ -151,14 +151,35 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -208,26 +229,26 @@ - - - + - + + - + + - - + + @@ -237,6 +258,9 @@ + + + @@ -274,14 +298,35 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -289,7 +334,7 @@ - + @@ -321,22 +366,22 @@ - + - + + - @@ -345,6 +390,9 @@ + + + diff --git a/macosx/SmallTorrentCell.h b/macosx/SmallTorrentCell.h index 3af100116..2cfa56f22 100644 --- a/macosx/SmallTorrentCell.h +++ b/macosx/SmallTorrentCell.h @@ -15,7 +15,11 @@ @property(nonatomic) IBOutlet NSImageView* fIconView; @property(nonatomic) IBOutlet NSImageView* fGroupIndicatorView; +@property(nonatomic) IBOutlet NSStackView* fStackView; @property(nonatomic) IBOutlet NSTextField* fTorrentTitleField; +@property(nonatomic) IBOutlet NSImageView* fTorrentPriorityView; +@property(nonatomic) IBOutlet NSLayoutConstraint* fTorrentPriorityViewWidthConstraint; + @property(nonatomic) IBOutlet NSTextField* fTorrentStatusField; @property(nonatomic) IBOutlet NSView* fTorrentProgressBarView; diff --git a/macosx/SmallTorrentCell.mm b/macosx/SmallTorrentCell.mm index 2078c9415..c5ac93fa2 100644 --- a/macosx/SmallTorrentCell.mm +++ b/macosx/SmallTorrentCell.mm @@ -7,6 +7,9 @@ #import "ProgressGradients.h" #import "TorrentTableView.h" #import "Torrent.h" +#import "NSImageAdditions.h" + +static CGFloat const kPriorityIconWidth = 12.0; @interface SmallTorrentCell () @property(nonatomic) NSTrackingArea* fTrackingArea; @@ -24,6 +27,24 @@ Torrent* torrent = (Torrent*)self.objectValue; [progressBar drawBarInRect:barRect forTableView:self.fTorrentTableView withTorrent:torrent]; + + // set priority icon + if (torrent.priority != TR_PRI_NORMAL) + { + NSColor* priorityColor = self.backgroundStyle == NSBackgroundStyleEmphasized ? NSColor.whiteColor : NSColor.labelColor; + NSImage* priorityImage = [[NSImage imageNamed:(torrent.priority == TR_PRI_HIGH ? @"PriorityHighTemplate" : @"PriorityLowTemplate")] + imageWithColor:priorityColor]; + + self.fTorrentPriorityView.image = priorityImage; + self.fStackView.spacing = 4; + self.fTorrentPriorityViewWidthConstraint.constant = kPriorityIconWidth; + } + else + { + self.fTorrentPriorityView.image = nil; + self.fStackView.spacing = 0; + self.fTorrentPriorityViewWidthConstraint.constant = 0; + } } [super drawRect:dirtyRect]; diff --git a/macosx/TorrentCell.h b/macosx/TorrentCell.h index ab6caf4ae..45b3dac3a 100644 --- a/macosx/TorrentCell.h +++ b/macosx/TorrentCell.h @@ -14,7 +14,11 @@ @property(nonatomic) IBOutlet NSImageView* fIconView; @property(nonatomic) IBOutlet NSImageView* fGroupIndicatorView; +@property(nonatomic) IBOutlet NSStackView* fStackView; @property(nonatomic) IBOutlet NSTextField* fTorrentTitleField; +@property(nonatomic) IBOutlet NSImageView* fTorrentPriorityView; +@property(nonatomic) IBOutlet NSLayoutConstraint* fTorrentPriorityViewWidthConstraint; + @property(nonatomic) IBOutlet NSTextField* fTorrentProgressField; @property(nonatomic) IBOutlet NSTextField* fTorrentStatusField; diff --git a/macosx/TorrentCell.mm b/macosx/TorrentCell.mm index 92944e3cb..dbb2726e3 100644 --- a/macosx/TorrentCell.mm +++ b/macosx/TorrentCell.mm @@ -6,6 +6,9 @@ #import "ProgressBarView.h" #import "ProgressGradients.h" #import "Torrent.h" +#import "NSImageAdditions.h" + +static CGFloat const kPriorityIconWidth = 12.0; @implementation TorrentCell @@ -19,6 +22,24 @@ Torrent* torrent = (Torrent*)self.objectValue; [progressBar drawBarInRect:barRect forTableView:self.fTorrentTableView withTorrent:torrent]; + + // set priority icon + if (torrent.priority != TR_PRI_NORMAL) + { + NSColor* priorityColor = self.backgroundStyle == NSBackgroundStyleEmphasized ? NSColor.whiteColor : NSColor.labelColor; + NSImage* priorityImage = [[NSImage imageNamed:(torrent.priority == TR_PRI_HIGH ? @"PriorityHighTemplate" : @"PriorityLowTemplate")] + imageWithColor:priorityColor]; + + self.fTorrentPriorityView.image = priorityImage; + self.fStackView.spacing = 4; + self.fTorrentPriorityViewWidthConstraint.constant = kPriorityIconWidth; + } + else + { + self.fTorrentPriorityView.image = nil; + self.fStackView.spacing = 0; + self.fTorrentPriorityViewWidthConstraint.constant = 0; + } } [super drawRect:dirtyRect];