MacGui: show a preview image in the summary tab.

This commit is contained in:
Damiano Galassi 2017-11-12 12:41:42 +01:00
parent 2c75047460
commit 2ce11e0c32
No known key found for this signature in database
GPG Key ID: 27A26119422278AA
6 changed files with 47 additions and 5 deletions

View File

@ -9,6 +9,7 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="HBSummaryViewController">
<connections>
<outlet property="previewView" destination="m5a-0z-QQ4" id="1G9-3A-dM4"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
@ -158,7 +159,7 @@ Multiline LabelMultiline Label</string>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<customView wantsLayer="YES" translatesAutoresizingMaskIntoConstraints="NO" id="m5a-0z-QQ4">
<customView wantsLayer="YES" translatesAutoresizingMaskIntoConstraints="NO" id="m5a-0z-QQ4" customClass="HBPreviewView">
<rect key="frame" x="254" y="16" width="597" height="334"/>
</customView>
</subviews>

View File

@ -813,7 +813,9 @@
if (job)
{
fPreviewController.generator = [[HBPreviewGenerator alloc] initWithCore:self.core job:job];
HBPreviewGenerator *generator = [[HBPreviewGenerator alloc] initWithCore:self.core job:job];
fPreviewController.generator = generator;
self.summaryController.generator = generator;
HBTitle *title = job.title;
@ -830,6 +832,7 @@
else
{
fPreviewController.generator = nil;
self.summaryController.generator = nil;
}
fPreviewController.picture = job.picture;

View File

@ -40,6 +40,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readwrite) BOOL showBorder;
/**
* If enabled, the view will show a shadow around the image.
*/
@property (nonatomic, readwrite) BOOL showShadow;
/**
* Given the size of the preview image to be shown, returns the best possible
* size for the view.

View File

@ -118,6 +118,11 @@
[self _updatePreviewLayout];
}
- (void)setShowShadow:(BOOL)showShadow
{
_backLayer.shadowOpacity = showShadow ? 0.5f : 0;
}
- (void)setFrame:(NSRect)newRect {
// A change in size has required the view to be invalidated.
if ([self inLiveResize]) {

View File

@ -7,9 +7,15 @@
#import <Cocoa/Cocoa.h>
@class HBJob;
@class HBPreviewGenerator;
NS_ASSUME_NONNULL_BEGIN
@interface HBSummaryViewController : NSViewController
@property (nonatomic, readwrite, weak) HBJob *job;
@property (nonatomic, readwrite, weak, nullable) HBJob *job;
@property (nonatomic, readwrite, weak, nullable) HBPreviewGenerator *generator;
@end
NS_ASSUME_NONNULL_END

View File

@ -5,18 +5,40 @@
It may be used under the terms of the GNU General Public License. */
#import "HBSummaryViewController.h"
#import "HBPreviewView.h"
#import "HBPreviewGenerator.h"
@import HandBrakeKit.HBJob;
@import HandBrakeKit;
@interface HBSummaryViewController ()
@property (strong) IBOutlet HBPreviewView *previewView;
@end
@implementation HBSummaryViewController
- (void)loadView {
[super loadView];
// Do view setup here.
self.previewView.showShadow = NO;
}
- (void)setGenerator:(HBPreviewGenerator *)generator
{
_generator = generator;
if (generator)
{
NSUInteger index = generator.imagesCount > 1 ? 1 : 0;
CGImageRef fPreviewImage = [generator copyImageAtIndex:index shouldCache:NO];
self.previewView.image = fPreviewImage;
CFRelease(fPreviewImage);
}
else
{
self.previewView.image = nil;
}
}
@end