Skip to content

Commit

Permalink
skin preview: consider devicePixelRation when scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jun 4, 2021
1 parent 9e7e0c7 commit cd6bfcf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
40 changes: 25 additions & 15 deletions src/preferences/dialog/dlgprefinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ bool skinFitsScreenSize(

} // namespace

DlgPrefInterface::DlgPrefInterface(QWidget * parent, MixxxMainWindow * mixxx,
SkinLoader* pSkinLoader,
UserSettingsPointer pConfig)
: DlgPreferencePage(parent),
m_pConfig(pConfig),
m_mixxx(mixxx),
m_pSkinLoader(pSkinLoader),
m_dScaleFactorAuto(1.0),
m_bUseAutoScaleFactor(false),
m_dScaleFactor(1.0),
m_bStartWithFullScreen(false),
m_bRebootMixxxView(false) {
DlgPrefInterface::DlgPrefInterface(QWidget* parent,
MixxxMainWindow* mixxx,
SkinLoader* pSkinLoader,
UserSettingsPointer pConfig)
: DlgPreferencePage(parent),
m_pConfig(pConfig),
m_mixxx(mixxx),
m_pSkinLoader(pSkinLoader),
m_dScaleFactorAuto(1.0),
m_bUseAutoScaleFactor(false),
m_dScaleFactor(1.0),
m_dDevicePixelRatio(1.0),
m_bStartWithFullScreen(false),
m_bRebootMixxxView(false) {
setupUi(this);

// Locale setting
Expand Down Expand Up @@ -150,6 +152,8 @@ DlgPrefInterface::DlgPrefInterface(QWidget * parent, MixxxMainWindow * mixxx,
skins.append(dir.entryInfoList());
}

m_dDevicePixelRatio = getDevicePixelRatioF(this);

QString configuredSkinPath = m_pSkinLoader->getConfiguredSkinPath();
int index = 0;
const auto* const pScreen = getScreen();
Expand All @@ -161,7 +165,9 @@ DlgPrefInterface::DlgPrefInterface(QWidget * parent, MixxxMainWindow * mixxx,
ComboBoxSkinconf->setCurrentIndex(index);
// schemes must be updated here to populate the drop-down box and set m_colorScheme
slotUpdateSchemes();
skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(m_skin, m_colorScheme));
skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(m_skin,
m_colorScheme,
m_dDevicePixelRatio));
if (skinFitsScreenSize(*pScreen, configuredSkinPath)) {
warningLabel->hide();
} else {
Expand Down Expand Up @@ -373,7 +379,9 @@ void DlgPrefInterface::slotSetScheme(int) {
m_colorScheme = newScheme;
m_bRebootMixxxView = true;
}
skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(m_skin, m_colorScheme));
skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(m_skin,
m_colorScheme,
m_dDevicePixelRatio));
}

void DlgPrefInterface::slotSetSkinDescription(const QString& skin) {
Expand Down Expand Up @@ -404,7 +412,9 @@ void DlgPrefInterface::slotSetSkin(int) {
slotSetSkinDescription(m_skin);
}

skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(newSkin, m_colorScheme));
skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(newSkin,
m_colorScheme,
m_dDevicePixelRatio));
}

void DlgPrefInterface::slotApply() {
Expand Down
1 change: 1 addition & 0 deletions src/preferences/dialog/dlgprefinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DlgPrefInterface : public DlgPreferencePage, public Ui::DlgPrefControlsDlg
double m_dScaleFactorAuto;
bool m_bUseAutoScaleFactor;
double m_dScaleFactor;
double m_dDevicePixelRatio;
bool m_bStartWithFullScreen;
mixxx::ScreenSaverPreference m_screensaverMode;

Expand Down
10 changes: 8 additions & 2 deletions src/skin/skinloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ QString SkinLoader::getSkinPath(const QString& skinName) const {
return QString();
}

QPixmap SkinLoader::getSkinPreview(const QString& skinName, const QString& schemeName) const {
QPixmap SkinLoader::getSkinPreview(const QString& skinName,
const QString& schemeName,
const double devicePixelRatio) const {
QPixmap preview;
if (!schemeName.isEmpty()) {
QString schemeNameUnformatted = schemeName;
Expand All @@ -72,7 +74,11 @@ QPixmap SkinLoader::getSkinPreview(const QString& skinName, const QString& schem
if (preview.isNull()) {
preview.load(":/images/skin_preview_placeholder.png");
}
preview = preview.scaled(QSize(640, 360), Qt::KeepAspectRatio, Qt::SmoothTransformation);
QSize scaledSize(static_cast<int>(640 * devicePixelRatio),
static_cast<int>(360 * devicePixelRatio));
preview.setDevicePixelRatio(devicePixelRatio);
preview = preview.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
preview.setDevicePixelRatio(devicePixelRatio);
return preview;
}

Expand Down
4 changes: 3 additions & 1 deletion src/skin/skinloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class SkinLoader {
LaunchImage* loadLaunchImage(QWidget* pParent);

QString getSkinPath(const QString& skinName) const;
QPixmap getSkinPreview(const QString& skinName, const QString& schemeName) const;
QPixmap getSkinPreview(const QString& skinName,
const QString& schemeName,
const double devicePixelRatio) const;
QString getConfiguredSkinPath() const;
QString getDefaultSkinName() const;
QList<QDir> getSkinSearchPaths() const;
Expand Down

0 comments on commit cd6bfcf

Please sign in to comment.