qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
friendlistlayout.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "friendlistlayout.h"
21 #include "friendlistwidget.h"
22 #include "friendwidget.h"
23 #include "src/model/friend.h"
24 #include "src/model/status.h"
25 #include "src/friendlist.h"
26 #include <cassert>
27 
29  : QVBoxLayout()
30 {
31  init();
32 }
33 
35  : QVBoxLayout(parent)
36 {
37  init();
38 }
39 
41 {
42  setSpacing(0);
43  setMargin(0);
44 
45  friendOnlineLayout.getLayout()->setSpacing(0);
46  friendOnlineLayout.getLayout()->setMargin(0);
47 
48  friendOfflineLayout.getLayout()->setSpacing(0);
49  friendOfflineLayout.getLayout()->setMargin(0);
50 
51  addLayout(friendOnlineLayout.getLayout());
52  addLayout(friendOfflineLayout.getLayout());
53 }
54 
56 {
59 
60  if (s == Status::Status::Offline) {
62  return;
63  }
64 
66 }
67 
69 {
70  if (s == Status::Status::Offline)
72  else
74 }
75 
77 {
78  if (online)
81 }
82 
84 {
85  while (!friendOnlineLayout.getLayout()->isEmpty()) {
86  QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
87 
88  FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
89  const Friend* f = friendWidget->getFriend();
90  listWidget->moveWidget(friendWidget, f->getStatus(), true);
91  }
92  while (!friendOfflineLayout.getLayout()->isEmpty()) {
93  QWidget* getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
94 
95  FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
96  const Friend* f = friendWidget->getFriend();
97  listWidget->moveWidget(friendWidget, f->getStatus(), true);
98  }
99 }
100 
102 {
103  return friendOnlineLayout.getLayout()->count();
104 }
105 
107 {
108  return friendOfflineLayout.getLayout()->count() + friendOnlineCount();
109 }
110 
112 {
113  return !(friendOfflineLayout.getLayout()->isEmpty() && friendOnlineLayout.getLayout()->isEmpty());
114 }
115 
116 void FriendListLayout::searchChatrooms(const QString& searchString, bool hideOnline, bool hideOffline)
117 {
118  friendOnlineLayout.search(searchString, hideOnline);
119  friendOfflineLayout.search(searchString, hideOffline);
120 }
121 
123 {
124  return friendOnlineLayout.getLayout();
125 }
126 
128 {
130 }
131 
133 {
135 }
Status::Status
Status
Definition: status.h:28
FriendListWidget::moveWidget
void moveWidget(FriendWidget *w, Status::Status s, bool add=false)
Definition: friendlistwidget.cpp:563
friend.h
GenericChatItemLayout::search
void search(const QString &searchString, bool hideAll=false)
Definition: genericchatitemlayout.cpp:91
GenericChatItemLayout::removeSortedWidget
void removeSortedWidget(GenericChatItemWidget *widget)
Definition: genericchatitemlayout.cpp:73
friendlist.h
Status::Status::Offline
@ Offline
FriendListLayout::addFriendWidget
void addFriendWidget(FriendWidget *widget, Status::Status s)
Definition: friendlistlayout.cpp:55
FriendListLayout::friendTotalCount
int friendTotalCount() const
Definition: friendlistlayout.cpp:106
FriendListLayout::removeFriendWidget
void removeFriendWidget(FriendWidget *widget, Status::Status s)
Definition: friendlistlayout.cpp:68
FriendListLayout::FriendListLayout
FriendListLayout()
Definition: friendlistlayout.cpp:28
FriendListLayout::indexOfFriendWidget
int indexOfFriendWidget(GenericChatItemWidget *widget, bool online) const
Definition: friendlistlayout.cpp:76
GenericChatItemWidget
Definition: genericchatitemwidget.h:27
GenericChatItemLayout::getLayout
QLayout * getLayout() const
Definition: genericchatitemlayout.cpp:102
FriendListLayout::friendOnlineLayout
GenericChatItemLayout friendOnlineLayout
Definition: friendlistlayout.h:55
Friend::getStatus
Status::Status getStatus() const
Definition: friend.cpp:190
FriendListLayout::getFriendLayout
QLayout * getFriendLayout(Status::Status s) const
Definition: friendlistlayout.cpp:132
FriendListLayout::getLayoutOnline
QLayout * getLayoutOnline() const
Definition: friendlistlayout.cpp:122
Friend
Definition: friend.h:31
FriendWidget::getFriend
const Friend * getFriend() const final
Definition: friendwidget.cpp:347
FriendListLayout::searchChatrooms
void searchChatrooms(const QString &searchString, bool hideOnline=false, bool hideOffline=false)
Definition: friendlistlayout.cpp:116
FriendListLayout::init
void init()
Definition: friendlistlayout.cpp:40
FriendListLayout::moveFriendWidgets
void moveFriendWidgets(FriendListWidget *listWidget)
Definition: friendlistlayout.cpp:83
friendlistwidget.h
FriendListWidget
Definition: friendlistwidget.h:42
FriendListLayout::getLayoutOffline
QLayout * getLayoutOffline() const
Definition: friendlistlayout.cpp:127
FriendListLayout::friendOfflineLayout
GenericChatItemLayout friendOfflineLayout
Definition: friendlistlayout.h:56
FriendListLayout::hasChatrooms
bool hasChatrooms() const
Definition: friendlistlayout.cpp:111
FriendListLayout::friendOnlineCount
int friendOnlineCount() const
Definition: friendlistlayout.cpp:101
friendlistlayout.h
friendwidget.h
status.h
GenericChatItemLayout::indexOfSortedWidget
int indexOfSortedWidget(GenericChatItemWidget *widget) const
Definition: genericchatitemlayout.cpp:48
FriendWidget
Definition: friendwidget.h:33
GenericChatItemLayout::addSortedWidget
void addSortedWidget(GenericChatItemWidget *widget, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Definition: genericchatitemlayout.cpp:41