PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/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. #include "DiffStatusView.h"
  19. #include <QPainter>
  20. #include <QBrush>
  21. #include <math.h>
  22. DiffStatusView::DiffStatusView(QWidget* parent)
  23. : QWidget(parent)
  24. {
  25. model = 0;
  26. }
  27. DiffStatusView::~DiffStatusView() {}
  28. QSize DiffStatusView::minimumSizeHint() const
  29. {
  30. return QSize(10, 100);
  31. }
  32. QSize DiffStatusView::sizeHint() const
  33. {
  34. return QSize(10, 200);
  35. }
  36. void DiffStatusView::paintEvent(QPaintEvent *)
  37. {
  38. if (!model) return;
  39. QPainter painter(this);
  40. float lineHeight = (float) height() / model->rowCount();
  41. float lastY = 0.f;
  42. for (int i=0, j=model->rowCount(); i<j; i++)
  43. {
  44. QModelIndex index = model->index(i, 0, QModelIndex());
  45. QVariant var = model->data(index, Qt::BackgroundRole);
  46. if (var.canConvert<QBrush>())
  47. {
  48. painter.fillRect(
  49. 0,
  50. (int)ceil(lastY),
  51. width(),
  52. (int)ceil(lineHeight),
  53. var.value<QBrush>()
  54. );
  55. }
  56. lastY += lineHeight;
  57. }
  58. }