Commit 62a49280 authored by Julius Künzel's avatar Julius Künzel
Browse files

[Code Gardening] Use qRound instead of +0.5

Why? Read https://releases.llvm.org/11.0.0/tools/clang/tools/extra/docs/
clang-tidy/checks/bugprone-incorrect-roundings.html
parent 7761a558
Pipeline #142553 passed with stage
in 5 minutes and 57 seconds
......@@ -765,11 +765,11 @@ QVariant AssetParameterModel::parseAttribute(const ObjectId &owner, const QStrin
if (sourceDar > pCore->getCurrentDar()) {
// Fit to width
double factor = double(width) / frameSize.width() * pCore->getCurrentSar();
contentHeight = int(height * factor + 0.5);
contentHeight = qRound(height * factor);
} else {
// Fit to height
double factor = double(height) / frameSize.height();
contentWidth =int(frameSize.width() / pCore->getCurrentSar() * factor + 0.5);
contentWidth = qRound(frameSize.width() / pCore->getCurrentSar() * factor);
}
// Center
content = QString("%1 %2 %3 %4").arg((width - contentWidth) / 2).arg((height - contentHeight) / 2).arg(contentWidth).arg(contentHeight);
......
......@@ -389,8 +389,7 @@ template <typename CurveWidget_t> void CurveParamWidget<CurveWidget_t>::slotRefr
{
if (m_model->data(m_index, AssetParameterModel::TypeRole).template value<ParamType>() == ParamType::Curve) {
QList<QPointF> points;
// Rounding gives really weird results. (int) (10 * 0.3) gives 2! So for now, add 0.5 to get correct result
int number = int(m_model->data(m_index, AssetParameterModel::Enum3Role).toDouble() * 10 + 0.5);
int number = qRound(m_model->data(m_index, AssetParameterModel::Enum3Role).toDouble() * 10);
int start = m_model->data(m_index, AssetParameterModel::MinRole).toInt();
// for the curve, inpoints are numbered: 6, 8, 10, 12, 14
// outpoints, 7, 9, 11, 13,15 so we need to deduce these enums
......
......@@ -890,7 +890,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int trackId, int
}
warpProducer.reset(new Mlt::Producer(*originalProducer()->profile(), url.toUtf8().constData()));
int original_length = originalProducer()->get_length();
int updated_length = int(original_length / std::abs(speed) + 0.5);
int updated_length = qRound(original_length / std::abs(speed));
warpProducer->set("length", updated_length);
if (!original_resource.isEmpty()) {
// Don't lose original resource for placeholder clips
......@@ -908,7 +908,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int trackId, int
//if the producer has a "time-to-live" (frame duration) we need to scale it according to the speed
int ttl = originalProducer()->get_int("ttl");
if(ttl > 0) {
int new_ttl = ttl / std::abs(speed) + 0.5;
int new_ttl = qRound(ttl / std::abs(speed));
warpProducer->set("ttl", std::max(new_ttl, 1));
}
......
......@@ -517,7 +517,7 @@ double Core::getCurrentFps() const
QSize Core::getCurrentFrameDisplaySize() const
{
return {int(getCurrentProfile()->height() * getCurrentDar() + 0.5), getCurrentProfile()->height()};
return {qRound(getCurrentProfile()->height() * getCurrentDar()), getCurrentProfile()->height()};
}
QSize Core::getCurrentFrameSize() const
......@@ -941,7 +941,7 @@ Mlt::Profile *Core::thumbProfile()
m_thumbProfile = std::make_unique<Mlt::Profile>(m_currentProfile.toStdString().c_str());
double factor = 144. / m_thumbProfile->height();
m_thumbProfile->set_height(144);
int width = int(m_thumbProfile->width() * factor + 0.5);
int width = qRound(m_thumbProfile->width() * factor);
if (width % 2 > 0) {
width ++;
}
......
......@@ -938,13 +938,13 @@ void KdenliveSettingsDialog::updateSettings()
if (m_configTimeline.kcfg_trackheight->value() == 0) {
QFont ft = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
// Default unit for timeline.qml objects size
int baseUnit = qMax(28, int(QFontInfo(ft).pixelSize() * 1.8 + 0.5));
int baseUnit = qMax(28, qRound(QFontInfo(ft).pixelSize() * 1.8));
int trackHeight = qMax(50, int(2.2 * baseUnit + 6));
m_configTimeline.kcfg_trackheight->setValue(trackHeight);
} else if (m_configTimeline.kcfg_trackheight->value() != KdenliveSettings::trackheight()) {
QFont ft = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
// Default unit for timeline.qml objects size
int baseUnit = qMax(28, int(QFontInfo(ft).pixelSize() * 1.8 + 0.5));
int baseUnit = qMax(28, qRound(QFontInfo(ft).pixelSize() * 1.8));
if (m_configTimeline.kcfg_trackheight->value() < baseUnit) {
m_configTimeline.kcfg_trackheight->setValue(baseUnit);
}
......
......@@ -23,7 +23,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
CacheTask::CacheTask(const ObjectId &owner, int thumbsCount, int in, int out, QObject* object)
: AbstractTask(owner, AbstractTask::CACHEJOB, object)
, m_fullWidth(qFuzzyCompare(pCore->getCurrentSar(), 1.0) ? 0 : int(pCore->thumbProfile()->height() * pCore->getCurrentDar() + 0.5))
, m_fullWidth(qFuzzyCompare(pCore->getCurrentSar(), 1.0) ? 0 : qRound(pCore->thumbProfile()->height() * pCore->getCurrentDar()))
, m_thumbsCount(thumbsCount)
, m_in(in)
, m_out(out)
......
......@@ -273,7 +273,7 @@ void ClipLoadTask::generateThumbnail(std::shared_ptr<ProjectClip>binClip, std::s
if ((frame != nullptr) && frame->is_valid()) {
int imageHeight(pCore->thumbProfile()->height());
int imageWidth(pCore->thumbProfile()->width());
int fullWidth(int(imageHeight * pCore->getCurrentDar() + 0.5));
int fullWidth(qRound(imageHeight * pCore->getCurrentDar()));
QImage result = KThumb::getFrame(frame.data(), imageWidth, imageHeight, fullWidth);
if (result.isNull() && !m_isCanceled) {
qDebug() << "+++++\nINVALID RESULT IMAGE\n++++++++++++++";
......
......@@ -1946,7 +1946,7 @@ bool MainWindow::readOptions()
}
QFont ft = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
// Default unit for timeline.qml objects size
int baseUnit = qMax(28, int(QFontInfo(ft).pixelSize() * 1.8 + 0.5));
int baseUnit = qMax(28, qRound(QFontInfo(ft).pixelSize() * 1.8));
if (KdenliveSettings::trackheight() == 0) {
int trackHeight = qMax(50, int(2.2 * baseUnit + 6));
KdenliveSettings::setTrackheight(trackHeight);
......
......@@ -511,7 +511,7 @@ void GLWidget::paintGL()
f->glDisable(GL_BLEND);
f->glDisable(GL_DEPTH_TEST);
f->glDepthMask(GL_FALSE);
f->glViewport(0, int(m_displayRulerHeight * devicePixelRatio() * 0.5 + 0.5), int(width), int(height));
f->glViewport(0, qRound(m_displayRulerHeight * devicePixelRatio() * 0.5), int(width), int(height));
check_error(f);
f->glClearColor(float(m_bgColor.redF()), float(m_bgColor.greenF()), float(m_bgColor.blueF()), 0);
f->glClear(GL_COLOR_BUFFER_BIT);
......
......@@ -80,6 +80,6 @@ QImage ThumbnailProvider::makeThumbnail(const std::shared_ptr<Mlt::Producer> &pr
// TODO: cache these values ?
int imageHeight = pCore->thumbProfile()->height();
int imageWidth = pCore->thumbProfile()->width();
int fullWidth = int(imageHeight * pCore->getCurrentDar() + 0.5);
int fullWidth = qRound(imageHeight * pCore->getCurrentDar());
return KThumb::getFrame(frame.data(), imageWidth, imageHeight, fullWidth);
}
......@@ -4556,7 +4556,7 @@ void TimelineController::collapseActiveTrack()
}
int collapsed = m_model->getTrackProperty(m_activeTrack, QStringLiteral("kdenlive:collapsed")).toInt();
// Default unit for timeline.qml objects size
int baseUnit = qMax(28, int(QFontInfo(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)).pixelSize() * 1.8 + 0.5));
int baseUnit = qMax(28, qRound(QFontInfo(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)).pixelSize() * 1.8));
m_model->setTrackProperty(m_activeTrack, QStringLiteral("kdenlive:collapsed"), collapsed > 0 ? QStringLiteral("0") : QString::number(baseUnit));
}
......
......@@ -156,7 +156,7 @@ TitleWidget::TitleWidget(const QUrl &url, QString projectTitlePath, Monitor *mon
itemzoom->setSuffix(i18n("%"));
QSize profileSize = pCore->getCurrentFrameSize();
m_frameWidth = int(profileSize.height() * pCore->getCurrentDar() + 0.5);
m_frameWidth = qRound(profileSize.height() * pCore->getCurrentDar());
m_frameHeight = profileSize.height();
showToolbars(TITLE_SELECT);
......@@ -1001,7 +1001,7 @@ void TitleWidget::slotAdjustZoom()
/*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
if (scalex > scaley) scalex = scaley;
int zoompos = (int)(scalex * 7 + 0.5);*/
int zoompos = qRound(scalex * 7);*/
graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
int zoompos = int(graphicsView->transform().m11() * 100);
zoom_slider->setValue(zoompos);
......@@ -1526,7 +1526,7 @@ void TitleWidget::updateRotZoom(QGraphicsItem *i)
if (!i->data(TitleDocument::ZoomFactor).isNull()) {
itemzoom->setValue(i->data(TitleDocument::ZoomFactor).toInt());
} else {
itemzoom->setValue(int(t.scalex * 100.0 + 0.5));
itemzoom->setValue(qRound(t.scalex * 100.0));
}
itemrotatex->setValue(int(t.rotatex));
......@@ -3163,7 +3163,7 @@ void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
if (!referenceItem->data(TitleDocument::ZoomFactor).isNull()) {
itemzoom->setValue(referenceItem->data(TitleDocument::ZoomFactor).toInt());
} else {
itemzoom->setValue(int(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
itemzoom->setValue(qRound(m_transformations.value(referenceItem).scalex * 100.0));
}
itemrotatex->setValue(int(m_transformations.value(referenceItem).rotatex));
itemrotatey->setValue(int(m_transformations.value(referenceItem).rotatey));
......
......@@ -80,7 +80,7 @@ Timecode::~Timecode() = default;
void Timecode::setFormat(double framesPerSecond, Formats format)
{
m_displayedFramesPerSecond = (int)(framesPerSecond + 0.5);
m_displayedFramesPerSecond = qRound(framesPerSecond);
m_dropFrameTimecode = qFuzzyCompare(framesPerSecond, 30000.0/1001.0);
m_format = format;
m_realFps = framesPerSecond;
......@@ -206,7 +206,7 @@ QString Timecode::getStringTimecode(int frames, const double &fps, bool showFram
}
auto seconds = (int)(frames / fps);
int frms = frames % (int)(fps + 0.5);
int frms = frames % qRound(fps);
int minutes = seconds / 60;
seconds = seconds % 60;
int hours = minutes / 60;
......
......@@ -172,7 +172,7 @@ void GeometryWidget::slotAdjustToSource()
{
m_spinWidth->blockSignals(true);
m_spinHeight->blockSignals(true);
m_spinWidth->setValue((int)(m_sourceSize.width() / pCore->getCurrentSar() + 0.5), false);
m_spinWidth->setValue(qRound(m_sourceSize.width() / pCore->getCurrentSar()), false);
m_spinHeight->setValue(m_sourceSize.height(), false);
m_spinWidth->blockSignals(false);
m_spinHeight->blockSignals(false);
......@@ -191,13 +191,13 @@ void GeometryWidget::slotAdjustToFrameSize()
if (sourceDar > monitorDar) {
// Fit to width
double factor = (double)m_defaultSize.width() / m_sourceSize.width() * pCore->getCurrentSar();
m_spinHeight->setValue((int)(m_sourceSize.height() * factor + 0.5));
m_spinHeight->setValue(qRound(m_sourceSize.height() * factor));
m_spinWidth->setValue(m_defaultSize.width());
} else {
// Fit to height
double factor = (double)m_defaultSize.height() / m_sourceSize.height();
m_spinHeight->setValue(m_defaultSize.height());
m_spinWidth->setValue((int)(m_sourceSize.width() / pCore->getCurrentSar() * factor + 0.5));
m_spinWidth->setValue(qRound(m_sourceSize.width() / pCore->getCurrentSar() * factor));
}
// Center
QSignalBlocker bk3(m_spinX);
......@@ -212,7 +212,7 @@ void GeometryWidget::slotFitToWidth()
double factor = (double)m_defaultSize.width() / m_sourceSize.width() * pCore->getCurrentSar();
m_spinWidth->blockSignals(true);
m_spinHeight->blockSignals(true);
m_spinHeight->setValue((int)(m_sourceSize.height() * factor + 0.5));
m_spinHeight->setValue(qRound(m_sourceSize.height() * factor));
m_spinWidth->setValue(m_defaultSize.width());
m_spinWidth->blockSignals(false);
m_spinHeight->blockSignals(false);
......@@ -224,7 +224,7 @@ void GeometryWidget::slotFitToHeight()
m_spinWidth->blockSignals(true);
m_spinHeight->blockSignals(true);
m_spinHeight->setValue(m_defaultSize.height());
m_spinWidth->setValue((int)(m_sourceSize.width() / pCore->getCurrentSar() * factor + 0.5));
m_spinWidth->setValue(qRound(m_sourceSize.width() / pCore->getCurrentSar() * factor));
m_spinWidth->blockSignals(false);
m_spinHeight->blockSignals(false);
slotAdjustRectKeyframeValue();
......@@ -296,9 +296,9 @@ void GeometryWidget::slotAdjustRectHeight()
if (m_lockRatio->isChecked()) {
m_spinWidth->blockSignals(true);
if (m_originalSize->isChecked()) {
m_spinWidth->setValue((int)(m_spinHeight->value() * m_sourceSize.width() / m_sourceSize.height() + 0.5));
m_spinWidth->setValue(qRound(m_spinHeight->value() * m_sourceSize.width() / m_sourceSize.height()));
} else {
m_spinWidth->setValue((int)(m_spinHeight->value() * m_defaultSize.width() / m_defaultSize.height() + 0.5));
m_spinWidth->setValue(qRound(m_spinHeight->value() * m_defaultSize.width() / m_defaultSize.height()));
}
m_spinWidth->blockSignals(false);
}
......@@ -311,9 +311,9 @@ void GeometryWidget::slotAdjustRectWidth()
if (m_lockRatio->isChecked()) {
m_spinHeight->blockSignals(true);
if (m_originalSize->isChecked()) {
m_spinHeight->setValue((int)(m_spinWidth->value() * m_sourceSize.height() / m_sourceSize.width() + 0.5));
m_spinHeight->setValue(qRound(m_spinWidth->value() * m_sourceSize.height() / m_sourceSize.width()));
} else {
m_spinHeight->setValue((int)(m_spinWidth->value() * m_defaultSize.height() / m_defaultSize.width() + 0.5));
m_spinHeight->setValue(qRound(m_spinWidth->value() * m_defaultSize.height() / m_defaultSize.width()));
}
m_spinHeight->blockSignals(false);
}
......@@ -389,7 +389,7 @@ void GeometryWidget::setValue(const QRect r, double opacity)
if (opacity < 0) {
opacity = 100 / m_opacityFactor;
}
m_opacity->setValue((int)(opacity * m_opacityFactor + 0.5));
m_opacity->setValue(qRound(opacity * m_opacityFactor));
m_opacity->blockSignals(false);
}
m_spinX->blockSignals(false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment