-
Notifications
You must be signed in to change notification settings - Fork 2
/
chapterinfowidget.cpp
66 lines (57 loc) · 2.62 KB
/
chapterinfowidget.cpp
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
#include "chapterinfowidget.h"
#include "ui_chapterinfowidget.h"
#include "chaptertreemodel.h"
#include <QLineEdit>
#include <QTimeEdit>
ChapterInfoWidget::ChapterInfoWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ChapterInfoWidget)
{
ui->setupUi(this);
}
ChapterInfoWidget::~ChapterInfoWidget()
{
delete ui;
}
void ChapterInfoWidget::setCurrentChapter(ChapterTreeModel *model, const QModelIndex &selectedIndex)
{
m_model = model;
m_currentIndex = selectedIndex;
ui->chapterInfoTable->clear();
ChapterItem * currentItem = static_cast<ChapterItem *>(model->itemFromIndex(m_currentIndex));
if (currentItem->hasChildren()) {
return;
}
ui->chapterInfoTable->setItem(0, 0, new QTableWidgetItem(tr("Title:")));
auto titleEdit = new QLineEdit(currentItem->data(ChapterTitle).toString());
connect(titleEdit, &QLineEdit::textChanged, [currentItem](const QString &text){
currentItem->setItemProperty(ChapterTitle, text);
});
ui->chapterInfoTable->setCellWidget(0, 1, titleEdit);
ui->chapterInfoTable->setItem(1, 0, new QTableWidgetItem(tr("Start Time:")));
auto startTimeWidget = new QTimeEdit;
startTimeWidget->setDisplayFormat("hh:mm:ss.zzz");
startTimeWidget->setTime(QTime::fromMSecsSinceStartOfDay(currentItem->data(ChapterStartTimeMs).toInt()));
connect(startTimeWidget, &QTimeEdit::timeChanged, [currentItem](const QTime &time){
currentItem->setItemProperty(ChapterStartTimeMs, time.msecsSinceStartOfDay());
});
ui->chapterInfoTable->setCellWidget(1, 1, startTimeWidget);
QVariant endTime(currentItem->data(ChapterEndTimeMs));
if (endTime.isNull()) {
ui->chapterInfoTable->setRowCount(2);
} else {
ui->chapterInfoTable->setRowCount(3);
ui->chapterInfoTable->setItem(2, 0, new QTableWidgetItem(tr("End Time:")));
auto endTimeWidget = new QTimeEdit;
endTimeWidget->setDisplayFormat("hh:mm:ss.zzz");
endTimeWidget->setTime(QTime::fromMSecsSinceStartOfDay(currentItem->data(ChapterEndTimeMs).toInt()));
connect(endTimeWidget, &QTimeEdit::timeChanged, [endTimeWidget, currentItem](const QTime &time){
if (currentItem->data(ChapterStartTimeMs).toInt() > time.msecsSinceStartOfDay()) {
endTimeWidget->setTime(QTime::fromMSecsSinceStartOfDay(currentItem->data(ChapterEndTimeMs).toInt()));
return;
}
currentItem->setItemProperty(ChapterEndTimeMs, time.msecsSinceStartOfDay());
});
ui->chapterInfoTable->setCellWidget(2, 1, endTimeWidget);
}
}