This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathqtaskbarcontrol_mac.mm
92 lines (75 loc) · 2.41 KB
/
qtaskbarcontrol_mac.mm
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
#include "qtaskbarcontrol_mac.h"
#include <QtMacExtras>
#include <QLocale>
#import <AppKit/NSApplication.h>
#import <AppKit/NSImageView.h>
#import <AppKit/NSDockTile.h>
#import <AppKit/NSColor.h>
#import <AppKit/NSCIImageRep.h>
#import <AppKit/NSBezierPath.h>
@implementation TaskProgressView
- (void)setProgress:(double)value
{
_progress = value;
}
- (void)drawRect:(NSRect)rect
{
Q_UNUSED(rect)
NSRect bounds = [self bounds];
[[NSApp applicationIconImage] drawInRect:bounds
fromRect:NSZeroRect
operation:NSCompositeCopy
fraction:1.0];
NSRect progressRect = bounds;
progressRect.size.width *= 0.8;
progressRect.size.height *= 0.042;
progressRect.origin.x = (NSWidth(bounds) - NSWidth(progressRect)) / 2.0;
progressRect.origin.y = 1;
auto radius = progressRect.size.height / 2.0;
NSRect currentRect = progressRect;
currentRect.size.width = (currentRect.size.width - 2*radius) * _progress + 2*radius;
auto cBase = 0xce / 256.0f;
NSColor *baseColor = [NSColor colorWithRed:cBase green:cBase blue:cBase alpha:1.0f];
auto cFill = 0x4f / 256.0f;
NSColor *fillColor = [NSColor colorWithRed:cFill green:cFill blue:cFill alpha:1.0f];
NSBezierPath *basePath = [NSBezierPath bezierPath];
[basePath appendBezierPathWithRoundedRect:progressRect xRadius:radius yRadius:radius];
[baseColor setFill];
[basePath fill];
NSBezierPath *progressPath = [NSBezierPath bezierPath];
[progressPath appendBezierPathWithRoundedRect:currentRect xRadius:radius yRadius:radius];
[fillColor setFill];
[progressPath fill];
NSBezierPath *framePath = [NSBezierPath bezierPath];
[framePath appendBezierPathWithRoundedRect:progressRect xRadius:radius yRadius:radius];
[fillColor setStroke];
[framePath stroke];
}
@end
QTaskbarControlPrivate *QTaskbarControlPrivate::createPrivate(QTaskbarControl *)
{
return new QMacTaskbarControl{};
}
QMacTaskbarControl::QMacTaskbarControl() :
_taskView{[[TaskProgressView alloc] init]}
{}
QMacTaskbarControl::~QMacTaskbarControl()
{
[_taskView release];
}
void QMacTaskbarControl::setProgress(bool visible, double value)
{
[_taskView setProgress:value];
if (visible && value >= 0.0)
[[NSApp dockTile] setContentView:_taskView];
else
[[NSApp dockTile] setContentView:nil];
[[NSApp dockTile] display];
}
void QMacTaskbarControl::setCounter(bool visible, int value)
{
if(visible)
QtMac::setBadgeLabelText(QLocale().toString(value));
else
QtMac::setBadgeLabelText(QString());
}