VirtualBox

Changeset 30188 in vbox


Ignore:
Timestamp:
Jun 15, 2010 9:06:21 AM (14 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: some improvements to the special controls

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 added
4 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r30122 r30188  
    322322        src/widgets/VBoxSpecialControls.h \
    323323        src/widgets/VBoxWarningPane.h \
     324        src/widgets/UISpacerWidgets.h \
    324325        src/runtime/UISession.h \
    325326        src/runtime/UIActionsPool.h \
     
    526527        src/darwin/UICocoaApplication.mm \
    527528        src/darwin/VBoxUtils-darwin-cocoa.mm \
    528         src/darwin/VBoxCocoaSpecialControls.mm
     529        src/darwin/UICocoaSpecialControls.mm
    529530 VirtualBox_QT_MOCHDRS.darwin = \
    530         src/darwin/VBoxCocoaSpecialControls.h
     531        src/darwin/UICocoaSpecialControls.h
    531532endif
    532533
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMLogViewer.cpp

    r29972 r30188  
    359359    mButtonsNextPrev = new VBoxSegmentedButton (2, this);
    360360    mButtonsNextPrev->setEnabled (0, false);
     361    mButtonsNextPrev->setEnabled (1, false);
     362#ifndef Q_WS_MAC
     363    /* No icons on the Mac */
    361364    mButtonsNextPrev->setIcon (0, VBoxGlobal::iconSet (":/list_movedown_16px.png",
    362365                                                       ":/list_movedown_disabled_16px.png"));
    363     mButtonsNextPrev->setEnabled (1, false);
    364366    mButtonsNextPrev->setIcon (1, VBoxGlobal::iconSet (":/list_moveup_16px.png",
    365367                                                       ":/list_moveup_disabled_16px.png"));
     368#endif /* !Q_WS_MAC */
    366369    connect (mButtonsNextPrev, SIGNAL (clicked (int)), this, SLOT (find (int)));
    367370
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaSpecialControls.h

    r30187 r30188  
    66
    77/*
    8  * Copyright (C) 2009 Oracle Corporation
     8 * Copyright (C) 2009-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717 */
    1818
    19 #ifndef ___darwin_VBoxCocoaSpecialControls_h__
    20 #define ___darwin_VBoxCocoaSpecialControls_h__
     19#ifndef ___darwin_UICocoaSpecialControls_h__
     20#define ___darwin_UICocoaSpecialControls_h__
    2121
    2222/* VBox includes */
     
    2424
    2525/* Qt includes */
    26 #include <QMacCocoaViewContainer>
     26#include <QWidget>
     27
     28/* Qt forward includes */
     29class QMacCocoaViewContainer;
    2730
    2831/* Add typedefs for Cocoa types */
    29 ADD_COCOA_NATIVE_REF (NSButton);
    30 ADD_COCOA_NATIVE_REF (NSSegmentedControl);
    31 ADD_COCOA_NATIVE_REF (NSSearchField);
     32ADD_COCOA_NATIVE_REF(NSButton);
     33ADD_COCOA_NATIVE_REF(NSSegmentedControl);
     34ADD_COCOA_NATIVE_REF(NSSearchField);
    3235
    33 class VBoxCocoaButton: public QMacCocoaViewContainer
     36class UICocoaWrapper: public QWidget
     37{
     38public:
     39    UICocoaWrapper(QWidget *pParent = 0);
     40
     41protected:
     42    virtual void resizeEvent(QResizeEvent *pEvent);
     43
     44    QMacCocoaViewContainer *m_pContainer;
     45};
     46
     47class UICocoaButton: public UICocoaWrapper
    3448{
    3549    Q_OBJECT
     
    4357    };
    4458
    45     VBoxCocoaButton (CocoaButtonType aType, QWidget *aParent = 0);
    46     ~VBoxCocoaButton();
     59    UICocoaButton(CocoaButtonType aType, QWidget *pParent = 0);
     60    ~UICocoaButton();
    4761
    4862    QSize sizeHint() const;
    4963
    50     void setText (const QString& aText);
    51     void setToolTip (const QString& aTip);
     64    void setText(const QString& strText);
     65    void setToolTip(const QString& strTip);
    5266
    5367    void onClicked();
    5468
    5569signals:
    56     void clicked (bool checked = false);
    57 
    58 protected:
    59     void resizeEvent(QResizeEvent *pEvent);
     70    void clicked(bool fChecked = false);
    6071
    6172private:
    6273    /* Private member vars */
    63     NativeNSButtonRef mNativeRef;
     74    NativeNSButtonRef m_pNativeRef;
    6475};
    6576
    66 class VBoxCocoaSegmentedButton: public QMacCocoaViewContainer
     77class UICocoaSegmentedButton: public UICocoaWrapper
    6778{
    6879    Q_OBJECT
    6980
    7081public:
    71     VBoxCocoaSegmentedButton (int aCount, QWidget *aParent = 0);
    72     ~VBoxCocoaSegmentedButton();
     82    enum CocoaSegmentType
     83    {
     84        RoundRectSegment,
     85        TexturedRoundedSegment
     86    };
     87
     88    UICocoaSegmentedButton(int count, CocoaSegmentType type = RoundRectSegment, QWidget *pParent = 0);
     89    ~UICocoaSegmentedButton();
    7390
    7491    QSize sizeHint() const;
    7592
    76     void setTitle (int aSegment, const QString &aTitle);
     93    void setTitle(int iSegment, const QString &strTitle);
     94    void setToolTip(int iSegment, const QString &strTip);
     95    void setIcon(int iSegment, const QIcon& icon);
     96    void setEnabled(int iSegment, bool fEnabled);
    7797
    78     void setToolTip (int aSegment, const QString &aTip);
    79 
    80     void setEnabled (int aSegment, bool fEnabled);
    81 
    82     void animateClick (int aSegment);
    83 
    84     void onClicked (int aSegment);
     98    void animateClick(int iSegment);
     99    void onClicked(int iSegment);
    85100
    86101signals:
    87     void clicked (int aSegment, bool aChecked = false);
     102    void clicked(int iSegment, bool fChecked = false);
    88103
    89104private:
    90105    /* Private member vars */
    91     NativeNSSegmentedControlRef mNativeRef;
     106    NativeNSSegmentedControlRef m_pNativeRef;
    92107};
    93108
    94 class VBoxCocoaSearchField: public QMacCocoaViewContainer
     109class UICocoaSearchField: public UICocoaWrapper
    95110{
    96111    Q_OBJECT
    97112
    98113public:
    99     VBoxCocoaSearchField (QWidget* aParent = 0);
    100     ~VBoxCocoaSearchField();
     114    UICocoaSearchField(QWidget* pParent = 0);
     115    ~UICocoaSearchField();
    101116
    102117    QSize sizeHint() const;
    103118
    104119    QString text() const;
    105     void insert (const QString &aText);
    106     void setToolTip (const QString &aTip);
     120    void insert(const QString &strText);
     121    void setToolTip(const QString &strTip);
    107122    void selectAll();
    108123
     
    110125    void unmarkError();
    111126
    112     void onTextChanged (const QString &aText);
     127    void onTextChanged(const QString &strText);
    113128
    114129signals:
    115     void textChanged (const QString& aText);
     130    void textChanged(const QString& strText);
    116131
    117132private:
    118133    /* Private member vars */
    119     NativeNSSearchFieldRef mNativeRef;
     134    NativeNSSearchFieldRef m_pNativeRef;
    120135};
    121136
    122 #endif /* ___darwin_VBoxCocoaSpecialControls_h__ */
     137#endif /* ___darwin_UICocoaSpecialControls_h__ */
    123138
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaSpecialControls.mm

    r30187 r30188  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VBoxCocoaSpecialControls implementation
     5 * UICocoaSpecialControls implementation
    66 */
    77
     
    1919
    2020/* VBox includes */
    21 #include "VBoxCocoaSpecialControls.h"
     21#include "UICocoaSpecialControls.h"
     22#include "VBoxUtils-darwin.h"
    2223#include <VBox/cdefs.h>
    2324
    2425/* System includes */
     26#import <AppKit/NSApplication.h>
     27#import <AppKit/NSBezierPath.h>
    2528#import <AppKit/NSButton.h>
    26 #import <AppKit/NSApplication.h>
     29#import <AppKit/NSFont.h>
    2730#import <AppKit/NSImage.h>
    28 #import <AppKit/NSFont.h>
    2931#import <AppKit/NSSegmentedControl.h>
    30 #import <AppKit/NSBezierPath.h>
    3132
    3233/* Qt includes */
    3334#include <QApplication>
     35#include <QIcon>
    3436#include <QKeyEvent>
    35 
    36 @interface NSButtonTarget: NSObject
    37 {
    38     VBoxCocoaButton *mRealTarget;
    39 }
    40 -(id)initWithObject:(VBoxCocoaButton*)object;
     37#include <QMacCocoaViewContainer>
     38
     39/*
     40 * Private interfaces
     41 */
     42@interface UIButtonTargetPrivate: NSObject
     43{
     44    UICocoaButton *mRealTarget;
     45}
     46-(id)initWithObject:(UICocoaButton*)object;
    4147-(IBAction)clicked:(id)sender;
    4248@end
    4349
    44 @implementation NSButtonTarget
    45 -(id)initWithObject:(VBoxCocoaButton*)object
     50@interface UISegmentedButtonTargetPrivate: NSObject
     51{
     52    UICocoaSegmentedButton *mRealTarget;
     53}
     54-(id)initWithObject1:(UICocoaSegmentedButton*)object;
     55-(IBAction)segControlClicked:(id)sender;
     56@end
     57
     58@interface UISearchFieldCellPrivate: NSSearchFieldCell
     59{
     60    NSColor *mBGColor;
     61}
     62- (void)setBackgroundColor:(NSColor*)aBGColor;
     63@end
     64
     65@interface UISearchFieldPrivate: NSSearchField
     66{
     67    UICocoaSearchField *mRealTarget;
     68}
     69-(id)initWithObject2:(UICocoaSearchField*)object;
     70@end
     71
     72#if MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_6
     73@interface UISearchFieldDelegatePrivate: NSObject<NSTextFieldDelegate>
     74#else
     75@interface UISearchFieldDelegatePrivate: NSObject
     76#endif
     77{}
     78@end
     79
     80/*
     81 * Implementation of the private interfaces
     82 */
     83@implementation UIButtonTargetPrivate
     84-(id)initWithObject:(UICocoaButton*)object
    4685{
    4786    self = [super init];
     
    5897@end
    5998
    60 @interface NSSegmentedButtonTarget: NSObject
    61 {
    62     VBoxCocoaSegmentedButton *mRealTarget;
    63 }
    64 -(id)initWithObject1:(VBoxCocoaSegmentedButton*)object;
     99@implementation UISegmentedButtonTargetPrivate
     100-(id)initWithObject1:(UICocoaSegmentedButton*)object
     101{
     102    self = [super init];
     103
     104    mRealTarget = object;
     105
     106    return self;
     107}
     108
    65109-(IBAction)segControlClicked:(id)sender;
    66 @end
    67 
    68 @implementation NSSegmentedButtonTarget
    69 -(id)initWithObject1:(VBoxCocoaSegmentedButton*)object
     110{
     111    mRealTarget->onClicked([sender selectedSegment]);
     112}
     113@end
     114
     115@implementation UISearchFieldCellPrivate
     116-(id)init
     117{
     118    if ((self = [super init]))
     119        mBGColor = Nil;
     120    return self;
     121}
     122
     123- (void)dealloc
     124{
     125    [mBGColor release];
     126    [super dealloc];
     127}
     128
     129- (void)setBackgroundColor:(NSColor*)aBGColor
     130{
     131    if (mBGColor != aBGColor)
     132    {
     133        [mBGColor release];
     134        mBGColor = [aBGColor retain];
     135    }
     136}
     137
     138- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
     139{
     140    if (mBGColor != Nil)
     141    {
     142        [mBGColor setFill];
     143        NSRect frame = cellFrame;
     144        double radius = RT_MIN(NSWidth(frame), NSHeight(frame)) / 2.0;
     145        [[NSBezierPath bezierPathWithRoundedRect:frame xRadius:radius yRadius:radius] fill];
     146    }
     147
     148    [super drawInteriorWithFrame:cellFrame inView:controlView];
     149}
     150@end
     151
     152@implementation UISearchFieldPrivate
     153+ (Class)cellClass
     154{
     155    return [UISearchFieldCellPrivate class];
     156}
     157
     158-(id)initWithObject2:(UICocoaSearchField*)object
    70159{
    71160    self = [super init];
     
    73162    mRealTarget = object;
    74163
    75     return self;
    76 }
    77 
    78 -(IBAction)segControlClicked:(id)sender;
    79 {
    80     mRealTarget->onClicked([sender selectedSegment]);
    81 }
    82 @end
    83 
    84 @interface VBSearchField: NSSearchField
    85 {
    86     VBoxCocoaSearchField *mRealTarget;
    87 }
    88 -(id)initWithObject2:(VBoxCocoaSearchField*)object;
    89 @end
    90 
    91 @implementation VBSearchField
    92 -(id)initWithObject2:(VBoxCocoaSearchField*)object
    93 {
    94     self = [super init];
    95 
    96     mRealTarget = object;
    97164
    98165    return self;
     
    113180    {
    114181        QKeyEvent ke(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
    115         QApplication::sendEvent (mRealTarget, &ke);
     182        QApplication::sendEvent(mRealTarget, &ke);
    116183    }
    117184    else if (ch == 27) /* Escape */
    118185    {
    119186        QKeyEvent ke(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
    120         QApplication::sendEvent (mRealTarget, &ke);
     187        QApplication::sendEvent(mRealTarget, &ke);
    121188    }
    122189    else if (ch == NSF3FunctionKey)
    123190    {
    124191        QKeyEvent ke(QEvent::KeyPress, Qt::Key_F3, [theEvent modifierFlags] & NSShiftKeyMask ? Qt::ShiftModifier : Qt::NoModifier);
    125         QApplication::sendEvent (mRealTarget, &ke);
     192        QApplication::sendEvent(mRealTarget, &ke);
    126193    }
    127194
     
    137204- (void)textDidChange:(NSNotification *)aNotification
    138205{
    139     mRealTarget->onTextChanged (::darwinNSStringToQString ([[aNotification object] string]));
    140 }
    141 @end
    142 
    143 #if MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_6
    144 @interface VBSearchFieldDelegate: NSObject<NSTextFieldDelegate>
    145 #else
    146 @interface VBSearchFieldDelegate: NSObject
    147 #endif
    148 {}
    149 @end
    150 @implementation VBSearchFieldDelegate
     206    mRealTarget->onTextChanged(::darwinNSStringToQString([[aNotification object] string]));
     207}
     208@end
     209
     210@implementation UISearchFieldDelegatePrivate
    151211-(BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
    152212{
    153 //    NSLog (NSStringFromSelector (commandSelector));
     213//    NSLog(NSStringFromSelector(commandSelector));
    154214    /* Don't execute the selector for Enter & Escape. */
    155215    if (   commandSelector == @selector(insertNewline:)
     
    160220@end
    161221
    162 @interface VBSearchFieldCell: NSSearchFieldCell
    163 {
    164     NSColor *mBGColor;
    165 }
    166 - (void)setBackgroundColor:(NSColor*)aBGColor;
    167 @end
    168 
    169 @implementation VBSearchFieldCell
    170 - (void)setBackgroundColor:(NSColor*)aBGColor
    171 {
    172     if (mBGColor != aBGColor)
    173     {
    174         [mBGColor release];
    175         mBGColor = [aBGColor retain];
    176     }
    177 }
    178 
    179 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
    180 {
    181     if (mBGColor)
    182     {
    183         [mBGColor setFill];
    184         NSRect frame = cellFrame;
    185         frame.size.height -= 1;
    186         frame.origin.y += 1;
    187         double radius = RT_MIN(frame.size.width, frame.size.height) / 2.0;
    188         [[NSBezierPath bezierPathWithRoundedRect:frame xRadius:radius yRadius:radius] fill];
    189     }
    190 
    191     [super drawInteriorWithFrame:cellFrame inView:controlView];
    192 }
    193 @end
    194 
    195 NSRect darwinCenterRectVerticalTo (NSRect aRect, const NSRect& aToRect)
     222
     223/*
     224 * Helper functions
     225 */
     226NSRect darwinCenterRectVerticalTo(NSRect aRect, const NSRect& aToRect)
    196227{
    197228    aRect.origin.y = (aToRect.size.height - aRect.size.height) / 2.0;
     
    199230}
    200231
    201 VBoxCocoaButton::VBoxCocoaButton (CocoaButtonType aType, QWidget *aParent /* = 0 */)
    202   : QMacCocoaViewContainer (0, aParent)
    203 {
    204     setContentsMargins(0, 0, 0, 0);
     232QImage toGray(const QImage& image)
     233{
     234    QImage result = image.convertToFormat(QImage::Format_ARGB32);
     235    for (int i=0; i < result.height(); ++i)
     236    {
     237        QRgb *pScanLine = (QRgb *)result.scanLine(i);
     238        for (int j=0; j < result.width(); ++j)
     239        {
     240            const int g = qGray(pScanLine[j]);
     241            pScanLine[j] = qRgba(g, g, g, qAlpha(pScanLine[j]));
     242        }
     243    }
     244    return result;
     245}
     246
     247/*
     248 * Public classes
     249 */
     250UICocoaWrapper::UICocoaWrapper(QWidget *pParent /* = 0 */)
     251    : QWidget(pParent)
     252    , m_pContainer(0)
     253{
     254}
     255
     256void UICocoaWrapper::resizeEvent(QResizeEvent *pEvent)
     257{
     258    if (m_pContainer)
     259        m_pContainer->resize(pEvent->size());
     260    QWidget::resizeEvent(pEvent);
     261}
     262
     263UICocoaButton::UICocoaButton(CocoaButtonType aType, QWidget *pParent /* = 0 */)
     264  : UICocoaWrapper(pParent)
     265{
     266    NSRect initFrame;
     267
    205268    switch (aType)
    206269    {
    207270        case HelpButton:
    208271        {
    209             mNativeRef = [[NSButton alloc] init];
    210             [mNativeRef setTitle: @""];
    211             [mNativeRef setBezelStyle: NSHelpButtonBezelStyle];
    212             [mNativeRef setBordered: YES];
    213             [mNativeRef setAlignment: NSCenterTextAlignment];
    214             [mNativeRef sizeToFit];
    215             NSRect frame = [mNativeRef frame];
    216             frame.size.width += 12; /* Margin */
    217             [mNativeRef setFrame:frame];
     272            m_pNativeRef = [[NSButton alloc] init];
     273            [m_pNativeRef setTitle: @""];
     274            [m_pNativeRef setBezelStyle: NSHelpButtonBezelStyle];
     275            [m_pNativeRef setBordered: YES];
     276            [m_pNativeRef setAlignment: NSCenterTextAlignment];
     277            [m_pNativeRef sizeToFit];
     278            initFrame = [m_pNativeRef frame];
     279            initFrame.size.width += 12; /* Margin */
     280            [m_pNativeRef setFrame:initFrame];
    218281            break;
    219282        };
    220283        case CancelButton:
    221284        {
    222             mNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)];
    223             [mNativeRef setTitle: @""];
    224             [mNativeRef setBezelStyle:NSShadowlessSquareBezelStyle];
    225             [mNativeRef setButtonType:NSMomentaryChangeButton];
    226             [mNativeRef setImage: [NSImage imageNamed: NSImageNameStopProgressFreestandingTemplate]];
    227             [mNativeRef setBordered: NO];
    228             [[mNativeRef cell] setImageScaling: NSImageScaleProportionallyDown];
     285            m_pNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)];
     286            [m_pNativeRef setTitle: @""];
     287            [m_pNativeRef setBezelStyle:NSShadowlessSquareBezelStyle];
     288            [m_pNativeRef setButtonType:NSMomentaryChangeButton];
     289            [m_pNativeRef setImage: [NSImage imageNamed: NSImageNameStopProgressFreestandingTemplate]];
     290            [m_pNativeRef setBordered: NO];
     291            [[m_pNativeRef cell] setImageScaling: NSImageScaleProportionallyDown];
     292            initFrame = [m_pNativeRef frame];
    229293            break;
    230294        }
    231295        case ResetButton:
    232296        {
    233             mNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)];
    234             [mNativeRef setTitle: @""];
    235             [mNativeRef setBezelStyle:NSShadowlessSquareBezelStyle];
    236             [mNativeRef setButtonType:NSMomentaryChangeButton];
    237             [mNativeRef setImage: [NSImage imageNamed: NSImageNameRefreshFreestandingTemplate]];
    238             [mNativeRef setBordered: NO];
    239             [[mNativeRef cell] setImageScaling: NSImageScaleProportionallyDown];
     297            m_pNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)];
     298            [m_pNativeRef setTitle: @""];
     299            [m_pNativeRef setBezelStyle:NSShadowlessSquareBezelStyle];
     300            [m_pNativeRef setButtonType:NSMomentaryChangeButton];
     301            [m_pNativeRef setImage: [NSImage imageNamed: NSImageNameRefreshFreestandingTemplate]];
     302            [m_pNativeRef setBordered: NO];
     303            [[m_pNativeRef cell] setImageScaling: NSImageScaleProportionallyDown];
     304            initFrame = [m_pNativeRef frame];
    240305            break;
    241306        }
    242307    }
    243308
    244     NSButtonTarget *bt = [[NSButtonTarget alloc] initWithObject:this];
    245     [mNativeRef setTarget:bt];
    246     [mNativeRef setAction:@selector(clicked:)];
    247 
    248     NSRect frame = [mNativeRef frame];
    249     resize (frame.size.width, frame.size.height);
    250 
    251     setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
    252 
    253     setCocoaView (mNativeRef);
    254 }
    255 
    256 VBoxCocoaButton::~VBoxCocoaButton()
    257 {
    258     [[mNativeRef target] release];
    259     [mNativeRef release];
    260 }
    261 
    262 QSize VBoxCocoaButton::sizeHint() const
    263 {
    264     NSRect frame = [mNativeRef frame];
    265     return QSize (frame.size.width, frame.size.height);
    266 }
    267 
    268 void VBoxCocoaButton::resizeEvent(QResizeEvent * /* pEvent */)
    269 {
    270     NSRect frame = [mNativeRef frame];
    271     frame.size.width = width();
    272     frame.size.height = height();
    273     [mNativeRef setFrame:frame];
    274 }
    275 
    276 void VBoxCocoaButton::setText (const QString& aText)
    277 {
    278     QString s (aText);
     309    UIButtonTargetPrivate *bt = [[UIButtonTargetPrivate alloc] initWithObject:this];
     310    [m_pNativeRef setTarget:bt];
     311    [m_pNativeRef setAction:@selector(clicked:)];
     312
     313    /* Create the container widget and attach the native view. */
     314    m_pContainer = new QMacCocoaViewContainer(m_pNativeRef, this);
     315    /* Finally resize the widget */
     316    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     317    setFixedSize(NSWidth(initFrame), NSHeight(initFrame));
     318}
     319
     320UICocoaButton::~UICocoaButton()
     321{
     322}
     323
     324QSize UICocoaButton::sizeHint() const
     325{
     326    NSRect frame = [m_pNativeRef frame];
     327    return QSize(frame.size.width, frame.size.height);
     328}
     329
     330void UICocoaButton::setText(const QString& strText)
     331{
     332    QString s(strText);
    279333    /* Set it for accessibility reasons as alternative title */
    280     [mNativeRef setAlternateTitle: ::darwinQStringToNSString (s.remove ('&'))];
    281 }
    282 
    283 void VBoxCocoaButton::setToolTip (const QString& aTip)
    284 {
    285     [mNativeRef setToolTip: ::darwinQStringToNSString (aTip)];
    286 }
    287 
    288 void VBoxCocoaButton::onClicked()
    289 {
    290     emit clicked (false);
    291 }
    292 
    293 VBoxCocoaSegmentedButton::VBoxCocoaSegmentedButton (int aCount, QWidget *aParent /* = 0 */)
    294   : QMacCocoaViewContainer (0, aParent)
    295 {
    296     mNativeRef = [[NSSegmentedControl alloc] init];
    297     [mNativeRef setSegmentCount:aCount];
    298     [mNativeRef setSegmentStyle:NSSegmentStyleRoundRect];
    299     [[mNativeRef cell] setTrackingMode: NSSegmentSwitchTrackingMomentary];
    300     [mNativeRef setFont: [NSFont controlContentFontOfSize:
    301         [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
    302     [mNativeRef sizeToFit];
    303 
    304     NSSegmentedButtonTarget *bt = [[NSSegmentedButtonTarget alloc] initWithObject1:this];
    305     [mNativeRef setTarget:bt];
    306     [mNativeRef setAction:@selector(segControlClicked:)];
    307 
    308     NSRect frame = [mNativeRef frame];
    309     resize (frame.size.width, frame.size.height);
    310 
    311     setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
    312 
    313     setCocoaView (mNativeRef);
    314 
    315 }
    316 
    317 VBoxCocoaSegmentedButton::~VBoxCocoaSegmentedButton()
    318 {
    319     [[mNativeRef target] release];
    320     [mNativeRef release];
    321 }
    322 
    323 QSize VBoxCocoaSegmentedButton::sizeHint() const
    324 {
    325     NSRect frame = [mNativeRef frame];
    326     return QSize (frame.size.width, frame.size.height);
    327 }
    328 
    329 void VBoxCocoaSegmentedButton::setTitle (int aSegment, const QString &aTitle)
    330 {
    331     QString s (aTitle);
    332     [mNativeRef setLabel: ::darwinQStringToNSString (s.remove ('&')) forSegment: aSegment];
    333     [mNativeRef sizeToFit];
    334     NSRect frame = [mNativeRef frame];
    335     resize (frame.size.width, frame.size.height);
    336 }
    337 
    338 void VBoxCocoaSegmentedButton::setToolTip (int aSegment, const QString &aTip)
    339 {
    340     [[mNativeRef cell] setToolTip: ::darwinQStringToNSString (aTip) forSegment: aSegment];
    341 }
    342 
    343 void VBoxCocoaSegmentedButton::setEnabled (int aSegment, bool fEnabled)
    344 {
    345     [[mNativeRef cell] setEnabled: fEnabled forSegment: aSegment];
    346 }
    347 
    348 void VBoxCocoaSegmentedButton::animateClick (int aSegment)
    349 {
    350     [mNativeRef setSelectedSegment: aSegment];
    351     [[mNativeRef cell] performClick: mNativeRef];
    352 }
    353 
    354 void VBoxCocoaSegmentedButton::onClicked (int aSegment)
    355 {
    356     emit clicked (aSegment, false);
    357 }
    358 
    359 VBoxCocoaSearchField::VBoxCocoaSearchField (QWidget *aParent /* = 0 */)
    360   : QMacCocoaViewContainer (0, aParent)
    361 {
    362     mNativeRef = [[VBSearchField alloc] initWithObject2: this];
    363     [[mNativeRef cell] setControlSize: NSSmallControlSize];
    364     [mNativeRef setFont: [NSFont controlContentFontOfSize:
    365         [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
    366     [mNativeRef sizeToFit];
    367     NSRect f = [mNativeRef frame];
    368     f.size.width = 180;
    369     [mNativeRef setFrame: f];
    370 
    371     setCocoaView (mNativeRef);
     334    [m_pNativeRef setAlternateTitle: ::darwinQStringToNSString(s.remove('&'))];
     335}
     336
     337void UICocoaButton::setToolTip(const QString& strTip)
     338{
     339    [m_pNativeRef setToolTip: ::darwinQStringToNSString(strTip)];
     340}
     341
     342void UICocoaButton::onClicked()
     343{
     344    emit clicked(false);
     345}
     346
     347UICocoaSegmentedButton::UICocoaSegmentedButton(int count, CocoaSegmentType type /* = RoundRectSegment */, QWidget *pParent /* = 0 */)
     348  : UICocoaWrapper(pParent)
     349{
     350    NSRect initFrame;
     351
     352    m_pNativeRef = [[NSSegmentedControl alloc] init];
     353    [m_pNativeRef setSegmentCount:count];
     354    switch (type)
     355    {
     356        case RoundRectSegment:
     357        {
     358            [[m_pNativeRef cell] setTrackingMode: NSSegmentSwitchTrackingMomentary];
     359            [m_pNativeRef setFont: [NSFont controlContentFontOfSize:
     360                [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
     361            [m_pNativeRef setSegmentStyle:NSSegmentStyleRoundRect];
     362            break;
     363        }
     364        case TexturedRoundedSegment:
     365        {
     366            [m_pNativeRef setSegmentStyle:NSSegmentStyleTexturedRounded];
     367            [m_pNativeRef setFont: [NSFont controlContentFontOfSize:
     368                [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
     369            break;
     370        }
     371    }
     372    [m_pNativeRef sizeToFit];
     373
     374    UISegmentedButtonTargetPrivate *bt = [[UISegmentedButtonTargetPrivate alloc] initWithObject1:this];
     375    [m_pNativeRef setTarget:bt];
     376    [m_pNativeRef setAction:@selector(segControlClicked:)];
     377
     378    initFrame = [m_pNativeRef frame];
     379    /* Create the container widget and attach the native view. */
     380    m_pContainer = new QMacCocoaViewContainer(m_pNativeRef, this);
     381    /* Finally resize the widget */
     382    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     383    setFixedSize(NSWidth(initFrame), NSHeight(initFrame));
     384}
     385
     386UICocoaSegmentedButton::~UICocoaSegmentedButton()
     387{
     388}
     389
     390QSize UICocoaSegmentedButton::sizeHint() const
     391{
     392    NSRect frame = [m_pNativeRef frame];
     393    return QSize(frame.size.width, frame.size.height);
     394}
     395
     396void UICocoaSegmentedButton::setTitle(int iSegment, const QString &strTitle)
     397{
     398    QString s(strTitle);
     399    [m_pNativeRef setLabel: ::darwinQStringToNSString(s.remove('&')) forSegment: iSegment];
     400    [m_pNativeRef sizeToFit];
     401    NSRect frame = [m_pNativeRef frame];
     402    setFixedSize(NSWidth(frame), NSHeight(frame));
     403}
     404
     405void UICocoaSegmentedButton::setToolTip(int iSegment, const QString &strTip)
     406{
     407    [[m_pNativeRef cell] setToolTip: ::darwinQStringToNSString(strTip) forSegment: iSegment];
     408}
     409
     410void UICocoaSegmentedButton::setIcon(int iSegment, const QIcon& icon)
     411{
     412    QImage image = toGray(icon.pixmap(icon.actualSize(QSize(13, 13))).toImage());
     413
     414    NSImage *pNSimage = [::darwinToNSImageRef(&image) autorelease];
     415    [m_pNativeRef setImage: pNSimage forSegment: iSegment];
     416    [m_pNativeRef sizeToFit];
     417    NSRect frame = [m_pNativeRef frame];
     418    setFixedSize(NSWidth(frame), NSHeight(frame));
     419}
     420
     421void UICocoaSegmentedButton::setEnabled(int iSegment, bool fEnabled)
     422{
     423    [[m_pNativeRef cell] setEnabled: fEnabled forSegment: iSegment];
     424}
     425
     426void UICocoaSegmentedButton::animateClick(int iSegment)
     427{
     428    [m_pNativeRef setSelectedSegment: iSegment];
     429    [[m_pNativeRef cell] performClick: m_pNativeRef];
     430}
     431
     432void UICocoaSegmentedButton::onClicked(int iSegment)
     433{
     434    emit clicked(iSegment, false);
     435}
     436
     437UICocoaSearchField::UICocoaSearchField(QWidget *pParent /* = 0 */)
     438  : UICocoaWrapper(pParent)
     439{
     440    NSRect initFrame;
     441
     442    m_pNativeRef = [[UISearchFieldPrivate alloc] initWithObject2: this];
     443    [m_pNativeRef setFont: [NSFont controlContentFontOfSize:
     444        [NSFont systemFontSizeForControlSize: NSMiniControlSize]]];
     445    [[m_pNativeRef cell] setControlSize: NSMiniControlSize];
     446    [m_pNativeRef sizeToFit];
     447    initFrame = [m_pNativeRef frame];
     448    initFrame.size.width = 180;
     449    [m_pNativeRef setFrame: initFrame];
     450
     451    /* Use our own delegate */
     452    UISearchFieldDelegatePrivate *sfd = [[UISearchFieldDelegatePrivate alloc] init];
     453    [m_pNativeRef setDelegate: sfd];
     454
     455    /* Create the container widget and attach the native view. */
     456    m_pContainer = new QMacCocoaViewContainer(m_pNativeRef, this);
     457
     458    /* Finally resize the widget */
     459    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     460    setMinimumWidth(NSWidth(initFrame));
     461    setFixedHeight(NSHeight(initFrame));
    372462    setFocusPolicy(Qt::StrongFocus);
    373 
    374     /* Replace the cell class used for the NSSearchField */
    375     [NSKeyedArchiver setClassName:@"VBSearchFieldCell" forClass:[NSSearchFieldCell class]];
    376     [mNativeRef setCell:[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[mNativeRef cell]]]];
    377     /* Get the original behavior back */
    378     [NSKeyedArchiver setClassName:@"NSSearchFieldCell" forClass:[NSSearchFieldCell class]];
    379 
    380     /* Use our own delegate */
    381     VBSearchFieldDelegate *sfd = [[VBSearchFieldDelegate alloc] init];
    382     [mNativeRef setDelegate: sfd];
    383 
    384     NSRect frame = [mNativeRef frame];
    385     resize (frame.size.width, frame.size.height + 1);
    386     setMinimumWidth (50);
    387 
    388     setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    389 
    390 }
    391 
    392 VBoxCocoaSearchField::~VBoxCocoaSearchField()
    393 {
    394     [[mNativeRef delegate] release];
    395     [mNativeRef release];
    396 }
    397 
    398 QSize VBoxCocoaSearchField::sizeHint() const
    399 {
    400     NSRect frame = [mNativeRef frame];
    401     return QSize (frame.size.width, frame.size.height);
    402 }
    403 
    404 QString VBoxCocoaSearchField::text() const
    405 {
    406     return ::darwinNSStringToQString ([mNativeRef stringValue]);
    407 }
    408 
    409 void VBoxCocoaSearchField::insert (const QString &aText)
    410 {
    411     [[mNativeRef currentEditor] setString: [[mNativeRef stringValue] stringByAppendingString: ::darwinQStringToNSString (aText)]];
    412 }
    413 
    414 void VBoxCocoaSearchField::setToolTip (const QString &aTip)
    415 {
    416     [mNativeRef setToolTip: ::darwinQStringToNSString (aTip)];
    417 }
    418 
    419 void VBoxCocoaSearchField::selectAll()
    420 {
    421     [mNativeRef selectText: mNativeRef];
    422 }
    423 
    424 void VBoxCocoaSearchField::markError()
    425 {
    426     [[mNativeRef cell] setBackgroundColor: [[NSColor redColor] colorWithAlphaComponent: 0.3]];
    427 }
    428 
    429 void VBoxCocoaSearchField::unmarkError()
    430 {
    431     [[mNativeRef cell] setBackgroundColor: nil];
    432 }
    433 
    434 void VBoxCocoaSearchField::onTextChanged (const QString &aText)
    435 {
    436     emit textChanged (aText);
    437 }
    438 
     463}
     464
     465UICocoaSearchField::~UICocoaSearchField()
     466{
     467}
     468
     469QSize UICocoaSearchField::sizeHint() const
     470{
     471    NSRect frame = [m_pNativeRef frame];
     472    return QSize(frame.size.width, frame.size.height);
     473}
     474
     475QString UICocoaSearchField::text() const
     476{
     477    return ::darwinNSStringToQString([m_pNativeRef stringValue]);
     478}
     479
     480void UICocoaSearchField::insert(const QString &strText)
     481{
     482    [[m_pNativeRef currentEditor] setString: [[m_pNativeRef stringValue] stringByAppendingString: ::darwinQStringToNSString(strText)]];
     483}
     484
     485void UICocoaSearchField::setToolTip(const QString &strTip)
     486{
     487    [m_pNativeRef setToolTip: ::darwinQStringToNSString(strTip)];
     488}
     489
     490void UICocoaSearchField::selectAll()
     491{
     492    [m_pNativeRef selectText: m_pNativeRef];
     493}
     494
     495void UICocoaSearchField::markError()
     496{
     497    [[m_pNativeRef cell] setBackgroundColor: [[NSColor redColor] colorWithAlphaComponent: 0.3]];
     498}
     499
     500void UICocoaSearchField::unmarkError()
     501{
     502    [[m_pNativeRef cell] setBackgroundColor: nil];
     503}
     504
     505void UICocoaSearchField::onTextChanged(const QString &strText)
     506{
     507    emit textChanged(strText);
     508}
     509
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxSpecialControls.cpp

    r28800 r30188  
    3535{
    3636    setShortcut (QKeySequence (Qt::Key_Escape));
    37     mButton = new VBoxCocoaButton (VBoxCocoaButton::CancelButton, this);
     37    mButton = new UICocoaButton (UICocoaButton::CancelButton, this);
    3838    connect (mButton, SIGNAL (clicked()),
    3939             this, SIGNAL (clicked()));
     
    5454  : QAbstractButton(pParent)
    5555{
    56     m_pButton = new VBoxCocoaButton(VBoxCocoaButton::ResetButton, this);
     56    m_pButton = new UICocoaButton(UICocoaButton::ResetButton, this);
    5757    connect(m_pButton, SIGNAL(clicked()),
    5858            this, SIGNAL(clicked()));
     
    7474{
    7575    setShortcut (QKeySequence (QKeySequence::HelpContents));
    76     mButton = new VBoxCocoaButton (VBoxCocoaButton::HelpButton, this);
     76    mButton = new UICocoaButton (UICocoaButton::HelpButton, this);
    7777    connect (mButton, SIGNAL (clicked()),
    7878             this, SIGNAL (clicked()));
     
    8686 ********************************************************************************/
    8787VBoxSegmentedButton::VBoxSegmentedButton (int aCount, QWidget *aParent /* = 0 */)
    88   : VBoxCocoaSegmentedButton (aCount, aParent)
     88  : UICocoaSegmentedButton (aCount, UICocoaSegmentedButton::TexturedRoundedSegment, aParent)
    8989{
    9090}
     
    9595 ********************************************************************************/
    9696VBoxSearchField::VBoxSearchField (QWidget *aParent /* = 0 */)
    97   : VBoxCocoaSearchField (aParent)
     97  : UICocoaSearchField (aParent)
    9898{
    9999}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxSpecialControls.h

    r28800 r30188  
    2929
    3030/* VBox includes */
    31 #include "VBoxCocoaSpecialControls.h"
     31#include "UICocoaSpecialControls.h"
    3232
    3333/********************************************************************************
     
    5252
    5353private:
    54     VBoxCocoaButton *mButton;
     54    UICocoaButton *mButton;
    5555};
    5656
     
    7676
    7777private:
    78     VBoxCocoaButton *m_pButton;
     78    UICocoaButton *m_pButton;
    7979};
    8080
     
    9999
    100100private:
    101     VBoxCocoaButton *mButton;
     101    UICocoaButton *mButton;
    102102};
    103103
     
    107107 *
    108108 ********************************************************************************/
    109 class VBoxSegmentedButton: public VBoxCocoaSegmentedButton
     109class VBoxSegmentedButton: public UICocoaSegmentedButton
    110110{
    111111    Q_OBJECT;
     
    113113public:
    114114    VBoxSegmentedButton (int aCount, QWidget *aParent = 0);
    115 
    116     void setIcon (int /* aSegment */, const QIcon & /* aIcon */) {}
    117115};
    118116
     
    122120 *
    123121 ********************************************************************************/
    124 class VBoxSearchField: public VBoxCocoaSearchField
     122class VBoxSearchField: public UICocoaSearchField
    125123{
    126124    Q_OBJECT;
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