| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkListWidget.h" | 10 #include "SkListWidget.h" |
| 11 | 11 |
| 12 SkListWidget::SkListWidget(QObject *parent) {} | |
| 13 | |
| 14 SkListWidget::~SkListWidget() {} | |
| 15 | |
| 16 void SkListWidget::paint (QPainter *painter, | 12 void SkListWidget::paint (QPainter *painter, |
| 17 const QStyleOptionViewItem &option, | 13 const QStyleOptionViewItem &option, |
| 18 const QModelIndex &index) const { | 14 const QModelIndex &index) const { |
| 19 /* We adjust the initial position of the list item so that | 15 /* We adjust the initial position of the list item so that |
| 20 * we don't have overlapping top and bottom borders of concurrent | 16 * we don't have overlapping top and bottom borders of concurrent |
| 21 * widget items. */ | 17 * widget items. */ |
| 22 QRect r = option.rect; | 18 QRect r = option.rect; |
| 23 r.adjust(-1,-1,1,0); | 19 r.adjust(-1,-1,1,0); |
| 24 | 20 |
| 25 QPen linePen(QColor::fromRgb(211,211,211), 1, Qt::SolidLine); | 21 QPen linePen(QColor::fromRgb(211,211,211), 1, Qt::SolidLine); |
| 26 QPen fontPen(QColor::fromRgb(51,51,51), 1, Qt::SolidLine); | 22 QPen fontPen(QColor::fromRgb(51,51,51), 1, Qt::SolidLine); |
| 27 QPen fontMarkedPen(Qt::white, 1, Qt::SolidLine); | 23 QPen fontMarkedPen(Qt::white, 1, Qt::SolidLine); |
| 28 | 24 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 57 painter->setPen(fontPen); | 53 painter->setPen(fontPen); |
| 58 } | 54 } |
| 59 | 55 |
| 60 QIcon breakpointIcon = | 56 QIcon breakpointIcon = |
| 61 QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole))); | 57 QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole))); |
| 62 QIcon deleteIcon = | 58 QIcon deleteIcon = |
| 63 QIcon(qvariant_cast<QPixmap>(index.data(Qt::UserRole + 2))); | 59 QIcon(qvariant_cast<QPixmap>(index.data(Qt::UserRole + 2))); |
| 64 int indent = index.data(Qt::UserRole + 3).toInt(); | 60 int indent = index.data(Qt::UserRole + 3).toInt(); |
| 65 | 61 |
| 66 QString drawCommandText = index.data(Qt::DisplayRole).toString(); | 62 QString drawCommandText = index.data(Qt::DisplayRole).toString(); |
| 67 QString drawCommandNumber = index.data(Qt::UserRole + 1).toString(); | 63 QString drawCommandNumber; |
| 64 if (kIndex_IndexStyle == fIndexStyle) { |
| 65 drawCommandNumber = index.data(Qt::UserRole + 1).toString(); |
| 66 } else { |
| 67 drawCommandNumber = index.data(Qt::UserRole + 5).toString(); |
| 68 } |
| 68 float time = index.data(Qt::UserRole + 4).toFloat(); | 69 float time = index.data(Qt::UserRole + 4).toFloat(); |
| 69 QString drawTime; | 70 QString drawTime; |
| 70 drawTime.setNum(time, 'f', 2); | 71 drawTime.setNum(time, 'f', 2); |
| 71 drawTime += "%"; | 72 drawTime += "%"; |
| 72 | 73 |
| 73 /* option.rect is a struct that Qt uses as a target to draw into. Following | 74 /* option.rect is a struct that Qt uses as a target to draw into. Following |
| 74 * the format (x1,y1,x2,y2) x1 and y1 represent where the painter can start | 75 * the format (x1,y1,x2,y2) x1 and y1 represent where the painter can start |
| 75 * drawing. x2 and y2 represent where the drawing area has to terminate | 76 * drawing. x2 and y2 represent where the drawing area has to terminate |
| 76 * counting from the bottom right corner of each list item styled with this | 77 * counting from the bottom right corner of each list item styled with this |
| 77 * widget. A (x1,y1,0,0) rect would mean that the item being drawn would | 78 * widget. A (x1,y1,0,0) rect would mean that the item being drawn would |
| (...skipping 19 matching lines...) Expand all Loading... |
| 97 } else { | 98 } else { |
| 98 // don't need time offset | 99 // don't need time offset |
| 99 r = option.rect.adjusted(kImageSpace+kCommandNumberSpace+indent, 0, -10,
-7); | 100 r = option.rect.adjusted(kImageSpace+kCommandNumberSpace+indent, 0, -10,
-7); |
| 100 } | 101 } |
| 101 painter->drawText(r.left(), r.top(), r.width(), r.height(), | 102 painter->drawText(r.left(), r.top(), r.width(), r.height(), |
| 102 Qt::AlignBottom|Qt::AlignLeft, drawCommandText, &r); | 103 Qt::AlignBottom|Qt::AlignLeft, drawCommandText, &r); |
| 103 | 104 |
| 104 // Draw Command Number | 105 // Draw Command Number |
| 105 r = option.rect.adjusted(kImageSpace, 0, -10, -7); | 106 r = option.rect.adjusted(kImageSpace, 0, -10, -7); |
| 106 painter->drawText(r.left(), r.top(), r.width(), r.height(), | 107 painter->drawText(r.left(), r.top(), r.width(), r.height(), |
| 107 Qt::AlignBottom|Qt::AlignLeft, drawCommandNumber, &r); | 108 Qt::AlignBottom|Qt::AlignLeft, drawCommandNumber, &r); |
| 108 | 109 |
| 109 if (time >= 0.0) { | 110 if (time >= 0.0) { |
| 110 // Draw time | 111 // Draw time |
| 111 r = option.rect.adjusted(kImageSpace+kCommandNumberSpace, 0, -10, -7); | 112 r = option.rect.adjusted(kImageSpace+kCommandNumberSpace, 0, -10, -7); |
| 112 painter->drawText(r.left(), r.top(), r.width(), r.height(), | 113 painter->drawText(r.left(), r.top(), r.width(), r.height(), |
| 113 Qt::AlignBottom|Qt::AlignLeft, drawTime, &r); | 114 Qt::AlignBottom|Qt::AlignLeft, drawTime, &r); |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 117 QSize SkListWidget::sizeHint ( const QStyleOptionViewItem & option, | 118 QSize SkListWidget::sizeHint (const QStyleOptionViewItem& option, |
| 118 const QModelIndex & index ) const{ | 119 const QModelIndex& index) const{ |
| 119 return QSize(200, 30); | 120 return QSize(200, 30); |
| 120 } | 121 } |
| OLD | NEW |