VirtualBox

Changeset 71577 in vbox for trunk/src


Ignore:
Timestamp:
Mar 29, 2018 5:13:05 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for UISpecialControls and UICocoaSpecialControls stuff.

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  
    2626class QFrame;
    2727class QIToolButton;
    28 class UIRoundRectSegmentedButton;
    2928
    3029/** 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  
    3131class QLabel;
    3232class QIToolButton;
    33 class UISearchField;
    3433class UIVMLogViewerSearchField;
    3534class UIVMLogViewerWidget;
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.h

    r69500 r71577  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VBoxCocoaSpecialControls class declaration.
     3 * VBox Qt GUI - UICocoaSpecialControls class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef ___darwin_UICocoaSpecialControls_h__
    19 #define ___darwin_UICocoaSpecialControls_h__
     18#ifndef ___UICocoaSpecialControls_h___
     19#define ___UICocoaSpecialControls_h___
    2020
    21 /* VBox includes */
     21/* Qt includes: */
     22#include <QMacCocoaViewContainer>
     23#include <QWidget>
     24
     25/* GUI includes: */
    2226#include "VBoxCocoaHelper.h"
    2327
    24 /* Qt includes */
    25 #include <QWidget>
    26 #include <QMacCocoaViewContainer>
     28/* Add typedefs for Cocoa types: */
     29ADD_COCOA_NATIVE_REF(NSButton);
    2730
    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. */
     33class UICocoaButton : public QMacCocoaViewContainer
    3434{
    3535    Q_OBJECT
    3636
     37signals:
     38
     39    /** Notifies about button click and whether it's @a fChecked. */
     40    void clicked(bool fChecked = false);
     41
    3742public:
     43
     44    /** Cocoa button types. */
    3845    enum CocoaButtonType
    3946    {
     
    4350    };
    4451
    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. */
    4656    ~UICocoaButton();
    4757
     58    /** Returns size-hint. */
    4859    QSize sizeHint() const;
    4960
    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);
    5265
     66    /** Handles button click. */
    5367    void onClicked();
    5468
    55 signals:
    56     void clicked(bool fChecked = false);
     69private:
    5770
    58 private:
     71    /** Returns native cocoa button reference. */
    5972    NativeNSButtonRef nativeRef() const { return static_cast<NativeNSButtonRef>(cocoaView()); }
    6073};
    6174
    62 class UICocoaSegmentedButton: public QMacCocoaViewContainer
    63 {
    64     Q_OBJECT
     75#endif /* !___UICocoaSpecialControls_h___ */
    6576
    66 public:
    67     enum CocoaSegmentType
    68     {
    69         RoundRectSegment,
    70         TexturedRoundedSegment
    71     };
    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 QMacCocoaViewContainer
    103 {
    104     Q_OBJECT
    105 
    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  
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    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: */
    4219#include <QMacCocoaViewContainer>
    4320
    44 /* Other VBox includes: */
    45 #include <iprt/assert.h>
     21/* GUI includes: */
     22#include "VBoxUtils-darwin.h"
     23#include "UICocoaSpecialControls.h"
    4624
    47 /* Forward declarations: */
    48 class UIAccessibilityInterfaceForUICocoaSegmentedButton;
     25/* System includes: */
     26#import <AppKit/NSButton.h>
    4927
    5028
    51 /*
    52  * Private interfaces
    53  */
    54 @interface UIButtonTargetPrivate: NSObject
     29/** Private button-target interface. */
     30@interface UIButtonTargetPrivate : NSObject
    5531{
    56     UICocoaButton *mRealTarget;
     32    UICocoaButton *m_pRealTarget;
    5733}
    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;
    6239@end
    6340
    64 @interface UISegmentedButtonTargetPrivate: NSObject
    65 {
    66     UICocoaSegmentedButton *mRealTarget;
    67 }
    68 -(id)initWithObject1:(UICocoaSegmentedButton*)object;
    69 -(IBAction)segControlClicked:(id)sender;
    70 @end
    7141
    72 @interface UISearchFieldCellPrivate: NSSearchFieldCell
    73 {
    74     NSColor *mBGColor;
    75 }
    76 - (void)setBackgroundColor:(NSColor*)aBGColor;
    77 @end
     42/*********************************************************************************************************************************
     43*   Class UIButtonTargetPrivate implementation.                                                                                  *
     44*********************************************************************************************************************************/
    7845
    79 @interface UISearchFieldPrivate: NSSearchField
    80 {
    81     UICocoaSearchField *mRealTarget;
    82 }
    83 -(id)initWithObject2:(UICocoaSearchField*)object;
    84 @end
    85 
    86 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
    87 @interface UISearchFieldDelegatePrivate: NSObject<NSTextFieldDelegate>
    88 #else
    89 @interface UISearchFieldDelegatePrivate: NSObject
    90 #endif
    91 {}
    92 @end
    93 
    94 /*
    95  * Implementation of the private interfaces
    96  */
    9746@implementation UIButtonTargetPrivate
    98 -(id)initWithObjectAndLionTrouble:(UICocoaButton*)object
     47-(id)initWithObjectAndLionTrouble:(UICocoaButton*)pObject
    9948{
    10049    self = [super init];
    10150
    102     mRealTarget = object;
     51    m_pRealTarget = pObject;
    10352
    10453    return self;
    10554}
    10655
    107 -(IBAction)clicked:(id)sender
     56-(IBAction)clicked:(id)pSender
    10857{
    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();
    23560}
    23661@end
    23762
    23863
    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*********************************************************************************************************************************/
    24767
    248 /*
    249  * Public classes
    250  */
    251 UICocoaButton::UICocoaButton(QWidget *pParent, CocoaButtonType type)
     68UICocoaButton::UICocoaButton(QWidget *pParent, CocoaButtonType enmType)
    25269    : QMacCocoaViewContainer(0, pParent)
    25370{
    25471    /* Prepare auto-release pool: */
    255     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     72    NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
    25673
    25774    /* Prepare native button reference: */
     
    26077
    26178    /* Configure button: */
    262     switch (type)
     79    switch (enmType)
    26380    {
    26481        case HelpButton:
     
    317134
    318135    /* Cleanup auto-release pool: */
    319     [pool release];
     136    [pPool release];
    320137}
    321138
     
    330147}
    331148
    332 void UICocoaButton::setText(const QString& strText)
     149void UICocoaButton::setText(const QString &strText)
    333150{
    334151    QString s(strText);
    335     /* Set it for accessibility reasons as alternative title */
     152    /* Set it for accessibility reasons as alternative title: */
    336153    [nativeRef() setAlternateTitle: ::darwinQStringToNSString(s.remove('&'))];
    337154}
    338155
    339 void UICocoaButton::setToolTip(const QString& strTip)
     156void UICocoaButton::setToolTip(const QString &strToolTip)
    340157{
    341     [nativeRef() setToolTip: ::darwinQStringToNSString(strTip)];
     158    [nativeRef() setToolTip: ::darwinQStringToNSString(strToolTip)];
    342159}
    343160
     
    347164}
    348165
    349 
    350 /** QAccessibleInterface extension used as an accessibility interface for segmented-button segment. */
    351 class UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment : public QAccessibleInterface
    352 {
    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 QAccessibleWidget
    404 {
    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() const
    465 {
    466     return m_pParent;
    467 }
    468 
    469 QRect UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::rect() const
    470 {
    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 */) const
    478 {
    479     /* Return the segment description: */
    480     return m_pParent->button()->description(m_iIndex);
    481 }
    482 
    483 QAccessible::State UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::state() const
    484 {
    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 class
    542      * 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() const
    554 {
    555     return [nativeRef() segmentCount];
    556 }
    557 
    558 bool UICocoaSegmentedButton::isSelected(int iSegment) const
    559 {
    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) const
    569 {
    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() const
    579 {
    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 QAccessibleWidget
    633 {
    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 accessible
    653         // 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 class
    693      * 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() const
    711 {
    712     NSRect frame = [nativeRef() frame];
    713     return QSize(frame.size.width, frame.size.height);
    714 }
    715 
    716 QString UICocoaSearchField::text() const
    717 {
    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  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VBoxSpecialButtons implementation.
     3 * VBox Qt GUI - UISpecialControls implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    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: */
    2332# include "UIIconPool.h"
    2433# include "UISpecialControls.h"
    25 
    26 /* Global includes */
    27 # include <QHBoxLayout>
    2834
    2935#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    3238#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    3339
    34 /********************************************************************************
    35  *
    36  * A mini cancel button in the native Cocoa version.
    37  *
    38  ********************************************************************************/
     40
     41/*********************************************************************************************************************************
     42*   Class UIMiniCancelButton implementation.                                                                                     *
     43*********************************************************************************************************************************/
     44
    3945UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
    40   : QAbstractButton(pParent)
     46    : QAbstractButton(pParent)
    4147{
    4248    setShortcut(QKeySequence(Qt::Key_Escape));
    4349    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()));
    4651    setFixedSize(m_pButton->size());
    4752}
    4853
    49 void UIMiniCancelButton::resizeEvent(QResizeEvent * /* pEvent */)
     54void UIMiniCancelButton::resizeEvent(QResizeEvent *)
    5055{
    5156    m_pButton->resize(size());
    5257}
    5358
    54 /********************************************************************************
    55  *
    56  * A rest button in the native Cocoa version.
    57  *
    58  ********************************************************************************/
    59 UIResetButton::UIResetButton(QWidget *pParent /* = 0 */)
    60   : QAbstractButton(pParent)
     59
     60/*********************************************************************************************************************************
     61*   Class UIHelpButton implementation.                                                                                           *
     62*********************************************************************************************************************************/
     63
     64UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */)
     65    : QPushButton(pParent)
    6166{
    62     m_pButton = new UICocoaButton(this, UICocoaButton::ResetButton);
    63     connect(m_pButton, SIGNAL(clicked()),
    64             this, SIGNAL(clicked()));
     67    setShortcut(QKeySequence(QKeySequence::HelpContents));
     68    m_pButton = new UICocoaButton(this, UICocoaButton::HelpButton);
     69    connect(m_pButton, SIGNAL(clicked()), this, SIGNAL(clicked()));
    6570    setFixedSize(m_pButton->size());
    6671}
    6772
    68 void UIResetButton::resizeEvent(QResizeEvent * /* pEvent */)
    69 {
    70     m_pButton->resize(size());
    71 }
    7273
    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 */
    8775
    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 }
    9776
    98 UITexturedSegmentedButton::UITexturedSegmentedButton(QWidget *pParent, int cCount)
    99   : UICocoaSegmentedButton(pParent, cCount, UICocoaSegmentedButton::TexturedRoundedSegment)
    100 {
    101 }
     77/*********************************************************************************************************************************
     78*   Class UIMiniCancelButton implementation.                                                                                     *
     79*********************************************************************************************************************************/
    10280
    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_HEADERS
    116 /* Qt includes */
    117 #  include <QPainter>
    118 #  include <QBitmap>
    119 #  include <QMouseEvent>
    120 #  include <QSignalMapper>
    121 # endif
    122 
    123 /********************************************************************************
    124  *
    125  * A mini cancel button for the other OS's.
    126  *
    127  ********************************************************************************/
    12881UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
    129   : QIWithRetranslateUI<QIToolButton>(pParent)
     82    : QIWithRetranslateUI<QIToolButton>(pParent)
    13083{
    13184    setAutoRaise(true);
     
    13588}
    13689
    137 /********************************************************************************
    138  *
    139  * A help button for the other OS's.
    140  *
    141  ********************************************************************************/
     90
     91/*********************************************************************************************************************************
     92*   Class UIHelpButton implementation.                                                                                           *
     93*********************************************************************************************************************************/
     94
    14295/* From: src/gui/styles/qmacstyle_mac.cpp */
    14396static const int PushButtonLeftOffset = 6;
     
    149102    : QIWithRetranslateUI<QPushButton>(pParent)
    150103{
    151 #ifdef VBOX_WS_MAC
     104# ifdef VBOX_WS_MAC
    152105    m_pButtonPressed = false;
    153106    m_pNormalPixmap = new QPixmap(":/help_button_normal_mac_22px.png");
     
    159112                    m_size.width(),
    160113                    m_size.height());
    161 #endif /* VBOX_WS_MAC */
    162     /* Applying language settings */
     114# endif /* VBOX_WS_MAC */
     115
     116    /* Apply language settings: */
    163117    retranslateUi();
    164118}
     
    166120void UIHelpButton::initFrom(QPushButton *pOther)
    167121{
     122    /* Copy settings from pOther: */
    168123    setIcon(pOther->icon());
    169124    setText(pOther->text());
     
    172127    setAutoDefault(pOther->autoDefault());
    173128    setDefault(pOther->isDefault());
    174     /* Applying language settings */
     129
     130    /* Apply language settings: */
    175131    retranslateUi();
    176132}
     
    183139}
    184140
    185 #ifdef VBOX_WS_MAC
     141# ifdef VBOX_WS_MAC
    186142UIHelpButton::~UIHelpButton()
    187143{
     
    197153}
    198154
    199 void UIHelpButton::paintEvent(QPaintEvent * /* pEvent */)
     155void UIHelpButton::paintEvent(QPaintEvent *)
    200156{
    201157    QPainter painter(this);
     
    203159}
    204160
    205 bool UIHelpButton::hitButton(const QPoint &pos) const
     161bool UIHelpButton::hitButton(const QPoint &position) const
    206162{
    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;
    210166    else
    211167        return false;
     
    227183}
    228184
    229 void UIHelpButton::leaveEvent(QEvent * pEvent)
     185void UIHelpButton::leaveEvent(QEvent *pEvent)
    230186{
    231187    QPushButton::leaveEvent(pEvent);
     
    233189    update();
    234190}
    235 #endif /* VBOX_WS_MAC */
     191# endif /* VBOX_WS_MAC */
    236192
    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);
    246193
    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 */
    263195
    264 }
    265 
    266 UIRoundRectSegmentedButton::~UIRoundRectSegmentedButton()
    267 {
    268     delete m_pSignalMapper;
    269     qDeleteAll(m_pButtons);
    270 }
    271 
    272 int UIRoundRectSegmentedButton::count() const
    273 {
    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  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VBoxSpecialButtons declarations.
     3 * VBox Qt GUI - UISpecialControls declarations.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1919#define ___VBoxSpecialControls_h__
    2020
    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: */
    2228#include "QIWithRetranslateUI.h"
     29#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
     30# include "UICocoaSpecialControls.h"
     31#else
     32# include "QIToolButton.h"
     33#endif
    2334
    24 /* Qt includes */
    25 #include <QPushButton>
     35/* Forward declarations: */
     36#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
     37class UICocoaButton;
     38#endif
     39
    2640
    2741#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    2842
    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. */
     44class UIMiniCancelButton : public QAbstractButton
    3845{
    3946    Q_OBJECT;
    4047
    4148public:
     49
     50    /** Constructs mini cancel-button passing @a pParent to the base-class. */
    4251    UIMiniCancelButton(QWidget *pParent = 0);
    4352
     53    /** Defines button @a strText. */
    4454    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. */
    4658    void removeBorder() {}
    4759
    4860protected:
    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 */;
    5166
    5267private:
     68
     69    /** Holds the wrapped cocoa button instance. */
    5370    UICocoaButton *m_pButton;
    5471};
    5572
    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. */
     75class UIHelpButton : public QPushButton
    6276{
    6377    Q_OBJECT;
    6478
    6579public:
    66     UIResetButton(QWidget *pParent = 0);
    6780
    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); }
    7189
    7290protected:
    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); }
    7594
    7695private:
     96
     97    /** Holds the wrapped cocoa button instance. */
    7798    UICocoaButton *m_pButton;
    7899};
    79100
    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. */
     104class UIMiniCancelButton : public QIWithRetranslateUI<QIToolButton>
    86105{
    87106    Q_OBJECT;
    88107
    89108public:
    90     UIHelpButton(QWidget *pParent = 0);
    91109
    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);
    95112
    96113protected:
    97     void paintEvent(QPaintEvent * /* pEvent */) {}
    98114
    99 private:
    100     UICocoaButton *m_pButton;
     115    /** Handles translation event. */
     116    virtual void retranslateUi() /* override */ {};
    101117};
    102118
    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. */
     121class UIHelpButton : public QIWithRetranslateUI<QPushButton>
    109122{
    110123    Q_OBJECT;
    111124
    112125public:
    113     UIRoundRectSegmentedButton(QWidget *pParent, int cCount);
    114 };
    115126
    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);
    119129
    120 public:
    121     UITexturedSegmentedButton(QWidget *pParent, int cCount);
    122 };
     130# ifdef VBOX_WS_MAC
     131    /** Destructs help-button. */
     132    ~UIHelpButton();
    123133
    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 */
    132137
    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. */
    194139    void initFrom(QPushButton *pOther);
    195140
    196141protected:
     142
     143    /** Handles translation event. */
    197144    void retranslateUi();
    198145
    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;
    201149
    202     bool hitButton(const QPoint &pos) const;
     150    /** Handles paint @a pEvent. */
     151    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
    203152
    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 */;
    207159
    208160private:
    209     /* Private member vars */
     161
     162    /** Holds the pressed button instance. */
    210163    bool m_pButtonPressed;
    211164
     165    /** Holds the button size. */
    212166    QSize m_size;
     167
     168    /** Holds the normal pixmap instance. */
    213169    QPixmap *m_pNormalPixmap;
     170    /** Holds the pressed pixmap instance. */
    214171    QPixmap *m_pPressedPixmap;
     172
     173    /** Holds the button mask instance. */
    215174    QImage *m_pMask;
     175
     176    /** Holds the button rect. */
    216177    QRect m_BRect;
    217 #endif /* VBOX_WS_MAC */
     178# endif /* VBOX_WS_MAC */
    218179};
    219180
    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 */
    228182
    229 public:
    230     UIRoundRectSegmentedButton(QWidget *pParent, int aCount);
    231     ~UIRoundRectSegmentedButton();
    232183
    233     int count() const;
     184#endif /* !___UISpecialControls_h___ */
    234185
    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 UIRoundRectSegmentedButton
    253 {
    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 QLineEdit
    266 {
    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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette