- Timestamp:
- Mar 29, 2018 5:13:05 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksPanel.h
r71479 r71577 26 26 class QFrame; 27 27 class QIToolButton; 28 class UIRoundRectSegmentedButton;29 28 30 29 /** UIVMLogViewerPanel extension providing GUI for bookmark management. Show a list of bookmarks currently set -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h
r70792 r71577 31 31 class QLabel; 32 32 class QIToolButton; 33 class UISearchField;34 33 class UIVMLogViewerSearchField; 35 34 class UIVMLogViewerWidget; -
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.h
r69500 r71577 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - VBoxCocoaSpecialControls class declaration.3 * VBox Qt GUI - UICocoaSpecialControls class declaration. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef ___ darwin_UICocoaSpecialControls_h__19 #define ___ darwin_UICocoaSpecialControls_h__18 #ifndef ___UICocoaSpecialControls_h___ 19 #define ___UICocoaSpecialControls_h___ 20 20 21 /* VBox includes */ 21 /* Qt includes: */ 22 #include <QMacCocoaViewContainer> 23 #include <QWidget> 24 25 /* GUI includes: */ 22 26 #include "VBoxCocoaHelper.h" 23 27 24 /* Qt includes */ 25 #include <QWidget> 26 #include <QMacCocoaViewContainer> 28 /* Add typedefs for Cocoa types: */ 29 ADD_COCOA_NATIVE_REF(NSButton); 27 30 28 /* Add typedefs for Cocoa types */ 29 ADD_COCOA_NATIVE_REF(NSButton); 30 ADD_COCOA_NATIVE_REF(NSSegmentedControl); 31 ADD_COCOA_NATIVE_REF(NSSearchField); 32 33 class UICocoaButton: public QMacCocoaViewContainer 31 /** QMacCocoaViewContainer extension, 32 * used as cocoa button container. */ 33 class UICocoaButton : public QMacCocoaViewContainer 34 34 { 35 35 Q_OBJECT 36 36 37 signals: 38 39 /** Notifies about button click and whether it's @a fChecked. */ 40 void clicked(bool fChecked = false); 41 37 42 public: 43 44 /** Cocoa button types. */ 38 45 enum CocoaButtonType 39 46 { … … 43 50 }; 44 51 45 UICocoaButton(QWidget *pParent, CocoaButtonType type); 52 /** Constructs cocoa button passing @a pParent to the base-class. 53 * @param enmType Brings the button type. */ 54 UICocoaButton(QWidget *pParent, CocoaButtonType enmType); 55 /** Destructs cocoa button. */ 46 56 ~UICocoaButton(); 47 57 58 /** Returns size-hint. */ 48 59 QSize sizeHint() const; 49 60 50 void setText(const QString& strText); 51 void setToolTip(const QString& strTip); 61 /** Defines button @a strText. */ 62 void setText(const QString &strText); 63 /** Defines button @a strToolTip. */ 64 void setToolTip(const QString &strToolTip); 52 65 66 /** Handles button click. */ 53 67 void onClicked(); 54 68 55 signals: 56 void clicked(bool fChecked = false); 69 private: 57 70 58 private: 71 /** Returns native cocoa button reference. */ 59 72 NativeNSButtonRef nativeRef() const { return static_cast<NativeNSButtonRef>(cocoaView()); } 60 73 }; 61 74 62 class UICocoaSegmentedButton: public QMacCocoaViewContainer 63 { 64 Q_OBJECT 75 #endif /* !___UICocoaSpecialControls_h___ */ 65 76 66 public:67 enum CocoaSegmentType68 {69 RoundRectSegment,70 TexturedRoundedSegment71 };72 73 UICocoaSegmentedButton(QWidget *pParent, int count, CocoaSegmentType type = RoundRectSegment);74 75 /** Returns the number of segments. */76 int count() const;77 78 /** Returns whether the @a iSegment is selected. */79 bool isSelected(int iSegment) const;80 81 /** Returns the @a iSegment description. */82 QString description(int iSegment) const;83 84 QSize sizeHint() const;85 86 void setTitle(int iSegment, const QString &strTitle);87 void setToolTip(int iSegment, const QString &strTip);88 void setIcon(int iSegment, const QIcon& icon);89 void setEnabled(int iSegment, bool fEnabled);90 91 void setSelected(int iSegment);92 void animateClick(int iSegment);93 void onClicked(int iSegment);94 95 signals:96 void clicked(int iSegment, bool fChecked = false);97 98 private:99 NativeNSSegmentedControlRef nativeRef() const { return static_cast<NativeNSSegmentedControlRef>(cocoaView()); }100 };101 102 class UICocoaSearchField: public QMacCocoaViewContainer103 {104 Q_OBJECT105 106 public:107 UICocoaSearchField(QWidget* pParent);108 ~UICocoaSearchField();109 110 QSize sizeHint() const;111 112 QString text() const;113 void insert(const QString &strText);114 void setToolTip(const QString &strTip);115 void selectAll();116 117 void markError();118 void unmarkError();119 120 void onTextChanged(const QString &strText);121 122 signals:123 void textChanged(const QString& strText);124 125 private:126 NativeNSSearchFieldRef nativeRef() const { return static_cast<NativeNSSearchFieldRef>(cocoaView()); }127 };128 129 #endif /* ___darwin_UICocoaSpecialControls_h__ */130 -
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.mm
r71006 r71577 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 /* VBox includes */ 19 #include "UICocoaSpecialControls.h" 20 #include "VBoxUtils-darwin.h" 21 #include "UIImageTools.h" 22 #include <VBox/cdefs.h> 23 24 /* System includes */ 25 #import <AppKit/NSApplication.h> 26 #import <AppKit/NSBezierPath.h> 27 #import <AppKit/NSButton.h> 28 #import <AppKit/NSFont.h> 29 #import <AppKit/NSImage.h> 30 #import <AppKit/NSSegmentedControl.h> 31 #import <AppKit/NSEvent.h> 32 #import <AppKit/NSColor.h> 33 #import <AppKit/NSSearchFieldCell.h> 34 #import <AppKit/NSSearchField.h> 35 #import <AppKit/NSSegmentedCell.h> 36 37 /* Qt includes */ 38 #include <QAccessibleWidget> 39 #include <QApplication> 40 #include <QIcon> 41 #include <QKeyEvent> 18 /* Qt includes: */ 42 19 #include <QMacCocoaViewContainer> 43 20 44 /* Other VBox includes: */ 45 #include <iprt/assert.h> 21 /* GUI includes: */ 22 #include "VBoxUtils-darwin.h" 23 #include "UICocoaSpecialControls.h" 46 24 47 /* Forward declarations: */48 class UIAccessibilityInterfaceForUICocoaSegmentedButton; 25 /* System includes: */ 26 #import <AppKit/NSButton.h> 49 27 50 28 51 /* 52 * Private interfaces 53 */ 54 @interface UIButtonTargetPrivate: NSObject 29 /** Private button-target interface. */ 30 @interface UIButtonTargetPrivate : NSObject 55 31 { 56 UICocoaButton *m RealTarget;32 UICocoaButton *m_pRealTarget; 57 33 } 58 /* The next method used to be called initWithObject, but Xcode 4.1 preview 5 59 cannot cope with that for some reason. Hope this doesn't break anything... */ 60 -(id)initWithObjectAndLionTrouble:(UICocoaButton*)object; 61 -(IBAction)clicked:(id)sender; 34 // WORKAROUND: 35 // The next method used to be called initWithObject, but Xcode 4.1 preview 5 36 // cannot cope with that for some reason. Hope this doesn't break anything. 37 -(id)initWithObjectAndLionTrouble:(UICocoaButton*)pObject; 38 -(IBAction)clicked:(id)pSender; 62 39 @end 63 40 64 @interface UISegmentedButtonTargetPrivate: NSObject65 {66 UICocoaSegmentedButton *mRealTarget;67 }68 -(id)initWithObject1:(UICocoaSegmentedButton*)object;69 -(IBAction)segControlClicked:(id)sender;70 @end71 41 72 @interface UISearchFieldCellPrivate: NSSearchFieldCell 73 { 74 NSColor *mBGColor; 75 } 76 - (void)setBackgroundColor:(NSColor*)aBGColor; 77 @end 42 /********************************************************************************************************************************* 43 * Class UIButtonTargetPrivate implementation. * 44 *********************************************************************************************************************************/ 78 45 79 @interface UISearchFieldPrivate: NSSearchField80 {81 UICocoaSearchField *mRealTarget;82 }83 -(id)initWithObject2:(UICocoaSearchField*)object;84 @end85 86 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_687 @interface UISearchFieldDelegatePrivate: NSObject<NSTextFieldDelegate>88 #else89 @interface UISearchFieldDelegatePrivate: NSObject90 #endif91 {}92 @end93 94 /*95 * Implementation of the private interfaces96 */97 46 @implementation UIButtonTargetPrivate 98 -(id)initWithObjectAndLionTrouble:(UICocoaButton*) object47 -(id)initWithObjectAndLionTrouble:(UICocoaButton*)pObject 99 48 { 100 49 self = [super init]; 101 50 102 m RealTarget = object;51 m_pRealTarget = pObject; 103 52 104 53 return self; 105 54 } 106 55 107 -(IBAction)clicked:(id) sender56 -(IBAction)clicked:(id)pSender 108 57 { 109 RT_NOREF(sender); 110 mRealTarget->onClicked(); 111 } 112 @end 113 114 @implementation UISegmentedButtonTargetPrivate 115 -(id)initWithObject1:(UICocoaSegmentedButton*)object 116 { 117 self = [super init]; 118 119 mRealTarget = object; 120 121 return self; 122 } 123 124 -(IBAction)segControlClicked:(id)sender 125 { 126 mRealTarget->onClicked([sender selectedSegment]); 127 } 128 @end 129 130 @implementation UISearchFieldCellPrivate 131 -(id)init 132 { 133 if ((self = [super init])) 134 mBGColor = Nil; 135 return self; 136 } 137 138 - (void)dealloc 139 { 140 [mBGColor release]; 141 [super dealloc]; 142 } 143 144 - (void)setBackgroundColor:(NSColor*)aBGColor 145 { 146 if (mBGColor != aBGColor) 147 { 148 [mBGColor release]; 149 mBGColor = [aBGColor retain]; 150 } 151 } 152 153 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 154 { 155 if (mBGColor != Nil) 156 { 157 [mBGColor setFill]; 158 NSRect frame = cellFrame; 159 double radius = RT_MIN(NSWidth(frame), NSHeight(frame)) / 2.0; 160 [[NSBezierPath bezierPathWithRoundedRect:frame xRadius:radius yRadius:radius] fill]; 161 } 162 163 [super drawInteriorWithFrame:cellFrame inView:controlView]; 164 } 165 @end 166 167 @implementation UISearchFieldPrivate 168 + (Class)cellClass 169 { 170 return [UISearchFieldCellPrivate class]; 171 } 172 173 -(id)initWithObject2:(UICocoaSearchField*)object 174 { 175 self = [super init]; 176 177 mRealTarget = object; 178 179 180 return self; 181 } 182 183 - (void)keyUp:(NSEvent *)theEvent 184 { 185 /* This here is a little bit hacky. Grab important keys & forward they to 186 the parent Qt widget. There a special key handling is done. */ 187 NSString *str = [theEvent charactersIgnoringModifiers]; 188 unichar ch = 0; 189 190 /* Get the pressed character */ 191 if ([str length] > 0) 192 ch = [str characterAtIndex:0]; 193 194 if (ch == NSCarriageReturnCharacter || ch == NSEnterCharacter) 195 { 196 QKeyEvent ke(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); 197 QApplication::sendEvent(mRealTarget, &ke); 198 } 199 else if (ch == 27) /* Escape */ 200 { 201 QKeyEvent ke(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); 202 QApplication::sendEvent(mRealTarget, &ke); 203 } 204 else if (ch == NSF3FunctionKey) 205 { 206 QKeyEvent ke(QEvent::KeyPress, Qt::Key_F3, [theEvent modifierFlags] & NSShiftKeyMask ? Qt::ShiftModifier : Qt::NoModifier); 207 QApplication::sendEvent(mRealTarget, &ke); 208 } 209 210 [super keyUp:theEvent]; 211 } 212 213 //{ 214 // QWidget *w = QApplication::focusWidget(); 215 // if (w) 216 // w->clearFocus(); 217 //} 218 219 - (void)textDidChange:(NSNotification *)aNotification 220 { 221 mRealTarget->onTextChanged(::darwinNSStringToQString([[aNotification object] string])); 222 } 223 @end 224 225 @implementation UISearchFieldDelegatePrivate 226 -(BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector 227 { 228 RT_NOREF(control, textView); 229 // NSLog(NSStringFromSelector(commandSelector)); 230 /* Don't execute the selector for Enter & Escape. */ 231 if ( commandSelector == @selector(insertNewline:) 232 || commandSelector == @selector(cancelOperation:)) 233 return YES; 234 return NO; 58 Q_UNUSED(pSender); 59 m_pRealTarget->onClicked(); 235 60 } 236 61 @end 237 62 238 63 239 /* 240 * Helper functions 241 */ 242 NSRect darwinCenterRectVerticalTo(NSRect aRect, const NSRect& aToRect) 243 { 244 aRect.origin.y = (aToRect.size.height - aRect.size.height) / 2.0; 245 return aRect; 246 } 64 /********************************************************************************************************************************* 65 * Class UICocoaButton implementation. * 66 *********************************************************************************************************************************/ 247 67 248 /* 249 * Public classes 250 */ 251 UICocoaButton::UICocoaButton(QWidget *pParent, CocoaButtonType type) 68 UICocoaButton::UICocoaButton(QWidget *pParent, CocoaButtonType enmType) 252 69 : QMacCocoaViewContainer(0, pParent) 253 70 { 254 71 /* Prepare auto-release pool: */ 255 NSAutoreleasePool *p ool = [[NSAutoreleasePool alloc] init];72 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 256 73 257 74 /* Prepare native button reference: */ … … 260 77 261 78 /* Configure button: */ 262 switch ( type)79 switch (enmType) 263 80 { 264 81 case HelpButton: … … 317 134 318 135 /* Cleanup auto-release pool: */ 319 [p ool release];136 [pPool release]; 320 137 } 321 138 … … 330 147 } 331 148 332 void UICocoaButton::setText(const QString &strText)149 void UICocoaButton::setText(const QString &strText) 333 150 { 334 151 QString s(strText); 335 /* Set it for accessibility reasons as alternative title */152 /* Set it for accessibility reasons as alternative title: */ 336 153 [nativeRef() setAlternateTitle: ::darwinQStringToNSString(s.remove('&'))]; 337 154 } 338 155 339 void UICocoaButton::setToolTip(const QString & strTip)156 void UICocoaButton::setToolTip(const QString &strToolTip) 340 157 { 341 [nativeRef() setToolTip: ::darwinQStringToNSString(strT ip)];158 [nativeRef() setToolTip: ::darwinQStringToNSString(strToolTip)]; 342 159 } 343 160 … … 347 164 } 348 165 349 350 /** QAccessibleInterface extension used as an accessibility interface for segmented-button segment. */351 class UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment : public QAccessibleInterface352 {353 public:354 355 /** Constructs an accessibility interface.356 * @param pParent Brings the parent interface we are linked to.357 * @param iIndex Brings the index of segment we are referring to. */358 UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment(UIAccessibilityInterfaceForUICocoaSegmentedButton *pParent, int iIndex)359 : m_pParent(pParent)360 , m_iIndex(iIndex)361 {}362 363 /** Returns whether the interface is valid. */364 virtual bool isValid() const /* override */ { return true; }365 366 /** Returns the wrapped object. */367 virtual QObject *object() const /* override */ { return 0; }368 /** Returns the parent. */369 virtual QAccessibleInterface *parent() const /* override */;370 371 /** Returns the number of children. */372 virtual int childCount() const /* override */ { return 0; }373 /** Returns the child with the passed @a iIndex. */374 virtual QAccessibleInterface *child(int /* iIndex */) const /* override */ { return 0; }375 /** Returns the child at position QPoint(@a x, @a y). */376 virtual QAccessibleInterface *childAt(int /* x */, int /* y */) const /* override */ { return 0; }377 /** Returns the index of the passed @a pChild. */378 virtual int indexOfChild(const QAccessibleInterface * /* pChild */) const /* override */ { return -1; }379 380 /** Returns the rect. */381 virtual QRect rect() const /* override */;382 383 /** Defines a @a strText for the passed @a enmTextRole. */384 virtual void setText(QAccessible::Text /* enmTextRole */, const QString & /* strText */) /* override */ {}385 /** Returns a text for the passed @a enmTextRole. */386 virtual QString text(QAccessible::Text /* enmTextRole */) const /* override */;387 388 /** Returns the role. */389 virtual QAccessible::Role role() const /* override */ { return QAccessible::RadioButton; }390 /** Returns the state. */391 virtual QAccessible::State state() const /* override */;392 393 private:394 395 /** Holds the parent interface we are linked to. */396 UIAccessibilityInterfaceForUICocoaSegmentedButton *m_pParent;397 /** Holds the index of segment we are referring to. */398 const int m_iIndex;399 };400 401 402 /** QAccessibleWidget extension used as an accessibility interface for segmented-button. */403 class UIAccessibilityInterfaceForUICocoaSegmentedButton : public QAccessibleWidget404 {405 public:406 407 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */408 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)409 {410 /* Creating segmented-button accessibility interface: */411 if (pObject && strClassname == QLatin1String("UICocoaSegmentedButton"))412 return new UIAccessibilityInterfaceForUICocoaSegmentedButton(qobject_cast<QWidget*>(pObject));413 414 /* Null by default: */415 return 0;416 }417 418 /** Constructs an accessibility interface passing @a pWidget to the base-class. */419 UIAccessibilityInterfaceForUICocoaSegmentedButton(QWidget *pWidget)420 : QAccessibleWidget(pWidget, QAccessible::ToolBar)421 {422 /* Prepare: */423 prepare();424 }425 426 /** Destructs an accessibility interface. */427 ~UIAccessibilityInterfaceForUICocoaSegmentedButton()428 {429 /* Cleanup: */430 cleanup();431 }432 433 /** Returns the number of children. */434 virtual int childCount() const /* override */ { return m_children.size(); }435 /** Returns the child with the passed @a iIndex. */436 virtual QAccessibleInterface *child(int iIndex) const /* override */ { return m_children.at(iIndex); }437 438 /** Returns corresponding segmented-button. */439 UICocoaSegmentedButton *button() const { return qobject_cast<UICocoaSegmentedButton*>(widget()); }440 441 private:442 443 /** Prepares all. */444 void prepare()445 {446 /* Prepare the list of children interfaces: */447 for (int i = 0; i < button()->count(); ++i)448 m_children << new UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment(this, i);449 }450 451 /** Cleanups all. */452 void cleanup()453 {454 /* Cleanup the list of children interfaces: */455 qDeleteAll(m_children);456 m_children.clear();457 }458 459 /** Holds the list of children interfaces. */460 QList<UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment*> m_children;461 };462 463 464 QAccessibleInterface *UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::parent() const465 {466 return m_pParent;467 }468 469 QRect UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::rect() const470 {471 /// @todo Return the -=real=- segment rectangle.472 const QRect myRect = m_pParent->rect();473 return QRect(myRect.x() + myRect.width() / 2 * m_iIndex,474 myRect.y(), myRect.width() / 2, myRect.height());475 }476 477 QString UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::text(QAccessible::Text /* enmTextRole */) const478 {479 /* Return the segment description: */480 return m_pParent->button()->description(m_iIndex);481 }482 483 QAccessible::State UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::state() const484 {485 /* Compose the segment state: */486 QAccessible::State state;487 state.checkable = true;488 state.checked = m_pParent->button()->isSelected(m_iIndex);489 490 /* Return the segment state: */491 return state;492 }493 494 495 UICocoaSegmentedButton::UICocoaSegmentedButton(QWidget *pParent, int count, CocoaSegmentType type /* = RoundRectSegment */)496 : QMacCocoaViewContainer(0, pParent)497 {498 /* Install segmented-button accessibility interface factory: */499 QAccessible::installFactory(UIAccessibilityInterfaceForUICocoaSegmentedButton::pFactory);500 501 /* Prepare auto-release pool: */502 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];503 504 /* Prepare native segmented-button reference: */505 NativeNSSegmentedControlRef pNativeRef;506 NSRect initFrame;507 508 /* Configure segmented-button: */509 pNativeRef = [[NSSegmentedControl alloc] init];510 [pNativeRef setSegmentCount:count];511 switch (type)512 {513 case RoundRectSegment:514 {515 [pNativeRef setSegmentStyle: NSSegmentStyleRoundRect];516 [pNativeRef setFont: [NSFont controlContentFontOfSize:517 [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];518 [[pNativeRef cell] setTrackingMode: NSSegmentSwitchTrackingMomentary];519 break;520 }521 case TexturedRoundedSegment:522 {523 [pNativeRef setSegmentStyle: NSSegmentStyleTexturedRounded];524 [pNativeRef setFont: [NSFont controlContentFontOfSize:525 [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];526 break;527 }528 }529 530 /* Calculate corresponding size: */531 [pNativeRef sizeToFit];532 initFrame = [pNativeRef frame];533 534 /* Install click listener: */535 UISegmentedButtonTargetPrivate *bt = [[UISegmentedButtonTargetPrivate alloc] initWithObject1:this];536 [pNativeRef setTarget:bt];537 [pNativeRef setAction:@selector(segControlClicked:)];538 539 /* Put the button to the QCocoaViewContainer: */540 setCocoaView(pNativeRef);541 /* Release our reference, since our super class542 * takes ownership and we don't need it anymore. */543 [pNativeRef release];544 545 /* Finally resize the widget: */546 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);547 setFixedSize(NSWidth(initFrame), NSHeight(initFrame));548 549 /* Cleanup auto-release pool: */550 [pool release];551 }552 553 int UICocoaSegmentedButton::count() const554 {555 return [nativeRef() segmentCount];556 }557 558 bool UICocoaSegmentedButton::isSelected(int iSegment) const559 {560 /* Return whether the segment is selected if segment index inside the bounds: */561 if (iSegment >=0 && iSegment < count())562 return [nativeRef() isSelectedForSegment: iSegment];563 564 /* False by default: */565 return false;566 }567 568 QString UICocoaSegmentedButton::description(int iSegment) const569 {570 /* Return segment description if segment index inside the bounds: */571 if (iSegment >=0 && iSegment < count())572 return ::darwinNSStringToQString([nativeRef() labelForSegment: iSegment]);573 574 /* Null-string by default: */575 return QString();576 }577 578 QSize UICocoaSegmentedButton::sizeHint() const579 {580 NSRect frame = [nativeRef() frame];581 return QSize(frame.size.width, frame.size.height);582 }583 584 void UICocoaSegmentedButton::setTitle(int iSegment, const QString &strTitle)585 {586 QString s(strTitle);587 [nativeRef() setLabel: ::darwinQStringToNSString(s.remove('&')) forSegment: iSegment];588 [nativeRef() sizeToFit];589 NSRect frame = [nativeRef() frame];590 setFixedSize(NSWidth(frame), NSHeight(frame));591 }592 593 void UICocoaSegmentedButton::setToolTip(int iSegment, const QString &strTip)594 {595 [[nativeRef() cell] setToolTip: ::darwinQStringToNSString(strTip) forSegment: iSegment];596 }597 598 void UICocoaSegmentedButton::setIcon(int iSegment, const QIcon& icon)599 {600 QImage image = toGray(icon.pixmap(icon.availableSizes().value(0, QSize(16, 16))).toImage());601 602 NSImage *pNSimage = [::darwinToNSImageRef(&image) autorelease];603 [nativeRef() setImage: pNSimage forSegment: iSegment];604 [nativeRef() sizeToFit];605 NSRect frame = [nativeRef() frame];606 setFixedSize(NSWidth(frame), NSHeight(frame));607 }608 609 void UICocoaSegmentedButton::setEnabled(int iSegment, bool fEnabled)610 {611 [[nativeRef() cell] setEnabled: fEnabled forSegment: iSegment];612 }613 614 void UICocoaSegmentedButton::setSelected(int iSegment)615 {616 [nativeRef() setSelectedSegment: iSegment];617 }618 619 void UICocoaSegmentedButton::animateClick(int iSegment)620 {621 [nativeRef() setSelectedSegment: iSegment];622 [[nativeRef() cell] performClick: nativeRef()];623 }624 625 void UICocoaSegmentedButton::onClicked(int iSegment)626 {627 emit clicked(iSegment, false);628 }629 630 631 /** QAccessibleWidget extension used as an accessibility interface for search-field. */632 class UIAccessibilityInterfaceForUICocoaSearchField : public QAccessibleWidget633 {634 public:635 636 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */637 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)638 {639 /* Creating segmented-button accessibility interface: */640 if (pObject && strClassname == QLatin1String("UICocoaSearchField"))641 return new UIAccessibilityInterfaceForUICocoaSearchField(qobject_cast<QWidget*>(pObject));642 643 /* Null by default: */644 return 0;645 }646 647 /** Constructs an accessibility interface passing @a pWidget to the base-class. */648 UIAccessibilityInterfaceForUICocoaSearchField(QWidget *pWidget)649 : QAccessibleWidget(pWidget, QAccessible::EditableText)650 {651 // For now this class doesn't implement interface casting.652 // Which means there will be no editable text accessible653 // in basic accessibility layer, only in advanced one.654 }655 656 private:657 658 /** Returns corresponding search-field. */659 UICocoaSearchField *field() const { return qobject_cast<UICocoaSearchField*>(widget()); }660 };661 662 663 UICocoaSearchField::UICocoaSearchField(QWidget *pParent)664 : QMacCocoaViewContainer(0, pParent)665 {666 /* Install segmented-button accessibility interface factory: */667 QAccessible::installFactory(UIAccessibilityInterfaceForUICocoaSearchField::pFactory);668 669 /* Prepare auto-release pool: */670 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];671 672 /* Prepare native search-field reference: */673 NativeNSSearchFieldRef pNativeRef;674 NSRect initFrame;675 676 /* Configure search-field: */677 pNativeRef = [[UISearchFieldPrivate alloc] initWithObject2: this];678 [pNativeRef setFont: [NSFont controlContentFontOfSize:679 [NSFont systemFontSizeForControlSize: NSMiniControlSize]]];680 [[pNativeRef cell] setControlSize: NSMiniControlSize];681 [pNativeRef sizeToFit];682 initFrame = [pNativeRef frame];683 initFrame.size.width = 180;684 [pNativeRef setFrame: initFrame];685 686 /* Use our own delegate: */687 UISearchFieldDelegatePrivate *sfd = [[UISearchFieldDelegatePrivate alloc] init];688 [pNativeRef setDelegate: sfd];689 690 /* Put the button to the QCocoaViewContainer: */691 setCocoaView(pNativeRef);692 /* Release our reference, since our super class693 * takes ownership and we don't need it anymore. */694 [pNativeRef release];695 696 /* Finally resize the widget: */697 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);698 setMinimumWidth(NSWidth(initFrame));699 setFixedHeight(NSHeight(initFrame));700 setFocusPolicy(Qt::StrongFocus);701 702 /* Cleanup auto-release pool: */703 [pool release];704 }705 706 UICocoaSearchField::~UICocoaSearchField()707 {708 }709 710 QSize UICocoaSearchField::sizeHint() const711 {712 NSRect frame = [nativeRef() frame];713 return QSize(frame.size.width, frame.size.height);714 }715 716 QString UICocoaSearchField::text() const717 {718 return ::darwinNSStringToQString([nativeRef() stringValue]);719 }720 721 void UICocoaSearchField::insert(const QString &strText)722 {723 [[nativeRef() currentEditor] setString: [[nativeRef() stringValue] stringByAppendingString: ::darwinQStringToNSString(strText)]];724 }725 726 void UICocoaSearchField::setToolTip(const QString &strTip)727 {728 [nativeRef() setToolTip: ::darwinQStringToNSString(strTip)];729 }730 731 void UICocoaSearchField::selectAll()732 {733 [nativeRef() selectText: nativeRef()];734 }735 736 void UICocoaSearchField::markError()737 {738 [[nativeRef() cell] setBackgroundColor: [[NSColor redColor] colorWithAlphaComponent: 0.3]];739 }740 741 void UICocoaSearchField::unmarkError()742 {743 [[nativeRef() cell] setBackgroundColor: nil];744 }745 746 void UICocoaSearchField::onTextChanged(const QString &strText)747 {748 emit textChanged(strText);749 }750 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISpecialControls.cpp
r69726 r71577 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - VBoxSpecialButtons implementation.3 * VBox Qt GUI - UISpecialControls implementation. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 22 /* VBox includes */ 22 /* Qt includes: */ 23 # include <QHBoxLayout> 24 # ifndef VBOX_DARWIN_USE_NATIVE_CONTROLS 25 # include <QBitmap> 26 # include <QMouseEvent> 27 # include <QPainter> 28 # include <QSignalMapper> 29 # endif 30 31 /* GUI includes: */ 23 32 # include "UIIconPool.h" 24 33 # include "UISpecialControls.h" 25 26 /* Global includes */27 # include <QHBoxLayout>28 34 29 35 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 32 38 #ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS 33 39 34 /******************************************************************************** 35 36 * A mini cancel button in the native Cocoa version. 37 * 38 ********************************************************************************/ 40 41 /********************************************************************************************************************************* 42 * Class UIMiniCancelButton implementation. * 43 *********************************************************************************************************************************/ 44 39 45 UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */) 40 : QAbstractButton(pParent)46 : QAbstractButton(pParent) 41 47 { 42 48 setShortcut(QKeySequence(Qt::Key_Escape)); 43 49 m_pButton = new UICocoaButton(this, UICocoaButton::CancelButton); 44 connect(m_pButton, SIGNAL(clicked()), 45 this, SIGNAL(clicked())); 50 connect(m_pButton, SIGNAL(clicked()), this, SIGNAL(clicked())); 46 51 setFixedSize(m_pButton->size()); 47 52 } 48 53 49 void UIMiniCancelButton::resizeEvent(QResizeEvent * /* pEvent */)54 void UIMiniCancelButton::resizeEvent(QResizeEvent *) 50 55 { 51 56 m_pButton->resize(size()); 52 57 } 53 58 54 /******************************************************************************** 55 56 * A rest button in the native Cocoa version. 57 * 58 ********************************************************************************/ 59 UI ResetButton::UIResetButton(QWidget *pParent /* = 0 */)60 : QAbstractButton(pParent)59 60 /********************************************************************************************************************************* 61 * Class UIHelpButton implementation. * 62 *********************************************************************************************************************************/ 63 64 UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */) 65 : QPushButton(pParent) 61 66 { 62 m_pButton = new UICocoaButton(this, UICocoaButton::ResetButton);63 connect(m_pButton, SIGNAL(clicked()),64 67 setShortcut(QKeySequence(QKeySequence::HelpContents)); 68 m_pButton = new UICocoaButton(this, UICocoaButton::HelpButton); 69 connect(m_pButton, SIGNAL(clicked()), this, SIGNAL(clicked())); 65 70 setFixedSize(m_pButton->size()); 66 71 } 67 72 68 void UIResetButton::resizeEvent(QResizeEvent * /* pEvent */)69 {70 m_pButton->resize(size());71 }72 73 73 /******************************************************************************** 74 * 75 * A help button in the native Cocoa version. 76 * 77 ********************************************************************************/ 78 UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */) 79 : QPushButton(pParent) 80 { 81 setShortcut(QKeySequence(QKeySequence::HelpContents)); 82 m_pButton = new UICocoaButton(this, UICocoaButton::HelpButton); 83 connect(m_pButton, SIGNAL(clicked()), 84 this, SIGNAL(clicked())); 85 setFixedSize(m_pButton->size()); 86 } 74 #else /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */ 87 75 88 /********************************************************************************89 *90 * A segmented button in the native Cocoa version.91 *92 ********************************************************************************/93 UIRoundRectSegmentedButton::UIRoundRectSegmentedButton(QWidget *pParent, int cCount)94 : UICocoaSegmentedButton(pParent, cCount, UICocoaSegmentedButton::RoundRectSegment)95 {96 }97 76 98 UITexturedSegmentedButton::UITexturedSegmentedButton(QWidget *pParent, int cCount) 99 : UICocoaSegmentedButton(pParent, cCount, UICocoaSegmentedButton::TexturedRoundedSegment) 100 { 101 } 77 /********************************************************************************************************************************* 78 * Class UIMiniCancelButton implementation. * 79 *********************************************************************************************************************************/ 102 80 103 /********************************************************************************104 *105 * A search field in the native Cocoa version.106 *107 ********************************************************************************/108 UISearchField::UISearchField(QWidget *pParent /* = 0 */)109 : UICocoaSearchField(pParent)110 {111 }112 113 #else /* VBOX_DARWIN_USE_NATIVE_CONTROLS */114 115 # ifndef VBOX_WITH_PRECOMPILED_HEADERS116 /* Qt includes */117 # include <QPainter>118 # include <QBitmap>119 # include <QMouseEvent>120 # include <QSignalMapper>121 # endif122 123 /********************************************************************************124 *125 * A mini cancel button for the other OS's.126 *127 ********************************************************************************/128 81 UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */) 129 : QIWithRetranslateUI<QIToolButton>(pParent)82 : QIWithRetranslateUI<QIToolButton>(pParent) 130 83 { 131 84 setAutoRaise(true); … … 135 88 } 136 89 137 /******************************************************************************** 138 139 * A help button for the other OS's. 140 * 141 ********************************************************************************/ 90 91 /********************************************************************************************************************************* 92 * Class UIHelpButton implementation. * 93 *********************************************************************************************************************************/ 94 142 95 /* From: src/gui/styles/qmacstyle_mac.cpp */ 143 96 static const int PushButtonLeftOffset = 6; … … 149 102 : QIWithRetranslateUI<QPushButton>(pParent) 150 103 { 151 # ifdef VBOX_WS_MAC104 # ifdef VBOX_WS_MAC 152 105 m_pButtonPressed = false; 153 106 m_pNormalPixmap = new QPixmap(":/help_button_normal_mac_22px.png"); … … 159 112 m_size.width(), 160 113 m_size.height()); 161 #endif /* VBOX_WS_MAC */ 162 /* Applying language settings */ 114 # endif /* VBOX_WS_MAC */ 115 116 /* Apply language settings: */ 163 117 retranslateUi(); 164 118 } … … 166 120 void UIHelpButton::initFrom(QPushButton *pOther) 167 121 { 122 /* Copy settings from pOther: */ 168 123 setIcon(pOther->icon()); 169 124 setText(pOther->text()); … … 172 127 setAutoDefault(pOther->autoDefault()); 173 128 setDefault(pOther->isDefault()); 174 /* Applying language settings */ 129 130 /* Apply language settings: */ 175 131 retranslateUi(); 176 132 } … … 183 139 } 184 140 185 # ifdef VBOX_WS_MAC141 # ifdef VBOX_WS_MAC 186 142 UIHelpButton::~UIHelpButton() 187 143 { … … 197 153 } 198 154 199 void UIHelpButton::paintEvent(QPaintEvent * /* pEvent */)155 void UIHelpButton::paintEvent(QPaintEvent *) 200 156 { 201 157 QPainter painter(this); … … 203 159 } 204 160 205 bool UIHelpButton::hitButton(const QPoint &pos ) const161 bool UIHelpButton::hitButton(const QPoint &position) const 206 162 { 207 if (m_BRect.contains(pos ))208 return m_pMask->pixel(pos .x() - PushButtonLeftOffset,209 pos .y() - PushButtonTopOffset) == 0xff000000;163 if (m_BRect.contains(position)) 164 return m_pMask->pixel(position.x() - PushButtonLeftOffset, 165 position.y() - PushButtonTopOffset) == 0xff000000; 210 166 else 211 167 return false; … … 227 183 } 228 184 229 void UIHelpButton::leaveEvent(QEvent * 185 void UIHelpButton::leaveEvent(QEvent *pEvent) 230 186 { 231 187 QPushButton::leaveEvent(pEvent); … … 233 189 update(); 234 190 } 235 # endif /* VBOX_WS_MAC */191 # endif /* VBOX_WS_MAC */ 236 192 237 /********************************************************************************238 *239 * A segmented button for the other OS's.240 *241 ********************************************************************************/242 UIRoundRectSegmentedButton::UIRoundRectSegmentedButton(QWidget *pParent, int aCount)243 : QWidget(pParent)244 {245 m_pSignalMapper = new QSignalMapper(this);246 193 247 QHBoxLayout *layout = new QHBoxLayout(this); 248 layout->setContentsMargins(0, 0, 0, 0); 249 for (int i=0; i < aCount; ++i) 250 { 251 QIToolButton *button = new QIToolButton(this); 252 button->setAutoRaise(true); 253 button->setFocusPolicy(Qt::TabFocus); 254 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 255 m_pButtons.append(button); 256 layout->addWidget(button); 257 connect(button, SIGNAL(clicked()), 258 m_pSignalMapper, SLOT(map())); 259 m_pSignalMapper->setMapping(button, i); 260 } 261 connect(m_pSignalMapper, SIGNAL(mapped(int)), 262 this, SIGNAL(clicked(int))); 194 #endif /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */ 263 195 264 }265 266 UIRoundRectSegmentedButton::~UIRoundRectSegmentedButton()267 {268 delete m_pSignalMapper;269 qDeleteAll(m_pButtons);270 }271 272 int UIRoundRectSegmentedButton::count() const273 {274 return m_pButtons.size();275 }276 277 void UIRoundRectSegmentedButton::setTitle(int iSegment, const QString &aTitle)278 {279 m_pButtons.at(iSegment)->setText(aTitle);280 }281 282 void UIRoundRectSegmentedButton::setToolTip(int iSegment, const QString &strTip)283 {284 m_pButtons.at(iSegment)->setToolTip(strTip);285 }286 287 void UIRoundRectSegmentedButton::setIcon(int iSegment, const QIcon &icon)288 {289 m_pButtons.at(iSegment)->setIcon(icon);290 }291 292 void UIRoundRectSegmentedButton::setEnabled(int iSegment, bool fEnabled)293 {294 m_pButtons.at(iSegment)->setEnabled(fEnabled);295 }296 297 void UIRoundRectSegmentedButton::setSelected(int iSegment)298 {299 m_pButtons.at(iSegment)->setChecked(true);300 }301 302 void UIRoundRectSegmentedButton::animateClick(int iSegment)303 {304 m_pButtons.at(iSegment)->animateClick();305 }306 307 UITexturedSegmentedButton::UITexturedSegmentedButton(QWidget *pParent, int cCount)308 : UIRoundRectSegmentedButton(pParent, cCount)309 {310 for (int i=0; i < m_pButtons.size(); ++i)311 {312 m_pButtons.at(i)->setAutoExclusive(true);313 m_pButtons.at(i)->setCheckable(true);314 }315 }316 317 /********************************************************************************318 *319 * A search field for the other OS's.320 *321 ********************************************************************************/322 UISearchField::UISearchField(QWidget *pParent)323 : QLineEdit(pParent)324 {325 m_baseBrush = palette().base();326 }327 328 void UISearchField::markError()329 {330 QPalette pal = palette();331 QColor c(Qt::red);332 c.setAlphaF(0.3);333 pal.setBrush(QPalette::Base, c);334 setPalette(pal);335 }336 337 void UISearchField::unmarkError()338 {339 QPalette pal = palette();340 pal.setBrush(QPalette::Base, m_baseBrush);341 setPalette(pal);342 }343 344 #endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */345 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISpecialControls.h
r69500 r71577 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - VBoxSpecialButtons declarations.3 * VBox Qt GUI - UISpecialControls declarations. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 19 19 #define ___VBoxSpecialControls_h__ 20 20 21 /* VBox includes */ 21 /* Qt includes: */ 22 #include <QPushButton> 23 #ifndef VBOX_DARWIN_USE_NATIVE_CONTROLS 24 # include <QLineEdit> 25 #endif 26 27 /* GUI includes: */ 22 28 #include "QIWithRetranslateUI.h" 29 #ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS 30 # include "UICocoaSpecialControls.h" 31 #else 32 # include "QIToolButton.h" 33 #endif 23 34 24 /* Qt includes */ 25 #include <QPushButton> 35 /* Forward declarations: */ 36 #ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS 37 class UICocoaButton; 38 #endif 39 26 40 27 41 #ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS 28 42 29 /* VBox includes */ 30 #include "UICocoaSpecialControls.h" 31 32 /******************************************************************************** 33 * 34 * A mini cancel button in the native Cocoa version. 35 * 36 ********************************************************************************/ 37 class UIMiniCancelButton: public QAbstractButton 43 /** QAbstractButton subclass, used as mini cancel button. */ 44 class UIMiniCancelButton : public QAbstractButton 38 45 { 39 46 Q_OBJECT; 40 47 41 48 public: 49 50 /** Constructs mini cancel-button passing @a pParent to the base-class. */ 42 51 UIMiniCancelButton(QWidget *pParent = 0); 43 52 53 /** Defines button @a strText. */ 44 54 void setText(const QString &strText) { m_pButton->setText(strText); } 45 void setToolTip(const QString &strTip) { m_pButton->setToolTip(strTip); } 55 /** Defines button @a strToolTip. */ 56 void setToolTip(const QString &strToolTip) { m_pButton->setToolTip(strToolTip); } 57 /** Removes button border. */ 46 58 void removeBorder() {} 47 59 48 60 protected: 49 void paintEvent(QPaintEvent * /* pEvent */) {} 50 void resizeEvent(QResizeEvent *pEvent); 61 62 /** Handles paint @a pEvent. */ 63 virtual void paintEvent(QPaintEvent *pEvent) /* override */ { Q_UNUSED(pEvent); } 64 /** Handles resize @a pEvent. */ 65 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 51 66 52 67 private: 68 69 /** Holds the wrapped cocoa button instance. */ 53 70 UICocoaButton *m_pButton; 54 71 }; 55 72 56 /******************************************************************************** 57 * 58 * A reset button in the native Cocoa version. 59 * 60 ********************************************************************************/ 61 class UIResetButton: public QAbstractButton 73 74 /** QAbstractButton subclass, used as mini cancel button. */ 75 class UIHelpButton : public QPushButton 62 76 { 63 77 Q_OBJECT; 64 78 65 79 public: 66 UIResetButton(QWidget *pParent = 0);67 80 68 void setText(const QString &strText) { m_pButton->setText(strText); } 69 void setToolTip(const QString &strTip) { m_pButton->setToolTip(strTip); } 70 void removeBorder() {} 81 /** Constructs help-button passing @a pParent to the base-class. */ 82 UIHelpButton(QWidget *pParent = 0); 83 84 /** Defines button @a strToolTip. */ 85 void setToolTip(const QString &strToolTip) { m_pButton->setToolTip(strToolTip); } 86 87 /** Inits this button from pOther. */ 88 void initFrom(QPushButton *pOther) { Q_UNUSED(pOther); } 71 89 72 90 protected: 73 void paintEvent(QPaintEvent * /* pEvent */) {} 74 void resizeEvent(QResizeEvent *pEvent); 91 92 /** Handles paint @a pEvent. */ 93 virtual void paintEvent(QPaintEvent *pEvent) /* override */ { Q_UNUSED(pEvent); } 75 94 76 95 private: 96 97 /** Holds the wrapped cocoa button instance. */ 77 98 UICocoaButton *m_pButton; 78 99 }; 79 100 80 /******************************************************************************** 81 * 82 * A help button in the native Cocoa version. 83 * 84 ********************************************************************************/ 85 class UIHelpButton: public QPushButton 101 #else /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */ 102 103 /** QAbstractButton subclass, used as mini cancel button. */ 104 class UIMiniCancelButton : public QIWithRetranslateUI<QIToolButton> 86 105 { 87 106 Q_OBJECT; 88 107 89 108 public: 90 UIHelpButton(QWidget *pParent = 0);91 109 92 void setToolTip(const QString &strTip) { m_pButton->setToolTip(strTip); } 93 94 void initFrom(QPushButton * /* pOther */) {} 110 /** Constructs mini cancel-button passing @a pParent to the base-class. */ 111 UIMiniCancelButton(QWidget *pParent = 0); 95 112 96 113 protected: 97 void paintEvent(QPaintEvent * /* pEvent */) {}98 114 99 private: 100 UICocoaButton *m_pButton;115 /** Handles translation event. */ 116 virtual void retranslateUi() /* override */ {}; 101 117 }; 102 118 103 /******************************************************************************** 104 * 105 * A segmented button in the native Cocoa version. 106 * 107 ********************************************************************************/ 108 class UIRoundRectSegmentedButton: public UICocoaSegmentedButton 119 120 /** QAbstractButton subclass, used as mini cancel button. */ 121 class UIHelpButton : public QIWithRetranslateUI<QPushButton> 109 122 { 110 123 Q_OBJECT; 111 124 112 125 public: 113 UIRoundRectSegmentedButton(QWidget *pParent, int cCount);114 };115 126 116 class UITexturedSegmentedButton: public UICocoaSegmentedButton 117 { 118 Q_OBJECT; 127 /** Constructs help-button passing @a pParent to the base-class. */ 128 UIHelpButton(QWidget *pParent = 0); 119 129 120 public: 121 UITexturedSegmentedButton(QWidget *pParent, int cCount);122 };130 # ifdef VBOX_WS_MAC 131 /** Destructs help-button. */ 132 ~UIHelpButton(); 123 133 124 /******************************************************************************** 125 * 126 * A search field in the native Cocoa version. 127 * 128 ********************************************************************************/ 129 class UISearchField: public UICocoaSearchField 130 { 131 Q_OBJECT; 134 /** Returns size-hint. */ 135 QSize sizeHint() const; 136 # endif /* VBOX_WS_MAC */ 132 137 133 public: 134 UISearchField(QWidget *pParent); 135 }; 136 137 #else /* VBOX_DARWIN_USE_NATIVE_CONTROLS */ 138 139 /* VBox includes */ 140 #include "QIToolButton.h" 141 142 /* Qt includes */ 143 #include <QLineEdit> 144 145 /* Qt forward declarations */ 146 class QSignalMapper; 147 148 /******************************************************************************** 149 * 150 * A mini cancel button for the other OS's. 151 * 152 ********************************************************************************/ 153 class UIMiniCancelButton: public QIWithRetranslateUI<QIToolButton> 154 { 155 Q_OBJECT; 156 157 public: 158 UIMiniCancelButton(QWidget *pParent = 0); 159 160 protected: 161 void retranslateUi() {}; 162 }; 163 164 /******************************************************************************** 165 * 166 * A reset button for the other OS's (same as the cancel button for now) 167 * 168 ********************************************************************************/ 169 class UIResetButton: public UIMiniCancelButton 170 { 171 Q_OBJECT; 172 173 public: 174 UIResetButton(QWidget *pParent = 0) 175 : UIMiniCancelButton(pParent) {} 176 }; 177 178 /******************************************************************************** 179 * 180 * A help button for the other OS's. 181 * 182 ********************************************************************************/ 183 class UIHelpButton: public QIWithRetranslateUI<QPushButton> 184 { 185 Q_OBJECT; 186 187 public: 188 UIHelpButton(QWidget *pParent = 0); 189 #ifdef VBOX_WS_MAC 190 ~UIHelpButton(); 191 QSize sizeHint() const; 192 #endif /* VBOX_WS_MAC */ 193 138 /** Inits this button from pOther. */ 194 139 void initFrom(QPushButton *pOther); 195 140 196 141 protected: 142 143 /** Handles translation event. */ 197 144 void retranslateUi(); 198 145 199 #ifdef VBOX_WS_MAC 200 void paintEvent(QPaintEvent *pEvent); 146 # ifdef VBOX_WS_MAC 147 /** Handles button hit as certain @a position. */ 148 bool hitButton(const QPoint &position) const; 201 149 202 bool hitButton(const QPoint &pos) const; 150 /** Handles paint @a pEvent. */ 151 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 203 152 204 void mousePressEvent(QMouseEvent *pEvent); 205 void mouseReleaseEvent(QMouseEvent *pEvent); 206 void leaveEvent(QEvent *pEvent); 153 /** Handles mouse-press @a pEvent. */ 154 virtual void mousePressEvent(QMouseEvent *pEvent) /* override */; 155 /** Handles mouse-release @a pEvent. */ 156 virtual void mouseReleaseEvent(QMouseEvent *pEvent) /* override */; 157 /** Handles mouse-leave @a pEvent. */ 158 virtual void leaveEvent(QEvent *pEvent) /* override */; 207 159 208 160 private: 209 /* Private member vars */ 161 162 /** Holds the pressed button instance. */ 210 163 bool m_pButtonPressed; 211 164 165 /** Holds the button size. */ 212 166 QSize m_size; 167 168 /** Holds the normal pixmap instance. */ 213 169 QPixmap *m_pNormalPixmap; 170 /** Holds the pressed pixmap instance. */ 214 171 QPixmap *m_pPressedPixmap; 172 173 /** Holds the button mask instance. */ 215 174 QImage *m_pMask; 175 176 /** Holds the button rect. */ 216 177 QRect m_BRect; 217 # endif /* VBOX_WS_MAC */178 # endif /* VBOX_WS_MAC */ 218 179 }; 219 180 220 /******************************************************************************** 221 * 222 * A segmented button for the other OS's. 223 * 224 ********************************************************************************/ 225 class UIRoundRectSegmentedButton: public QWidget 226 { 227 Q_OBJECT; 181 #endif /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */ 228 182 229 public:230 UIRoundRectSegmentedButton(QWidget *pParent, int aCount);231 ~UIRoundRectSegmentedButton();232 183 233 int count() const; 184 #endif /* !___UISpecialControls_h___ */ 234 185 235 void setTitle(int iSegment, const QString &aTitle);236 void setToolTip(int iSegment, const QString &strTip);237 void setIcon(int iSegment, const QIcon &icon);238 void setEnabled(int iSegment, bool fEnabled);239 240 void setSelected(int iSegment);241 void animateClick(int iSegment);242 243 signals:244 void clicked(int iSegment);245 246 protected:247 /* Protected member vars */248 QList<QIToolButton*> m_pButtons;249 QSignalMapper *m_pSignalMapper;250 };251 252 class UITexturedSegmentedButton: public UIRoundRectSegmentedButton253 {254 Q_OBJECT;255 256 public:257 UITexturedSegmentedButton(QWidget *pParent, int cCount);258 };259 260 /********************************************************************************261 *262 * A search field for the other OS's.263 *264 ********************************************************************************/265 class UISearchField: public QLineEdit266 {267 Q_OBJECT;268 269 public:270 UISearchField(QWidget *pParent);271 272 void markError();273 void unmarkError();274 275 private:276 /* Private member vars */277 QBrush m_baseBrush;278 };279 280 #endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */281 282 #endif /* ___VBoxSpecialControls_h__ */283
Note:
See TracChangeset
for help on using the changeset viewer.