source: trunk/macosx/FileOutlineView.m @ 9844

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

happy new year!

  • Property Id set to /Users/mitchell/Desktop/Transmission/macosx/ActionMenuRatioToDisplayRatioTransformer.h
  • Property svn:keywords set to Date Rev Author Id
File size: 7.7 KB
Line 
1/******************************************************************************
2 * $Id: FileOutlineView.m 9844 2010-01-01 21:12:04Z livings124 $
3 *
4 * Copyright (c) 2007-2010 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 "FileListNode.h"
27#import "FileNameCell.h"
28#import "FileOutlineView.h"
29#import "FilePriorityCell.h"
30#import "Torrent.h"
31#import "NSApplicationAdditions.h"
32#import <Quartz/Quartz.h>
33
34@implementation FileOutlineView
35
36- (void) awakeFromNib
37{
38    FileNameCell * nameCell = [[FileNameCell alloc] init];
39    [[self tableColumnWithIdentifier: @"Name"] setDataCell: nameCell];
40    [nameCell release];
41   
42    FilePriorityCell * priorityCell = [[FilePriorityCell alloc] init];
43    [[self tableColumnWithIdentifier: @"Priority"] setDataCell: priorityCell];
44    [priorityCell release];
45   
46    [self setAutoresizesOutlineColumn: NO];
47    [self setIndentationPerLevel: 14.0];
48   
49    NSColor * endingColor = [NSColor colorWithCalibratedRed: 217.0/255.0 green: 250.0/255.0 blue: 211.0/255.0 alpha: 1.0];
50    NSColor * beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
51    fHighPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
52   
53    endingColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 243.0/255.0 blue: 206.0/255.0 alpha: 1.0];
54    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
55    fLowPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
56   
57    endingColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 218.0/255.0 blue: 255.0/255.0 alpha: 1.0];
58    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
59    fMixedPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
60   
61    fMouseRow = -1;
62}
63
64- (void) dealloc
65{
66    [fHighPriorityGradient release];
67    [fLowPriorityGradient release];
68    [fMixedPriorityGradient release];
69   
70    [super dealloc];
71}
72
73- (void) setTorrent: (Torrent *) torrent
74{
75    fTorrent = torrent;
76}
77
78- (Torrent *) torrent
79{
80    return fTorrent;
81}
82
83- (void) mouseDown: (NSEvent *) event
84{
85    [[self window] makeKeyWindow];
86    [super mouseDown: event];
87}
88
89- (void) keyDown: (NSEvent *) event
90{
91    const unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
92   
93    //don't allow quick look on add window
94    #warning get rid of conversion of protocol and replace with @protocol(QLPreviewPanelDataSource)
95    if ([NSApp isOnSnowLeopardOrBetter] && firstChar == ' ' && [[[self window] windowController] conformsToProtocol: NSProtocolFromString(@"QLPreviewPanelDataSource")])
96    {
97        if ([[QLPreviewPanelSL sharedPreviewPanel] isVisible])
98            [[QLPreviewPanelSL sharedPreviewPanel] orderOut: nil];
99        else
100            [[QLPreviewPanelSL sharedPreviewPanel] makeKeyAndOrderFront: nil];
101    }
102   
103    [super keyDown: event]; 
104}
105
106- (NSMenu *) menuForEvent: (NSEvent *) event
107{
108    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
109   
110    if (row >= 0)
111    {
112        if (![self isRowSelected: row])
113            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
114    }
115    else
116        [self deselectAll: self];
117   
118    return [self menu];
119}
120
121- (NSRect) iconRectForRow: (int) row
122{
123    FileNameCell * cell = (FileNameCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Name"] row: row];
124    NSRect iconRect = [cell imageRectForBounds: [self rectOfRow: row]];
125   
126    iconRect.origin.x += [self indentationPerLevel] * (float)([self levelForRow: row] + 1);
127    return iconRect;
128}
129
130- (void) updateTrackingAreas
131{
132    [super updateTrackingAreas];
133   
134    for (NSTrackingArea * area in [self trackingAreas])
135    {
136        if ([area owner] == self && [[area userInfo] objectForKey: @"Row"])
137            [self removeTrackingArea: area];
138    }
139   
140    NSRange visibleRows = [self rowsInRect: [self visibleRect]];
141    if (visibleRows.length == 0)
142        return;
143   
144    NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
145   
146    for (NSInteger row = visibleRows.location, col = [self columnWithIdentifier: @"Priority"]; row < NSMaxRange(visibleRows); row++)
147    {
148        FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: col row: row];
149       
150        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
151        [cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
152                mouseLocation: mouseLocation];
153    }
154}
155
156- (int) hoveredRow
157{
158    return fMouseRow;
159}
160
161- (void) mouseEntered: (NSEvent *) event
162{
163    NSNumber * row;
164    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
165    {
166        fMouseRow = [row intValue];
167        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: fMouseRow]];
168    }
169}
170
171- (void) mouseExited: (NSEvent *) event
172{
173    NSNumber * row;
174    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
175    {
176        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: [row intValue]]];
177        fMouseRow = -1;
178    }
179}
180
181- (void) drawRow: (NSInteger) row clipRect: (NSRect) clipRect
182{
183    if (![self isRowSelected: row])
184    {
185        NSDictionary * item = [self itemAtRow: row];
186        NSIndexSet * indexes = [(FileListNode *)item indexes];
187       
188        if ([fTorrent checkForFiles: indexes] != NSOffState)
189        {
190            NSGradient * gradient = nil;
191           
192            NSSet * priorities = [fTorrent filePrioritiesForIndexes: indexes];
193            int count = [priorities count];
194            if (count == 1)
195            {
196                switch ([[priorities anyObject] intValue])
197                {
198                    case TR_PRI_LOW:
199                        gradient = fLowPriorityGradient;
200                        break;
201                    case TR_PRI_HIGH:
202                        gradient = fHighPriorityGradient;
203                        break;
204                }
205            }
206            else if (count > 1)
207                gradient = fMixedPriorityGradient;
208            else;
209           
210            if (gradient)
211            {
212                NSRect rect = [self rectOfRow: row];
213                rect.size.height -= 1.0;
214                [gradient drawInRect: rect angle: 90];
215            }
216        }
217    }
218   
219    [super drawRow: row clipRect: clipRect];
220}
221
222@end
Note: See TracBrowser for help on using the repository browser.