From cc3d12bddc893bd7eca7c83b64929f5b416c7dc4 Mon Sep 17 00:00:00 2001 From: Sergei Ilinykh Date: Thu, 11 Jul 2024 01:46:56 +0300 Subject: [PATCH] Message forwarding: introduce roster's contact pick mode --- src/contactlistview.cpp | 7 +++++- src/contactlistview.h | 6 +++++ src/psicon.cpp | 4 ++- src/psirosterwidget.cpp | 36 ++++++++++++++++++++++----- src/psirosterwidget.h | 6 +++++ themes/chatview/psi/bubble/Dark.css | 4 +-- themes/chatview/psi/bubble/index.html | 2 +- 7 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/contactlistview.cpp b/src/contactlistview.cpp index 05f501b51d..d375032da5 100644 --- a/src/contactlistview.cpp +++ b/src/contactlistview.cpp @@ -326,7 +326,12 @@ void ContactListView::activate(const QModelIndex &index) { itemActivated(index); void ContactListView::itemActivated(const QModelIndex &index) { - model()->setData(index, QVariant(true), ContactListModel::ActivateRole); + if (activateAction == Activate) { + model()->setData(index, QVariant(true), ContactListModel::ActivateRole); + } else { + emit contactSelected( + model()->data(index, ContactListModel::ContactListItemRole).value()->contact()); + } } static QAbstractItemModel *realModel(QAbstractItemModel *model) diff --git a/src/contactlistview.h b/src/contactlistview.h index 1a285e5108..dc445d6b6e 100644 --- a/src/contactlistview.h +++ b/src/contactlistview.h @@ -29,11 +29,14 @@ class ContactListItemMenu; class ContactListModel; class QLineEdit; class QWidget; +class PsiContact; class ContactListView : public HoverableTreeView { Q_OBJECT public: + enum ActivateAction { Activate, SignalSelected }; + ContactListView(QWidget *parent = nullptr); ContactListModel *realModel() const; @@ -47,6 +50,7 @@ class ContactListView : public HoverableTreeView { void activate(const QModelIndex &index); void toggleExpandedState(const QModelIndex &index); void ensureVisible(const QModelIndex &index); + void setActivateAction(ActivateAction action) { activateAction = action; } // reimplemented void setModel(QAbstractItemModel *model) override; @@ -58,6 +62,7 @@ public slots: void realExpanded(const QModelIndex &); void realCollapsed(const QModelIndex &); void modelItemsUpdated(); + void contactSelected(PsiContact *); protected: // reimplemented @@ -98,6 +103,7 @@ protected slots: private: QPointer contextMenu_; bool contextMenuActive_; + ActivateAction activateAction = Activate; }; #endif // CONTACTLISTVIEW_H diff --git a/src/psicon.cpp b/src/psicon.cpp index 7f1548bc60..5f3493f730 100644 --- a/src/psicon.cpp +++ b/src/psicon.cpp @@ -1997,7 +1997,9 @@ void PsiCon::invokeForwardMessage(const Jid &from, const QString &text) auto roster = new PsiRosterWidget(d->mainwin); roster->setContactList(d->contactList); - roster->setFilterModeEnabled(true); + roster->setPickContactMode(true); + connect(roster, &PsiRosterWidget::contactPick, this, + [](PsiContact *c) { qDebug("TODO forwarding to: %s", qPrintable(c->jid().full())); }); auto btn = new QPushButton(tr("Forward")); connect(btn, &QPushButton::clicked, dlg, [this, roster](bool) { qDebug("TODO: implement forwarding"); }); diff --git a/src/psirosterwidget.cpp b/src/psirosterwidget.cpp index 688bdd17c7..f4175f1ed2 100644 --- a/src/psirosterwidget.cpp +++ b/src/psirosterwidget.cpp @@ -178,6 +178,7 @@ void PsiRosterWidget::setContactList(PsiContactList *contactList) contactListModel_->invalidateLayout(); contactListModel_->setAccountsEnabled(true); contactListModel_->setGroupsEnabled(PsiOptions::instance()->getOption(enableGroupsOptionPath).toBool()); + // connect #ifdef MODELTEST new ModelTest(contactListModel_, this); #endif @@ -249,9 +250,19 @@ void PsiRosterWidget::filterEditTextChanged(const QString &text) #endif } -void PsiRosterWidget::quitFilteringMode() { setFilterModeEnabled(false); } +void PsiRosterWidget::quitFilteringMode() +{ + if (!pickContactMode_) { + setFilterModeEnabled(false); + } +} -void PsiRosterWidget::updateFilterMode() { setFilterModeEnabled(!filterEdit_->text().isEmpty()); } +void PsiRosterWidget::updateFilterMode() +{ + if (!pickContactMode_) { + setFilterModeEnabled(!filterEdit_->text().isEmpty()); + } +} void PsiRosterWidget::setFilterModeEnabled(bool enabled) { @@ -297,9 +308,18 @@ void PsiRosterWidget::setFilterModeEnabled(bool enabled) delete selection; } +void PsiRosterWidget::setPickContactMode(bool value) +{ + pickContactMode_ = value; + if (value) { + setFilterModeEnabled(true); + } + contactListPageView_->setActivateAction(value ? ContactListView::SignalSelected : ContactListView::Activate); +} + void PsiRosterWidget::clearFilterEdit() { - if (filterEdit_->text().isEmpty()) + if (filterEdit_->text().isEmpty() && !pickContactMode_) setFilterModeEnabled(false); else filterEdit_->setText(""); @@ -332,7 +352,7 @@ bool PsiRosterWidget::eventFilter(QObject *obj, QEvent *e) filterEdit_->setText(text); return true; } - } else if (ke->key() == Qt::Key_F3) { + } else if (ke->key() == Qt::Key_F3 && !pickContactMode_) { setFilterModeEnabled(!(filterEdit_->isVisible() && filterEdit_->text().isEmpty())); filterEdit_->setText(""); return true; @@ -340,11 +360,15 @@ bool PsiRosterWidget::eventFilter(QObject *obj, QEvent *e) if (obj == filterEdit_ || obj == filterPageView_ || obj == filterPage_) { if (ke->key() == Qt::Key_Escape) { - setFilterModeEnabled(false); + if (pickContactMode_) { + deleteLater(); + } else { + setFilterModeEnabled(false); + } return true; } - if (ke->key() == Qt::Key_Backspace && filterEdit_->text().isEmpty()) { + if (ke->key() == Qt::Key_Backspace && filterEdit_->text().isEmpty() && !pickContactMode_) { setFilterModeEnabled(false); return true; } diff --git a/src/psirosterwidget.h b/src/psirosterwidget.h index 229abba220..7ef85d67b0 100644 --- a/src/psirosterwidget.h +++ b/src/psirosterwidget.h @@ -27,6 +27,7 @@ class ContactListDragModel; class PsiContactList; class PsiContactListView; class PsiFilteredContactListView; +class PsiContact; class QLineEdit; class QMimeData; class QSortFilterProxyModel; @@ -40,6 +41,10 @@ class PsiRosterWidget : public QWidget { void setContactList(PsiContactList *contactList); + void setPickContactMode(bool); +signals: + void contactPick(PsiContact *); + public slots: void filterEditTextChanged(const QString &); void quitFilteringMode(); @@ -69,6 +74,7 @@ private slots: ContactListDragModel *contactListModel_; QSortFilterProxyModel *filterModel_; + bool pickContactMode_ = false; }; #endif // PSIROSTERWIDGET_H diff --git a/themes/chatview/psi/bubble/Dark.css b/themes/chatview/psi/bubble/Dark.css index 155d454bf6..d1ee41ec97 100644 --- a/themes/chatview/psi/bubble/Dark.css +++ b/themes/chatview/psi/bubble/Dark.css @@ -55,11 +55,11 @@ blockquote>div { } .reactions_selector { - background-color: #111; + background-color: #033; } .context_menu { - background-color: black; + background-color: #033; } .context_menu>div+div { diff --git a/themes/chatview/psi/bubble/index.html b/themes/chatview/psi/bubble/index.html index dbe103f4f5..468040debc 100644 --- a/themes/chatview/psi/bubble/index.html +++ b/themes/chatview/psi/bubble/index.html @@ -557,7 +557,7 @@ .context_menu>div { box-sizing: border-box; - padding: .3rem .5rem; + padding: .3rem 1rem; } .context_menu>div+div {