mirror of
https://github.com/transmission/transmission
synced 2025-02-20 13:16:53 +00:00
migrate some of the action button code to TorrentCell
This commit is contained in:
parent
a275277903
commit
7933bc4d9e
4 changed files with 32 additions and 52 deletions
|
@ -52,5 +52,6 @@
|
|||
|
||||
- (NSRect) controlButtonRectForBounds: (NSRect) bounds;
|
||||
- (NSRect) revealButtonRectForBounds: (NSRect) bounds;
|
||||
- (NSRect) actionButtonRectForBounds: (NSRect) bounds;
|
||||
|
||||
@end
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#define IMAGE_SIZE_MIN 16.0
|
||||
|
||||
#define NORMAL_BUTTON_WIDTH 14.0
|
||||
#define ACTION_BUTTON_HEIGHT 14.0
|
||||
#define ACTION_BUTTON_WIDTH 32.0
|
||||
|
||||
//ends up being larger than font height
|
||||
#define HEIGHT_TITLE 16.0
|
||||
|
@ -43,6 +45,7 @@
|
|||
|
||||
#define PADDING_HORIZONTAL 2.0
|
||||
#define PADDING_ABOVE_IMAGE_REG 9.0
|
||||
#define PADDING_BETWEEN_IMAGE_AND_ACTION_BUTTON 3.0
|
||||
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0
|
||||
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0
|
||||
#define PADDING_ABOVE_TITLE 3.0
|
||||
|
@ -247,6 +250,21 @@
|
|||
return result;
|
||||
}
|
||||
|
||||
- (NSRect) actionButtonRectForBounds: (NSRect) bounds
|
||||
{
|
||||
NSRect iconRect = [self iconRectForBounds: bounds];
|
||||
if ([fDefaults boolForKey: @"SmallView"])
|
||||
return iconRect;
|
||||
|
||||
NSRect result = iconRect;
|
||||
result.origin.x += (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5;
|
||||
result.origin.y += iconRect.size.height + PADDING_BETWEEN_IMAGE_AND_ACTION_BUTTON;
|
||||
result.size.width = ACTION_BUTTON_WIDTH;
|
||||
result.size.height = ACTION_BUTTON_HEIGHT;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSUInteger) hitTestForEvent: (NSEvent *) event inRect: (NSRect) cellFrame ofView: (NSView *) controlView
|
||||
{
|
||||
NSPoint point = [controlView convertPoint: [event locationInWindow] fromView: nil];
|
||||
|
@ -437,6 +455,12 @@
|
|||
[revealImage drawInRect: [self revealButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
|
||||
fraction: 1.0];
|
||||
|
||||
//action button
|
||||
NSImage * actionImage = /*fMouseDownActionButton ? [NSImage imageNamed: @"ActionOn.png"] :*/ [NSImage imageNamed: @"ActionOff.png"];
|
||||
[actionImage setFlipped: YES];
|
||||
[actionImage drawInRect: [self actionButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
|
||||
fraction: 1.0];
|
||||
|
||||
//status
|
||||
if (!minimal)
|
||||
{
|
||||
|
|
|
@ -26,9 +26,6 @@
|
|||
#import <transmission.h>
|
||||
#import <Controller.h>
|
||||
|
||||
#define ACTION_BUTTON_HEIGHT 14.0
|
||||
#define ACTION_BUTTON_WIDTH 32.0
|
||||
|
||||
@interface TorrentTableView : NSTableView
|
||||
{
|
||||
IBOutlet Controller * fController;
|
||||
|
|
|
@ -29,31 +29,17 @@
|
|||
#import "NSApplicationAdditions.h"
|
||||
#import "NSMenuAdditions.h"
|
||||
|
||||
#define PADDING 3.0
|
||||
|
||||
#define BUTTON_TO_TOP_REGULAR 33.0
|
||||
#define BUTTON_TO_TOP_SMALL 20.0
|
||||
|
||||
//button layout (from end of bar) is: button, padding, button, padding
|
||||
#define BUTTON_WIDTH 14.0
|
||||
#define BUTTONS_TOTAL_WIDTH 36.0
|
||||
|
||||
#define ACTION_BUTTON_TO_TOP 44.0
|
||||
|
||||
#define ACTION_MENU_GLOBAL_TAG 101
|
||||
#define ACTION_MENU_UNLIMITED_TAG 102
|
||||
#define ACTION_MENU_LIMIT_TAG 103
|
||||
|
||||
@interface TorrentTableView (Private)
|
||||
|
||||
- (NSRect) actionRectForRow: (int) row;
|
||||
- (BOOL) pointInActionRect: (NSPoint) point;
|
||||
|
||||
- (BOOL) pointInIconRect: (NSPoint) point;
|
||||
- (BOOL) pointInProgressRect: (NSPoint) point;
|
||||
- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
|
||||
|
||||
- (BOOL) pointInActionRect: (NSPoint) point;
|
||||
|
||||
- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
|
||||
|
||||
@end
|
||||
|
@ -309,7 +295,8 @@
|
|||
[fActionMenu appendItemsFromMenu: fileMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range] atBottom: YES];
|
||||
|
||||
//place menu below button
|
||||
NSRect rect = [self actionRectForRow: row];
|
||||
NSRect rect = [[[self tableColumnWithIdentifier: @"Torrent"] dataCell] actionButtonRectForBounds:
|
||||
[self frameOfCellAtColumn: 0 row: row]];
|
||||
NSPoint location = rect.origin;
|
||||
location.y += rect.size.height + 5.0;
|
||||
location = [self convertPoint: location toView: nil];
|
||||
|
@ -480,38 +467,18 @@
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
|
||||
}
|
||||
|
||||
- (void) drawRow: (int) row clipRect: (NSRect) rect
|
||||
{
|
||||
[super drawRow: row clipRect: rect];
|
||||
|
||||
//action icon
|
||||
if (![fDefaults boolForKey: @"SmallView"])
|
||||
{
|
||||
NSRect actionRect = [self actionRectForRow: row];
|
||||
NSImage * actionImage = /*NSPointInRect(fClickPoint, actionRect) ? [NSImage imageNamed: @"ActionOn.png"]
|
||||
:*/ [NSImage imageNamed: @"ActionOff.png"];
|
||||
[actionImage compositeToPoint: NSMakePoint(actionRect.origin.x, NSMaxY(actionRect)) operation: NSCompositeSourceOver];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TorrentTableView (Private)
|
||||
|
||||
- (NSRect) actionRectForRow: (int) row
|
||||
- (BOOL) pointInActionRect: (NSPoint) point
|
||||
{
|
||||
int row = [self rowAtPoint: point];
|
||||
if (row < 0)
|
||||
return NSZeroRect;
|
||||
return NO;
|
||||
|
||||
TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
|
||||
NSRect cellRect = [self frameOfCellAtColumn: 0 row: row],
|
||||
iconRect = [cell iconRectForBounds: cellRect];
|
||||
|
||||
if ([fDefaults boolForKey: @"SmallView"])
|
||||
return iconRect;
|
||||
else
|
||||
return NSMakeRect(iconRect.origin.x + (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5,
|
||||
cellRect.origin.y + ACTION_BUTTON_TO_TOP, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT);
|
||||
return NSPointInRect(point, [cell actionButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
||||
}
|
||||
|
||||
- (BOOL) pointInIconRect: (NSPoint) point
|
||||
|
@ -558,15 +525,6 @@
|
|||
return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
||||
}
|
||||
|
||||
- (BOOL) pointInActionRect: (NSPoint) point
|
||||
{
|
||||
int row = [self rowAtPoint: point];
|
||||
if (row < 0)
|
||||
return NO;
|
||||
|
||||
return NSPointInRect(point, [self actionRectForRow: row]);
|
||||
}
|
||||
|
||||
- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
|
||||
{
|
||||
BOOL create = [menu numberOfItems] <= 0;
|
||||
|
|
Loading…
Reference in a new issue