Font size implemented through bindings.

CQTexperiment
matthewleon 2008-02-18 00:11:38 +00:00
parent 6663d149b7
commit 7f52608e6c
8 changed files with 2998 additions and 2872 deletions

View File

@ -337,6 +337,11 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
{
NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary];
// Font defaults
float fFontSize = [NSFont systemFontSizeForControlSize:NSSmallControlSize];
NSNumber *fontSize = [NSNumber numberWithFloat:fFontSize];
[userDefaultsValuesDict setObject:fontSize forKey:@"fontSize"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:35] forKey:@"hotKeyPlayKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPlayModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:'P'] forKey:@"hotKeyPlayCharacter"];
@ -451,32 +456,10 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
- (void)changeFontSize:(float)size
{
NSFont *f = [[NSFontManager sharedFontManager] selectedFont];
float origFontSize = [[f fontDescriptor] pointSize];
// hack to make the file drawer stay unbolded - might affect things I haven't seen
f = [[NSFontManager sharedFontManager] convertFont:f toNotHaveTrait:NSBoldFontMask];
f = [[NSFontManager sharedFontManager] convertFont:f toSize:origFontSize+size];
NSEnumerator *playlistEntries = [[playlistView tableColumns] objectEnumerator];
id c;
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[playlistView setRowHeight:[layoutManager defaultLineHeightForFont:f]];
[layoutManager release];
while (c = [playlistEntries nextObject])
{
[[c dataCell] setFont:f];
}
// we must set the selectedFont so that we have updated font information
// next time we want to change it
[[NSFontManager sharedFontManager] setSelectedFont:f isMultiple:NO];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
float fCurrentSize = [defaults floatForKey:@"fontSize"];
NSNumber *newSize = [NSNumber numberWithFloat:(fCurrentSize + size)];
[defaults setObject:newSize forKey:@"fontSize"];
}
- (IBAction)increaseFontSize:(id)sender

View File

@ -117,6 +117,7 @@
56462DDA0D61D71E000AB68C /* SpotlightPlaylistView.m in Sources */ = {isa = PBXBuildFile; fileRef = 56462DD90D61D71E000AB68C /* SpotlightPlaylistView.m */; };
56462EAF0D6341F6000AB68C /* SpotlightTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = 56462EAE0D6341F6000AB68C /* SpotlightTransformers.m */; };
56462EB20D634206000AB68C /* SpotlightPlaylistController.m in Sources */ = {isa = PBXBuildFile; fileRef = 56462EB10D634206000AB68C /* SpotlightPlaylistController.m */; };
56AE86C10D6901BC00B0F89B /* FontSizetoLineHeightTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 56AE86C00D6901BC00B0F89B /* FontSizetoLineHeightTransformer.m */; };
56C63D910D647DF300EAE25A /* NSComparisonPredicate+CogPredicate.m in Sources */ = {isa = PBXBuildFile; fileRef = 56C63D900D647DF300EAE25A /* NSComparisonPredicate+CogPredicate.m */; };
56DB084C0D6717DC00453B6A /* NSNumber+CogSort.m in Sources */ = {isa = PBXBuildFile; fileRef = 56DB084B0D6717DC00453B6A /* NSNumber+CogSort.m */; };
56DB08550D67185300453B6A /* NSArray+CogSort.m in Sources */ = {isa = PBXBuildFile; fileRef = 56DB08540D67185300453B6A /* NSArray+CogSort.m */; };
@ -625,6 +626,8 @@
56462EB00D634206000AB68C /* SpotlightPlaylistController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpotlightPlaylistController.h; path = Spotlight/SpotlightPlaylistController.h; sourceTree = "<group>"; };
56462EB10D634206000AB68C /* SpotlightPlaylistController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpotlightPlaylistController.m; path = Spotlight/SpotlightPlaylistController.m; sourceTree = "<group>"; };
566D32160D538550004466A5 /* APL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = APL.xcodeproj; path = Plugins/APL/APL.xcodeproj; sourceTree = "<group>"; };
56AE86BF0D6901BC00B0F89B /* FontSizetoLineHeightTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontSizetoLineHeightTransformer.h; sourceTree = "<group>"; };
56AE86C00D6901BC00B0F89B /* FontSizetoLineHeightTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FontSizetoLineHeightTransformer.m; sourceTree = "<group>"; };
56C63D8F0D647DF300EAE25A /* NSComparisonPredicate+CogPredicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSComparisonPredicate+CogPredicate.h"; path = "Spotlight/NSComparisonPredicate+CogPredicate.h"; sourceTree = "<group>"; };
56C63D900D647DF300EAE25A /* NSComparisonPredicate+CogPredicate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSComparisonPredicate+CogPredicate.m"; path = "Spotlight/NSComparisonPredicate+CogPredicate.m"; sourceTree = "<group>"; };
56DB084A0D6717DC00453B6A /* NSNumber+CogSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSNumber+CogSort.h"; path = "Spotlight/NSNumber+CogSort.h"; sourceTree = "<group>"; };
@ -859,6 +862,8 @@
07E18DF20D62B38400BB0E11 /* NSArray+ShuffleUtils.m */,
17E78CAF0D68D46F005C5A59 /* StringToURLTransformer.h */,
17E78CB00D68D46F005C5A59 /* StringToURLTransformer.m */,
56AE86BF0D6901BC00B0F89B /* FontSizetoLineHeightTransformer.h */,
56AE86C00D6901BC00B0F89B /* FontSizetoLineHeightTransformer.m */,
);
path = Utils;
sourceTree = "<group>";
@ -1688,6 +1693,7 @@
17211A780D68B79700911CA9 /* PathNode.m in Sources */,
17211A790D68B79700911CA9 /* SmartFolderNode.m in Sources */,
17E78CB10D68D46F005C5A59 /* StringToURLTransformer.m in Sources */,
56AE86C10D6901BC00B0F89B /* FontSizetoLineHeightTransformer.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

File diff suppressed because it is too large Load Diff

View File

@ -22,27 +22,20 @@
{
[[self menu] setAutoenablesItems:NO];
NSControlSize s = NSSmallControlSize;
NSEnumerator *oe = [[self tableColumns] objectEnumerator];
NSControlSize s = NSSmallControlSize;
NSFont *f = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:s]];
NSFont *bf = [[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[self setRowHeight:[layoutManager defaultLineHeightForFont:bf]];
[layoutManager release];
//Resize the fonts
id c;
while (c = [oe nextObject])
// NSFont *bf = [[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask];
for(NSTableColumn *col in [self tableColumns])
{
[[c dataCell] setControlSize:s];
//Using the bold font defined from the default system font with the bold trait added seems to fix problems related to bold display with some fonts.
[[c dataCell] setFont:bf];
[[col dataCell] setControlSize:s];
[[col dataCell] setFont:f];
[col bind:@"fontSize"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.fontSize"
options:nil];
}
[[NSFontManager sharedFontManager] setSelectedFont:bf isMultiple:NO];
NSTableHeaderView *currentTableHeaderView = [self headerView];
PlaylistHeaderView *customTableHeaderView = [[PlaylistHeaderView alloc] init];

File diff suppressed because it is too large Load Diff

View File

@ -11,18 +11,4 @@
@implementation SpotlightPlaylistView
- (void)awakeFromNib
{
[super awakeFromNib];
// We don't want the font to be bold
NSFontManager *fontManager = [NSFontManager sharedFontManager];
for(NSTableColumn *c in self.tableColumns)
{
[c.dataCell setFont:[fontManager convertFont:[c.dataCell font]
toHaveTrait:NSUnboldFontMask]];
}
}
@end

View File

@ -0,0 +1,14 @@
//
// FontSizetoLineHeightTransformer.h
// Cog
//
// Created by Matthew Grinshpun on 18/02/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface FontSizetoLineHeightTransformer : NSValueTransformer {}
@end

View File

@ -0,0 +1,34 @@
//
// FontSizetoLineHeightTransformer.m
// Cog
//
// Created by Matthew Grinshpun on 18/02/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "FontSizetoLineHeightTransformer.h"
@implementation FontSizetoLineHeightTransformer
+ (void)initialize
{
NSValueTransformer *fontSizetoLineHeightTransformer =
[[[FontSizetoLineHeightTransformer alloc] init]autorelease];
[NSValueTransformer setValueTransformer:fontSizetoLineHeightTransformer
forName:@"FontSizetoLineHeightTransformer"];
}
+ (Class)transformedValueClass { return [NSNumber class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
// Convert from font size to height in playlist view
- (id)transformedValue:(id)value {
NSFont *font = [NSFont systemFontOfSize:[(NSNumber *)value floatValue]];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc]init];
float fRowSize = [layoutManager defaultLineHeightForFont:font];
[layoutManager release];
return [NSNumber numberWithFloat: fRowSize];
}
@end