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
|
#import "BBLiquidGlassBezelInterface.h"
@interface BBLiquidGlassBezelInterface () {
CGRect initialRect;
}
@end
@implementation BBLiquidGlassBezelInterface
- (void)dealloc {
// Remove KVO observers
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"QSLiquidGlassBezelApplyTint"];
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"QSAppearance1A"];
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"QSAppearance1T"];
}
- (id)init {
return [self initWithWindowNibName:@"BBLiquidGlassBezelInterface"];
}
- (void)windowDidLoad {
initialRect = centerRectInRect([[self window] frame], [[NSScreen mainScreen] frame]);
[super windowDidLoad];
QSWindow *window = (QSWindow *)[self window];
[window setLevel:NSPopUpMenuWindowLevel];
[window setBackgroundColor:[NSColor clearColor]];
[window setOpaque:NO];
[window setHideOffset:NSMakePoint(0, 0)];
[window setShowOffset:NSMakePoint(0, 0)];
[window setMovableByWindowBackground:NO];
[window setFastShow:YES];
[window setHasShadow:YES];
[window setFrame:standardRect display:YES];
NSArray *theControls = [NSArray arrayWithObjects:dSelector, aSelector, iSelector, nil];
for(QSSearchObjectView *theControl in theControls) {
QSObjectCell *theCell = [theControl cell];
[theControl setPreferredEdge:NSMinYEdge];
[(QSWindow *)[(theControl)->resultController window] setHideOffset:NSMakePoint(0, NSMinY([iSelector frame]))];
[(QSWindow *)[(theControl)->resultController window] setShowOffset:NSMakePoint(0, NSMinY([dSelector frame]))];
[theCell setBackgroundColor:[NSColor clearColor]];
[theCell setFont:[NSFont systemFontOfSize:11 weight:NSFontWeightLight]];
[theCell setCellRadiusFactor:32];
BOOL shouldApplyTint = [[NSUserDefaults standardUserDefaults] boolForKey:@"QSLiquidGlassBezelApplyTint"];
NSColor *userHighlightColor = [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1A"];
NSColor *userTextColor = shouldApplyTint ? [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1T"] : [NSColor textColor];
[theCell setHighlightColor: userHighlightColor ? userHighlightColor : [NSColor colorWithRed:1 green:1 blue:1 alpha:.15]];
[theCell setTextColor: userTextColor ? userTextColor : [NSColor textColor]];
[theCell setShowDetails:NO];
[theCell setState:NSControlStateValueOn];
[theCell setIconSize:QSSize128];
[theCell setImagePosition:NSImageAbove];
}
// Add KVO observers for preference changes
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"QSLiquidGlassBezelApplyTint" options:NSKeyValueObservingOptionNew context:nil];
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"QSAppearance1A" options:NSKeyValueObservingOptionNew context:nil];
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"QSAppearance1T" options:NSKeyValueObservingOptionNew context:nil];
[self contractWindow:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
[self updateColors];
}
- (void)updateColors {
NSArray *theControls = [NSArray arrayWithObjects:dSelector, aSelector, iSelector, nil];
BOOL shouldApplyTint = [[NSUserDefaults standardUserDefaults] boolForKey:@"QSLiquidGlassBezelApplyTint"];
NSColor *userHighlightColor = [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1A"];
NSColor *userTextColor = shouldApplyTint ? [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1T"] : [NSColor textColor];
for(QSSearchObjectView *theControl in theControls) {
QSObjectCell *theCell = [theControl cell];
[theCell setHighlightColor: userHighlightColor ? userHighlightColor : [NSColor colorWithRed:1 green:1 blue:1 alpha:.15]];
[theCell setTextColor: userTextColor ? userTextColor : [NSColor textColor]];
@try {
[theCell setValue:@(NO) forKey:@"stylesLoaded"];
} @catch (NSException *exception) {
// We couldn't update. Ignore for now.p
}
[theControl setNeedsDisplay:YES];
}
}
- (NSSize) maxIconSize {
return QSSize32;
}
- (void)showMainWindow:(id)sender {
[[self window] setFrame:[self rectForState:[self expanded]] display:YES];
if ([[self window] isVisible]) [[self window] pulse:self];
[super showMainWindow:sender];
// Does this need to be here?
[[[self window] contentView] setNeedsDisplay:YES];
}
- (void)expandWindow:(id)sender {
if (![self expanded])
[[self window] setFrame:[self rectForState:YES] display:YES animate:YES];
[super expandWindow:sender];
}
- (void)contractWindow:(id)sender {
if ([self expanded])
[[self window] setFrame:[self rectForState:NO] display:YES animate:YES];
[super contractWindow:sender];
}
- (NSRect)rectForState:(BOOL)shouldExpand {
NSRect newRect = initialRect;
NSRect screenRect = [[NSScreen mainScreen] frame];
if (!shouldExpand) {
newRect.size.width -= 192;
}
return NSOffsetRect(centerRectInRect(newRect, screenRect), 0, (NSHeight(screenRect) / 5));
}
- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect {
return NSOffsetRect(NSInsetRect(rect, 8, 0), 0, 0);
}
- (NSTimeInterval)animationResizeTime:(NSRect)newWindowFrame {
return 0.01;
}
- (IBAction)customize:(id)sender{
[[NSClassFromString(@"QSPreferencesController") sharedInstance] showPaneWithIdentifier:@"BBLiquidGlassBezelPrefs"];
}
@end
|