diff options
author | Arno <am@disconnect.de> | 2010-07-25 13:00:30 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-07-25 13:00:30 +0200 |
commit | 004b9243248a29eaa73b5fae5a5ef7b5ca914f94 (patch) | |
tree | 0b1f9f413d798390fba316d5093bbd5dcd466398 /graphbarwidget.cpp | |
parent | bfcb2cd0e0168e1f740678a626a5d5077cf6e677 (diff) | |
download | SheMov-004b9243248a29eaa73b5fae5a5ef7b5ca914f94.tar.gz SheMov-004b9243248a29eaa73b5fae5a5ef7b5ca914f94.tar.bz2 SheMov-004b9243248a29eaa73b5fae5a5ef7b5ca914f94.zip |
Fixed StatisticsDialog
adapted StatisticsDialog to the new database schema and make it use
WebKit and HTML to display the graph bars.
This change obsoleted the classes ActorCountModel and GraphBarWidget.
Diffstat (limited to 'graphbarwidget.cpp')
-rw-r--r-- | graphbarwidget.cpp | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/graphbarwidget.cpp b/graphbarwidget.cpp deleted file mode 100644 index c6f9b0e..0000000 --- a/graphbarwidget.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - 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 - 2 of the License, or (at your option) any later version. -*/ - -#include <QFontMetrics> -#include <QPainter> - -#include "graphbarwidget.h" - -GraphBarWidget::GraphBarWidget(const QList<QList<QVariant> > data, QWidget *parent) : QWidget(parent), mMargin(10), mData(data) { - mBarHeight = fontMetrics().height(); -} - -int GraphBarWidget::maxValue() const { - int retval = -1; - foreach(QList<QVariant> l, mData){ - if(l.at(1).toInt() > retval){ - retval = l.at(1).toInt(); - } - } - return retval; -} - -QSize GraphBarWidget::maxDescr() const { - QFont f = font(); - f.setBold(true); - QFontMetrics fm(f); - QSize retval(0,0); - foreach(QList<QVariant> l, mData){ - QString descr = l.at(0).toString(); - QSize curSize = fm.size(Qt::TextSingleLine, descr); - if(curSize.width() > retval.width()){ - retval = curSize; - } - } - return retval; -} - -QSize GraphBarWidget::maxCount() const { - QFontMetrics fm = fontMetrics(); - QSize retval(0,0); - foreach(QList<QVariant> l, mData){ - QString curCount = QString("(%1)").arg(l.at(2).toString()); - QSize curSize = fm.size(Qt::TextSingleLine, curCount); - if(curSize.width() > retval.width()){ - retval = curSize; - } - } - return retval; -} - -QSize GraphBarWidget::sizeHint() const { - int height = mData.count() * mBarHeight; - height += mData.count() * mMargin; - height += mBarHeight + mMargin; - return QSize(400, height); -} - -void GraphBarWidget::paintEvent(QPaintEvent *){ - QPainter p(this); - QHash<QString, qreal> length; //int - QList<QList<QVariant> >::const_iterator it; - - //draw background - QPen pen(Qt::red, 2); - p.setPen(pen); - QLinearGradient bgGradient(QPointF(0.0, height() / 2), QPointF(width(), height() / 2)); - bgGradient.setColorAt(0, QColor(221, 107, 80)); - bgGradient.setColorAt(1, QColor(251, 179, 150)); - QBrush brush(bgGradient); - p.setBrush(brush); - p.drawRect(contentsRect()); - - //draw caption - QFont f = font(); - f.setUnderline(true); - f.setBold(true); - p.setFont(f); - QString cap(caption()); - QFontMetrics fm(f); - int captionStartx = (width() - fm.width(cap)) / 2; - int captionStarty = fm.height(); - p.drawText(captionStartx, captionStarty, cap); - - //prepare drawing data - int barsStarty = fm.height() + 2 * mMargin + 10; - f.setUnderline(false); - f.setBold(true); - p.setFont(f); - int maxdescr = maxDescr().width(); - int maxcount = maxCount().width(); - - int barsStartx = maxdescr + 2 * mMargin; - int marginRight = maxcount + 2 * mMargin; - int maxWidth = width() - barsStartx - marginRight; - p.setRenderHints(QPainter::Antialiasing); - p.setPen(QPen(Qt::red, 1)); - - //calculate real lengths based on widget width - for(it = mData.constBegin(); it != mData.constEnd(); ++it){ - qreal value = it->at(1).toDouble(); - value = value / maxValue() * maxWidth; - length[it->at(0).toString()] = value; - } - - //draw the bars and numbers - int ctr(0); - for(QList<QList<QVariant> >::const_iterator itr = mData.constBegin(); itr != mData.constEnd() ; ++itr, ++ctr){ - int starty = barsStarty + ctr * p.fontMetrics().height() + ctr * mMargin; - p.drawText(mMargin, starty, itr->at(0).toString()); - QLinearGradient barGradient(QPointF(barsStartx, starty), QPointF(width(), starty)); - barGradient.setColorAt(0, QColor(0, 128, 170)); - barGradient.setColorAt(1, QColor(131, 205, 214)); - QBrush b(barGradient); - p.setBrush(b); - qreal len = length.value(itr->at(0).toString()); - QRect bar(barsStartx, starty - p.fontMetrics().height() + p.fontMetrics().descent(), len, p.fontMetrics().height()); - p.drawRect(bar); - int nStartx = barsStartx + len + mMargin; - p.drawText(nStartx, starty, QString(tr("(%1)")).arg(itr->at(2).toString())); - } -} |