track: store height in "units" rather than pixels
Fixes DPI scalability issue if a project ever moved from a display with one DPI to another.
This commit is contained in:
@@ -29,6 +29,10 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
const double TrackOutput::kTrackHeightDefault = 3.0;
|
||||
const double TrackOutput::kTrackHeightMinimum = 1.5;
|
||||
const double TrackOutput::kTrackHeightInterval = 0.5;
|
||||
|
||||
TrackOutput::TrackOutput() :
|
||||
track_type_(Timeline::kTrackTypeNone),
|
||||
index_(-1),
|
||||
@@ -48,7 +52,7 @@ TrackOutput::TrackOutput() :
|
||||
AddInput(muted_input_);
|
||||
|
||||
// Set default height
|
||||
track_height_ = GetDefaultTrackHeight();
|
||||
track_height_ = kTrackHeightDefault;
|
||||
}
|
||||
|
||||
void TrackOutput::set_track_type(const Timeline::TrackType &track_type)
|
||||
@@ -96,21 +100,21 @@ QString TrackOutput::GetTrackName()
|
||||
return track_name_;
|
||||
}
|
||||
|
||||
const int &TrackOutput::GetTrackHeight() const
|
||||
const double &TrackOutput::GetTrackHeight() const
|
||||
{
|
||||
return track_height_;
|
||||
}
|
||||
|
||||
void TrackOutput::SetTrackHeight(const int &height)
|
||||
void TrackOutput::SetTrackHeight(const double &height)
|
||||
{
|
||||
track_height_ = height;
|
||||
emit TrackHeightChanged(track_height_);
|
||||
emit TrackHeightChangedInPixels(GetTrackHeightInPixels());
|
||||
}
|
||||
|
||||
void TrackOutput::LoadInternal(QXmlStreamReader *reader, XMLNodeData &xml_node_data)
|
||||
{
|
||||
if (reader->name() == QStringLiteral("height")) {
|
||||
SetTrackHeight(reader->readElementText().toInt());
|
||||
SetTrackHeight(reader->readElementText().toDouble());
|
||||
} else {
|
||||
Node::LoadInternal(reader, xml_node_data);
|
||||
}
|
||||
@@ -387,21 +391,6 @@ bool TrackOutput::IsTrack() const
|
||||
return true;
|
||||
}
|
||||
|
||||
int TrackOutput::GetTrackHeightIncrement()
|
||||
{
|
||||
return qApp->fontMetrics().height() / 2;
|
||||
}
|
||||
|
||||
int TrackOutput::GetDefaultTrackHeight()
|
||||
{
|
||||
return qApp->fontMetrics().height() * 3;
|
||||
}
|
||||
|
||||
int TrackOutput::GetTrackHeightMinimum()
|
||||
{
|
||||
return qApp->fontMetrics().height() * 3 / 2;
|
||||
}
|
||||
|
||||
QString TrackOutput::GetDefaultTrackName(Timeline::TrackType type, int index)
|
||||
{
|
||||
// Starts tracks at 1 rather than 0
|
||||
|
||||
@@ -48,8 +48,38 @@ public:
|
||||
|
||||
QString GetTrackName();
|
||||
|
||||
const int& GetTrackHeight() const;
|
||||
void SetTrackHeight(const int& height);
|
||||
const double& GetTrackHeight() const;
|
||||
void SetTrackHeight(const double& height);
|
||||
|
||||
int GetTrackHeightInPixels() const
|
||||
{
|
||||
return InternalHeightToPixelHeight(GetTrackHeight());
|
||||
}
|
||||
|
||||
void SetTrackHeightInPixels(int h)
|
||||
{
|
||||
SetTrackHeight(PixelHeightToInternalHeight(h));
|
||||
}
|
||||
|
||||
static int InternalHeightToPixelHeight(double h)
|
||||
{
|
||||
return qRound(h * QFontMetrics(QFont()).height());
|
||||
}
|
||||
|
||||
static double PixelHeightToInternalHeight(int h)
|
||||
{
|
||||
return double(h) / double(QFontMetrics(QFont()).height());
|
||||
}
|
||||
|
||||
static int GetDefaultTrackHeightInPixels()
|
||||
{
|
||||
return InternalHeightToPixelHeight(kTrackHeightDefault);
|
||||
}
|
||||
|
||||
static int GetMinimumTrackHeightInPixels()
|
||||
{
|
||||
return InternalHeightToPixelHeight(kTrackHeightMinimum);
|
||||
}
|
||||
|
||||
virtual void Retranslate() override;
|
||||
|
||||
@@ -172,12 +202,6 @@ public:
|
||||
|
||||
virtual bool IsTrack() const override;
|
||||
|
||||
static int GetTrackHeightIncrement();
|
||||
|
||||
static int GetDefaultTrackHeight();
|
||||
|
||||
static int GetTrackHeightMinimum();
|
||||
|
||||
static QString GetDefaultTrackName(Timeline::TrackType type, int index);
|
||||
|
||||
bool IsMuted() const;
|
||||
@@ -198,6 +222,10 @@ public:
|
||||
return &waveform_lock_;
|
||||
}
|
||||
|
||||
static const double kTrackHeightDefault;
|
||||
static const double kTrackHeightMinimum;
|
||||
static const double kTrackHeightInterval;
|
||||
|
||||
public slots:
|
||||
void SetTrackName(const QString& name);
|
||||
|
||||
@@ -224,7 +252,7 @@ signals:
|
||||
/**
|
||||
* @brief Signal emitted when the height of the track has changed
|
||||
*/
|
||||
void TrackHeightChanged(int height);
|
||||
void TrackHeightChangedInPixels(int pixel_height);
|
||||
|
||||
/**
|
||||
* @brief Signal emitted when the muted setting changes
|
||||
@@ -264,7 +292,7 @@ private:
|
||||
|
||||
rational track_length_;
|
||||
|
||||
int track_height_;
|
||||
double track_height_;
|
||||
|
||||
QString track_name_;
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ void TrackList::TrackConnected(NodeEdgePtr edge)
|
||||
connect(connected_track, &TrackOutput::BlockAdded, this, &TrackList::TrackAddedBlock);
|
||||
connect(connected_track, &TrackOutput::BlockRemoved, this, &TrackList::TrackRemovedBlock);
|
||||
connect(connected_track, &TrackOutput::TrackLengthChanged, this, &TrackList::UpdateTotalLength);
|
||||
connect(connected_track, &TrackOutput::TrackHeightChanged, this, &TrackList::TrackHeightChangedSlot);
|
||||
connect(connected_track, &TrackOutput::TrackHeightChangedInPixels, this, &TrackList::TrackHeightChangedSlot);
|
||||
|
||||
connected_track->set_track_type(type_);
|
||||
|
||||
@@ -233,7 +233,7 @@ void TrackList::TrackDisconnected(NodeEdgePtr edge)
|
||||
disconnect(track, &TrackOutput::BlockAdded, this, &TrackList::TrackAddedBlock);
|
||||
disconnect(track, &TrackOutput::BlockRemoved, this, &TrackList::TrackRemovedBlock);
|
||||
disconnect(track, &TrackOutput::TrackLengthChanged, this, &TrackList::UpdateTotalLength);
|
||||
disconnect(track, &TrackOutput::TrackHeightChanged, this, &TrackList::TrackHeightChangedSlot);
|
||||
disconnect(track, &TrackOutput::TrackHeightChangedInPixels, this, &TrackList::TrackHeightChangedSlot);
|
||||
|
||||
emit TrackListChanged();
|
||||
|
||||
|
||||
@@ -573,7 +573,7 @@ void TimelineWidget::IncreaseTrackHeight()
|
||||
|
||||
// Increase the height of each track by one "unit"
|
||||
foreach (TrackOutput* t, all_tracks) {
|
||||
t->SetTrackHeight(t->GetTrackHeight() + t->GetTrackHeightIncrement());
|
||||
t->SetTrackHeight(t->GetTrackHeight() + TrackOutput::kTrackHeightInterval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,7 +587,7 @@ void TimelineWidget::DecreaseTrackHeight()
|
||||
|
||||
// Decrease the height of each track by one "unit"
|
||||
foreach (TrackOutput* t, all_tracks) {
|
||||
t->SetTrackHeight(qMax(t->GetTrackHeight() - t->GetTrackHeightIncrement(), t->GetTrackHeightMinimum()));
|
||||
t->SetTrackHeight(qMax(t->GetTrackHeight() - TrackOutput::kTrackHeightInterval, TrackOutput::kTrackHeightMinimum));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,9 @@ void TrackView::ConnectTrackList(TrackList *list)
|
||||
foreach (TrackOutput* track, list_->GetTracks()) {
|
||||
TrackViewItem* item = new TrackViewItem(track);
|
||||
items_.append(item);
|
||||
splitter_->Insert(track->Index(), track->GetTrackHeight(), item);
|
||||
splitter_->Insert(track->Index(),
|
||||
track->GetTrackHeightInPixels(),
|
||||
item);
|
||||
}
|
||||
|
||||
connect(list_, &TrackList::TrackHeightChanged, splitter_, &TrackViewSplitter::SetTrackHeight);
|
||||
@@ -120,12 +122,14 @@ void TrackView::ScrollbarRangeChanged(int, int max)
|
||||
|
||||
void TrackView::TrackHeightChanged(int index, int height)
|
||||
{
|
||||
list_->GetTrackAt(index)->SetTrackHeight(height);
|
||||
list_->GetTrackAt(index)->SetTrackHeightInPixels(height);
|
||||
}
|
||||
|
||||
void TrackView::InsertTrack(TrackOutput *track)
|
||||
{
|
||||
splitter_->Insert(track->Index(), track->GetTrackHeight(), new TrackViewItem(track));
|
||||
splitter_->Insert(track->Index(),
|
||||
track->GetTrackHeightInPixels(),
|
||||
new TrackViewItem(track));
|
||||
}
|
||||
|
||||
void TrackView::RemoveTrack(TrackOutput *track)
|
||||
|
||||
@@ -69,7 +69,7 @@ void TrackViewSplitter::HandleReceiver(TrackViewSplitterHandle *h, int diff)
|
||||
int new_ele_sz = old_ele_sz + diff;
|
||||
|
||||
// Limit by track minimum height
|
||||
new_ele_sz = qMax(new_ele_sz, TrackOutput::GetTrackHeightMinimum());
|
||||
new_ele_sz = qMax(new_ele_sz, TrackOutput::GetMinimumTrackHeightInPixels());
|
||||
|
||||
if (alignment_ == Qt::AlignBottom) {
|
||||
ele_id = count() - ele_id - 1;
|
||||
|
||||
@@ -207,7 +207,7 @@ void TimelineView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
int line_y = 0;
|
||||
|
||||
foreach (TrackOutput* track, connected_track_list_->GetTracks()) {
|
||||
line_y += track->GetTrackHeight();
|
||||
line_y += track->GetTrackHeightInPixels();
|
||||
|
||||
// One px gap between tracks
|
||||
line_y++;
|
||||
@@ -375,10 +375,10 @@ int TimelineView::GetTrackY(int track_index) const
|
||||
int TimelineView::GetTrackHeight(int track_index) const
|
||||
{
|
||||
if (!connected_track_list_ || track_index >= connected_track_list_->GetTrackCount()) {
|
||||
return TrackOutput::GetDefaultTrackHeight();
|
||||
return TrackOutput::GetDefaultTrackHeightInPixels();
|
||||
}
|
||||
|
||||
return connected_track_list_->GetTrackAt(track_index)->GetTrackHeight();
|
||||
return connected_track_list_->GetTrackAt(track_index)->GetTrackHeightInPixels();
|
||||
}
|
||||
|
||||
QPoint TimelineView::GetScrollCoordinates() const
|
||||
|
||||
@@ -119,7 +119,7 @@ void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
painter->setPen(Qt::lightGray);
|
||||
}
|
||||
|
||||
int text_top = TrackOutput::GetTrackHeightMinimum() / 2 - painter->fontMetrics().height() / 2;
|
||||
int text_top = TrackOutput::GetMinimumTrackHeightInPixels() / 2 - painter->fontMetrics().height() / 2;
|
||||
QRectF text_rect = rect();
|
||||
text_rect.adjust(0, text_top, 0, 0);
|
||||
painter->drawText(text_rect, Qt::AlignLeft | Qt::AlignTop, block_->GetLabel());
|
||||
|
||||
Reference in New Issue
Block a user