Skip to content

Commit

Permalink
Improve icon display for Qt6.
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin Li <[email protected]>
  • Loading branch information
Zalafina committed Dec 23, 2022
1 parent 7722640 commit 19d50c4
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions QKeyMapper/qkeymapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,25 +1610,33 @@ void QKeyMapper::updateProcessInfoDisplay()
qDebug() << "[UpdateProcessInfo]" << "Icon availableSizes:" << iconsizeList;
#endif
QSize selectedSize = QSize(0, 0);
for(auto it = iconsizeList.crbegin(); it != iconsizeList.crend(); ++it) {
const QSize iconsize = (*it);
if ((iconsize.width() > 0)
&& (iconsize.height() > 0)){
QSize selectedSize_previous = QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
for(const QSize &iconsize : fileicon.availableSizes()){
if ((iconsize.width() >= DEFAULT_ICON_WIDTH)
&& (iconsize.height() >= DEFAULT_ICON_HEIGHT)){
selectedSize = iconsize;
break;
}
selectedSize_previous = iconsize;
}

if (selectedSize == QSize(0, 0)){
selectedSize = QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
#ifdef DEBUG_LOGOUT_ON
qDebug() << "[UpdateProcessInfo]" << "No available icon size, use previous icon size:" << selectedSize_previous;
#endif
selectedSize = selectedSize_previous;
}
else if (selectedSize.width() > DEFAULT_ICON_WIDTH || selectedSize.height() > DEFAULT_ICON_HEIGHT) {
#ifdef DEBUG_LOGOUT_ON
qDebug() << "[UpdateProcessInfo]" << "Icon resize:" << selectedSize << "->" << QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
qDebug() << "[UpdateProcessInfo]" << "Icon size larger than default, use previous icon size:" << selectedSize_previous;
#endif
selectedSize = QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
selectedSize = selectedSize_previous;
}
QPixmap IconPixmap = m_MapProcessInfo.WindowIcon.pixmap(selectedSize);
#ifdef DEBUG_LOGOUT_ON
qDebug() << "[UpdateProcessInfo]" << "Pixmap devicePixelRatio is" << IconPixmap.devicePixelRatio();
// IconPixmap.save("selecticon.png");
#endif
ui->iconLabel->setPixmap(IconPixmap);
}
else{
Expand Down Expand Up @@ -1944,25 +1952,33 @@ void QKeyMapper::on_processinfoTable_doubleClicked(const QModelIndex &index)
qDebug() << "[SelectProcessInfo]" << "Icon availableSizes:" << iconsizeList;
#endif
QSize selectedSize = QSize(0, 0);
for(auto it = iconsizeList.crbegin(); it != iconsizeList.crend(); ++it) {
const QSize iconsize = (*it);
if ((iconsize.width() > 0)
&& (iconsize.height() > 0)){
QSize selectedSize_previous = QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
for(const QSize &iconsize : fileicon.availableSizes()){
if ((iconsize.width() >= DEFAULT_ICON_WIDTH)
&& (iconsize.height() >= DEFAULT_ICON_HEIGHT)){
selectedSize = iconsize;
break;
}
selectedSize_previous = iconsize;
}

if (selectedSize == QSize(0, 0)){
selectedSize = QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
#ifdef DEBUG_LOGOUT_ON
qDebug() << "[SelectProcessInfo]" << "No available icon size, use previous icon size:" << selectedSize_previous;
#endif
selectedSize = selectedSize_previous;
}
else if (selectedSize.width() > DEFAULT_ICON_WIDTH || selectedSize.height() > DEFAULT_ICON_HEIGHT) {
#ifdef DEBUG_LOGOUT_ON
qDebug() << "[SelectProcessInfo]" << "Icon resize:" << selectedSize << "->" << QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
qDebug() << "[SelectProcessInfo]" << "Icon size larger than default, use previous icon size:" << selectedSize_previous;
#endif
selectedSize = QSize(DEFAULT_ICON_WIDTH, DEFAULT_ICON_HEIGHT);
selectedSize = selectedSize_previous;
}
QPixmap IconPixmap = m_MapProcessInfo.WindowIcon.pixmap(selectedSize);
#ifdef DEBUG_LOGOUT_ON
qDebug() << "[SelectProcessInfo]" << "Pixmap devicePixelRatio is" << IconPixmap.devicePixelRatio();
// IconPixmap.save("selecticon.png");
#endif
ui->iconLabel->setPixmap(IconPixmap);
ui->nameLineEdit->setToolTip(ProcessPath);
}
Expand Down

0 comments on commit 19d50c4

Please sign in to comment.