make highlighting ALSO work actually properly
This commit is contained in:
parent
d38ea35cd3
commit
eaf901fd9f
3 changed files with 79 additions and 46 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "database/databasefactory.h"
|
#include "database/databasefactory.h"
|
||||||
#include "database/databasequeries.h"
|
#include "database/databasequeries.h"
|
||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
|
#include "definitions/globals.h"
|
||||||
#include "gui/messagesview.h"
|
#include "gui/messagesview.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
@ -468,34 +469,30 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
case Qt::ItemDataRole::ForegroundRole:
|
case Qt::ItemDataRole::ForegroundRole:
|
||||||
case HIGHLIGHTED_FOREGROUND_TITLE_ROLE:
|
case HIGHLIGHTED_FOREGROUND_TITLE_ROLE: {
|
||||||
switch (m_messageHighlighter) {
|
if (Globals::hasFlag(m_messageHighlighter, MessageHighlighter::HighlightImportant)) {
|
||||||
case MessageHighlighter::HighlightImportant: {
|
|
||||||
QModelIndex idx_important = index(idx.row(), MSG_DB_IMPORTANT_INDEX);
|
QModelIndex idx_important = index(idx.row(), MSG_DB_IMPORTANT_INDEX);
|
||||||
QVariant dta = m_cache->containsData(idx_important.row()) ? m_cache->data(idx_important)
|
QVariant dta = m_cache->containsData(idx_important.row()) ? m_cache->data(idx_important)
|
||||||
: QSqlQueryModel::data(idx_important);
|
: QSqlQueryModel::data(idx_important);
|
||||||
|
|
||||||
return dta.toInt() == 1
|
if (dta.toInt() == 1) {
|
||||||
? qApp->skins()->currentSkin().colorForModel(role == Qt::ItemDataRole::ForegroundRole
|
return qApp->skins()->currentSkin().colorForModel(role == Qt::ItemDataRole::ForegroundRole
|
||||||
? SkinEnums::PaletteColors::FgInteresting
|
? SkinEnums::PaletteColors::FgInteresting
|
||||||
: SkinEnums::PaletteColors::FgSelectedInteresting)
|
: SkinEnums::PaletteColors::FgSelectedInteresting);
|
||||||
: QVariant();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case MessageHighlighter::HighlightUnread: {
|
if (Globals::hasFlag(m_messageHighlighter, MessageHighlighter::HighlightUnread)) {
|
||||||
QModelIndex idx_read = index(idx.row(), MSG_DB_READ_INDEX);
|
QModelIndex idx_read = index(idx.row(), MSG_DB_READ_INDEX);
|
||||||
QVariant dta =
|
QVariant dta = m_cache->containsData(idx_read.row()) ? m_cache->data(idx_read) : QSqlQueryModel::data(idx_read);
|
||||||
m_cache->containsData(idx_read.row()) ? m_cache->data(idx_read) : QSqlQueryModel::data(idx_read);
|
|
||||||
|
|
||||||
return dta.toInt() == 0
|
if (dta.toInt() == 0) {
|
||||||
? qApp->skins()->currentSkin().colorForModel(role == Qt::ItemDataRole::ForegroundRole
|
return qApp->skins()->currentSkin().colorForModel(role == Qt::ItemDataRole::ForegroundRole
|
||||||
? SkinEnums::PaletteColors::FgInteresting
|
? SkinEnums::PaletteColors::FgInteresting
|
||||||
: SkinEnums::PaletteColors::FgSelectedInteresting)
|
: SkinEnums::PaletteColors::FgSelectedInteresting);
|
||||||
: QVariant();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case MessageHighlighter::NoHighlighting:
|
|
||||||
default:
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer {
|
||||||
public:
|
public:
|
||||||
// Enum which describes basic highlighting schemes
|
// Enum which describes basic highlighting schemes
|
||||||
// for messages.
|
// for messages.
|
||||||
enum class MessageHighlighter { NoHighlighting = 100, HighlightUnread = 101, HighlightImportant = 102 };
|
enum class MessageHighlighter { NoHighlighting = 1, HighlightUnread = 2, HighlightImportant = 4 };
|
||||||
|
|
||||||
enum class MessageUnreadIcon { Dot = 1, Envelope = 2, FeedIcon = 3 };
|
enum class MessageUnreadIcon { Dot = 1, Envelope = 2, FeedIcon = 3 };
|
||||||
|
|
||||||
|
|
|
@ -105,43 +105,79 @@ void MessagesToolBar::loadSpecificActions(const QList<QAction*>& actions, bool i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesToolBar::handleMessageHighlighterChange(QAction* action) {
|
|
||||||
m_btnMessageHighlighter->setDefaultAction(action);
|
|
||||||
saveToolButtonSelection(HIGHLIGHTER_ACTION_NAME, {action});
|
|
||||||
|
|
||||||
emit messageHighlighterChanged(action->data().value<MessagesModel::MessageHighlighter>());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline MessagesProxyModel::MessageListFilter operator|(MessagesProxyModel::MessageListFilter a,
|
inline MessagesProxyModel::MessageListFilter operator|(MessagesProxyModel::MessageListFilter a,
|
||||||
MessagesProxyModel::MessageListFilter b) {
|
MessagesProxyModel::MessageListFilter b) {
|
||||||
return static_cast<MessagesProxyModel::MessageListFilter>(static_cast<int>(a) | static_cast<int>(b));
|
return static_cast<MessagesProxyModel::MessageListFilter>(static_cast<int>(a) | static_cast<int>(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline MessagesModel::MessageHighlighter operator|(MessagesModel::MessageHighlighter a,
|
||||||
|
MessagesModel::MessageHighlighter b) {
|
||||||
|
return static_cast<MessagesModel::MessageHighlighter>(static_cast<int>(a) | static_cast<int>(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessagesToolBar::handleMessageHighlighterChange(QAction* action) {
|
||||||
|
MessagesModel::MessageHighlighter task = action->data().value<MessagesModel::MessageHighlighter>();
|
||||||
|
|
||||||
|
m_btnMessageHighlighter->setDefaultAction(action);
|
||||||
|
|
||||||
|
std::list<QAction*> checked_tasks_std;
|
||||||
|
|
||||||
|
if (task == MessagesModel::MessageHighlighter::NoHighlighting) {
|
||||||
|
checked_tasks_std.push_back(m_menuMessageHighlighter->actions().first());
|
||||||
|
|
||||||
|
// Uncheck everything.
|
||||||
|
m_menuMessageHighlighter->blockSignals(true);
|
||||||
|
|
||||||
|
for (QAction* tsk : m_menuMessageHighlighter->actions()) {
|
||||||
|
tsk->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_menuMessageHighlighter->blockSignals(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
task = MessagesModel::MessageHighlighter(0);
|
||||||
|
checked_tasks_std = boolinq::from(m_menuMessageHighlighter->actions())
|
||||||
|
.where([](QAction* act) {
|
||||||
|
return act->isChecked();
|
||||||
|
})
|
||||||
|
.toStdList();
|
||||||
|
|
||||||
|
for (QAction* tsk : checked_tasks_std) {
|
||||||
|
task = task | tsk->data().value<MessagesModel::MessageHighlighter>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveToolButtonSelection(HIGHLIGHTER_ACTION_NAME, FROM_STD_LIST(QList<QAction*>, checked_tasks_std));
|
||||||
|
emit messageHighlighterChanged(task);
|
||||||
|
}
|
||||||
|
|
||||||
void MessagesToolBar::handleMessageFilterChange(QAction* action) {
|
void MessagesToolBar::handleMessageFilterChange(QAction* action) {
|
||||||
MessagesProxyModel::MessageListFilter task = action->data().value<MessagesProxyModel::MessageListFilter>();
|
MessagesProxyModel::MessageListFilter task = action->data().value<MessagesProxyModel::MessageListFilter>();
|
||||||
|
|
||||||
m_btnMessageFilter->setDefaultAction(action);
|
m_btnMessageFilter->setDefaultAction(action);
|
||||||
|
|
||||||
auto checked_tasks_std = boolinq::from(m_menuMessageFilter->actions())
|
std::list<QAction*> checked_tasks_std;
|
||||||
|
|
||||||
|
if (task == MessagesProxyModel::MessageListFilter::NoFiltering) {
|
||||||
|
checked_tasks_std.push_back(m_menuMessageFilter->actions().first());
|
||||||
|
|
||||||
|
// Uncheck everything.
|
||||||
|
m_menuMessageFilter->blockSignals(true);
|
||||||
|
|
||||||
|
for (QAction* tsk : m_menuMessageFilter->actions()) {
|
||||||
|
tsk->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_menuMessageFilter->blockSignals(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
task = MessagesProxyModel::MessageListFilter(0);
|
||||||
|
checked_tasks_std = boolinq::from(m_menuMessageFilter->actions())
|
||||||
.where([](QAction* act) {
|
.where([](QAction* act) {
|
||||||
return act->isChecked();
|
return act->isChecked();
|
||||||
})
|
})
|
||||||
.toStdList();
|
.toStdList();
|
||||||
|
|
||||||
if (task == MessagesProxyModel::MessageListFilter::NoFiltering) {
|
|
||||||
// Uncheck everything.
|
|
||||||
m_menuMessageFilter->blockSignals(true);
|
|
||||||
|
|
||||||
for (QAction* tsk : checked_tasks_std) {
|
|
||||||
tsk->setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_menuMessageFilter->blockSignals(false);
|
|
||||||
|
|
||||||
checked_tasks_std.clear();
|
|
||||||
checked_tasks_std.push_back(m_menuMessageFilter->actions().first());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (QAction* tsk : checked_tasks_std) {
|
for (QAction* tsk : checked_tasks_std) {
|
||||||
task = task | tsk->data().value<MessagesProxyModel::MessageListFilter>();
|
task = task | tsk->data().value<MessagesProxyModel::MessageListFilter>();
|
||||||
}
|
}
|
||||||
|
@ -263,14 +299,14 @@ void MessagesToolBar::initializeHighlighter() {
|
||||||
m_btnMessageHighlighter = new QToolButton(this);
|
m_btnMessageHighlighter = new QToolButton(this);
|
||||||
m_btnMessageHighlighter->setToolTip(tr("Display all articles"));
|
m_btnMessageHighlighter->setToolTip(tr("Display all articles"));
|
||||||
m_btnMessageHighlighter->setMenu(m_menuMessageHighlighter);
|
m_btnMessageHighlighter->setMenu(m_menuMessageHighlighter);
|
||||||
m_btnMessageHighlighter->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup);
|
m_btnMessageHighlighter->setPopupMode(QToolButton::ToolButtonPopupMode::InstantPopup);
|
||||||
m_btnMessageHighlighter->setIcon(qApp->icons()->fromTheme(QSL("mail-mark-read")));
|
m_btnMessageHighlighter->setIcon(qApp->icons()->fromTheme(QSL("mail-mark-read")));
|
||||||
m_btnMessageHighlighter->setDefaultAction(m_menuMessageHighlighter->actions().constFirst());
|
m_btnMessageHighlighter->setDefaultAction(m_menuMessageHighlighter->actions().constFirst());
|
||||||
|
|
||||||
m_btnMessageFilter = new QToolButton(this);
|
m_btnMessageFilter = new QToolButton(this);
|
||||||
m_btnMessageFilter->setToolTip(tr("Display all articles"));
|
m_btnMessageFilter->setToolTip(tr("Display all articles"));
|
||||||
m_btnMessageFilter->setMenu(m_menuMessageFilter);
|
m_btnMessageFilter->setMenu(m_menuMessageFilter);
|
||||||
m_btnMessageFilter->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup);
|
m_btnMessageFilter->setPopupMode(QToolButton::ToolButtonPopupMode::InstantPopup);
|
||||||
m_btnMessageFilter->setIcon(qApp->icons()->fromTheme(QSL("mail-mark-read")));
|
m_btnMessageFilter->setIcon(qApp->icons()->fromTheme(QSL("mail-mark-read")));
|
||||||
m_btnMessageFilter->setDefaultAction(m_menuMessageFilter->actions().constFirst());
|
m_btnMessageFilter->setDefaultAction(m_menuMessageFilter->actions().constFirst());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue