File: sheetview.cpp

package info (click to toggle)
mediainfo 25.04-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,124 kB
  • sloc: cpp: 18,542; objc: 3,089; sh: 1,417; xml: 1,268; python: 319; makefile: 214; perl: 207
file content (148 lines) | stat: -rw-r--r-- 5,054 bytes parent folder | download | duplicates (2)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */

#include "sheetview.h"
#include "ui_sheetview.h"
#include "sheet.h"
#include "mainwindow.h"
#include <QDesktopServices>
#include <QUrl>

#include <ZenLib/Ztring.h>
using namespace ZenLib;
#define wstring2QString(_DATA) \
    QString::fromUtf8(Ztring(_DATA).To_UTF8().c_str())
#define QString2wstring(_DATA) \
    Ztring().From_UTF8(_DATA.toUtf8())

SheetView::SheetView(Core *C, QWidget *parent, QFont* monoFont) :
    QFrame(parent),
    ui(new Ui::SheetView)
{
    this->C=C;

    ui->setupUi(this);

    ui->splitter->setSizes({1, 2});

#if defined(_WIN32) && defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_APP) // Workaround render bug
    QString style = "QComboBox QAbstractItemView { border: 1px solid gray }";
    ui->comboBox->setStyleSheet(style);
#endif

    refreshDisplay();
    ui->tableWidget->selectRow(0);

    QFont font;
    if (monoFont)
        font = *monoFont;
    else {
        font.setFamily("Mono");
        font.setStyleHint(QFont::TypeWriter);
    }
    ui->label->setFont(font);
}

SheetView::~SheetView()
{
    delete ui;
}

void SheetView::refreshDisplay() {
    ui->tableWidget->setRowCount((int)C->Count_Get());
    ui->tableWidget->setColumnCount(Sheet::getSheet()->getNbColumns());
    for(int i=0;i<Sheet::getSheet()->getNbColumns();++i) {
        column c = Sheet::getSheet()->getColumn(i);
        if(ui->tableWidget->horizontalHeaderItem(i))
            ui->tableWidget->horizontalHeaderItem(i)->setText(c.name);
        else
            ui->tableWidget->setHorizontalHeaderItem(i,new QTableWidgetItem(c.name));
        ui->tableWidget->setColumnWidth(i,c.width);
    }
    for (unsigned FilePos=0;FilePos<C->Count_Get();FilePos++) {
        //ui->tableWidget->setItem(FilePos,0,new QTableWidgetItem(wstring2QString(C->Get(FilePos, Stream_General, 0, __T("CompleteName")))));
        for(int i=0;i<Sheet::getSheet()->getNbColumns();++i) {
            column c = Sheet::getSheet()->getColumn(i);
            QString itemText = wstring2QString(C->Get(FilePos,c.stream,0,QString2wstring(c.key)));
            if(c.key=="CompleteName")
                itemText=MainWindow::shortName(C,itemText);
            QTableWidgetItem* twi = new QTableWidgetItem(itemText);
            twi->setData(Qt::UserRole,FilePos);
            ui->tableWidget->setItem(FilePos,i,twi);
        }
    }
    if(Sheet::getSheet()->getAdaptColumns())
        ui->tableWidget->resizeColumnsToContents();
}

void SheetView::adaptColumnsToContent() {
    ui->tableWidget->resizeColumnsToContents();
}

void SheetView::resetColumnsSizes() {
    refreshDisplay();
}

void SheetView::changeEvent(QEvent *e)
{
    QFrame::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void SheetView::on_tableWidget_itemSelectionChanged()
{
    ui->comboBox->clear();
    ui->comboBox->addItem(tr("Summary"),QPoint(-1,-1));
    if(ui->tableWidget->selectedItems().isEmpty())
        return;
    int filePos = ui->tableWidget->selectedItems().at(0)->data(Qt::UserRole).toInt();
    for(int streamKind=0;streamKind<Stream_Max;++streamKind) {
        if(C->Count_Get(filePos,(stream_t)streamKind) && ui->comboBox->count())
            ui->comboBox->insertSeparator(ui->comboBox->count());
        for(unsigned int streamPos=0;streamPos<C->Count_Get(filePos,(stream_t)streamKind);++streamPos) {
            ui->comboBox->addItem(wstring2QString(C->Summary_Get(filePos,(stream_t)streamKind, streamPos)),QPoint(streamKind,streamPos));
        }
    }
}

void SheetView::on_comboBox_currentIndexChanged(int index)
{
    if(ui->tableWidget->selectedItems().isEmpty()) {
        ui->label->setText("no selection");
        ui->toolButton->setEnabled(false);
        return;
    }
    int filePos = ui->tableWidget->selectedItems().at(0)->data(Qt::UserRole).toInt();
    int kind = ui->comboBox->itemData(index).toPoint().x();
    if(kind == -1) {
        QString str="";
        for(int streamKind=0;streamKind<Stream_Max;++streamKind) {
            for(unsigned int streamPos=0;streamPos<C->Count_Get(filePos,(stream_t)streamKind);++streamPos) {
                str.append(wstring2QString(C->Summary_Get(filePos,(stream_t)streamKind, streamPos))+"\n");
            }
        }
        ui->label->setText(str);
        url = "";
    } else {
        int pos = ui->comboBox->itemData(index).toPoint().y();
        ui->label->setText(wstring2QString(C->Inform_Get(filePos, (stream_t)kind, pos)));
        url = wstring2QString(C->Get(filePos, (stream_t)kind, pos, __T("CodecID/Url")));
        if(url.isEmpty())
            url = wstring2QString(C->Get(filePos, (stream_t)kind, pos, __T("Format/Url")));
    }
    ui->toolButton->setEnabled(!url.isEmpty());
}

void SheetView::on_toolButton_clicked()
{
    QDesktopServices::openUrl(QUrl(url));
}