chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "SkListWidget.h" |
| 11 | |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 12 | void SkListWidget::paint (QPainter *painter, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 13 | const QStyleOptionViewItem &option, |
| 14 | const QModelIndex &index) const { |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 15 | /* We adjust the initial position of the list item so that |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 16 | * we don't have overlapping top and bottom borders of concurrent |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 17 | * widget items. */ |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 18 | QRect r = option.rect; |
| 19 | r.adjust(-1,-1,1,0); |
| 20 | |
| 21 | QPen linePen(QColor::fromRgb(211,211,211), 1, Qt::SolidLine); |
| 22 | QPen fontPen(QColor::fromRgb(51,51,51), 1, Qt::SolidLine); |
| 23 | QPen fontMarkedPen(Qt::white, 1, Qt::SolidLine); |
| 24 | |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 25 | // If selected |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 26 | if(option.state & QStyle::State_Selected){ |
| 27 | QLinearGradient gradientSelected(r.left(),r.top(),r.left(),r.height()+r.top()); |
| 28 | gradientSelected.setColorAt(0.0, QColor::fromRgb(119,213,247)); |
| 29 | gradientSelected.setColorAt(0.9, QColor::fromRgb(27,134,183)); |
| 30 | gradientSelected.setColorAt(1.0, QColor::fromRgb(0,120,174)); |
| 31 | painter->setBrush(gradientSelected); |
| 32 | painter->drawRect(r); |
| 33 | |
| 34 | painter->setPen(linePen); |
| 35 | painter->drawLine(r.topLeft(),r.topRight()); |
| 36 | painter->drawLine(r.topRight(),r.bottomRight()); |
| 37 | painter->drawLine(r.bottomLeft(),r.bottomRight()); |
| 38 | painter->drawLine(r.topLeft(),r.bottomLeft()); |
| 39 | |
| 40 | painter->setPen(fontMarkedPen); |
| 41 | |
| 42 | } else { |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 43 | // Alternating background |
| 44 | painter->setBrush((index.row() % 2) ? Qt::white : QColor(252,252,252)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 45 | painter->drawRect(r); |
| 46 | |
| 47 | painter->setPen(linePen); |
| 48 | painter->drawLine(r.topLeft(),r.topRight()); |
| 49 | painter->drawLine(r.topRight(),r.bottomRight()); |
| 50 | painter->drawLine(r.bottomLeft(),r.bottomRight()); |
| 51 | painter->drawLine(r.topLeft(),r.bottomLeft()); |
| 52 | |
| 53 | painter->setPen(fontPen); |
| 54 | } |
| 55 | |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 56 | QIcon breakpointIcon = |
| 57 | QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole))); |
| 58 | QIcon deleteIcon = |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 59 | QIcon(qvariant_cast<QPixmap>(index.data(Qt::UserRole + 2))); |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 60 | int indent = index.data(Qt::UserRole + 3).toInt(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 61 | |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 62 | QString drawCommandText = index.data(Qt::DisplayRole).toString(); |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 63 | QString drawCommandNumber; |
robertphillips | 546db46 | 2015-03-26 10:08:04 -0700 | [diff] [blame] | 64 | drawCommandNumber = index.data(Qt::UserRole + 1).toString(); |
robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 65 | float time = index.data(Qt::UserRole + 4).toFloat(); |
| 66 | QString drawTime; |
robertphillips@google.com | e099bc4 | 2012-11-19 16:26:40 +0000 | [diff] [blame] | 67 | drawTime.setNum(time, 'f', 2); |
robertphillips@google.com | 20beb48 | 2013-03-07 19:32:45 +0000 | [diff] [blame] | 68 | drawTime += "%"; |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 69 | |
| 70 | /* option.rect is a struct that Qt uses as a target to draw into. Following |
| 71 | * the format (x1,y1,x2,y2) x1 and y1 represent where the painter can start |
| 72 | * drawing. x2 and y2 represent where the drawing area has to terminate |
| 73 | * counting from the bottom right corner of each list item styled with this |
| 74 | * widget. A (x1,y1,0,0) rect would mean that the item being drawn would |
| 75 | * be pushed down into that bottom corner. Negative values in the x2,y2 |
| 76 | * spot act as a margin for the bottom and right sides. Positive values in |
| 77 | * x1,y1 act as a margin for the top and left. The target area will not |
| 78 | * affect size of text but will scale icons. */ |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 79 | static const int kImageSpace = 35; |
robertphillips@google.com | e099bc4 | 2012-11-19 16:26:40 +0000 | [diff] [blame] | 80 | static const int kCommandNumberSpace = 33; |
robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 81 | static const int kTimeSpace = 30; |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 82 | |
| 83 | // Breakpoint Icon |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 84 | r = option.rect.adjusted(5, 10, -10, -10); |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 85 | breakpointIcon.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 86 | |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 87 | // Delete Icon |
| 88 | r = option.rect.adjusted(19, 10, -10, -10); |
| 89 | deleteIcon.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 90 | |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 91 | // Draw Command |
robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 92 | if (time >= 0.0) { |
| 93 | r = option.rect.adjusted(kImageSpace+kCommandNumberSpace+kTimeSpace+indent, 0, -10, -7); |
| 94 | } else { |
| 95 | // don't need time offset |
| 96 | r = option.rect.adjusted(kImageSpace+kCommandNumberSpace+indent, 0, -10, -7); |
| 97 | } |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 98 | painter->drawText(r.left(), r.top(), r.width(), r.height(), |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 99 | Qt::AlignBottom|Qt::AlignLeft, drawCommandText, &r); |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 100 | |
| 101 | // Draw Command Number |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 102 | r = option.rect.adjusted(kImageSpace, 0, -10, -7); |
chudy@google.com | e565de4 | 2012-07-12 14:15:54 +0000 | [diff] [blame] | 103 | painter->drawText(r.left(), r.top(), r.width(), r.height(), |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 104 | Qt::AlignBottom|Qt::AlignLeft, drawCommandNumber, &r); |
robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 105 | |
| 106 | if (time >= 0.0) { |
| 107 | // Draw time |
| 108 | r = option.rect.adjusted(kImageSpace+kCommandNumberSpace, 0, -10, -7); |
| 109 | painter->drawText(r.left(), r.top(), r.width(), r.height(), |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 110 | Qt::AlignBottom|Qt::AlignLeft, drawTime, &r); |
robertphillips@google.com | d26c706 | 2012-11-12 20:42:12 +0000 | [diff] [blame] | 111 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 112 | } |
| 113 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 114 | QSize SkListWidget::sizeHint (const QStyleOptionViewItem& option, |
| 115 | const QModelIndex& index) const{ |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 116 | return QSize(200, 30); |
| 117 | } |