2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "SkListWidget.h"
|
|
|
|
|
|
|
|
SkListWidget::SkListWidget(QObject *parent) {}
|
|
|
|
|
|
|
|
SkListWidget::~SkListWidget() {}
|
|
|
|
|
2012-07-12 14:15:54 +00:00
|
|
|
void SkListWidget::paint (QPainter *painter,
|
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const {
|
|
|
|
/* We adjust the initial position of the list item so that
|
2012-06-29 14:21:22 +00:00
|
|
|
* we don't have overlapping top and bottom borders of concurrent
|
2012-07-12 14:15:54 +00:00
|
|
|
* widget items. */
|
2012-06-29 14:21:22 +00:00
|
|
|
QRect r = option.rect;
|
|
|
|
r.adjust(-1,-1,1,0);
|
|
|
|
|
|
|
|
QPen linePen(QColor::fromRgb(211,211,211), 1, Qt::SolidLine);
|
|
|
|
QPen fontPen(QColor::fromRgb(51,51,51), 1, Qt::SolidLine);
|
|
|
|
QPen fontMarkedPen(Qt::white, 1, Qt::SolidLine);
|
|
|
|
|
2012-07-12 14:15:54 +00:00
|
|
|
// If selected
|
2012-06-29 14:21:22 +00:00
|
|
|
if(option.state & QStyle::State_Selected){
|
|
|
|
QLinearGradient gradientSelected(r.left(),r.top(),r.left(),r.height()+r.top());
|
|
|
|
gradientSelected.setColorAt(0.0, QColor::fromRgb(119,213,247));
|
|
|
|
gradientSelected.setColorAt(0.9, QColor::fromRgb(27,134,183));
|
|
|
|
gradientSelected.setColorAt(1.0, QColor::fromRgb(0,120,174));
|
|
|
|
painter->setBrush(gradientSelected);
|
|
|
|
painter->drawRect(r);
|
|
|
|
|
|
|
|
painter->setPen(linePen);
|
|
|
|
painter->drawLine(r.topLeft(),r.topRight());
|
|
|
|
painter->drawLine(r.topRight(),r.bottomRight());
|
|
|
|
painter->drawLine(r.bottomLeft(),r.bottomRight());
|
|
|
|
painter->drawLine(r.topLeft(),r.bottomLeft());
|
|
|
|
|
|
|
|
painter->setPen(fontMarkedPen);
|
|
|
|
|
|
|
|
} else {
|
2012-07-12 14:15:54 +00:00
|
|
|
// Alternating background
|
|
|
|
painter->setBrush((index.row() % 2) ? Qt::white : QColor(252,252,252));
|
2012-06-29 14:21:22 +00:00
|
|
|
painter->drawRect(r);
|
|
|
|
|
|
|
|
painter->setPen(linePen);
|
|
|
|
painter->drawLine(r.topLeft(),r.topRight());
|
|
|
|
painter->drawLine(r.topRight(),r.bottomRight());
|
|
|
|
painter->drawLine(r.bottomLeft(),r.bottomRight());
|
|
|
|
painter->drawLine(r.topLeft(),r.bottomLeft());
|
|
|
|
|
|
|
|
painter->setPen(fontPen);
|
|
|
|
}
|
|
|
|
|
2012-07-12 14:15:54 +00:00
|
|
|
QIcon breakpointIcon =
|
|
|
|
QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
|
|
|
|
QIcon deleteIcon =
|
2012-07-17 15:40:51 +00:00
|
|
|
QIcon(qvariant_cast<QPixmap>(index.data(Qt::UserRole + 2)));
|
2012-11-06 16:45:36 +00:00
|
|
|
int indent = index.data(Qt::UserRole + 3).toInt();
|
2012-07-12 14:15:54 +00:00
|
|
|
|
|
|
|
QString drawCommandText = index.data(Qt::DisplayRole).toString();
|
|
|
|
QString drawCommandNumber = index.data(Qt::UserRole + 1).toString();
|
|
|
|
|
|
|
|
/* option.rect is a struct that Qt uses as a target to draw into. Following
|
|
|
|
* the format (x1,y1,x2,y2) x1 and y1 represent where the painter can start
|
|
|
|
* drawing. x2 and y2 represent where the drawing area has to terminate
|
|
|
|
* counting from the bottom right corner of each list item styled with this
|
|
|
|
* widget. A (x1,y1,0,0) rect would mean that the item being drawn would
|
|
|
|
* be pushed down into that bottom corner. Negative values in the x2,y2
|
|
|
|
* spot act as a margin for the bottom and right sides. Positive values in
|
|
|
|
* x1,y1 act as a margin for the top and left. The target area will not
|
|
|
|
* affect size of text but will scale icons. */
|
2012-11-06 16:45:36 +00:00
|
|
|
static const int kImageSpace = 35;
|
|
|
|
static const int kCommandNumberSpace = 30;
|
2012-07-12 14:15:54 +00:00
|
|
|
|
|
|
|
// Breakpoint Icon
|
2012-06-29 14:21:22 +00:00
|
|
|
r = option.rect.adjusted(5, 10, -10, -10);
|
2012-07-12 14:15:54 +00:00
|
|
|
breakpointIcon.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft);
|
|
|
|
|
|
|
|
// Delete Icon
|
|
|
|
r = option.rect.adjusted(19, 10, -10, -10);
|
|
|
|
deleteIcon.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft);
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2012-07-12 14:15:54 +00:00
|
|
|
// Draw Command
|
2012-11-06 16:45:36 +00:00
|
|
|
r = option.rect.adjusted(kImageSpace+kCommandNumberSpace+indent, 0, -10, -7);
|
2012-07-12 14:15:54 +00:00
|
|
|
painter->drawText(r.left(), r.top(), r.width(), r.height(),
|
2012-11-06 16:45:36 +00:00
|
|
|
Qt::AlignBottom|Qt::AlignLeft, drawCommandText, &r);
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2012-07-12 14:15:54 +00:00
|
|
|
// Draw Command Number
|
2012-11-06 16:45:36 +00:00
|
|
|
r = option.rect.adjusted(kImageSpace, 0, -10, -7);
|
2012-07-12 14:15:54 +00:00
|
|
|
painter->drawText(r.left(), r.top(), r.width(), r.height(),
|
|
|
|
Qt::AlignBottom|Qt::AlignLeft, drawCommandNumber, &r);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 14:15:54 +00:00
|
|
|
QSize SkListWidget::sizeHint ( const QStyleOptionViewItem & option,
|
|
|
|
const QModelIndex & index ) const{
|
2012-06-29 14:21:22 +00:00
|
|
|
return QSize(200, 30);
|
|
|
|
}
|