Changeset 14454
- Timestamp:
- Jan 17, 2015, 4:59:42 PM (7 years ago)
- Location:
- trunk/qt
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/filterbar.cc
r14445 r14454 54 54 return fadedColor; 55 55 } 56 57 void58 narrowRect (QRect& rect, int dx1, int dx2, Qt::LayoutDirection direction)59 {60 if (direction == Qt::LeftToRight)61 rect.adjust (dx1, 0, -dx2, 0);62 else63 rect.adjust (dx2, 0, -dx1, 0);64 }65 56 } 66 57 … … 118 109 Qt::AlignLeft|Qt::AlignVCenter, 119 110 decorationRect.size (), boundingBox); 120 narrowRect (boundingBox, decorationRect.width () + hmargin, 0, option.direction);111 Utils::narrowRect (boundingBox, decorationRect.width () + hmargin, 0, option.direction); 121 112 122 113 QRect countRect = rect (option, index, TorrentCountStringRole); … … 124 115 Qt::AlignRight|Qt::AlignVCenter, 125 116 countRect.size (), boundingBox); 126 narrowRect (boundingBox, 0, countRect.width () + hmargin, option.direction);117 Utils::narrowRect (boundingBox, 0, countRect.width () + hmargin, option.direction); 127 118 const QRect displayRect = boundingBox; 128 119 … … 264 255 opt.iconSize, rect); 265 256 painter.drawPixmap (iconRect.topLeft (), pixmap); 266 narrowRect (rect, iconRect.width () + hmargin, 0, opt.direction);257 Utils::narrowRect (rect, iconRect.width () + hmargin, 0, opt.direction); 267 258 } 268 259 … … 276 267 QSize (opt.fontMetrics.width (text), rect.height ()), rect); 277 268 painter.drawText (textRect, Qt::AlignRight | Qt::AlignVCenter, text); 278 narrowRect (rect, 0, textRect.width () + hmargin, opt.direction);269 Utils::narrowRect (rect, 0, textRect.width () + hmargin, opt.direction); 279 270 painter.setPen (pen); 280 271 } -
trunk/qt/torrent-delegate-min.cc
r14453 r14454 27 27 #include "torrent-delegate-min.h" 28 28 #include "torrent-model.h" 29 #include "utils.h" 29 30 30 31 enum … … 44 45 ***/ 45 46 47 namespace 48 { 49 class ItemLayout 50 { 51 private: 52 QString myNameText; 53 QString myStatusText; 54 55 public: 56 QFont nameFont; 57 QFont statusFont; 58 59 QRect iconRect; 60 QRect emblemRect; 61 QRect nameRect; 62 QRect statusRect; 63 QRect barRect; 64 65 public: 66 ItemLayout(const QString& nameText, const QString& statusText, const QIcon& emblemIcon, 67 const QFont& baseFont, Qt::LayoutDirection direction, const QPoint& topLeft, int width); 68 69 QSize size () const 70 { 71 return (iconRect | nameRect | statusRect | barRect).size (); 72 } 73 74 QString nameText () const { return elidedText (nameFont, myNameText, nameRect.width ()); } 75 QString statusText () const { return myStatusText; } 76 77 private: 78 QString elidedText (const QFont& font, const QString& text, int width) const 79 { 80 return QFontMetrics (font).elidedText (text, Qt::ElideRight, width); 81 } 82 }; 83 84 ItemLayout::ItemLayout(const QString& nameText, const QString& statusText, const QIcon& emblemIcon, 85 const QFont& baseFont, Qt::LayoutDirection direction, const QPoint& topLeft, int width): 86 myNameText (nameText), 87 myStatusText (statusText), 88 nameFont (baseFont), 89 statusFont (baseFont) 90 { 91 const QStyle * style (qApp->style ()); 92 const int iconSize (style->pixelMetric (QStyle::PM_SmallIconSize)); 93 94 const QFontMetrics nameFM (nameFont); 95 const QSize nameSize (nameFM.size (0, myNameText)); 96 97 statusFont.setPointSize (static_cast<int> (statusFont.pointSize () * 0.85)); 98 const QFontMetrics statusFM (statusFont); 99 const QSize statusSize (statusFM.size (0, myStatusText)); 100 101 QRect baseRect (topLeft, QSize (width, qMax (iconSize, qMax (nameSize.height (), qMax (statusSize.height (), static_cast<int>(BAR_HEIGHT)))))); 102 103 iconRect = style->alignedRect (direction, Qt::AlignLeft | Qt::AlignVCenter, QSize (iconSize, iconSize), baseRect); 104 emblemRect = style->alignedRect (direction, Qt::AlignRight | Qt::AlignBottom, 105 emblemIcon.actualSize (iconRect.size () / 2, QIcon::Normal, QIcon::On), 106 iconRect); 107 barRect = style->alignedRect (direction, Qt::AlignRight | Qt::AlignVCenter, QSize (BAR_WIDTH, BAR_HEIGHT), baseRect); 108 Utils::narrowRect (baseRect, iconRect.width () + GUI_PAD, barRect.width () + GUI_PAD, direction); 109 statusRect = style->alignedRect (direction, Qt::AlignRight | Qt::AlignVCenter, QSize (statusSize.width (), baseRect.height ()), baseRect); 110 Utils::narrowRect (baseRect, 0, statusRect.width () + GUI_PAD, direction); 111 nameRect = baseRect; 112 } 113 } 114 46 115 QSize 47 116 TorrentDelegateMin::sizeHint (const QStyleOptionViewItem & option, 48 117 const Torrent & tor) const 49 118 { 50 const QStyle* style (qApp->style());51 static const int iconSize (style->pixelMetric (QStyle::PM_SmallIconSize));52 53 QFont nameFont (option.font);54 const QFontMetrics nameFM (nameFont);55 119 const bool isMagnet (!tor.hasMetadata()); 56 const QString nameStr = (isMagnet ? progressString (tor) : tor.name()); 57 const int nameWidth = nameFM.width (nameStr); 58 59 QFont statusFont (option.font); 60 statusFont.setPointSize (static_cast<int> (option.font.pointSize() * 0.85)); 61 const QFontMetrics statusFM (statusFont); 62 const QString statusStr (shortStatusString (tor)); 63 const int statusWidth = statusFM.width (statusStr); 64 65 const QSize m (margin (*style)); 66 67 return QSize (m.width()*2 + iconSize + GUI_PAD + nameWidth 68 + GUI_PAD + statusWidth 69 + GUI_PAD + BAR_WIDTH, 70 m.height()*2 + std::max (nameFM.height(), (int)BAR_HEIGHT)); 120 const QSize m (margin (*qApp->style())); 121 const ItemLayout layout (isMagnet ? progressString (tor) : tor.name(), shortStatusString (tor), QIcon (), 122 option.font, option.direction, QPoint (0, 0), option.rect.width () - m.width () * 2); 123 return layout.size () + m * 2; 71 124 } 72 125 … … 76 129 const Torrent & tor) const 77 130 { 131 const QStyle * style (qApp->style()); 132 78 133 const bool isPaused (tor.isPaused()); 79 const QStyle * style (qApp->style());80 static const int iconSize (style->pixelMetric (QStyle::PM_SmallIconSize));81 82 QFont nameFont (option.font);83 const QFontMetrics nameFM (nameFont);84 134 const bool isMagnet (!tor.hasMetadata()); 85 const QString nameStr = (isMagnet ? progressString (tor) : tor.name());86 87 QFont statusFont (option.font);88 statusFont.setPointSize (static_cast<int> (option.font.pointSize() * 0.85));89 const QFontMetrics statusFM (statusFont);90 const QString statusStr (shortStatusString (tor));91 const QSize statusSize (statusFM.size (0, statusStr));92 135 93 136 const bool isItemSelected ((option.state & QStyle::State_Selected) != 0); … … 142 185 // layout 143 186 const QSize m (margin (*style)); 144 QRect fillArea (option.rect); 145 fillArea.adjust (m.width(), m.height(), -m.width(), -m.height()); 146 const QRect iconArea (fillArea.x(), 147 fillArea.y() + (fillArea.height() - iconSize) / 2, 148 iconSize, 149 iconSize); 150 const QRect emblemRect (style->alignedRect (option.direction, Qt::AlignRight | Qt::AlignBottom, 151 emblemIcon.actualSize (QSize (iconSize / 2, iconSize / 2), emblemIm, qs), 152 iconArea)); 153 const QRect barArea (fillArea.x() + fillArea.width() - BAR_WIDTH, 154 fillArea.y() + (fillArea.height() - BAR_HEIGHT) / 2, 155 BAR_WIDTH, 156 BAR_HEIGHT); 157 const QRect statusArea (barArea.x() - GUI_PAD - statusSize.width(), 158 fillArea.y() + (fillArea.height() - statusSize.height()) / 2, 159 fillArea.width(), 160 fillArea.height()); 161 const QRect nameArea (iconArea.x() + iconArea.width() + GUI_PAD, 162 fillArea.y(), 163 statusArea.x() - (iconArea.x() + iconArea.width() + GUI_PAD * 2), 164 fillArea.height()); 187 const QRect contentRect (option.rect.adjusted (m.width(), m.height(), -m.width(), -m.height())); 188 const ItemLayout layout (isMagnet ? progressString (tor) : tor.name(), shortStatusString (tor), emblemIcon, 189 option.font, option.direction, contentRect.topLeft (), contentRect.width ()); 165 190 166 191 // render … … 169 194 else 170 195 painter->setPen (option.palette.color (cg, cr)); 171 tor.getMimeTypeIcon().paint (painter, iconArea, Qt::AlignCenter, im, qs);196 tor.getMimeTypeIcon().paint (painter, layout.iconRect, Qt::AlignCenter, im, qs); 172 197 if (!emblemIcon.isNull ()) 173 emblemIcon.paint (painter, emblemRect, Qt::AlignCenter, emblemIm, qs);174 painter->setFont ( nameFont);175 painter->drawText ( nameArea, 0, nameFM.elidedText (nameStr, Qt::ElideRight, nameArea.width()));176 painter->setFont ( statusFont);177 painter->drawText ( statusArea, 0, statusStr);178 myProgressBarStyle->rect = barArea;198 emblemIcon.paint (painter, layout.emblemRect, Qt::AlignCenter, emblemIm, qs); 199 painter->setFont (layout.nameFont); 200 painter->drawText (layout.nameRect, Qt::AlignLeft | Qt::AlignVCenter, layout.nameText ()); 201 painter->setFont (layout.statusFont); 202 painter->drawText (layout.statusRect, Qt::AlignLeft | Qt::AlignVCenter, layout.statusText ()); 203 myProgressBarStyle->rect = layout.barRect; 179 204 if (tor.isDownloading()) 180 205 { -
trunk/qt/torrent-delegate.cc
r14453 r14454 25 25 #include "torrent-delegate.h" 26 26 #include "torrent-model.h" 27 #include "utils.h" 27 28 28 29 enum … … 38 39 QColor TorrentDelegate::blueBack; 39 40 QColor TorrentDelegate::silverBack; 41 42 namespace 43 { 44 class ItemLayout 45 { 46 private: 47 QString myNameText; 48 QString myStatusText; 49 QString myProgressText; 50 51 public: 52 QFont nameFont; 53 QFont statusFont; 54 QFont progressFont; 55 56 QRect iconRect; 57 QRect emblemRect; 58 QRect nameRect; 59 QRect statusRect; 60 QRect barRect; 61 QRect progressRect; 62 63 public: 64 ItemLayout(const QString& nameText, const QString& statusText, const QString& progressText, 65 const QIcon& emblemIcon, const QFont& baseFont, Qt::LayoutDirection direction, 66 const QPoint& topLeft, int width); 67 68 QSize size () const 69 { 70 return (iconRect | nameRect | statusRect | barRect | progressRect).size (); 71 } 72 73 QString nameText () const { return elidedText (nameFont, myNameText, nameRect.width ()); } 74 QString statusText () const { return elidedText (statusFont, myStatusText, statusRect.width ()); } 75 QString progressText () const { return elidedText (progressFont, myProgressText, progressRect.width ()); } 76 77 private: 78 QString elidedText (const QFont& font, const QString& text, int width) const 79 { 80 return QFontMetrics (font).elidedText (text, Qt::ElideRight, width); 81 } 82 }; 83 84 ItemLayout::ItemLayout(const QString& nameText, const QString& statusText, const QString& progressText, 85 const QIcon& emblemIcon, const QFont& baseFont, Qt::LayoutDirection direction, 86 const QPoint& topLeft, int width): 87 myNameText (nameText), 88 myStatusText (statusText), 89 myProgressText (progressText), 90 nameFont (baseFont), 91 statusFont (baseFont), 92 progressFont (baseFont) 93 { 94 const QStyle * style (qApp->style ()); 95 const int iconSize (style->pixelMetric (QStyle::PM_LargeIconSize)); 96 97 nameFont.setWeight (QFont::Bold); 98 const QFontMetrics nameFM (nameFont); 99 const QSize nameSize (nameFM.size (0, myNameText)); 100 101 statusFont.setPointSize (static_cast<int> (statusFont.pointSize () * 0.9)); 102 const QFontMetrics statusFM (statusFont); 103 const QSize statusSize (statusFM.size (0, myStatusText)); 104 105 progressFont.setPointSize (static_cast<int> (progressFont.pointSize () * 0.9)); 106 const QFontMetrics progressFM (progressFont); 107 const QSize progressSize (progressFM.size (0, myProgressText)); 108 109 QRect baseRect (topLeft, QSize (width, 0)); 110 Utils::narrowRect (baseRect, iconSize + GUI_PAD, 0, direction); 111 112 nameRect = baseRect.adjusted(0, 0, 0, nameSize.height ()); 113 statusRect = nameRect.adjusted(0, nameRect.height () + 1, 0, statusSize.height () + 1); 114 barRect = statusRect.adjusted(0, statusRect.height () + 1, 0, BAR_HEIGHT + 1); 115 progressRect = barRect.adjusted (0, barRect.height () + 1, 0, progressSize.height () + 1); 116 iconRect = style->alignedRect (direction, Qt::AlignLeft | Qt::AlignVCenter, 117 QSize (iconSize, iconSize), 118 QRect (topLeft, QSize (width, progressRect.bottom () - nameRect.top ()))); 119 emblemRect = style->alignedRect (direction, Qt::AlignRight | Qt::AlignBottom, 120 emblemIcon.actualSize (iconRect.size () / 2, QIcon::Normal, QIcon::On), 121 iconRect); 122 } 123 } 40 124 41 125 TorrentDelegate::TorrentDelegate (QObject * parent): … … 169 253 } 170 254 171 return str ;255 return str.trimmed (); 172 256 } 173 257 … … 188 272 str = Formatter::uploadSpeedToString(tor.uploadSpeed()); 189 273 190 return str ;274 return str.trimmed (); 191 275 } 192 276 … … 216 300 } 217 301 218 return str ;302 return str.trimmed (); 219 303 } 220 304 … … 272 356 } 273 357 274 return str ;358 return str.trimmed (); 275 359 } 276 360 … … 279 363 ***/ 280 364 281 namespace282 {283 int MAX3 (int a, int b, int c)284 {285 const int ab (a > b ? a : b);286 return ab > c ? ab : c;287 }288 }289 290 365 QSize 291 366 TorrentDelegate::sizeHint (const QStyleOptionViewItem& option, const Torrent& tor) const 292 367 { 293 const QStyle* style (qApp->style ()); 294 static const int iconSize (style->pixelMetric (QStyle::PM_MessageBoxIconSize)); 295 296 QFont nameFont (option.font); 297 nameFont.setWeight (QFont::Bold); 298 const QFontMetrics nameFM (nameFont); 299 const QString nameStr (tor.name ()); 300 const int nameWidth = nameFM.width (nameStr); 301 QFont statusFont (option.font); 302 statusFont.setPointSize (static_cast<int> (option.font.pointSize () * 0.9)); 303 const QFontMetrics statusFM (statusFont); 304 const QString statusStr (statusString (tor)); 305 const int statusWidth = statusFM.width (statusStr); 306 QFont progressFont (statusFont); 307 const QFontMetrics progressFM (progressFont); 308 const QString progressStr (progressString (tor)); 309 const int progressWidth = progressFM.width (progressStr); 310 const QSize m (margin (*style)); 311 return QSize (m.width()*2 + iconSize + GUI_PAD + MAX3 (nameWidth, statusWidth, progressWidth), 312 //m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing()*2 + progressFM.lineSpacing()); 313 m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing() + BAR_HEIGHT + progressFM.lineSpacing()); 368 const QSize m (margin (*qApp->style ())); 369 const ItemLayout layout (tor.name (), progressString (tor), statusString (tor), QIcon (), 370 option.font, option.direction, QPoint (0, 0), option.rect.width () - m.width () * 2); 371 return layout.size () + m * 2; 314 372 } 315 373 … … 359 417 { 360 418 const QStyle * style (qApp->style ()); 361 static const int iconSize (style->pixelMetric (QStyle::PM_LargeIconSize)); 362 QFont nameFont (option.font); 363 nameFont.setWeight (QFont::Bold); 364 const QFontMetrics nameFM (nameFont); 365 const QString nameStr (tor.name ()); 366 const QSize nameSize (nameFM.size (0, nameStr)); 367 QFont statusFont (option.font); 368 statusFont.setPointSize (static_cast<int> (option.font.pointSize () * 0.9)); 369 const QFontMetrics statusFM (statusFont); 370 const QString statusStr (progressString (tor)); 371 QFont progressFont (statusFont); 372 const QFontMetrics progressFM (progressFont); 373 const QString progressStr (statusString (tor)); 419 374 420 const bool isPaused (tor.isPaused ()); 375 421 … … 425 471 // layout 426 472 const QSize m (margin (*style)); 427 QRect fillArea (option.rect); 428 fillArea.adjust (m.width(), m.height(), -m.width(), -m.height()); 429 QRect iconArea (fillArea.x (), fillArea.y () + (fillArea.height () - iconSize) / 2, iconSize, iconSize); 430 QRect emblemRect (style->alignedRect (option.direction, Qt::AlignRight | Qt::AlignBottom, 431 emblemIcon.actualSize (QSize (iconSize / 2, iconSize / 2), emblemIm, qs), iconArea)); 432 QRect nameArea (iconArea.x () + iconArea.width () + GUI_PAD, fillArea.y (), 433 fillArea.width () - GUI_PAD - iconArea.width (), nameSize.height ()); 434 QRect statusArea (nameArea); 435 statusArea.moveTop (nameArea.y () + nameFM.lineSpacing ()); 436 statusArea.setHeight (nameSize.height ()); 437 QRect barArea (statusArea); 438 barArea.setHeight (BAR_HEIGHT); 439 barArea.moveTop (statusArea.y () + statusFM.lineSpacing ()); 440 QRect progArea (statusArea); 441 progArea.moveTop (barArea.y () + barArea.height ()); 473 const QRect contentRect (option.rect.adjusted (m.width(), m.height(), -m.width(), -m.height())); 474 const ItemLayout layout (tor.name (), progressString (tor), statusString (tor), emblemIcon, 475 option.font, option.direction, contentRect.topLeft (), contentRect.width ()); 442 476 443 477 // render … … 446 480 else 447 481 painter->setPen (option.palette.color (cg, cr)); 448 tor.getMimeTypeIcon().paint (painter, iconArea, Qt::AlignCenter, im, qs);482 tor.getMimeTypeIcon().paint (painter, layout.iconRect, Qt::AlignCenter, im, qs); 449 483 if (!emblemIcon.isNull ()) 450 emblemIcon.paint (painter, emblemRect, Qt::AlignCenter, emblemIm, qs);451 painter->setFont ( nameFont);452 painter->drawText ( nameArea, 0, nameFM.elidedText (nameStr, Qt::ElideRight, nameArea.width ()));453 painter->setFont ( statusFont);454 painter->drawText ( statusArea, 0, statusFM.elidedText (statusStr, Qt::ElideRight, statusArea.width ()));455 painter->setFont ( progressFont);456 painter->drawText ( progArea, 0, progressFM.elidedText (progressStr, Qt::ElideRight, progArea.width ()));457 myProgressBarStyle->rect = barArea;484 emblemIcon.paint (painter, layout.emblemRect, Qt::AlignCenter, emblemIm, qs); 485 painter->setFont (layout.nameFont); 486 painter->drawText (layout.nameRect, Qt::AlignLeft | Qt::AlignVCenter, layout.nameText ()); 487 painter->setFont (layout.statusFont); 488 painter->drawText (layout.statusRect, Qt::AlignLeft | Qt::AlignVCenter, layout.statusText ()); 489 painter->setFont (layout.progressFont); 490 painter->drawText (layout.progressRect, Qt::AlignLeft | Qt::AlignVCenter, layout.progressText ()); 491 myProgressBarStyle->rect = layout.barRect; 458 492 if (tor.isDownloading()) 459 493 { -
trunk/qt/utils.h
r14241 r14454 11 11 #define QTR_UTILS 12 12 13 #include <QIcon> 14 #include <QObject> 15 #include <QRect> 13 16 #include <QString> 14 #include <QObject>15 #include <QIcon>16 17 17 18 #include <cctype> // isxdigit() … … 34 35 35 36 static QString removeTrailingDirSeparator (const QString& path); 37 38 static void narrowRect (QRect& rect, int dx1, int dx2, Qt::LayoutDirection direction) 39 { 40 if (direction == Qt::RightToLeft) 41 qSwap (dx1, dx2); 42 rect.adjust (dx1, 0, -dx2, 0); 43 } 36 44 37 45 // meh
Note: See TracChangeset
for help on using the changeset viewer.