OSDN Git Service

3a4097730c324fe2cc6082f3cbf737991205a615
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / progressmanager / progressmanager_mac.mm
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "progressmanager_p.h"
35
36 void Core::Internal::ProgressManagerPrivate::init()
37 {
38 }
39
40 void Core::Internal::ProgressManagerPrivate::cleanup()
41 {
42 }
43
44 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
45 #import <AppKit/NSDockTile.h>
46 #import <AppKit/NSApplication.h>
47 #import <AppKit/NSImageView.h>
48 #import <AppKit/NSCIImageRep.h>
49 #import <AppKit/NSBezierPath.h>
50 #import <AppKit/NSColor.h>
51 #import <Foundation/NSString.h>
52
53 @interface ApplicationProgressView : NSView {
54     int min;
55     int max;
56     int value;
57 }
58
59 + (ApplicationProgressView *)sharedProgressView;
60
61 - (void)setRangeMin:(int)v1 max:(int)v2;
62 - (void)setValue:(int)v;
63 - (void)updateBadge;
64
65 @end
66
67 static ApplicationProgressView *sharedProgressView = nil;
68
69 @implementation ApplicationProgressView
70
71 + (ApplicationProgressView *)sharedProgressView
72 {
73     if (sharedProgressView == nil) {
74         sharedProgressView = [[ApplicationProgressView alloc] init];
75     }
76     return sharedProgressView;
77 }
78
79 - (void)setRangeMin:(int)v1 max:(int)v2
80 {
81     min = v1;
82     max = v2;
83     [self updateBadge];
84 }
85
86 - (void)setValue:(int)v
87 {
88     value = v;
89     [self updateBadge];
90 }
91
92 - (void)updateBadge
93 {
94     [[NSApp dockTile] display];
95 }
96
97 - (void)drawRect:(NSRect)rect
98 {
99     Q_UNUSED(rect)
100     NSRect boundary = [self bounds];
101     [[NSApp applicationIconImage] drawInRect:boundary
102                                      fromRect:NSZeroRect
103                                     operation:NSCompositeCopy
104                                      fraction:1.0];
105     NSRect progressBoundary = boundary;
106     progressBoundary.size.height *= 0.13;
107     progressBoundary.size.width *= 0.8;
108     progressBoundary.origin.x = (NSWidth(boundary) - NSWidth(progressBoundary))/2.;
109     progressBoundary.origin.y = NSHeight(boundary)*0.13;
110
111     double range = max - min;
112     double percent = 0.50;
113     if (range != 0)
114         percent = (value - min) / range;
115     if (percent > 1)
116         percent = 1;
117     else if (percent < 0)
118         percent = 0;
119
120     NSRect currentProgress = progressBoundary;
121     currentProgress.size.width *= percent;
122     [[NSColor blackColor] setFill];
123     [NSBezierPath fillRect:progressBoundary];
124     [[NSColor lightGrayColor] setFill];
125     [NSBezierPath fillRect:currentProgress];
126     [[NSColor blackColor] setStroke];
127     [NSBezierPath strokeRect:progressBoundary];
128 }
129
130 @end
131
132 void Core::Internal::ProgressManagerPrivate::setApplicationLabel(const QString &text)
133 {
134     const char *utf8String = text.toUtf8().constData();
135     NSString *cocoaString = [[NSString alloc] initWithUTF8String:utf8String];
136     [[NSApp dockTile] setBadgeLabel:cocoaString];
137     [cocoaString release];
138 }
139
140 void Core::Internal::ProgressManagerPrivate::setApplicationProgressRange(int min, int max)
141 {
142     [[ApplicationProgressView sharedProgressView] setRangeMin:min max:max];
143 }
144
145 void Core::Internal::ProgressManagerPrivate::setApplicationProgressValue(int value)
146 {
147     [[ApplicationProgressView sharedProgressView] setValue:value];
148 }
149
150 void Core::Internal::ProgressManagerPrivate::setApplicationProgressVisible(bool visible)
151 {
152     if (visible) {
153         [[NSApp dockTile] setContentView:[ApplicationProgressView sharedProgressView]];
154     } else {
155         [[NSApp dockTile] setContentView:nil];
156     }
157     [[NSApp dockTile] display];
158 }
159
160 #else
161
162 void Core::Internal::ProgressManagerPrivate::setApplicationLabel(const QString &text)
163 {
164     Q_UNUSED(text)
165 }
166
167 void Core::Internal::ProgressManagerPrivate::setApplicationProgressRange(int min, int max)
168 {
169     Q_UNUSED(min)
170     Q_UNUSED(max)
171 }
172
173 void Core::Internal::ProgressManagerPrivate::setApplicationProgressValue(int value)
174 {
175     Q_UNUSED(value)
176 }
177
178 void Core::Internal::ProgressManagerPrivate::setApplicationProgressVisible(bool visible)
179 {
180     Q_UNUSED(visible)
181 }
182
183 #endif