Commit 6a341a52 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

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.
parent d6706efc
......@@ -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<int, QVariant> 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<int, QVariant> 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<Profile::Property>(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<std::shared_ptr<const ColorScheme>>()->name();
delayedPreview(Profile::ColorScheme, name);
preview(Profile::ColorScheme, name);
}
void EditProfileDialog::showFontDialog()
......
......@@ -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<int, QVariant> _previewedProperties;
QHash<int, QVariant> _delayedPreviewProperties;
QTimer *_delayedPreviewTimer = nullptr;
ColorSchemeEditor *_colorDialog = nullptr;
QDialogButtonBox *_buttonBox = nullptr;
......
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