1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
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 <QVariant>
#include <QSpinBox>
#include <QComboBox>
#include "delegates.h"
#include "smglobals.h"
#include "helper.h"
/* Delegate for File no. */
QString FileNoDelegate::displayText(const QVariant &value, const QLocale &locale) const{
Q_UNUSED(locale);
int no = value.toInt();
if(no){
return QString::number(no);
}
return QString();
}
QWidget *FileNoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{
Q_UNUSED(option);
QSpinBox *retval = new QSpinBox(parent);
int no = index.data().toInt();
retval->setValue(no);
return retval;
}
/* Delegate for file type */
FileTypeDelegate::FileTypeDelegate(QObject *parent) : QStyledItemDelegate(parent){
mFiletypeMap = SmGlobals::instance()->filetypeMap();
}
QString FileTypeDelegate::displayText(const QVariant &value, const QLocale &locale) const{
Q_UNUSED(locale);
int type = value.toInt();
QString retval = mFiletypeMap.value(type);
if(!retval.isEmpty()){
return retval;
}
return tr("n/a");
}
QWidget *FileTypeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{
Q_UNUSED(option);
Q_UNUSED(index);
QComboBox *retval = new QComboBox(parent);
retval->addItems(mFiletypeMap.values());
return retval;
}
/* Delegate for Dvd no. */
QString DvdNoDelegate::displayText(const QVariant &value, const QLocale &locale) const{
Q_UNUSED(locale);
int no = value.toInt();
if(no == -1){
return tr("(local)");
}else if(no == -2){
return tr("(origin)");
}
QString retval = QString(tr("#%1")).arg(QString::number(no));
return retval;
}
/* Delegate for size */
QString SizeDelegate::displayText(const QVariant &value, const QLocale &locale) const{
// locale.toString() doesn't work, maybe b/c it's const
Q_UNUSED(locale);
QLocale l;
return l.toString(value.toLongLong());
}
/* Delegate for duration */
QString DurationDelegate::displayText(const QVariant &value, const QLocale &locale) const{
Q_UNUSED(locale);
if(value.toString().contains("x") || value.toString() == "skipped"){
return value.toString();
}
int secs = value.toFloat();
if(secs == 0){
return tr("n/a");
}
Helper::Duration dur(secs);
return dur.toString();
}
/* Delegate for bitrate */
QString BitrateDelegate::displayText(const QVariant &value, const QLocale &locale) const{
Q_UNUSED(locale);
int br = value.toInt() / 1000;
QString retval = QString("%1 kb/s").arg(QString::number(br));
return retval;
}
/* Empty delegate */
QString EmptyDelegate::displayText(const QVariant &value, const QLocale &locale) const{
int i = value.toInt();
if(i < 1){
return QString();
}
return QStyledItemDelegate::displayText(value, locale);
}
|