From b15cac8c4376fb75598386b8cd67c0774c9a67d4 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 23 Oct 2011 17:45:05 +0000 Subject: [PATCH] #4356 Extend tooltip support to torrent names in the main window --- macosx/FilePriorityCell.m | 2 +- macosx/TorrentCell.h | 1 + macosx/TorrentCell.m | 53 ++++++++++++++++++++++++++++++++++++--- macosx/TorrentTableView.m | 3 +-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/macosx/FilePriorityCell.m b/macosx/FilePriorityCell.m index 4f199f754..a9cb1cf60 100644 --- a/macosx/FilePriorityCell.m +++ b/macosx/FilePriorityCell.m @@ -28,7 +28,7 @@ #import "NSImageAdditions.h" #import "Torrent.h" -#define IMAGE_OVERLAP 3.0 +#define IMAGE_OVERLAP 1.0 @implementation FilePriorityCell diff --git a/macosx/TorrentCell.h b/macosx/TorrentCell.h index 88daf10fc..a2d8caf09 100644 --- a/macosx/TorrentCell.h +++ b/macosx/TorrentCell.h @@ -35,6 +35,7 @@ } - (NSRect) iconRectForBounds: (NSRect) bounds; +- (NSRect) rectForTitleWithString: (NSAttributedString *) string withRightBound: (CGFloat) rightBound inBounds: (NSRect) bounds; - (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo mouseLocation: (NSPoint) mouseLocation; diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index 7c787813b..469c9f6bd 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -50,13 +50,14 @@ #define PADDING_BETWEEN_BUTTONS 3.0 #define PADDING_BETWEEN_IMAGE_AND_TITLE (PADDING_HORIZONTAL + 1.0) #define PADDING_BETWEEN_IMAGE_AND_BAR PADDING_HORIZONTAL -#define PADDING_BETWEEN_TITLE_AND_PRIORITY 4.0 +#define PADDING_BETWEEN_TITLE_AND_PRIORITY 6.0 #define PADDING_ABOVE_TITLE 4.0 #define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 3.0 #define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0 #define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0 #define PADDING_BETWEEN_BAR_AND_STATUS 2.0 #define PADDING_BETWEEN_BAR_AND_EDGE_MIN 3.0 +#define PADDING_EXPANSION_FRAME 2.0 #define PIECES_TOTAL_PERCENT 0.6 @@ -487,6 +488,8 @@ NSColor * priorityColor = [self backgroundStyle] == NSBackgroundStyleDark ? [NSColor whiteColor] : [NSColor darkGrayColor]; NSImage * priorityImage = [[NSImage imageNamed: ([torrent priority] == TR_PRI_HIGH ? @"PriorityHighTemplate.png" : @"PriorityLowTemplate.png")] imageWithColor: priorityColor]; + + [priorityImage drawInRect: priorityRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0 respectFlipped: YES hints: nil]; } @@ -498,6 +501,50 @@ } } +- (NSRect) expansionFrameWithFrame: (NSRect) cellFrame inView: (NSView *) view +{ + BOOL minimal = [fDefaults boolForKey: @"SmallView"]; + + //this code needs to match the code in drawInteriorWithFrame:withView: + CGFloat minimalTitleRightBound; + if (minimal) + { + NSAttributedString * minimalString = [self attributedStatusString: [self minimalStatusString]]; + NSRect minimalStatusRect = [self rectForMinimalStatusWithString: minimalString inBounds: cellFrame]; + + minimalTitleRightBound = NSMinX(minimalStatusRect); + } + + if (!minimal || fHover) + { + const NSRect controlRect = [self controlButtonRectForBounds: cellFrame]; + minimalTitleRightBound = MIN(minimalTitleRightBound, NSMinX(controlRect)); + } + + NSAttributedString * titleString = [self attributedTitle]; + NSRect realRect = [self rectForTitleWithString: titleString withRightBound: minimalTitleRightBound inBounds: cellFrame]; + + NSAssert([titleString size].width >= NSWidth(realRect), @"Full rect width should not be less than the used title rect width!"); + + if ([titleString size].width > NSWidth(realRect) + && NSMouseInRect([view convertPoint: [[view window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil], realRect, [view isFlipped])) + { + realRect.size.width = [titleString size].width; + return NSInsetRect(realRect, -PADDING_EXPANSION_FRAME, -PADDING_EXPANSION_FRAME); + } + + return NSZeroRect; +} + +- (void) drawWithExpansionFrame: (NSRect) cellFrame inView: (NSView *)view +{ + cellFrame.origin.x += PADDING_EXPANSION_FRAME; + cellFrame.origin.y += PADDING_EXPANSION_FRAME; + + NSAttributedString * titleString = [self attributedTitle]; + [titleString drawInRect: cellFrame]; +} + @end @implementation TorrentCell (Private) @@ -683,10 +730,8 @@ } if ([(Torrent *)[self representedObject] priority] != TR_PRI_NORMAL) - { result.size.width -= PRIORITY_ICON_WIDTH + PADDING_BETWEEN_TITLE_AND_PRIORITY; - result.size.width = MIN(NSWidth(result), [string size].width); //only need to force it smaller for the priority icon - } + result.size.width = MIN(NSWidth(result), [string size].width); return result; } diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index a7596fbad..8bec13557 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -206,8 +206,7 @@ : [[self preparedCellAtColumn: [self columnWithIdentifier: @"Group"] row: [self rowForItem: item]] stringValue]; } -- (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect - tableColumn: (NSTableColumn *) column item: (id) item mouseLocation: (NSPoint) mouseLocation +- (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect tableColumn: (NSTableColumn *) column item: (id) item mouseLocation: (NSPoint) mouseLocation { NSString * ident = [column identifier]; if ([ident isEqualToString: @"DL"] || [ident isEqualToString: @"DL Image"])