made formal QtUtils class
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
OLIVE_NAMESPACE_ENTER
|
OLIVE_NAMESPACE_ENTER
|
||||||
|
|
||||||
int QFontMetricsWidth(QFontMetrics fm, const QString& s) {
|
int QtUtils::QFontMetricsWidth(QFontMetrics fm, const QString& s) {
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
return fm.width(s);
|
return fm.width(s);
|
||||||
#else
|
#else
|
||||||
@@ -30,4 +30,12 @@ int QFontMetricsWidth(QFontMetrics fm, const QString& s) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFrame *QtUtils::CreateHorizontalLine()
|
||||||
|
{
|
||||||
|
QFrame* horizontal_line = new QFrame();
|
||||||
|
horizontal_line->setFrameShape(QFrame::HLine);
|
||||||
|
horizontal_line->setFrameShadow(QFrame::Sunken);
|
||||||
|
return horizontal_line;
|
||||||
|
}
|
||||||
|
|
||||||
OLIVE_NAMESPACE_EXIT
|
OLIVE_NAMESPACE_EXIT
|
||||||
|
|||||||
+15
-8
@@ -28,19 +28,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
#include <QFrame>
|
||||||
|
|
||||||
#include "common/define.h"
|
#include "common/define.h"
|
||||||
|
|
||||||
OLIVE_NAMESPACE_ENTER
|
OLIVE_NAMESPACE_ENTER
|
||||||
|
|
||||||
/**
|
class QtUtils {
|
||||||
* @brief Retrieves the width of a string according to certain QFontMetrics
|
public:
|
||||||
*
|
/**
|
||||||
* QFontMetrics::width() has been deprecatd in favor of QFontMetrics::horizontalAdvance(), but the
|
* @brief Retrieves the width of a string according to certain QFontMetrics
|
||||||
* latter was only introduced in 5.11+. This function wraps the latter for 5.11+ and the former for
|
*
|
||||||
* earlier.
|
* QFontMetrics::width() has been deprecatd in favor of QFontMetrics::horizontalAdvance(), but the
|
||||||
*/
|
* latter was only introduced in 5.11+. This function wraps the latter for 5.11+ and the former for
|
||||||
int QFontMetricsWidth(QFontMetrics fm, const QString& s);
|
* earlier.
|
||||||
|
*/
|
||||||
|
static int QFontMetricsWidth(QFontMetrics fm, const QString& s);
|
||||||
|
|
||||||
|
static QFrame* CreateHorizontalLine();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
OLIVE_NAMESPACE_EXIT
|
OLIVE_NAMESPACE_EXIT
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ ColorDialog::ColorDialog(ColorManager* color_manager, const ManagedColor& start,
|
|||||||
wheel_layout->addWidget(color_wheel_);
|
wheel_layout->addWidget(color_wheel_);
|
||||||
|
|
||||||
hsv_value_gradient_ = new ColorGradientWidget(Qt::Vertical);
|
hsv_value_gradient_ = new ColorGradientWidget(Qt::Vertical);
|
||||||
hsv_value_gradient_->setFixedWidth(QFontMetricsWidth(fontMetrics(), QStringLiteral("HHH")));
|
hsv_value_gradient_->setFixedWidth(QtUtils::QFontMetricsWidth(fontMetrics(), QStringLiteral("HHH")));
|
||||||
wheel_layout->addWidget(hsv_value_gradient_);
|
wheel_layout->addWidget(hsv_value_gradient_);
|
||||||
|
|
||||||
QWidget* value_area = new QWidget();
|
QWidget* value_area = new QWidget();
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ H264CRFSection::H264CRFSection(QWidget *parent) :
|
|||||||
layout->addWidget(crf_slider_);
|
layout->addWidget(crf_slider_);
|
||||||
|
|
||||||
IntegerSlider* crf_input = new IntegerSlider();
|
IntegerSlider* crf_input = new IntegerSlider();
|
||||||
crf_input->setMaximumWidth(QFontMetricsWidth(crf_input->fontMetrics(), QStringLiteral("HHHH")));
|
crf_input->setMaximumWidth(QtUtils::QFontMetricsWidth(crf_input->fontMetrics(), QStringLiteral("HHHH")));
|
||||||
crf_input->SetMinimum(kMinimumCRF);
|
crf_input->SetMinimum(kMinimumCRF);
|
||||||
crf_input->SetMaximum(kMaximumCRF);
|
crf_input->SetMaximum(kMaximumCRF);
|
||||||
crf_input->SetValue(kDefaultCRF);
|
crf_input->SetValue(kDefaultCRF);
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ void AudioMonitor::paintGL()
|
|||||||
|
|
||||||
// Create rect where decibel markings will go on the side
|
// Create rect where decibel markings will go on the side
|
||||||
QRect db_labels_rect = rect();
|
QRect db_labels_rect = rect();
|
||||||
db_labels_rect.setWidth(QFontMetricsWidth(p.fontMetrics(), "-00"));
|
db_labels_rect.setWidth(QtUtils::QFontMetricsWidth(p.fontMetrics(), "-00"));
|
||||||
db_labels_rect.adjust(0, font_height, 0, 0);
|
db_labels_rect.adjust(0, font_height, 0, 0);
|
||||||
|
|
||||||
// Determine rect where the main meter will go
|
// Determine rect where the main meter will go
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ BezierControlPointItem::BezierControlPointItem(NodeKeyframePtr key, NodeKeyframe
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int control_point_size = QFontMetricsWidth(qApp->fontMetrics(), "o");
|
int control_point_size = QtUtils::QFontMetricsWidth(qApp->fontMetrics(), "o");
|
||||||
int half_sz = control_point_size / 2;
|
int half_sz = control_point_size / 2;
|
||||||
setRect(-half_sz, -half_sz, control_point_size, control_point_size);
|
setRect(-half_sz, -half_sz, control_point_size, control_point_size);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ CurveView::CurveView(QWidget *parent) :
|
|||||||
setViewportUpdateMode(FullViewportUpdate);
|
setViewportUpdateMode(FullViewportUpdate);
|
||||||
SetYAxisEnabled(true);
|
SetYAxisEnabled(true);
|
||||||
|
|
||||||
text_padding_ = QFontMetricsWidth(fontMetrics(), QStringLiteral("i"));
|
text_padding_ = QtUtils::QFontMetricsWidth(fontMetrics(), QStringLiteral("i"));
|
||||||
|
|
||||||
minimum_grid_space_ = QFontMetricsWidth(fontMetrics(), QStringLiteral("00000"));
|
minimum_grid_space_ = QtUtils::QFontMetricsWidth(fontMetrics(), QStringLiteral("00000"));
|
||||||
|
|
||||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &CurveView::SelectionChanged);
|
connect(scene(), &QGraphicsScene::selectionChanged, this, &CurveView::SelectionChanged);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ KeyframeViewItem::KeyframeViewItem(NodeKeyframePtr key, QGraphicsItem *parent) :
|
|||||||
connect(key.get(), &NodeKeyframe::TimeChanged, this, &KeyframeViewItem::UpdatePos);
|
connect(key.get(), &NodeKeyframe::TimeChanged, this, &KeyframeViewItem::UpdatePos);
|
||||||
connect(key.get(), &NodeKeyframe::TypeChanged, this, &KeyframeViewItem::Redraw);
|
connect(key.get(), &NodeKeyframe::TypeChanged, this, &KeyframeViewItem::Redraw);
|
||||||
|
|
||||||
int keyframe_size = QFontMetricsWidth(qApp->fontMetrics(), "Oi");
|
int keyframe_size = QtUtils::QFontMetricsWidth(qApp->fontMetrics(), "Oi");
|
||||||
int half_sz = keyframe_size/2;
|
int half_sz = keyframe_size/2;
|
||||||
setRect(-half_sz, -half_sz, keyframe_size, keyframe_size);
|
setRect(-half_sz, -half_sz, keyframe_size, keyframe_size);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ NodeParamViewConnectedLabel::NodeParamViewConnectedLabel(NodeInput *input, QWidg
|
|||||||
input_(input)
|
input_(input)
|
||||||
{
|
{
|
||||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||||
layout->setSpacing(QFontMetricsWidth(fontMetrics(), QStringLiteral(" ")));
|
layout->setSpacing(QtUtils::QFontMetricsWidth(fontMetrics(), QStringLiteral(" ")));
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
|
|
||||||
layout->addWidget(new QLabel(tr("Connected to")));
|
layout->addWidget(new QLabel(tr("Connected to")));
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ int NodeViewItem::DefaultItemHeight()
|
|||||||
|
|
||||||
int NodeViewItem::DefaultItemWidth()
|
int NodeViewItem::DefaultItemWidth()
|
||||||
{
|
{
|
||||||
return QFontMetricsWidth(QFontMetrics(QFont()), "HHHHHHHHHHHH");;
|
return QtUtils::QFontMetricsWidth(QFontMetrics(QFont()), "HHHHHHHHHHHH");;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NodeViewItem::DefaultItemBorder()
|
int NodeViewItem::DefaultItemBorder()
|
||||||
@@ -316,7 +316,7 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||||||
// Calculate how much space we have for text
|
// Calculate how much space we have for text
|
||||||
int item_width = title_bar_rect_.width();
|
int item_width = title_bar_rect_.width();
|
||||||
int max_text_width = item_width - DefaultTextPadding() * 2 - icon_full_size;
|
int max_text_width = item_width - DefaultTextPadding() * 2 - icon_full_size;
|
||||||
int label_width = QFontMetricsWidth(fm, node_label);
|
int label_width = QtUtils::QFontMetricsWidth(fm, node_label);
|
||||||
|
|
||||||
// Concatenate text if necessary (adds a "..." to the end and removes characters until the
|
// Concatenate text if necessary (adds a "..." to the end and removes characters until the
|
||||||
// string fits in the bounds)
|
// string fits in the bounds)
|
||||||
@@ -326,7 +326,7 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||||||
do {
|
do {
|
||||||
node_label.chop(1);
|
node_label.chop(1);
|
||||||
concatenated = QCoreApplication::translate("NodeViewItem", "%1...").arg(node_label);
|
concatenated = QCoreApplication::translate("NodeViewItem", "%1...").arg(node_label);
|
||||||
} while ((label_width = QFontMetricsWidth(fm, concatenated)) > max_text_width);
|
} while ((label_width = QtUtils::QFontMetricsWidth(fm, concatenated)) > max_text_width);
|
||||||
|
|
||||||
node_label = concatenated;
|
node_label = concatenated;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void ProjectExplorerIconViewItemDelegate::paint(QPainter *painter, const QStyleO
|
|||||||
|
|
||||||
QString duration_str = index.data(Qt::UserRole).toString();
|
QString duration_str = index.data(Qt::UserRole).toString();
|
||||||
|
|
||||||
int timecode_width = QFontMetricsWidth(fm, duration_str);
|
int timecode_width = QtUtils::QFontMetricsWidth(fm, duration_str);
|
||||||
|
|
||||||
int max_name_width = option.rect.width();
|
int max_name_width = option.rect.width();
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ void HistogramScope::DrawScope(TexturePtr managed_tex, QVariant pipeline)
|
|||||||
histogram_start_dim_y);
|
histogram_start_dim_y);
|
||||||
label = QString::number(
|
label = QString::number(
|
||||||
*it * 100, 'f', 1) + "%";
|
*it * 100, 'f', 1) + "%";
|
||||||
font_x_offset = QFontMetricsWidth(font_metrics, label) + 4;
|
font_x_offset = QtUtils::QFontMetricsWidth(font_metrics, label) + 4;
|
||||||
|
|
||||||
p.drawText(
|
p.drawText(
|
||||||
histogram_start_dim_x - font_x_offset,
|
histogram_start_dim_x - font_x_offset,
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ void WaveformScope::DrawScope(TexturePtr managed_tex, QVariant pipeline)
|
|||||||
waveform_end_dim_x,
|
waveform_end_dim_x,
|
||||||
(waveform_dim_y * (i * ire_increment)) + waveform_start_dim_y);
|
(waveform_dim_y * (i * ire_increment)) + waveform_start_dim_y);
|
||||||
label = QString::number(1.0 - (i * ire_increment), 'f', 1);
|
label = QString::number(1.0 - (i * ire_increment), 'f', 1);
|
||||||
font_x_offset = QFontMetricsWidth(font_metrics, label) + 4;
|
font_x_offset = QtUtils::QFontMetricsWidth(font_metrics, label) + 4;
|
||||||
|
|
||||||
p.drawText(
|
p.drawText(
|
||||||
waveform_start_dim_x - font_x_offset,
|
waveform_start_dim_x - font_x_offset,
|
||||||
|
|||||||
@@ -203,12 +203,12 @@ QString SliderBase::GetFormat() const
|
|||||||
void SliderBase::RepositionLadder()
|
void SliderBase::RepositionLadder()
|
||||||
{
|
{
|
||||||
QPoint label_global_pos = label_->mapToGlobal(label_->pos());
|
QPoint label_global_pos = label_->mapToGlobal(label_->pos());
|
||||||
int text_width = QFontMetricsWidth(label_->fontMetrics(), label_->text());
|
int text_width = QtUtils::QFontMetricsWidth(label_->fontMetrics(), label_->text());
|
||||||
QPoint ladder_pos(label_global_pos.x(),
|
QPoint ladder_pos(label_global_pos.x(),
|
||||||
label_global_pos.y() + label_->height() / 2 - drag_ladder_->height() / 2);
|
label_global_pos.y() + label_->height() / 2 - drag_ladder_->height() / 2);
|
||||||
|
|
||||||
if (ladder_element_count_ > 0) {
|
if (ladder_element_count_ > 0) {
|
||||||
ladder_pos.setX(ladder_pos.x() + text_width + QFontMetricsWidth(label_->fontMetrics(), QStringLiteral("H")));
|
ladder_pos.setX(ladder_pos.x() + text_width + QtUtils::QFontMetricsWidth(label_->fontMetrics(), QStringLiteral("H")));
|
||||||
} else {
|
} else {
|
||||||
ladder_pos.setX(ladder_pos.x() + text_width / 2 - drag_ladder_->width() / 2);
|
ladder_pos.setX(ladder_pos.x() + text_width / 2 - drag_ladder_->width() / 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ ImportTool::ImportTool(TimelineWidget *parent) :
|
|||||||
TimelineTool(parent)
|
TimelineTool(parent)
|
||||||
{
|
{
|
||||||
// Calculate width used for importing to give ghosts a slight lead-in so the ghosts aren't right on the cursor
|
// Calculate width used for importing to give ghosts a slight lead-in so the ghosts aren't right on the cursor
|
||||||
import_pre_buffer_ = QFontMetricsWidth(parent->fontMetrics(), "HHHHHHHH");
|
import_pre_buffer_ = QtUtils::QFontMetricsWidth(parent->fontMetrics(), "HHHHHHHH");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportTool::DragEnter(TimelineViewMouseEvent *event)
|
void ImportTool::DragEnter(TimelineViewMouseEvent *event)
|
||||||
|
|||||||
@@ -717,7 +717,7 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event)
|
|||||||
|
|
||||||
Timeline::MovementMode PointerTool::IsCursorInTrimHandle(TimelineViewBlockItem *block, qreal cursor_x)
|
Timeline::MovementMode PointerTool::IsCursorInTrimHandle(TimelineViewBlockItem *block, qreal cursor_x)
|
||||||
{
|
{
|
||||||
double kTrimHandle = QFontMetricsWidth(parent()->fontMetrics(), "H");
|
double kTrimHandle = QtUtils::QFontMetricsWidth(parent()->fontMetrics(), "H");
|
||||||
|
|
||||||
// Block is too narrow, no trimming allowed
|
// Block is too narrow, no trimming allowed
|
||||||
if (block->rect().width() <= kTrimHandle * 2) {
|
if (block->rect().width() <= kTrimHandle * 2) {
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
|||||||
// Linked clips are underlined
|
// Linked clips are underlined
|
||||||
if (block_->HasLinks()) {
|
if (block_->HasLinks()) {
|
||||||
QFontMetrics fm = painter->fontMetrics();
|
QFontMetrics fm = painter->fontMetrics();
|
||||||
int text_width = qMin(qRound(rect().width()), QFontMetricsWidth(fm, block_->GetLabel()));
|
int text_width = qMin(qRound(rect().width()), QtUtils::QFontMetricsWidth(fm, block_->GetLabel()));
|
||||||
|
|
||||||
QPointF underline_start = rect().topLeft() + QPointF(0, text_top + fm.height());
|
QPointF underline_start = rect().topLeft() + QPointF(0, text_top + fm.height());
|
||||||
QPointF underline_end = underline_start + QPointF(text_width, 0);
|
QPointF underline_end = underline_start + QPointF(text_width, 0);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ SeekableWidget::SeekableWidget(QWidget* parent) :
|
|||||||
text_height_ = fm.height();
|
text_height_ = fm.height();
|
||||||
|
|
||||||
// Set width of playhead marker
|
// Set width of playhead marker
|
||||||
playhead_width_ = QFontMetricsWidth(fm, "H");
|
playhead_width_ = QtUtils::QFontMetricsWidth(fm, "H");
|
||||||
|
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* pare
|
|||||||
|
|
||||||
// Get the "minimum" space allowed between two line markers on the ruler (in screen pixels)
|
// Get the "minimum" space allowed between two line markers on the ruler (in screen pixels)
|
||||||
// Mediocre but reliable way of scaling UI objects by font/DPI size
|
// Mediocre but reliable way of scaling UI objects by font/DPI size
|
||||||
minimum_gap_between_lines_ = QFontMetricsWidth(fm, "H");
|
minimum_gap_between_lines_ = QtUtils::QFontMetricsWidth(fm, "H");
|
||||||
|
|
||||||
// Text visibility affects height, so we set that here
|
// Text visibility affects height, so we set that here
|
||||||
UpdateHeight();
|
UpdateHeight();
|
||||||
@@ -209,7 +209,7 @@ void TimeRuler::paintEvent(QPaintEvent *)
|
|||||||
QRect text_rect;
|
QRect text_rect;
|
||||||
Qt::Alignment text_align;
|
Qt::Alignment text_align;
|
||||||
QString timecode_str = Timecode::timestamp_to_timecode(ScreenToUnit(i), timebase(), Core::instance()->GetTimecodeDisplay());
|
QString timecode_str = Timecode::timestamp_to_timecode(ScreenToUnit(i), timebase(), Core::instance()->GetTimecodeDisplay());
|
||||||
int timecode_width = QFontMetricsWidth(fm, timecode_str);
|
int timecode_width = QtUtils::QFontMetricsWidth(fm, timecode_str);
|
||||||
int timecode_left;
|
int timecode_left;
|
||||||
|
|
||||||
if (centered_text_) {
|
if (centered_text_) {
|
||||||
|
|||||||
Reference in New Issue
Block a user