treeviews: set text color to default when item is selected
This ensures that the text color is properly inverted against the
selection color for better visibility.
Change-Id: I2fdacecf1ff2eac0dfd8a376cd915b0da66a2ab7
Tuleap: #41
diff --git a/src/accountview.cpp b/src/accountview.cpp
index fd6746e..0837be7 100644
--- a/src/accountview.cpp
+++ b/src/accountview.cpp
@@ -328,8 +328,15 @@
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
- G_GNUC_UNUSED gpointer data)
+ GtkTreeView *treeview)
{
+ // check if this iter is selected
+ gboolean is_selected = FALSE;
+ if (GTK_IS_TREE_VIEW(treeview)) {
+ auto selection = gtk_tree_view_get_selection(treeview);
+ is_selected = gtk_tree_selection_iter_is_selected(selection, iter);
+ }
+
gchar *display_state = NULL;
/* get account */
@@ -339,23 +346,29 @@
auto account = AccountModel::instance()->getAccountByModelIndex(idx);
auto humanState = account->toHumanStateName();
- switch (account->registrationState()) {
- case Account::RegistrationState::READY:
- display_state = g_strdup_printf("<span fgcolor=\"green\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::UNREGISTERED:
- display_state = g_strdup_printf("<span fgcolor=\"gray\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::TRYING:
- display_state = g_strdup_printf("<span fgcolor=\"orange\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::ERROR:
- display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::COUNT__:
- g_warning("registration state should never be \"count\"");
- display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
- break;
+ /* we want the color of the status text to be the default color if this iter is
+ * selected so that the treeview is able to invert it against the selection color */
+ if (is_selected) {
+ display_state = g_strdup_printf("%s", humanState.toUtf8().constData());
+ } else {
+ switch (account->registrationState()) {
+ case Account::RegistrationState::READY:
+ display_state = g_strdup_printf("<span fgcolor=\"green\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::UNREGISTERED:
+ display_state = g_strdup_printf("<span fgcolor=\"gray\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::TRYING:
+ display_state = g_strdup_printf("<span fgcolor=\"orange\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::ERROR:
+ display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::COUNT__:
+ g_warning("registration state should never be \"count\"");
+ display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
+ break;
+ }
}
}
@@ -401,7 +414,7 @@
column,
renderer,
(GtkTreeCellDataFunc)state_to_string,
- NULL,
+ priv->treeview_account_list,
NULL);
/* add an empty box to the account stack initially, otherwise there will
diff --git a/src/contactsview.cpp b/src/contactsview.cpp
index 8c27509..f8373f8 100644
--- a/src/contactsview.cpp
+++ b/src/contactsview.cpp
@@ -103,8 +103,15 @@
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
- G_GNUC_UNUSED gpointer data)
+ GtkTreeView *treeview)
{
+ // check if this iter is selected
+ gboolean is_selected = FALSE;
+ if (GTK_IS_TREE_VIEW(treeview)) {
+ auto selection = gtk_tree_view_get_selection(treeview);
+ is_selected = gtk_tree_selection_iter_is_selected(selection, iter);
+ }
+
/**
* If contact (person), show the name and the contact method (number)
* underneath; if multiple contact methods, then indicate as such
@@ -139,9 +146,17 @@
if (var_n.isValid())
number = var_n.value<QString>();
- text = g_strdup_printf("%s\n <span fgcolor=\"gray\">%s</span>",
- c->formattedName().toUtf8().constData(),
- number.toUtf8().constData());
+ /* we want the color of the status text to be the default color if this iter is
+ * selected so that the treeview is able to invert it against the selection color */
+ if (is_selected) {
+ text = g_strdup_printf("%s\n %s",
+ c->formattedName().toUtf8().constData(),
+ number.toUtf8().constData());
+ } else {
+ text = g_strdup_printf("%s\n <span fgcolor=\"gray\">%s</span>",
+ c->formattedName().toUtf8().constData(),
+ number.toUtf8().constData());
+ }
break;
}
default:
@@ -393,7 +408,7 @@
column,
renderer,
(GtkTreeCellDataFunc)render_name_and_contact_method,
- NULL,
+ treeview_contacts,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_contacts), column);
diff --git a/src/historyview.cpp b/src/historyview.cpp
index 085a225..43a8633 100644
--- a/src/historyview.cpp
+++ b/src/historyview.cpp
@@ -259,8 +259,15 @@
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
- G_GNUC_UNUSED gpointer data)
+ GtkTreeView *treeview)
{
+ // check if this iter is selected
+ gboolean is_selected = FALSE;
+ if (GTK_IS_TREE_VIEW(treeview)) {
+ auto selection = gtk_tree_view_get_selection(treeview);
+ is_selected = gtk_tree_selection_iter_is_selected(selection, iter);
+ }
+
/**
* If call, show the name and the contact method (number) underneath;
* otherwise just display the category.
@@ -281,9 +288,18 @@
/* call item */
QVariant var_name = idx.data(static_cast<int>(Call::Role::Name));
QVariant var_number = idx.data(static_cast<int>(Call::Role::Number));
- text = g_strdup_printf("%s\n <span fgcolor=\"gray\">%s</span>",
- var_name.value<QString>().toUtf8().constData(),
- var_number.value<QString>().toUtf8().constData());
+
+ /* we want the color of the status text to be the default color if this iter is
+ * selected so that the treeview is able to invert it against the selection color */
+ if (is_selected) {
+ text = g_strdup_printf("%s\n %s",
+ var_name.value<QString>().toUtf8().constData(),
+ var_number.value<QString>().toUtf8().constData());
+ } else {
+ text = g_strdup_printf("%s\n <span fgcolor=\"gray\">%s</span>",
+ var_name.value<QString>().toUtf8().constData(),
+ var_number.value<QString>().toUtf8().constData());
+ }
}
}
@@ -445,7 +461,7 @@
column,
renderer,
(GtkTreeCellDataFunc)render_name_and_contact_method,
- NULL,
+ treeview_history,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_history), column);
diff --git a/src/recentcontactsview.cpp b/src/recentcontactsview.cpp
index c2808bb..2a044f1 100644
--- a/src/recentcontactsview.cpp
+++ b/src/recentcontactsview.cpp
@@ -130,12 +130,19 @@
GtkCellRenderer *cell,
GtkTreeModel *model,
GtkTreeIter *iter,
- G_GNUC_UNUSED gpointer data)
+ GtkTreeView *treeview)
{
gchar *text = NULL;
QModelIndex idx = gtk_q_sort_filter_tree_model_get_source_idx(GTK_Q_SORT_FILTER_TREE_MODEL(model), iter);
+ // check if this iter is selected
+ gboolean is_selected = FALSE;
+ if (GTK_IS_TREE_VIEW(treeview)) {
+ auto selection = gtk_tree_view_get_selection(treeview);
+ is_selected = gtk_tree_selection_iter_is_selected(selection, iter);
+ }
+
auto type = idx.data(static_cast<int>(Ring::Role::ObjectType));
if (idx.isValid() && type.isValid()) {
switch (type.value<Ring::ObjectType>()) {
@@ -170,9 +177,17 @@
}
}
- text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"gray\">%s</span>",
- name.toUtf8().constData(),
- status.toUtf8().constData());
+ /* we want the color of the status text to be the default color if this iter is
+ * selected so that the treeview is able to invert it against the selection color */
+ if (is_selected) {
+ text = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>",
+ name.toUtf8().constData(),
+ status.toUtf8().constData());
+ } else {
+ text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"gray\">%s</span>",
+ name.toUtf8().constData(),
+ status.toUtf8().constData());
+ }
}
break;
case Ring::ObjectType::Call:
@@ -184,7 +199,12 @@
if (var_status.isValid())
status += var_status.value<QString>();
- text = g_strdup_printf("<span size=\"smaller\" color=\"gray\">%s</span>", status.toUtf8().constData());
+ /* we want the color of the status text to be the default color if this iter is
+ * selected so that the treeview is able to invert it against the selection color */
+ if (is_selected)
+ text = g_strdup_printf("<span size=\"smaller\">%s</span>", status.toUtf8().constData());
+ else
+ text = g_strdup_printf("<span size=\"smaller\" color=\"gray\">%s</span>", status.toUtf8().constData());
}
break;
case Ring::ObjectType::Media:
@@ -521,7 +541,7 @@
column,
renderer,
(GtkTreeCellDataFunc)render_name_and_info,
- NULL,
+ self,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(self), column);