made formal QtUtils class
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
|
||||
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)
|
||||
return fm.width(s);
|
||||
#else
|
||||
@@ -30,4 +30,12 @@ int QFontMetricsWidth(QFontMetrics fm, const QString& s) {
|
||||
#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
|
||||
|
||||
+15
-8
@@ -28,19 +28,26 @@
|
||||
*/
|
||||
|
||||
#include <QFontMetrics>
|
||||
#include <QFrame>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
/**
|
||||
* @brief Retrieves the width of a string according to certain QFontMetrics
|
||||
*
|
||||
* 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
|
||||
* earlier.
|
||||
*/
|
||||
int QFontMetricsWidth(QFontMetrics fm, const QString& s);
|
||||
class QtUtils {
|
||||
public:
|
||||
/**
|
||||
* @brief Retrieves the width of a string according to certain QFontMetrics
|
||||
*
|
||||
* 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
|
||||
* earlier.
|
||||
*/
|
||||
static int QFontMetricsWidth(QFontMetrics fm, const QString& s);
|
||||
|
||||
static QFrame* CreateHorizontalLine();
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ ColorDialog::ColorDialog(ColorManager* color_manager, const ManagedColor& start,
|
||||
wheel_layout->addWidget(color_wheel_);
|
||||
|
||||
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_);
|
||||
|
||||
QWidget* value_area = new QWidget();
|
||||
|
||||
@@ -117,7 +117,7 @@ H264CRFSection::H264CRFSection(QWidget *parent) :
|
||||
layout->addWidget(crf_slider_);
|
||||
|
||||
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->SetMaximum(kMaximumCRF);
|
||||
crf_input->SetValue(kDefaultCRF);
|
||||
|
||||
@@ -124,7 +124,7 @@ void AudioMonitor::paintGL()
|
||||
|
||||
// Create rect where decibel markings will go on the side
|
||||
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);
|
||||
|
||||
// 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;
|
||||
setRect(-half_sz, -half_sz, control_point_size, control_point_size);
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ CurveView::CurveView(QWidget *parent) :
|
||||
setViewportUpdateMode(FullViewportUpdate);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ KeyframeViewItem::KeyframeViewItem(NodeKeyframePtr key, QGraphicsItem *parent) :
|
||||
connect(key.get(), &NodeKeyframe::TimeChanged, this, &KeyframeViewItem::UpdatePos);
|
||||
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;
|
||||
setRect(-half_sz, -half_sz, keyframe_size, keyframe_size);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ NodeParamViewConnectedLabel::NodeParamViewConnectedLabel(NodeInput *input, QWidg
|
||||
input_(input)
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
layout->setSpacing(QFontMetricsWidth(fontMetrics(), QStringLiteral(" ")));
|
||||
layout->setSpacing(QtUtils::QFontMetricsWidth(fontMetrics(), QStringLiteral(" ")));
|
||||
layout->setMargin(0);
|
||||
|
||||
layout->addWidget(new QLabel(tr("Connected to")));
|
||||
|
||||
@@ -133,7 +133,7 @@ int NodeViewItem::DefaultItemHeight()
|
||||
|
||||
int NodeViewItem::DefaultItemWidth()
|
||||
{
|
||||
return QFontMetricsWidth(QFontMetrics(QFont()), "HHHHHHHHHHHH");;
|
||||
return QtUtils::QFontMetricsWidth(QFontMetrics(QFont()), "HHHHHHHHHHHH");;
|
||||
}
|
||||
|
||||
int NodeViewItem::DefaultItemBorder()
|
||||
@@ -316,7 +316,7 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
// Calculate how much space we have for text
|
||||
int item_width = title_bar_rect_.width();
|
||||
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
|
||||
// string fits in the bounds)
|
||||
@@ -326,7 +326,7 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
do {
|
||||
node_label.chop(1);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void ProjectExplorerIconViewItemDelegate::paint(QPainter *painter, const QStyleO
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ void HistogramScope::DrawScope(TexturePtr managed_tex, QVariant pipeline)
|
||||
histogram_start_dim_y);
|
||||
label = QString::number(
|
||||
*it * 100, 'f', 1) + "%";
|
||||
font_x_offset = QFontMetricsWidth(font_metrics, label) + 4;
|
||||
font_x_offset = QtUtils::QFontMetricsWidth(font_metrics, label) + 4;
|
||||
|
||||
p.drawText(
|
||||
histogram_start_dim_x - font_x_offset,
|
||||
|
||||
@@ -111,7 +111,7 @@ void WaveformScope::DrawScope(TexturePtr managed_tex, QVariant pipeline)
|
||||
waveform_end_dim_x,
|
||||
(waveform_dim_y * (i * ire_increment)) + waveform_start_dim_y);
|
||||
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(
|
||||
waveform_start_dim_x - font_x_offset,
|
||||
|
||||
@@ -143,8 +143,8 @@ void SliderBase::SetValue(const QVariant &v)
|
||||
UpdateLabel(value_);
|
||||
}
|
||||
|
||||
void SliderBase::SetDefaultValue(const QVariant &v)
|
||||
{
|
||||
void SliderBase::SetDefaultValue(const QVariant &v)
|
||||
{
|
||||
default_value_ = v;
|
||||
}
|
||||
|
||||
@@ -203,12 +203,12 @@ QString SliderBase::GetFormat() const
|
||||
void SliderBase::RepositionLadder()
|
||||
{
|
||||
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(),
|
||||
label_global_pos.y() + label_->height() / 2 - drag_ladder_->height() / 2);
|
||||
|
||||
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 {
|
||||
ladder_pos.setX(ladder_pos.x() + text_width / 2 - drag_ladder_->width() / 2);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ ImportTool::ImportTool(TimelineWidget *parent) :
|
||||
TimelineTool(parent)
|
||||
{
|
||||
// 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)
|
||||
|
||||
@@ -717,7 +717,7 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event)
|
||||
|
||||
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
|
||||
if (block->rect().width() <= kTrimHandle * 2) {
|
||||
|
||||
@@ -120,7 +120,7 @@ void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
// Linked clips are underlined
|
||||
if (block_->HasLinks()) {
|
||||
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_end = underline_start + QPointF(text_width, 0);
|
||||
|
||||
@@ -41,7 +41,7 @@ SeekableWidget::SeekableWidget(QWidget* parent) :
|
||||
text_height_ = fm.height();
|
||||
|
||||
// Set width of playhead marker
|
||||
playhead_width_ = QFontMetricsWidth(fm, "H");
|
||||
playhead_width_ = QtUtils::QFontMetricsWidth(fm, "H");
|
||||
|
||||
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)
|
||||
// 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
|
||||
UpdateHeight();
|
||||
@@ -209,7 +209,7 @@ void TimeRuler::paintEvent(QPaintEvent *)
|
||||
QRect text_rect;
|
||||
Qt::Alignment text_align;
|
||||
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;
|
||||
|
||||
if (centered_text_) {
|
||||
|
||||
Reference in New Issue
Block a user