source: trunk/macosx/FileOutlineView.m @ 9034

Last change on this file since 9034 was 9034, checked in by livings124, 13 years ago

draft #1 of #2369 - use public API for QuickLook? on 10.6 (and drop the hack for 10.5-support)

  • Property Id set to /Users/mitchell/Desktop/Transmission/macosx/ActionMenuRatioToDisplayRatioTransformer.h
  • Property svn:keywords set to Date Rev Author Id
File size: 6.9 KB
Line 
1/******************************************************************************
2 * $Id: FileOutlineView.m 9034 2009-09-04 04:10:46Z livings124 $
3 *
4 * Copyright (c) 2007-2009 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "InfoWindowController.h"
26#import "FileOutlineView.h"
27#import "FileNameCell.h"
28#import "FilePriorityCell.h"
29#import "Torrent.h"
30#import "FileListNode.h"
31
32@implementation FileOutlineView
33
34- (void) awakeFromNib
35{
36    FileNameCell * nameCell = [[FileNameCell alloc] init];
37    [[self tableColumnWithIdentifier: @"Name"] setDataCell: nameCell];
38    [nameCell release];
39   
40    FilePriorityCell * priorityCell = [[FilePriorityCell alloc] init];
41    [[self tableColumnWithIdentifier: @"Priority"] setDataCell: priorityCell];
42    [priorityCell release];
43   
44    [self setAutoresizesOutlineColumn: NO];
45    [self setIndentationPerLevel: 14.0];
46   
47    NSColor * endingColor = [NSColor colorWithCalibratedRed: 217.0/255.0 green: 250.0/255.0 blue: 211.0/255.0 alpha: 1.0];
48    NSColor * beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
49    fHighPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
50   
51    endingColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 243.0/255.0 blue: 206.0/255.0 alpha: 1.0];
52    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
53    fLowPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
54   
55    endingColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 218.0/255.0 blue: 255.0/255.0 alpha: 1.0];
56    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
57    fMixedPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
58   
59    fMouseRow = -1;
60}
61
62- (void) dealloc
63{
64    [fHighPriorityGradient release];
65    [fLowPriorityGradient release];
66    [fMixedPriorityGradient release];
67   
68    [super dealloc];
69}
70
71- (void) setTorrent: (Torrent *) torrent
72{
73    fTorrent = torrent;
74}
75
76- (Torrent *) torrent
77{
78    return fTorrent;
79}
80
81- (void) mouseDown: (NSEvent *) event
82{
83    [[self window] makeKeyWindow];
84    [super mouseDown: event];
85}
86
87- (NSMenu *) menuForEvent: (NSEvent *) event
88{
89    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
90   
91    if (row >= 0)
92    {
93        if (![self isRowSelected: row])
94            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
95    }
96    else
97        [self deselectAll: self];
98   
99    return [self menu];
100}
101
102- (NSRect) iconRectForRow: (int) row
103{
104    FileNameCell * cell = (FileNameCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Name"] row: row];
105    NSRect iconRect = [cell imageRectForBounds: [self rectOfRow: row]];
106   
107    iconRect.origin.x += [self indentationPerLevel] * (float)([self levelForRow: row] + 1);
108    return iconRect;
109}
110
111- (void) updateTrackingAreas
112{
113    [super updateTrackingAreas];
114   
115    for (NSTrackingArea * area in [self trackingAreas])
116    {
117        if ([area owner] == self && [[area userInfo] objectForKey: @"Row"])
118            [self removeTrackingArea: area];
119    }
120   
121    NSRange visibleRows = [self rowsInRect: [self visibleRect]];
122    if (visibleRows.length == 0)
123        return;
124   
125    NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
126   
127    for (NSInteger row = visibleRows.location, col = [self columnWithIdentifier: @"Priority"]; row < NSMaxRange(visibleRows); row++)
128    {
129        FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: col row: row];
130       
131        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
132        [cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
133                mouseLocation: mouseLocation];
134    }
135}
136
137- (int) hoveredRow
138{
139    return fMouseRow;
140}
141
142- (void) mouseEntered: (NSEvent *) event
143{
144    NSNumber * row;
145    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
146    {
147        fMouseRow = [row intValue];
148        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: fMouseRow]];
149    }
150}
151
152- (void) mouseExited: (NSEvent *) event
153{
154    NSNumber * row;
155    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
156    {
157        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: [row intValue]]];
158        fMouseRow = -1;
159    }
160}
161
162- (void) drawRow: (NSInteger) row clipRect: (NSRect) clipRect
163{
164    if (![self isRowSelected: row])
165    {
166        NSDictionary * item = [self itemAtRow: row];
167        NSIndexSet * indexes = [(FileListNode *)item indexes];
168       
169        if ([fTorrent checkForFiles: indexes] != NSOffState)
170        {
171            NSGradient * gradient = nil;
172           
173            NSSet * priorities = [fTorrent filePrioritiesForIndexes: indexes];
174            int count = [priorities count];
175            if (count == 1)
176            {
177                switch ([[priorities anyObject] intValue])
178                {
179                    case TR_PRI_LOW:
180                        gradient = fLowPriorityGradient;
181                        break;
182                    case TR_PRI_HIGH:
183                        gradient = fHighPriorityGradient;
184                        break;
185                }
186            }
187            else if (count > 1)
188                gradient = fMixedPriorityGradient;
189            else;
190           
191            if (gradient)
192            {
193                NSRect rect = [self rectOfRow: row];
194                rect.size.height -= 1.0;
195                [gradient drawInRect: rect angle: 90];
196            }
197        }
198    }
199   
200    [super drawRow: row clipRect: clipRect];
201}
202
203@end
Note: See TracBrowser for help on using the repository browser.