1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "progressmanager_p.h"
36 void Core::Internal::ProgressManagerPrivate::init()
40 void Core::Internal::ProgressManagerPrivate::cleanup()
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>
53 @interface ApplicationProgressView : NSView {
59 + (ApplicationProgressView *)sharedProgressView;
61 - (void)setRangeMin:(int)v1 max:(int)v2;
62 - (void)setValue:(int)v;
67 static ApplicationProgressView *sharedProgressView = nil;
69 @implementation ApplicationProgressView
71 + (ApplicationProgressView *)sharedProgressView
73 if (sharedProgressView == nil) {
74 sharedProgressView = [[ApplicationProgressView alloc] init];
76 return sharedProgressView;
79 - (void)setRangeMin:(int)v1 max:(int)v2
86 - (void)setValue:(int)v
94 [[NSApp dockTile] display];
97 - (void)drawRect:(NSRect)rect
100 NSRect boundary = [self bounds];
101 [[NSApp applicationIconImage] drawInRect:boundary
103 operation:NSCompositeCopy
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;
111 double range = max - min;
112 double percent = 0.50;
114 percent = (value - min) / range;
117 else if (percent < 0)
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];
132 void Core::Internal::ProgressManagerPrivate::setApplicationLabel(const QString &text)
134 const char *utf8String = text.toUtf8().constData();
135 NSString *cocoaString = [[NSString alloc] initWithUTF8String:utf8String];
136 [[NSApp dockTile] setBadgeLabel:cocoaString];
137 [cocoaString release];
140 void Core::Internal::ProgressManagerPrivate::setApplicationProgressRange(int min, int max)
142 [[ApplicationProgressView sharedProgressView] setRangeMin:min max:max];
145 void Core::Internal::ProgressManagerPrivate::setApplicationProgressValue(int value)
147 [[ApplicationProgressView sharedProgressView] setValue:value];
150 void Core::Internal::ProgressManagerPrivate::setApplicationProgressVisible(bool visible)
153 [[NSApp dockTile] setContentView:[ApplicationProgressView sharedProgressView]];
155 [[NSApp dockTile] setContentView:nil];
157 [[NSApp dockTile] display];
162 void Core::Internal::ProgressManagerPrivate::setApplicationLabel(const QString &text)
167 void Core::Internal::ProgressManagerPrivate::setApplicationProgressRange(int min, int max)
173 void Core::Internal::ProgressManagerPrivate::setApplicationProgressValue(int value)
178 void Core::Internal::ProgressManagerPrivate::setApplicationProgressVisible(bool visible)