Qt: Show tooltip when adjusting icon/cover scale (#3563)

* Qt: Show tooltip when adjusting icon/cover scale

* Qt: removed tooltip on hover, handle zoom via View menu and more

- Tooltip only shows when changing the scale;
- "View > Zoom In/Out" also works for the list view;
- Grid View scale percentage display value adjusted (10%-200%);
- Added translation support for the scale tooltip;
pull/3566/head
Ariel Nogueira Kovaljski 1 month ago committed by GitHub
parent b95f2b16f2
commit c6666a388f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -31,6 +31,7 @@
#include <QtWidgets/QMenu>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QToolTip>
#include <algorithm>
#include <limits>
@ -46,6 +47,7 @@ static constexpr int ICON_SIZE_STEP = 4;
static constexpr int MIN_ICON_SIZE = 16;
static constexpr int MAX_ICON_SIZE = 80;
static constexpr float MIN_COVER_SCALE = 0.1f;
static constexpr float DEFAULT_COVER_SCALE = 0.45f;
static constexpr float MAX_COVER_SCALE = 2.0f;
static const char* SUPPORTED_FORMATS_STRING =
@ -145,7 +147,7 @@ GameListModel::GameListModel(GameListWidget* parent)
: QAbstractTableModel(parent), m_device_pixel_ratio(QtUtils::GetDevicePixelRatioForWidget(parent)),
m_icon_pixmap_cache(MIN_COVER_CACHE_SIZE)
{
m_cover_scale = Host::GetBaseFloatSettingValue("UI", "GameListCoverArtScale", 0.45f);
m_cover_scale = Host::GetBaseFloatSettingValue("UI", "GameListCoverArtScale", DEFAULT_COVER_SCALE);
m_icon_size = Host::GetBaseFloatSettingValue("UI", "GameListIconSize", MIN_ICON_SIZE);
m_show_localized_titles = GameList::ShouldShowLocalizedTitles();
m_show_titles_for_covers = Host::GetBaseBoolSettingValue("UI", "GameListShowCoverTitles", true);
@ -1374,6 +1376,7 @@ void GameListWidget::initialize(QAction* actionGameList, QAction* actionGameGrid
m_ui.showGridTitles->setDefaultAction(actionGridShowTitles);
m_ui.showLocalizedTitles->setDefaultAction(actionShowLocalizedTitles);
connect(m_ui.scale, &QSlider::sliderPressed, this, &GameListWidget::showScaleToolTip);
connect(m_ui.scale, &QSlider::valueChanged, this, &GameListWidget::onScaleSliderChanged);
connect(m_ui.filterType, &QComboBox::currentIndexChanged, this, [this](int index) {
m_sort_model->setFilterType((index == 0) ? GameList::EntryType::MaxCount :
@ -1721,6 +1724,15 @@ void GameListWidget::setViewMode(int stack_index)
}
}
void GameListWidget::showScaleToolTip()
{
const int value = m_ui.scale->value();
if (isShowingGameGrid())
QToolTip::showText(QCursor::pos(), tr("Cover scale: %1%").arg(value));
else if (isShowingGameList())
QToolTip::showText(QCursor::pos(), tr("Icon size: %1%").arg((value * 100) / ICON_SIZE_STEP));
}
void GameListWidget::onScaleSliderChanged(int value)
{
if (isShowingGameGrid())
@ -1739,6 +1751,7 @@ void GameListWidget::onScaleChanged()
QSignalBlocker sb(m_ui.scale);
m_ui.scale->setValue(value);
showScaleToolTip();
}
void GameListWidget::onIconSizeChanged(int size)
@ -2010,6 +2023,16 @@ void GameListListView::adjustIconSize(int delta)
m_model->setIconSize(new_size);
}
void GameListListView::zoomIn()
{
adjustIconSize(ICON_SIZE_STEP);
}
void GameListListView::zoomOut()
{
adjustIconSize(-ICON_SIZE_STEP);
}
GameListGridView::GameListGridView(GameListModel* model, GameListSortModel* sort_model, QWidget* parent)
: QListView(parent), m_model(model)
{

@ -177,6 +177,10 @@ public:
void setFixedColumnWidth(const QFontMetrics& fm, int column, int str_width);
void setAndSaveColumnHidden(int column, bool hidden);
public Q_SLOTS:
void zoomOut();
void zoomIn();
protected:
void wheelEvent(QWheelEvent* e) override;
@ -265,6 +269,7 @@ private Q_SLOTS:
void onRefreshProgress(const QString& status, int current, int total, int entry_count, float time);
void onRefreshComplete();
void showScaleToolTip();
void onScaleSliderChanged(int value);
void onScaleChanged();
void onIconSizeChanged(int size);

@ -1455,15 +1455,25 @@ void MainWindow::onViewSystemDisplayTriggered()
switchToEmulationView();
}
void MainWindow::onViewGameGridZoomInActionTriggered()
void MainWindow::onViewZoomInActionTriggered()
{
if (isShowingGameList())
if (!isShowingGameList())
return;
if (m_game_list_widget->isShowingGameList())
m_game_list_widget->getListView()->zoomIn();
else if (m_game_list_widget->isShowingGameGrid())
m_game_list_widget->getGridView()->zoomIn();
}
void MainWindow::onViewGameGridZoomOutActionTriggered()
void MainWindow::onViewZoomOutActionTriggered()
{
if (isShowingGameList())
if (!isShowingGameList())
return;
if (m_game_list_widget->isShowingGameList())
m_game_list_widget->getListView()->zoomOut();
else if (m_game_list_widget->isShowingGameGrid())
m_game_list_widget->getGridView()->zoomOut();
}
@ -1826,10 +1836,10 @@ void MainWindow::setupAdditionalUi()
m_shortcuts.game_list_search->setKeys(QKeySequence::keyBindings(QKeySequence::Find) +
QKeySequence::keyBindings(QKeySequence::FindNext));
connect(m_shortcuts.game_list_search, &QShortcut::activated, m_game_list_widget, &GameListWidget::focusSearchWidget);
m_shortcuts.game_grid_zoom_in =
new QShortcut(QKeySequence::ZoomIn, this, this, &MainWindow::onViewGameGridZoomInActionTriggered);
m_shortcuts.game_grid_zoom_out =
new QShortcut(QKeySequence::ZoomOut, this, this, &MainWindow::onViewGameGridZoomOutActionTriggered);
m_shortcuts.game_list_zoom_in =
new QShortcut(QKeySequence::ZoomIn, this, this, &MainWindow::onViewZoomInActionTriggered);
m_shortcuts.game_list_zoom_out =
new QShortcut(QKeySequence::ZoomOut, this, this, &MainWindow::onViewZoomOutActionTriggered);
s_disable_window_rounded_corners = Host::GetBaseBoolSettingValue("Main", "DisableWindowRoundedCorners", false);
if (s_disable_window_rounded_corners)
@ -2096,8 +2106,8 @@ void MainWindow::updateShortcutActions(bool starting)
m_shortcuts.open_file->setEnabled(!starting_or_running);
m_shortcuts.game_list_refresh->setEnabled(is_showing_game_list);
m_shortcuts.game_list_search->setEnabled(is_showing_game_list);
m_shortcuts.game_grid_zoom_in->setEnabled(is_showing_game_list);
m_shortcuts.game_grid_zoom_out->setEnabled(is_showing_game_list);
m_shortcuts.game_list_zoom_in->setEnabled(is_showing_game_list);
m_shortcuts.game_list_zoom_out->setEnabled(is_showing_game_list);
}
void MainWindow::updateStatusBarWidgetVisibility()
@ -2368,8 +2378,8 @@ void MainWindow::connectSignals()
&GameListWidget::setShowLocalizedTitles);
connect(m_ui.actionShowGameIcons, &QAction::triggered, m_game_list_widget, &GameListWidget::setShowGameIcons);
connect(m_ui.actionGridViewShowTitles, &QAction::triggered, m_game_list_widget, &GameListWidget::setShowCoverTitles);
connect(m_ui.actionGridViewZoomIn, &QAction::triggered, this, &MainWindow::onViewGameGridZoomInActionTriggered);
connect(m_ui.actionGridViewZoomOut, &QAction::triggered, this, &MainWindow::onViewGameGridZoomOutActionTriggered);
connect(m_ui.actionViewZoomIn, &QAction::triggered, this, &MainWindow::onViewZoomInActionTriggered);
connect(m_ui.actionViewZoomOut, &QAction::triggered, this, &MainWindow::onViewZoomOutActionTriggered);
connect(m_ui.actionGridViewRefreshCovers, &QAction::triggered, m_game_list_widget,
&GameListWidget::refreshGridCovers);
connect(m_ui.actionViewRefreshAchievementProgress, &QAction::triggered, g_emu_thread,

@ -198,8 +198,8 @@ private Q_SLOTS:
void onViewGameListActionTriggered();
void onViewGameGridActionTriggered();
void onViewSystemDisplayTriggered();
void onViewGameGridZoomInActionTriggered();
void onViewGameGridZoomOutActionTriggered();
void onViewZoomInActionTriggered();
void onViewZoomOutActionTriggered();
void onGitHubRepositoryActionTriggered();
void onIssueTrackerActionTriggered();
void onDiscordServerActionTriggered();
@ -328,8 +328,8 @@ private:
QShortcut* open_file = nullptr;
QShortcut* game_list_refresh = nullptr;
QShortcut* game_list_search = nullptr;
QShortcut* game_grid_zoom_in = nullptr;
QShortcut* game_grid_zoom_out = nullptr;
QShortcut* game_list_zoom_in = nullptr;
QShortcut* game_list_zoom_out = nullptr;
} m_shortcuts;
SettingsWindow* m_settings_window = nullptr;

@ -215,8 +215,8 @@
<addaction name="actionShowLocalizedTitles"/>
<addaction name="actionShowGameIcons"/>
<addaction name="actionGridViewShowTitles"/>
<addaction name="actionGridViewZoomIn"/>
<addaction name="actionGridViewZoomOut"/>
<addaction name="actionViewZoomIn"/>
<addaction name="actionViewZoomOut"/>
<addaction name="actionGridViewRefreshCovers"/>
<addaction name="actionViewRefreshAchievementProgress"/>
<addaction name="separator"/>
@ -874,14 +874,14 @@
<string>Show Titles</string>
</property>
</action>
<action name="actionGridViewZoomIn">
<action name="actionViewZoomIn">
<property name="text">
<string>Zoom &amp;In (Grid View)</string>
<string>Zoom &amp;In</string>
</property>
</action>
<action name="actionGridViewZoomOut">
<action name="actionViewZoomOut">
<property name="text">
<string>Zoom &amp;Out (Grid View)</string>
<string>Zoom &amp;Out</string>
</property>
</action>
<action name="actionGridViewRefreshCovers">

Loading…
Cancel
Save