/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
- /***************************************************************************
- * Copyright (C) 2006 by Thomas Keller *
- * me@thomaskeller.biz *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
- ***************************************************************************/
- #include "DiffStatusView.h"
- #include <QPainter>
- #include <QBrush>
- #include <math.h>
- DiffStatusView::DiffStatusView(QWidget* parent)
- : QWidget(parent)
- {
- model = 0;
- }
- DiffStatusView::~DiffStatusView() {}
- QSize DiffStatusView::minimumSizeHint() const
- {
- return QSize(10, 100);
- }
- QSize DiffStatusView::sizeHint() const
- {
- return QSize(10, 200);
- }
- void DiffStatusView::paintEvent(QPaintEvent *)
- {
- if (!model) return;
- QPainter painter(this);
- float lineHeight = (float) height() / model->rowCount();
- float lastY = 0.f;
- for (int i=0, j=model->rowCount(); i<j; i++)
- {
- QModelIndex index = model->index(i, 0, QModelIndex());
- QVariant var = model->data(index, Qt::BackgroundRole);
- if (var.canConvert<QBrush>())
- {
- painter.fillRect(
- 0,
- (int)ceil(lastY),
- width(),
- (int)ceil(lineHeight),
- var.value<QBrush>()
- );
- }
- lastY += lineHeight;
- }
- }