1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge branch 'pr1515'

This commit is contained in:
tux3 2015-05-07 21:39:32 +02:00
commit 19bf083b41
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 149 additions and 13 deletions

View File

@ -368,7 +368,7 @@ QSplitter:handle{
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
@ -1008,6 +1008,42 @@ QSplitter:handle{
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QWidget" name="searchContactsContainer" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="searchContactText">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="searchContactFilterCBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="AdjustingScrollArea" name="friendList"> <widget class="AdjustingScrollArea" name="friendList">
<property name="sizePolicy"> <property name="sizePolicy">
@ -1036,8 +1072,8 @@ QSplitter:handle{
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>285</width> <width>284</width>
<height>381</height> <height>348</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"/> <layout class="QVBoxLayout" name="verticalLayout_5"/>
@ -1802,7 +1838,7 @@ QSplitter:handle{
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>775</width> <width>775</width>
<height>22</height> <height>25</height>
</rect> </rect>
</property> </property>
</widget> </widget>
@ -1817,17 +1853,17 @@ QSplitter:handle{
</action> </action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>CroppingLabel</class>
<extends>QLabel</extends>
<header location="global">src/widget/croppinglabel.h</header>
</customwidget>
<customwidget> <customwidget>
<class>AdjustingScrollArea</class> <class>AdjustingScrollArea</class>
<extends>QScrollArea</extends> <extends>QScrollArea</extends>
<header>src/widget/adjustingscrollarea.h</header> <header>src/widget/adjustingscrollarea.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>CroppingLabel</class>
<extends>QLabel</extends>
<header>src/widget/croppinglabel.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../res.qrc"/> <include location="../res.qrc"/>

View File

@ -133,10 +133,13 @@ void Widget::init()
ui->mainHead->layout()->setMargin(0); ui->mainHead->layout()->setMargin(0);
ui->mainHead->layout()->setSpacing(0); ui->mainHead->layout()->setSpacing(0);
ui->addButton->setCheckable(true); ui->searchContactFilterCBox->addItem(tr("All"));
ui->groupButton->setCheckable(false); ui->searchContactFilterCBox->addItem(tr("Online"));
ui->transferButton->setCheckable(true); ui->searchContactFilterCBox->addItem(tr("Offline"));
ui->settingsButton->setCheckable(true); ui->searchContactFilterCBox->addItem(tr("Friends"));
ui->searchContactFilterCBox->addItem(tr("Groups"));
ui->searchContactText->setPlaceholderText("Search Contacts");
if (QStyleFactory::keys().contains(Settings::getInstance().getStyle()) if (QStyleFactory::keys().contains(Settings::getInstance().getStyle())
&& Settings::getInstance().getStyle() != "None") && Settings::getInstance().getStyle() != "None")
@ -200,6 +203,8 @@ void Widget::init()
connect(timer, &QTimer::timeout, this, &Widget::onEventIconTick); connect(timer, &QTimer::timeout, this, &Widget::onEventIconTick);
connect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon); connect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon);
connect(offlineMsgTimer, &QTimer::timeout, this, &Widget::processOfflineMsgs); connect(offlineMsgTimer, &QTimer::timeout, this, &Widget::processOfflineMsgs);
connect(ui->searchContactText, &QLineEdit::textChanged, this, &Widget::searchContacts);
connect(ui->searchContactFilterCBox, &QComboBox::currentTextChanged, this, &Widget::searchContacts);
// keyboard shortcuts // keyboard shortcuts
new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close())); new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close()));
@ -645,6 +650,8 @@ void Widget::addFriend(int friendId, const QString &userId)
newfriend->getChatForm()->onAvatarChange(friendId, avatar); newfriend->getChatForm()->onAvatarChange(friendId, avatar);
newfriend->getFriendWidget()->onAvatarChange(friendId, avatar); newfriend->getFriendWidget()->onAvatarChange(friendId, avatar);
} }
searchContacts();
} }
void Widget::addFriendFailed(const QString&, const QString& errorInfo) void Widget::addFriendFailed(const QString&, const QString& errorInfo)
@ -732,6 +739,7 @@ void Widget::onFriendUsernameChanged(int friendId, const QString& username)
QString str = username; str.replace('\n', ' '); QString str = username; str.replace('\n', ' ');
str.remove('\r'); str.remove(QChar((char)0)); // null terminator... str.remove('\r'); str.remove(QChar((char)0)); // null terminator...
f->setName(str); f->setName(str);
searchContacts();
} }
void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget) void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget)
@ -989,6 +997,7 @@ void Widget::onGroupTitleChanged(int groupnumber, const QString& author, const Q
g->setName(title); g->setName(title);
if (!author.isEmpty()) if (!author.isEmpty())
g->getChatForm()->addSystemInfoMessage(tr("%1 has set the title to %2").arg(author, title), ChatMessage::INFO, QDateTime::currentDateTime()); g->getChatForm()->addSystemInfoMessage(tr("%1 has set the title to %2").arg(author, title), ChatMessage::INFO, QDateTime::currentDateTime());
searchContacts();
} }
void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber) void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber)
@ -1047,6 +1056,7 @@ Group *Widget::createGroup(int groupId)
connect(newgroup->getChatForm(), &GroupChatForm::sendMessage, core, &Core::sendGroupMessage); connect(newgroup->getChatForm(), &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
connect(newgroup->getChatForm(), &GroupChatForm::sendAction, core, &Core::sendGroupAction); connect(newgroup->getChatForm(), &GroupChatForm::sendAction, core, &Core::sendGroupAction);
connect(newgroup->getChatForm(), &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle); connect(newgroup->getChatForm(), &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle);
searchContacts();
return newgroup; return newgroup;
} }
@ -1367,6 +1377,85 @@ Status Widget::getStatusFromString(QString status)
return Status::Offline; return Status::Offline;
} }
void Widget::searchContacts()
{
QString searchString = ui->searchContactText->text();
int filter = ui->searchContactFilterCBox->currentIndex();
switch(filter)
{
case FilterCriteria::All:
hideFriends(searchString, Status::Online);
hideFriends(searchString, Status::Offline);
hideGroups(searchString);
break;
case FilterCriteria::Online:
hideFriends(searchString, Status::Online);
hideFriends(QString(), Status::Offline, true);
hideGroups(searchString);
break;
case FilterCriteria::Offline:
hideFriends(QString(), Status::Online, true);
hideFriends(searchString, Status::Offline);
hideGroups(QString(), true);
break;
case FilterCriteria::Friends:
hideFriends(searchString, Status::Online);
hideFriends(searchString, Status::Offline);
hideGroups(QString(), true);
break;
case FilterCriteria::Groups:
hideFriends(QString(), Status::Online, true);
hideFriends(QString(), Status::Offline, true);
hideGroups(searchString);
break;
default:
return;
}
contactListWidget->hide();
contactListWidget->show();
}
void Widget::hideFriends(QString searchString, Status status, bool hideAll)
{
QVBoxLayout* friends = contactListWidget->getFriendLayout(status);
int friendCount = friends->count(), index;
for (index = 0; index<friendCount; index++)
{
FriendWidget* friendWidget = static_cast<FriendWidget*>(friends->itemAt(index)->widget());
QString friendName = friendWidget->getName();
if (!friendName.contains(searchString, Qt::CaseInsensitive) | hideAll)
friendWidget->setVisible(false);
else
friendWidget->setVisible(true);
}
}
void Widget::hideGroups(QString searchString, bool hideAll)
{
QVBoxLayout* groups = contactListWidget->getGroupLayout();
int groupCount = groups->count(), index;
for (index = 0; index<groupCount; index++)
{
GroupWidget* groupWidget = static_cast<GroupWidget*>(groups->itemAt(index)->widget());
QString groupName = groupWidget->getName();
if (!groupName.contains(searchString, Qt::CaseInsensitive) | hideAll)
groupWidget->setVisible(false);
else
groupWidget->setVisible(true);
}
}
void Widget::setActiveToolMenuButton(ActiveToolMenuButton newActiveButton) void Widget::setActiveToolMenuButton(ActiveToolMenuButton newActiveButton)
{ {
ui->addButton->setChecked(newActiveButton == Widget::AddButton); ui->addButton->setChecked(newActiveButton == Widget::AddButton);

View File

@ -55,6 +55,14 @@ protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);
public: public:
enum FilterCriteria
{
All=0,
Online,
Offline,
Friends,
Groups
};
explicit Widget(QWidget *parent = 0); explicit Widget(QWidget *parent = 0);
void init(); void init();
void setCentralWidget(QWidget *widget, const QString &widgetName); void setCentralWidget(QWidget *widget, const QString &widgetName);
@ -149,6 +157,9 @@ private slots:
void onSetShowSystemTray(bool newValue); void onSetShowSystemTray(bool newValue);
void onSplitterMoved(int pos, int index); void onSplitterMoved(int pos, int index);
void processOfflineMsgs(); void processOfflineMsgs();
void searchContacts();
void hideFriends(QString searchString, Status status, bool hideAll = false);
void hideGroups(QString searchString, bool hideAll = false);
private: private:
enum ActiveToolMenuButton { enum ActiveToolMenuButton {