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

skin preview: consider devicePixelRatio when scaling #3941

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 7 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,10 @@ 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);
preview = preview.scaled(QSize(640, 360) * devicePixelRatio,
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