- Timestamp:
- Aug 14, 2012 4:06:44 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.cpp
r42795 r42812 217 217 218 218 /* Search for the maximum line widths: */ 219 int iMaximumFirstLineWidth = 0; 220 int iMaximumSecondLineWidth = 0; 219 int iMaximumLeftLineWidth = 0; 220 int iMaximumRightLineWidth = 0; 221 bool fSingleColumnText = true; 221 222 foreach (const UITextTableLine line, m_text) 222 223 { 223 bool fKeyValueRow = !line.second.isEmpty(); 224 QString strFirstLine = fKeyValueRow ? line.first + ":" : line.first; 225 QString strSecondLine = line.second; 226 iMaximumFirstLineWidth = qMax(iMaximumFirstLineWidth, fm.width(strFirstLine)); 227 iMaximumSecondLineWidth = qMax(iMaximumSecondLineWidth, fm.width(strSecondLine)); 224 bool fRightColumnPresent = !line.second.isEmpty(); 225 if (fRightColumnPresent) 226 fSingleColumnText = false; 227 QString strLeftLine = fRightColumnPresent ? line.first + ":" : line.first; 228 QString strRightLine = line.second; 229 iMaximumLeftLineWidth = qMax(iMaximumLeftLineWidth, fm.width(strLeftLine)); 230 iMaximumRightLineWidth = qMax(iMaximumRightLineWidth, fm.width(strRightLine)); 228 231 } 232 iMaximumLeftLineWidth += 1; 233 iMaximumRightLineWidth += 1; 229 234 230 235 /* Calculate minimum text width: */ 231 int iMinimumSecondLineWidth = qMin(iMaximumSecondLineWidth, iMinimumTextColumnWidth); 232 int iMinimumTextWidth = iMaximumFirstLineWidth + iSpacing + iMinimumSecondLineWidth; 236 int iMinimumTextWidth = 0; 237 if (fSingleColumnText) 238 { 239 /* Take into account only left column: */ 240 int iMinimumLeftColumnWidth = qMin(iMaximumLeftLineWidth, iMinimumTextColumnWidth); 241 iMinimumTextWidth = iMinimumLeftColumnWidth; 242 } 243 else 244 { 245 /* Take into account both columns, but wrap only right one: */ 246 int iMinimumLeftColumnWidth = iMaximumLeftLineWidth; 247 int iMinimumRightColumnWidth = qMin(iMaximumRightLineWidth, iMinimumTextColumnWidth); 248 iMinimumTextWidth = iMinimumLeftColumnWidth + iSpacing + iMinimumRightColumnWidth; 249 } 233 250 234 251 /* Return result: */ … … 240 257 int iMargin = data(ElementData_Margin).toInt(); 241 258 int iSpacing = data(ElementData_Spacing).toInt(); 259 int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt(); 242 260 int iMaximumTextWidth = (int)geometry().width() - 3 * iMargin - iSpacing; 243 261 QFont textFont = data(ElementData_TextFont).value<QFont>(); 244 262 QFontMetrics fm(textFont); 245 263 246 /* Search for maximum line widths: */ 247 int iMaximumFirstLineWidth = 0; 248 int iMaximumSecondLineWidth = 0; 264 /* Search for the maximum line widths: */ 265 int iMaximumLeftLineWidth = 0; 266 int iMaximumRightLineWidth = 0; 267 bool fSingleColumnText = true; 249 268 foreach (const UITextTableLine line, m_text) 250 269 { 251 bool fKeyValueRow = !line.second.isEmpty(); 252 QString strFirstLine = fKeyValueRow ? line.first + ":" : line.first; 270 bool fRightColumnPresent = !line.second.isEmpty(); 271 if (fRightColumnPresent) 272 fSingleColumnText = false; 273 QString strFirstLine = fRightColumnPresent ? line.first + ":" : line.first; 253 274 QString strSecondLine = line.second; 254 iMaximum FirstLineWidth = qMax(iMaximumFirstLineWidth, fm.width(strFirstLine));255 iMaximum SecondLineWidth = qMax(iMaximumSecondLineWidth, fm.width(strSecondLine));275 iMaximumLeftLineWidth = qMax(iMaximumLeftLineWidth, fm.width(strFirstLine)); 276 iMaximumRightLineWidth = qMax(iMaximumRightLineWidth, fm.width(strSecondLine)); 256 277 } 257 iMaximum FirstLineWidth += 1;258 iMaximum SecondLineWidth += 1;278 iMaximumLeftLineWidth += 1; 279 iMaximumRightLineWidth += 1; 259 280 260 281 /* Calculate column widths: */ 261 int iFirstColumnWidth = iMaximumFirstLineWidth; 262 int iSecondColumnWidth = iMaximumTextWidth - iFirstColumnWidth; 282 int iLeftColumnWidth = 0; 283 int iRightColumnWidth = 0; 284 if (fSingleColumnText) 285 { 286 /* Take into account only left column: */ 287 iLeftColumnWidth = qMax(iMinimumTextColumnWidth, iMaximumTextWidth); 288 } 289 else 290 { 291 /* Take into account both columns, but wrap only right one: */ 292 iLeftColumnWidth = iMaximumLeftLineWidth; 293 iRightColumnWidth = iMaximumTextWidth - iLeftColumnWidth; 294 } 263 295 264 296 /* For each the line: */ … … 267 299 { 268 300 /* First layout: */ 269 int i FirstColumnHeight = 0;301 int iLeftColumnHeight = 0; 270 302 if (!line.first.isEmpty()) 271 303 { 272 bool f KeyValueRow= !line.second.isEmpty();304 bool fRightColumnPresent = !line.second.isEmpty(); 273 305 QTextLayout *pTextLayout = prepareTextLayout(textFont, 274 f KeyValueRow? line.first + ":" : line.first,275 i FirstColumnWidth, iFirstColumnHeight);306 fRightColumnPresent ? line.first + ":" : line.first, 307 iLeftColumnWidth, iLeftColumnHeight); 276 308 delete pTextLayout; 277 309 } 278 310 279 311 /* Second layout: */ 280 int i SecondColumnHeight = 0;312 int iRightColumnHeight = 0; 281 313 if (!line.second.isEmpty()) 282 314 { 283 315 QTextLayout *pTextLayout = prepareTextLayout(textFont, line.second, 284 i SecondColumnWidth, iSecondColumnHeight);316 iRightColumnWidth, iRightColumnHeight); 285 317 delete pTextLayout; 286 318 } 287 319 288 320 /* Append summary text height: */ 289 iSummaryTextHeight += qMax(i FirstColumnHeight, iSecondColumnHeight);321 iSummaryTextHeight += qMax(iLeftColumnHeight, iRightColumnHeight); 290 322 } 291 323 … … 317 349 void UIGDetailsElement::setText(const UITextTable &text) 318 350 { 319 m_text = text; 351 /* Clear first: */ 352 m_text.clear(); 353 /* For each the line of the passed table: */ 354 foreach (const UITextTableLine &line, text) 355 { 356 /* Get lines: */ 357 QString strLeftLine = line.first; 358 QString strRightLine = line.second; 359 /* If 2nd line is empty: */ 360 if (strRightLine.isEmpty()) 361 { 362 /* Parse the 1st one: */ 363 QStringList subLines = strLeftLine.split(QRegExp("\\n")); 364 foreach (const QString &strSubLine, subLines) 365 m_text << UITextTableLine(strSubLine, QString()); 366 } 367 else 368 m_text << UITextTableLine(strLeftLine, strRightLine); 369 } 320 370 } 321 371 … … 557 607 { 558 608 /* Prepare variables: */ 609 int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt(); 559 610 int iMaximumTextWidth = geometry().width() - 3 * iMargin - iSpacing; 560 611 QFont textFont = data(ElementData_TextFont).value<QFont>(); 561 612 QFontMetrics fm(textFont); 562 613 563 /* Search for maximum line widths: */ 564 int iMaximumFirstLineWidth = 0; 565 int iMaximumSecondLineWidth = 0; 614 /* Search for the maximum line widths: */ 615 int iMaximumLeftLineWidth = 0; 616 int iMaximumRightLineWidth = 0; 617 bool fSingleColumnText = true; 566 618 foreach (const UITextTableLine line, m_text) 567 619 { 568 bool fKeyValueRow = !line.second.isEmpty(); 569 QString strFirstLine = fKeyValueRow ? line.first + ":" : line.first; 620 bool fRightColumnPresent = !line.second.isEmpty(); 621 if (fRightColumnPresent) 622 fSingleColumnText = false; 623 QString strFirstLine = fRightColumnPresent ? line.first + ":" : line.first; 570 624 QString strSecondLine = line.second; 571 iMaximum FirstLineWidth = qMax(iMaximumFirstLineWidth, fm.width(strFirstLine));572 iMaximum SecondLineWidth = qMax(iMaximumSecondLineWidth, fm.width(strSecondLine));573 } 574 iMaximum FirstLineWidth += 1;575 iMaximum SecondLineWidth += 1;625 iMaximumLeftLineWidth = qMax(iMaximumLeftLineWidth, fm.width(strFirstLine)); 626 iMaximumRightLineWidth = qMax(iMaximumRightLineWidth, fm.width(strSecondLine)); 627 } 628 iMaximumLeftLineWidth += 1; 629 iMaximumRightLineWidth += 1; 576 630 577 631 /* Calculate column widths: */ 578 int iFirstColumnWidth = iMaximumFirstLineWidth; 579 int iSecondColumnWidth = iMaximumTextWidth - iFirstColumnWidth; 632 int iLeftColumnWidth = 0; 633 int iRightColumnWidth = 0; 634 if (fSingleColumnText) 635 { 636 /* Take into account only left column: */ 637 iLeftColumnWidth = qMax(iMinimumTextColumnWidth, iMaximumTextWidth); 638 } 639 else 640 { 641 /* Take into account both columns, but wrap only right one: */ 642 iLeftColumnWidth = iMaximumLeftLineWidth; 643 iRightColumnWidth = iMaximumTextWidth - iLeftColumnWidth; 644 } 580 645 581 646 /* Where to paint? */ … … 587 652 { 588 653 /* First layout: */ 589 int i FirstColumnHeight = 0;654 int iLeftColumnHeight = 0; 590 655 if (!line.first.isEmpty()) 591 656 { 592 bool f KeyValueRow= !line.second.isEmpty();657 bool fRightColumnPresent = !line.second.isEmpty(); 593 658 QTextLayout *pTextLayout = prepareTextLayout(textFont, 594 f KeyValueRow? line.first + ":" : line.first,595 i FirstColumnWidth, iFirstColumnHeight);659 fRightColumnPresent ? line.first + ":" : line.first, 660 iLeftColumnWidth, iLeftColumnHeight); 596 661 pTextLayout->draw(pPainter, QPointF(iMachineTextX, iMachineTextY)); 597 662 delete pTextLayout; … … 599 664 600 665 /* Second layout: */ 601 int i SecondColumnHeight = 0;666 int iRightColumnHeight = 0; 602 667 if (!line.second.isEmpty()) 603 668 { 604 669 QTextLayout *pTextLayout = prepareTextLayout(textFont, line.second, 605 i SecondColumnWidth, iSecondColumnHeight);606 pTextLayout->draw(pPainter, QPointF(iMachineTextX + i FirstColumnWidth + iSpacing, iMachineTextY));670 iRightColumnWidth, iRightColumnHeight); 671 pTextLayout->draw(pPainter, QPointF(iMachineTextX + iLeftColumnWidth + iSpacing, iMachineTextY)); 607 672 delete pTextLayout; 608 673 } 609 674 610 675 /* Indent Y: */ 611 iMachineTextY += qMax(i FirstColumnHeight, iSecondColumnHeight);676 iMachineTextY += qMax(iLeftColumnHeight, iRightColumnHeight); 612 677 } 613 678 }
Note:
See TracChangeset
for help on using the changeset viewer.