Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:epopov:branches:openSUSE:Factory
gwenview
2002-zoomcombobox.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2002-zoomcombobox.patch of Package gwenview
diff --git a/lib/zoomcombobox/zoomcombobox.cpp b/lib/zoomcombobox/zoomcombobox.cpp index 22a49840758f1f7e918d93e4b183796dbdaa915a..f91f90b8a492dabbf34b402af48a178a888363b6 100644 --- a/lib/zoomcombobox/zoomcombobox.cpp +++ b/lib/zoomcombobox/zoomcombobox.cpp @@ -2,16 +2,14 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "zoomcombobox.h" -#include "zoomcombobox_p.h" -#include <KLocalizedString> #include <QAbstractItemView> #include <QAction> -#include <QEvent> #include <QLineEdit> -#include <QSignalBlocker> #include <QWheelEvent> +#include <KLocalizedString> + #include <cmath> bool fuzzyEqual(qreal a, qreal b) @@ -29,375 +27,248 @@ bool fuzzyGreaterEqual(qreal a, qreal b) return fuzzyEqual(a, b) || a > b; } -using namespace Gwenview; - -struct LineEditSelectionKeeper { - LineEditSelectionKeeper(QLineEdit *lineEdit) - : m_lineEdit(lineEdit) - { - Q_ASSERT(m_lineEdit); - m_cursorPos = m_lineEdit->cursorPosition(); - } - - ~LineEditSelectionKeeper() - { - m_lineEdit->end(false); - m_lineEdit->cursorBackward(true, m_lineEdit->text().length() - m_cursorPos); - } - -private: - QLineEdit *m_lineEdit; - int m_cursorPos; -}; - -ZoomValidator::ZoomValidator(qreal minimum, qreal maximum, ZoomComboBox *q, ZoomComboBoxPrivate *d, QWidget *parent) - : QValidator(parent) - , m_minimum(minimum) - , m_maximum(maximum) - , m_zoomComboBox(q) - , m_zoomComboBoxPrivate(d) +qreal textToValue(const QString &text, bool *ok) { -} + const QLocale locale; + QString fixedText = text; + fixedText.remove(locale.groupSeparator()); -ZoomValidator::~ZoomValidator() noexcept = default; + static const QRegularExpression regexPercent(QStringLiteral("^%1|%1$").arg(locale.percent())); + fixedText.remove(regexPercent); -qreal ZoomValidator::minimum() const -{ - return m_minimum; + return locale.toDouble(fixedText, ok) / 100.0; } -void ZoomValidator::setMinimum(const qreal minimum) +QString valueToText(qreal value) { - if (fuzzyEqual(m_minimum, minimum)) { - return; - } - m_minimum = minimum; - Q_EMIT changed(); -} + QLocale locale; + locale.setNumberOptions(QLocale::OmitGroupSeparator); -qreal ZoomValidator::maximum() const -{ - return m_maximum; + return i18nc("Percent value", "%1%", locale.toString(std::round(value * 100))); } -void ZoomValidator::setMaximum(const qreal maximum) -{ - if (fuzzyEqual(m_maximum, maximum)) { - return; - } - m_maximum = maximum; - Q_EMIT changed(); -} - -QValidator::State ZoomValidator::validate(QString &input, int &pos) const -{ - Q_UNUSED(pos) - if (m_zoomComboBox->findText(input, Qt::MatchFixedString) > -1) { - return QValidator::Acceptable; - } - - QString copy = input.trimmed(); - copy.remove(locale().groupSeparator()); - copy.remove(locale().percent()); - const bool startsWithNumber = copy.constBegin()->isNumber(); - - if (startsWithNumber || copy.isEmpty()) { - return QValidator::Intermediate; - } - - QValidator::State state; - bool ok = false; - int value = locale().toInt(copy, &ok); - if (!ok || value < std::ceil(m_minimum * 100) || value > std::floor(m_maximum * 100)) { - state = QValidator::Intermediate; - } else { - state = QValidator::Acceptable; - } - return state; -} - -ZoomComboBoxPrivate::ZoomComboBoxPrivate(ZoomComboBox *q) - : q_ptr(q) - , validator(new ZoomValidator(0, 0, q, this, q)) -{ -} +using namespace Gwenview; ZoomComboBox::ZoomComboBox(QWidget *parent) : QComboBox(parent) - , d_ptr(new ZoomComboBoxPrivate(this)) { - Q_D(ZoomComboBox); - - d->validator->setObjectName(QLatin1String("zoomValidator")); - setValidator(d->validator); - setEditable(true); - setInsertPolicy(QComboBox::NoInsert); - // QLocale::percent() will return a QString in Qt 6. - // Qt encourages using QString(locale().percent()) in QLocale documentation. - const int percentLength = QString(locale().percent()).length(); - setMinimumContentsLength(locale().toString(9999).length() + percentLength); - - connect(lineEdit(), &QLineEdit::textEdited, this, [this, d](const QString &text) { - const bool startsWithNumber = text.constBegin()->isNumber(); - int matchedIndex = -1; - if (startsWithNumber) { - matchedIndex = findText(text, Qt::MatchFixedString); - } else { - // check if there is more than 1 match - for (int i = 0, n = count(); i < n; ++i) { - if (itemText(i).startsWith(text, Qt::CaseInsensitive)) { - if (matchedIndex != -1) { - // there is more than 1 match - return; - } - matchedIndex = i; + setInsertPolicy(NoInsert); + + connect(this, &ZoomComboBox::editTextChanged, this, [this](const QString &text) { + if (text.isEmpty()) { + return; + } + if (findText(text, Qt::MatchStartsWith) != -1) { + // predefined values will be completed automatically + return; + } + bool ok = false; + qreal value = textToValue(text, &ok); + if (ok && value > 0 && fuzzyLessEqual(value, m_maximum)) { + // emulate autocompletion for valid values that aren't predefined + while (value < m_minimum) { + value *= 10; + if (value > m_maximum) { + // autocompletion cannot be emulated for this value + return; } } + const int cursorPos = lineEdit()->cursorPosition(); + lineEdit()->setText(valueToText(value)); + lineEdit()->cursorBackward(true, lineEdit()->text().length() - cursorPos); } - if (matchedIndex != -1) { - LineEditSelectionKeeper selectionKeeper(lineEdit()); - updateCurrentIndex(); - if (matchedIndex == currentIndex()) { - updateDisplayedText(); - } else { - activateAndChangeZoomTo(matchedIndex); - } - } else if (startsWithNumber) { - bool ok = false; - qreal value = valueFromText(text, &ok); - if (ok && value > 0 && fuzzyLessEqual(value, maximum())) { - // emulate autocompletion for valid values that aren't predefined - while (value < minimum()) { - value *= 10; - if (value > maximum()) { - // autocompletion cannot be emulated for this value - return; - } - } - LineEditSelectionKeeper selectionKeeper(lineEdit()); - if (fuzzyEqual(value, d->value)) { - updateDisplayedText(); - } else { - d->lastCustomZoomValue = value; - activateAndChangeZoomTo(-1); - } + }); + connect(this, QOverload<int>::of(&ZoomComboBox::activated), this, [this](int index) { + const QVariant data = itemData(index); + if (QAction *action = data.value<QAction *>()) { + if (!action->isCheckable() || !action->isChecked()) { + action->trigger(); } + } else { + const qreal value = data.value<qreal>(); + Q_ASSERT(fuzzyGreaterEqual(value, m_minimum) && fuzzyLessEqual(value, m_maximum)); + Q_EMIT valueChanged(value); } }); - connect(this, qOverload<int>(&ZoomComboBox::highlighted), this, &ZoomComboBox::changeZoomTo); - view()->installEventFilter(this); - connect(this, qOverload<int>(&ZoomComboBox::activated), this, &ZoomComboBox::activateAndChangeZoomTo); -} - -ZoomComboBox::~ZoomComboBox() noexcept = default; - -void ZoomComboBox::setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction) -{ - Q_D(ZoomComboBox); - d->setActions(zoomToFitAction, zoomToFillAction, actualSizeAction); - - connect(zoomToFitAction, &QAction::toggled, this, &ZoomComboBox::updateDisplayedText); - connect(zoomToFillAction, &QAction::toggled, this, &ZoomComboBox::updateDisplayedText); -} + connect(lineEdit(), &QLineEdit::editingFinished, this, [this]() { + const QString text = currentText(); + if (text.isEmpty()) { + updateCurrentText(); + return; + } + if (findText(text, Qt::MatchFixedString) != -1) { + // predefined values will be accepted automatically + return; + } + bool ok = false; + const qreal value = textToValue(text, &ok); + if (ok && !fuzzyEqual(m_value, value) && fuzzyGreaterEqual(value, m_minimum) && fuzzyLessEqual(value, m_maximum)) { + setCurrentIndex(-1); + Q_EMIT valueChanged(value); + return; + } + updateCurrentText(); + }); -void ZoomComboBoxPrivate::setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction) -{ - Q_Q(ZoomComboBox); - q->clear(); - q->addItem(zoomToFitAction->iconText(), QVariant::fromValue(zoomToFitAction)); // index = 0 - q->addItem(zoomToFillAction->iconText(), QVariant::fromValue(zoomToFillAction)); // index = 1 - q->addItem(actualSizeAction->iconText(), QVariant::fromValue(actualSizeAction)); // index will change later - - mZoomToFitAction = zoomToFitAction; - mZoomToFillAction = zoomToFillAction; - mActualSizeAction = actualSizeAction; + view()->installEventFilter(this); } qreal ZoomComboBox::value() const { - Q_D(const ZoomComboBox); - return d->value; + return m_value; } void ZoomComboBox::setValue(qreal value) { - Q_D(ZoomComboBox); - d->value = value; + if (fuzzyEqual(m_value, value)) { + return; + } - updateDisplayedText(); + m_value = value; + + updateCurrentText(); } qreal ZoomComboBox::minimum() const { - Q_D(const ZoomComboBox); - return d->validator->minimum(); + return m_minimum; } void ZoomComboBox::setMinimum(qreal minimum) { - Q_D(ZoomComboBox); - if (fuzzyEqual(this->minimum(), minimum)) { + if (fuzzyEqual(m_minimum, minimum)) { return; } - d->validator->setMinimum(minimum); - setValue(qMax(minimum, d->value)); - // Generate zoom presets below 100% - // FIXME: combobox value gets reset to last index value when this code runs - const int zoomToFillActionIndex = findData(QVariant::fromValue(d->mZoomToFillAction)); - const int actualSizeActionIndex = findData(QVariant::fromValue(d->mActualSizeAction)); - for (int i = actualSizeActionIndex - 1; i > zoomToFillActionIndex; --i) { + + m_minimum = minimum; + + setValue(std::max(m_value, m_minimum)); + + if (fuzzyLessEqual(m_maximum, m_minimum) || count() == 0) { + return; + } + + // delete old values + const int fromIndex = findData(QVariant::fromValue(m_zoomToFillAction)); + const int toIndex = findData(QVariant::fromValue(m_actualSizeAction)); + for (int i = toIndex - 1; i > fromIndex; --i) { removeItem(i); } - qreal value = minimum * 2; // The minimum zoom value itself is already available through "fit". - for (int i = zoomToFillActionIndex + 1; value < 1.0; ++i) { - insertItem(i, textFromValue(value), QVariant::fromValue(value)); - value *= 2; + + // populate with new values + int indexToInsert = fromIndex + 1; + for (qreal value = m_minimum * 2; value < 1; value *= 2) { + insertItem(indexToInsert++, valueToText(value), value); } } qreal ZoomComboBox::maximum() const { - Q_D(const ZoomComboBox); - return d->validator->maximum(); + return m_maximum; } void ZoomComboBox::setMaximum(qreal maximum) { - Q_D(ZoomComboBox); - if (fuzzyEqual(this->maximum(), maximum)) { + if (fuzzyEqual(m_maximum, maximum)) { return; } - d->validator->setMaximum(maximum); - setValue(qMin(d->value, maximum)); - // Generate zoom presets above 100% - // NOTE: This probably has the same problem as setMinimum(), - // but the problem is never enountered since max zoom doesn't actually change - const int actualSizeActionIndex = findData(QVariant::fromValue(d->mActualSizeAction)); - const int count = this->count(); - for (int i = actualSizeActionIndex + 1; i < count; ++i) { - removeItem(i); - } - qreal value = 2.0; - while (value < maximum) { - addItem(textFromValue(value), QVariant::fromValue(value)); - value *= 2; - } - if (fuzzyGreaterEqual(value, maximum)) { - addItem(textFromValue(maximum), QVariant::fromValue(maximum)); - } -} -qreal ZoomComboBox::valueFromText(const QString &text, bool *ok) const -{ - Q_D(const ZoomComboBox); + m_maximum = maximum; - const QLocale l = locale(); - QString s = text; - s.remove(l.groupSeparator()); + setValue(std::min(m_value, m_maximum)); - if (s.endsWith(l.percent())) { - s = s.chopped(1); + if (fuzzyGreaterEqual(m_minimum, m_maximum) || count() == 0) { + return; } - if (s.startsWith(l.percent())) { - s = s.remove(0, 1); + // delete old values + const int fromIndex = findData(QVariant::fromValue(m_actualSizeAction)); + for (int i = count() - 1; i > fromIndex; --i) { + removeItem(i); } - return l.toDouble(s, ok) / 100.0; + // populate with new values + for (qreal value = 2; fuzzyLessEqual(value, m_maximum); value = std::min(value * 2, m_maximum)) { + addItem(valueToText(value), value); + if (fuzzyEqual(value, m_maximum)) { + break; + } + } } -QString ZoomComboBox::textFromValue(const qreal value) const +void ZoomComboBox::setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction) { - Q_D(const ZoomComboBox); + clear(); - QLocale l = locale(); - l.setNumberOptions(QLocale::OmitGroupSeparator); + m_zoomToFitAction = zoomToFitAction; + m_zoomToFillAction = zoomToFillAction; + m_actualSizeAction = actualSizeAction; - QString formattedValue = l.toString(qRound(value * 100)); - return i18nc("Percent value", "%1%", formattedValue); -} + addItem(m_zoomToFitAction->iconText(), QVariant::fromValue(m_zoomToFitAction)); + addItem(m_zoomToFillAction->iconText(), QVariant::fromValue(m_zoomToFillAction)); + addItem(m_actualSizeAction->iconText(), QVariant::fromValue(m_actualSizeAction)); -void ZoomComboBox::updateDisplayedText() -{ - Q_D(ZoomComboBox); - if (d->mZoomToFitAction->isChecked()) { - lineEdit()->setText(d->mZoomToFitAction->iconText()); - } else if (d->mZoomToFillAction->isChecked()) { - lineEdit()->setText(d->mZoomToFillAction->iconText()); - } else if (d->mActualSizeAction->isChecked()) { - lineEdit()->setText(d->mActualSizeAction->iconText()); - } else { - lineEdit()->setText(textFromValue(d->value)); - } + updateCurrentText(); + + connect(m_zoomToFitAction, &QAction::toggled, this, &ZoomComboBox::updateCurrentText); + connect(m_zoomToFillAction, &QAction::toggled, this, &ZoomComboBox::updateCurrentText); } -void Gwenview::ZoomComboBox::showPopup() +bool ZoomComboBox::event(QEvent *event) { - updateCurrentIndex(); + switch (event->type()) { + case QEvent::ShortcutOverride: { + const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event); + if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) { + // allow lineEdit() to properly emit the editingFinished() signal + event->accept(); + } + break; + } + default: + break; + } - // We don't want to emit a QComboBox::highlighted event just because the popup is opened. - const QSignalBlocker blocker(this); - QComboBox::showPopup(); + return QComboBox::event(event); } bool ZoomComboBox::eventFilter(QObject *watched, QEvent *event) { if (watched == view()) { switch (event->type()) { - case QEvent::Hide: { - Q_D(ZoomComboBox); - changeZoomTo(d->lastSelectedIndex); - break; - } - case QEvent::ShortcutOverride: { - if (view()->isVisibleTo(this)) { - auto keyEvent = static_cast<QKeyEvent *>(event); - if (keyEvent->key() == Qt::Key_Escape) { - event->accept(); + case QEvent::ShortcutOverride: { + if (view()->isVisibleTo(this)) { + auto keyEvent = static_cast<QKeyEvent *>(event); + if (keyEvent->key() == Qt::Key_Escape) { + event->accept(); + } } + break; } - break; - } - default: - break; + default: + break; } } return QComboBox::eventFilter(watched, event); } -void ZoomComboBox::focusOutEvent(QFocusEvent *event) -{ - Q_D(ZoomComboBox); - // Should the user have started typing a custom value - // that was out of our range, then we have a temporary - // state that is illegal. This is needed to allow a user - // to type a zoom with multiple keystrokes, but when the - // user leaves focus we should reset to the last known 'good' - // zoom value. - if (d->lastSelectedIndex == -1) - setValue(d->lastCustomZoomValue); - - QComboBox::focusOutEvent(event); -} - void ZoomComboBox::keyPressEvent(QKeyEvent *event) { switch (event->key()) { - case Qt::Key_Down: - case Qt::Key_Up: - case Qt::Key_PageDown: - case Qt::Key_PageUp: { - updateCurrentIndex(); - if (currentIndex() != -1) { - break; + case Qt::Key_Down: + case Qt::Key_Up: + case Qt::Key_PageDown: + case Qt::Key_PageUp: { + if (currentIndex() != -1) { + break; + } + moveCurrentIndex(event->key() == Qt::Key_Down || event->key() == Qt::Key_PageDown); + return; } - moveCurrentIndex(event->key() == Qt::Key_Down || event->key() == Qt::Key_PageDown); - return; - } - default: - break; + default: + break; } QComboBox::keyPressEvent(event); @@ -405,9 +276,7 @@ void ZoomComboBox::keyPressEvent(QKeyEvent *event) void ZoomComboBox::wheelEvent(QWheelEvent *event) { - updateCurrentIndex(); if (currentIndex() != -1) { - // Everything should work as expected. QComboBox::wheelEvent(event); return; } @@ -415,67 +284,39 @@ void ZoomComboBox::wheelEvent(QWheelEvent *event) moveCurrentIndex(event->angleDelta().y() < 0); } -void ZoomComboBox::updateCurrentIndex() -{ - Q_D(ZoomComboBox); - - if (d->mZoomToFitAction->isChecked()) { - setCurrentIndex(0); - d->lastSelectedIndex = 0; - } else if (d->mZoomToFillAction->isChecked()) { - setCurrentIndex(1); - d->lastSelectedIndex = 1; - } else if (d->mActualSizeAction->isChecked()) { - const int actualSizeActionIndex = findData(QVariant::fromValue(d->mActualSizeAction)); - setCurrentIndex(actualSizeActionIndex); - d->lastSelectedIndex = actualSizeActionIndex; - } else { - // 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)); - setCurrentIndex(d->lastSelectedIndex); - } -} - void ZoomComboBox::moveCurrentIndex(bool moveUp) { - // There is no exact match for the current zoom value in the - // ComboBox. We need to find the closest matches, so scrolling - // works as expected. - Q_D(ZoomComboBox); + Q_ASSERT(currentIndex() == -1); int newIndex; if (moveUp) { - // switch to a larger item + // move to a larger item newIndex = count() - 1; for (int i = 2; i < newIndex; ++i) { const QVariant data = itemData(i); qreal value; - if (data.value<QAction *>() == d->mActualSizeAction) { + if (data.value<QAction *>() == m_actualSizeAction) { value = 1; } else { value = data.value<qreal>(); } - if (value > d->value) { + if (value > m_value) { newIndex = i; break; } } } else { - // switch to a smaller item + // move to a smaller item newIndex = 1; for (int i = count() - 1; i > newIndex; --i) { const QVariant data = itemData(i); qreal value; - if (data.value<QAction *>() == d->mActualSizeAction) { + if (data.value<QAction *>() == m_actualSizeAction) { value = 1; } else { value = data.value<qreal>(); } - if (value < d->value) { + if (value < m_value) { newIndex = i; break; } @@ -485,40 +326,15 @@ void ZoomComboBox::moveCurrentIndex(bool moveUp) Q_EMIT activated(newIndex); } -void ZoomComboBox::changeZoomTo(int index) -{ - if (index < 0) { - Q_D(ZoomComboBox); - Q_EMIT zoomChanged(d->lastCustomZoomValue); - return; - } - - QVariant itemData = this->itemData(index); - auto action = itemData.value<QAction *>(); - if (action) { - if (!action->isCheckable() || !action->isChecked()) { - action->trigger(); - } - } else if (itemData.canConvert(QMetaType::QReal)) { - Q_EMIT zoomChanged(itemData.toReal()); - } -} - -void ZoomComboBox::activateAndChangeZoomTo(int index) +void ZoomComboBox::updateCurrentText() { - Q_D(ZoomComboBox); - 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(); + if (m_zoomToFitAction->isChecked()) { + setCurrentText(m_zoomToFitAction->iconText()); + } else if (m_zoomToFillAction->isChecked()) { + setCurrentText(m_zoomToFillAction->iconText()); + } else if (m_actualSizeAction->isChecked()) { + setCurrentText(m_actualSizeAction->iconText()); + } else { + setCurrentText(valueToText(m_value)); } - - changeZoomTo(index); } - -#include "moc_zoomcombobox.cpp" - -#include "moc_zoomcombobox_p.cpp" diff --git a/lib/zoomcombobox/zoomcombobox.h b/lib/zoomcombobox/zoomcombobox.h index 15ef53f4e295508c54e8953724e1798f43d1711b..993dd606046b7417b6466fb84fb6a6c8b4f5ac16 100644 --- a/lib/zoomcombobox/zoomcombobox.h +++ b/lib/zoomcombobox/zoomcombobox.h @@ -5,14 +5,9 @@ #define GWENVIEW_ZOOMCOMBOBOX_H #include <QComboBox> -#include <lib/gwenviewlib_export.h> - -class QWheelEvent; namespace Gwenview { -class ZoomComboBoxPrivate; - /** * QComboBox subclass designed to be somewhat similar to QSpinBox. * Allows the user to use non-integer combobox list items, @@ -23,90 +18,44 @@ class ZoomComboBoxPrivate; * done to the visual state of this class without user interaction will not * lead to emitted zoom changes/signals from this class. */ -class GWENVIEWLIB_EXPORT ZoomComboBox : public QComboBox +class ZoomComboBox : public QComboBox { Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) - Q_PROPERTY(qreal minimum READ minimum WRITE setMinimum) - Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum) public: explicit ZoomComboBox(QWidget *parent = nullptr); - ~ZoomComboBox() override; - - void setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction); qreal value() const; - /** - * Called when the value that is being displayed should change. - * Calling this method doesn't affect the zoom of the currently viewed image. - */ - void setValue(const qreal value); + void setValue(qreal value); qreal minimum() const; - void setMinimum(const qreal minimum); + void setMinimum(qreal minimum); qreal maximum() const; - void setMaximum(const qreal maximum); - - /// Gets an integer value from text. - qreal valueFromText(const QString &text, bool *ok = nullptr) const; - - /// Gets appropriately decorated text from an integer value. - QString textFromValue(const qreal value) const; + void setMaximum(qreal maximum); - void updateDisplayedText(); - - void showPopup() override; + void setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction); Q_SIGNALS: - void zoomChanged(qreal zoom); + void valueChanged(qreal value); protected: + bool event(QEvent *event) override; bool eventFilter(QObject *watched, QEvent *event) override; - void focusOutEvent(QFocusEvent *event) override; void keyPressEvent(QKeyEvent *event) override; - - /** - * Makes sure using the mouse wheel on the combobox works as - * expected even though we sometimes programmatically change - * the currentIndex() of this ComboBox. - * @see updateCurrentIndex() - */ void wheelEvent(QWheelEvent *event) override; private: - /** - * The current index is the row in the popup of the ComboBox that is - * highlighted. - * This method updates the current index so it matches the current zoom - * state of the application. - * If the zoom value that is currently used doesn't exist as a row in - * the ComboBox, the currentIndex is set to -1 which hides the highlight. - */ - void updateCurrentIndex(); - void moveCurrentIndex(bool moveUp); + void updateCurrentText(); -private Q_SLOTS: - /** - * This method changes the zoom mode or value of the currently displayed image in response to - * user interaction with the Combobox' dropdown menu. - * @param index of the zoom mode or value that the user interacted with. - */ - void changeZoomTo(int index); - - /** - * Sets the index as the fallback when the popup menu is closed without selection in the - * future and then calls changeZoomTo(). - * @see changeZoomTo() - */ - void activateAndChangeZoomTo(int index); + qreal m_value = 0; + qreal m_minimum = 0; + qreal m_maximum = 0; -private: - const std::unique_ptr<ZoomComboBoxPrivate> d_ptr; - Q_DECLARE_PRIVATE(ZoomComboBox) - Q_DISABLE_COPY(ZoomComboBox) + QAction *m_zoomToFitAction = nullptr; + QAction *m_zoomToFillAction = nullptr; + QAction *m_actualSizeAction = nullptr; }; } diff --git a/lib/zoomcombobox/zoomcombobox_p.h b/lib/zoomcombobox/zoomcombobox_p.h deleted file mode 100644 index 984dc4aee1d8d9dfc543fa018571e3d1a87bc804..0000000000000000000000000000000000000000 --- a/lib/zoomcombobox/zoomcombobox_p.h +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com> -// SPDX-License-Identifier: LGPL-2.1-or-later - -#ifndef GWENVIEW_ZOOMCOMBOBOX_P_H -#define GWENVIEW_ZOOMCOMBOBOX_P_H - -#include "zoomcombobox.h" - -namespace Gwenview -{ -class ZoomValidator : public QValidator -{ - Q_OBJECT - Q_PROPERTY(qreal minimum READ minimum WRITE setMinimum NOTIFY changed) - Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum NOTIFY changed) -public: - explicit ZoomValidator(qreal minimum, qreal maximum, ZoomComboBox *q, ZoomComboBoxPrivate *d, QWidget *parent = nullptr); - ~ZoomValidator() override; - - qreal minimum() const; - void setMinimum(const qreal minimum); - - qreal maximum() const; - void setMaximum(const qreal maximum); - - QValidator::State validate(QString &input, int &pos) const override; - -private: - qreal m_minimum; - qreal m_maximum; - ZoomComboBox *m_zoomComboBox; - ZoomComboBoxPrivate *m_zoomComboBoxPrivate; - Q_DISABLE_COPY(ZoomValidator) -}; - -class ZoomComboBoxPrivate -{ - Q_DECLARE_PUBLIC(ZoomComboBox) - -public: - ZoomComboBoxPrivate(ZoomComboBox *q); - - void setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction); - -public: - ZoomComboBox *const q_ptr; - - QAction *mZoomToFitAction = nullptr; - QAction *mZoomToFillAction = nullptr; - QAction *mActualSizeAction = nullptr; - - qreal value = 1.0; - ZoomValidator *validator = nullptr; - int lastSelectedIndex = 0; - qreal lastCustomZoomValue = 1.0; -}; - -} - -#endif // GWENVIEW_ZOOMCOMBOBOX_P_H diff --git a/lib/zoomwidget.cpp b/lib/zoomwidget.cpp index c38bf8bffe7ce9bf804d3abd5798362f365ccf29..8df024459080bde69e6482b422055e92f171cc53 100644 --- a/lib/zoomwidget.cpp +++ b/lib/zoomwidget.cpp @@ -88,7 +88,7 @@ ZoomWidget::ZoomWidget(QWidget *parent) connect(d->mZoomSlider->slider(), &QAbstractSlider::actionTriggered, this, &ZoomWidget::slotZoomSliderActionTriggered); d->mZoomComboBox = new ZoomComboBox(this); - connect(d->mZoomComboBox, &ZoomComboBox::zoomChanged, this, &ZoomWidget::zoomChanged); + connect(d->mZoomComboBox, &ZoomComboBox::valueChanged, this, &ZoomWidget::zoomChanged); // Layout auto layout = new QHBoxLayout(this);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor