summaryrefslogtreecommitdiffstats
path: root/macosx/HBPictureHUDController.m
blob: 8db23767b63f352112d4ef82086ccb6a56ce0691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*  HBPictureHUDController.m $

 This file is part of the HandBrake source code.
 Homepage: <http://handbrake.fr/>.
 It may be used under the terms of the GNU General Public License. */

#import "HBPictureHUDController.h"

@interface HBPictureHUDController ()

@property (weak) IBOutlet NSTextField *scaleLabel;
@property (weak) IBOutlet NSTextField *infoLabel;

@property (weak) IBOutlet NSSlider *slider;

@property (weak) IBOutlet NSPopUpButton *durationPopUp;
@property (weak) IBOutlet NSButton *scaleToScreenButton;

@property (weak) IBOutlet NSTextField *durationLabel;
@property (weak) IBOutlet NSTextField *durationUnitLabel;

@property (nonatomic) BOOL fitToView;

@end

@implementation HBPictureHUDController

- (NSString *)nibName
{
    return @"HBPictureHUDController";
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // we set the preview length popup in seconds
    [self.durationPopUp removeAllItems];
    [self.durationPopUp addItemsWithTitles:@[@"15", @"30", @"45", @"60", @"90",
                                             @"120", @"150", @"180", @"210", @"240"]];

    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewLength"])
    {
        [self.durationPopUp selectItemWithTitle:[[NSUserDefaults standardUserDefaults]
                                                       objectForKey:@"PreviewLength"]];
    }
    if (!self.durationPopUp.selectedItem)
    {
        // currently hard set default to 15 seconds
        [self.durationPopUp selectItemAtIndex:0];
    }
}

- (BOOL)canBeHidden
{
    return YES;
}

- (void)setPictureCount:(NSUInteger)pictureCount
{
    self.slider.numberOfTickMarks = pictureCount;
    self.slider.maxValue = pictureCount - 1;

    if (self.selectedIndex > pictureCount)
    {
        self.selectedIndex = pictureCount - 1;
    }
}

- (NSUInteger)selectedIndex
{
    return self.slider.integerValue;
}

- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    self.slider.integerValue = selectedIndex;
}

- (void)setInfo:(NSString *)info
{
    self.infoLabel.stringValue = info;
}

- (void)setScale:(NSString *)scale
{
    self.scaleLabel.stringValue = scale;
}

- (IBAction)previewDurationPopUpChanged:(id)sender
{
    [[NSUserDefaults standardUserDefaults] setObject:self.durationPopUp.titleOfSelectedItem forKey:@"PreviewLength"];
}

- (IBAction)pictureSliderChanged:(id)sender
{
    [self.delegate displayPreviewAtIndex:self.slider.integerValue];
}

- (IBAction)toggleScaleToScreen:(id)sender
{
    [self.delegate toggleScaleToScreen];
    if (self.fitToView == YES)
    {
        self.scaleToScreenButton.title = NSLocalizedString(@"Scale To Screen", @"Picture HUD -> scale button");
    }
    else
    {
        self.scaleToScreenButton.title = NSLocalizedString(@"Actual Scale", @"Picture HUD -> scale button");
    }
    self.fitToView = !self.fitToView;
}

- (IBAction)showPictureSettings:(id)sender
{
    [self.delegate showPictureSettings];
}

- (IBAction)createMoviePreview:(id)sender
{
    [self.delegate createMoviePreviewWithPictureIndex:self.slider.integerValue duration:self.durationPopUp.titleOfSelectedItem.intValue];
}

- (BOOL)HB_keyDown:(NSEvent *)event
{
    unichar key = [event.charactersIgnoringModifiers characterAtIndex:0];
    if (key == NSLeftArrowFunctionKey)
    {
        self.slider.integerValue = self.selectedIndex > self.slider.minValue ? self.selectedIndex - 1 : self.selectedIndex;
        [self.delegate displayPreviewAtIndex:self.slider.integerValue];
        return YES;
    }
    else if (key == NSRightArrowFunctionKey)
    {
        self.slider.integerValue = self.selectedIndex < self.slider.maxValue ? self.selectedIndex + 1 : self.selectedIndex;
        [self.delegate displayPreviewAtIndex:self.slider.integerValue];
        return YES;
    }
    else
    {
        return NO;
    }
}

- (BOOL)HB_scrollWheel:(NSEvent *)theEvent
{
    if (theEvent.deltaY < 0)
    {
        self.slider.integerValue = self.selectedIndex < self.slider.maxValue ? self.selectedIndex + 1 : self.selectedIndex;
        [self.delegate displayPreviewAtIndex:self.slider.integerValue];
    }
    else if (theEvent.deltaY > 0)
    {
        self.slider.integerValue = self.selectedIndex > self.slider.minValue ? self.selectedIndex - 1 : self.selectedIndex;
        [self.delegate displayPreviewAtIndex:self.slider.integerValue];
    }
    return YES;
}

@end