VirtualBox

Changeset 15804 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 5, 2009 2:55:35 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: new look of the dock preview icon

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
4 added
1 deleted
8 edited

Legend:

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

    r15513 r15804  
    382382        src/darwin/DarwinKeyboard.cpp \
    383383        src/darwin/VBoxUtils-darwin.cpp \
     384        src/darwin/VBoxDockIconPreview.cpp \
    384385        src/VBoxFBQuartz2D.cpp
    385 #       src/darwin/VBoxAquaStyle.cpp
    386386
    387387ifdef VBOX_WITH_ICHAT_THEATER
  • trunk/src/VBox/Frontends/VirtualBox4/VirtualBox.qrc

    r15501 r15804  
    301301    <file alias="meditation_32px.png">images/meditation_32px.png</file>
    302302    <file alias="welcome.png">images/welcome.png</file>
    303     <file alias="dock_1.png">images/dock_1.png</file>
     303    <file alias="monitor.png">images/monitor.png</file>
     304    <file alias="monitor_glossy.png">images/monitor_glossy.png</file>
    304305 </qresource>
    305306 </RCC>
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h

    r15652 r15804  
    4545class MousePointerChangeEvent;
    4646class VBoxFrameBuffer;
     47class VBoxDockIconPreview;
    4748
    4849class QPainter;
     
    128129#if defined(Q_WS_MAC)
    129130    void updateDockIcon();
     131    void updateDockOverlay();
    130132    void setDockIconEnabled (bool aOn) { mDockIconEnabled = aOn; };
    131133    void setMouseCoalescingEnabled (bool aOn);
     
    323325    QPixmap mPausedShot;
    324326#if defined(Q_WS_MAC)
    325     CGImageRef mVirtualBoxLogo;
     327    VBoxDockIconPreview *mDockIconPreview;
    326328    bool mDockIconEnabled;
    327329#endif
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleWnd.h

    r15469 r15804  
    111111    void clearMask();
    112112
    113 #if defined (Q_WS_MAC)
    114     CGImageRef dockImageState () const;
    115 #endif
     113    KMachineState machineState() const { return machine_state; }
    116114
    117115public slots:
     
    372370    QRect mNormalGeometry;
    373371    Qt::WindowFlags mSavedFlags;
    374     /* Dock images */
    375     CGImageRef dockImgStatePaused;
    376     CGImageRef dockImgStateSaving;
    377     CGImageRef dockImgStateRestoring;
    378     CGImageRef dockImgBack100x75;
    379     CGImageRef dockImgOS;
    380372    /* For the fade effect if the the window goes fullscreen */
    381373    CGDisplayFadeReservationToken mFadeToken;
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h

    r15642 r15804  
    209209QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
    210210
    211 /* Special routines for the dock handling */
    212 CGImageRef darwinCreateDockBadge (const char *aSource);
    213 void darwinUpdateDockPreview (QWidget *aMainWindow, CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
    214 void darwinUpdateDockPreview (QWidget *aMainWindow, VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
    215 
    216211/* Icons in the menu of an mac application are unusual. */
    217212void darwinDisableIconsInMenus();
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp

    r15652 r15804  
    8080
    8181#if defined (Q_WS_MAC)
     82# include "VBoxDockIconPreview.h"
    8283# include "DarwinKeyboard.h"
    8384# ifdef VBOX_WITH_HACKED_QT
     
    670671    , mDarwinKeyModifiers (0)
    671672    , mKeyboardGrabbed (false)
    672     , mVirtualBoxLogo (NULL)
    673673    , mDockIconEnabled (true)
    674674#endif
     
    683683#ifdef Q_WS_MAC
    684684    /* Overlay logo for the dock icon */
    685     mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_cube_42px.png");
     685    //mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_cube_42px.png");
     686    QString osTypeId = mConsole.GetGuest().GetOSTypeId();
     687    mDockIconPreview = new VBoxDockIconPreview (mMainWnd, vboxGlobal().vmGuestOSTypeIcon (osTypeId));
    686688
    687689    /* Install the event handler which will proceed external window handling */
     
    885887        mDarwinWindowOverlayHandlerRef = NULL;
    886888    }
    887     CGImageRelease (mVirtualBoxLogo);
     889    delete mDockIconPreview;
    888890#endif
    889891}
     
    39033905    {
    39043906        if (!mPausedShot.isNull())
     3907        {
     3908            CGImageRef pauseImg = ::darwinToCGImageRef (&mPausedShot);
    39053909            /* Use the pause image as background */
    3906             ::darwinUpdateDockPreview (mMainWnd, ::darwinToCGImageRef (&mPausedShot), mVirtualBoxLogo, mMainWnd->dockImageState());
     3910            mDockIconPreview->updateDockPreview (pauseImg);
     3911            CGImageRelease (pauseImg);
     3912        }
    39073913        else
    39083914        {
     
    39133919                 * of the framebuffer for the dock icon creation. This saves
    39143920                 * some conversion time. */
    3915                 ::darwinUpdateDockPreview (mMainWnd, static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef(), mVirtualBoxLogo, mMainWnd->dockImageState());
     3921                mDockIconPreview->updateDockPreview (static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef());
    39163922            }
    39173923            else
     
    39193925                /* In image mode we have to create the image ref out of the
    39203926                 * framebuffer */
    3921                 ::darwinUpdateDockPreview (mMainWnd, mFrameBuf, mVirtualBoxLogo, mMainWnd->dockImageState());
    3922         }
    3923     }
     3927                mDockIconPreview->updateDockPreview (mFrameBuf);
     3928        }
     3929    }
     3930}
     3931
     3932void VBoxConsoleView::updateDockOverlay()
     3933{
     3934    if (mDockIconEnabled)
     3935        updateDockIcon();
     3936    else
     3937        mDockIconPreview->updateDockOverlay ();
    39243938}
    39253939
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp

    r15642 r15804  
    238238    , mDbgGui (NULL)
    239239    , mDbgGuiVT (NULL)
    240 #endif
    241 #ifdef Q_WS_MAC
    242     , dockImgStatePaused (NULL)
    243     , dockImgStateSaving (NULL)
    244     , dockImgStateRestoring (NULL)
    245     , dockImgBack100x75 (NULL)
    246     , dockImgOS (NULL)
    247240#endif
    248241{
     
    694687    initSharedAVManager();
    695688# endif
    696     /* prepare the dock images */
    697     dockImgStatePaused    = ::darwinCreateDockBadge (":/state_paused_16px.png");
    698     dockImgStateSaving    = ::darwinCreateDockBadge (":/state_saving_16px.png");
    699     dockImgStateRestoring = ::darwinCreateDockBadge (":/state_restoring_16px.png");
    700     dockImgBack100x75     = ::darwinCreateDockBadge (":/dock_1.png");
    701     SetApplicationDockTileImage (dockImgOS);
    702689#endif
    703690    mMaskShift.scale (0, 0, Qt::IgnoreAspectRatio);
     
    707694{
    708695    closeView();
    709 
    710 #ifdef Q_WS_MAC
    711     /* release the dock images */
    712     if (dockImgStatePaused)
    713         CGImageRelease (dockImgStatePaused);
    714     if (dockImgStateSaving)
    715         CGImageRelease (dockImgStateSaving);
    716     if (dockImgStateRestoring)
    717         CGImageRelease (dockImgStateRestoring);
    718     if (dockImgBack100x75)
    719         CGImageRelease (dockImgBack100x75);
    720     if (dockImgOS)
    721         CGImageRelease (dockImgOS);
    722 #endif
    723696
    724697#ifdef VBOX_WITH_DEBUGGER_GUI
     
    951924    bool f = (testStr.isEmpty() || testStr == "true");
    952925    console->setDockIconEnabled (f);
    953     if (f)
    954     {
    955         QString osTypeId = cmachine.GetOSTypeId();
    956         QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).toImage().scaled (100, 75, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    957         QImage osImg = QImage (":/dock_1.png");
    958         QImage VBoxOverlay = QImage (":/VirtualBox_cube_42px.png");
    959         QPainter painter (&osImg);
    960         painter.drawImage (QPoint (14, 22), osImg100x75);
    961         painter.drawImage (QPoint (osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height()), VBoxOverlay);
    962         painter.end();
    963         if (dockImgOS)
    964             CGImageRelease (dockImgOS);
    965         dockImgOS = ::darwinToCGImageRef (&osImg);
    966         SetApplicationDockTileImage (dockImgOS);
    967     }
     926    console->updateDockOverlay();
    968927#endif
    969928
     
    24492408}
    24502409
    2451 #ifdef Q_WS_MAC
    2452 CGImageRef VBoxConsoleWnd::dockImageState() const
    2453 {
    2454     CGImageRef img;
    2455     if (machine_state == KMachineState_Paused)
    2456         img = dockImgStatePaused;
    2457     else if (machine_state == KMachineState_Restoring)
    2458         img = dockImgStateRestoring;
    2459     else if (machine_state == KMachineState_Saving)
    2460         img = dockImgStateSaving;
    2461     else
    2462         img = NULL;
    2463     return img;
    2464 }
    2465 #endif
    2466 
    24672410void VBoxConsoleWnd::changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &e)
    24682411{
     
    24712414    {
    24722415        console->setDockIconEnabled (e.mChanged);
    2473         if (e.mChanged)
    2474             console->updateDockIcon();
    2475         else
    2476         {
    2477             RestoreApplicationDockTileImage();
    2478             CGImageRef img = dockImageState();
    2479             if (img)
    2480                 OverlayApplicationDockTileImage (img);
    2481         }
     2416        console->updateDockOverlay();
    24822417    }
    24832418#else
     
    34873422
    34883423#ifdef Q_WS_MAC
    3489     CGImageRef img = dockImageState();
    3490     if (img)
    3491         OverlayApplicationDockTileImage (img);
    3492     else
    3493         RestoreApplicationDockTileImage();
     3424    if (console)
     3425        console->updateDockOverlay();
    34943426#endif
    34953427}
  • trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp

    r15642 r15804  
    140140    painter.end();
    141141    return dragPixmap;
    142 }
    143 
    144 /**
    145  * Creates a dock badge image.
    146  *
    147  * The badge will be placed on the right hand size and vertically centered
    148  * after having been scaled up to 32x32.
    149  *
    150  * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
    151  * @param   aSource     The source name.
    152  */
    153 CGImageRef darwinCreateDockBadge (const char *aSource)
    154 {
    155     /* Create a transparent image in size 128x128. */
    156     QImage transImage (128, 128, QImage::Format_ARGB32);
    157     transImage.fill (qRgba (0, 0, 0, 0));
    158     /* load the badge */
    159     QImage badge (aSource);
    160     Assert (!badge.isNull());
    161     /* resize it and copy it onto the background. */
    162     if (badge.width() < 32)
    163         badge = badge.scaled (32, 32, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    164     QPainter painter (&transImage);
    165     painter.drawImage (QPoint ((transImage.width() - badge.width()) / 2.0,
    166                                (transImage.height() - badge.height()) / 2.0),
    167                        badge);
    168     painter.end();
    169     /* Convert it to a CGImage. */
    170     return ::darwinToCGImageRef (&transImage);
    171 }
    172 
    173 /* Import private function to capture the window content of any given window. */
    174 CG_EXTERN_C_BEGIN
    175 typedef int CGSWindowID;
    176 typedef void *CGSConnectionID;
    177 CG_EXTERN CGSWindowID GetNativeWindowFromWindowRef(WindowRef ref);
    178 CG_EXTERN CGSConnectionID CGSMainConnectionID(void);
    179 CG_EXTERN void CGContextCopyWindowCaptureContentsToRect(CGContextRef c, CGRect dstRect, CGSConnectionID connection, CGSWindowID window, int zero);
    180 CG_EXTERN_C_END
    181 
    182 /**
    183  * Updates the dock preview image.
    184  *
    185  * This method is a callback that updates the 128x128 preview image of the VM window in the dock.
    186  *
    187  * @param   aVMImage   the vm screen as a CGImageRef
    188  * @param   aOverlayImage   an optional icon overlay image to add at the bottom right of the icon
    189  * @param   aStateImage   an optional state overlay image to add at the center of the icon
    190  */
    191 void darwinUpdateDockPreview (QWidget *aMainWindow, CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)
    192 {
    193     Assert (aVMImage);
    194 
    195     CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
    196     Assert (cs);
    197 
    198     /* Calc the size of the dock icon image and fit it into 128x128 */
    199     int targetWidth = 128;
    200     int targetHeight = 128;
    201     int scaledWidth;
    202     int scaledHeight;
    203     float aspect = static_cast <float> (CGImageGetWidth (aVMImage)) / CGImageGetHeight (aVMImage);
    204     if (aspect > 1.0)
    205     {
    206         scaledWidth = targetWidth;
    207         scaledHeight = targetHeight / aspect;
    208     }
    209     else
    210     {
    211         scaledWidth = targetWidth * aspect;
    212         scaledHeight = targetHeight;
    213     }
    214     CGRect iconRect = CGRectMake ((targetWidth - scaledWidth) / 2.0,
    215                                   (targetHeight - scaledHeight) / 2.0,
    216                                   scaledWidth, scaledHeight);
    217     /* Create the context to draw on */
    218     CGContextRef context = BeginCGContextForApplicationDockTile();
    219     Assert (context);
    220     /* Clear the background */
    221     CGContextSetBlendMode (context, kCGBlendModeNormal);
    222     CGContextClearRect (context, CGRectMake (0, 0, 128, 128));
    223     /* rounded corners */
    224 //        CGContextSetLineJoin (context, kCGLineJoinRound);
    225 //        CGContextSetShadow (context, CGSizeMake (10, 5), 1);
    226 //        CGContextSetAllowsAntialiasing (context, true);
    227     /* some little boarder */
    228     iconRect = CGRectInset (iconRect, 1, 1);
    229     /* gray stroke */
    230     CGContextSetRGBStrokeColor (context, 225.0/255.0, 218.0/255.0, 211.0/255.0, 1);
    231     iconRect = CGRectInset (iconRect, 6, 6);
    232     CGContextStrokeRectWithWidth (context, iconRect, 12);
    233     iconRect = CGRectInset (iconRect, 5, 5);
    234     /* black stroke */
    235     CGContextSetRGBStrokeColor (context, 0.0, 0.0, 0.0, 1.0);
    236     CGContextStrokeRectWithWidth (context, iconRect, 2);
    237     /* vm content */
    238     iconRect = CGRectInset (iconRect, 1, 1);
    239     CGContextDrawImage (context, iconRect, aVMImage);
    240     /* Process the content of any external OpenGL windows. */
    241     WindowRef w = darwinToWindowRef (aMainWindow);
    242     WindowGroupRef g = GetWindowGroup (w);
    243     WindowGroupContentOptions wgco = kWindowGroupContentsReturnWindows | kWindowGroupContentsRecurse | kWindowGroupContentsVisible;
    244     ItemCount c = CountWindowGroupContents (g, wgco);
    245     float a1 = iconRect.size.width / static_cast <float> (CGImageGetWidth (aVMImage));
    246     float a2 = iconRect.size.height / static_cast <float> (CGImageGetHeight (aVMImage));
    247     HIViewRef mainView = HIViewGetRoot (w);
    248     Rect tmpR;
    249     GetWindowBounds (w, kWindowContentRgn, &tmpR);
    250     HIRect mainRect = CGRectMake (tmpR.left, tmpR.top, tmpR.right-tmpR.left, tmpR.bottom-tmpR.top);
    251     for (ItemCount i = 0; i <= c; ++i)
    252     {
    253         WindowRef wc;
    254         OSStatus status = GetIndexedWindow (g, i, wgco, &wc);
    255         if (status == noErr &&
    256             wc != w)
    257         {
    258             WindowClass winClass;
    259             status = GetWindowClass (wc, &winClass);
    260             if (status == noErr &&
    261                 winClass == kOverlayWindowClass)
    262             {
    263                 Rect tmpR1;
    264                 GetWindowBounds (wc, kWindowContentRgn, &tmpR1);
    265                 HIRect rect;
    266                 rect.size.width = (tmpR1.right-tmpR1.left) * a1;
    267                 rect.size.height = (tmpR1.bottom-tmpR1.top) * a2;
    268                 rect.origin.x = iconRect.origin.x + (tmpR1.left - mainRect.origin.x) * a1;
    269                 rect.origin.y = targetHeight - (iconRect.origin.y + (tmpR1.top - mainRect.origin.y) * a2) - rect.size.height;
    270                 /* This is a big, bad hack. The following functions aren't
    271                  * documented nor official supported by apple. But its the only way
    272                  * to capture the OpenGL content of a window without fiddling
    273                  * around with gPixelRead or something like that. */
    274                 CGSWindowID wid = GetNativeWindowFromWindowRef(wc);
    275                 CGContextCopyWindowCaptureContentsToRect(context, rect, CGSMainConnectionID(), wid, 0);
    276             }
    277         }
    278     }
    279 
    280     /* the state image at center */
    281     if (aStateImage)
    282     {
    283         CGRect stateRect = CGRectMake ((targetWidth - CGImageGetWidth (aStateImage)) / 2.0,
    284                                        (targetHeight - CGImageGetHeight (aStateImage)) / 2.0,
    285                                        CGImageGetWidth (aStateImage),
    286                                        CGImageGetHeight (aStateImage));
    287         CGContextDrawImage (context, stateRect, aStateImage);
    288     }
    289     /* the overlay image at bottom/right */
    290     if (aOverlayImage)
    291     {
    292 
    293         CGRect overlayRect = CGRectMake (targetWidth - CGImageGetWidth (aOverlayImage),
    294                                          0,
    295                                          CGImageGetWidth (aOverlayImage),
    296                                          CGImageGetHeight (aOverlayImage));
    297         CGContextDrawImage (context, overlayRect, aOverlayImage);
    298     }
    299     /* This flush updates the dock icon */
    300     CGContextFlush (context);
    301     EndCGContextForApplicationDockTile (context);
    302 
    303     CGColorSpaceRelease (cs);
    304 }
    305 
    306 /**
    307  * Updates the dock preview image.
    308  *
    309  * This method is a callback that updates the 128x128 preview image of the VM window in the dock.
    310  *
    311  * @param   aFrameBuffer    The guest frame buffer.
    312  * @param   aOverlayImage   an optional icon overlay image to add at the bottom right of the icon
    313  */
    314 void darwinUpdateDockPreview (QWidget *aMainWindow, VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)
    315 {
    316     CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
    317     Assert (cs);
    318     /* Create the image copy of the framebuffer */
    319     CGDataProviderRef dp = CGDataProviderCreateWithData (aFrameBuffer, aFrameBuffer->address(), aFrameBuffer->bitsPerPixel() / 8 * aFrameBuffer->width() * aFrameBuffer->height(), NULL);
    320     Assert (dp);
    321     CGImageRef ir = CGImageCreate (aFrameBuffer->width(), aFrameBuffer->height(), 8, 32, aFrameBuffer->bytesPerLine(), cs,
    322                                    kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host, dp, 0, false,
    323                                    kCGRenderingIntentDefault);
    324     /* Update the dock preview icon */
    325     ::darwinUpdateDockPreview (aMainWindow, ir, aOverlayImage, aStateImage);
    326     /* Release the temp data and image */
    327     CGDataProviderRelease (dp);
    328     CGImageRelease (ir);
    329     CGColorSpaceRelease (cs);
    330142}
    331143
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