/guitone-1.0rc5/src/view/widgets/DiffStatusView.cpp
C++ | 72 lines | 41 code | 14 blank | 17 comment | 3 complexity | 4c5c5ac191dc4ff60eaf5a7fef3854af MD5 | raw file
Possible License(s): GPL-3.0
1/***************************************************************************
2 * Copyright (C) 2006 by Thomas Keller *
3 * me@thomaskeller.biz *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
18
19#include "DiffStatusView.h"
20
21#include <QPainter>
22#include <QBrush>
23#include <math.h>
24
25DiffStatusView::DiffStatusView(QWidget* parent)
26: QWidget(parent)
27{
28 model = 0;
29}
30
31DiffStatusView::~DiffStatusView() {}
32
33QSize DiffStatusView::minimumSizeHint() const
34{
35 return QSize(10, 100);
36}
37
38QSize DiffStatusView::sizeHint() const
39{
40 return QSize(10, 200);
41}
42
43
44void DiffStatusView::paintEvent(QPaintEvent *)
45{
46 if (!model) return;
47
48 QPainter painter(this);
49
50 float lineHeight = (float) height() / model->rowCount();
51 float lastY = 0.f;
52
53 for (int i=0, j=model->rowCount(); i<j; i++)
54 {
55 QModelIndex index = model->index(i, 0, QModelIndex());
56 QVariant var = model->data(index, Qt::BackgroundRole);
57
58 if (var.canConvert<QBrush>())
59 {
60 painter.fillRect(
61 0,
62 (int)ceil(lastY),
63 width(),
64 (int)ceil(lineHeight),
65 var.value<QBrush>()
66 );
67 }
68
69 lastY += lineHeight;
70 }
71}
72