1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00

combine similar code for attributes in the torrent cell

This commit is contained in:
Mitchell Livingston 2007-08-11 04:46:21 +00:00
parent 974bc096e1
commit b476e6f8eb

View file

@ -56,9 +56,7 @@
- (NSRect) rectForStatusBasedOnProgressRect: (NSRect) progressRect inBounds: (NSRect) bounds; - (NSRect) rectForStatusBasedOnProgressRect: (NSRect) progressRect inBounds: (NSRect) bounds;
- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color; - (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
- (NSAttributedString *) attributedProgressWithColor: (NSColor *) color; - (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color;
- (NSAttributedString *) attributedStatusWithColor: (NSColor *) color;
- (NSAttributedString *) attributedMinimalStatusWithColor: (NSColor *) color;
@end @end
@ -148,7 +146,10 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
if (![fDefaults boolForKey: @"SmallView"]) if (![fDefaults boolForKey: @"SmallView"])
return NSZeroRect; return NSZeroRect;
NSAttributedString * status = [self attributedMinimalStatusWithColor: nil]; Torrent * torrent = [self representedObject];
NSString * string = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
? [torrent remainingTimeString] : [torrent shortStatusString];
NSAttributedString * status = [self attributedStatusString: string withColor: nil];
NSRect result = bounds; NSRect result = bounds;
result.size = [status size]; result.size = [status size];
@ -221,7 +222,11 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
//minimal status //minimal status
NSRect minimalStatusRect = [self minimalStatusRectForBounds: cellFrame]; NSRect minimalStatusRect = [self minimalStatusRectForBounds: cellFrame];
if (minimal) if (minimal)
[[self attributedMinimalStatusWithColor: statusColor] drawInRect: minimalStatusRect]; {
NSString * string = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
? [torrent remainingTimeString] : [torrent shortStatusString];
[[self attributedStatusString: string withColor: statusColor] drawInRect: minimalStatusRect];
}
//title //title
NSRect titleRect = [self rectForTitleBasedOnMinimalStatusRect: minimalStatusRect inBounds: cellFrame]; NSRect titleRect = [self rectForTitleBasedOnMinimalStatusRect: minimalStatusRect inBounds: cellFrame];
@ -232,7 +237,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
if (!minimal) if (!minimal)
{ {
progressRect = [self rectForProgressBasedOnTitleRect: titleRect inBounds: cellFrame]; progressRect = [self rectForProgressBasedOnTitleRect: titleRect inBounds: cellFrame];
[[self attributedProgressWithColor: statusColor] drawInRect: progressRect]; [[self attributedStatusString: [torrent progressString] withColor: statusColor] drawInRect: progressRect];
} }
//bar //bar
@ -244,7 +249,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
if (!minimal) if (!minimal)
{ {
NSRect statusRect = [self rectForStatusBasedOnProgressRect: progressRect inBounds: cellFrame]; NSRect statusRect = [self rectForStatusBasedOnProgressRect: progressRect inBounds: cellFrame];
[[self attributedStatusWithColor: statusColor] drawInRect: statusRect]; [[self attributedStatusString: [torrent statusString] withColor: statusColor] drawInRect: statusRect];
} }
} }
@ -539,7 +544,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
if ([fDefaults boolForKey: @"SmallView"]) if ([fDefaults boolForKey: @"SmallView"])
return NSZeroRect; return NSZeroRect;
NSSize progressSize = [[self attributedProgressWithColor: nil] size]; NSSize progressSize = [[self attributedStatusString: [[self representedObject] progressString] withColor: nil] size];
NSRect result = titleRect; NSRect result = titleRect;
@ -569,7 +574,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
if ([fDefaults boolForKey: @"SmallView"]) if ([fDefaults boolForKey: @"SmallView"])
return NSZeroRect; return NSZeroRect;
NSSize statusSize = [[self attributedStatusWithColor: nil] size]; NSSize statusSize = [[self attributedStatusString: [[self representedObject] statusString] withColor: nil] size];
NSRect result = progressRect; NSRect result = progressRect;
result.size.width = MIN(statusSize.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL); result.size.width = MIN(statusSize.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL);
@ -589,35 +594,12 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease]; return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
} }
- (NSAttributedString *) attributedProgressWithColor: (NSColor *) color - (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color
{ {
if (color) if (color)
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName]; [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
NSString * progress = [[self representedObject] progressString]; return [[[NSAttributedString alloc] initWithString: string attributes: fStatusAttributes] autorelease];
return [[[NSAttributedString alloc] initWithString: progress attributes: fStatusAttributes] autorelease];
}
- (NSAttributedString *) attributedStatusWithColor: (NSColor *) color
{
if (color)
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
NSString * status = [[self representedObject] statusString];
return [[[NSAttributedString alloc] initWithString: status attributes: fStatusAttributes] autorelease];
}
#warning combine?
- (NSAttributedString *) attributedMinimalStatusWithColor: (NSColor *) color
{
if (color)
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
Torrent * torrent = [self representedObject];
NSString * status = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
? [torrent remainingTimeString] : [torrent shortStatusString];
return [[[NSAttributedString alloc] initWithString: status attributes: fStatusAttributes] autorelease];
} }
@end @end