1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00
transmission/macosx/TorrentCellControlButton.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

107 lines
2.8 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 "TorrentCellControlButton.h"
#import "TorrentTableView.h"
#import "Torrent.h"
@interface TorrentCellControlButton ()
@property(nonatomic) NSTrackingArea* fTrackingArea;
@property(nonatomic, copy) NSString* controlImageSuffix;
@property(nonatomic) TorrentTableView* torrentTableView;
@end
@implementation TorrentCellControlButton
- (void)awakeFromNib
{
self.controlImageSuffix = @"Off";
[self updateImage];
}
- (void)resetImage
{
self.controlImageSuffix = @"Off";
[self updateImage];
}
- (void)setupTorrentTableView
{
if (!self.torrentTableView)
{
self.torrentTableView = (TorrentTableView*)[[[self superview] superview] superview];
}
}
- (void)mouseEntered:(NSEvent*)event
{
[super mouseEntered:event];
self.controlImageSuffix = @"Hover";
[self updateImage];
[self.torrentTableView hoverEventBeganForView:self];
}
- (void)mouseExited:(NSEvent*)event
{
[super mouseExited:event];
self.controlImageSuffix = @"Off";
[self updateImage];
[self.torrentTableView hoverEventEndedForView:self];
}
- (void)mouseDown:(NSEvent*)event
{
//when filterbar is shown, we need to remove focus otherwise action fails
[self.window makeFirstResponder:self.torrentTableView];
[super mouseDown:event];
self.controlImageSuffix = @"On";
[self updateImage];
[self.torrentTableView hoverEventEndedForView:self];
}
- (void)updateImage
{
[self setupTorrentTableView];
NSImage* controlImage;
Torrent* torrent = [self.torrentTableView itemAtRow:[self.torrentTableView rowForView:self]];
if (torrent.active)
{
controlImage = [NSImage imageNamed:[@"Pause" stringByAppendingString:self.controlImageSuffix]];
}
else
{
if (NSApp.currentEvent.modifierFlags & NSEventModifierFlagOption)
{
controlImage = [NSImage imageNamed:[@"ResumeNoWait" stringByAppendingString:self.controlImageSuffix]];
}
else if (torrent.waitingToStart)
{
controlImage = [NSImage imageNamed:[@"Pause" stringByAppendingString:self.controlImageSuffix]];
}
else
{
controlImage = [NSImage imageNamed:[@"Resume" stringByAppendingString:self.controlImageSuffix]];
}
}
self.image = controlImage;
}
- (void)updateTrackingAreas
{
if (self.fTrackingArea != nil)
{
[self removeTrackingArea:self.fTrackingArea];
}
NSTrackingAreaOptions opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);
self.fTrackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds options:opts owner:self userInfo:nil];
[self addTrackingArea:self.fTrackingArea];
}
@end