Commit 514e35ae authored by Felix Ernst's avatar Felix Ernst 🇺🇦
Browse files

Don't change the zoom value unless the user made a selection

This is a fix for a feature that was recently introduced.

The ZoomComboBox in the very bottom right of the Gwenview main
window can be used to select different zoom values. The zoom values
are changed when they are hovered so users have a way to know
which zoom these values correspond to in relation to the size of
the currently viewed image.

Unfortunately when a user hovered any option and then closed
the popup without making a selection, the zoom value wasn't
correctly reset to the zoom value that was used before the popup
was opened. This commit fixes this.

This commit also makes it so when the popup is opened, the option
that corresponds to the current zoom value is highlighted. If the
current zoom value doesn't exist as an option in the popup,
nothing is highlighted by default.

BUG: 441004
FIXED-IN: 21.12
parent e8efe118
......@@ -260,10 +260,7 @@ void ZoomComboBox::updateDisplayedText()
} else if (d->mActualSizeAction->isChecked()) {
} else {
const QString currentZoomValueText(textFromValue(d->value));
d->lastSelectedIndex = -1;
d->lastCustomZoomValue = d->value;
......@@ -287,13 +284,24 @@ void ZoomComboBox::mousePressEvent(QMouseEvent *event)
d->lastSelectedIndex = 1;
} else if (d->mActualSizeAction->isChecked()) {
d->lastSelectedIndex = 2;
const int actualSizeActionIndex = findData(QVariant::fromValue(d->mActualSizeAction));
d->lastSelectedIndex = actualSizeActionIndex;
} else {
d->lastSelectedIndex = -1;
// Now is a good time to save the zoom value that was selected before the user changes it through the popup.
d->lastCustomZoomValue = d->value;
// Highlight the correct index if the current zoom value exists as an option in the popup.
// If it doesn't exist, it is set to -1.
d->lastSelectedIndex = findText(textFromValue(d->value));
// We don't want to emit a QComboBox::highlighted event just because the popup is opened.
const bool previousSignalsBlockedState = signalsBlocked();
void ZoomComboBox::focusOutEvent(QFocusEvent *)
......@@ -334,5 +342,13 @@ void ZoomComboBox::activateAndChangeZoomTo(int index)
d->lastSelectedIndex = index;
// The user has explicitly selected this zoom value so we
// remember it the same way as if they had typed it themselves.
QVariant itemData = this->itemData(index);
if (!itemData.value<QAction *>() && itemData.canConvert(QMetaType::QReal)) {
d->lastCustomZoomValue = itemData.toReal();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment