#4356 Extend tooltip support to torrent names in the main window

This commit is contained in:
Mitchell Livingston 2011-10-23 17:45:05 +00:00
parent 568a6bd119
commit b15cac8c43
4 changed files with 52 additions and 7 deletions

View File

@ -28,7 +28,7 @@
#import "NSImageAdditions.h"
#import "Torrent.h"
#define IMAGE_OVERLAP 3.0
#define IMAGE_OVERLAP 1.0
@implementation FilePriorityCell

View File

@ -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;

View File

@ -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;
}

View File

@ -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"])