Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing RTL Features: Feed Titles Alignment, Tableview Layout Direction Switching, and Message Marking Read #1371

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/librssguard/core/messagesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,20 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
index_column != MSG_DB_AUTHOR_INDEX) {
return Qt::LayoutDirection::LayoutDirectionAuto;
}
else {
return (m_cache->containsData(idx.row())
? m_cache->data(index(idx.row(), MSG_DB_FEED_IS_RTL_INDEX))
: QSqlQueryModel::data(index(idx.row(), MSG_DB_FEED_IS_RTL_INDEX), Qt::ItemDataRole::EditRole))
.toInt() == 0
? Qt::LayoutDirection::LayoutDirectionAuto
: Qt::LayoutDirection::RightToLeft;
}

int isFeedRtl = (m_cache->containsData(idx.row())
? m_cache->data(index(idx.row(), MSG_DB_FEED_IS_RTL_INDEX))
: QSqlQueryModel::data(index(idx.row(), MSG_DB_FEED_IS_RTL_INDEX), Qt::ItemDataRole::EditRole)).toInt();

bool m_isSwitchEntireTableview = qApp->settings()->value(GROUP(GUI), SETTING(GUI::SwitchRtlEntireTableview)).toBool();

if (isFeedRtl == 0 && m_isSwitchEntireTableview)
return Qt::LayoutDirection::LayoutDirectionAuto;
else if (isFeedRtl == 0)
return Qt::LayoutDirection::LayoutDirectionAuto;
else
return Qt::LayoutDirection::RightToLeft;

}

case LOWER_TITLE_ROLE:
Expand Down
55 changes: 42 additions & 13 deletions src/librssguard/gui/messagesview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ void MessagesView::initializeContextMenu() {
m_contextMenu = new QMenu(tr("Context menu for articles"), this);
}

m_contextMenu->setLayoutDirection(Qt::LayoutDirection::LeftToRight);
m_contextMenu->clear();
QList<Message> selected_messages;

Expand Down Expand Up @@ -504,8 +505,10 @@ void MessagesView::selectionChanged(const QItemSelection& selected, const QItemS
// Set this message as read only if current item
// wasn't changed by "mark selected messages unread" action.
if (!m_processingRightMouseButton) {
m_sourceModel->setMessageRead(mapped_current_index.row(), RootItem::ReadStatus::Read);
message.m_isRead = true;
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::MarkMessageReadOnSelectionChange)).toBool()) {
m_sourceModel->setMessageRead(mapped_current_index.row(), RootItem::ReadStatus::Read);
message.m_isRead = true;
}
}

emit currentMessageChanged(message, m_sourceModel->loadedItem());
Expand Down Expand Up @@ -534,25 +537,51 @@ void MessagesView::loadItem(RootItem* item) {
sort(col, ord, false, true, false, true);
m_sourceModel->loadMessages(item);

/*
if (item->kind() == RootItem::Kind::Feed) {
if (item->toFeed()->isRtl()) {
setLayoutDirection(Qt::LayoutDirection::RightToLeft);
}
else {
setLayoutDirection(Qt::LayoutDirection::LeftToRight);
// Handle the direction of messages and their Tableview.
if (item != nullptr) {

Qt::LayoutDirection direction = Qt::LayoutDirection::LayoutDirectionAuto;

// Check if the current item is a category and if all child items and grandchildren are RTL feeds.
if (item->kind() == RootItem::Kind::Category) {
const QList<RootItem*> childItemsList = collectChildAndGrandchildFeeds(item);

const bool areAllChildrenRtl = std::all_of(childItemsList.begin(), childItemsList.end(), [](RootItem* childItem) {
return childItem->kind() == RootItem::Kind::Feed && childItem->toFeed()->isRtl();
});

// Set layout direction based on RTL status of child items and current item.
if (areAllChildrenRtl && qApp->settings()->value(GROUP(GUI), SETTING(GUI::SwitchRtlEntireTableview)).toBool())
direction = Qt::LayoutDirection::RightToLeft;

} else if (item->kind() == RootItem::Kind::Feed) {
if (item->toFeed()->isRtl() && qApp->settings()->value(GROUP(GUI), SETTING(GUI::SwitchRtlEntireTableview)).toBool())
direction = Qt::LayoutDirection::RightToLeft;
}

setLayoutDirection(direction);
}
else {
setLayoutDirection(Qt::LayoutDirection::LeftToRight);
}
*/

// Messages are loaded, make sure that previously
// active message is not shown in browser.
emit currentMessageRemoved(m_sourceModel->loadedItem());
}

QList<RootItem*> MessagesView::collectChildAndGrandchildFeeds(RootItem* item) {
QList<RootItem*> childItemsList;

for (RootItem *childItem : item->childItems()) {
if (childItem->kind() == RootItem::Kind::Category) {
QList<RootItem*> recursiveList = collectChildAndGrandchildFeeds(childItem);
childItemsList.append(recursiveList);
} else {
childItemsList.append(childItem);
}
}

return childItemsList;
}

void MessagesView::changeFilter(MessagesProxyModel::MessageListFilter filter) {
m_proxyModel->setMessageListFilter(filter);
reloadSelections();
Expand Down
3 changes: 3 additions & 0 deletions src/librssguard/gui/messagesview.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class MessagesView : public BaseTreeView {
// Loads un-deleted messages from selected feeds.
void loadItem(RootItem* item);

// Allow to recursively collects all child & grandchild feeds of the given RootItem.
QList<RootItem*> collectChildAndGrandchildFeeds(RootItem* item);

// Message manipulators.
#if defined(ENABLE_MEDIAPLAYER)
void playSelectedArticleInMediaPlayer();
Expand Down
16 changes: 16 additions & 0 deletions src/librssguard/gui/settings/settingsfeedsmessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
connect(m_ui->m_checkAutoUpdate, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_cbUpdateFeedListDuringFetching, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_checkAutoUpdateOnlyUnfocused, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);

connect(m_ui->m_checkSwitchRtlEntireTableview, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_checkApplyRtlFeedsTitles, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);

connect(m_ui->m_checkMarkMessageReadOnSelectionChange, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);

connect(m_ui->m_cmbUnreadIconType,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
Expand Down Expand Up @@ -281,6 +287,8 @@ void SettingsFeedsMessages::loadSettings() {
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::OnlyBasicShortcutsInLists)).toBool());
m_ui->m_cbHideCountsIfNoUnread
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::HideCountsIfNoUnread)).toBool());
m_ui->m_checkSwitchRtlEntireTableview
->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::SwitchRtlEntireTableview)).toBool());
m_ui->m_cmbUnreadIconType
->setCurrentIndex(m_ui->m_cmbUnreadIconType
->findData(settings()->value(GROUP(Messages), SETTING(Messages::UnreadIconType)).toInt()));
Expand All @@ -290,6 +298,8 @@ void SettingsFeedsMessages::loadSettings() {
.toBool());
m_ui->m_checkKeppMessagesInTheMiddle
->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::KeepCursorInCenter)).toBool());
m_ui->m_checkMarkMessageReadOnSelectionChange
->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::MarkMessageReadOnSelectionChange)).toBool());
m_ui->m_checkRemoveReadMessagesOnExit
->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool());
m_ui->m_checkAutoUpdate->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::AutoUpdateEnabled)).toBool());
Expand Down Expand Up @@ -317,6 +327,8 @@ void SettingsFeedsMessages::loadSettings() {
m_ui->m_cmbCountsFeedList->setEditText(settings()->value(GROUP(Feeds), SETTING(Feeds::CountFormat)).toString());
m_ui->m_checkShowTooltips
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::EnableTooltipsFeedsMessages)).toBool());
m_ui->m_checkApplyRtlFeedsTitles
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::ApplyRtlToFeedsTitles)).toBool());
m_ui->m_cmbIgnoreContentsChanges
->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::IgnoreContentsChanges)).toBool());
m_ui->m_checkMultilineArticleList
Expand Down Expand Up @@ -391,6 +403,8 @@ void SettingsFeedsMessages::saveSettings() {
settings()->setValue(GROUP(Feeds), Feeds::HideCountsIfNoUnread, m_ui->m_cbHideCountsIfNoUnread->isChecked());
settings()->setValue(GROUP(Messages), Messages::UnreadIconType, m_ui->m_cmbUnreadIconType->currentData().toInt());

settings()->setValue(GROUP(GUI), GUI::SwitchRtlEntireTableview, m_ui->m_checkSwitchRtlEntireTableview->isChecked());

// Make registry hack to make "show app window after external viewer called" feature
// work more reliably on Windows 10+.
#if defined(Q_OS_WIN)
Expand All @@ -415,6 +429,7 @@ void SettingsFeedsMessages::saveSettings() {
settings()->setValue(GROUP(Messages),
Messages::KeepCursorInCenter,
m_ui->m_checkKeppMessagesInTheMiddle->isChecked());
settings()->setValue(GROUP(Messages), Messages::MarkMessageReadOnSelectionChange, m_ui->m_checkMarkMessageReadOnSelectionChange->isChecked());
settings()->setValue(GROUP(Messages), Messages::ClearReadOnExit, m_ui->m_checkRemoveReadMessagesOnExit->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::AutoUpdateEnabled, m_ui->m_checkAutoUpdate->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::AutoUpdateOnlyUnfocused, m_ui->m_checkAutoUpdateOnlyUnfocused->isChecked());
Expand Down Expand Up @@ -443,6 +458,7 @@ void SettingsFeedsMessages::saveSettings() {
settings()->setValue(GROUP(Feeds), Feeds::FeedsUpdateStartupDelay, m_ui->m_spinStartupUpdateDelay->value());
settings()->setValue(GROUP(Feeds), Feeds::CountFormat, m_ui->m_cmbCountsFeedList->currentText());
settings()->setValue(GROUP(Feeds), Feeds::EnableTooltipsFeedsMessages, m_ui->m_checkShowTooltips->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::ApplyRtlToFeedsTitles, m_ui->m_checkApplyRtlFeedsTitles->isChecked());
settings()->setValue(GROUP(Messages), Messages::IgnoreContentsChanges, m_ui->m_cmbIgnoreContentsChanges->isChecked());
settings()->setValue(GROUP(Messages), Messages::MultilineArticleList, m_ui->m_checkMultilineArticleList->isChecked());
settings()->setValue(GROUP(Messages),
Expand Down
47 changes: 40 additions & 7 deletions src/librssguard/gui/settings/settingsfeedsmessages.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<item>
<widget class="QTabWidget" name="m_tabFeedsMessages">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="m_tabFeeds">
<attribute name="title">
Expand Down Expand Up @@ -266,6 +266,13 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkApplyRtlFeedsTitles">
<property name="text">
<string>Apply RTL mode to feeds titles</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbUpdateFeedListDuringFetching">
<property name="text">
Expand All @@ -281,34 +288,41 @@
</attribute>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkMarkMessageReadOnSelectionChange">
<property name="text">
<string>Mark article as read on mouse click or on keyboard up/down press</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="m_checkRemoveReadMessagesOnExit">
<property name="text">
<string>Remove all read articles from all feeds on application exit</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="m_cmbIgnoreContentsChanges">
<property name="text">
<string>Ignore changes in article body when new articles are being fetched</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbFixupArticleDatetime">
<property name="text">
<string>Fixup date/time of articles which are in the future</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QCheckBox" name="m_checkBringToForegroundAfterMsgOpened">
<property name="text">
<string>Bring application window to front once article is opened in external web browser</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Internal article viewer</string>
Expand Down Expand Up @@ -407,14 +421,14 @@
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbArticleViewerAlwaysVisible">
<property name="text">
<string>Keep article viewer always visible</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbLegacyArticleFormatting">
<property name="text">
<string>Use legacy article formatting</string>
Expand Down Expand Up @@ -650,6 +664,22 @@
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QGroupBox" name="m_gbRtlBehaviour">
<property name="title">
<string>RTL behaviour</string>
</property>
<layout class="QFormLayout" name="formLayout_21">
<item row="0" column="0">
<widget class="QCheckBox" name="m_checkSwitchRtlEntireTableview">
<property name="text">
<string>Switch messages tableview direction</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down Expand Up @@ -690,6 +720,8 @@
<tabstop>m_cbUpdateFeedListDuringFetching</tabstop>
<tabstop>m_cbListsRestrictedShortcuts</tabstop>
<tabstop>m_checkShowTooltips</tabstop>
<tabstop>m_checkApplyRtlFeedsTitles</tabstop>
<tabstop>m_checkMarkMessageReadOnSelectionChange</tabstop>
<tabstop>m_checkRemoveReadMessagesOnExit</tabstop>
<tabstop>m_cbArticleViewerAlwaysVisible</tabstop>
<tabstop>m_cmbIgnoreContentsChanges</tabstop>
Expand All @@ -712,6 +744,7 @@
<tabstop>m_tabFeedsMessages</tabstop>
<tabstop>m_gbFeedListFont</tabstop>
<tabstop>m_gbArticleListFont</tabstop>
<tabstop>m_checkSwitchRtlEntireTableview</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down
9 changes: 9 additions & 0 deletions src/librssguard/miscellaneous/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ DVALUE(char*) Feeds::CountFormatDef = "(%unread)";
DKEY Feeds::EnableTooltipsFeedsMessages = "show_tooltips";
DVALUE(bool) Feeds::EnableTooltipsFeedsMessagesDef = true;

DKEY Feeds::ApplyRtlToFeedsTitles = "apply_rtl_to_feeds_titles";
DVALUE(bool) Feeds::ApplyRtlToFeedsTitlesDef = false;

DKEY Feeds::AutoUpdateInterval = "auto_update_interval";
DVALUE(int) Feeds::AutoUpdateIntervalDef = DEFAULT_AUTO_UPDATE_INTERVAL;

Expand Down Expand Up @@ -214,6 +217,9 @@ DVALUE(bool) Messages::UseCustomTimeDef = false;
DKEY Messages::CustomTimeFormat = "custom_time_format";
DVALUE(QString) Messages::CustomTimeFormatDef = {};

DKEY Messages::MarkMessageReadOnSelectionChange = "mark_message_read_on_selection_change";
DVALUE(bool) Messages::MarkMessageReadOnSelectionChangeDef = false;

DKEY Messages::ClearReadOnExit = "clear_read_on_exit";
DVALUE(bool) Messages::ClearReadOnExitDef = false;

Expand Down Expand Up @@ -270,6 +276,9 @@ DVALUE(int) GUI::ToolbarIconSizeDef = 0;
DKEY GUI::ToolbarStyle = "toolbar_style";
DVALUE(Qt::ToolButtonStyle) GUI::ToolbarStyleDef = Qt::ToolButtonIconOnly;

DKEY GUI::SwitchRtlEntireTableview = "switch_rtl_entire_tableview";
DVALUE(bool) GUI::SwitchRtlEntireTableviewDef = true;

DKEY GUI::HeightRowMessages = "height_row_messages";
DVALUE(int) GUI::HeightRowMessagesDef = -1;

Expand Down
9 changes: 9 additions & 0 deletions src/librssguard/miscellaneous/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ namespace Feeds {
KEY EnableTooltipsFeedsMessages;
VALUE(bool) EnableTooltipsFeedsMessagesDef;

KEY ApplyRtlToFeedsTitles;
VALUE(bool) ApplyRtlToFeedsTitlesDef;

KEY AutoUpdateInterval;
VALUE(int) AutoUpdateIntervalDef;

Expand Down Expand Up @@ -160,6 +163,9 @@ namespace Messages {
KEY HoursToAvoidArticle;
VALUE(int) HoursToAvoidArticleDef;

KEY MarkMessageReadOnSelectionChange;
VALUE(bool) MarkMessageReadOnSelectionChangeDef;

KEY LimitDoNotRemoveUnread;
VALUE(bool) LimitDoNotRemoveUnreadDef;

Expand Down Expand Up @@ -374,6 +380,9 @@ namespace GUI {
KEY DefaultSortColumnFeeds;
VALUE(int) DefaultSortColumnFeedsDef;

KEY SwitchRtlEntireTableview;
VALUE(bool) SwitchRtlEntireTableviewDef;

KEY HeightRowMessages;
VALUE(int) HeightRowMessagesDef;

Expand Down
3 changes: 2 additions & 1 deletion src/librssguard/services/abstract/feed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ QVariant Feed::data(int column, int role) const {

case TEXT_DIRECTION_ROLE: {
if (column == FDS_MODEL_TITLE_INDEX) {
return isRtl() ? Qt::LayoutDirection::RightToLeft : Qt::LayoutDirection::LayoutDirectionAuto;
const bool m_areRtlFeedsTitlesApplied = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::ApplyRtlToFeedsTitles)).toBool();
return isRtl() && m_areRtlFeedsTitlesApplied ? Qt::LayoutDirection::RightToLeft : Qt::LayoutDirection::LayoutDirectionAuto;
}
else {
return Qt::LayoutDirection::LayoutDirectionAuto;
Expand Down