This repository has been archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
DockTimeLine.cpp
224 lines (200 loc) · 7.64 KB
/
DockTimeLine.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/***************************************************************************//**
* @brief Thumbnail me 3.0
* Thumbnail me is a user interface for Movie thumbnailer.
* Generate thumbnails from any movie is now easier !
*
* @file DockTimeLine.cpp
* @class DockTimeLine
* Cette classe permet la génération du dock TimeLine.
*
* @author Quentin Rousseau\n
* @note Copyright (C) 2011-2012 Quentin Rousseau\n
* License: GNU General Public License version 2 (GPLv2) - http://www.gnu.org/licenses/gpl-2.0.html\n
* Site web: www.thumbnailme.com\n
* Email: [email protected]
*
* @since 3.0
* @version 3.0
* @date 2011-2012
*******************************************************************************/
#include "DockTimeLine.h"
#include "ThumbnailItem.h"
#include "QTHelper.h"
/**
*@brief Constructeur.
*@param *main_window Fenêtre principale de Thumbnail me.
*/
DockTimeLine::DockTimeLine(QWidget *main_window) : QFrame (main_window)
{
this->setFrameStyle(QFrame::StyledPanel);
this->setStyleSheet("DockTimeLine{border-style: solid;border-width: 1px;border-radius: 10px;border-color: grey;padding: 6px;}");
thumbnailItem = 0;
titleWidgetLabel = new QLabel( this );
titleWidgetLabel->setAlignment(Qt::AlignCenter);
spanSliderLowerLabel = new QLabel( this );
spanSliderUpperLabel = new QLabel( this );
spanSlider = new QxtSpanSlider(Qt::Horizontal,this);
spanSlider->setHandleMovementMode(QxtSpanSlider::NoOverlapping);
spanSliderDuration = new QLabel( this );
QGridLayout *layoutSpanSlider = new QGridLayout;
layoutSpanSlider->addWidget(titleWidgetLabel,0,0,1,2);
layoutSpanSlider->addWidget(QtHelper::addHSeparator(),1,0,1,2);
layoutSpanSlider->addWidget(spanSliderLowerLabel,2,0);
layoutSpanSlider->addWidget(spanSliderUpperLabel,2,1,Qt::AlignRight);
layoutSpanSlider->addWidget(spanSlider,3,0,1,2);
layoutSpanSlider->addWidget(spanSliderDuration,4,0,1,2,Qt::AlignHCenter);
/*Connections*/
connect(spanSlider, SIGNAL(lowerPositionChanged(int)), this , SLOT(updateLowerLabel(int)));
connect(spanSlider, SIGNAL(upperPositionChanged(int)), this , SLOT(updateUpperLabel(int)));
this->setLayout(layoutSpanSlider);
this->setDisabled(true);
this->retranslate();
}
/**
*@brief Destructeur.
*/
DockTimeLine::~DockTimeLine()
{
}
/**
*@brief Retourne le Thumbnail Item courant associé à la timeline.
*@return ThumbnailItem* - Thumbnail Item.
*/
ThumbnailItem * DockTimeLine::getCurrentItem()
{
return thumbnailItem;
}
/**
*@brief Modifie la timeline selon les données de l'item.
*@param item Item sélectionné.
*/
void DockTimeLine::update(QListWidgetItem *item)
{
this->thumbnailItem = 0;
this->thumbnailItem = static_cast<ThumbnailItem *> (item);
/*
Hack - Si l'utilisateur clique trop vite sur l'item
ou Service Windows Audio désactivé
*/
if(this->thumbnailItem->getTotalDuration().isNull())
{
this->setDisabled(true); this->retranslate(); return;
}
else this->setDisabled(false);
/*****************************************************/
if (!this->thumbnailItem->isReadable())
{
this->setDisabled(true);
spanSlider->setLowerPosition(0);
spanSlider->setUpperPosition(0);
}
else
{
//update
this->setEnabled(true);
spanSlider->setRange(0,-thumbnailItem->getTotalDuration().secsTo(QTime()));
if(thumbnailItem->getLowerTime().isNull())
{
spanSlider->setLowerPosition(0);
thumbnailItem->setLowerTime(QTime(0,0));
}
else
{
spanSlider->setLowerPosition(-thumbnailItem->getLowerTime().secsTo(QTime()));
}
if(thumbnailItem->getUpperTime().isNull())
{
QTime t;
thumbnailItem->setUpperTime(t.addSecs(-thumbnailItem->getTotalDuration().secsTo(QTime())));
spanSlider->setUpperPosition(-thumbnailItem->getTotalDuration().secsTo(QTime()));
}
else
{
spanSlider->setUpperPosition(-thumbnailItem->getUpperTime().secsTo(QTime()));
}
}
this->retranslate();
}
/**
*@brief Traitement des erreurs.
*@param error Type de l'erreur.
*/
void DockTimeLine::manageErrors(QMediaPlayer::Error error)
{
this->setDisabled(true);
titleWidgetLabel->setText( "<b>" + tr( "TimeLine (Not available) | Media isn't fully supported" ) + "</b>");
}
/**
*@brief Update Lower QLabel.
*@param lower Valeur de "lower" du QxtSpanSlider.
*/
void DockTimeLine::updateLowerLabel(int lower)
{
lowerQTime = QTime(0,0);
thumbnailItem->setLowerTime(lowerQTime.addSecs(lower));
spanSliderLowerLabel->setText(tr( "From" ) + " : " + QString("%1").arg(thumbnailItem->getLowerTime().toString(Qt::TextDate)));
}
/**
*@brief Update Upper QLabel.
*@param upper Valeur de "upper" du QxtSpanSlider.
*/
void DockTimeLine::updateUpperLabel(int upper)
{
upperQTime = QTime(0,0);
thumbnailItem->setUpperTime(upperQTime.addSecs(upper));
spanSliderUpperLabel->setText(tr( "To" ) + " : " + QString("%1").arg(thumbnailItem->getUpperTime().toString(Qt::TextDate)));
}
/**
*@brief ChangeEvent.
*@param *event Evenement.
*/
void DockTimeLine::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
retranslate();
QWidget::changeEvent(event);
}
/**
*@brief Reset la timeline.
*/
void DockTimeLine::clear()
{
this->thumbnailItem = 0;
this->setDisabled(true);
this->spanSlider->setSpan(0,0);
this->retranslate();
}
/**
*@brief Fonction de traduction dynamique.
*/
void DockTimeLine::retranslate()
{
if(thumbnailItem && thumbnailItem->isReadable() && thumbnailItem->getLowerTime().isNull() && thumbnailItem->getUpperTime().isNull())
{
titleWidgetLabel->setText( "<b>" + tr( "TimeLine" ) + "</b>" );
spanSliderLowerLabel->setText( tr( "From" ) + " : " + QTime(0,0).toString(Qt::TextDate) );
spanSliderUpperLabel->setText( tr( "To" ) + " : " + thumbnailItem->getTotalDuration().toString(Qt::TextDate) );
spanSliderDuration->setText( tr( "Total duration" ) + ": " + thumbnailItem->getTotalDuration().toString(Qt::TextDate) );
}
else if(thumbnailItem && thumbnailItem->isReadable() && !thumbnailItem->getLowerTime().isNull() && !thumbnailItem->getUpperTime().isNull())
{
titleWidgetLabel->setText( "<b>" + tr( "TimeLine" ) + "</b>" );
spanSliderLowerLabel->setText( tr( "From" ) + " : " + thumbnailItem->getLowerTime().toString(Qt::TextDate) );
spanSliderUpperLabel->setText( tr( "To" ) + " : " + thumbnailItem->getUpperTime().toString(Qt::TextDate) );
spanSliderDuration->setText( tr( "Total duration" ) + " : " + thumbnailItem->getTotalDuration().toString(Qt::TextDate) );
}
else if(thumbnailItem && !thumbnailItem->isReadable())
{
titleWidgetLabel->setText( "<b>" + tr( "TimeLine (Not available) | Media isn't fully supported" ) + "</b>" );
spanSliderLowerLabel->setText( tr( "From" ) + " : " + QTime(0,0).toString(Qt::TextDate) );
spanSliderUpperLabel->setText( tr( "To" ) + " : " + QTime(0,0).toString(Qt::TextDate) );
spanSliderDuration->setText( tr( "Total duration" ) + " : " + QTime(0,0).toString(Qt::TextDate) );
}
else
{
titleWidgetLabel->setText( "<b>" + tr( "TimeLine" ) + "</b>" );
spanSliderLowerLabel->setText( tr( "From" ) + " : " + QTime(0,0).toString(Qt::TextDate) );
spanSliderUpperLabel->setText( tr( "To" ) + " : " + QTime(0,0).toString(Qt::TextDate) );
spanSliderDuration->setText( tr( "Total duration" ) + " : " + QTime(0,0).toString(Qt::TextDate) );
}
}