From d0839ac36ee3b6b2492c54f344d8ca31d2bea814 Mon Sep 17 00:00:00 2001 From: Leon Richardt Date: Thu, 20 Feb 2020 00:10:10 +0100 Subject: [PATCH] Make pre-defined highlight columns unselectable Fixes #1539. --- src/controllers/highlights/HighlightModel.cpp | 12 ++++++------ src/util/StandardItemHelper.hpp | 14 ++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index 05f37bf78..ef134c12d 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -63,10 +63,10 @@ void HighlightModel::afterInit() usernameRow[Column::CaseSensitive]->setFlags(0); QUrl selfSound = QUrl(getSettings()->selfHighlightSoundUrl.getValue()); - setFilePathItem(usernameRow[Column::SoundPath], selfSound); + setFilePathItem(usernameRow[Column::SoundPath], selfSound, false); auto selfColor = ColorProvider::instance().color(ColorType::SelfHighlight); - setColorItem(usernameRow[Column::Color], *selfColor); + setColorItem(usernameRow[Column::Color], *selfColor, false); this->insertCustomRow(usernameRow, 0); @@ -86,10 +86,10 @@ void HighlightModel::afterInit() QUrl whisperSound = QUrl(getSettings()->whisperHighlightSoundUrl.getValue()); - setFilePathItem(whisperRow[Column::SoundPath], whisperSound); + setFilePathItem(whisperRow[Column::SoundPath], whisperSound, false); auto whisperColor = ColorProvider::instance().color(ColorType::Whisper); - setColorItem(whisperRow[Column::Color], *whisperColor); + setColorItem(whisperRow[Column::Color], *whisperColor, false); this->insertCustomRow(whisperRow, 1); @@ -107,10 +107,10 @@ void HighlightModel::afterInit() subRow[Column::CaseSensitive]->setFlags(0); QUrl subSound = QUrl(getSettings()->subHighlightSoundUrl.getValue()); - setFilePathItem(subRow[Column::SoundPath], subSound); + setFilePathItem(subRow[Column::SoundPath], subSound, false); auto subColor = ColorProvider::instance().color(ColorType::Subscription); - setColorItem(subRow[Column::Color], *subColor); + setColorItem(subRow[Column::Color], *subColor, false); this->insertCustomRow(subRow, 2); } diff --git a/src/util/StandardItemHelper.hpp b/src/util/StandardItemHelper.hpp index 4b7ba52b9..47e4db14b 100644 --- a/src/util/StandardItemHelper.hpp +++ b/src/util/StandardItemHelper.hpp @@ -22,17 +22,23 @@ static void setStringItem(QStandardItem *item, const QString &value, (editable ? (Qt::ItemIsEditable) : 0))); } -static void setFilePathItem(QStandardItem *item, const QUrl &value) +static void setFilePathItem(QStandardItem *item, const QUrl &value, + bool selectable = true) { item->setData(value, Qt::UserRole); item->setData(value.fileName(), Qt::DisplayRole); - item->setFlags(Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable)); + item->setFlags( + Qt::ItemFlags(Qt::ItemIsEnabled | + (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); } -static void setColorItem(QStandardItem *item, const QColor &value) +static void setColorItem(QStandardItem *item, const QColor &value, + bool selectable = true) { item->setData(value, Qt::DecorationRole); - item->setFlags(Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable)); + item->setFlags( + Qt::ItemFlags(Qt::ItemIsEnabled | + (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); } static QStandardItem *emptyItem()