2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2007-2012 Transmission authors and contributors
|
2007-09-16 01:02:06 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "FilePriorityCell.h"
|
2007-10-20 19:13:52 +00:00
|
|
|
#import "FileOutlineView.h"
|
2008-05-22 18:39:49 +00:00
|
|
|
#import "FileListNode.h"
|
2011-10-22 20:45:20 +00:00
|
|
|
#import "NSImageAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "Torrent.h"
|
|
|
|
|
2011-10-23 17:45:05 +00:00
|
|
|
#define IMAGE_OVERLAP 1.0
|
2011-05-30 00:09:22 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@implementation FilePriorityCell
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
[self setTrackingMode: NSSegmentSwitchTrackingSelectAny];
|
|
|
|
[self setControlSize: NSMiniControlSize];
|
|
|
|
[self setSegmentCount: 3];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = 0; i < [self segmentCount]; i++)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
[self setLabel: @"" forSegment: i];
|
2008-11-01 15:22:32 +00:00
|
|
|
[self setWidth: 9.0f forSegment: i]; //9 is minimum size to get proper look
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-06-10 02:35:58 +00:00
|
|
|
[self setImage: [NSImage imageNamed: @"PriorityControlLow"] forSegment: 0];
|
|
|
|
[self setImage: [NSImage imageNamed: @"PriorityControlNormal"] forSegment: 1];
|
|
|
|
[self setImage: [NSImage imageNamed: @"PriorityControlHigh"] forSegment: 2];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-12 03:39:26 +00:00
|
|
|
fHoverRow = NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-05-19 22:04:46 +00:00
|
|
|
- (id) copyWithZone: (NSZone *) zone
|
|
|
|
{
|
|
|
|
id value = [super copyWithZone: zone];
|
|
|
|
[value setRepresentedObject: [self representedObject]];
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2008-11-01 15:22:32 +00:00
|
|
|
- (void) setSelected: (BOOL) flag forSegment: (NSInteger) segment
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
[super setSelected: flag forSegment: segment];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//only for when clicking manually
|
2008-11-01 15:22:32 +00:00
|
|
|
NSInteger priority;
|
2007-10-20 19:38:10 +00:00
|
|
|
switch (segment)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-05-31 22:26:04 +00:00
|
|
|
Torrent * torrent = [(FileListNode *)[self representedObject] torrent];
|
2008-05-22 18:39:49 +00:00
|
|
|
[torrent setFilePriority: priority forIndexes: [(FileListNode *)[self representedObject] indexes]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-05-31 22:26:04 +00:00
|
|
|
FileOutlineView * controlView = (FileOutlineView *)[self controlView];
|
2012-01-04 00:36:21 +00:00
|
|
|
[controlView setNeedsDisplay: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
2008-01-12 03:39:26 +00:00
|
|
|
mouseLocation: (NSPoint) mouseLocation
|
|
|
|
{
|
|
|
|
NSTrackingAreaOptions options = NSTrackingEnabledDuringMouseDrag | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-12 03:53:41 +00:00
|
|
|
if (NSMouseInRect(mouseLocation, cellFrame, [controlView isFlipped]))
|
2008-01-12 03:39:26 +00:00
|
|
|
{
|
|
|
|
options |= NSTrackingAssumeInside;
|
2008-01-12 03:53:41 +00:00
|
|
|
[controlView setNeedsDisplayInRect: cellFrame];
|
2008-01-12 03:39:26 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-12 03:53:41 +00:00
|
|
|
NSTrackingArea * area = [[NSTrackingArea alloc] initWithRect: cellFrame options: options owner: controlView userInfo: userInfo];
|
2008-01-12 03:39:26 +00:00
|
|
|
[controlView addTrackingArea: area];
|
2012-03-13 02:52:11 +00:00
|
|
|
[area release];
|
2008-01-12 03:39:26 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 03:17:35 +00:00
|
|
|
- (void) setHovered: (BOOL) hovered
|
2008-01-12 03:39:26 +00:00
|
|
|
{
|
2008-03-25 03:17:35 +00:00
|
|
|
fHoverRow = hovered;
|
2008-01-12 03:39:26 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
|
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
FileListNode * node = [self representedObject];
|
2011-05-31 22:26:04 +00:00
|
|
|
Torrent * torrent = [node torrent];
|
2008-05-22 18:39:49 +00:00
|
|
|
NSSet * priorities = [torrent filePrioritiesForIndexes: [node indexes]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
const NSUInteger count = [priorities count];
|
2008-01-12 03:39:26 +00:00
|
|
|
if (fHoverRow && count > 0)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-12-26 21:31:00 +00:00
|
|
|
[super setSelected: [priorities containsObject: [NSNumber numberWithInteger: TR_PRI_LOW]] forSegment: 0];
|
|
|
|
[super setSelected: [priorities containsObject: [NSNumber numberWithInteger: TR_PRI_NORMAL]] forSegment: 1];
|
|
|
|
[super setSelected: [priorities containsObject: [NSNumber numberWithInteger: TR_PRI_HIGH]] forSegment: 2];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[super drawWithFrame: cellFrame inView: controlView];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-11 10:22:49 +00:00
|
|
|
NSMutableArray * images = [NSMutableArray arrayWithCapacity: MAX(count, 1u)];
|
2011-05-30 00:09:22 +00:00
|
|
|
CGFloat totalWidth;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (count == 0)
|
2011-05-30 00:09:22 +00:00
|
|
|
{
|
2011-10-22 20:45:20 +00:00
|
|
|
//if ([self backgroundStyle] != NSBackgroundStyleDark)
|
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
NSImage * image = [[NSImage imageNamed: @"PriorityNormalTemplate"] imageWithColor: [NSColor lightGrayColor]];
|
2011-10-22 20:45:20 +00:00
|
|
|
[images addObject: image];
|
|
|
|
totalWidth = [image size].width;
|
|
|
|
}
|
2011-05-30 00:09:22 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
2011-10-22 20:45:20 +00:00
|
|
|
NSColor * priorityColor = [self backgroundStyle] == NSBackgroundStyleDark ? [NSColor whiteColor] : [NSColor darkGrayColor];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-05-30 00:09:22 +00:00
|
|
|
totalWidth = 0.0;
|
|
|
|
if ([priorities containsObject: [NSNumber numberWithInteger: TR_PRI_LOW]])
|
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
NSImage * image = [[NSImage imageNamed: @"PriorityLowTemplate"] imageWithColor: priorityColor];
|
2011-05-30 00:09:22 +00:00
|
|
|
[images addObject: image];
|
|
|
|
totalWidth += [image size].width;
|
|
|
|
}
|
|
|
|
if ([priorities containsObject: [NSNumber numberWithInteger: TR_PRI_NORMAL]])
|
2007-10-20 19:25:14 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
NSImage * image = [[NSImage imageNamed: @"PriorityNormalTemplate"] imageWithColor: priorityColor];
|
2011-05-30 00:09:22 +00:00
|
|
|
[images addObject: image];
|
|
|
|
totalWidth += [image size].width;
|
|
|
|
}
|
|
|
|
if ([priorities containsObject: [NSNumber numberWithInteger: TR_PRI_HIGH]])
|
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
NSImage * image = [[NSImage imageNamed: @"PriorityHighTemplate"] imageWithColor: priorityColor];
|
2011-05-30 00:09:22 +00:00
|
|
|
[images addObject: image];
|
|
|
|
totalWidth += [image size].width;
|
2007-10-20 19:25:14 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-05-30 00:09:22 +00:00
|
|
|
if (count > 1)
|
|
|
|
totalWidth -= IMAGE_OVERLAP * (count-1);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-05-30 00:09:22 +00:00
|
|
|
CGFloat currentWidth = floor(NSMidX(cellFrame) - totalWidth * 0.5);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-05-30 00:09:22 +00:00
|
|
|
for (NSImage * image in images)
|
2009-08-29 23:10:53 +00:00
|
|
|
{
|
2011-05-30 00:09:22 +00:00
|
|
|
const NSSize imageSize = [image size];
|
2011-10-06 00:30:40 +00:00
|
|
|
const NSRect imageRect = NSMakeRect(currentWidth, floor(NSMidY(cellFrame) - imageSize.height * 0.5), imageSize.width, imageSize.height);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
[image drawInRect: imageRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0 respectFlipped: YES hints: nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-05-30 00:09:22 +00:00
|
|
|
currentWidth += imageSize.width - IMAGE_OVERLAP;
|
2009-08-29 23:10:53 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|