From 6a341a520c96700af45c0b033cfefe86def0ebe4 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 5 Aug 2022 19:31:00 +0200 Subject: [PATCH] Preview ColorScheme changes like other Profile Properties The difference is the preview isn't triggered on hover, you now have to select a color scheme in the model to trigger a preview. The font selection dialog works the same way (i.e. select to preview, not just hover), and that seems to work quite well. --- src/widgets/EditProfileDialog.cpp | 50 ++----------------------------- src/widgets/EditProfileDialog.h | 9 ------ 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/src/widgets/EditProfileDialog.cpp b/src/widgets/EditProfileDialog.cpp index e3178be8..672980ba 100644 --- a/src/widgets/EditProfileDialog.cpp +++ b/src/widgets/EditProfileDialog.cpp @@ -58,7 +58,6 @@ using namespace Konsole; EditProfileDialog::EditProfileDialog(QWidget *parent) : KPageDialog(parent) - , _delayedPreviewTimer(new QTimer(this)) { setWindowTitle(i18n("Edit Profile")); setFaceType(KPageDialog::List); @@ -77,8 +76,6 @@ EditProfileDialog::EditProfileDialog(QWidget *parent) } }); - connect(_delayedPreviewTimer, &QTimer::timeout, this, &Konsole::EditProfileDialog::delayedPreviewActivate); - // Set a fallback icon for non-plasma desktops as this dialog looks // terrible without all the icons on the left sidebar. On GTK related // desktops, this dialog look good enough without installing @@ -694,11 +691,10 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr &profile) updateColorSchemeList(currentColorSchemeName()); _appearanceUi->colorSchemeList->setMouseTracking(true); - _appearanceUi->colorSchemeList->installEventFilter(this); _appearanceUi->colorSchemeList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); connect(_appearanceUi->colorSchemeList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &Konsole::EditProfileDialog::colorSchemeSelected); - connect(_appearanceUi->colorSchemeList, &QListView::entered, this, &Konsole::EditProfileDialog::previewColorScheme); + connect(_appearanceUi->colorSchemeList, &QListView::activated, this, &Konsole::EditProfileDialog::previewColorScheme); updateColorSchemeButtons(); @@ -1012,19 +1008,6 @@ void EditProfileDialog::updateKeyBindingsList(const QString &selectKeyBindingsNa } } -bool EditProfileDialog::eventFilter(QObject *watched, QEvent *event) -{ - if (watched == _appearanceUi->colorSchemeList && event->type() == QEvent::Leave) { - if (_tempProfile->isPropertySet(Profile::ColorScheme)) { - preview(Profile::ColorScheme, _tempProfile->colorScheme()); - } else { - unpreview(Profile::ColorScheme); - } - } - - return QDialog::eventFilter(watched, event); -} - QSize EditProfileDialog::sizeHint() const { QFontMetrics fm(font()); @@ -1039,9 +1022,6 @@ QSize EditProfileDialog::sizeHint() const void EditProfileDialog::unpreviewAll() { - _delayedPreviewTimer->stop(); - _delayedPreviewProperties.clear(); - Profile::PropertyMap map; QHashIterator iter(_previewedProperties); while (iter.hasNext()) { @@ -1057,8 +1037,6 @@ void EditProfileDialog::unpreviewAll() void EditProfileDialog::unpreview(int property) { - _delayedPreviewProperties.remove(property); - if (!_previewedProperties.contains(property)) { return; } @@ -1069,33 +1047,9 @@ void EditProfileDialog::unpreview(int property) _previewedProperties.remove(property); } -void EditProfileDialog::delayedPreview(int property, const QVariant &value) -{ - _delayedPreviewProperties.insert(property, value); - - _delayedPreviewTimer->stop(); - _delayedPreviewTimer->start(300); -} - -void EditProfileDialog::delayedPreviewActivate() -{ - Q_ASSERT(_delayedPreviewTimer); - - QMutableHashIterator iter(_delayedPreviewProperties); - if (iter.hasNext()) { - iter.next(); - preview(iter.key(), iter.value()); - } -} - void EditProfileDialog::preview(int property, const QVariant &value) { - // Copy "value" into the map before removing the key/value pair - // from _delayedPreviewProperties const Profile::PropertyMap map{{static_cast(property), value}}; - - _delayedPreviewProperties.remove(property); - const Profile::Ptr original = lookupProfile(); // skip previews for profile groups if the profiles in the group @@ -1118,7 +1072,7 @@ void EditProfileDialog::preview(int property, const QVariant &value) void EditProfileDialog::previewColorScheme(const QModelIndex &index) { const QString &name = index.data(Qt::UserRole + 1).value>()->name(); - delayedPreview(Profile::ColorScheme, name); + preview(Profile::ColorScheme, name); } void EditProfileDialog::showFontDialog() diff --git a/src/widgets/EditProfileDialog.h b/src/widgets/EditProfileDialog.h index 1cc9c3ae..49fc9489 100644 --- a/src/widgets/EditProfileDialog.h +++ b/src/widgets/EditProfileDialog.h @@ -100,9 +100,6 @@ public Q_SLOTS: // reimplemented void reject() override; -protected: - bool eventFilter(QObject *watched, QEvent *event) override; - private Q_SLOTS: QSize sizeHint() const override; @@ -220,9 +217,6 @@ private Q_SLOTS: void setDefaultCodec(QTextCodec *); - // apply the first previewed changes stored up by delayedPreview() - void delayedPreviewActivate(); - void setTextEditorCombo(const Profile::Ptr &profile); void toggleAllowLinkEscapeSequence(bool); @@ -279,7 +273,6 @@ private: void closeColorSchemeEditor(); void preview(int property, const QVariant &value); - void delayedPreview(int property, const QVariant &value); void unpreview(int property); void unpreviewAll(); void enableIfNonEmptySelection(QWidget *widget, QItemSelectionModel *selectionModel); @@ -353,8 +346,6 @@ private: QHash _previewedProperties; - QHash _delayedPreviewProperties; - QTimer *_delayedPreviewTimer = nullptr; ColorSchemeEditor *_colorDialog = nullptr; QDialogButtonBox *_buttonBox = nullptr;