Skip to content

Commit

Permalink
Make pre-defined highlight columns unselectable
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-richardt committed Feb 19, 2020
1 parent 6229b2f commit d0839ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/controllers/highlights/HighlightModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);
}
Expand Down
14 changes: 10 additions & 4 deletions src/util/StandardItemHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d0839ac

Please sign in to comment.