Changeset 30188 in vbox
- Timestamp:
- Jun 15, 2010 9:06:21 AM (14 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 1 added
- 4 edited
- 2 moved
-
Makefile.kmk (modified) (2 diffs)
-
src/VBoxVMLogViewer.cpp (modified) (1 diff)
-
src/darwin/UICocoaSpecialControls.h (moved) (moved from trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaSpecialControls.h ) (5 diffs)
-
src/darwin/UICocoaSpecialControls.mm (moved) (moved from trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaSpecialControls.mm ) (8 diffs)
-
src/widgets/UISpacerWidgets.h (added)
-
src/widgets/VBoxSpecialControls.cpp (modified) (5 diffs)
-
src/widgets/VBoxSpecialControls.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r30122 r30188 322 322 src/widgets/VBoxSpecialControls.h \ 323 323 src/widgets/VBoxWarningPane.h \ 324 src/widgets/UISpacerWidgets.h \ 324 325 src/runtime/UISession.h \ 325 326 src/runtime/UIActionsPool.h \ … … 526 527 src/darwin/UICocoaApplication.mm \ 527 528 src/darwin/VBoxUtils-darwin-cocoa.mm \ 528 src/darwin/ VBoxCocoaSpecialControls.mm529 src/darwin/UICocoaSpecialControls.mm 529 530 VirtualBox_QT_MOCHDRS.darwin = \ 530 src/darwin/ VBoxCocoaSpecialControls.h531 src/darwin/UICocoaSpecialControls.h 531 532 endif 532 533 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMLogViewer.cpp
r29972 r30188 359 359 mButtonsNextPrev = new VBoxSegmentedButton (2, this); 360 360 mButtonsNextPrev->setEnabled (0, false); 361 mButtonsNextPrev->setEnabled (1, false); 362 #ifndef Q_WS_MAC 363 /* No icons on the Mac */ 361 364 mButtonsNextPrev->setIcon (0, VBoxGlobal::iconSet (":/list_movedown_16px.png", 362 365 ":/list_movedown_disabled_16px.png")); 363 mButtonsNextPrev->setEnabled (1, false);364 366 mButtonsNextPrev->setIcon (1, VBoxGlobal::iconSet (":/list_moveup_16px.png", 365 367 ":/list_moveup_disabled_16px.png")); 368 #endif /* !Q_WS_MAC */ 366 369 connect (mButtonsNextPrev, SIGNAL (clicked (int)), this, SLOT (find (int))); 367 370 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaSpecialControls.h
r30187 r30188 6 6 7 7 /* 8 * Copyright (C) 2009 Oracle Corporation8 * Copyright (C) 2009-2010 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 */ 18 18 19 #ifndef ___darwin_ VBoxCocoaSpecialControls_h__20 #define ___darwin_ VBoxCocoaSpecialControls_h__19 #ifndef ___darwin_UICocoaSpecialControls_h__ 20 #define ___darwin_UICocoaSpecialControls_h__ 21 21 22 22 /* VBox includes */ … … 24 24 25 25 /* Qt includes */ 26 #include <QMacCocoaViewContainer> 26 #include <QWidget> 27 28 /* Qt forward includes */ 29 class QMacCocoaViewContainer; 27 30 28 31 /* Add typedefs for Cocoa types */ 29 ADD_COCOA_NATIVE_REF (NSButton);30 ADD_COCOA_NATIVE_REF (NSSegmentedControl);31 ADD_COCOA_NATIVE_REF (NSSearchField);32 ADD_COCOA_NATIVE_REF(NSButton); 33 ADD_COCOA_NATIVE_REF(NSSegmentedControl); 34 ADD_COCOA_NATIVE_REF(NSSearchField); 32 35 33 class VBoxCocoaButton: public QMacCocoaViewContainer 36 class UICocoaWrapper: public QWidget 37 { 38 public: 39 UICocoaWrapper(QWidget *pParent = 0); 40 41 protected: 42 virtual void resizeEvent(QResizeEvent *pEvent); 43 44 QMacCocoaViewContainer *m_pContainer; 45 }; 46 47 class UICocoaButton: public UICocoaWrapper 34 48 { 35 49 Q_OBJECT … … 43 57 }; 44 58 45 VBoxCocoaButton (CocoaButtonType aType, QWidget *aParent = 0);46 ~ VBoxCocoaButton();59 UICocoaButton(CocoaButtonType aType, QWidget *pParent = 0); 60 ~UICocoaButton(); 47 61 48 62 QSize sizeHint() const; 49 63 50 void setText (const QString& aText);51 void setToolTip (const QString& aTip);64 void setText(const QString& strText); 65 void setToolTip(const QString& strTip); 52 66 53 67 void onClicked(); 54 68 55 69 signals: 56 void clicked (bool checked = false); 57 58 protected: 59 void resizeEvent(QResizeEvent *pEvent); 70 void clicked(bool fChecked = false); 60 71 61 72 private: 62 73 /* Private member vars */ 63 NativeNSButtonRef m NativeRef;74 NativeNSButtonRef m_pNativeRef; 64 75 }; 65 76 66 class VBoxCocoaSegmentedButton: public QMacCocoaViewContainer77 class UICocoaSegmentedButton: public UICocoaWrapper 67 78 { 68 79 Q_OBJECT 69 80 70 81 public: 71 VBoxCocoaSegmentedButton (int aCount, QWidget *aParent = 0); 72 ~VBoxCocoaSegmentedButton(); 82 enum CocoaSegmentType 83 { 84 RoundRectSegment, 85 TexturedRoundedSegment 86 }; 87 88 UICocoaSegmentedButton(int count, CocoaSegmentType type = RoundRectSegment, QWidget *pParent = 0); 89 ~UICocoaSegmentedButton(); 73 90 74 91 QSize sizeHint() const; 75 92 76 void setTitle (int aSegment, const QString &aTitle); 93 void setTitle(int iSegment, const QString &strTitle); 94 void setToolTip(int iSegment, const QString &strTip); 95 void setIcon(int iSegment, const QIcon& icon); 96 void setEnabled(int iSegment, bool fEnabled); 77 97 78 void setToolTip (int aSegment, const QString &aTip); 79 80 void setEnabled (int aSegment, bool fEnabled); 81 82 void animateClick (int aSegment); 83 84 void onClicked (int aSegment); 98 void animateClick(int iSegment); 99 void onClicked(int iSegment); 85 100 86 101 signals: 87 void clicked (int aSegment, bool aChecked = false);102 void clicked(int iSegment, bool fChecked = false); 88 103 89 104 private: 90 105 /* Private member vars */ 91 NativeNSSegmentedControlRef m NativeRef;106 NativeNSSegmentedControlRef m_pNativeRef; 92 107 }; 93 108 94 class VBoxCocoaSearchField: public QMacCocoaViewContainer109 class UICocoaSearchField: public UICocoaWrapper 95 110 { 96 111 Q_OBJECT 97 112 98 113 public: 99 VBoxCocoaSearchField (QWidget* aParent = 0);100 ~ VBoxCocoaSearchField();114 UICocoaSearchField(QWidget* pParent = 0); 115 ~UICocoaSearchField(); 101 116 102 117 QSize sizeHint() const; 103 118 104 119 QString text() const; 105 void insert (const QString &aText);106 void setToolTip (const QString &aTip);120 void insert(const QString &strText); 121 void setToolTip(const QString &strTip); 107 122 void selectAll(); 108 123 … … 110 125 void unmarkError(); 111 126 112 void onTextChanged (const QString &aText);127 void onTextChanged(const QString &strText); 113 128 114 129 signals: 115 void textChanged (const QString& aText);130 void textChanged(const QString& strText); 116 131 117 132 private: 118 133 /* Private member vars */ 119 NativeNSSearchFieldRef m NativeRef;134 NativeNSSearchFieldRef m_pNativeRef; 120 135 }; 121 136 122 #endif /* ___darwin_ VBoxCocoaSpecialControls_h__ */137 #endif /* ___darwin_UICocoaSpecialControls_h__ */ 123 138 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaSpecialControls.mm
r30187 r30188 3 3 * 4 4 * VBox frontends: Qt GUI ("VirtualBox"): 5 * VBoxCocoaSpecialControls implementation5 * UICocoaSpecialControls implementation 6 6 */ 7 7 … … 19 19 20 20 /* VBox includes */ 21 #include "VBoxCocoaSpecialControls.h" 21 #include "UICocoaSpecialControls.h" 22 #include "VBoxUtils-darwin.h" 22 23 #include <VBox/cdefs.h> 23 24 24 25 /* System includes */ 26 #import <AppKit/NSApplication.h> 27 #import <AppKit/NSBezierPath.h> 25 28 #import <AppKit/NSButton.h> 26 #import <AppKit/NS Application.h>29 #import <AppKit/NSFont.h> 27 30 #import <AppKit/NSImage.h> 28 #import <AppKit/NSFont.h>29 31 #import <AppKit/NSSegmentedControl.h> 30 #import <AppKit/NSBezierPath.h>31 32 32 33 /* Qt includes */ 33 34 #include <QApplication> 35 #include <QIcon> 34 36 #include <QKeyEvent> 35 36 @interface NSButtonTarget: NSObject 37 { 38 VBoxCocoaButton *mRealTarget; 39 } 40 -(id)initWithObject:(VBoxCocoaButton*)object; 37 #include <QMacCocoaViewContainer> 38 39 /* 40 * Private interfaces 41 */ 42 @interface UIButtonTargetPrivate: NSObject 43 { 44 UICocoaButton *mRealTarget; 45 } 46 -(id)initWithObject:(UICocoaButton*)object; 41 47 -(IBAction)clicked:(id)sender; 42 48 @end 43 49 44 @implementation NSButtonTarget 45 -(id)initWithObject:(VBoxCocoaButton*)object 50 @interface UISegmentedButtonTargetPrivate: NSObject 51 { 52 UICocoaSegmentedButton *mRealTarget; 53 } 54 -(id)initWithObject1:(UICocoaSegmentedButton*)object; 55 -(IBAction)segControlClicked:(id)sender; 56 @end 57 58 @interface UISearchFieldCellPrivate: NSSearchFieldCell 59 { 60 NSColor *mBGColor; 61 } 62 - (void)setBackgroundColor:(NSColor*)aBGColor; 63 @end 64 65 @interface UISearchFieldPrivate: NSSearchField 66 { 67 UICocoaSearchField *mRealTarget; 68 } 69 -(id)initWithObject2:(UICocoaSearchField*)object; 70 @end 71 72 #if MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_6 73 @interface UISearchFieldDelegatePrivate: NSObject<NSTextFieldDelegate> 74 #else 75 @interface UISearchFieldDelegatePrivate: NSObject 76 #endif 77 {} 78 @end 79 80 /* 81 * Implementation of the private interfaces 82 */ 83 @implementation UIButtonTargetPrivate 84 -(id)initWithObject:(UICocoaButton*)object 46 85 { 47 86 self = [super init]; … … 58 97 @end 59 98 60 @interface NSSegmentedButtonTarget: NSObject 61 { 62 VBoxCocoaSegmentedButton *mRealTarget; 63 } 64 -(id)initWithObject1:(VBoxCocoaSegmentedButton*)object; 99 @implementation UISegmentedButtonTargetPrivate 100 -(id)initWithObject1:(UICocoaSegmentedButton*)object 101 { 102 self = [super init]; 103 104 mRealTarget = object; 105 106 return self; 107 } 108 65 109 -(IBAction)segControlClicked:(id)sender; 66 @end 67 68 @implementation NSSegmentedButtonTarget 69 -(id)initWithObject1:(VBoxCocoaSegmentedButton*)object 110 { 111 mRealTarget->onClicked([sender selectedSegment]); 112 } 113 @end 114 115 @implementation UISearchFieldCellPrivate 116 -(id)init 117 { 118 if ((self = [super init])) 119 mBGColor = Nil; 120 return self; 121 } 122 123 - (void)dealloc 124 { 125 [mBGColor release]; 126 [super dealloc]; 127 } 128 129 - (void)setBackgroundColor:(NSColor*)aBGColor 130 { 131 if (mBGColor != aBGColor) 132 { 133 [mBGColor release]; 134 mBGColor = [aBGColor retain]; 135 } 136 } 137 138 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 139 { 140 if (mBGColor != Nil) 141 { 142 [mBGColor setFill]; 143 NSRect frame = cellFrame; 144 double radius = RT_MIN(NSWidth(frame), NSHeight(frame)) / 2.0; 145 [[NSBezierPath bezierPathWithRoundedRect:frame xRadius:radius yRadius:radius] fill]; 146 } 147 148 [super drawInteriorWithFrame:cellFrame inView:controlView]; 149 } 150 @end 151 152 @implementation UISearchFieldPrivate 153 + (Class)cellClass 154 { 155 return [UISearchFieldCellPrivate class]; 156 } 157 158 -(id)initWithObject2:(UICocoaSearchField*)object 70 159 { 71 160 self = [super init]; … … 73 162 mRealTarget = object; 74 163 75 return self;76 }77 78 -(IBAction)segControlClicked:(id)sender;79 {80 mRealTarget->onClicked([sender selectedSegment]);81 }82 @end83 84 @interface VBSearchField: NSSearchField85 {86 VBoxCocoaSearchField *mRealTarget;87 }88 -(id)initWithObject2:(VBoxCocoaSearchField*)object;89 @end90 91 @implementation VBSearchField92 -(id)initWithObject2:(VBoxCocoaSearchField*)object93 {94 self = [super init];95 96 mRealTarget = object;97 164 98 165 return self; … … 113 180 { 114 181 QKeyEvent ke(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); 115 QApplication::sendEvent (mRealTarget, &ke);182 QApplication::sendEvent(mRealTarget, &ke); 116 183 } 117 184 else if (ch == 27) /* Escape */ 118 185 { 119 186 QKeyEvent ke(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); 120 QApplication::sendEvent (mRealTarget, &ke);187 QApplication::sendEvent(mRealTarget, &ke); 121 188 } 122 189 else if (ch == NSF3FunctionKey) 123 190 { 124 191 QKeyEvent ke(QEvent::KeyPress, Qt::Key_F3, [theEvent modifierFlags] & NSShiftKeyMask ? Qt::ShiftModifier : Qt::NoModifier); 125 QApplication::sendEvent (mRealTarget, &ke);192 QApplication::sendEvent(mRealTarget, &ke); 126 193 } 127 194 … … 137 204 - (void)textDidChange:(NSNotification *)aNotification 138 205 { 139 mRealTarget->onTextChanged (::darwinNSStringToQString ([[aNotification object] string])); 140 } 141 @end 142 143 #if MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_6 144 @interface VBSearchFieldDelegate: NSObject<NSTextFieldDelegate> 145 #else 146 @interface VBSearchFieldDelegate: NSObject 147 #endif 148 {} 149 @end 150 @implementation VBSearchFieldDelegate 206 mRealTarget->onTextChanged(::darwinNSStringToQString([[aNotification object] string])); 207 } 208 @end 209 210 @implementation UISearchFieldDelegatePrivate 151 211 -(BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector 152 212 { 153 // NSLog (NSStringFromSelector(commandSelector));213 // NSLog(NSStringFromSelector(commandSelector)); 154 214 /* Don't execute the selector for Enter & Escape. */ 155 215 if ( commandSelector == @selector(insertNewline:) … … 160 220 @end 161 221 162 @interface VBSearchFieldCell: NSSearchFieldCell 163 { 164 NSColor *mBGColor; 165 } 166 - (void)setBackgroundColor:(NSColor*)aBGColor; 167 @end 168 169 @implementation VBSearchFieldCell 170 - (void)setBackgroundColor:(NSColor*)aBGColor 171 { 172 if (mBGColor != aBGColor) 173 { 174 [mBGColor release]; 175 mBGColor = [aBGColor retain]; 176 } 177 } 178 179 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 180 { 181 if (mBGColor) 182 { 183 [mBGColor setFill]; 184 NSRect frame = cellFrame; 185 frame.size.height -= 1; 186 frame.origin.y += 1; 187 double radius = RT_MIN(frame.size.width, frame.size.height) / 2.0; 188 [[NSBezierPath bezierPathWithRoundedRect:frame xRadius:radius yRadius:radius] fill]; 189 } 190 191 [super drawInteriorWithFrame:cellFrame inView:controlView]; 192 } 193 @end 194 195 NSRect darwinCenterRectVerticalTo (NSRect aRect, const NSRect& aToRect) 222 223 /* 224 * Helper functions 225 */ 226 NSRect darwinCenterRectVerticalTo(NSRect aRect, const NSRect& aToRect) 196 227 { 197 228 aRect.origin.y = (aToRect.size.height - aRect.size.height) / 2.0; … … 199 230 } 200 231 201 VBoxCocoaButton::VBoxCocoaButton (CocoaButtonType aType, QWidget *aParent /* = 0 */) 202 : QMacCocoaViewContainer (0, aParent) 203 { 204 setContentsMargins(0, 0, 0, 0); 232 QImage toGray(const QImage& image) 233 { 234 QImage result = image.convertToFormat(QImage::Format_ARGB32); 235 for (int i=0; i < result.height(); ++i) 236 { 237 QRgb *pScanLine = (QRgb *)result.scanLine(i); 238 for (int j=0; j < result.width(); ++j) 239 { 240 const int g = qGray(pScanLine[j]); 241 pScanLine[j] = qRgba(g, g, g, qAlpha(pScanLine[j])); 242 } 243 } 244 return result; 245 } 246 247 /* 248 * Public classes 249 */ 250 UICocoaWrapper::UICocoaWrapper(QWidget *pParent /* = 0 */) 251 : QWidget(pParent) 252 , m_pContainer(0) 253 { 254 } 255 256 void UICocoaWrapper::resizeEvent(QResizeEvent *pEvent) 257 { 258 if (m_pContainer) 259 m_pContainer->resize(pEvent->size()); 260 QWidget::resizeEvent(pEvent); 261 } 262 263 UICocoaButton::UICocoaButton(CocoaButtonType aType, QWidget *pParent /* = 0 */) 264 : UICocoaWrapper(pParent) 265 { 266 NSRect initFrame; 267 205 268 switch (aType) 206 269 { 207 270 case HelpButton: 208 271 { 209 m NativeRef = [[NSButton alloc] init];210 [m NativeRef setTitle: @""];211 [m NativeRef setBezelStyle: NSHelpButtonBezelStyle];212 [m NativeRef setBordered: YES];213 [m NativeRef setAlignment: NSCenterTextAlignment];214 [m NativeRef sizeToFit];215 NSRect frame = [mNativeRef frame];216 frame.size.width += 12; /* Margin */217 [m NativeRef setFrame:frame];272 m_pNativeRef = [[NSButton alloc] init]; 273 [m_pNativeRef setTitle: @""]; 274 [m_pNativeRef setBezelStyle: NSHelpButtonBezelStyle]; 275 [m_pNativeRef setBordered: YES]; 276 [m_pNativeRef setAlignment: NSCenterTextAlignment]; 277 [m_pNativeRef sizeToFit]; 278 initFrame = [m_pNativeRef frame]; 279 initFrame.size.width += 12; /* Margin */ 280 [m_pNativeRef setFrame:initFrame]; 218 281 break; 219 282 }; 220 283 case CancelButton: 221 284 { 222 mNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)]; 223 [mNativeRef setTitle: @""]; 224 [mNativeRef setBezelStyle:NSShadowlessSquareBezelStyle]; 225 [mNativeRef setButtonType:NSMomentaryChangeButton]; 226 [mNativeRef setImage: [NSImage imageNamed: NSImageNameStopProgressFreestandingTemplate]]; 227 [mNativeRef setBordered: NO]; 228 [[mNativeRef cell] setImageScaling: NSImageScaleProportionallyDown]; 285 m_pNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)]; 286 [m_pNativeRef setTitle: @""]; 287 [m_pNativeRef setBezelStyle:NSShadowlessSquareBezelStyle]; 288 [m_pNativeRef setButtonType:NSMomentaryChangeButton]; 289 [m_pNativeRef setImage: [NSImage imageNamed: NSImageNameStopProgressFreestandingTemplate]]; 290 [m_pNativeRef setBordered: NO]; 291 [[m_pNativeRef cell] setImageScaling: NSImageScaleProportionallyDown]; 292 initFrame = [m_pNativeRef frame]; 229 293 break; 230 294 } 231 295 case ResetButton: 232 296 { 233 mNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)]; 234 [mNativeRef setTitle: @""]; 235 [mNativeRef setBezelStyle:NSShadowlessSquareBezelStyle]; 236 [mNativeRef setButtonType:NSMomentaryChangeButton]; 237 [mNativeRef setImage: [NSImage imageNamed: NSImageNameRefreshFreestandingTemplate]]; 238 [mNativeRef setBordered: NO]; 239 [[mNativeRef cell] setImageScaling: NSImageScaleProportionallyDown]; 297 m_pNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)]; 298 [m_pNativeRef setTitle: @""]; 299 [m_pNativeRef setBezelStyle:NSShadowlessSquareBezelStyle]; 300 [m_pNativeRef setButtonType:NSMomentaryChangeButton]; 301 [m_pNativeRef setImage: [NSImage imageNamed: NSImageNameRefreshFreestandingTemplate]]; 302 [m_pNativeRef setBordered: NO]; 303 [[m_pNativeRef cell] setImageScaling: NSImageScaleProportionallyDown]; 304 initFrame = [m_pNativeRef frame]; 240 305 break; 241 306 } 242 307 } 243 308 244 NSButtonTarget *bt = [[NSButtonTarget alloc] initWithObject:this]; 245 [mNativeRef setTarget:bt]; 246 [mNativeRef setAction:@selector(clicked:)]; 247 248 NSRect frame = [mNativeRef frame]; 249 resize (frame.size.width, frame.size.height); 250 251 setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); 252 253 setCocoaView (mNativeRef); 254 } 255 256 VBoxCocoaButton::~VBoxCocoaButton() 257 { 258 [[mNativeRef target] release]; 259 [mNativeRef release]; 260 } 261 262 QSize VBoxCocoaButton::sizeHint() const 263 { 264 NSRect frame = [mNativeRef frame]; 265 return QSize (frame.size.width, frame.size.height); 266 } 267 268 void VBoxCocoaButton::resizeEvent(QResizeEvent * /* pEvent */) 269 { 270 NSRect frame = [mNativeRef frame]; 271 frame.size.width = width(); 272 frame.size.height = height(); 273 [mNativeRef setFrame:frame]; 274 } 275 276 void VBoxCocoaButton::setText (const QString& aText) 277 { 278 QString s (aText); 309 UIButtonTargetPrivate *bt = [[UIButtonTargetPrivate alloc] initWithObject:this]; 310 [m_pNativeRef setTarget:bt]; 311 [m_pNativeRef setAction:@selector(clicked:)]; 312 313 /* Create the container widget and attach the native view. */ 314 m_pContainer = new QMacCocoaViewContainer(m_pNativeRef, this); 315 /* Finally resize the widget */ 316 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 317 setFixedSize(NSWidth(initFrame), NSHeight(initFrame)); 318 } 319 320 UICocoaButton::~UICocoaButton() 321 { 322 } 323 324 QSize UICocoaButton::sizeHint() const 325 { 326 NSRect frame = [m_pNativeRef frame]; 327 return QSize(frame.size.width, frame.size.height); 328 } 329 330 void UICocoaButton::setText(const QString& strText) 331 { 332 QString s(strText); 279 333 /* Set it for accessibility reasons as alternative title */ 280 [mNativeRef setAlternateTitle: ::darwinQStringToNSString (s.remove ('&'))]; 281 } 282 283 void VBoxCocoaButton::setToolTip (const QString& aTip) 284 { 285 [mNativeRef setToolTip: ::darwinQStringToNSString (aTip)]; 286 } 287 288 void VBoxCocoaButton::onClicked() 289 { 290 emit clicked (false); 291 } 292 293 VBoxCocoaSegmentedButton::VBoxCocoaSegmentedButton (int aCount, QWidget *aParent /* = 0 */) 294 : QMacCocoaViewContainer (0, aParent) 295 { 296 mNativeRef = [[NSSegmentedControl alloc] init]; 297 [mNativeRef setSegmentCount:aCount]; 298 [mNativeRef setSegmentStyle:NSSegmentStyleRoundRect]; 299 [[mNativeRef cell] setTrackingMode: NSSegmentSwitchTrackingMomentary]; 300 [mNativeRef setFont: [NSFont controlContentFontOfSize: 301 [NSFont systemFontSizeForControlSize: NSSmallControlSize]]]; 302 [mNativeRef sizeToFit]; 303 304 NSSegmentedButtonTarget *bt = [[NSSegmentedButtonTarget alloc] initWithObject1:this]; 305 [mNativeRef setTarget:bt]; 306 [mNativeRef setAction:@selector(segControlClicked:)]; 307 308 NSRect frame = [mNativeRef frame]; 309 resize (frame.size.width, frame.size.height); 310 311 setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); 312 313 setCocoaView (mNativeRef); 314 315 } 316 317 VBoxCocoaSegmentedButton::~VBoxCocoaSegmentedButton() 318 { 319 [[mNativeRef target] release]; 320 [mNativeRef release]; 321 } 322 323 QSize VBoxCocoaSegmentedButton::sizeHint() const 324 { 325 NSRect frame = [mNativeRef frame]; 326 return QSize (frame.size.width, frame.size.height); 327 } 328 329 void VBoxCocoaSegmentedButton::setTitle (int aSegment, const QString &aTitle) 330 { 331 QString s (aTitle); 332 [mNativeRef setLabel: ::darwinQStringToNSString (s.remove ('&')) forSegment: aSegment]; 333 [mNativeRef sizeToFit]; 334 NSRect frame = [mNativeRef frame]; 335 resize (frame.size.width, frame.size.height); 336 } 337 338 void VBoxCocoaSegmentedButton::setToolTip (int aSegment, const QString &aTip) 339 { 340 [[mNativeRef cell] setToolTip: ::darwinQStringToNSString (aTip) forSegment: aSegment]; 341 } 342 343 void VBoxCocoaSegmentedButton::setEnabled (int aSegment, bool fEnabled) 344 { 345 [[mNativeRef cell] setEnabled: fEnabled forSegment: aSegment]; 346 } 347 348 void VBoxCocoaSegmentedButton::animateClick (int aSegment) 349 { 350 [mNativeRef setSelectedSegment: aSegment]; 351 [[mNativeRef cell] performClick: mNativeRef]; 352 } 353 354 void VBoxCocoaSegmentedButton::onClicked (int aSegment) 355 { 356 emit clicked (aSegment, false); 357 } 358 359 VBoxCocoaSearchField::VBoxCocoaSearchField (QWidget *aParent /* = 0 */) 360 : QMacCocoaViewContainer (0, aParent) 361 { 362 mNativeRef = [[VBSearchField alloc] initWithObject2: this]; 363 [[mNativeRef cell] setControlSize: NSSmallControlSize]; 364 [mNativeRef setFont: [NSFont controlContentFontOfSize: 365 [NSFont systemFontSizeForControlSize: NSSmallControlSize]]]; 366 [mNativeRef sizeToFit]; 367 NSRect f = [mNativeRef frame]; 368 f.size.width = 180; 369 [mNativeRef setFrame: f]; 370 371 setCocoaView (mNativeRef); 334 [m_pNativeRef setAlternateTitle: ::darwinQStringToNSString(s.remove('&'))]; 335 } 336 337 void UICocoaButton::setToolTip(const QString& strTip) 338 { 339 [m_pNativeRef setToolTip: ::darwinQStringToNSString(strTip)]; 340 } 341 342 void UICocoaButton::onClicked() 343 { 344 emit clicked(false); 345 } 346 347 UICocoaSegmentedButton::UICocoaSegmentedButton(int count, CocoaSegmentType type /* = RoundRectSegment */, QWidget *pParent /* = 0 */) 348 : UICocoaWrapper(pParent) 349 { 350 NSRect initFrame; 351 352 m_pNativeRef = [[NSSegmentedControl alloc] init]; 353 [m_pNativeRef setSegmentCount:count]; 354 switch (type) 355 { 356 case RoundRectSegment: 357 { 358 [[m_pNativeRef cell] setTrackingMode: NSSegmentSwitchTrackingMomentary]; 359 [m_pNativeRef setFont: [NSFont controlContentFontOfSize: 360 [NSFont systemFontSizeForControlSize: NSSmallControlSize]]]; 361 [m_pNativeRef setSegmentStyle:NSSegmentStyleRoundRect]; 362 break; 363 } 364 case TexturedRoundedSegment: 365 { 366 [m_pNativeRef setSegmentStyle:NSSegmentStyleTexturedRounded]; 367 [m_pNativeRef setFont: [NSFont controlContentFontOfSize: 368 [NSFont systemFontSizeForControlSize: NSSmallControlSize]]]; 369 break; 370 } 371 } 372 [m_pNativeRef sizeToFit]; 373 374 UISegmentedButtonTargetPrivate *bt = [[UISegmentedButtonTargetPrivate alloc] initWithObject1:this]; 375 [m_pNativeRef setTarget:bt]; 376 [m_pNativeRef setAction:@selector(segControlClicked:)]; 377 378 initFrame = [m_pNativeRef frame]; 379 /* Create the container widget and attach the native view. */ 380 m_pContainer = new QMacCocoaViewContainer(m_pNativeRef, this); 381 /* Finally resize the widget */ 382 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 383 setFixedSize(NSWidth(initFrame), NSHeight(initFrame)); 384 } 385 386 UICocoaSegmentedButton::~UICocoaSegmentedButton() 387 { 388 } 389 390 QSize UICocoaSegmentedButton::sizeHint() const 391 { 392 NSRect frame = [m_pNativeRef frame]; 393 return QSize(frame.size.width, frame.size.height); 394 } 395 396 void UICocoaSegmentedButton::setTitle(int iSegment, const QString &strTitle) 397 { 398 QString s(strTitle); 399 [m_pNativeRef setLabel: ::darwinQStringToNSString(s.remove('&')) forSegment: iSegment]; 400 [m_pNativeRef sizeToFit]; 401 NSRect frame = [m_pNativeRef frame]; 402 setFixedSize(NSWidth(frame), NSHeight(frame)); 403 } 404 405 void UICocoaSegmentedButton::setToolTip(int iSegment, const QString &strTip) 406 { 407 [[m_pNativeRef cell] setToolTip: ::darwinQStringToNSString(strTip) forSegment: iSegment]; 408 } 409 410 void UICocoaSegmentedButton::setIcon(int iSegment, const QIcon& icon) 411 { 412 QImage image = toGray(icon.pixmap(icon.actualSize(QSize(13, 13))).toImage()); 413 414 NSImage *pNSimage = [::darwinToNSImageRef(&image) autorelease]; 415 [m_pNativeRef setImage: pNSimage forSegment: iSegment]; 416 [m_pNativeRef sizeToFit]; 417 NSRect frame = [m_pNativeRef frame]; 418 setFixedSize(NSWidth(frame), NSHeight(frame)); 419 } 420 421 void UICocoaSegmentedButton::setEnabled(int iSegment, bool fEnabled) 422 { 423 [[m_pNativeRef cell] setEnabled: fEnabled forSegment: iSegment]; 424 } 425 426 void UICocoaSegmentedButton::animateClick(int iSegment) 427 { 428 [m_pNativeRef setSelectedSegment: iSegment]; 429 [[m_pNativeRef cell] performClick: m_pNativeRef]; 430 } 431 432 void UICocoaSegmentedButton::onClicked(int iSegment) 433 { 434 emit clicked(iSegment, false); 435 } 436 437 UICocoaSearchField::UICocoaSearchField(QWidget *pParent /* = 0 */) 438 : UICocoaWrapper(pParent) 439 { 440 NSRect initFrame; 441 442 m_pNativeRef = [[UISearchFieldPrivate alloc] initWithObject2: this]; 443 [m_pNativeRef setFont: [NSFont controlContentFontOfSize: 444 [NSFont systemFontSizeForControlSize: NSMiniControlSize]]]; 445 [[m_pNativeRef cell] setControlSize: NSMiniControlSize]; 446 [m_pNativeRef sizeToFit]; 447 initFrame = [m_pNativeRef frame]; 448 initFrame.size.width = 180; 449 [m_pNativeRef setFrame: initFrame]; 450 451 /* Use our own delegate */ 452 UISearchFieldDelegatePrivate *sfd = [[UISearchFieldDelegatePrivate alloc] init]; 453 [m_pNativeRef setDelegate: sfd]; 454 455 /* Create the container widget and attach the native view. */ 456 m_pContainer = new QMacCocoaViewContainer(m_pNativeRef, this); 457 458 /* Finally resize the widget */ 459 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 460 setMinimumWidth(NSWidth(initFrame)); 461 setFixedHeight(NSHeight(initFrame)); 372 462 setFocusPolicy(Qt::StrongFocus); 373 374 /* Replace the cell class used for the NSSearchField */ 375 [NSKeyedArchiver setClassName:@"VBSearchFieldCell" forClass:[NSSearchFieldCell class]]; 376 [mNativeRef setCell:[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[mNativeRef cell]]]]; 377 /* Get the original behavior back */ 378 [NSKeyedArchiver setClassName:@"NSSearchFieldCell" forClass:[NSSearchFieldCell class]]; 379 380 /* Use our own delegate */ 381 VBSearchFieldDelegate *sfd = [[VBSearchFieldDelegate alloc] init]; 382 [mNativeRef setDelegate: sfd]; 383 384 NSRect frame = [mNativeRef frame]; 385 resize (frame.size.width, frame.size.height + 1); 386 setMinimumWidth (50); 387 388 setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); 389 390 } 391 392 VBoxCocoaSearchField::~VBoxCocoaSearchField() 393 { 394 [[mNativeRef delegate] release]; 395 [mNativeRef release]; 396 } 397 398 QSize VBoxCocoaSearchField::sizeHint() const 399 { 400 NSRect frame = [mNativeRef frame]; 401 return QSize (frame.size.width, frame.size.height); 402 } 403 404 QString VBoxCocoaSearchField::text() const 405 { 406 return ::darwinNSStringToQString ([mNativeRef stringValue]); 407 } 408 409 void VBoxCocoaSearchField::insert (const QString &aText) 410 { 411 [[mNativeRef currentEditor] setString: [[mNativeRef stringValue] stringByAppendingString: ::darwinQStringToNSString (aText)]]; 412 } 413 414 void VBoxCocoaSearchField::setToolTip (const QString &aTip) 415 { 416 [mNativeRef setToolTip: ::darwinQStringToNSString (aTip)]; 417 } 418 419 void VBoxCocoaSearchField::selectAll() 420 { 421 [mNativeRef selectText: mNativeRef]; 422 } 423 424 void VBoxCocoaSearchField::markError() 425 { 426 [[mNativeRef cell] setBackgroundColor: [[NSColor redColor] colorWithAlphaComponent: 0.3]]; 427 } 428 429 void VBoxCocoaSearchField::unmarkError() 430 { 431 [[mNativeRef cell] setBackgroundColor: nil]; 432 } 433 434 void VBoxCocoaSearchField::onTextChanged (const QString &aText) 435 { 436 emit textChanged (aText); 437 } 438 463 } 464 465 UICocoaSearchField::~UICocoaSearchField() 466 { 467 } 468 469 QSize UICocoaSearchField::sizeHint() const 470 { 471 NSRect frame = [m_pNativeRef frame]; 472 return QSize(frame.size.width, frame.size.height); 473 } 474 475 QString UICocoaSearchField::text() const 476 { 477 return ::darwinNSStringToQString([m_pNativeRef stringValue]); 478 } 479 480 void UICocoaSearchField::insert(const QString &strText) 481 { 482 [[m_pNativeRef currentEditor] setString: [[m_pNativeRef stringValue] stringByAppendingString: ::darwinQStringToNSString(strText)]]; 483 } 484 485 void UICocoaSearchField::setToolTip(const QString &strTip) 486 { 487 [m_pNativeRef setToolTip: ::darwinQStringToNSString(strTip)]; 488 } 489 490 void UICocoaSearchField::selectAll() 491 { 492 [m_pNativeRef selectText: m_pNativeRef]; 493 } 494 495 void UICocoaSearchField::markError() 496 { 497 [[m_pNativeRef cell] setBackgroundColor: [[NSColor redColor] colorWithAlphaComponent: 0.3]]; 498 } 499 500 void UICocoaSearchField::unmarkError() 501 { 502 [[m_pNativeRef cell] setBackgroundColor: nil]; 503 } 504 505 void UICocoaSearchField::onTextChanged(const QString &strText) 506 { 507 emit textChanged(strText); 508 } 509 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxSpecialControls.cpp
r28800 r30188 35 35 { 36 36 setShortcut (QKeySequence (Qt::Key_Escape)); 37 mButton = new VBoxCocoaButton (VBoxCocoaButton::CancelButton, this);37 mButton = new UICocoaButton (UICocoaButton::CancelButton, this); 38 38 connect (mButton, SIGNAL (clicked()), 39 39 this, SIGNAL (clicked())); … … 54 54 : QAbstractButton(pParent) 55 55 { 56 m_pButton = new VBoxCocoaButton(VBoxCocoaButton::ResetButton, this);56 m_pButton = new UICocoaButton(UICocoaButton::ResetButton, this); 57 57 connect(m_pButton, SIGNAL(clicked()), 58 58 this, SIGNAL(clicked())); … … 74 74 { 75 75 setShortcut (QKeySequence (QKeySequence::HelpContents)); 76 mButton = new VBoxCocoaButton (VBoxCocoaButton::HelpButton, this);76 mButton = new UICocoaButton (UICocoaButton::HelpButton, this); 77 77 connect (mButton, SIGNAL (clicked()), 78 78 this, SIGNAL (clicked())); … … 86 86 ********************************************************************************/ 87 87 VBoxSegmentedButton::VBoxSegmentedButton (int aCount, QWidget *aParent /* = 0 */) 88 : VBoxCocoaSegmentedButton (aCount, aParent)88 : UICocoaSegmentedButton (aCount, UICocoaSegmentedButton::TexturedRoundedSegment, aParent) 89 89 { 90 90 } … … 95 95 ********************************************************************************/ 96 96 VBoxSearchField::VBoxSearchField (QWidget *aParent /* = 0 */) 97 : VBoxCocoaSearchField (aParent)97 : UICocoaSearchField (aParent) 98 98 { 99 99 } -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxSpecialControls.h
r28800 r30188 29 29 30 30 /* VBox includes */ 31 #include " VBoxCocoaSpecialControls.h"31 #include "UICocoaSpecialControls.h" 32 32 33 33 /******************************************************************************** … … 52 52 53 53 private: 54 VBoxCocoaButton *mButton;54 UICocoaButton *mButton; 55 55 }; 56 56 … … 76 76 77 77 private: 78 VBoxCocoaButton *m_pButton;78 UICocoaButton *m_pButton; 79 79 }; 80 80 … … 99 99 100 100 private: 101 VBoxCocoaButton *mButton;101 UICocoaButton *mButton; 102 102 }; 103 103 … … 107 107 * 108 108 ********************************************************************************/ 109 class VBoxSegmentedButton: public VBoxCocoaSegmentedButton109 class VBoxSegmentedButton: public UICocoaSegmentedButton 110 110 { 111 111 Q_OBJECT; … … 113 113 public: 114 114 VBoxSegmentedButton (int aCount, QWidget *aParent = 0); 115 116 void setIcon (int /* aSegment */, const QIcon & /* aIcon */) {}117 115 }; 118 116 … … 122 120 * 123 121 ********************************************************************************/ 124 class VBoxSearchField: public VBoxCocoaSearchField122 class VBoxSearchField: public UICocoaSearchField 125 123 { 126 124 Q_OBJECT;
Note:
See TracChangeset
for help on using the changeset viewer.

