Changeset 51740 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 26, 2014 2:43:09 PM (10 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 deleted
- 8 edited
- 10 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/VirtualBox1.qrc
r51472 r51740 254 254 <file alias="os_win2k3_64.png">images/os_win2k3_64.png</file> 255 255 <file alias="os_win2k8.png">images/os_win2k8.png</file> 256 <file alias="os_win2k8_64.png">images/os_win2k8_64.png</file> 257 <file alias="os_win31.png">images/os_win31.png</file> 256 258 </qresource> 257 259 </RCC> -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox1_hidpi.qrc
r51472 r51740 236 236 <file alias="os_os2ecs_hidpi.png">images/hidpi/os_os2ecs_hidpi.png</file> 237 237 <file alias="os_os2warp3_hidpi.png">images/hidpi/os_os2warp3_hidpi.png</file> 238 <file alias="os_os2warp45_hidpi.png">images/hidpi/os_os2warp45_hidpi.png</file> 239 <file alias="os_os2warp4_hidpi.png">images/hidpi/os_os2warp4_hidpi.png</file> 238 240 </qresource> 239 241 </RCC> -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc
r51472 r51740 1 1 <RCC> 2 2 <qresource prefix="/"> 3 <file alias="os_win2k8_64.png">images/os_win2k8_64.png</file>4 <file alias="os_win31.png">images/os_win31.png</file>5 3 <file alias="os_win7.png">images/os_win7.png</file> 6 4 <file alias="os_win7_64.png">images/os_win7_64.png</file> … … 23 21 <file alias="parallel_port_warning_16px.png">images/parallel_port_warning_16px.png</file> 24 22 <file alias="pin_16px.png">images/pin_16px.png</file> 25 <file alias="preview_empty_228x168px.png">images/preview_empty_228x168px.png</file> 26 <file alias="preview_full_228x168px.png">images/preview_full_228x168px.png</file> 23 <file alias="preview_empty_16to10_242x167px.png">images/preview_empty_16to10_242x167px.png</file> 24 <file alias="preview_empty_16to9_242x155px.png">images/preview_empty_16to9_242x155px.png</file> 25 <file alias="preview_empty_4to3_242x192px.png">images/preview_empty_4to3_242x192px.png</file> 26 <file alias="preview_full_16to10_242x167px.png">images/preview_full_16to10_242x167px.png</file> 27 <file alias="preview_full_16to9_242x155px.png">images/preview_full_16to9_242x155px.png</file> 28 <file alias="preview_full_4to3_242x192px.png">images/preview_full_4to3_242x192px.png</file> 27 29 <file alias="previous_16px.png">images/previous_16px.png</file> 28 30 <file alias="progress_clone_90px.png">images/progress_clone_90px.png</file> -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox2_hidpi.qrc
r51472 r51740 1 1 <RCC> 2 2 <qresource prefix="/"> 3 <file alias="os_os2warp45_hidpi.png">images/hidpi/os_os2warp45_hidpi.png</file>4 <file alias="os_os2warp4_hidpi.png">images/hidpi/os_os2warp4_hidpi.png</file>5 3 <file alias="os_other_64_hidpi.png">images/hidpi/os_other_64_hidpi.png</file> 6 4 <file alias="os_other_hidpi.png">images/hidpi/os_other_hidpi.png</file> … … 41 39 <file alias="parallel_port_warning_16px_hidpi.png">images/hidpi/parallel_port_warning_16px_hidpi.png</file> 42 40 <file alias="pin_16px_hidpi.png">images/hidpi/pin_16px_hidpi.png</file> 43 <file alias="preview_empty_228x168px_hidpi.png">images/hidpi/preview_empty_228x168px_hidpi.png</file> 44 <file alias="preview_full_228x168px_hidpi.png">images/hidpi/preview_full_228x168px_hidpi.png</file> 41 <file alias="preview_empty_16to10_242x167px_hidpi.png">images/hidpi/preview_empty_16to10_242x167px_hidpi.png</file> 42 <file alias="preview_empty_16to9_242x155px_hidpi.png">images/hidpi/preview_empty_16to9_242x155px_hidpi.png</file> 43 <file alias="preview_empty_4to3_242x192px_hidpi.png">images/hidpi/preview_empty_4to3_242x192px_hidpi.png</file> 44 <file alias="preview_full_16to10_242x167px_hidpi.png">images/hidpi/preview_full_16to10_242x167px_hidpi.png</file> 45 <file alias="preview_full_16to9_242x155px_hidpi.png">images/hidpi/preview_full_16to9_242x155px_hidpi.png</file> 46 <file alias="preview_full_4to3_242x192px_hidpi.png">images/hidpi/preview_full_4to3_242x192px_hidpi.png</file> 45 47 <file alias="previous_16px_hidpi.png">images/hidpi/previous_16px_hidpi.png</file> 46 48 <file alias="proxy_16px_hidpi.png">images/hidpi/proxy_16px_hidpi.png</file> -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElements.cpp
r51322 r51740 187 187 /* Create preview: */ 188 188 m_pPreview = new UIGMachinePreview(this); 189 connect(m_pPreview, SIGNAL(sigSizeHintChanged()), 190 this, SLOT(sltPreviewSizeHintChanged())); 189 191 pLayout->addItem(m_pPreview); 190 192 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); … … 192 194 /* Translate: */ 193 195 retranslateUi(); 196 } 197 198 void UIGDetailsElementPreview::sltPreviewSizeHintChanged() 199 { 200 /* Recursively update size-hints: */ 201 updateGeometry(); 202 /* Update whole model layout: */ 203 model()->updateLayout(); 194 204 } 195 205 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElements.h
r50041 r51740 137 137 UIGDetailsElementPreview(UIGDetailsSet *pParent, bool fOpened); 138 138 139 private slots: 140 141 /** Handles preview size-hint changes. */ 142 void sltPreviewSizeHintChanged(); 143 139 144 private: 140 145 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.cpp
r51708 r51740 42 42 , m_pUpdateTimerMenu(0) 43 43 , m_iMargin(0) 44 , m_pbgEmptyImage(0) 45 , m_pbgFullImage(0) 44 , m_preset(AspectRatioPreset_16x9) 46 45 , m_pPreviewImg(0) 47 46 { 48 /* Setup contents: */49 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);50 51 47 /* Create session instance: */ 52 48 m_session.createInstance(CLSID_Session); 53 49 54 /* Create bg images: */ 55 m_pbgEmptyImage = new QPixmap(UIIconPool::pixmap(":/preview_empty_228x168px.png")); 56 m_pbgFullImage = new QPixmap(UIIconPool::pixmap(":/preview_full_228x168px.png")); 50 /* Cache aspect-ratio preset settings: */ 51 const QIcon empty16x10 = UIIconPool::iconSet(":/preview_empty_16to10_242x167px.png"); 52 const QIcon empty16x9 = UIIconPool::iconSet(":/preview_empty_16to9_242x155px.png"); 53 const QIcon empty4x3 = UIIconPool::iconSet(":/preview_empty_4to3_242x192px.png"); 54 const QIcon full16x10 = UIIconPool::iconSet(":/preview_full_16to10_242x167px.png"); 55 const QIcon full16x9 = UIIconPool::iconSet(":/preview_full_16to9_242x155px.png"); 56 const QIcon full4x3 = UIIconPool::iconSet(":/preview_full_4to3_242x192px.png"); 57 m_sizes.insert(AspectRatioPreset_16x10, empty16x10.availableSizes().first()); 58 m_sizes.insert(AspectRatioPreset_16x9, empty16x9.availableSizes().first()); 59 m_sizes.insert(AspectRatioPreset_4x3, empty4x3.availableSizes().first()); 60 m_ratios.insert(AspectRatioPreset_16x10, (double)16/10); 61 m_ratios.insert(AspectRatioPreset_16x9, (double)16/9); 62 m_ratios.insert(AspectRatioPreset_4x3, (double)4/3); 63 m_emptyPixmaps.insert(AspectRatioPreset_16x10, new QPixmap(empty16x10.pixmap(m_sizes.value(AspectRatioPreset_16x10)))); 64 m_emptyPixmaps.insert(AspectRatioPreset_16x9, new QPixmap(empty16x9.pixmap(m_sizes.value(AspectRatioPreset_16x9)))); 65 m_emptyPixmaps.insert(AspectRatioPreset_4x3, new QPixmap(empty4x3.pixmap(m_sizes.value(AspectRatioPreset_4x3)))); 66 m_fullPixmaps.insert(AspectRatioPreset_16x10, new QPixmap(full16x10.pixmap(m_sizes.value(AspectRatioPreset_16x10)))); 67 m_fullPixmaps.insert(AspectRatioPreset_16x9, new QPixmap(full16x9.pixmap(m_sizes.value(AspectRatioPreset_16x9)))); 68 m_fullPixmaps.insert(AspectRatioPreset_4x3, new QPixmap(full4x3.pixmap(m_sizes.value(AspectRatioPreset_4x3)))); 69 70 /* Setup contents (depends on presets above!): */ 71 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 57 72 58 73 /* Create the context menu: */ … … 88 103 if (m_session.GetState() == KSessionState_Locked) 89 104 m_session.UnlockMachine(); 90 delete m_pbgEmptyImage; 91 delete m_pbgFullImage; 105 106 /* Destroy background images: */ 107 foreach (const AspectRatioPreset &preset, m_emptyPixmaps.keys()) 108 { 109 delete m_emptyPixmaps.value(preset); 110 m_emptyPixmaps.remove(preset); 111 } 112 foreach (const AspectRatioPreset &preset, m_fullPixmaps.keys()) 113 { 114 delete m_fullPixmaps.value(preset); 115 m_fullPixmaps.remove(preset); 116 } 117 118 /* Destroy preview image: */ 92 119 if (m_pPreviewImg) 93 120 delete m_pPreviewImg; 121 122 /* Destroy update timer: */ 94 123 if (m_pUpdateTimerMenu) 95 124 delete m_pUpdateTimerMenu; … … 151 180 /* Prepare image: */ 152 181 QImage image; 182 183 /* Use 10x9 as the aspect-ratio preset by default: */ 184 AspectRatioPreset preset = AspectRatioPreset_16x9; 153 185 154 186 /* Preview update enabled? */ … … 163 195 { 164 196 /* Use the screenshot from saved-state if possible: */ 165 ULONG uWidth = 0, uHeight = 0; 166 QVector<BYTE> screenData = m_machine.ReadSavedScreenshotPNGToArray(0, uWidth, uHeight); 167 if (m_machine.isOk() && !screenData.isEmpty()) 168 { 169 /* Create image based on shallow copy or screenshot data, 170 * scale image down if necessary to the size possible to reflect: */ 171 image = QImage::fromData(screenData.data(), screenData.size(), "PNG") 172 .scaled(imageAspectRatioSize(m_vRect.size(), QSize(uWidth, uHeight)), 173 Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 174 /* Dim image to give it required look: */ 175 dimImage(image); 176 } 197 ULONG uGuestWidth = 0, uGuestHeight = 0; 198 QVector<BYTE> screenData = m_machine.ReadSavedScreenshotPNGToArray(0, uGuestWidth, uGuestHeight); 199 200 /* Make sure screen-data is OK: */ 201 if (!m_machine.isOk() || screenData.isEmpty()) 202 break; 203 204 /* Calculate aspect-ratio: */ 205 double dAspectRatio = (double)uGuestWidth / uGuestHeight; 206 /* Look for the best aspect-ratio preset: */ 207 preset = bestAspectRatioPreset(dAspectRatio, m_ratios); 208 209 /* Create image based on shallow copy or screenshot data, 210 * scale image down if necessary to the size possible to reflect: */ 211 image = QImage::fromData(screenData.data(), screenData.size(), "PNG") 212 .scaled(imageAspectRatioSize(m_vRect.size(), QSize(uGuestWidth, uGuestHeight)), 213 Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 214 /* Dim image to give it required look: */ 215 dimImage(image); 177 216 break; 178 217 } … … 194 233 break; 195 234 196 /* Calculate aspect-ratio size: */ 235 /* Calculate aspect-ratio: */ 236 LONG iOriginX, iOriginY; 197 237 ULONG uGuestWidth, uGuestHeight, uBpp; 198 LONG iOriginX, iOriginY;199 238 display.GetScreenResolution(0, uGuestWidth, uGuestHeight, uBpp, iOriginX, iOriginY); 239 double dAspectRatio = (double)uGuestWidth / uGuestHeight; 240 /* Look for the best aspect-ratio preset preset: */ 241 preset = bestAspectRatioPreset(dAspectRatio, m_ratios); 242 243 /* Calculate size corresponding to aspect-ratio: */ 200 244 const QSize size = imageAspectRatioSize(m_vRect.size(), QSize(uGuestWidth, uGuestHeight)); 201 245 202 246 /* Use direct VM content: */ 203 247 QVector<BYTE> screenData = display.TakeScreenShotToArray(0, size.width(), size.height()); 204 if (display.isOk() && !screenData.isEmpty()) 248 249 /* Make sure screen-data is OK: */ 250 if (!display.isOk() || screenData.isEmpty()) 251 break; 252 253 /* Unfortunately we have to reorder the pixel data, 254 * cause the VBox API returns RGBA data, 255 * which is not a format QImage understand. */ 256 uint32_t *pData = (uint32_t*)screenData.data(); 257 for (int i = 0; i < screenData.size() / 4; ++i) 205 258 { 206 /* Unfortunately we have to reorder the pixel data, 207 * cause the VBox API returns RGBA data, 208 * which is not a format QImage understand. */ 209 uint32_t *pData = (uint32_t*)screenData.data(); 210 for (int i = 0; i < screenData.size() / 4; ++i) 211 { 212 uint32_t e = pData[i]; 213 pData[i] = RT_MAKE_U32_FROM_U8(RT_BYTE3(e), RT_BYTE2(e), RT_BYTE1(e), RT_BYTE4(e)); 214 } 215 /* Create image based on shallow copy or reordered data: */ 216 image = QImage((uchar*)pData, size.width(), size.height(), QImage::Format_RGB32); 217 /* Dim image to give it required look for PAUSED state: */ 218 if (machineState == KMachineState_Paused) 219 dimImage(image); 259 uint32_t e = pData[i]; 260 pData[i] = RT_MAKE_U32_FROM_U8(RT_BYTE3(e), RT_BYTE2(e), RT_BYTE1(e), RT_BYTE4(e)); 220 261 } 262 /* Create image based on shallow copy or reordered data: */ 263 image = QImage((uchar*)pData, size.width(), size.height(), QImage::Format_RGB32); 264 /* Dim image to give it required look for PAUSED state: */ 265 if (machineState == KMachineState_Paused) 266 dimImage(image); 221 267 break; 222 268 } … … 233 279 /* And detach that copy: */ 234 280 m_pPreviewImg->bits(); 281 } 282 283 /* If preset changed: */ 284 if (m_preset != preset) 285 { 286 /* Save new preset: */ 287 m_preset = preset; 288 /* And update geometry: */ 289 updateGeometry(); 290 emit sigSizeHintChanged(); 235 291 } 236 292 } … … 283 339 { 284 340 if (which == Qt::MinimumSize) 285 return QSize(228 /* pixmap width */ + 2 * m_iMargin, 286 168 /* pixmap height */ + 2 * m_iMargin); 341 { 342 AssertReturn(m_emptyPixmaps.contains(m_preset), 343 QIGraphicsWidget::sizeHint(which, constraint)); 344 QSize size = m_sizes.value(m_preset); 345 if (m_iMargin != 0) 346 { 347 size.setWidth(size.width() - 2 * m_iMargin); 348 size.setHeight(size.height() - 2 * m_iMargin); 349 } 350 return size; 351 } 287 352 return QIGraphicsWidget::sizeHint(which, constraint); 288 353 } … … 298 363 if (m_pPreviewImg) 299 364 { 300 /* Draw black background: */301 pPainter->fillRect(m_vRect, Qt::black);302 303 365 /* Draw empty monitor frame: */ 304 pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_ pbgEmptyImage);366 pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_emptyPixmaps.value(m_preset)); 305 367 306 368 /* Move image to viewport center: */ … … 313 375 { 314 376 /* Draw full monitor frame: */ 315 pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_ pbgFullImage);377 pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_fullPixmaps.value(m_preset)); 316 378 317 379 /* Paint preview name: */ … … 370 432 /* Contents rectangle: */ 371 433 QRect cr = contentsRect().toRect(); 372 m_vRect = cr.adjusted(21 + m_iMargin, 17 + m_iMargin, -21 - m_iMargin, -20- m_iMargin);434 m_vRect = cr.adjusted(21 + m_iMargin, 21 + m_iMargin, -21 - m_iMargin, -21 - m_iMargin); 373 435 } 374 436 … … 403 465 /* Stop the timer: */ 404 466 m_pUpdateTimer->stop(); 467 } 468 469 /* static */ 470 UIGMachinePreview::AspectRatioPreset UIGMachinePreview::bestAspectRatioPreset(const double dAspectRatio, 471 const QMap<AspectRatioPreset, double> &ratios) 472 { 473 /* Use 16x9 preset as the 'best' by 'default': */ 474 AspectRatioPreset bestPreset = AspectRatioPreset_16x9; 475 /* Calculate minimum diff based on 'default' preset: */ 476 double dMinimumDiff = qAbs(dAspectRatio - ratios.value(bestPreset)); 477 /* Now look for the 'best' aspect-ratio preset among existing: */ 478 for (AspectRatioPreset currentPreset = AspectRatioPreset_16x10; 479 currentPreset <= AspectRatioPreset_4x3; 480 currentPreset = (AspectRatioPreset)(currentPreset + 1)) 481 { 482 /* Calculate current diff based on 'current' preset: */ 483 const double dDiff = qAbs(dAspectRatio - ratios.value(currentPreset)); 484 /* If new 'best' preset found: */ 485 if (dDiff < dMinimumDiff) 486 { 487 /* Remember new diff: */ 488 dMinimumDiff = dDiff; 489 /* And new preset: */ 490 bestPreset = currentPreset; 491 } 492 } 493 /* Return 'best' preset: */ 494 return bestPreset; 405 495 } 406 496 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.h
r51708 r51740 45 45 Q_OBJECT; 46 46 47 signals: 48 49 /** Notifies about size-hint changes. */ 50 void sigSizeHintChanged(); 51 47 52 public: 48 53 … … 69 74 private: 70 75 76 /** Aspect ratio presets. */ 77 enum AspectRatioPreset 78 { 79 AspectRatioPreset_16x10, 80 AspectRatioPreset_16x9, 81 AspectRatioPreset_4x3, 82 }; 83 71 84 /* Helpers: Event handlers: */ 72 85 void resizeEvent(QGraphicsSceneResizeEvent *pEvent); … … 90 103 void stop(); 91 104 105 /** Looks for the best aspect-ratio preset for the passed @a dAspectRatio among all the passed @a ratios. */ 106 static AspectRatioPreset bestAspectRatioPreset(const double dAspectRatio, const QMap<AspectRatioPreset, double> &ratios); 92 107 /** Calculates image size suitable to passed @a hostSize and @a guestSize. */ 93 108 static QSize imageAspectRatioSize(const QSize &hostSize, const QSize &guestSize); … … 101 116 const int m_iMargin; 102 117 QRect m_vRect; 103 QPixmap *m_pbgEmptyImage; 104 QPixmap *m_pbgFullImage; 118 AspectRatioPreset m_preset; 119 QMap<AspectRatioPreset, QSize> m_sizes; 120 QMap<AspectRatioPreset, double> m_ratios; 121 QMap<AspectRatioPreset, QPixmap*> m_emptyPixmaps; 122 QMap<AspectRatioPreset, QPixmap*> m_fullPixmaps; 105 123 QImage *m_pPreviewImg; 106 124 QString m_strPreviewName;
Note:
See TracChangeset
for help on using the changeset viewer.