From ecfe74213c7fdd633ca12f946a345c19a48fe41e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anthony=20L=C3=A9onard?=
 <anthony.leonard@savoirfairelinux.com>
Date: Thu, 4 May 2017 14:14:37 -0400
Subject: [PATCH] replace text by icons on main tabs + ui fixes

Tabs are now smaller and use icons instead of text for "Conversations"
and "Contact requests" tabs. It gives a better looking UI and room for
 additional pages.

Moreover, tab switching was giving inconsistencies in many situations
between item selected on the left and what is displayed on the right
panel. Showing or hiding a widget on the right panel now depends on
the selection model of the list on the left. Consequently, clicking on
a back button now deselects the item on the left which is what switches
the view back to the welcome page.

Change-Id: Ib67149dba62e15bebcfe3ebce2398b7717e3f85d
Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
---
 callwidget.cpp                               |  46 +++++++++++++++----
 callwidget.h                                 |   1 +
 callwidget.ui                                |  24 +++++++++-
 images/icons/ic_chat_black_24dp_2x.png       | Bin 0 -> 193 bytes
 images/icons/ic_person_add_black_24dp_2x.png | Bin 0 -> 323 bytes
 ressources.qrc                               |   2 +
 stylesheet.css                               |  14 +++++-
 7 files changed, 75 insertions(+), 12 deletions(-)
 create mode 100644 images/icons/ic_chat_black_24dp_2x.png
 create mode 100644 images/icons/ic_person_add_black_24dp_2x.png

diff --git a/callwidget.cpp b/callwidget.cpp
index 9c63093..effcfaa 100644
--- a/callwidget.cpp
+++ b/callwidget.cpp
@@ -135,8 +135,11 @@ CallWidget::CallWidget(QWidget* parent) :
                         auto idx = selected.indexes().first();
                         auto realIdx = RecentModel::instance().peopleProxy()->mapFromSource(idx);
                         ui->smartList->selectionModel()->setCurrentIndex(realIdx, QItemSelectionModel::ClearAndSelect);
-                    } else
+                    } else {
+                        RecentModel::instance().selectionModel()->clearCurrentIndex();
                         ui->smartList->clearSelection();
+                        ui->smartList->selectionModel()->clearCurrentIndex();
+                    }
                 });
 
         connect(&NameDirectory::instance(), SIGNAL(registeredNameFound(Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
@@ -150,7 +153,10 @@ CallWidget::CallWidget(QWidget* parent) :
         connect(ui->sendContactRequestWidget, &SendContactRequestWidget::sendCRclicked, [=]{slidePage(ui->messagingPage);});
 
         connect(ui->contactRequestWidget, &ContactRequestWidget::choiceMade, [this]() {
-            slidePage(ui->welcomePage);
+            if (getSelectedAccount()->pendingContactRequestModel()->rowCount() == 0)
+                ui->mainTabMenu->setCurrentWidget(ui->mainTabMenuPage1);
+            else
+                ui->contactRequestList->selectionModel()->clear();
         });
 
         connect(AvailableAccountModel::instance().selectionModel(), &QItemSelectionModel::currentChanged,
@@ -538,8 +544,14 @@ void
 CallWidget::smartListCurrentChanged(const QModelIndex &currentIdx, const QModelIndex &previousIdx)
 {
     Q_UNUSED(previousIdx);
-    if (not currentIdx.isValid())
+    if (not currentIdx.isValid()) {
+        auto widget = ui->stackedWidget->currentWidget();
+        if (widget == ui->messagingPage || widget == ui->videoPage)
+            slidePage(ui->welcomePage);
+        if(actualCall_)
+            setActualCall(nullptr);
         return;
+    }
 
     //catch call of current index
     auto currentIdxCall = RecentModel::instance().getActiveCall(currentIdx);
@@ -587,8 +599,14 @@ CallWidget::contactReqListCurrentChanged(const QModelIndex &currentIdx, const QM
 {
     Q_UNUSED(previousIdx)
 
-    ui->contactRequestWidget->setCurrentContactRequest(currentIdx);
-    ui->stackedWidget->setCurrentWidget(ui->contactRequestPage);
+    if (currentIdx.isValid()) {
+        ui->contactRequestWidget->setCurrentContactRequest(currentIdx);
+        ui->stackedWidget->setCurrentWidget(ui->contactRequestPage);
+    } else {
+        ui->contactRequestWidget->setCurrentContactRequest(QModelIndex());
+        if (ui->stackedWidget->currentWidget() == ui->contactRequestPage)
+            slidePage(ui->welcomePage);
+    }
 }
 
 void
@@ -713,11 +731,11 @@ CallWidget::selectedAccountChanged(const QModelIndex &current, const QModelIndex
 
         // Then, we update the pending CR list with those from the newly selected account
         if (disconnect(crListSelectionConnection_)) {
+            ui->contactRequestList->selectionModel()->clear();
             // The selection model must be deleted by the application (see QT doc).
             QItemSelectionModel* sMod = ui->contactRequestList->selectionModel();
             delete sMod;
             RecentModel::instance().selectionModel()->clear();
-            slidePage(ui->welcomePage);
         }
 
         ui->contactRequestList->setItemModel(ac->pendingContactRequestModel());
@@ -839,7 +857,6 @@ void
 CallWidget::backToWelcomePage()
 {
     RecentModel::instance().selectionModel()->clear();
-    slidePage(ui->welcomePage);
     disconnect(imConnection_);
 }
 
@@ -931,14 +948,13 @@ CallWidget::on_sendContactRequestPageButton_clicked()
 void
 CallWidget::on_sendCRBackButton_clicked()
 {
-    slidePage(ui->messagingPage);
+    ui->stackedWidget->setCurrentWidget(ui->messagingPage);
 }
 
 void
 CallWidget::on_pendingCRBackButton_clicked()
 {
     ui->contactRequestList->selectionModel()->clear();
-    slidePage(ui->welcomePage);
 }
 
 Account*
@@ -951,3 +967,15 @@ CallWidget::getSelectedAccount()
     }
     return nullptr;
 }
+
+void CallWidget::on_mainTabMenu_currentChanged(int index)
+{
+    Q_UNUSED(index)
+
+    auto current = ui->mainTabMenu->currentWidget();
+
+    if(current == ui->mainTabMenuPage1)
+        ui->contactRequestList->selectionModel()->clear();
+    else if (current == ui->mainTabMenuPage2)
+        RecentModel::instance().selectionModel()->clear();
+}
diff --git a/callwidget.h b/callwidget.h
index 3aa7b51..087fb76 100644
--- a/callwidget.h
+++ b/callwidget.h
@@ -83,6 +83,7 @@ private slots:
     void on_qrButton_toggled(bool checked);
     void on_shareButton_clicked();
     void on_pendingCRBackButton_clicked();
+    void on_mainTabMenu_currentChanged(int index);
 
 private slots:
     void callIncoming(Call* call);
diff --git a/callwidget.ui b/callwidget.ui
index 3e66272..3559778 100644
--- a/callwidget.ui
+++ b/callwidget.ui
@@ -306,8 +306,21 @@
                <property name="currentIndex">
                 <number>0</number>
                </property>
-               <widget class="QWidget" name="mainTabMenuPage1_2">
+               <property name="iconSize">
+                <size>
+                 <width>24</width>
+                 <height>24</height>
+                </size>
+               </property>
+               <widget class="QWidget" name="mainTabMenuPage1">
+                <attribute name="icon">
+                 <iconset resource="ressources.qrc">
+                  <normaloff>:/images/icons/ic_chat_black_24dp_2x.png</normaloff>:/images/icons/ic_chat_black_24dp_2x.png</iconset>
+                </attribute>
                 <attribute name="title">
+                 <string/>
+                </attribute>
+                <attribute name="toolTip">
                  <string>Conversations</string>
                 </attribute>
                 <layout class="QVBoxLayout" name="verticalLayout_6">
@@ -351,8 +364,15 @@
                 </layout>
                </widget>
                <widget class="QWidget" name="mainTabMenuPage2">
+                <attribute name="icon">
+                 <iconset resource="ressources.qrc">
+                  <normaloff>:/images/icons/ic_person_add_black_24dp_2x.png</normaloff>:/images/icons/ic_person_add_black_24dp_2x.png</iconset>
+                </attribute>
                 <attribute name="title">
-                 <string>Contact Requests</string>
+                 <string/>
+                </attribute>
+                <attribute name="toolTip">
+                 <string>Contact requests</string>
                 </attribute>
                 <layout class="QVBoxLayout" name="verticalLayout_7">
                  <property name="spacing">
diff --git a/images/icons/ic_chat_black_24dp_2x.png b/images/icons/ic_chat_black_24dp_2x.png
new file mode 100644
index 0000000000000000000000000000000000000000..e9e92e5f809cd0a62b9a5867d57319d1a86fe31e
GIT binary patch
literal 193
zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4i*LmhQHi~JPZsB9iA?ZAr*{oFJ0thG8AyV
z811{|jIKw-)(slR{7ZEbS_I}C@0w}-|Gfi;edxBwCwPB<dN=3h<HZFBo8JBEv`A<y
zKNRZR*!H@yb>8cl2Q&<#nC`0maMiyltZKl}a_^hNdQQg4%m=3*xaJVdyjpC9i0p-k
xzkArl4hf%MJkQ;>ze?__&8y0Y6aTiDmuwcC&An_vC<6lngQu&X%Q~loCID%eO@;sf

literal 0
HcmV?d00001

diff --git a/images/icons/ic_person_add_black_24dp_2x.png b/images/icons/ic_person_add_black_24dp_2x.png
new file mode 100644
index 0000000000000000000000000000000000000000..f3e8931b62c359a28c6cdd1151f3c1b49c5d9889
GIT binary patch
literal 323
zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4i*LmhQHi~JPZtsT%InDAr*{oCvEg%b`)@k
zUo}U5;o683GwTK39Cfolc|-N#x)bso({6bRxIAK4+4-B3-_?^Vf6pPeooCkWzRdAE
z&OX0fLTO@$I&+biSud-k=CU^iu5}TUC*SC;cZix3sk-chnDOkpr^B*?nobHH<@7tT
zJ$Fi0f~4Gy6^&o*IYhD&1m#X#IiO)PAxJyDY6b7rQp+ob5iCM!9^K!+<T6c|@INZ#
z><qgIR)!!ook(*%iOk*Clgw_gCnfZAuiKIAdNe)xXjgRGoXyfw5(Z0LM7Z@V4>ilB
z+bH*)vs~J4E%Tw}&qeodg-=?{j~ou~yBqhvvEtXePu<cg2ePeJHZkd!C?#64B`FAX
b)-YQ8Rn6RS=|%|y0|SGntDnm{r-UW|1vGz5

literal 0
HcmV?d00001

diff --git a/ressources.qrc b/ressources.qrc
index 6b259ab..35ae24c 100644
--- a/ressources.qrc
+++ b/ressources.qrc
@@ -41,5 +41,7 @@
         <file>images/icons/ic_share_black_48dp_2x.png</file>
         <file>images/loading.gif</file>
         <file>images/FontAwesome.otf</file>
+        <file>images/icons/ic_chat_black_24dp_2x.png</file>
+        <file>images/icons/ic_person_add_black_24dp_2x.png</file>
     </qresource>
 </RCC>
diff --git a/stylesheet.css b/stylesheet.css
index 8838f61..474f0d4 100644
--- a/stylesheet.css
+++ b/stylesheet.css
@@ -460,7 +460,6 @@ QPushButton#quickBanCRBtn:hover{
 }
 
 QTabBar::tab{
-    background: transparent;
     color: rgb(77, 77, 77);
     border-radius: 0px;
     border-style: solid;
@@ -475,9 +474,22 @@ QTabBar::tab{
     height: 20px;
 }
 
+QTabWidget#mainTabMenu QTabBar::tab {
+    height: 24px;
+    width: auto;
+    padding-left: 14px;
+    margin-left:auto;
+    margin-right:auto;
+}
+
+QTabWidget#mainTabMenu QTabBar::tab:hover {
+    background-color: rgb(242, 242, 242);
+}
+
 QTabWidget::tab-bar{
     alignment: center;
 }
+
 QTabBar QToolButton{
     height: 9;
     width : 9;
-- 
GitLab