dim the action button when hovered over, and display the appropriate status string

This commit is contained in:
Mitchell Livingston 2008-01-15 23:48:03 +00:00
parent ff833b37d6
commit 06f0fee7b5
4 changed files with 51 additions and 29 deletions

View File

@ -31,7 +31,7 @@
NSMutableDictionary * fTitleAttributes, * fStatusAttributes;
BOOL fTracking, fMouseDownControlButton, fMouseDownRevealButton, fHoverControl, fHoverReveal;
BOOL fTracking, fMouseDownControlButton, fMouseDownRevealButton, fHoverControl, fHoverReveal, fHoverAction;
NSColor * fBarOverlayColor;
CTGradient * fWhiteGradient, * fGrayGradient, * fLightGrayGradient, * fBlueGradient, * fDarkBlueGradient,
@ -58,5 +58,6 @@
mouseLocation: (NSPoint) mouseLocation;
- (void) setControlHover: (BOOL) hover;
- (void) setRevealHover: (BOOL) hover;
- (void) setActionHover: (BOOL) hover;
@end

View File

@ -391,6 +391,22 @@
[controlView addTrackingArea: area];
[revealInfo release];
[area release];
//action button (needed even in minimal mode to display status string
NSRect actionButtonRect = [self actionButtonRectForBounds: cellFrame];
NSTrackingAreaOptions actionOptions = options;
if (NSMouseInRect(mouseLocation, actionButtonRect, [controlView isFlipped]))
{
actionOptions |= NSTrackingAssumeInside;
[(TorrentTableView *)controlView setActionButtonHover: [[userInfo objectForKey: @"Row"] intValue]];
}
NSMutableDictionary * actionInfo = [userInfo mutableCopy];
[actionInfo setObject: @"Action" forKey: @"Type"];
area = [[NSTrackingArea alloc] initWithRect: actionButtonRect options: actionOptions owner: controlView userInfo: actionInfo];
[controlView addTrackingArea: area];
[actionInfo release];
[area release];
}
- (void) setControlHover: (BOOL) hover
@ -403,6 +419,11 @@
fHoverReveal = [NSApp isOnLeopardOrBetter] ? hover : -1;
}
- (void) setActionHover: (BOOL) hover
{
fHoverAction = [NSApp isOnLeopardOrBetter] ? hover : -1;
}
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
{
[super drawWithFrame: cellFrame inView: controlView];
@ -531,8 +552,13 @@
//action button
if (!minimal)
{
NSImage * actionImage = /*fMouseDownActionButton ? [NSImage imageNamed: @"ActionOn.png"] :*/
[NSImage imageNamed: @"ActionOff.png"];
NSString * actionImageSuffix;
if (!fTracking && fHoverAction)
actionImageSuffix = /*@"Hover.png"*/@"On.png";
else
actionImageSuffix = @"Off.png";
NSImage * actionImage = [NSImage imageNamed: [@"Action" stringByAppendingString: actionImageSuffix]];
[actionImage setFlipped: YES];
[actionImage drawInRect: [self actionButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
fraction: 1.0];
@ -846,7 +872,7 @@
{
Torrent * torrent = [self representedObject];
if ([torrent isActive])
return NSLocalizedString(@"Pause the transfer.", "Torrent Table -> tooltip");
return NSLocalizedString(@"Pause the transfer", "Torrent Table -> tooltip");
else
{
if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask && [fDefaults boolForKey: @"Queue"])
@ -857,6 +883,8 @@
return NSLocalizedString(@"Resume the transfer", "Torrent cell -> button info");
}
}
else if (!fTracking && fHoverAction)
return NSLocalizedString(@"Change transfer settings", "Torrent Table -> tooltip");
else
return nil;
}

View File

@ -37,7 +37,7 @@
IBOutlet NSMenu * fContextRow, * fContextNoRow;
int fMouseControlRow, fMouseRevealRow;
int fMouseControlRow, fMouseRevealRow, fMouseActionRow;
NSIndexSet * fSelectedIndexes;
NSMutableArray * fKeyStrokes;
@ -51,6 +51,7 @@
- (void) removeButtonTrackingAreas;
- (void) setControlButtonHover: (int) row;
- (void) setRevealButtonHover: (int) row;
- (void) setActionButtonHover: (int) row;
- (void) toggleControlForTorrent: (Torrent *) torrent;

View File

@ -56,6 +56,7 @@
fMouseControlRow = -1;
fMouseRevealRow = -1;
fMouseActionRow = -1;
[self setDelegate: self];
}
@ -83,6 +84,7 @@
[cell setRepresentedObject: [fTorrents objectAtIndex: row]];
[cell setControlHover: row == fMouseControlRow];
[cell setRevealHover: row == fMouseRevealRow];
[cell setActionHover: row == fMouseActionRow];
}
- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row
@ -118,6 +120,7 @@
{
fMouseControlRow = -1;
fMouseRevealRow = -1;
fMouseActionRow = -1;
NSEnumerator * enumerator = [[self trackingAreas] objectEnumerator];
NSTrackingArea * area;
@ -142,6 +145,14 @@
[self setNeedsDisplayInRect: [self rectOfRow: row]];
}
- (void) setActionButtonHover: (int) row
{
fMouseActionRow = row;
if (row >= 0)
[self setNeedsDisplayInRect: [self rectOfRow: row]];
}
- (void) mouseEntered: (NSEvent *) event
{
NSDictionary * dict = (NSDictionary *)[event userData];
@ -152,8 +163,10 @@
int rowVal = [row intValue];
if ([[dict objectForKey: @"Type"] isEqualToString: @"Control"])
fMouseControlRow = rowVal;
else
else if ([[dict objectForKey: @"Type"] isEqualToString: @"Reveal"])
fMouseRevealRow = rowVal;
else
fMouseActionRow = rowVal;
[self setNeedsDisplayInRect: [self rectOfRow: rowVal]];
}
@ -166,6 +179,7 @@
{
fMouseControlRow = -1;
fMouseRevealRow = -1;
fMouseActionRow = -1;
[self setNeedsDisplayInRect: [self rectOfRow: [row intValue]]];
}
@ -208,7 +222,7 @@
[self reloadData];
}
if ([NSApp isOnLeopardOrBetter] && [event clickCount] == 2)
if ([event clickCount] == 2) //double click
{
if ([self pointInProgressRect: point])
{
@ -223,28 +237,6 @@
}
}
//only applies for paths in mouseDown: where the super mouseDown: isn't called
- (void) mouseUp: (NSEvent *) event
{
if (![NSApp isOnLeopardOrBetter] && [event clickCount] == 2)
{
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
int row = [self rowAtPoint: point];
if ([self pointInProgressRect: point])
{
[fDefaults setBool: ![fDefaults boolForKey: @"DisplayStatusProgressSelected"] forKey: @"DisplayStatusProgressSelected"];
[self reloadData];
}
else if ([self pointInIconRect: point])
[[fTorrents objectAtIndex: row] revealData];
else
[fController showInfo: nil];
}
[super mouseUp: event];
}
- (NSMenu *) menuForEvent: (NSEvent *) event
{
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];