mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Rewrite focus{Friend,Group}
This commit is contained in:
parent
2b3918b25e
commit
b806f9e7e3
|
@ -557,6 +557,26 @@ void ContentDialog::keyPressEvent(QKeyEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void ContentDialog::focusFriend(int friendId)
|
||||
{
|
||||
focusCommon(friendId, friendWidgets);
|
||||
}
|
||||
|
||||
void ContentDialog::focusGroup(int groupId)
|
||||
{
|
||||
focusCommon(groupId, groupWidgets);
|
||||
}
|
||||
|
||||
void ContentDialog::focusCommon(int id, QHash<int, GenericChatroomWidget*> list)
|
||||
{
|
||||
auto it = list.find(id);
|
||||
if (it == list.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
activate(*it);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Show ContentDialog, activate chatroom widget.
|
||||
* @param widget Widget which should be activated.
|
||||
|
|
|
@ -74,6 +74,9 @@ public:
|
|||
bool hasFriendWidget(int friendId) const;
|
||||
bool hasGroupWidget(int groupId) const;
|
||||
|
||||
void focusFriend(int friendId);
|
||||
void focusGroup(int groupId);
|
||||
|
||||
signals:
|
||||
void friendDialogShown(const Friend* f);
|
||||
void groupDialogShown(Group* g);
|
||||
|
@ -111,6 +114,9 @@ private:
|
|||
void saveSplitterState();
|
||||
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
||||
int getCurrentLayout(QLayout*& layout);
|
||||
void focusCommon(int id, QHash<int, GenericChatroomWidget*> list);
|
||||
|
||||
private:
|
||||
|
||||
QList<QLayout*> layouts;
|
||||
QSplitter* splitter;
|
||||
|
|
|
@ -97,34 +97,39 @@ bool ContentDialogManager::existsWidget(int id, const QHash<int, ContactInfo>& l
|
|||
|
||||
void ContentDialogManager::focusFriend(int friendId)
|
||||
{
|
||||
focusDialog(friendId, friendList);
|
||||
auto dialog = focusDialog(friendId, friendDialogs);
|
||||
if (dialog != nullptr)
|
||||
dialog->focusFriend(friendId);
|
||||
}
|
||||
|
||||
void ContentDialogManager::focusGroup(int groupId)
|
||||
{
|
||||
focusDialog(groupId, groupList);
|
||||
auto dialog = focusDialog(groupId, groupDialogs);
|
||||
if (dialog != nullptr)
|
||||
dialog->focusGroup(groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Focus the dialog if it exists.
|
||||
* @param id User Id.
|
||||
* @param list List with contact info.
|
||||
* @param list List with dialogs
|
||||
* @return ContentDialog if found, nullptr otherwise
|
||||
*/
|
||||
void ContentDialogManager::focusDialog(int id, const QHash<int, ContactInfo>& list)
|
||||
ContentDialog* ContentDialogManager::focusDialog(int id, const QHash<int, ContentDialog*>& list)
|
||||
{
|
||||
auto iter = list.find(id);
|
||||
if (iter == list.end()) {
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ContentDialog* dialog = std::get<0>(*iter);
|
||||
ContentDialog* dialog = *iter;
|
||||
if (dialog->windowState() & Qt::WindowMinimized) {
|
||||
dialog->showNormal();
|
||||
}
|
||||
|
||||
dialog->raise();
|
||||
dialog->activateWindow();
|
||||
dialog->activate(std::get<1>(iter.value()));
|
||||
return dialog;
|
||||
}
|
||||
|
||||
void ContentDialogManager::updateFriendStatus(int friendId)
|
||||
|
|
|
@ -55,8 +55,8 @@ private slots:
|
|||
void onDialogActivate();
|
||||
|
||||
private:
|
||||
ContentDialog* focusDialog(int id, const QHash<int, ContentDialog*>& list);
|
||||
bool existsWidget(int id, const QHash<int, ContactInfo>& list);
|
||||
void focusDialog(int id, const QHash<int, ContactInfo>& list);
|
||||
void updateStatus(int id, const QHash<int, ContactInfo>& list);
|
||||
bool isWidgetActive(int id, const QHash<int, ContactInfo>& list);
|
||||
ContentDialog* getDialog(int id, const QHash<int, ContactInfo>& list) const;
|
||||
|
|
Loading…
Reference in New Issue
Block a user