Changeset 42909 in vbox for trunk/src/VBox
- Timestamp:
- Aug 21, 2012 3:46:56 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp
r42873 r42909 337 337 338 338 /* static */ 339 int UIGChooserItem::textWidth(const QFont &font, int iCount)339 int UIGChooserItem::textWidth(const QFont &font, QPaintDevice *pPaintDevice, int iCount) 340 340 { 341 341 /* Return text width: */ 342 QFontMetrics fm(font );342 QFontMetrics fm(font, pPaintDevice); 343 343 QString strString; 344 344 strString.fill('_', iCount); … … 347 347 348 348 /* static */ 349 QString UIGChooserItem::compressText(const QFont &font, Q String strText, int iWidth)349 QString UIGChooserItem::compressText(const QFont &font, QPaintDevice *pPaintDevice, QString strText, int iWidth) 350 350 { 351 351 /* Check if passed text is empty: */ … … 354 354 355 355 /* Check if passed text feats maximum width: */ 356 QFontMetrics fm(font );356 QFontMetrics fm(font, pPaintDevice); 357 357 if (fm.width(strText) <= iWidth) 358 358 return strText; -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.h
r42872 r42909 151 151 152 152 /* Helpers: Text compression stuff: */ 153 static int textWidth(const QFont &font, int iCount);154 static QString compressText(const QFont &font, Q String strText, int iWidth);153 static int textWidth(const QFont &font, QPaintDevice *pPaintDevice, int iCount); 154 static QString compressText(const QFont &font, QPaintDevice *pPaintDevice, QString strText, int iWidth); 155 155 156 156 private: -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp
r42879 r42909 350 350 if (isHovered() && !strMachineCountText.isEmpty()) 351 351 iMaximumWidth -= (iMachinePixmapWidth + iMachineCountTextWidth); 352 return compressText(data(GroupItemData_NameFont).value<QFont>(), m_strName, iMaximumWidth); 352 return compressText(data(GroupItemData_NameFont).value<QFont>(), 353 model()->paintDevice(), 354 m_strName, iMaximumWidth); 353 355 } 354 356 case GroupItemData_GroupCountText: return m_groupItems.isEmpty() ? QString() : QString::number(m_groupItems.size()); … … 363 365 return QSizeF(0, 0); 364 366 QFont font = data(GroupItemData_NameFont).value<QFont>(); 365 QFontMetrics fm(font); 366 int iMaximumTextWidth = textWidth(font, 20); 367 QString strCompressedName = compressText(font, m_strName, iMaximumTextWidth); 367 QPaintDevice *pPaintDevice = model()->paintDevice(); 368 QFontMetrics fm(font, pPaintDevice); 369 int iMaximumTextWidth = textWidth(font, pPaintDevice, 20); 370 QString strCompressedName = compressText(font, pPaintDevice, 371 m_strName, iMaximumTextWidth); 368 372 return QSize(fm.width(strCompressedName), fm.height()); 369 373 } … … 372 376 if (isMainRoot()) 373 377 return QSizeF(0, 0); 374 QFontMetrics fm(data(GroupItemData_NameFont).value<QFont>() );378 QFontMetrics fm(data(GroupItemData_NameFont).value<QFont>(), model()->paintDevice()); 375 379 return QSize(fm.width(data(GroupItemData_Name).toString()) + 2, fm.height()); 376 380 } … … 389 393 if (isMainRoot()) 390 394 return QSizeF(0, 0); 391 QFontMetrics fm(data(GroupItemData_InfoFont).value<QFont>() );395 QFontMetrics fm(data(GroupItemData_InfoFont).value<QFont>(), model()->paintDevice()); 392 396 return QSize(fm.width(data(GroupItemData_GroupCountText).toString()), fm.height()); 393 397 } … … 396 400 if (isMainRoot()) 397 401 return QSizeF(0, 0); 398 QFontMetrics fm(data(GroupItemData_InfoFont).value<QFont>() );402 QFontMetrics fm(data(GroupItemData_InfoFont).value<QFont>(), model()->paintDevice()); 399 403 return QSize(fm.width(data(GroupItemData_MachineCountText).toString()), fm.height()); 400 404 } -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.cpp
r42872 r42909 150 150 case MachineItemData_Name: 151 151 { 152 return compressText(data(MachineItemData_NameFont).value<QFont>(), name(),153 data(MachineItemData_MaximumNameWidth).toInt());152 return compressText(data(MachineItemData_NameFont).value<QFont>(), model()->paintDevice(), 153 name(), data(MachineItemData_MaximumNameWidth).toInt()); 154 154 } 155 155 case MachineItemData_SnapshotName: 156 156 { 157 int iBracketWidth = QFontMetrics(data(MachineItemData_SnapshotNameFont).value<QFont>()).width("()"); 158 QString strCompressedName = compressText(data(MachineItemData_SnapshotNameFont).value<QFont>(), snapshotName(), 157 QPaintDevice *pPaintDevice = model()->paintDevice(); 158 int iBracketWidth = QFontMetrics(data(MachineItemData_SnapshotNameFont).value<QFont>(), 159 pPaintDevice).width("()"); 160 QString strCompressedName = compressText(data(MachineItemData_SnapshotNameFont).value<QFont>(), 161 pPaintDevice, snapshotName(), 159 162 data(MachineItemData_MaximumSnapshotNameWidth).toInt() - iBracketWidth); 160 163 return QString("(%1)").arg(strCompressedName); … … 168 171 case MachineItemData_NameSize: 169 172 { 170 QFontMetrics fm(data(MachineItemData_NameFont).value<QFont>() );173 QFontMetrics fm(data(MachineItemData_NameFont).value<QFont>(), model()->paintDevice()); 171 174 return QSize(fm.width(data(MachineItemData_Name).toString()) + 2, fm.height()); 172 175 } … … 174 177 { 175 178 QFont font = data(MachineItemData_NameFont).value<QFont>(); 176 return QFontMetrics(font).width(compressText(font, name(), textWidth(font, 15))); 179 QPaintDevice *pPaintDevice = model()->paintDevice(); 180 return QFontMetrics(font, pPaintDevice).width(compressText(font, pPaintDevice, 181 name(), textWidth(font, pPaintDevice, 15))); 177 182 } 178 183 case MachineItemData_MaximumNameWidth: … … 184 189 case MachineItemData_SnapshotNameSize: 185 190 { 186 QFontMetrics fm(data(MachineItemData_SnapshotNameFont).value<QFont>() );191 QFontMetrics fm(data(MachineItemData_SnapshotNameFont).value<QFont>(), model()->paintDevice()); 187 192 return QSize(fm.width(data(MachineItemData_SnapshotName).toString()) + 2, fm.height()); 188 193 } … … 191 196 if (snapshotName().isEmpty()) 192 197 return 0; 193 QFontMetrics fm(data(MachineItemData_SnapshotNameFont).value<QFont>() );198 QFontMetrics fm(data(MachineItemData_SnapshotNameFont).value<QFont>(), model()->paintDevice()); 194 199 int iBracketWidth = fm.width("()"); 195 200 int iActualTextWidth = fm.width(snapshotName()); … … 222 227 case MachineItemData_StateTextSize: 223 228 { 224 QFontMetrics fm(data(MachineItemData_StateTextFont).value<QFont>() );229 QFontMetrics fm(data(MachineItemData_StateTextFont).value<QFont>(), model()->paintDevice()); 225 230 return QSize(fm.width(data(MachineItemData_StateText).toString()) + 2, fm.height()); 226 231 } -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp
r42879 r42909 138 138 { 139 139 return m_pScene; 140 } 141 142 QPaintDevice* UIGChooserModel::paintDevice() const 143 { 144 if (!m_pScene || m_pScene->views().isEmpty()) 145 return 0; 146 return m_pScene->views().first(); 140 147 } 141 148 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h
r42851 r42909 45 45 class UIGChooserHandlerKeyboard; 46 46 class QTimer; 47 class QPaintDevice; 47 48 48 49 /* Context-menu type: */ … … 97 98 /* API: Scene getter: */ 98 99 QGraphicsScene* scene() const; 100 101 /* API: Paint-device getter: */ 102 QPaintDevice* paintDevice() const; 99 103 100 104 /* API: Root stuff: */ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.cpp
r42906 r42909 192 192 case ElementData_NameSize: 193 193 { 194 QFontMetrics fm(data(ElementData_NameFont).value<QFont>() );194 QFontMetrics fm(data(ElementData_NameFont).value<QFont>(), model()->paintDevice()); 195 195 return QSize(fm.width(m_strName), fm.height()); 196 196 } … … 218 218 int iSpacing = data(ElementData_Spacing).toInt(); 219 219 int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt(); 220 QFontMetrics fm(data(ElementData_TextFont).value<QFont>() );220 QFontMetrics fm(data(ElementData_TextFont).value<QFont>(), model()->paintDevice()); 221 221 222 222 /* Search for the maximum line widths: */ … … 264 264 int iMaximumTextWidth = (int)geometry().width() - 3 * iMargin - iSpacing; 265 265 QFont textFont = data(ElementData_TextFont).value<QFont>(); 266 QFontMetrics fm(textFont); 266 QPaintDevice *pPaintDevice = model()->paintDevice(); 267 QFontMetrics fm(textFont, pPaintDevice); 267 268 268 269 /* Search for the maximum line widths: */ … … 307 308 { 308 309 bool fRightColumnPresent = !line.second.isEmpty(); 309 QTextLayout *pTextLayout = prepareTextLayout(textFont, 310 QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice, 310 311 fRightColumnPresent ? line.first + ":" : line.first, 311 312 iLeftColumnWidth, iLeftColumnHeight); … … 317 318 if (!line.second.isEmpty()) 318 319 { 319 QTextLayout *pTextLayout = prepareTextLayout(textFont, line.second,320 QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice, line.second, 320 321 iRightColumnWidth, iRightColumnHeight); 321 322 delete pTextLayout; … … 605 606 int iMaximumTextWidth = geometry().width() - 3 * iMargin - iSpacing; 606 607 QFont textFont = data(ElementData_TextFont).value<QFont>(); 607 QFontMetrics fm(textFont); 608 QPaintDevice *pPaintDevice = model()->paintDevice(); 609 QFontMetrics fm(textFont, pPaintDevice); 608 610 609 611 /* Search for the maximum line widths: */ … … 641 643 /* Where to paint? */ 642 644 int iMachineTextX = iMachinePixmapX; 643 int iMachineTextY = iMa chinePixmapY+ iHeaderHeight + 2 * iMargin;645 int iMachineTextY = iMargin + iHeaderHeight + 2 * iMargin; 644 646 645 647 /* For each the line: */ … … 651 653 { 652 654 bool fRightColumnPresent = !line.second.isEmpty(); 653 QTextLayout *pTextLayout = prepareTextLayout(textFont, 655 QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice, 654 656 fRightColumnPresent ? line.first + ":" : line.first, 655 657 iLeftColumnWidth, iLeftColumnHeight); … … 662 664 if (!line.second.isEmpty()) 663 665 { 664 QTextLayout *pTextLayout = prepareTextLayout(textFont, line.second,665 iRightColumnWidth, iRightColumnHeight);666 QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice, 667 line.second, iRightColumnWidth, iRightColumnHeight); 666 668 pTextLayout->draw(pPainter, QPointF(iMachineTextX + iLeftColumnWidth + iSpacing, iMachineTextY)); 667 669 delete pTextLayout; … … 817 819 818 820 /* static */ 819 QTextLayout* UIGDetailsElement::prepareTextLayout(const QFont &font, const QString &strText, int iWidth, int &iHeight) 821 QTextLayout* UIGDetailsElement::prepareTextLayout(const QFont &font, QPaintDevice *pPaintDevice, 822 const QString &strText, int iWidth, int &iHeight) 820 823 { 821 824 /* Prepare variables: */ 822 QFontMetrics fm(font );825 QFontMetrics fm(font, pPaintDevice); 823 826 int iLeading = fm.leading(); 824 827 825 828 /* Create layout; */ 826 QTextLayout *pTextLayout = new QTextLayout(strText, font );829 QTextLayout *pTextLayout = new QTextLayout(strText, font, pPaintDevice); 827 830 828 831 /* Configure layout: */ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h
r42906 r42909 186 186 187 187 /* Helper: Layout stuff: */ 188 static QTextLayout* prepareTextLayout(const QFont &font, const QString &strText, int iWidth, int &iHeight); 188 static QTextLayout* prepareTextLayout(const QFont &font, QPaintDevice *pPaintDevice, 189 const QString &strText, int iWidth, int &iHeight); 189 190 190 191 /* Helper: Animation stuff: */ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsModel.cpp
r42906 r42909 64 64 { 65 65 return m_pScene; 66 } 67 68 QPaintDevice* UIGDetailsModel::paintDevice() const 69 { 70 if (!m_pScene || m_pScene->views().isEmpty()) 71 return 0; 72 return m_pScene->views().first(); 66 73 } 67 74 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsModel.h
r42856 r42909 63 63 /* API: Scene getter: */ 64 64 QGraphicsScene* scene() const; 65 66 /* API: Paint-device getter: */ 67 QPaintDevice* paintDevice() const; 65 68 66 69 /* API: Item positioning stuff: */
Note:
See TracChangeset
for help on using the changeset viewer.