summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--graphbarwidget.cpp125
-rw-r--r--graphbarwidget.h45
-rw-r--r--shemov.pro139
-rw-r--r--shemov.qrc20
-rw-r--r--statisticsdialog.cpp118
-rw-r--r--statisticsdialog.h19
6 files changed, 286 insertions, 180 deletions
diff --git a/graphbarwidget.cpp b/graphbarwidget.cpp
new file mode 100644
index 0000000..c6f9b0e
--- /dev/null
+++ b/graphbarwidget.cpp
@@ -0,0 +1,125 @@
+/*
+ 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()));
+ }
+}
diff --git a/graphbarwidget.h b/graphbarwidget.h
new file mode 100644
index 0000000..af7c8ba
--- /dev/null
+++ b/graphbarwidget.h
@@ -0,0 +1,45 @@
+/*
+ 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.
+*/
+
+#ifndef GRAPHBARWIDGET_H
+#define GRAPHBARWIDGET_H
+
+#include <QWidget>
+#include <QVariant>
+#include <QSize>
+
+class QPaintEvent;
+
+class GraphBarWidget : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(int maxValue READ maxValue);
+ Q_PROPERTY(QSize maxDescr READ maxDescr);
+ Q_PROPERTY(QSize maxCount READ maxCount);
+ Q_PROPERTY(QString caption READ caption WRITE setCaption);
+ public:
+ GraphBarWidget(const QList<QList<QVariant> > data, QWidget *parent = 0);
+ ~GraphBarWidget() {}
+ QString caption() const { return mCaption; }
+ void setCaption(const QString &caption) { mCaption = caption; }
+ int maxValue() const;
+ QSize maxDescr() const;
+ QSize maxCount() const;
+ virtual QSize sizeHint() const;
+
+ protected:
+ void paintEvent(QPaintEvent *);
+
+ private:
+ int mBarHeight;
+ int mMargin;
+ QString mCaption;
+ QList<QList<QVariant> > mData;
+ QList<QSize> mSizes;
+
+};
+
+#endif
diff --git a/shemov.pro b/shemov.pro
index 043d169..d3d8fdb 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -1,75 +1,80 @@
TEMPLATE = app
-CONFIG += warn_on thread qt debug
+CONFIG += warn_on \
+ thread \
+ qt \
+ debug
CONFIG -= release
QT += sql
SOURCES = main.cpp \
-listmodel.cpp \
-movieitem.cpp \
-moviemodel.cpp \
-coveritem.cpp \
-filesystemdirproxy.cpp \
-filesystemwidget.cpp \
-fileview.cpp \
-shemov.cpp \
-filesystemfileproxy.cpp \
-helper.cpp \
-shemoviconprovider.cpp \
-messagedialog.cpp \
-configurationdialog.cpp \
-extractordialog.cpp \
-archiveeditdialog.cpp \
-listeditor.cpp \
-covereditor.cpp \
-archivefilewidget.cpp \
-archiveviewwidget.cpp \
-archivefileview.cpp \
-archiveproxy.cpp \
-editarchiveitemdialog.cpp \
-sizedelegate.cpp \
-archiveddelegate.cpp \
-coverarchiveeditor.cpp \
-textenterdialog.cpp \
-moviepropertiesdialog.cpp \
-statisticsdialog.cpp \
-actorwidget.cpp \
-actormodel.cpp \
-fileinfoitem.cpp \
-fileinfomodel.cpp \
-actorcountmodel.cpp
+ listmodel.cpp \
+ movieitem.cpp \
+ moviemodel.cpp \
+ coveritem.cpp \
+ filesystemdirproxy.cpp \
+ filesystemwidget.cpp \
+ fileview.cpp \
+ shemov.cpp \
+ filesystemfileproxy.cpp \
+ helper.cpp \
+ shemoviconprovider.cpp \
+ messagedialog.cpp \
+ configurationdialog.cpp \
+ extractordialog.cpp \
+ archiveeditdialog.cpp \
+ listeditor.cpp \
+ covereditor.cpp \
+ archivefilewidget.cpp \
+ archiveviewwidget.cpp \
+ archivefileview.cpp \
+ archiveproxy.cpp \
+ editarchiveitemdialog.cpp \
+ sizedelegate.cpp \
+ archiveddelegate.cpp \
+ coverarchiveeditor.cpp \
+ textenterdialog.cpp \
+ moviepropertiesdialog.cpp \
+ statisticsdialog.cpp \
+ actorwidget.cpp \
+ actormodel.cpp \
+ fileinfoitem.cpp \
+ fileinfomodel.cpp \
+ actorcountmodel.cpp \
+ graphbarwidget.cpp
HEADERS = listitem.h \
-listmodel.h \
-movieitem.h \
-moviemodel.h \
-coveritem.h \
-filesystemdirproxy.h \
-filesystemwidget.h \
-fileview.h \
-shemov.h \
-filesystemfileproxy.h \
-helper.h \
-shemoviconprovider.h \
-messagedialog.h \
-configurationdialog.h \
-extractordialog.h \
-archiveeditdialog.h \
-listeditor.h \
-covereditor.h \
-archivefilewidget.h \
-archiveviewwidget.h \
-archivefileview.h \
-archiveproxy.h \
-editarchiveitemdialog.h \
-sizedelegate.h \
-archiveddelegate.h \
-coverarchiveeditor.h \
-textenterdialog.h \
-moviepropertiesdialog.h \
-statisticsdialog.h \
-actorwidget.h \
-actormodel.h \
-fileinfoitem.h \
-fileinfomodel.h \
-actorcountmodel.h
+ listmodel.h \
+ movieitem.h \
+ moviemodel.h \
+ coveritem.h \
+ filesystemdirproxy.h \
+ filesystemwidget.h \
+ fileview.h \
+ shemov.h \
+ filesystemfileproxy.h \
+ helper.h \
+ shemoviconprovider.h \
+ messagedialog.h \
+ configurationdialog.h \
+ extractordialog.h \
+ archiveeditdialog.h \
+ listeditor.h \
+ covereditor.h \
+ archivefilewidget.h \
+ archiveviewwidget.h \
+ archivefileview.h \
+ archiveproxy.h \
+ editarchiveitemdialog.h \
+ sizedelegate.h \
+ archiveddelegate.h \
+ coverarchiveeditor.h \
+ textenterdialog.h \
+ moviepropertiesdialog.h \
+ statisticsdialog.h \
+ actorwidget.h \
+ actormodel.h \
+ fileinfoitem.h \
+ fileinfomodel.h \
+ actorcountmodel.h \
+ graphbarwidget.h
LIBS += -lmagic
LIBS += -lcryptopp
INCLUDEPATH += /usr/include/cryptopp
diff --git a/shemov.qrc b/shemov.qrc
index 8d54656..17ee5df 100644
--- a/shemov.qrc
+++ b/shemov.qrc
@@ -1,12 +1,10 @@
-<!DOCTYPE RCC>
-<RCC version="1.0">
- <qresource>
- <file>movie.svg</file>
- <file>dildo.png</file>
- <file>picture.svg</file>
- <file>shemov.png</file>
- <file>archive.svg</file>
- <file>shemov_splash.png</file>
- </qresource>
+<RCC>
+ <qresource prefix="/" >
+ <file>movie.svg</file>
+ <file>dildo.png</file>
+ <file>picture.svg</file>
+ <file>shemov.png</file>
+ <file>archive.svg</file>
+ <file>shemov_splash.png</file>
+ </qresource>
</RCC>
-
diff --git a/statisticsdialog.cpp b/statisticsdialog.cpp
index 5a48f63..ba93726 100644
--- a/statisticsdialog.cpp
+++ b/statisticsdialog.cpp
@@ -24,16 +24,49 @@
#include "statisticsdialog.h"
#include "actorcountmodel.h"
+#include "graphbarwidget.h"
StatisticsDialog::StatisticsDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
QVBoxLayout *mainLayout = new QVBoxLayout;
mTab = new QTabWidget;
// quality distribution
- QualityStats * qs = new QualityStats;
+ QList<QList<QVariant> > qualityData;
+ QSqlQuery q("SELECT DISTINCT(iquality), COUNT(iquality) FROM movies GROUP BY iquality ORDER BY iquality");
+ while(q.next()){
+ QList<QVariant> d;
+ d << q.value(0) << q.value(1) << q.value(1);
+ qualityData << d;
+ }
+ GraphBarWidget *qs = new GraphBarWidget(qualityData);
+ qs->setCaption(tr("Movie qualities"));
mTab->addTab(qs, tr("Quality Distribution"));
mainLayout->addWidget(mTab);
+ // genre distribution
+ QList<QList<QVariant> > genreData;
+ QSqlQuery q2("SELECT DISTINCT(genre.igenreid), genre.tgenrename, COUNT(movies.imovid) FROM movies, genre WHERE movies.igenreid = genre.igenreid GROUP by genre.igenreid, genre.tgenrename ORDER by genre.tgenrename");
+ while(q2.next()){
+ QList<QVariant> d;
+ d << q2.value(1) << q2.value(2) << q2.value(2);
+ genreData << d;
+ }
+ GraphBarWidget *gs = new GraphBarWidget(genreData);
+ gs->setCaption(tr("Genre Distribution"));
+ mTab->addTab(gs, tr("Genre Distribution"));
+
+ // top ten actors
+ QList<QList<QVariant> > actorData;
+ QSqlQuery q3("SELECT DISTINCT(actor.iactorid), actor.tactorname, COUNT(DISTINCT(movies.ttitle)) AS num FROM movies, actor, movieactormap WHERE actor.iactorid = movieactormap.iactorid AND movieactormap.imovid = movies.imovid GROUP BY actor.iactorid, actor.tactorname ORDER BY num DESC LIMIT 10");
+ while(q3.next()){
+ QList<QVariant> d;
+ d << q3.value(1) << q3.value(2) << q3.value(2);
+ actorData << d;
+ }
+ GraphBarWidget *as = new GraphBarWidget(actorData);
+ as->setCaption(tr("Top 10 actors"));
+ mTab->addTab(as, tr("Top 10 actors"));
+
// actor count
QWidget *actorWidget = new QWidget;
QHBoxLayout *actorLayout = new QHBoxLayout;
@@ -59,86 +92,3 @@ StatisticsDialog::StatisticsDialog(QWidget *parent, Qt::WindowFlags f) : QDialog
setLayout(mainLayout);
setWindowTitle(title);
}
-
-QualityStats::QualityStats(QWidget *parent) : QWidget(parent), mMargin(10), mMaxValue(0) {
- QSqlQuery q("SELECT DISTINCT(iquality), COUNT(iquality) FROM movies GROUP BY iquality");
- while(q.next()){
- mQualityDistrib[q.value(0).toInt()] = q.value(1).toInt();
- if(q.value(1).toInt() > mMaxValue){
- mMaxValue = q.value(1).toInt();
- }
- }
- QFontMetrics fm(qApp->font());
- mBarHeight = fm.height();
-}
-
-void QualityStats::paintEvent(QPaintEvent *){
- QPainter p(this);
- QMap<int, qreal> length;
- QMap<int, int>::const_iterator it;
- QMap<int, qreal>::const_iterator itr;
-
- //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 = qApp->font();
- f.setUnderline(true);
- f.setBold(true);
- p.setFont(f);
- QString caption(tr("Quality Distribution"));
- QFontMetrics fm(f);
- int captionStartx = (width() - fm.width(caption)) / 2;
- int captionStarty = fm.height();
- p.drawText(captionStartx, captionStarty, caption);
-
- //prepare drawing data
- int barsStarty = fm.height() + 2 * mMargin;
- f.setUnderline(false);
- f.setBold(true);
- p.setFont(f);
- int maxKey = (--mQualityDistrib.end()).key();
- int barsStartx = p.fontMetrics().width(QString::number(maxKey)) + 2 * mMargin;
- int marginRight = p.fontMetrics().width(QString(tr("(%1")).arg(QString::number(mMaxValue))) + 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 = mQualityDistrib.constBegin(); it != mQualityDistrib.constEnd(); ++it){
- qreal value = it.value();
- value = static_cast<qreal>(value) / mMaxValue * maxWidth;
- length[it.key()] = value;
- }
-
- //draw the bars and numbers
- int ctr(0);
- for(itr = length.constBegin(); itr != length.constEnd(); ++itr, ++ctr){
- int starty = barsStarty + ctr * p.fontMetrics().height() + ctr * mMargin;
- p.drawText(mMargin, starty, QString::number(itr.key()));
- 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);
- QRect bar(barsStartx, starty - p.fontMetrics().height() + p.fontMetrics().descent(), itr.value(), p.fontMetrics().height());
- p.drawRect(bar);
- int nStartx = barsStartx + itr.value() + mMargin;
- p.drawText(nStartx, starty, QString(tr("(%1)")).arg(QString::number(mQualityDistrib[itr.key()])));
- }
-}
-
-QSize QualityStats::sizeHint() const {
- int height = mQualityDistrib.count() * mBarHeight;
- height += mQualityDistrib.count() * mMargin;
- height += mBarHeight + mMargin;
- return QSize(400, height);
-}
-
diff --git a/statisticsdialog.h b/statisticsdialog.h
index 115d6c9..b431a07 100644
--- a/statisticsdialog.h
+++ b/statisticsdialog.h
@@ -20,29 +20,12 @@ class StatisticsDialog : public QDialog {
Q_OBJECT
public:
StatisticsDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
- ~StatisticsDialog() {};
+ ~StatisticsDialog() {}
private:
QTabWidget *mTab;
QPushButton *mOk;
};
-class QualityStats : public QWidget {
- Q_OBJECT
- public:
- QualityStats(QWidget *parent = 0);
- ~QualityStats() {};
- virtual QSize sizeHint() const;
-
- protected:
- void paintEvent(QPaintEvent *);
-
- private:
- int mBarHeight;
- const int mMargin;
- int mMaxValue;
- QMap<int, int> mQualityDistrib;
-};
-
#endif