Changeset 50847 in vbox
- Timestamp:
- Mar 21, 2014 9:40:21 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsTextPane.cpp
r50846 r50847 36 36 } 37 37 38 UIGraphicsTextPane::~UIGraphicsTextPane() 39 { 40 /* Clear text-layouts: */ 41 while (!m_leftList.isEmpty()) delete m_leftList.takeLast(); 42 while (!m_rightList.isEmpty()) delete m_rightList.takeLast(); 43 } 44 38 45 void UIGraphicsTextPane::setText(const UITextTable &text) 39 46 { … … 64 71 } 65 72 73 /* Update text-layout: */ 74 updateTextLayout(true); 75 66 76 /* Update minimum size-hint: */ 67 updateMinimumTextWidthHint();68 updateMinimumTextHeightHint();69 77 updateGeometry(); 70 78 } 71 79 72 void UIGraphicsTextPane::updateGeometry() 73 { 74 /* Discard cached minimum size-hint: */ 75 m_fMinimumSizeHintInvalidated = true; 76 77 /* Call to base-class to notify layout if any: */ 78 QIGraphicsWidget::updateGeometry(); 79 80 /* And notify listeners which are not layouts: */ 81 emit sigGeometryChanged(); 82 } 83 84 void UIGraphicsTextPane::updateMinimumTextWidthHint() 80 void UIGraphicsTextPane::updateTextLayout(bool fFull /* = false */) 85 81 { 86 82 /* Prepare variables: */ 87 83 QFontMetrics fm(font(), m_pPaintDevice); 88 89 /* Search for the maximum line widths: */ 90 int iMaximumLeftLineWidth = 0; 91 int iMaximumRightLineWidth = 0; 84 int iMaximumTextWidth = (int)size().width() - 2 * m_iMargin - m_iSpacing; 85 86 /* Search for the maximum column widths: */ 87 int iMaximumLeftColumnWidth = 0; 88 int iMaximumRightColumnWidth = 0; 92 89 bool fSingleColumnText = true; 93 90 foreach (const UITextTableLine &line, m_text) … … 98 95 QString strLeftLine = fRightColumnPresent ? line.first + ":" : line.first; 99 96 QString strRightLine = line.second; 100 iMaximumLeftLineWidth = qMax(iMaximumLeftLineWidth, fm.width(strLeftLine)); 101 iMaximumRightLineWidth = qMax(iMaximumRightLineWidth, fm.width(strRightLine)); 102 } 103 iMaximumLeftLineWidth += 1; 104 iMaximumRightLineWidth += 1; 105 106 /* Calculate minimum-text-width: */ 107 int iMinimumTextWidth = 0; 108 if (fSingleColumnText) 109 { 110 /* Take into account only left column: */ 111 int iMinimumLeftColumnWidth = qMin(iMaximumLeftLineWidth, m_iMinimumTextColumnWidth); 112 iMinimumTextWidth = iMinimumLeftColumnWidth; 113 } 114 else 115 { 116 /* Take into account both columns, but wrap only right one: */ 117 int iMinimumLeftColumnWidth = iMaximumLeftLineWidth; 118 int iMinimumRightColumnWidth = qMin(iMaximumRightLineWidth, m_iMinimumTextColumnWidth); 119 iMinimumTextWidth = iMinimumLeftColumnWidth + m_iSpacing + iMinimumRightColumnWidth; 120 } 121 122 /* Make sure something changed: */ 123 if (m_iMinimumTextWidth == iMinimumTextWidth) 124 return; 125 126 /* Remember new value: */ 127 m_iMinimumTextWidth = iMinimumTextWidth; 128 } 129 130 void UIGraphicsTextPane::updateMinimumTextHeightHint() 131 { 132 /* Prepare variables: */ 133 int iMaximumTextWidth = (int)size().width() - 2 * m_iMargin - m_iSpacing; 134 QFontMetrics fm(font(), m_pPaintDevice); 135 136 /* Search for the maximum line widths: */ 137 int iMaximumLeftLineWidth = 0; 138 int iMaximumRightLineWidth = 0; 139 bool fSingleColumnText = true; 140 foreach (const UITextTableLine &line, m_text) 141 { 142 bool fRightColumnPresent = !line.second.isEmpty(); 143 if (fRightColumnPresent) 144 fSingleColumnText = false; 145 QString strFirstLine = fRightColumnPresent ? line.first + ":" : line.first; 146 QString strSecondLine = line.second; 147 iMaximumLeftLineWidth = qMax(iMaximumLeftLineWidth, fm.width(strFirstLine)); 148 iMaximumRightLineWidth = qMax(iMaximumRightLineWidth, fm.width(strSecondLine)); 149 } 150 iMaximumLeftLineWidth += 1; 151 iMaximumRightLineWidth += 1; 152 153 /* Calculate column widths: */ 97 iMaximumLeftColumnWidth = qMax(iMaximumLeftColumnWidth, fm.width(strLeftLine)); 98 iMaximumRightColumnWidth = qMax(iMaximumRightColumnWidth, fm.width(strRightLine)); 99 } 100 iMaximumLeftColumnWidth += 1; 101 iMaximumRightColumnWidth += 1; 102 103 /* Calculate text attributes: */ 154 104 int iLeftColumnWidth = 0; 155 105 int iRightColumnWidth = 0; 106 /* Left column only: */ 156 107 if (fSingleColumnText) 157 108 { 158 /* Take into account only left column: */ 109 /* Full update? */ 110 if (fFull) 111 { 112 /* Minimum width for left column: */ 113 int iMinimumLeftColumnWidth = qMin(m_iMinimumTextColumnWidth, iMaximumLeftColumnWidth); 114 /* Minimum width for whole text: */ 115 m_iMinimumTextWidth = iMinimumLeftColumnWidth; 116 } 117 118 /* Current width for left column: */ 159 119 iLeftColumnWidth = qMax(m_iMinimumTextColumnWidth, iMaximumTextWidth); 160 120 } 121 /* Two columns: */ 161 122 else 162 123 { 163 /* Take into account both columns, but wrap only right one: */ 164 iLeftColumnWidth = iMaximumLeftLineWidth; 124 /* Full update? */ 125 if (fFull) 126 { 127 /* Minimum width for left column: */ 128 int iMinimumLeftColumnWidth = iMaximumLeftColumnWidth; 129 /* Minimum width for right column: */ 130 int iMinimumRightColumnWidth = qMin(m_iMinimumTextColumnWidth, iMaximumRightColumnWidth); 131 /* Minimum width for whole text: */ 132 m_iMinimumTextWidth = iMinimumLeftColumnWidth + m_iSpacing + iMinimumRightColumnWidth; 133 } 134 135 /* Current width for left column: */ 136 iLeftColumnWidth = iMaximumLeftColumnWidth; 137 /* Current width for right column: */ 165 138 iRightColumnWidth = iMaximumTextWidth - iLeftColumnWidth; 166 139 } 167 140 168 /* Calculate minimum-text-height: */ 169 int iMinimumTextHeight = 0; 170 foreach (const UITextTableLine line, m_text) 171 { 172 /* First layout: */ 141 /* Clear old text-layouts: */ 142 while (!m_leftList.isEmpty()) delete m_leftList.takeLast(); 143 while (!m_rightList.isEmpty()) delete m_rightList.takeLast(); 144 145 /* Prepare new text-layouts: */ 146 int iTextX = m_iMargin; 147 int iTextY = m_iMargin; 148 /* Populate text-layouts: */ 149 m_iMinimumTextHeight = 0; 150 foreach (const UITextTableLine &line, m_text) 151 { 152 /* Left layout: */ 173 153 int iLeftColumnHeight = 0; 174 154 if (!line.first.isEmpty()) 175 155 { 176 156 bool fRightColumnPresent = !line.second.isEmpty(); 177 QTextLayout *pTextLayout =buildTextLayout(font(), m_pPaintDevice,178 179 180 delete pTextLayout;181 } 182 183 /* Secondlayout: */157 m_leftList << buildTextLayout(font(), m_pPaintDevice, 158 fRightColumnPresent ? line.first + ":" : line.first, 159 iLeftColumnWidth, iLeftColumnHeight); 160 m_leftList.last()->setPosition(QPointF(iTextX, iTextY)); 161 } 162 163 /* Right layout: */ 184 164 int iRightColumnHeight = 0; 185 165 if (!line.second.isEmpty()) 186 166 { 187 QTextLayout *pTextLayout = buildTextLayout(font(), m_pPaintDevice, line.second, 188 iRightColumnWidth, iRightColumnHeight); 189 delete pTextLayout; 190 } 191 167 m_rightList << buildTextLayout(font(), m_pPaintDevice, 168 line.second, 169 iRightColumnWidth, iRightColumnHeight); 170 m_rightList.last()->setPosition(QPointF(iTextX + iLeftColumnWidth + m_iSpacing, iTextY)); 171 } 172 173 /* Maximum colum height? */ 174 int iMaximumColumnHeight = qMax(iLeftColumnHeight, iRightColumnHeight); 175 176 /* Indent Y: */ 177 iTextY += iMaximumColumnHeight; 192 178 /* Append summary text height: */ 193 iMinimumTextHeight += qMax(iLeftColumnHeight, iRightColumnHeight); 194 } 195 196 /* Make sure something changed: */ 197 if (m_iMinimumTextHeight == iMinimumTextHeight) 198 return; 199 200 /* Remember new value: */ 201 m_iMinimumTextHeight = iMinimumTextHeight; 179 m_iMinimumTextHeight += iMaximumColumnHeight; 180 } 181 } 182 183 void UIGraphicsTextPane::updateGeometry() 184 { 185 /* Discard cached minimum size-hint: */ 186 m_fMinimumSizeHintInvalidated = true; 187 188 /* Call to base-class to notify layout if any: */ 189 QIGraphicsWidget::updateGeometry(); 190 191 /* And notify listeners which are not layouts: */ 192 emit sigGeometryChanged(); 202 193 } 203 194 … … 224 215 void UIGraphicsTextPane::resizeEvent(QGraphicsSceneResizeEvent*) 225 216 { 226 /* Update minimum height-hint: */ 227 updateMinimumTextHeightHint(); 217 /* Update text-layout: */ 218 updateTextLayout(); 219 220 /* Update minimum size-hint: */ 228 221 updateGeometry(); 229 222 } … … 231 224 void UIGraphicsTextPane::paint(QPainter *pPainter, const QStyleOptionGraphicsItem*, QWidget*) 232 225 { 233 /* Prepare variables: */ 234 int iMaximumTextWidth = (int)size().width() - 2 * m_iMargin - m_iSpacing; 235 QFontMetrics fm(font(), m_pPaintDevice); 236 237 /* Where to paint? */ 238 int iTextX = m_iMargin; 239 int iTextY = m_iMargin; 240 241 /* Search for the maximum line widths: */ 242 int iMaximumLeftLineWidth = 0; 243 int iMaximumRightLineWidth = 0; 244 bool fSingleColumnText = true; 245 foreach (const UITextTableLine line, m_text) 246 { 247 bool fRightColumnPresent = !line.second.isEmpty(); 248 if (fRightColumnPresent) 249 fSingleColumnText = false; 250 QString strFirstLine = fRightColumnPresent ? line.first + ":" : line.first; 251 QString strSecondLine = line.second; 252 iMaximumLeftLineWidth = qMax(iMaximumLeftLineWidth, fm.width(strFirstLine)); 253 iMaximumRightLineWidth = qMax(iMaximumRightLineWidth, fm.width(strSecondLine)); 254 } 255 iMaximumLeftLineWidth += 1; 256 iMaximumRightLineWidth += 1; 257 258 /* Calculate column widths: */ 259 int iLeftColumnWidth = 0; 260 int iRightColumnWidth = 0; 261 if (fSingleColumnText) 262 { 263 /* Take into account only left column: */ 264 iLeftColumnWidth = qMax(m_iMinimumTextColumnWidth, iMaximumTextWidth); 265 } 266 else 267 { 268 /* Take into account both columns, but wrap only right one: */ 269 iLeftColumnWidth = iMaximumLeftLineWidth; 270 iRightColumnWidth = iMaximumTextWidth - iLeftColumnWidth; 271 } 272 273 /* For each the line: */ 274 foreach (const UITextTableLine line, m_text) 275 { 276 /* First layout: */ 277 int iLeftColumnHeight = 0; 278 if (!line.first.isEmpty()) 279 { 280 bool fRightColumnPresent = !line.second.isEmpty(); 281 QTextLayout *pTextLayout = buildTextLayout(font(), m_pPaintDevice, 282 fRightColumnPresent ? line.first + ":" : line.first, 283 iLeftColumnWidth, iLeftColumnHeight); 284 pTextLayout->draw(pPainter, QPointF(iTextX, iTextY)); 285 delete pTextLayout; 286 } 287 288 /* Second layout: */ 289 int iRightColumnHeight = 0; 290 if (!line.second.isEmpty()) 291 { 292 QTextLayout *pTextLayout = buildTextLayout(font(), m_pPaintDevice, 293 line.second, iRightColumnWidth, iRightColumnHeight); 294 pTextLayout->draw(pPainter, QPointF(iTextX + iLeftColumnWidth + m_iSpacing, iTextY)); 295 delete pTextLayout; 296 } 297 298 /* Indent Y: */ 299 iTextY += qMax(iLeftColumnHeight, iRightColumnHeight); 300 } 226 /* Draw all the text-layouts: */ 227 foreach (QTextLayout *pTextLayout, m_leftList) 228 pTextLayout->draw(pPainter, QPoint(0, 0)); 229 foreach (QTextLayout *pTextLayout, m_rightList) 230 pTextLayout->draw(pPainter, QPoint(0, 0)); 301 231 } 302 232 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsTextPane.h
r50846 r50847 43 43 /** Graphics text-pane constructor. */ 44 44 UIGraphicsTextPane(QIGraphicsWidget *pParent, QPaintDevice *pPaintDevice); 45 /** Graphics text-pane destructor. */ 46 ~UIGraphicsTextPane(); 45 47 46 48 /** Returns whether contained text is empty. */ … … 53 55 private: 54 56 57 /** Update text-layout. */ 58 void updateTextLayout(bool fFull = false); 59 55 60 /** Notifies listeners about size-hint changes. */ 56 61 void updateGeometry(); 57 /** Updates minimum text width hint. */58 void updateMinimumTextWidthHint();59 /** Updates minimum text height hint. */60 void updateMinimumTextHeightHint();61 62 /** Returns the size-hint to constrain the content. */ 62 63 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; … … 93 94 /** Contained text. */ 94 95 UITextTable m_text; 96 /** Left text-layout list. */ 97 QList<QTextLayout*> m_leftList; 98 /** Right text-layout list. */ 99 QList<QTextLayout*> m_rightList; 95 100 }; 96 101
Note:
See TracChangeset
for help on using the changeset viewer.