Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor gui_templates.h #7159

Merged
merged 10 commits into from
Mar 27, 2024
36 changes: 13 additions & 23 deletions include/gui_templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,27 @@
#include <QFont>
#include <QDesktopWidget>

// TODO: cleanup for qt6
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
#include <QScreen>
#else
#include <QGuiApplication>
#endif

namespace lmms
{


// return DPI-independent font-size - font with returned font-size has always
// the same size in pixels
template<int SIZE>
inline QFont pointSize( QFont _f )
template<typename T>
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
inline QFont pointSize(QFont _f, T SIZE)
{
static const float DPI = 96;
#ifdef LMMS_BUILD_WIN32
_f.setPointSizeF( ((float) SIZE+0.5f) * DPI /
QApplication::desktop()->logicalDpiY() );
#else
_f.setPointSizeF( (float) SIZE * DPI /
QApplication::desktop()->logicalDpiY() );
#endif
return( _f );
}

// to calculate DPI of a screen to make it HiDPI ready
qreal devicePixelRatio = QGuiApplication::primaryScreen()->devicePixelRatio();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using QGuiApplication::primaryScreen() i think there could be some issues when Switching the App to an other Monitor with an diffrent DPI, We should grab the current Monitor for our Window

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what you mean but can you suggest a way to handle this one properly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is something that should be handled by the GUI framework, i.e. by Qt. It just one example of why using these functions in application code is problematic.

Using code like this also won't do the "right thing" when LMMS is in the middle of being dragged from one screen to another with different DPI values. Qt likely knows that one part of the application rectangle must be rendered with different settings than the other and can do so. The application code does not even have the knowledge of the current state ("I am shown on two different monitors.") and cannot do the right thing.

qreal scaleFactor = devicePixelRatio > 1.0 ? devicePixelRatio : 1.0; // Ensure scaleFactor is at least 1.0
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved

inline QFont pointSizeF( QFont _f, float SIZE )
{
static const float DPI = 96;
#ifdef LMMS_BUILD_WIN32
_f.setPointSizeF( (SIZE+0.5f) * DPI /
QApplication::desktop()->logicalDpiY() );
#else
_f.setPointSizeF( SIZE * DPI /
QApplication::desktop()->logicalDpiY() );
#endif
_f.setPointSizeF((float)SIZE * scaleFactor);
return( _f );
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/AudioFileProcessor/AudioFileProcessorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ AudioFileProcessorView::AudioFileProcessorView(Instrument* instrument,
// interpolation selector
m_interpBox = new ComboBox(this);
m_interpBox->setGeometry(142, 62, 82, ComboBox::DEFAULT_HEIGHT);
m_interpBox->setFont(pointSize<8>(m_interpBox->font()));
m_interpBox->setFont(pointSize<int>(m_interpBox->font(), 8));

// wavegraph
m_waveView = 0;
Expand Down Expand Up @@ -228,7 +228,7 @@ void AudioFileProcessorView::paintEvent(QPaintEvent*)

int idx = a->sample().sampleFile().length();

p.setFont(pointSize<8>(font()));
p.setFont(pointSize<int>(font(), 8));

QFontMetrics fm(p.font());

Expand Down
2 changes: 1 addition & 1 deletion plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void AudioFileProcessorWaveView::paintEvent(QPaintEvent * pe)
p.fillRect(s_padding, s_padding, m_graph.width(), 14, g);

p.setPen(QColor(255, 255, 255));
p.setFont(pointSize<8>(font()));
p.setFont(pointSize<int>(font(), 8));

QString length_text;
const int length = m_sample->sampleDuration().count();
Expand Down
4 changes: 2 additions & 2 deletions plugins/CarlaBase/Carla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ CarlaInstrumentView::CarlaInstrumentView(CarlaInstrument* const instrument, QWid
m_toggleUIButton->setCheckable( true );
m_toggleUIButton->setChecked( false );
m_toggleUIButton->setIcon( embed::getIconPixmap( "zoom" ) );
m_toggleUIButton->setFont( pointSize<8>( m_toggleUIButton->font() ) );
m_toggleUIButton->setFont(pointSize<int>(m_toggleUIButton->font(), 8));
connect( m_toggleUIButton, SIGNAL( clicked(bool) ), this, SLOT( toggleUI( bool ) ) );

m_toggleUIButton->setToolTip(
Expand All @@ -642,7 +642,7 @@ CarlaInstrumentView::CarlaInstrumentView(CarlaInstrument* const instrument, QWid
m_toggleParamsWindowButton = new QPushButton(tr("Params"), this);
m_toggleParamsWindowButton->setIcon(embed::getIconPixmap("controller"));
m_toggleParamsWindowButton->setCheckable(true);
m_toggleParamsWindowButton->setFont(pointSize<8>(m_toggleParamsWindowButton->font()));
m_toggleParamsWindowButton->setFont(pointSize<int>(m_toggleParamsWindowButton->font(), 8));
#if CARLA_VERSION_HEX < CARLA_MIN_PARAM_VERSION
m_toggleParamsWindowButton->setEnabled(false);
m_toggleParamsWindowButton->setToolTip(tr("Available from Carla version 2.1 and up."));
Expand Down
4 changes: 2 additions & 2 deletions plugins/DualFilter/DualFilterControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ DualFilterControlDialog::DualFilterControlDialog( DualFilterControls* controls )

auto m_filter1ComboBox = new ComboBox(this);
m_filter1ComboBox->setGeometry( 19, 70, 137, ComboBox::DEFAULT_HEIGHT );
m_filter1ComboBox->setFont( pointSize<8>( m_filter1ComboBox->font() ) );
m_filter1ComboBox->setFont(pointSize<int>(m_filter1ComboBox->font(), 8));
m_filter1ComboBox->setModel( &controls->m_filter1Model );

auto m_filter2ComboBox = new ComboBox(this);
m_filter2ComboBox->setGeometry( 217, 70, 137, ComboBox::DEFAULT_HEIGHT );
m_filter2ComboBox->setFont( pointSize<8>( m_filter2ComboBox->font() ) );
m_filter2ComboBox->setFont(pointSize<int>(m_filter2ComboBox->font(), 8));
m_filter2ComboBox->setModel( &controls->m_filter2Model );
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/LadspaBrowser/LadspaBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ QWidget * LadspaBrowserView::createTab( QWidget * _parent, const QString & _txt,
auto title = new QLabel(type + _txt, tab);
QFont f = title->font();
f.setBold( true );
title->setFont( pointSize<12>( f ) );
title->setFont(pointSize<int>(f, 12));

layout->addSpacing( 5 );
layout->addWidget( title );
Expand Down
10 changes: 5 additions & 5 deletions plugins/Monstro/Monstro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ QWidget * MonstroView::setupOperatorsView( QWidget * _parent )

m_osc2WaveBox = new ComboBox( view );
m_osc2WaveBox -> setGeometry( 204, O2ROW + 7, 42, ComboBox::DEFAULT_HEIGHT );
m_osc2WaveBox->setFont( pointSize<8>( m_osc2WaveBox->font() ) );
m_osc2WaveBox->setFont(pointSize<int>(m_osc2WaveBox->font(), 8));

maketinyled( m_osc2SyncHButton, 212, O2ROW - 3, tr( "Hard sync oscillator 2" ) )
maketinyled( m_osc2SyncRButton, 191, O2ROW - 3, tr( "Reverse sync oscillator 2" ) )
Expand All @@ -1709,26 +1709,26 @@ QWidget * MonstroView::setupOperatorsView( QWidget * _parent )

m_osc3Wave1Box = new ComboBox( view );
m_osc3Wave1Box -> setGeometry( 160, O3ROW + 7, 42, ComboBox::DEFAULT_HEIGHT );
m_osc3Wave1Box->setFont( pointSize<8>( m_osc3Wave1Box->font() ) );
m_osc3Wave1Box->setFont(pointSize<int>(m_osc3Wave1Box->font(), 8));

m_osc3Wave2Box = new ComboBox( view );
m_osc3Wave2Box -> setGeometry( 204, O3ROW + 7, 42, ComboBox::DEFAULT_HEIGHT );
m_osc3Wave2Box->setFont( pointSize<8>( m_osc3Wave2Box->font() ) );
m_osc3Wave2Box->setFont(pointSize<int>(m_osc3Wave2Box->font(), 8));

maketinyled( m_osc3SyncHButton, 212, O3ROW - 3, tr( "Hard sync oscillator 3" ) )
maketinyled( m_osc3SyncRButton, 191, O3ROW - 3, tr( "Reverse sync oscillator 3" ) )

m_lfo1WaveBox = new ComboBox( view );
m_lfo1WaveBox -> setGeometry( 2, LFOROW + 7, 42, ComboBox::DEFAULT_HEIGHT );
m_lfo1WaveBox->setFont( pointSize<8>( m_lfo1WaveBox->font() ) );
m_lfo1WaveBox->setFont(pointSize<int>(m_lfo1WaveBox->font(), 8));

maketsknob( m_lfo1AttKnob, LFOCOL1, LFOROW, tr( "Attack" ), " ms", "lfoKnob" )
maketsknob( m_lfo1RateKnob, LFOCOL2, LFOROW, tr( "Rate" ), " ms", "lfoKnob" )
makeknob( m_lfo1PhsKnob, LFOCOL3, LFOROW, tr( "Phase" ), tr( " deg" ), "lfoKnob" )

m_lfo2WaveBox = new ComboBox( view );
m_lfo2WaveBox -> setGeometry( 127, LFOROW + 7, 42, ComboBox::DEFAULT_HEIGHT );
m_lfo2WaveBox->setFont( pointSize<8>( m_lfo2WaveBox->font() ) );
m_lfo2WaveBox->setFont(pointSize<int>(m_lfo2WaveBox->font(), 8));

maketsknob(m_lfo2AttKnob, LFOCOL4, LFOROW, tr("Attack"), " ms", "lfoKnob")
maketsknob(m_lfo2RateKnob, LFOCOL5, LFOROW, tr("Rate"), " ms", "lfoKnob")
Expand Down
4 changes: 2 additions & 2 deletions plugins/Patman/Patman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void PatmanView::updateFilename()
m_displayFilename = "";
int idx = m_pi->m_patchFile.length();

QFontMetrics fm( pointSize<8>( font() ) );
QFontMetrics fm(pointSize<int>(font(), 8));

// simple algorithm for creating a text from the filename that
// matches in the white rectangle
Expand Down Expand Up @@ -618,7 +618,7 @@ void PatmanView::paintEvent( QPaintEvent * )
{
QPainter p( this );

p.setFont( pointSize<8>( font() ) );
p.setFont(pointSize<int>(font() ,8));
p.drawText( 8, 116, 235, 16,
Qt::AlignLeft | Qt::TextSingleLine | Qt::AlignVCenter,
m_displayFilename );
Expand Down
2 changes: 1 addition & 1 deletion plugins/Stk/Mallets/Mallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ MalletsInstrumentView::MalletsInstrumentView( MalletsInstrument * _instrument,

m_presetsCombo = new ComboBox( this, tr( "Instrument" ) );
m_presetsCombo->setGeometry( 140, 50, 99, ComboBox::DEFAULT_HEIGHT );
m_presetsCombo->setFont( pointSize<8>( m_presetsCombo->font() ) );
m_presetsCombo->setFont(pointSize<int>(m_presetsCombo->font(), 8));

connect( &_instrument->m_presetsModel, SIGNAL( dataChanged() ),
this, SLOT( changePreset() ) );
Expand Down
8 changes: 4 additions & 4 deletions plugins/Vestige/Vestige.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ VestigeInstrumentView::VestigeInstrumentView( Instrument * _instrument,
m_toggleGUIButton = new QPushButton( tr( "Show/hide GUI" ), this );
m_toggleGUIButton->setGeometry( 20, 130, 200, 24 );
m_toggleGUIButton->setIcon( embed::getIconPixmap( "zoom" ) );
m_toggleGUIButton->setFont( pointSize<8>( m_toggleGUIButton->font() ) );
m_toggleGUIButton->setFont(pointSize<int>(m_toggleGUIButton->font(), 8));
connect( m_toggleGUIButton, SIGNAL( clicked() ), this,
SLOT( toggleGUI() ) );

Expand All @@ -596,7 +596,7 @@ VestigeInstrumentView::VestigeInstrumentView( Instrument * _instrument,
this);
note_off_all_btn->setGeometry( 20, 160, 200, 24 );
note_off_all_btn->setIcon( embed::getIconPixmap( "stop" ) );
note_off_all_btn->setFont( pointSize<8>( note_off_all_btn->font() ) );
note_off_all_btn->setFont(pointSize<int>(note_off_all_btn->font(), 8));
connect( note_off_all_btn, SIGNAL( clicked() ), this,
SLOT( noteOffAll() ) );

Expand Down Expand Up @@ -881,7 +881,7 @@ void VestigeInstrumentView::paintEvent( QPaintEvent * )
tr( "No VST plugin loaded" );
QFont f = p.font();
f.setBold( true );
p.setFont( pointSize<10>( f ) );
p.setFont(pointSize<int>(f, 10));
p.setPen( QColor( 255, 255, 255 ) );
p.drawText( 10, 100, plugin_name );

Expand All @@ -893,7 +893,7 @@ void VestigeInstrumentView::paintEvent( QPaintEvent * )
{
p.setPen( QColor( 0, 0, 0 ) );
f.setBold( false );
p.setFont( pointSize<8>( f ) );
p.setFont(pointSize<int>(f, 8));
p.drawText( 10, 114, tr( "by " ) +
m_vi->m_plugin->vendorString() );
p.setPen( QColor( 255, 255, 255 ) );
Expand Down
2 changes: 1 addition & 1 deletion plugins/VstEffect/VstEffectControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
tb->addWidget(space1);

tbLabel = new QLabel( tr( "Effect by: " ), this );
tbLabel->setFont( pointSize<7>( f ) );
tbLabel->setFont(pointSize<int>(f, 7));
tbLabel->setTextFormat(Qt::RichText);
tbLabel->setAlignment( Qt::AlignTop | Qt::AlignLeft );
tb->addWidget( tbLabel );
Expand Down
2 changes: 1 addition & 1 deletion plugins/ZynAddSubFx/ZynAddSubFx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ ZynAddSubFxView::ZynAddSubFxView( Instrument * _instrument, QWidget * _parent )
m_toggleUIButton->setCheckable( true );
m_toggleUIButton->setChecked( false );
m_toggleUIButton->setIcon( embed::getIconPixmap( "zoom" ) );
m_toggleUIButton->setFont( pointSize<8>( m_toggleUIButton->font() ) );
m_toggleUIButton->setFont(pointSize<int>(m_toggleUIButton->font(), 8));
connect( m_toggleUIButton, SIGNAL( toggled( bool ) ), this,
SLOT( toggleUI() ) );

Expand Down
1 change: 0 additions & 1 deletion src/core/audio/AudioJack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "LcdSpinBox.h"
#include "MainWindow.h"
#include "MidiJack.h"
#include "gui_templates.h"

namespace lmms
{
Expand Down
1 change: 0 additions & 1 deletion src/core/audio/AudioOss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "LcdSpinBox.h"
#include "AudioEngine.h"
#include "Engine.h"
#include "gui_templates.h"

#ifdef LMMS_HAVE_UNISTD_H
#include <unistd.h>
Expand Down
1 change: 0 additions & 1 deletion src/core/audio/AudioPortAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void AudioPortAudioSetupUtil::updateChannels()

#include "Engine.h"
#include "ConfigManager.h"
#include "gui_templates.h"
#include "ComboBox.h"
#include "AudioEngine.h"

Expand Down
1 change: 0 additions & 1 deletion src/core/audio/AudioPulseAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "ConfigManager.h"
#include "LcdSpinBox.h"
#include "AudioEngine.h"
#include "gui_templates.h"
#include "Engine.h"

namespace lmms
Expand Down
1 change: 0 additions & 1 deletion src/core/audio/AudioSdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include "AudioEngine.h"
#include "ConfigManager.h"
#include "gui_templates.h"

namespace lmms
{
Expand Down
1 change: 0 additions & 1 deletion src/core/audio/AudioSndio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "LcdSpinBox.h"
#include "AudioEngine.h"
#include "Engine.h"
#include "gui_templates.h"

#include "ConfigManager.h"

Expand Down
1 change: 0 additions & 1 deletion src/core/audio/AudioSoundIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "Engine.h"
#include "debug.h"
#include "ConfigManager.h"
#include "gui_templates.h"
#include "ComboBox.h"
#include "AudioEngine.h"

Expand Down
1 change: 0 additions & 1 deletion src/gui/AudioAlsaSetupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

#include "ConfigManager.h"
#include "LcdSpinBox.h"
#include "gui_templates.h"

namespace lmms::gui
{
Expand Down
4 changes: 2 additions & 2 deletions src/gui/EffectView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ EffectView::EffectView( Effect * _model, QWidget * _parent ) :
{
auto ctls_btn = new QPushButton(tr("Controls"), this);
QFont f = ctls_btn->font();
ctls_btn->setFont( pointSize<8>( f ) );
ctls_btn->setFont(pointSize<int>(f, 8));
ctls_btn->setGeometry( 150, 14, 50, 20 );
connect( ctls_btn, SIGNAL(clicked()),
this, SLOT(editControls()));
Expand Down Expand Up @@ -257,7 +257,7 @@ void EffectView::paintEvent( QPaintEvent * )
QPainter p( this );
p.drawPixmap( 0, 0, m_bg );

QFont f = pointSizeF( font(), 7.5f );
QFont f = pointSize<float>(font(), 7.5f);
f.setBold( true );
p.setFont( f );

Expand Down
3 changes: 1 addition & 2 deletions src/gui/Lv2ViewBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase) :
m_toggleUIButton->setCheckable(true);
m_toggleUIButton->setChecked(false);
m_toggleUIButton->setIcon(embed::getIconPixmap("zoom"));
m_toggleUIButton->setFont(
pointSize<8>(m_toggleUIButton->font()));
m_toggleUIButton->setFont(pointSize<int>(m_toggleUIButton->font(), 8));
btnBox->addWidget(m_toggleUIButton, 0);
}
btnBox->addStretch(1);
Expand Down
1 change: 0 additions & 1 deletion src/gui/MidiSetupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <QLineEdit>

#include "ConfigManager.h"
#include "gui_templates.h"


namespace lmms::gui
Expand Down
2 changes: 1 addition & 1 deletion src/gui/MixerChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace lmms::gui

m_renameLineEdit = new QLineEdit{mixerName, nullptr};
m_renameLineEdit->setFixedWidth(65);
m_renameLineEdit->setFont(pointSizeF(font(), 7.5f));
m_renameLineEdit->setFont(pointSize<float>(font(), 7.5f));
m_renameLineEdit->setReadOnly(true);
m_renameLineEdit->installEventFilter(this);

Expand Down
1 change: 0 additions & 1 deletion src/gui/SampleTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include "EffectRackView.h"
#include "embed.h"
#include "gui_templates.h"
#include "GuiApplication.h"
#include "Knob.h"
#include "MainWindow.h"
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ void AutomationEditor::paintEvent(QPaintEvent * pe )
p.fillRect( 0, 0, width(), height(), bgColor );

// set font-size to 8
p.setFont( pointSize<8>( p.font() ) );
p.setFont(pointSize<int>(p.font(), 8));

int grid_height = height() - TOP_MARGIN - SCROLLBAR_SIZE;

Expand Down Expand Up @@ -1423,7 +1423,7 @@ void AutomationEditor::paintEvent(QPaintEvent * pe )
{
QFont f = p.font();
f.setBold( true );
p.setFont( pointSize<14>( f ) );
p.setFont(pointSize<int>(f, 14));
p.setPen( QApplication::palette().color( QPalette::Active,
QPalette::BrightText ) );
p.drawText( VALUES_WIDTH + 20, TOP_MARGIN + 40,
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
// display note editing info
//QFont f = p.font();
f.setBold( false );
p.setFont( pointSize<10>( f ) );
p.setFont(pointSize<int>(f, 10));
p.setPen(m_noteModeColor);
p.drawText( QRect( 0, keyAreaBottom(),
m_whiteKeyWidth, noteEditBottom() - keyAreaBottom()),
Expand Down Expand Up @@ -3601,7 +3601,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
{
QFont f = p.font();
f.setBold( true );
p.setFont( pointSize<14>( f ) );
p.setFont(pointSize<int>(f, 14));
p.setPen( QApplication::palette().color( QPalette::Active,
QPalette::BrightText ) );
p.drawText(m_whiteKeyWidth + 20, PR_TOP_MARGIN + 40,
Expand Down
Loading
Loading