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
|
/*
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 <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QTreeView>
#include <QPushButton>
#include <QSettings>
#include <QColor>
#include <QVariant>
#include <QPalette>
#include "filepropertiesdialog.h"
#include "smtreemodel.h"
#include "smtreeitem.h"
#include "helper.h"
FilePropertiesDialog::FilePropertiesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
//main layout
QVBoxLayout *mainLayout = new QVBoxLayout;
//description
mDescriptionLabel = new QLabel(tr("Properties for [none]"));
mDescriptionLabel->setAutoFillBackground(true);
mDescriptionLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
mainLayout->addWidget(mDescriptionLabel);
QSettings s;
QVariant varColor = s.value("ui/alternatecolor");
QColor labelColor = varColor.value<QColor>();
QPalette labelPalette = mDescriptionLabel->palette();
labelPalette.setColor(QPalette::Window, labelColor);
mDescriptionLabel->setPalette(labelPalette);
//the view + model
mModel = new SmTreeModel((QStringList() << QString() << QString()), this);
mView = new QTreeView;
mView->setHeaderHidden(true);
mView->setAlternatingRowColors(true);
mView->setEditTriggers(QAbstractItemView::NoEditTriggers);
mView->setModel(mModel);
mainLayout->addWidget(mView);
//ok button
QHBoxLayout *buttonLayout = new QHBoxLayout;
mClose = new QPushButton(tr("Close"));
connect(mClose, SIGNAL(clicked()), this, SLOT(accept()));
buttonLayout->setAlignment(Qt::AlignCenter);
buttonLayout->addWidget(mClose);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setMinimumWidth(450);
}
void FilePropertiesDialog::setFileName(const QString &fileName){
QString text = QString(tr("Properties for %1")).arg(fileName);
mDescriptionLabel->setText(text);
setWindowTitle(text);
}
void FilePropertiesDialog::setStreamData(const QList<QMap<QString, QString> > &streamData){
SmTreeItem *root = new SmTreeItem(2);
for(int i = 0; i < streamData.size(); ++i){
QList<QVariant> titleData;
QString title = QString(tr("Stream %1")).arg(QString::number(i));
titleData << title << QVariant();
SmTreeItem *titleItem = new SmTreeItem(titleData, root);
root->appendChild(titleItem);
QMap<QString, QString>::const_iterator it = streamData.at(i).constBegin();
while(it != streamData.at(i).constEnd()){
QList<QVariant> itemData;
if(it.key() == "duration" && it.value() != "N/A"){
qint64 duration = it.value().toFloat();
itemData << it.key() << Helper::durationFromSecs(duration);
}else{
itemData << it.key() << it.value();
}
SmTreeItem *item = new SmTreeItem(itemData, titleItem);
titleItem->appendChild(item);
++it;
}
}
mModel->setRoot(root);
mView->expandAll();
mView->resizeColumnToContents(0);
mView->resizeColumnToContents(1);
}
void FilePropertiesDialog::addData(const QString &caption, const QMap<QString, QString> &data){
SmTreeItem *root = new SmTreeItem(*mModel->root());
QList<QVariant> titleData;
titleData << caption << QVariant();
SmTreeItem *titleItem = new SmTreeItem(titleData, root);
root->appendChild(titleItem);
QMap<QString, QString>::const_iterator it = data.constBegin();
while(it != data.constEnd()){
QList<QVariant> itemData;
itemData << it.key() << it.value();
SmTreeItem *item = new SmTreeItem(itemData, titleItem);
titleItem->appendChild(item);
++it;
}
mModel->setRoot(root);
mView->expandAll();
mView->resizeColumnToContents(0);
mView->resizeColumnToContents(1);
}
|