1 #include "HistoryEntryWidget.h"
2 #include "HistoryTableView.h"
3 #include "Components/Session/Session.h"
4 #include "Utils/Utils.h"
5 #include "Utils/Language/Language.h"
6 #include "Utils/Language/LanguageUtils.h"
7 
8 #include <QVBoxLayout>
9 #include <QLabel>
10 
11 struct HistoryEntryWidget::Private
12 {
13 	Session::Timecode timecode;
14 
15 	HistoryTableView*	tableView=nullptr;
16 	QLabel*				trackLabel=nullptr;
17 	QLabel*				dateLabel=nullptr;
18 
PrivateHistoryEntryWidget::Private19 	Private(Session::Timecode timecode) :
20 		timecode(timecode)
21 	{}
22 };
23 
dateToString(const QDateTime & date)24 static QString dateToString(const QDateTime& date)
25 {
26 	QLocale locale = Util::Language::getCurrentLocale();
27 	QString str = locale.toString(date.date());
28 	return str;
29 }
30 
HistoryEntryWidget(Session::Manager * sessionManager,Session::Timecode timecode,QWidget * parent)31 HistoryEntryWidget::HistoryEntryWidget(Session::Manager* sessionManager, Session::Timecode timecode, QWidget* parent) :
32 	Gui::Widget(parent)
33 {
34 	m = Pimpl::make<Private>(timecode);
35 
36 	auto* layout = new QVBoxLayout();
37 	this->setLayout(layout);
38 
39 	m->tableView = new HistoryTableView(sessionManager, timecode, this);
40 
41 	auto* labelLayout = new QHBoxLayout();
42 	{
43 		m->dateLabel = new QLabel(this);
44 		{
45 			QFont font = m->dateLabel->font();
46 			font.setBold(true);
47 			m->dateLabel->setFont(font);
48 			m->dateLabel->setText( dateToString(Util::intToDate(timecode)) );
49 		}
50 
51 		m->trackLabel = new QLabel(this);
52 		{
53 			QFont font = m->trackLabel->font();
54 			font.setBold(true);
55 			m->trackLabel->setFont(font);
56 			m->trackLabel->setText(Lang::getWithNumber(Lang::NrTracks, m->tableView->rows()));
57 		}
58 
59 		labelLayout->addWidget(m->dateLabel);
60 		labelLayout->addItem(new QSpacerItem(100, 1, QSizePolicy::MinimumExpanding, QSizePolicy::Maximum));
61 		labelLayout->addWidget(m->trackLabel);
62 	}
63 
64 	layout->setSpacing(10);
65 	layout->addLayout(labelLayout);
66 	layout->addWidget(m->tableView);
67 
68 	connect(m->tableView, &HistoryTableView::sigRowcountChanged, this, &HistoryEntryWidget::rowcount_changed);
69 }
70 
id() const71 Session::Id HistoryEntryWidget::id() const
72 {
73 	return m->timecode;
74 }
75 
76 HistoryEntryWidget::~HistoryEntryWidget() = default;
77 
languageChanged()78 void HistoryEntryWidget::languageChanged()
79 {
80 	m->dateLabel->setText( dateToString(Util::intToDate(m->timecode)) );
81 	m->trackLabel->setText(Lang::getWithNumber(Lang::NrTracks, m->tableView->rows()));
82 }
83 
rowcount_changed()84 void HistoryEntryWidget::rowcount_changed()
85 {
86 	m->trackLabel->setText(Lang::getWithNumber(Lang::NrTracks, m->tableView->rows()));
87 }
88