1
/*************************************************************************
2
* Copyright 2009-2010 Sandro Andrade sandroandrade@kde.org *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License as *
6
* published by the Free Software Foundation; either version 2 of *
7
* the License or (at your option) version 3 or any later version *
8
* accepted by the membership of KDE e.V. (or its successor approved *
9
* by the membership of KDE e.V.), which shall act as a proxy *
10
* defined in Section 14 of version 3 of the license. *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
19
* ***********************************************************************/
21
#include "commithistoryview.h"
23
#include <QGraphicsProxyWidget>
25
#include <KGlobalSettings>
28
#include <qwt_plot_grid.h>
29
#include <qwt_plot_curve.h>
30
#include <qwt_scale_widget.h>
32
class TimeScaleDraw : public QwtScaleDraw
35
TimeScaleDraw(const QDate &minDate)
40
virtual QwtText label(double v) const
42
QString dateFormat = KGlobal::locale()->dateFormatShort();
43
if (dateFormat == "%Y-%m-%d")
44
return QwtText(m_minDate.addDays((int)v).toString("MM/dd"));
46
return QwtText(m_minDate.addDays((int)v).toString("dd/MM"));
53
CommitHistoryView::CommitHistoryView(KdeObservatory *kdeObservatory, const QHash<QString, bool> &commitHistoryViewProjects, const QMap<QString, KdeObservatory::Project> &projects, QGraphicsWidget *parent, Qt::WindowFlags wFlags)
54
: IViewProvider(kdeObservatory, parent, wFlags),
55
m_commitHistoryViewProjects(commitHistoryViewProjects),
60
CommitHistoryView::~CommitHistoryView()
64
void CommitHistoryView::createViews()
67
QHashIterator<QString, bool> i(m_commitHistoryViewProjects);
72
createView(i18nc("Commit history for a given project %1", "Commit History - %1", i.key()), QString("Commit History - ") + i.key());
76
void CommitHistoryView::updateViews(const Plasma::DataEngine::Data &data)
78
QString project = data["project"].toString();
80
const DateCommitList &projectCommits = data[project].value<DateCommitList>();
82
int count = projectCommits.count();
87
QString tmpStr = projectCommits.at(0).first;
88
qlonglong minDate = tmpStr.remove('-').toLongLong();
89
double *x = new double[count];
90
double *y = new double[count];
92
int count = projectCommits.count();
94
for (j = 0; j < count; ++j)
96
const QPair<QString, int> &pair = projectCommits.at(j);
100
if (y[j] > maxCommit)
104
QGraphicsWidget *container = containerForView(QString("Commit History - ") + project);
108
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(container);
109
proxy->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
111
QwtPlot *plot = new QwtPlot;
112
plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113
plot->setAttribute(Qt::WA_TranslucentBackground, true);
115
plot->setAxisScale(QwtPlot::yLeft, 0, qRound((maxCommit/5.)+0.5)*5, qRound((maxCommit/5.)+0.5));
117
plot->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(QDate::fromString(QString::number(minDate), "yyyyMMdd")));
119
plot->setAxisFont(QwtPlot::yLeft, KGlobalSettings::smallestReadableFont());
120
plot->setAxisFont(QwtPlot::xBottom, KGlobalSettings::smallestReadableFont());
122
plot->setAxisLabelRotation(QwtPlot::xBottom, -15);
124
plot->setCanvasBackground(QColor(0, 0, 140));
126
QwtPlotCurve *curve = new QwtPlotCurve;
127
curve->setData(x, y, j);
132
QPen pen = curve->pen();
133
pen.setColor(QColor(255, 255, 0));
137
QwtPlotGrid *grid = new QwtPlotGrid;
138
grid->enableXMin(true);
139
grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine));
140
grid->setMinPen(QPen(Qt::NoPen));
143
proxy->setWidget(plot);
144
plot->setGeometry(0, 0, container->geometry().width(), container->geometry().height());