Skip to content

Commit

Permalink
Remove Qt4 code in Gui/ and Tests/
Browse files Browse the repository at this point in the history
  • Loading branch information
acolwell committed Mar 20, 2024
1 parent 4248f6a commit a90f2a4
Show file tree
Hide file tree
Showing 73 changed files with 19 additions and 1,071 deletions.
13 changes: 0 additions & 13 deletions Gui/AboutWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ AboutWindow::AboutWindow(QWidget* parent)
: QDialog(parent)
{
_scale = 1.;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#if defined(Q_OS_WIN)
// code from Gui::devicePixelRatio()
HDC wscreen = GetDC(winId());
FLOAT horizontalDPI = GetDeviceCaps(wscreen, LOGPIXELSX);
ReleaseDC(0, wscreen);
_scale = static_cast<qreal>(horizontalDPI) / 96.;
#endif
#endif

setWindowTitle( tr("About %1").arg( QString::fromUtf8(NATRON_APPLICATION_NAME) ) );
_mainLayout = new QVBoxLayout(this);
Expand Down Expand Up @@ -498,11 +489,7 @@ AboutWindow::AboutWindow(QWidget* parent)
_view->setUniformRowHeights(true);
_view->setSelectionMode(QAbstractItemView::SingleSelection);
_view->header()->close();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
_view->header()->setResizeMode(QHeaderView::ResizeToContents);
#else
_view->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
_view->header()->setStretchLastSection(true);
splitter->addWidget(_view);

Expand Down
29 changes: 0 additions & 29 deletions Gui/ComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ ComboBox::sizeForWidth(int w) const
int hextra = DROP_DOWN_ICON_SIZE * 2, vextra = 0;

///Indent of 1 character
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int indent = fm.horizontalAdvance( QLatin1Char('x') );
#else
int indent = fm.width( QLatin1Char('x') );
#endif

if (indent > 0) {
if ( (align & Qt::AlignLeft) || (align & Qt::AlignRight) ) {
Expand Down Expand Up @@ -243,11 +239,7 @@ ComboBox::layoutRect() const
{
QRect cr = contentsRect();
Qt::Alignment align = QStyle::visualAlignment( Qt::LeftToRight, QFlag(_align) );
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int indent = fontMetrics().horizontalAdvance( QLatin1Char('x') ) / 2;
#else
int indent = fontMetrics().width( QLatin1Char('x') ) / 2;
#endif

if (indent > 0) {
if (align & Qt::AlignLeft) {
Expand Down Expand Up @@ -414,11 +406,7 @@ ComboBox::wheelEvent(QWheelEvent *e)
return;
}
// a standard wheel click is 120
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
_currentDelta += e->angleDelta().y();
#else
_currentDelta += e->delta();
#endif

if ( (_currentDelta <= -120) || (120 <= _currentDelta) ) {
int c = count();
Expand Down Expand Up @@ -733,11 +721,7 @@ ComboBox::setCurrentText_internal(const QString & text)
}

if (_sizePolicy.horizontalPolicy() != QSizePolicy::Fixed) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int w = m.horizontalAdvance(str) + 2 * DROP_DOWN_ICON_SIZE;
#else
int w = m.width(str) + 2 * DROP_DOWN_ICON_SIZE;
#endif
setMinimumWidth(w);
}

Expand All @@ -757,11 +741,7 @@ ComboBox::setMaximumWidthFromText(const QString & str)
if (_sizePolicy.horizontalPolicy() == QSizePolicy::Fixed) {
return;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int w = fontMetrics().horizontalAdvance(str);
#else
int w = fontMetrics().width(str);
#endif
setMaximumWidth(w + DROP_DOWN_ICON_SIZE * 2);
}

Expand All @@ -771,12 +751,7 @@ ComboBox::growMaximumWidthFromText(const QString & str)
if (_sizePolicy.horizontalPolicy() == QSizePolicy::Fixed) {
return;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int w = fontMetrics().horizontalAdvance(str) + 2 * DROP_DOWN_ICON_SIZE;
#else
int w = fontMetrics().width(str) + 2 * DROP_DOWN_ICON_SIZE;
#endif

if ( w > maximumWidth() ) {
setMaximumWidth(w);
}
Expand Down Expand Up @@ -865,11 +840,7 @@ ComboBox::setCurrentIndex_internal(int index)

if (_sizePolicy.horizontalPolicy() != QSizePolicy::Fixed) {
QFontMetrics m = fontMetrics();
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int w = m.horizontalAdvance(str) + 2 * DROP_DOWN_ICON_SIZE;
#else
int w = m.width(str) + 2 * DROP_DOWN_ICON_SIZE;
#endif
setMinimumWidth(w);
}

Expand Down
2 changes: 0 additions & 2 deletions Gui/CurveGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
#include "Gui/CurveWidgetPrivate.h"
#include "Gui/KnobGui.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#endif

NATRON_NAMESPACE_ENTER

Expand Down
50 changes: 1 addition & 49 deletions Gui/CurveWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON
#include <QtCore/QThread>
#include <QApplication>
#include <QToolButton>
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
#include <QScreen>
#else
#include <QDesktopWidget>
#endif

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QWindow>
#endif

#include "Engine/Bezier.h"
#include "Engine/PyParameter.h" // IntParam
Expand All @@ -71,9 +64,7 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON
#include "Gui/TabWidget.h"
#include "Gui/ViewerGL.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#endif

NATRON_NAMESPACE_ENTER

Expand Down Expand Up @@ -122,11 +113,7 @@ CurveWidget::CurveWidget(Gui* gui,
TimeLinePtr timeline,
QWidget* parent,
const QOpenGLWidget* shareWidget)
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
: QOpenGLWidget(parent)
#else
: QOpenGLWidget(parent, shareWidget)
#endif
, _imp( new CurveWidgetPrivate(gui, selection, timeline, this) )
{
// always running in the main thread
Expand Down Expand Up @@ -444,11 +431,7 @@ CurveWidget::swapOpenGLBuffers()
// always running in the main thread
assert( qApp && qApp->thread() == QThread::currentThread() );

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
update();
#else
swapBuffers();
#endif
}

/**
Expand Down Expand Up @@ -498,11 +481,7 @@ CurveWidget::getScreenPixelRatio() const
// always running in the main thread
assert( qApp && qApp->thread() == QThread::currentThread() );

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return devicePixelRatio();
#else
return _imp->_gui ? _imp->_gui->devicePixelRatio() : 1.;
#endif
}
#endif

Expand Down Expand Up @@ -607,11 +586,9 @@ CurveWidget::resizeGL(int width,
glViewport (0, 0, width, height);
double zoomWidth = width;
double zoomHeight = height;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
double screenPixelRatio = getScreenPixelRatio();
zoomWidth /= screenPixelRatio;
zoomHeight /= screenPixelRatio;
#endif

// Width and height may be 0 when tearing off a viewer tab to another panel
if ( (width > 0) && (height > 0) ) {
Expand Down Expand Up @@ -823,13 +800,9 @@ CurveWidget::mouseDoubleClickEvent(QMouseEvent* e)
if (selectedText) {
EditKeyFrameDialog* dialog = new EditKeyFrameDialog(mode, this, selectedText, this);
int dialogW = dialog->sizeHint().width();
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
QScreen* desktop = QGuiApplication::primaryScreen();
QRect screen = desktop->availableGeometry();
#else
QDesktopWidget* desktop = QApplication::desktop();
QRect screen = desktop->screenGeometry();
#endif

QPoint gP = e->globalPos();
if ( gP.x() > (screen.width() - dialogW) ) {
gP.rx() -= dialogW;
Expand Down Expand Up @@ -1443,21 +1416,12 @@ CurveWidget::wheelEvent(QWheelEvent* e)
assert( qApp && qApp->thread() == QThread::currentThread() );

// don't handle horizontal wheel (e.g. on trackpad or Might Mouse)
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
if (e->angleDelta().x() != 0) {
#else
if (e->orientation() != Qt::Vertical) {
#endif
return;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
double scaleFactor = std::pow( NATRON_WHEEL_ZOOM_PER_DELTA, e->angleDelta().y() );
QPointF zoomCenter = _imp->zoomCtx.toZoomCoordinates( e->position().x(), e->position().y() );
#else
double scaleFactor = std::pow( NATRON_WHEEL_ZOOM_PER_DELTA, e->delta() );
QPointF zoomCenter = _imp->zoomCtx.toZoomCoordinates( e->x(), e->y() );
#endif

if ( modCASIsControlShift(e) ) {
_imp->zoomOrPannedSinceLastFit = true;
Expand Down Expand Up @@ -1548,11 +1512,7 @@ CurveWidget::getWidgetFontHeight() const
int
CurveWidget::getStringWidthForCurrentFont(const std::string& string) const
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return fontMetrics().horizontalAdvance( QString::fromUtf8( string.c_str() ) );
#else
return fontMetrics().width( QString::fromUtf8( string.c_str() ) );
#endif
}

QSize
Expand Down Expand Up @@ -1598,18 +1558,10 @@ CurveWidget::keyPressEvent(QKeyEvent* e)
} else if ( isKeybind(kShortcutGroupCurveEditor, kShortcutIDActionCurveEditorPaste, modifiers, key) ) {
pasteKeyFramesFromClipBoardToSelectedCurve();
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionZoomIn, Qt::NoModifier, key) ) { // zoom in/out doesn't care about modifiers
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
QWheelEvent e(mapFromGlobal( QCursor::pos() ), QCursor::pos(), QPoint(), QPoint(0, 120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
#else
QWheelEvent e(mapFromGlobal( QCursor::pos() ), 120, Qt::NoButton, Qt::NoModifier); // one wheel click = +-120 delta
#endif
wheelEvent(&e);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionZoomOut, Qt::NoModifier, key) ) { // zoom in/out doesn't care about modifiers
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
QWheelEvent e(mapFromGlobal( QCursor::pos() ), QCursor::pos(), QPoint(), QPoint(0, -120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
#else
QWheelEvent e(mapFromGlobal( QCursor::pos() ), -120, Qt::NoButton, Qt::NoModifier); // one wheel click = +-120 delta
#endif
wheelEvent(&e);
} else {
accept = false;
Expand Down
4 changes: 0 additions & 4 deletions Gui/CurveWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ CLANG_DIAG_OFF(uninitialized)
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLWidget>
#else
#include "Gui/QGLWidgetCompat.h"
#endif

#include "Global/GlobalDefines.h"

Expand Down
19 changes: 0 additions & 19 deletions Gui/CurveWidgetPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
#include "Gui/Menu.h"
#include "Gui/ticks.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#endif

#define CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE 5 //maximum distance from a curve that accepts a mouse click
// (in widget pixels)
Expand Down Expand Up @@ -497,11 +495,7 @@ CurveWidgetPrivate::drawScale(double screenPixelRatio)
ticks_fill(half_tick, ticks_max, m1, m2, &ticks);
const double smallestTickSize = range * smallestTickSizePixel / rangePixel;
const double largestTickSize = range * largestTickSizePixel / rangePixel;
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
const double minTickSizeTextPixel = ( (axis == 0) ? fm.horizontalAdvance( QLatin1String("00") ) : fm.height() ) / _screenPixelRatio;
#else
const double minTickSizeTextPixel = ( (axis == 0) ? fm.width( QLatin1String("00") ) : fm.height() ) / _screenPixelRatio; // AXIS-SPECIFIC
#endif
const double minTickSizeText = range * minTickSizeTextPixel / rangePixel;
for (int i = m1; i <= m2; ++i) {
double value = i * smallTickSize + offset;
Expand All @@ -526,11 +520,7 @@ CurveWidgetPrivate::drawScale(double screenPixelRatio)
if (tickSize > minTickSizeText) {
const int tickSizePixel = rangePixel * tickSize / range;
const QString s = QString::number(value);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
const double sSizePixel = ( (axis == 0) ? fm.horizontalAdvance(s) : fm.height() ) / _screenPixelRatio; // AXIS-SPECIFIC
#else
const double sSizePixel = ( (axis == 0) ? fm.width(s) : fm.height() ) / _screenPixelRatio; // AXIS-SPECIFIC
#endif
if (tickSizePixel > sSizePixel) {
const double sSizeFullPixel = sSizePixel + minTickSizeTextPixel;
double alphaText = 1.0; //alpha;
Expand Down Expand Up @@ -784,11 +774,7 @@ CurveWidgetPrivate::isNearbyKeyFrameText(const QPoint& pt) const
topLeftWidget.ry() += yOffset;

QString coordStr = QString::fromUtf8("x: %1, y: %2").arg( (*it2)->key.getTime() ).arg( (*it2)->key.getValue() );
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
QPointF btmRightWidget( topLeftWidget.x() + fm.horizontalAdvance(coordStr) / _screenPixelRatio, topLeftWidget.y() + fm.height() / _screenPixelRatio );
#else
QPointF btmRightWidget( topLeftWidget.x() + fm.width(coordStr) / _screenPixelRatio, topLeftWidget.y() + fm.height() / _screenPixelRatio );
#endif

if ( (pt.x() >= topLeftWidget.x() - CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) && (pt.x() <= btmRightWidget.x() + CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) &&
( pt.y() >= topLeftWidget.y() - CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) && ( pt.y() <= btmRightWidget.y() + CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) ) {
Expand Down Expand Up @@ -853,13 +839,8 @@ CurveWidgetPrivate::isNearbySelectedTangentText(const QPoint & pt) const

QString leftCoordStr = QString( tr("l: %1") ).arg(std::floor( ( (*it2)->key.getLeftDerivative() * rounding ) + 0.5 ) / rounding);
QString rightCoordStr = QString( tr("r: %1") ).arg(std::floor( ( (*it2)->key.getRightDerivative() * rounding ) + 0.5 ) / rounding);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
QPointF btmRight_LeftTanWidget( topLeft_LeftTanWidget.x() + fm.horizontalAdvance(leftCoordStr) / _screenPixelRatio, topLeft_LeftTanWidget.y() + fm.height() / _screenPixelRatio );
QPointF btmRight_RightTanWidget( topLeft_RightTanWidget.x() + fm.horizontalAdvance(rightCoordStr) / _screenPixelRatio, topLeft_RightTanWidget.y() + fm.height() / _screenPixelRatio );
#else
QPointF btmRight_LeftTanWidget( topLeft_LeftTanWidget.x() + fm.width(leftCoordStr) / _screenPixelRatio, topLeft_LeftTanWidget.y() + fm.height() / _screenPixelRatio );
QPointF btmRight_RightTanWidget( topLeft_RightTanWidget.x() + fm.width(rightCoordStr) / _screenPixelRatio, topLeft_RightTanWidget.y() + fm.height() / _screenPixelRatio );
#endif

if ( (pt.x() >= topLeft_LeftTanWidget.x() - CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) && (pt.x() <= btmRight_LeftTanWidget.x() + CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) &&
( pt.y() >= topLeft_LeftTanWidget.y() - CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) && ( pt.y() <= btmRight_LeftTanWidget.y() + CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE) ) {
Expand Down
17 changes: 0 additions & 17 deletions Gui/CustomParamInteract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
#include <QMouseEvent>
#include <QtCore/QByteArray>

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QWindow>
#endif

#include "Gui/KnobGui.h"
#include "Gui/Gui.h"
Expand All @@ -47,9 +45,7 @@
#include "Engine/AppInstance.h"
#include "Engine/TimeLine.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#endif


NATRON_NAMESPACE_ENTER
Expand Down Expand Up @@ -175,11 +171,7 @@ CustomParamInteract::sizeHint() const
void
CustomParamInteract::swapOpenGLBuffers()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
update();
#else
swapBuffers();
#endif
}

void
Expand Down Expand Up @@ -208,12 +200,7 @@ CustomParamInteract::getPixelScale(double & xScale,
double
CustomParamInteract::getScreenPixelRatio() const
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return devicePixelRatio();
#else
KnobGuiPtr k = _imp->knob.lock();
return (k && k->getGui()) ? k->getGui()->devicePixelRatio() : 1.;
#endif
}
#endif

Expand Down Expand Up @@ -299,11 +286,7 @@ CustomParamInteract::getWidgetFontHeight() const
int
CustomParamInteract::getStringWidthForCurrentFont(const std::string& string) const
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return fontMetrics().horizontalAdvance( QString::fromUtf8( string.c_str() ) );
#else
return fontMetrics().width( QString::fromUtf8( string.c_str() ) );
#endif
}

RectD
Expand Down
Loading

0 comments on commit a90f2a4

Please sign in to comment.