Skip to content

Commit

Permalink
Fix for the font of truncated sidebar items (LMMS#5714). (LMMS#5777)
Browse files Browse the repository at this point in the history
* Fix for the font of truncated sidebar items (LMMS#5714).

For windows platforms, retrieve the system font and set it for the FileBrowserTreeWidget. This makes sure that truncated items will use the font as non-truncated items.

* Add TODO to remove the fix when all builds use a recent enough version of qt.

* Add check on QT version and conditionally include the fix.
  • Loading branch information
DigArtRoks authored Nov 14, 2020
1 parent 357de8b commit ca10cfa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/GuiApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QtCore/QObject>

#include "lmms_export.h"
#include "lmmsconfig.h"

class QLabel;

Expand All @@ -48,6 +49,9 @@ class LMMS_EXPORT GuiApplication : public QObject
~GuiApplication();

static GuiApplication* instance();
#ifdef LMMS_BUILD_WIN32
static QFont getWin32SystemFont();
#endif

MainWindow* mainWindow() { return m_mainWindow; }
FxMixerView* fxMixerView() { return m_fxMixerView; }
Expand Down
9 changes: 7 additions & 2 deletions src/gui/FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
#include "StringPairDrag.h"
#include "TextFloat.h"



enum TreeWidgetItemTypes
{
TypeFileItem = QTreeWidgetItem::UserType,
Expand Down Expand Up @@ -335,6 +333,13 @@ FileBrowserTreeWidget::FileBrowserTreeWidget(QWidget * parent ) :
connect( this, SIGNAL( itemExpanded( QTreeWidgetItem * ) ),
SLOT( updateDirectory( QTreeWidgetItem * ) ) );

#if QT_VERSION < QT_VERSION_CHECK(5, 12, 2) && defined LMMS_BUILD_WIN32
// Set the font for the QTreeWidget to the Windows System font to make sure that
// truncated (elided) items use the same font as non-truncated items.
// This is a workaround for this qt bug, fixed in 5.12.2: https://bugreports.qt.io/browse/QTBUG-29232
// TODO: remove this when all builds use a recent enough version of qt.
setFont( GuiApplication::getWin32SystemFont() );
#endif
}


Expand Down
25 changes: 25 additions & 0 deletions src/gui/GuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#include <QMessageBox>
#include <QSplashScreen>

#ifdef LMMS_BUILD_WIN32
#include <windows.h>
#endif

GuiApplication* GuiApplication::s_instance = nullptr;

GuiApplication* GuiApplication::instance()
Expand Down Expand Up @@ -211,3 +215,24 @@ void GuiApplication::childDestroyed(QObject *obj)
m_controllerRackView = nullptr;
}
}

#ifdef LMMS_BUILD_WIN32
/*!
* @brief Returns the Windows System font.
*/
QFont GuiApplication::getWin32SystemFont()
{
NONCLIENTMETRICS metrics = { sizeof( NONCLIENTMETRICS ) };
SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( NONCLIENTMETRICS ), &metrics, 0 );
int pointSize = metrics.lfMessageFont.lfHeight;
if ( pointSize < 0 )
{
// height is in pixels, convert to points
HDC hDC = GetDC( NULL );
pointSize = MulDiv( abs( pointSize ), 72, GetDeviceCaps( hDC, LOGPIXELSY ) );
ReleaseDC( NULL, hDC );
}

return QFont( QString::fromUtf8( metrics.lfMessageFont.lfFaceName ), pointSize );
}
#endif

0 comments on commit ca10cfa

Please sign in to comment.