VirtualBox

Changeset 24107 in vbox for trunk/src


Ignore:
Timestamp:
Oct 27, 2009 9:08:43 AM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: initial set of native Cocoa controls

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 added
6 edited
3 moved

Legend:

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

    r24002 r24107  
    272272        include/QITreeWidget.h \
    273273        include/QIMainDialog.h \
    274         include/QIHelpButton.h \
    275274        include/QIDialog.h \
    276275        include/QIFileDialog.h \
     
    335334        include/VBoxImportApplianceWzd.h \
    336335        include/VBoxExportApplianceWgt.h \
    337         include/VBoxExportApplianceWzd.h
     336        include/VBoxExportApplianceWzd.h \
     337        include/VBoxSpecialControls.h
    338338
    339339# Sources containing local definitions of classes that use the Q_OBJECT macro.
     
    374374        src/QIMainDialog.cpp \
    375375        src/QILineEdit.cpp \
    376         src/QIHelpButton.cpp \
    377376        src/QISplitter.cpp \
    378377        src/QITreeView.cpp \
     
    435434        src/VBoxImportApplianceWzd.cpp \
    436435        src/VBoxExportApplianceWgt.cpp \
    437         src/VBoxExportApplianceWzd.cpp
     436        src/VBoxExportApplianceWzd.cpp \
     437        src/VBoxSpecialControls.cpp
    438438
    439439ifeq ($(filter-out freebsd linux netbsd openbsd solaris,$(KBUILD_TARGET)),) # X11
     
    473473
    474474ifdef VBOX_WITH_COCOA_QT
     475 VirtualBox_DEFS += VBOX_DARWIN_USE_NATIVE_CONTROLS
    475476 VirtualBox_SOURCES.darwin += \
    476477        src/darwin/VBoxCocoaApplication.m \
    477         src/darwin/VBoxUtils-darwin-cocoa.m \
    478         src/darwin/VBoxDockIconPreview-cocoa.m
     478        src/darwin/VBoxUtils-darwin-cocoa.mm \
     479        src/darwin/VBoxCocoaSpecialControls.mm \
     480        src/darwin/VBoxDockIconPreview-cocoa.m
     481 VirtualBox_QT_MOCHDRS.darwin = \
     482        include/VBoxCocoaSpecialControls.h
     483
    479484else
    480485 VirtualBox_SOURCES.darwin += \
  • trunk/src/VBox/Frontends/VirtualBox/include/QIDialogButtonBox.h

    r9866 r24107  
    3232class QBoxLayout;
    3333
    34 class QIHelpButton;
     34class VBoxHelpButton;
    3535
    3636class QIDialogButtonBox: public QIWithRetranslateUI<QDialogButtonBox>
     
    6060private:
    6161
    62     QPointer<QIHelpButton> mHelpButton;
     62    QPointer<VBoxHelpButton> mHelpButton;
    6363};
    6464
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxSpecialControls.h

    r24065 r24107  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * QIHelpButton class declaration
     4 * VBoxSpecialButtons declarations
    55 */
    66
    77/*
    8  * Copyright (C) 2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2009 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121 */
    2222
    23 #ifndef __QIHelpButton_h_
    24 #define __QIHelpButton_h_
    25 
     23#ifndef ___VBoxSpecialControls_h__
     24#define ___VBoxSpecialControls_h__
     25
     26/* VBox includes */
    2627#include "QIWithRetranslateUI.h"
    2728
     
    2930#include <QPushButton>
    3031
    31 class QIHelpButton: public QIWithRetranslateUI<QPushButton>
    32 {
    33     Q_OBJECT;
    34 
    35 public:
    36 
    37     QIHelpButton (QWidget *aParent = NULL);
     32#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
     33
     34/* VBox includes */
     35#include "VBoxCocoaSpecialControls.h"
     36
     37/********************************************************************************
     38 *
     39 * A mini cancel button in the native Cocoa version.
     40 *
     41 ********************************************************************************/
     42class VBoxMiniCancelButton: public QAbstractButton
     43{
     44    Q_OBJECT;
     45
     46public:
     47    VBoxMiniCancelButton (QWidget *aParent = 0);
     48
     49    void setToolTip (const QString &aTip) { mButton->setToolTip (aTip); }
     50
     51protected:
     52    void paintEvent (QPaintEvent * /* aEvent */) {}
     53
     54private:
     55    VBoxCocoaButton *mButton;
     56};
     57
     58/********************************************************************************
     59 *
     60 * A help button in the native Cocoa version.
     61 *
     62 ********************************************************************************/
     63class VBoxHelpButton: public QPushButton
     64{
     65    Q_OBJECT;
     66
     67public:
     68    VBoxHelpButton (QWidget *aParent = 0);
     69
     70    void setToolTip (const QString &aTip) { mButton->setToolTip (aTip); }
     71
     72    void initFrom (QPushButton * /* aOther */) {}
     73
     74protected:
     75    void paintEvent (QPaintEvent * /* aEvent */) {}
     76
     77private:
     78    VBoxCocoaButton *mButton;
     79};
     80
     81/********************************************************************************
     82 *
     83 * A segmented button in the native Cocoa version.
     84 *
     85 ********************************************************************************/
     86class VBoxSegmentedButton: public VBoxCocoaSegmentedButton
     87{
     88    Q_OBJECT;
     89
     90public:
     91    VBoxSegmentedButton (int aCount, QWidget *aParent = 0);
     92
     93    void setIcon (int /* aSegment */, const QIcon & /* aIcon */) {}
     94};
     95
     96/********************************************************************************
     97 *
     98 * A search field in the native Cocoa version.
     99 *
     100 ********************************************************************************/
     101class VBoxSearchField: public VBoxCocoaSearchField
     102{
     103    Q_OBJECT;
     104
     105public:
     106    VBoxSearchField (QWidget *aParent = 0);
     107};
     108
     109#else /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
     110
     111/* VBox includes */
     112#include "QIToolButton.h"
     113
     114/* Qt includes */
     115#include <QLineEdit>
     116
     117/* Qt forward declarations */
     118class QSignalMapper;
     119
     120/********************************************************************************
     121 *
     122 * A mini cancel button for the other OS's.
     123 *
     124 ********************************************************************************/
     125class VBoxMiniCancelButton: public QIWithRetranslateUI<QIToolButton>
     126{
     127    Q_OBJECT;
     128
     129public:
     130    VBoxMiniCancelButton (QWidget *aParent = 0);
     131
     132protected:
     133    void retranslateUi() {};
     134};
     135
     136/********************************************************************************
     137 *
     138 * A help button for the other OS's.
     139 *
     140 ********************************************************************************/
     141class VBoxHelpButton: public QIWithRetranslateUI<QPushButton>
     142{
     143    Q_OBJECT;
     144
     145public:
     146    VBoxHelpButton (QWidget *aParent = 0);
     147#ifdef Q_WS_MAC
     148    ~VBoxHelpButton();
     149    QSize sizeHint() const;
     150#endif /* Q_WS_MAC */
    38151
    39152    void initFrom (QPushButton *aOther);
    40153
     154protected:
     155    void retranslateUi();
     156
    41157#ifdef Q_WS_MAC
    42     ~QIHelpButton();
    43 
    44     QSize sizeHint() const;
    45 
    46 protected:
     158    void paintEvent (QPaintEvent *aEvent);
    47159
    48160    bool hitButton (const QPoint &pos) const;
     
    52164    void leaveEvent (QEvent *aEvent);
    53165
    54     void paintEvent (QPaintEvent *aEvent);
    55 #endif /* Q_WS_MAC */
    56 
    57 protected:
    58 
    59     void retranslateUi();
    60 
    61 private:
    62    
    63 #ifdef Q_WS_MAC
     166private:
    64167    /* Private member vars */
    65168    bool mButtonPressed;
     
    73176};
    74177
    75 #endif /* __QIHelpButton_h_ */
    76 
     178/********************************************************************************
     179 *
     180 * A segmented button for the other OS's.
     181 *
     182 ********************************************************************************/
     183class VBoxSegmentedButton: public QWidget
     184{
     185    Q_OBJECT;
     186
     187public:
     188    VBoxSegmentedButton (int aCount, QWidget *aParent = 0);
     189    ~VBoxSegmentedButton();
     190
     191    void setTitle (int aSegment, const QString &aTitle);
     192    void setToolTip (int aSegment, const QString &aTip);
     193    void setIcon (int aSegment, const QIcon &aIcon);
     194    void setEnabled (int aSegment, bool fEnabled);
     195
     196    void animateClick (int aSegment);
     197
     198signals:
     199    void clicked (int aSegment);
     200
     201private:
     202    /* Private member vars */
     203    QList<QIToolButton*> mButtons;
     204    QSignalMapper *mSignalMapper;
     205};
     206
     207/********************************************************************************
     208 *
     209 * A search field  for the other OS's.
     210 *
     211 ********************************************************************************/
     212class VBoxSearchField: public QLineEdit
     213{
     214    Q_OBJECT;
     215
     216public:
     217    VBoxSearchField (QWidget *aParent = 0);
     218
     219    void markError();
     220    void unmarkError();
     221
     222private:
     223    /* Private member vars */
     224    QBrush mBaseBrush;
     225};
     226
     227#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
     228
     229#endif /* ___VBoxSpecialControls_h__ */
     230
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxUtils-darwin.h

    r23708 r24107  
    4141
    4242# include <qglobal.h> /* for QT_MAC_USE_COCOA */
    43 # include <QRect>
    4443
    4544# include <ApplicationServices/ApplicationServices.h>
     
    6261
    6362#include <iprt/cdefs.h> /* for RT_C_DECLS_BEGIN/RT_C_DECLS_END & stuff */
     63#include <QRect>
    6464
    6565RT_C_DECLS_BEGIN
     
    9393void darwinWindowInvalidateShadowImpl (NativeWindowRef aWindow);
    9494int  darwinWindowToolBarHeight (NativeWindowRef aWindow);
     95float darwinSmallFontSize();
    9596
    9697RT_C_DECLS_END
    97 
    98 #ifndef __OBJC__
    99 /********************************************************************************
    100  *
    101  * Window/View management (Qt Wrapper)
    102  *
    103  ********************************************************************************/
    104 
    105 /**
    106  * Returns a reference to the native View of the QWidget.
    107  *
    108  * @returns either HIViewRef or NSView* of the QWidget.
    109  * @param   aWidget   Pointer to the QWidget
    110  */
    111 NativeViewRef darwinToNativeView (QWidget *aWidget);
    112 
    113 /**
    114  * Returns a reference to the native Window of the QWidget.
    115  *
    116  * @returns either WindowRef or NSWindow* of the QWidget.
    117  * @param   aWidget   Pointer to the QWidget
    118  */
    119 NativeWindowRef darwinToNativeWindow (QWidget *aWidget);
    120 
    121 /* This is necessary because of the C calling convention. Its a simple wrapper
    122    for darwinToNativeWindowImpl to allow operator overloading which isn't
    123    allowed in C. */
    124 /**
    125  * Returns a reference to the native Window of the View..
    126  *
    127  * @returns either WindowRef or NSWindow* of the View.
    128  * @param   aWidget   Pointer to the native View
    129  */
    130 NativeWindowRef darwinToNativeWindow (NativeViewRef aView);
    131 
    132 /**
    133  * Returns a reference to the native View of the Window.
    134  *
    135  * @returns either HIViewRef or NSView* of the Window.
    136  * @param   aWidget   Pointer to the native Window
    137  */
    138 NativeViewRef darwinToNativeView (NativeWindowRef aWindow);
    139 
    140 /********************************************************************************
    141  *
    142  * Simple setter methods (Qt Wrapper)
    143  *
    144  ********************************************************************************/
    145 void darwinSetShowsToolbarButton (QToolBar *aToolBar, bool aEnabled);
    146 void darwinSetShowsResizeIndicator (QWidget *aWidget, bool aEnabled);
    147 void darwinSetHidesAllTitleButtons (QWidget *aWidget);
    148 void darwinSetShowsWindowTransparent (QWidget *aWidget, bool aEnabled);
    149 void darwinDisableIconsInMenus (void);
    150 
    151 /********************************************************************************
    152  *
    153  * Simple helper methods (Qt Wrapper)
    154  *
    155  ********************************************************************************/
    156 void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget);
    157 void darwinWindowInvalidateShape (QWidget *aWidget);
    158 void darwinWindowInvalidateShadow (QWidget *aWidget);
    159 int  darwinWindowToolBarHeight (QWidget *aWidget);
    160 QString darwinSystemLanguage (void);
    161 QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
    162 
    163 
    164 /********************************************************************************
    165  *
    166  * Graphics stuff (Qt Wrapper)
    167  *
    168  ********************************************************************************/
    169 /**
    170  * Returns a reference to the CGContext of the QWidget.
    171  *
    172  * @returns CGContextRef of the QWidget.
    173  * @param   aWidget      Pointer to the QWidget
    174  */
    175 CGContextRef darwinToCGContextRef (QWidget *aWidget);
    176 
    177 CGImageRef darwinToCGImageRef (const QImage *aImage);
    178 CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
    179 CGImageRef darwinToCGImageRef (const char *aSource);
    18098
    18199DECLINLINE(CGRect) darwinToCGRect (const QRect& aRect) { return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height()); }
     
    188106    return aRect;
    189107}
     108
     109
     110#ifndef __OBJC__
     111/********************************************************************************
     112 *
     113 * Window/View management (Qt Wrapper)
     114 *
     115 ********************************************************************************/
     116
     117/**
     118 * Returns a reference to the native View of the QWidget.
     119 *
     120 * @returns either HIViewRef or NSView* of the QWidget.
     121 * @param   aWidget   Pointer to the QWidget
     122 */
     123NativeViewRef darwinToNativeView (QWidget *aWidget);
     124
     125/**
     126 * Returns a reference to the native Window of the QWidget.
     127 *
     128 * @returns either WindowRef or NSWindow* of the QWidget.
     129 * @param   aWidget   Pointer to the QWidget
     130 */
     131NativeWindowRef darwinToNativeWindow (QWidget *aWidget);
     132
     133/* This is necessary because of the C calling convention. Its a simple wrapper
     134   for darwinToNativeWindowImpl to allow operator overloading which isn't
     135   allowed in C. */
     136/**
     137 * Returns a reference to the native Window of the View..
     138 *
     139 * @returns either WindowRef or NSWindow* of the View.
     140 * @param   aWidget   Pointer to the native View
     141 */
     142NativeWindowRef darwinToNativeWindow (NativeViewRef aView);
     143
     144/**
     145 * Returns a reference to the native View of the Window.
     146 *
     147 * @returns either HIViewRef or NSView* of the Window.
     148 * @param   aWidget   Pointer to the native Window
     149 */
     150NativeViewRef darwinToNativeView (NativeWindowRef aWindow);
     151
     152/********************************************************************************
     153 *
     154 * Simple setter methods (Qt Wrapper)
     155 *
     156 ********************************************************************************/
     157void darwinSetShowsToolbarButton (QToolBar *aToolBar, bool aEnabled);
     158void darwinSetShowsResizeIndicator (QWidget *aWidget, bool aEnabled);
     159void darwinSetHidesAllTitleButtons (QWidget *aWidget);
     160void darwinSetShowsWindowTransparent (QWidget *aWidget, bool aEnabled);
     161void darwinDisableIconsInMenus (void);
     162
     163/********************************************************************************
     164 *
     165 * Simple helper methods (Qt Wrapper)
     166 *
     167 ********************************************************************************/
     168void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget);
     169void darwinWindowInvalidateShape (QWidget *aWidget);
     170void darwinWindowInvalidateShadow (QWidget *aWidget);
     171int  darwinWindowToolBarHeight (QWidget *aWidget);
     172QString darwinSystemLanguage (void);
     173QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
     174
     175
     176/********************************************************************************
     177 *
     178 * Graphics stuff (Qt Wrapper)
     179 *
     180 ********************************************************************************/
     181/**
     182 * Returns a reference to the CGContext of the QWidget.
     183 *
     184 * @returns CGContextRef of the QWidget.
     185 * @param   aWidget      Pointer to the QWidget
     186 */
     187CGContextRef darwinToCGContextRef (QWidget *aWidget);
     188
     189CGImageRef darwinToCGImageRef (const QImage *aImage);
     190CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
     191CGImageRef darwinToCGImageRef (const char *aSource);
    190192
    191193
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMLogViewer.h

    r23260 r24107  
    3232class QTabWidget;
    3333class QTextEdit;
    34 class QLineEdit;
     34class VBoxSearchField;
    3535class QLabel;
    3636class QIToolButton;
     37class VBoxMiniCancelButton;
     38class VBoxSegmentedButton;
    3739class QCheckBox;
    3840
     
    104106private slots:
    105107
     108    void find (int aButton);
    106109    void findNext() { search (true); }
    107110    void findBack() { search (false); }
     
    120123    void toggleWarning (bool aHide);
    121124
    122     VBoxVMLogViewer *mViewer;
    123     QIToolButton    *mButtonClose;
    124     QLabel          *mSearchName;
    125     QLineEdit       *mSearchString;
    126     QIToolButton    *mButtonPrev;
    127     QIToolButton    *mButtonNext;
    128     QCheckBox       *mCaseSensitive;
    129     QSpacerItem     *mWarningSpacer;
    130     QLabel          *mWarningIcon;
    131     QLabel          *mWarningString;
     125    VBoxVMLogViewer      *mViewer;
     126    VBoxMiniCancelButton *mButtonClose;
     127    QLabel               *mSearchName;
     128    VBoxSearchField      *mSearchString;
     129    VBoxSegmentedButton  *mButtonsNextPrev;
     130    QCheckBox            *mCaseSensitive;
     131    QSpacerItem          *mWarningSpacer;
     132    QLabel               *mWarningIcon;
     133    QLabel               *mWarningString;
    132134};
    133135
  • trunk/src/VBox/Frontends/VirtualBox/src/QIDialogButtonBox.cpp

    r10101 r24107  
    2222
    2323#include "QIDialogButtonBox.h"
    24 #include "QIHelpButton.h"
     24#include "VBoxSpecialControls.h"
    2525
    2626#include <iprt/assert.h>
     
    114114        /* Use our very own help button if the user requested for one. */
    115115        if (!mHelpButton)
    116             mHelpButton = new QIHelpButton;
     116            mHelpButton = new VBoxHelpButton;
    117117        mHelpButton->initFrom (btn);
    118118        removeButton (btn);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSpecialControls.cpp

    r24065 r24107  
    1 /** @file
    2  *
    3  * VBox frontends: Qt GUI ("VirtualBox"):
    4  * QIHelpButton class implementation
    5  */
    6 
    7 /*
    8  * Copyright (C) 2008 Sun Microsystems, Inc.
    9  *
    10  * This file is part of VirtualBox Open Source Edition (OSE), as
    11  * available from http://www.virtualbox.org. This file is free software;
    12  * you can redistribute it and/or modify it under the terms of the GNU
    13  * General Public License (GPL) as published by the Free Software
    14  * Foundation, in version 2 as it comes in the "COPYING" file of the
    15  * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
    16  * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    17  *
    18  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
    19  * Clara, CA 95054 USA or visit http://www.sun.com if you need
    20  * additional information or have any questions.
    21  */
    22 
    23 #include "QIHelpButton.h"
     1/* VBox includes */
     2#include "VBoxSpecialControls.h"
     3
     4/* VBox includes */
     5#include "VBoxGlobal.h"
     6
     7#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
     8
     9/********************************************************************************
     10 *
     11 * A mini cancel button in the native Cocoa version.
     12 *
     13 ********************************************************************************/
     14VBoxMiniCancelButton::VBoxMiniCancelButton (QWidget *aParent /* = 0 */)
     15  : QAbstractButton (aParent)
     16{
     17    setShortcut (QKeySequence (Qt::Key_Escape));
     18    mButton = new VBoxCocoaButton (VBoxCocoaButton::CancelButton, this);
     19    connect (mButton, SIGNAL (clicked()),
     20             this, SIGNAL (clicked()));
     21    setFixedSize (mButton->size());
     22}
     23
     24/********************************************************************************
     25 *
     26 * A help button in the native Cocoa version.
     27 *
     28 ********************************************************************************/
     29VBoxHelpButton::VBoxHelpButton (QWidget *aParent /* = 0 */)
     30  : QPushButton (aParent)
     31{
     32    setShortcut (QKeySequence (QKeySequence::HelpContents));
     33    mButton = new VBoxCocoaButton (VBoxCocoaButton::HelpButton, this);
     34    connect (mButton, SIGNAL (clicked()),
     35             this, SIGNAL (clicked()));
     36    setFixedSize (mButton->size());
     37}
     38
     39/********************************************************************************
     40 *
     41 * A segmented button in the native Cocoa version.
     42 *
     43 ********************************************************************************/
     44VBoxSegmentedButton::VBoxSegmentedButton (int aCount, QWidget *aParent /* = 0 */)
     45  : VBoxCocoaSegmentedButton (aCount, aParent)
     46{
     47}
     48/********************************************************************************
     49 *
     50 * A search field in the native Cocoa version.
     51 *
     52 ********************************************************************************/
     53VBoxSearchField::VBoxSearchField (QWidget *aParent /* = 0 */)
     54  : VBoxCocoaSearchField (aParent)
     55{
     56}
     57
     58#else /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    2459
    2560/* Qt includes */
     
    2762#include <QBitmap>
    2863#include <QMouseEvent>
    29 
     64#include <QSignalMapper>
     65
     66/********************************************************************************
     67 *
     68 * A mini cancel button for the other OS's.
     69 *
     70 ********************************************************************************/
     71VBoxMiniCancelButton::VBoxMiniCancelButton (QWidget *aParent /* = 0 */)
     72  : QIWithRetranslateUI<QIToolButton> (aParent)
     73{
     74    setAutoRaise (true);
     75    setFocusPolicy (Qt::TabFocus);
     76    setShortcut (QKeySequence (Qt::Key_Escape));
     77    setIcon (VBoxGlobal::iconSet (":/delete_16px.png",
     78                                  ":/delete_dis_16px.png"));
     79}
     80
     81/********************************************************************************
     82 *
     83 * A help button for the other OS's.
     84 *
     85 ********************************************************************************/
    3086/* From: src/gui/styles/qmacstyle_mac.cpp */
    3187static const int PushButtonLeftOffset = 6;
     
    3490static const int PushButtonBottomOffset = 4;
    3591
    36 QIHelpButton::QIHelpButton(QWidget *aParent /* = NULL */)
     92VBoxHelpButton::VBoxHelpButton (QWidget *aParent /* = 0 */)
    3793    : QIWithRetranslateUI<QPushButton> (aParent)
    3894{
     
    4399    mSize = mNormalPixmap->size();
    44100    mMask = new QImage (mNormalPixmap->mask().toImage());
    45     mBRect = QRect (PushButtonLeftOffset, 
     101    mBRect = QRect (PushButtonLeftOffset,
    46102                    PushButtonTopOffset,
    47103                    mSize.width(),
     
    52108}
    53109
    54 void QIHelpButton::initFrom (QPushButton *aOther)
     110void VBoxHelpButton::initFrom (QPushButton *aOther)
    55111{
    56112    setIcon (aOther->icon());
     
    64120}
    65121
     122void VBoxHelpButton::retranslateUi()
     123{
     124    QPushButton::setText (tr ("&Help"));
     125    if (QPushButton::shortcut().isEmpty())
     126        QPushButton::setShortcut (QKeySequence::HelpContents);
     127}
     128
    66129#ifdef Q_WS_MAC
    67 QIHelpButton::~QIHelpButton()
     130VBoxHelpButton::~VBoxHelpButton()
    68131{
    69132    delete mNormalPixmap;
     
    72135}
    73136
    74 QSize QIHelpButton::sizeHint() const
     137QSize VBoxHelpButton::sizeHint() const
    75138{
    76139    return QSize (mSize.width() + PushButtonLeftOffset + PushButtonRightOffset,
     
    78141}
    79142
    80 bool QIHelpButton::hitButton (const QPoint &pos) const
     143void VBoxHelpButton::paintEvent (QPaintEvent * /* aEvent */)
     144{
     145    QPainter painter (this);
     146    painter.drawPixmap (PushButtonLeftOffset, PushButtonTopOffset, mButtonPressed ? *mPressedPixmap: *mNormalPixmap);
     147}
     148
     149bool VBoxHelpButton::hitButton (const QPoint &pos) const
    81150{
    82151    if (mBRect.contains (pos))
     
    87156}
    88157
    89 void QIHelpButton::mousePressEvent (QMouseEvent *aEvent)
     158void VBoxHelpButton::mousePressEvent (QMouseEvent *aEvent)
    90159{
    91160    if (hitButton (aEvent->pos()))
     
    95164}
    96165
    97 void QIHelpButton::mouseReleaseEvent (QMouseEvent *aEvent)
     166void VBoxHelpButton::mouseReleaseEvent (QMouseEvent *aEvent)
    98167{
    99168    QPushButton::mouseReleaseEvent (aEvent);
     
    102171}
    103172
    104 void QIHelpButton::leaveEvent (QEvent * aEvent)
     173void VBoxHelpButton::leaveEvent (QEvent * aEvent)
    105174{
    106175    QPushButton::leaveEvent (aEvent);
     
    108177    update();
    109178}
    110 
    111 void QIHelpButton::paintEvent (QPaintEvent * /* aEvent */)
    112 {
    113     QPainter painter (this);
    114     painter.drawPixmap (PushButtonLeftOffset, PushButtonTopOffset, mButtonPressed ? *mPressedPixmap: *mNormalPixmap);
    115 }
    116179#endif /* Q_WS_MAC */
    117180
    118 void QIHelpButton::retranslateUi()
    119 {
    120     QPushButton::setText (tr ("&Help"));
    121     if (QPushButton::shortcut().isEmpty())
    122         QPushButton::setShortcut (QKeySequence::HelpContents);
    123 }
    124 
     181/********************************************************************************
     182 *
     183 * A segmented button for the other OS's.
     184 *
     185 ********************************************************************************/
     186VBoxSegmentedButton::VBoxSegmentedButton (int aCount, QWidget *aParent /* = 0 */)
     187  : QWidget (aParent)
     188{
     189    mSignalMapper = new QSignalMapper (this);
     190
     191    QHBoxLayout *layout = new QHBoxLayout (this);
     192    for (int i=0; i < aCount; ++i)
     193    {
     194        QIToolButton *button = new QIToolButton (this);
     195        button->setAutoRaise (true);
     196        button->setFocusPolicy (Qt::TabFocus);
     197        button->setToolButtonStyle (Qt::ToolButtonTextBesideIcon);
     198        mButtons.append (button);
     199        layout->addWidget (button);
     200        connect (button, SIGNAL(clicked()),
     201                 mSignalMapper, SLOT(map()));
     202        mSignalMapper->setMapping (button, i);
     203    }
     204    connect (mSignalMapper, SIGNAL(mapped(int)),
     205             this, SIGNAL(clicked(int)));
     206
     207}
     208
     209VBoxSegmentedButton::~VBoxSegmentedButton()
     210{
     211    delete mSignalMapper;
     212    qDeleteAll (mButtons);
     213}
     214
     215void VBoxSegmentedButton::setTitle (int aSegment, const QString &aTitle)
     216{
     217    mButtons.at (aSegment)->setText (aTitle);
     218}
     219
     220void VBoxSegmentedButton::setToolTip (int aSegment, const QString &aTip)
     221{
     222    mButtons.at (aSegment)->setToolTip (aTip);
     223}
     224
     225void VBoxSegmentedButton::setIcon (int aSegment, const QIcon &aIcon)
     226{
     227    mButtons.at (aSegment)->setIcon (aIcon);
     228}
     229
     230void VBoxSegmentedButton::setEnabled (int aSegment, bool fEnabled)
     231{
     232    mButtons.at (aSegment)->setEnabled (fEnabled);
     233}
     234
     235void VBoxSegmentedButton::animateClick (int aSegment)
     236{
     237    mButtons.at (aSegment)->animateClick();
     238}
     239
     240/********************************************************************************
     241 *
     242 * A search field  for the other OS's.
     243 *
     244 ********************************************************************************/
     245VBoxSearchField::VBoxSearchField (QWidget *aParent /* = 0 */)
     246  : QLineEdit (aParent)
     247{
     248    mBaseBrush = palette().base();
     249}
     250
     251void VBoxSearchField::markError()
     252{
     253    QPalette pal = palette();
     254    QColor c (Qt::red);
     255    c.setAlphaF (0.3);
     256    pal.setBrush (QPalette::Base, c);
     257    setPalette (pal);
     258}
     259
     260void VBoxSearchField::unmarkError()
     261{
     262    QPalette pal = palette();
     263    pal.setBrush (QPalette::Base, mBaseBrush);
     264    setPalette (pal);
     265}
     266
     267#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
     268
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMLogViewer.cpp

    r23260 r24107  
    2121 */
    2222
    23 #include <VBoxVMLogViewer.h>
    24 #include <VBoxGlobal.h>
    25 #include <VBoxProblemReporter.h>
    26 #include "QIToolButton.h"
     23#include "VBoxVMLogViewer.h"
     24#include "VBoxGlobal.h"
     25#include "VBoxProblemReporter.h"
     26#include "VBoxSpecialControls.h"
     27#include "VBoxUtils.h"
    2728
    2829/* Qt includes */
     
    121122    /* We have to force this to get the default button L&F on the mac. */
    122123    defaultButton()->setEnabled (true);
     124# ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
     125    logsFrameLayout->setSpacing (4);
     126# endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    123127#endif /* Q_WS_MAC */
    124128    /* Loading language constants */
     
    339343    , mButtonClose (0)
    340344    , mSearchName (0), mSearchString (0)
    341     , mButtonPrev (0), mButtonNext (0)
     345    , mButtonsNextPrev (0)
    342346    , mCaseSensitive (0)
    343347    , mWarningSpacer (0), mWarningIcon (0), mWarningString (0)
    344348{
    345     mButtonClose = new QIToolButton (this);
    346     mButtonClose->setAutoRaise (true);
    347     mButtonClose->setFocusPolicy (Qt::TabFocus);
    348     mButtonClose->setShortcut (QKeySequence (Qt::Key_Escape));
     349    mButtonClose = new VBoxMiniCancelButton (this);
    349350    connect (mButtonClose, SIGNAL (clicked()), this, SLOT (hide()));
    350     mButtonClose->setIcon (VBoxGlobal::iconSet (":/delete_16px.png",
    351                                                 ":/delete_dis_16px.png"));
    352351
    353352    mSearchName = new QLabel (this);
    354     mSearchString = new QLineEdit (this);
     353    mSearchString = new VBoxSearchField (this);
    355354    mSearchString->setSizePolicy (QSizePolicy::Preferred,
    356355                                  QSizePolicy::Fixed);
     
    358357             this, SLOT (findCurrent (const QString &)));
    359358
    360     mButtonNext = new QIToolButton (this);
    361     mButtonNext->setEnabled (false);
    362     mButtonNext->setAutoRaise (true);
    363     mButtonNext->setFocusPolicy (Qt::TabFocus);
    364     mButtonNext->setToolButtonStyle (Qt::ToolButtonTextBesideIcon);
    365     connect (mButtonNext, SIGNAL (clicked()), this, SLOT (findNext()));
    366     mButtonNext->setIcon (VBoxGlobal::iconSet (":/list_movedown_16px.png",
    367                                                ":/list_movedown_disabled_16px.png"));
    368 
    369     mButtonPrev = new QIToolButton (this);
    370     mButtonPrev->setEnabled (false);
    371     mButtonPrev->setAutoRaise (true);
    372     mButtonPrev->setFocusPolicy (Qt::TabFocus);
    373     mButtonPrev->setToolButtonStyle (Qt::ToolButtonTextBesideIcon);
    374     connect (mButtonPrev, SIGNAL (clicked()), this, SLOT (findBack()));
    375     mButtonPrev->setIcon (VBoxGlobal::iconSet (":/list_moveup_16px.png",
    376                                                ":/list_moveup_disabled_16px.png"));
     359    mButtonsNextPrev = new VBoxSegmentedButton (2, this);
     360    mButtonsNextPrev->setEnabled (0, false);
     361    mButtonsNextPrev->setIcon (0, VBoxGlobal::iconSet (":/list_movedown_16px.png",
     362                                                       ":/list_movedown_disabled_16px.png"));
     363    mButtonsNextPrev->setEnabled (1, false);
     364    mButtonsNextPrev->setIcon (1, VBoxGlobal::iconSet (":/list_moveup_16px.png",
     365                                                       ":/list_moveup_disabled_16px.png"));
     366    connect (mButtonsNextPrev, SIGNAL (clicked (int)), this, SLOT (find (int)));
    377367
    378368    mCaseSensitive = new QCheckBox (this);
     
    391381    QSpacerItem *spacer = new QSpacerItem (0, 0, QSizePolicy::Expanding,
    392382                                                 QSizePolicy::Minimum);
     383
     384#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
     385    QFont font = mSearchName->font();
     386    font.setPointSize (::darwinSmallFontSize());
     387    mSearchName->setFont (font);
     388    mCaseSensitive->setFont (font);
     389    mWarningString->setFont (font);
     390#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    393391
    394392    QHBoxLayout *mainLayout = new QHBoxLayout (this);
     
    398396    mainLayout->addWidget (mSearchName);
    399397    mainLayout->addWidget (mSearchString);
    400     mainLayout->addWidget (mButtonNext);
    401     mainLayout->addWidget (mButtonPrev);
     398    mainLayout->addWidget (mButtonsNextPrev);
    402399    mainLayout->addWidget (mCaseSensitive);
    403400    mainLayout->addItem   (mWarningSpacer);
     
    419416    mSearchString->setToolTip (tr ("Enter a search string here"));
    420417
    421     VBoxGlobal::setTextLabel (mButtonPrev, tr ("&Previous"));
    422     mButtonPrev->setToolTip (tr ("Search for the previous occurrence "
    423                                  "of the string"));
    424 
    425     VBoxGlobal::setTextLabel (mButtonNext, tr ("&Next"));
    426     mButtonNext->setToolTip (tr ("Search for the next occurrence of "
    427                                  "the string"));
     418    mButtonsNextPrev->setTitle (0, tr ("&Next"));
     419    mButtonsNextPrev->setToolTip (0, tr ("Search for the previous occurrence "
     420                                         "of the string"));
     421
     422    mButtonsNextPrev->setTitle (1, tr ("&Previous"));
     423    mButtonsNextPrev->setToolTip (1, tr ("Search for the next occurrence of "
     424                                         "the string"));
     425
    428426
    429427    mCaseSensitive->setText (tr ("C&ase Sensitive"));
     
    436434void VBoxLogSearchPanel::findCurrent (const QString &aSearchString)
    437435{
    438     mButtonNext->setEnabled (aSearchString.length());
    439     mButtonPrev->setEnabled (aSearchString.length());
     436    mButtonsNextPrev->setEnabled (0, aSearchString.length());
     437    mButtonsNextPrev->setEnabled (1, aSearchString.length());
    440438    toggleWarning (!aSearchString.length());
    441439    if (aSearchString.length())
     
    507505                (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return))
    508506            {
    509                 mButtonNext->animateClick();
     507                mButtonsNextPrev->animateClick (0);
    510508                return true;
    511509            }
     
    514512            {
    515513                if (e->QInputEvent::modifiers() == 0)
    516                     mButtonNext->animateClick();
     514                    mButtonsNextPrev->animateClick (0);
    517515                else if (e->QInputEvent::modifiers() == Qt::ShiftModifier)
    518                     mButtonPrev->animateClick();
     516                    mButtonsNextPrev->animateClick (1);
    519517                return true;
    520518            }
     
    573571    mWarningSpacer->changeSize (aHide ? 0 : 16, 0, QSizePolicy::Fixed,
    574572                                                   QSizePolicy::Minimum);
     573    if (!aHide)
     574        mSearchString->markError();
     575    else
     576        mSearchString->unmarkError();
    575577    mWarningIcon->setHidden (aHide);
    576578    mWarningString->setHidden (aHide);
    577579}
    578580
     581void VBoxLogSearchPanel::find (int aButton)
     582{
     583    if (aButton == 0)
     584        findNext();
     585    else
     586        findBack();
     587}
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-cocoa.mm

    r24106 r24107  
    2828#import <AppKit/NSEvent.h>
    2929#import <AppKit/NSColor.h>
     30#import <AppKit/NSFont.h>
    3031
    3132NativeWindowRef darwinToNativeWindowImpl (NativeViewRef aView)
     
    3637    if (aView)
    3738        window = [aView window];
    38 
     39   
    3940    [pool release];
    4041    return window;
     
    4748    NativeViewRef view = NULL;
    4849    if (aWindow)
    49         view = [aWindow contentView];
     50        view = [aWindow contentView];   
    5051
    5152    [pool release];
     
    156157}
    157158
     159int darwinWindowToolBarHeight (NativeWindowRef aWindow)
     160{
     161    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     162
     163    NSToolbar *toolbar = [aWindow toolbar];
     164    NSRect windowFrame = [aWindow frame];
     165    int toolbarHeight = 0;
     166    int theight = (NSHeight([NSWindow contentRectForFrameRect:[aWindow frame] styleMask:[aWindow styleMask]]) - NSHeight([[aWindow contentView] frame]));
     167    /* toolbar height: */
     168    if(toolbar && [toolbar isVisible])
     169        /* title bar height: */
     170        toolbarHeight = NSHeight (windowFrame) - NSHeight ([[aWindow contentView] frame]) - theight;
     171
     172    [pool release];
     173    return toolbarHeight;
     174}
     175
     176float darwinSmallFontSize()
     177{
     178    return [NSFont systemFontSizeForControlSize: NSSmallControlSize];
     179}
     180
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