File indexing completed on 2023-11-26 08:16:46

0001 /*
0002  * Copyright (C) 2011 David Edmundson <kde@davidedmundson.co.uk>
0003  * Copyright (C) 2012 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2.1 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public
0016  * License along with this library; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 
0021 #ifndef CONTACT_VIEW_WIDGET_H
0022 #define CONTACT_VIEW_WIDGET_H
0023 
0024 #include <QtWidgets/QWidget>
0025 #include <QtWidgets/QListView>
0026 
0027 #include <TelepathyQt/Types>
0028 
0029 #include <KTp/contact.h>
0030 #include <KTp/ktpcommoninternals_export.h>
0031 
0032 class QLineEdit;
0033 class QItemSelection;
0034 class QListView;
0035 
0036 namespace KTp
0037 {
0038 class ContactsFilterModel;
0039 class ContactsListModel;
0040 
0041 class KTPCOMMONINTERNALS_EXPORT ContactViewWidget : public QWidget
0042 {
0043     Q_OBJECT
0044     Q_DISABLE_COPY(ContactViewWidget)
0045 
0046     Q_PROPERTY(QString displayNameFilter
0047                READ displayNameFilter
0048                RESET clearDisplayNameFilter
0049                WRITE setDisplayNameFilter
0050                NOTIFY displayNameFilterChanged)
0051     Q_PROPERTY(QSize iconSize
0052                READ iconSize
0053                WRITE setIconSize
0054                NOTIFY iconSizeChanged)
0055     Q_PROPERTY(QListView::ViewMode viewMode
0056                READ viewMode
0057                WRITE setViewMode)
0058 public:
0059     explicit ContactViewWidget(ContactsListModel *model, QWidget *parent = nullptr);
0060     ~ContactViewWidget() override;
0061 
0062     virtual QString displayNameFilter() const;
0063     Q_SLOT virtual void clearDisplayNameFilter();
0064     Q_SLOT virtual void setDisplayNameFilter(const QString &displayNameFilter);
0065     Q_SIGNAL void displayNameFilterChanged(const QString &displayNameFilter);
0066 
0067     virtual QSize iconSize() const;
0068     Q_SLOT virtual void setIconSize(const QSize &iconSize);
0069     Q_SIGNAL void iconSizeChanged(const QSize &iconSize);
0070 
0071     virtual KTp::ContactsFilterModel* filter() const;
0072     virtual QLineEdit* contactFilterLineEdit() const;
0073 
0074     virtual bool hasSelection() const;
0075     virtual Tp::AccountPtr selectedAccount() const;
0076     virtual KTp::ContactPtr selectedContact() const;
0077 
0078     virtual QList<KTp::ContactPtr> selectedContacts() const;
0079 
0080     void setViewMode(QListView::ViewMode);
0081     QListView::ViewMode viewMode() const;
0082 
0083     void setSelectionMode(QAbstractItemView::SelectionMode mode);
0084     QAbstractItemView::SelectionMode selectionMode();
0085 
0086 Q_SIGNALS:
0087     void selectionChanged(const Tp::AccountPtr &selectedAccount, const KTp::ContactPtr &selectedContact);
0088     void contactDoubleClicked(const Tp::AccountPtr &account, const KTp::ContactPtr &contact);
0089 
0090 private:
0091     class Private;
0092     Private * const d;
0093 
0094     Q_PRIVATE_SLOT(d, void _k_onSelectionChanged(const QItemSelection &currentSelection,
0095                                                  const QItemSelection &previousSelection));
0096     Q_PRIVATE_SLOT(d, void _k_onDoubleClicked(const QModelIndex &index));
0097 
0098 }; // class ContactViewWidget
0099 
0100 } // namespace KTp
0101 
0102 #endif // CONTACT_VIEW_WIDGET_H