Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
#20 use NSTextField instead of NSTextView
Browse files Browse the repository at this point in the history
- add QMBorderedView
- fix test
- add settings[XYZ]
  • Loading branch information
Tae Won Ha committed Jan 12, 2014
1 parent 9b1bd6e commit 630459b
Show file tree
Hide file tree
Showing 11 changed files with 1,262 additions and 1,231 deletions.
8 changes: 8 additions & 0 deletions Qmind.xcodeproj/project.pbxproj
Expand Up @@ -20,6 +20,7 @@
1929B36A99C420734C86E3CE /* QMCellPropertiesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929BBD6539D9FDEC76E6137 /* QMCellPropertiesManager.m */; };
1929B3A02CC1561045BF1FEC /* QMCellPropertiesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929BBD6539D9FDEC76E6137 /* QMCellPropertiesManager.m */; };
1929B3DBFDDCED6A832EBA6B /* ToolbarZoomOutTemplate@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1929B38391793C25EF358118 /* ToolbarZoomOutTemplate@2x.png */; };
1929B4013A5FFD5A6E6DF6F9 /* QMBorderedView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B5877760CCBAFC69427F /* QMBorderedView.m */; };
1929B502755E4F47D5612FA2 /* ToolbarDeleteNodeTemplate@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1929B7F07C814229B2270D34 /* ToolbarDeleteNodeTemplate@2x.png */; };
1929B5884D28A022A0F52F48 /* QMIdGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929BB6573724B1C6F3E369C /* QMIdGenerator.m */; };
1929B676F4A74F9E9F96AB42 /* QMIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929BA02C47D9D0A43F49EFA /* QMIcon.m */; };
Expand Down Expand Up @@ -52,6 +53,7 @@
4B39307A14EC418900A9D541 /* QMMindmapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B39307914EC418900A9D541 /* QMMindmapView.m */; };
4B396DD614F7E446000C7B36 /* dummy.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4BFCD7AC14F3E32A00850936 /* dummy.pdf */; };
4B521D9C17A54EB600153278 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4B521D9B17A54EB600153278 /* fontawesome-webfont.ttf */; };
4B551D8B1882A448007A16D6 /* QMBorderedView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B5877760CCBAFC69427F /* QMBorderedView.m */; };
4B5CB60A15E1187500E05BD7 /* QMAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCD74E14F3D33600850924 /* QMAppDelegate.m */; };
4B5CB60B15E1187500E05BD7 /* QMAppSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B85653514E46D6800C6FF26 /* QMAppSettings.m */; };
4B5CB60C15E1187500E05BD7 /* QMUiDrawer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B20B51839B9482813969 /* QMUiDrawer.m */; };
Expand Down Expand Up @@ -372,13 +374,15 @@
1929B20B51839B9482813969 /* QMUiDrawer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMUiDrawer.m; sourceTree = "<group>"; };
1929B2B42279F40C0CE08187 /* QMIdGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMIdGenerator.h; sourceTree = "<group>"; };
1929B2FCB4A407CCC68D9D45 /* QMIconsPaneView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMIconsPaneView.m; sourceTree = "<group>"; };
1929B302EBBFF24DFC769829 /* QMBorderedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMBorderedView.h; sourceTree = "<group>"; };
1929B353C299640D7D91AA9D /* QMCellSizeManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMCellSizeManager.m; sourceTree = "<group>"; };
1929B38391793C25EF358118 /* ToolbarZoomOutTemplate@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "ToolbarZoomOutTemplate@2x.png"; path = "Resources/ToolbarZoomOutTemplate@2x.png"; sourceTree = "<group>"; };
1929B3AAAFA6CF293F45F812 /* QMLookUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMLookUtil.m; sourceTree = "<group>"; };
1929B43F698543362E51BAB9 /* QMManualBeanProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMManualBeanProvider.m; sourceTree = "<group>"; };
1929B49C1022861E4672965B /* QMCellPropertiesManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMCellPropertiesManager.h; sourceTree = "<group>"; };
1929B4E814EA183B1791462A /* QMUiDrawer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMUiDrawer.h; sourceTree = "<group>"; };
1929B5323A40ED9F3A4A04BE /* ToolbarZoomInTemplate@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "ToolbarZoomInTemplate@2x.png"; path = "Resources/ToolbarZoomInTemplate@2x.png"; sourceTree = "<group>"; };
1929B5877760CCBAFC69427F /* QMBorderedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMBorderedView.m; sourceTree = "<group>"; };
1929B5969C8028EF888FAA7C /* QMIconsPaneView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMIconsPaneView.h; sourceTree = "<group>"; };
1929B5A9AAEC82B9CE22DFA2 /* QMCellSizeManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMCellSizeManager.h; sourceTree = "<group>"; };
1929B743A0D8FAB8C620E299 /* IconCollectionViewItemTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IconCollectionViewItemTest.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -640,6 +644,8 @@
4B85653514E46D6800C6FF39 /* QMMindmapViewDataSource.h */,
4B39307814EC418900A9D541 /* QMMindmapView.h */,
4B39307914EC418900A9D541 /* QMMindmapView.m */,
1929B5877760CCBAFC69427F /* QMBorderedView.m */,
1929B302EBBFF24DFC769829 /* QMBorderedView.h */,
);
name = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -1226,6 +1232,7 @@
1929BB6FEB32F64962B24562 /* QMManualBeanProvider.m in Sources */,
1929B32033377AB1DF3E6675 /* QMCellPropertiesManager.m in Sources */,
1929B5884D28A022A0F52F48 /* QMIdGenerator.m in Sources */,
1929B4013A5FFD5A6E6DF6F9 /* QMBorderedView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1265,6 +1272,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4B551D8B1882A448007A16D6 /* QMBorderedView.m in Sources */,
4B6BC4B516AF303B00F24572 /* QMManualBeanProvider.m in Sources */,
4B1752D416A48B01002FAFC4 /* MindmapReaderTest.m in Sources */,
4B12E236168CC34900D972BE /* QMIconTest.m in Sources */,
Expand Down
53 changes: 0 additions & 53 deletions Qmind.xcodeproj/xcshareddata/xcschemes/QmindSenTesting.xcscheme

This file was deleted.

1 change: 1 addition & 0 deletions Qmind/QMAppSettings.h
Expand Up @@ -60,6 +60,7 @@ extern NSString * const qSettingCellVerticalPadding;
* General getter for a setting. When the result is a number, an NSNumber is returned.
*/
- (id)settingForKey:(NSString *)key;
- (id)objectForKeyedSubscript:(id)key;

/**
* If you want to access CGFloat values, for example folding marker radius, use this method.
Expand Down
143 changes: 74 additions & 69 deletions Qmind/QMAppSettings.m
Expand Up @@ -55,7 +55,7 @@
static const NSUInteger qSpaceCharacter = 0x20;

static inline NSCharacterSet *single_key_charset(NSUInteger charCode) {
return [NSCharacterSet characterSetWithRange:NSMakeRange(charCode, 1)];
return [NSCharacterSet characterSetWithRange:NSMakeRange(charCode, 1)];
}


Expand All @@ -70,109 +70,114 @@ @implementation QMAppSettings

#pragma mark Public
- (id)settingForKey:(NSString *)key {
return self.settingsDict[key];
return self.settingsDict[key];
}

- (id)objectForKeyedSubscript:(id)key {
return [self settingForKey:key];
}


- (CGFloat)floatForKey:(NSString *)key {
return (CGFloat) [self.settingsDict[key] floatValue];
return (CGFloat) [self.settingsDict[key] floatValue];
}

#pragma mark NSObject
- (id)init {
self = [super init];
if (self) {
[self initSettingsDict];
}
self = [super init];
if (self) {
[self initSettingsDict];
}

return self;
return self;
}

#pragma mark Private
- (void)initSettingsDict {
NSFont *defaultFont = [NSFont fontWithName:@"Helvetica" size:12.0];
NSMutableDictionary *attrDict = [[NSMutableDictionary alloc] initWithCapacity:2];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
NSFont *defaultFont = [NSFont fontWithName:@"Helvetica" size:12.0];
NSMutableDictionary *attrDict = [[NSMutableDictionary alloc] initWithCapacity:2];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];

NSFont *fontawesomeFont = [self fontawesomeFont];
NSFont *fontawesomeFont = [self fontawesomeFont];

[style setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
[style setAlignment:NSLeftTextAlignment];
[style setLineBreakMode:NSLineBreakByWordWrapping];
[style setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
[style setAlignment:NSLeftTextAlignment];
[style setLineBreakMode:NSLineBreakByWordWrapping];

attrDict[NSParagraphStyleAttributeName] = style;
attrDict[NSFontAttributeName] = defaultFont;
attrDict[NSParagraphStyleAttributeName] = style;
attrDict[NSFontAttributeName] = defaultFont;

_settingsDict = [[NSMutableDictionary alloc] initWithDictionary:@{
qSettingDefaultFont : defaultFont,
qSettingDefaultParagraphStyle : style,
qSettingDefaultStringAttributeDict : attrDict,
qSettingIconFont : [NSFont fontWithName:@"Apple Color Emoji" size:14],
qSettingBackgroundColor : [NSColor whiteColor],
_settingsDict = [[NSMutableDictionary alloc] initWithDictionary:@{
qSettingDefaultFont : defaultFont,
qSettingDefaultParagraphStyle : style,
qSettingDefaultStringAttributeDict : attrDict,
qSettingIconFont : [NSFont fontWithName:@"Apple Color Emoji" size:14],
qSettingBackgroundColor : [NSColor whiteColor],

qSettingInternodeHorizontalDistance : @30,
qSettingInternodeVerticalDistance : @7.5,
qSettingInternodeLineWidth : @1,
qSettingInternodeHorizontalDistance : @30,
qSettingInternodeVerticalDistance : @7.5,
qSettingInternodeLineWidth : @1,

qSettingNodeEditMinWidth : @200,
qSettingNodeEditMinHeight : @9,
qSettingNodeEditMaxWidth : @640,
qSettingNodeEditMinWidth : @200,
qSettingNodeEditMinHeight : @9,
qSettingNodeEditMaxWidth : @640,

qSettingNodeMinWidth : @100,
qSettingNodeMinHeight : @14,
qSettingNodeMinWidth : @100,
qSettingNodeMinHeight : @14,

qSettingFoldingMarkerRadius : @6,
qSettingFoldingMarkerLineWidth : @1,
qSettingFoldingMarkerRadius : @6,
qSettingFoldingMarkerLineWidth : @1,

qSettingMaxTextNodeWidth : @640,
qSettingMaxRootCellTextWidth : @400,
qSettingMaxTextNodeWidth : @640,
qSettingMaxRootCellTextWidth : @400,

qSettingMindMapViewMargin : @20,
qSettingMindMapViewMargin : @20,

qSettingNodeFocusRingMargin : @0,
qSettingNodeFocusRingBorderRadius : @2,
qSettingNodeFocusRingMargin : @0,
qSettingNodeFocusRingBorderRadius : @2,

qSettingBezierControlPoint1 : @20,
qSettingBezierControlPoint2 : @15,
qSettingBezierControlPoint1 : @20,
qSettingBezierControlPoint2 : @15,

qSettingDefaultNewNodeWidth : @100,
qSettingDefaultNewNodeWidth : @100,

qSettingCellHorizontalPadding : @3,
qSettingCellVerticalPadding : @3,
qSettingCellHorizontalPadding : @3,
qSettingCellVerticalPadding : @3,

qSettingIconTextDistance : @5,
qSettingInterIconDistance : @3,
qSettingIconDrawSize : @16,
qSettingIconTextDistance : @5,
qSettingInterIconDistance : @3,
qSettingIconDrawSize : @16,

qSettingLinkIconFont: fontawesomeFont,
qSettingLinkIconDrawSize : @16,
qSettingLinkIconHorizontalMargin : @3,
qSettingLinkIconFont : fontawesomeFont,
qSettingLinkIconDrawSize : @16,
qSettingLinkIconHorizontalMargin : @3,

qSettingNewChildNodeChars : single_key_charset(NSTabCharacter),
qSettingNewLeftChildNodeChars : single_key_charset(NSBackTabCharacter),
qSettingEditSelectedNodeChars : single_key_charset(NSCarriageReturnCharacter),
qSettingNewSiblingNodeChars : single_key_charset(NSCarriageReturnCharacter),
qSettingDeleteNodeChars : single_key_charset(NSDeleteFunctionKey),
qSettingDeselectCell : single_key_charset(qEscCharacter),
qSettingFoldingChars : single_key_charset(qSpaceCharacter),
}];
qSettingNewChildNodeChars : single_key_charset(NSTabCharacter),
qSettingNewLeftChildNodeChars : single_key_charset(NSBackTabCharacter),
qSettingEditSelectedNodeChars : single_key_charset(NSCarriageReturnCharacter),
qSettingNewSiblingNodeChars : single_key_charset(NSCarriageReturnCharacter),
qSettingDeleteNodeChars : single_key_charset(NSDeleteFunctionKey),
qSettingDeselectCell : single_key_charset(qEscCharacter),
qSettingFoldingChars : single_key_charset(qSpaceCharacter),
}];
}

- (NSFont *)fontawesomeFont {
NSString *fontPath = [[NSBundle bundleForClass:self.class] pathForResource:@"fontawesome-webfont" ofType:@"ttf"];
NSData *fontData = [[NSData alloc] initWithContentsOfFile:fontPath];
NSString *fontPath = [[NSBundle bundleForClass:self.class] pathForResource:@"fontawesome-webfont" ofType:@"ttf"];
NSData *fontData = [[NSData alloc] initWithContentsOfFile:fontPath];

CGDataProviderRef fontDataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef) fontData);
CGFontRef cgFont = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef) fontData);
CGFontRef cgFont = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);

// if we pass NULL for attributes, we crash when releasing the font descriptor
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef) @{});
CTFontRef ctFont = CTFontCreateWithGraphicsFont(cgFont, 0, NULL, fontDescriptor);
CFRelease(fontDescriptor);
CGFontRelease(cgFont);
// if we pass NULL for attributes, we crash when releasing the font descriptor
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef) @{});
CTFontRef ctFont = CTFontCreateWithGraphicsFont(cgFont, 0, NULL, fontDescriptor);
CFRelease(fontDescriptor);
CGFontRelease(cgFont);

NSFont *fontawesomeFont = (__bridge_transfer NSFont *) ctFont;
return fontawesomeFont;
NSFont *fontawesomeFont = (__bridge_transfer NSFont *) ctFont;
return fontawesomeFont;
}

@end
17 changes: 17 additions & 0 deletions Qmind/QMBorderedView.h
@@ -0,0 +1,17 @@
/**
* Tae Won Ha — @hataewon
*
* http://taewon.de
* http://qvacua.com
*
* See LICENSE
*/

#import <Cocoa/Cocoa.h>


@interface QMBorderedView : NSView

@property CGFloat borderWidth;

@end
60 changes: 60 additions & 0 deletions Qmind/QMBorderedView.m
@@ -0,0 +1,60 @@
/**
* Tae Won Ha — @hataewon
*
* http://taewon.de
* http://qvacua.com
*
* See LICENSE
*/

#import "QMBorderedView.h"
#import <Qkit/Qkit.h>


@interface QMBorderedView ()

@property NSBezierPath *borderPath;

@end

@implementation QMBorderedView

#pragma mark NSView
- (void)setFrame:(NSRect)frameRect {
self.borderPath = [NSBezierPath bezierPathWithRect:NewRectWithSize(0, 0, frameRect.size)];
self.borderPath.lineWidth = self.borderWidth;

[super setFrame:frameRect];
}

- (void)drawRect:(NSRect)dirtyRect {
[NSGraphicsContext saveGraphicsState];
{
[[NSColor grayColor] setStroke];
[[NSColor whiteColor] setFill];

[self.borderPath fill];
[self.borderPath stroke];
}
[NSGraphicsContext restoreGraphicsState];

[super drawRect:dirtyRect];
}

- (id)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if (self) {
_borderWidth = 1;

_borderPath = [NSBezierPath bezierPathWithRect:frameRect];
_borderPath.lineWidth = _borderWidth;
}

return self;
}

- (BOOL)isFlipped {
return YES;
}

@end

0 comments on commit 630459b

Please sign in to comment.