1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00
transmission/macosx/FilePriorityCell.m

153 lines
5.5 KiB
Mathematica
Raw Normal View History

2007-09-16 01:02:06 +00:00
/******************************************************************************
* $Id$
*
2008-01-02 16:55:05 +00:00
* Copyright (c) 2007-2008 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"
#import "FileOutlineView.h"
2007-09-16 01:02:06 +00:00
#import "Torrent.h"
@implementation FilePriorityCell
- (id) init
{
if ((self = [super init]))
{
[self setTrackingMode: NSSegmentSwitchTrackingSelectAny];
[self setControlSize: NSMiniControlSize];
[self setSegmentCount: 3];
int i;
for (i = 0; i < [self segmentCount]; i++)
{
[self setLabel: @"" forSegment: i];
[self setWidth: 9.0 forSegment: i]; //9 is minimum size to get proper look
2007-09-16 01:02:06 +00:00
}
2008-01-16 05:50:24 +00:00
[self setImage: [NSImage imageNamed: @"PriorityControlLow.png"] forSegment: 0];
[self setImage: [NSImage imageNamed: @"PriorityControlNormal.png"] forSegment: 1];
[self setImage: [NSImage imageNamed: @"PriorityControlHigh.png"] forSegment: 2];
fHoverRow = NO;
2007-09-16 01:02:06 +00:00
}
return self;
}
- (void) setSelected: (BOOL) flag forSegment: (int) segment
{
[super setSelected: flag forSegment: segment];
//only for when clicking manually
int 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;
}
2007-09-16 01:02:06 +00:00
2007-10-20 19:38:10 +00:00
FileOutlineView * controlView = (FileOutlineView *)[self controlView];
Torrent * torrent = [controlView torrent];
2007-09-16 01:02:06 +00:00
[torrent setFilePriority: priority forIndexes: [[self representedObject] objectForKey: @"Indexes"]];
2007-10-20 19:38:10 +00:00
[controlView reloadData];
2007-09-16 01:02:06 +00:00
}
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
mouseLocation: (NSPoint) mouseLocation
{
NSTrackingAreaOptions options = NSTrackingEnabledDuringMouseDrag | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
2008-01-12 03:53:41 +00:00
if (NSMouseInRect(mouseLocation, cellFrame, [controlView isFlipped]))
{
options |= NSTrackingAssumeInside;
2008-01-12 03:53:41 +00:00
[controlView setNeedsDisplayInRect: cellFrame];
}
2008-01-12 03:53:41 +00:00
NSTrackingArea * area = [[NSTrackingArea alloc] initWithRect: cellFrame options: options owner: controlView userInfo: userInfo];
[controlView addTrackingArea: area];
[area release];
}
- (void) mouseEntered: (NSEvent *) event
{
fHoverRow = YES;
[(NSControl *)[self controlView] updateCell: self];
}
- (void) mouseExited: (NSEvent *) event
{
fHoverRow = NO;
[(NSControl *)[self controlView] updateCell: self];
}
2007-09-16 01:02:06 +00:00
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
{
2007-10-20 19:29:50 +00:00
Torrent * torrent = [(FileOutlineView *)controlView torrent];
2007-09-16 01:02:06 +00:00
NSDictionary * dict = [self representedObject];
NSSet * priorities = [torrent filePrioritiesForIndexes: [dict objectForKey: @"Indexes"]];
int count = [priorities count];
if (fHoverRow && count > 0)
2007-09-16 01:02:06 +00:00
{
[super setSelected: [priorities containsObject: [NSNumber numberWithInt: TR_PRI_LOW]] forSegment: 0];
[super setSelected: [priorities containsObject: [NSNumber numberWithInt: TR_PRI_NORMAL]] forSegment: 1];
[super setSelected: [priorities containsObject: [NSNumber numberWithInt: TR_PRI_HIGH]] forSegment: 2];
[super drawWithFrame: cellFrame inView: controlView];
}
else
{
NSImage * image;
if (count == 0)
2007-12-04 16:47:00 +00:00
image = [NSImage imageNamed: @"PriorityNone.png"];
2007-09-16 01:02:06 +00:00
else if (count > 1)
2007-12-04 16:47:00 +00:00
image = [NSImage imageNamed: @"PriorityMixed.png"];
2007-09-16 01:02:06 +00:00
else
{
2007-10-20 19:25:14 +00:00
switch ([[priorities anyObject] intValue])
{
case TR_PRI_NORMAL:
2007-12-04 16:47:00 +00:00
image = [NSImage imageNamed: @"PriorityNormal.png"];
2007-10-20 19:25:14 +00:00
break;
case TR_PRI_LOW:
2007-12-04 16:47:00 +00:00
image = [NSImage imageNamed: @"PriorityLow.png"];
2007-10-20 19:25:14 +00:00
break;
case TR_PRI_HIGH:
2007-12-04 16:47:00 +00:00
image = [NSImage imageNamed: @"PriorityHigh.png"];
2007-10-20 19:25:14 +00:00
break;
}
2007-09-16 01:02:06 +00:00
}
NSSize imageSize = [image size];
[image compositeToPoint: NSMakePoint(cellFrame.origin.x + (cellFrame.size.width - imageSize.width) * 0.5,
cellFrame.origin.y + (cellFrame.size.height + imageSize.height) * 0.5) operation: NSCompositeSourceOver];
}
}
@end