- Timestamp:
- Mar 28, 2013 9:01:39 AM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc
r45221 r45223 192 192 <file alias="previous_16px.png">images/previous_16px.png</file> 193 193 <file alias="expanding_collapsing_16px.png">images/expanding_collapsing_16px.png</file> 194 <file alias="preview_empty_228x168px.png">images/preview_empty_228x168px.png</file> 195 <file alias="preview_full_228x168px.png">images/preview_full_228x168px.png</file> 194 196 </qresource> 195 197 </RCC> -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.cpp
r44528 r45223 52 52 , m_pUpdateTimer(new QTimer(this)) 53 53 , m_pUpdateTimerMenu(0) 54 , m_vMargin(10) 55 , m_pbgImage(0) 54 , m_iMargin(0) 55 , m_pbgEmptyImage(0) 56 , m_pbgFullImage(0) 56 57 , m_pPreviewImg(0) 57 , m_pGlossyImg(0)58 58 { 59 59 /* Setup contents: */ … … 62 62 /* Create session instance: */ 63 63 m_session.createInstance(CLSID_Session); 64 65 /* Create bg images: */ 66 m_pbgEmptyImage = new QPixmap(":/preview_empty_228x168px.png"); 67 m_pbgFullImage = new QPixmap(":/preview_full_228x168px.png"); 64 68 65 69 /* Create the context menu: */ … … 99 103 if (m_session.GetState() == KSessionState_Locked) 100 104 m_session.UnlockMachine(); 101 if (m_pbgImage) 102 delete m_pbgImage; 103 if (m_pGlossyImg) 104 delete m_pGlossyImg; 105 delete m_pbgEmptyImage; 106 delete m_pbgFullImage; 105 107 if (m_pPreviewImg) 106 108 delete m_pPreviewImg; … … 226 228 void UIGMachinePreview::resizeEvent(QGraphicsSceneResizeEvent *pEvent) 227 229 { 228 re paintBGImages();230 recalculatePreviewRectangle(); 229 231 sltRecreatePreview(); 230 232 QIGraphicsWidget::resizeEvent(pEvent); … … 267 269 { 268 270 if (which == Qt::MinimumSize) 269 return QSize(220, (int)(220 * 3.0/4.0)); 271 return QSize(228 /* pixmap width */ + 2 * m_iMargin, 272 168 /* pixmap height */ + 2 * m_iMargin); 270 273 return QIGraphicsWidget::sizeHint(which, constraint); 271 274 } … … 277 280 if (!cr.isValid()) 278 281 return; 279 /* Draw the background with the monitor and the shadow: */280 if (m_pbgImage)281 pPainter->drawImage(cr.x(), cr.y(), *m_pbgImage);282 282 283 283 /* If there is a preview image available: */ 284 284 if (m_pPreviewImg) 285 285 { 286 /* Draw empty background: */ 287 pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_pbgEmptyImage); 288 286 289 /* Draw that image: */ 287 290 pPainter->drawImage(0, 0, *m_pPreviewImg); … … 289 292 else 290 293 { 291 /* Fill rectangle with black color: */292 pPainter-> fillRect(m_vRect, Qt::black);294 /* Draw full background: */ 295 pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_pbgFullImage); 293 296 294 297 /* Compose name: */ … … 317 320 pPainter->drawText(m_vRect, fFlags, strName); 318 321 } 319 320 /* Draw the glossy overlay last: */321 if (m_pGlossyImg)322 pPainter->drawImage(m_vRect.x(), m_vRect.y(), *m_pGlossyImg);323 322 } 324 323 … … 370 369 } 371 370 372 void UIGMachinePreview::repaintBGImages() 373 { 374 /* Delete the old images: */ 375 if (m_pbgImage) 376 { 377 delete m_pbgImage; 378 m_pbgImage = 0; 379 } 380 if (m_pGlossyImg) 381 { 382 delete m_pGlossyImg; 383 m_pGlossyImg = 0; 384 } 385 386 /* Check that there is enough room for our fancy stuff. 387 * If not we just draw nothing (the border and the blur radius). */ 371 void UIGMachinePreview::recalculatePreviewRectangle() 372 { 373 /* Contents rectangle: */ 388 374 QRect cr = contentsRect().toRect(); 389 if (cr.width() < 41 || cr.height() < 41) 390 return; 391 392 QPalette pal = palette(); 393 m_wRect = cr.adjusted(10, 10, -10, -10); 394 m_vRect = m_wRect.adjusted(m_vMargin, m_vMargin, -m_vMargin, -m_vMargin).adjusted(-3, -3, 3, 3); 395 396 /* First draw the shadow. Its a rounded rectangle which get blurred: */ 397 QImage imageW(cr.size(), QImage::Format_ARGB32); 398 QColor bg = pal.color(QPalette::Base); 399 bg.setAlpha(0); /* We want blur to transparent _and_ whatever the base color is. */ 400 imageW.fill(bg.rgba()); 401 QPainter pW(&imageW); 402 pW.setBrush(QColor(30, 30, 30)); /* Dark gray */ 403 pW.setPen(Qt::NoPen); 404 pW.drawRoundedRect(QRect(QPoint(0, 0), cr.size()).adjusted(10, 10, -10, -10), m_vMargin, m_vMargin); 405 pW.end(); 406 /* Blur the rectangle */ 407 QImage imageO(cr.size(), QImage::Format_ARGB32); 408 blurImage(imageW, imageO, 10); 409 QPainter pO(&imageO); 410 411 /* Now paint the border with a gradient to get a look of a monitor: */ 412 QRect rr = QRect(QPoint(0, 0), cr.size()).adjusted(10, 10, -10, -10); 413 QLinearGradient lg(0, rr.y(), 0, rr.height()); 414 QColor base(200, 200, 200); /* light variant */ 415 // QColor base(80, 80, 80); /* Dark variant */ 416 lg.setColorAt(0, base); 417 lg.setColorAt(0.4, base.darker(300)); 418 lg.setColorAt(0.5, base.darker(400)); 419 lg.setColorAt(0.7, base.darker(300)); 420 lg.setColorAt(1, base); 421 pO.setBrush(lg); 422 pO.setPen(QPen(base.darker(150), 1)); 423 pO.drawRoundedRect(rr, m_vMargin, m_vMargin); 424 pO.end(); 425 426 /* Make a copy of the new bg image: */ 427 m_pbgImage = new QImage(imageO); 428 429 /* Now the glossy overlay has to be created. 430 * Start with defining a nice looking painter path. */ 431 QRect gRect = QRect(QPoint(0, 0), m_vRect.size()); 432 QPainterPath glossyPath(QPointF(gRect.x(), gRect.y())); 433 glossyPath.lineTo(gRect.x() + gRect.width(), gRect.y()); 434 glossyPath.lineTo(gRect.x() + gRect.width(), gRect.y() + gRect.height() * 1.0/3.0); 435 glossyPath.cubicTo(gRect.x() + gRect.width() / 2.0, gRect.y() + gRect.height() * 1.0/3.0, 436 gRect.x() + gRect.width() / 2.0, gRect.y() + gRect.height() * 2.0/3.0, 437 gRect.x(), gRect.y() + gRect.height() * 2.0/3.0); 438 glossyPath.closeSubpath(); 439 440 /* Paint the glossy path on a QImage: */ 441 QImage image(m_vRect.size(), QImage::Format_ARGB32); 442 QColor bg1(Qt::white); /* We want blur to transparent _and_ white. */ 443 bg1.setAlpha(0); 444 image.fill(bg1.rgba()); 445 QPainter painter(&image); 446 painter.fillPath(glossyPath, QColor(255, 255, 255, 80)); 447 painter.end(); 448 /* Blur the image to get a much more smooth feeling */ 449 QImage image1(m_vRect.size(), QImage::Format_ARGB32); 450 blurImage(image, image1, 7); 451 m_pGlossyImg = new QImage(image1); 452 453 /* Repaint: */ 454 update(); 375 m_vRect = cr.adjusted(21 + m_iMargin, 17 + m_iMargin, -21 - m_iMargin, -20 - m_iMargin); 455 376 } 456 377 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.h
r44528 r45223 35 35 class QAction; 36 36 class QImage; 37 class QPixmap; 37 38 class QMenu; 38 39 class QTimer; … … 97 98 /* Helpers: Update stuff: */ 98 99 void setUpdateInterval(UpdateInterval interval, bool fSave); 99 void re paintBGImages();100 void recalculatePreviewRectangle(); 100 101 void restart(); 101 102 void stop(); … … 108 109 QMenu *m_pUpdateTimerMenu; 109 110 QHash<UpdateInterval, QAction*> m_actions; 110 const int m_vMargin; 111 QRect m_wRect; 111 const int m_iMargin; 112 112 QRect m_vRect; 113 QImage *m_pbgImage; 113 QPixmap *m_pbgEmptyImage; 114 QPixmap *m_pbgFullImage; 114 115 QImage *m_pPreviewImg; 115 QImage *m_pGlossyImg;116 116 static UpdateIntervalMap m_intervals; 117 117 };
Note:
See TracChangeset
for help on using the changeset viewer.