1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00
transmission/macosx/SmallTorrentCell.mm
SweetPPro 635268854b
refactor: view-based TorrentTableView in macOS client (#5147)
Converted TorrentTableView from older style cell based table to more modern view based
* floating group rows are now used for an improved groups experience
* individual group indicators are hidden when _Use Groups_ is selected to minimize visual clutter (see #3328 )
* removed negated `usesAlternatingRowBackgroundColors` flag for minimal view in Controller.mm (personal preference - easy to restore)
2023-06-27 14:40:44 -05:00

98 lines
2.6 KiB
Text

// This file Copyright © 2006-2023 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
#import "SmallTorrentCell.h"
#import "ProgressBarView.h"
#import "ProgressGradients.h"
#import "TorrentTableView.h"
#import "Torrent.h"
@interface SmallTorrentCell ()
@property(nonatomic) NSTrackingArea* fTrackingArea;
@end
@implementation SmallTorrentCell
//draw progress bar
- (void)drawRect:(NSRect)dirtyRect
{
if (self.fTorrentTableView)
{
NSRect barRect = self.fTorrentProgressBarView.frame;
ProgressBarView* progressBar = [[ProgressBarView alloc] init];
Torrent* torrent = (Torrent*)self.objectValue;
[progressBar drawBarInRect:barRect forTableView:self.fTorrentTableView withTorrent:torrent];
}
[super drawRect:dirtyRect];
}
//otherwise progress bar is inverted
- (BOOL)isFlipped
{
return YES;
}
//show fControlButton and fRevealButton
- (void)mouseEntered:(NSEvent*)event
{
[super mouseEntered:event];
NSPoint mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];
if (NSPointInRect(mouseLocation, self.fTrackingArea.rect))
{
[self.fTorrentTableView hoverEventBeganForView:self];
}
}
- (void)mouseExited:(NSEvent*)event
{
[super mouseExited:event];
NSPoint mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];
if (!NSPointInRect(mouseLocation, self.fTrackingArea.rect))
{
[self.fTorrentTableView hoverEventEndedForView:self];
}
}
- (void)mouseUp:(NSEvent*)event
{
[super mouseUp:event];
[self updateTrackingAreas];
}
- (void)updateTrackingAreas
{
if (self.fTrackingArea != nil)
{
[self removeTrackingArea:self.fTrackingArea];
}
//tracking rect should not be entire row, but start at fGroupDownloadView
NSRect titleRect = self.fTorrentTitleField.frame;
CGFloat maxX = NSMaxX(titleRect);
NSRect rect = self.bounds;
rect.origin.x = maxX;
NSTrackingAreaOptions opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow);
self.fTrackingArea = [[NSTrackingArea alloc] initWithRect:rect options:opts owner:self userInfo:nil];
[self addTrackingArea:self.fTrackingArea];
//check to see if mouse is already within rect
NSPoint mouseLocation = [self.window mouseLocationOutsideOfEventStream];
mouseLocation = [self.superview convertPoint:mouseLocation fromView:nil];
if (NSPointInRect(mouseLocation, rect))
{
[self mouseEntered:[[NSEvent alloc] init]];
}
else
{
[self mouseExited:[[NSEvent alloc] init]];
}
}
@end