Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | bab169d | 2016-01-07 15:13:33 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 3 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | |
Edric Milaret | 5f316da | 2015-09-28 11:57:42 -0400 | [diff] [blame] | 19 | #pragma once |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 20 | |
| 21 | #include <QDialog> |
Edric Milaret | be0aa5a | 2015-07-31 15:08:39 -0400 | [diff] [blame] | 22 | #include <QSortFilterProxyModel> |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 23 | |
| 24 | #include "personmodel.h" |
Edric Milaret | be0aa5a | 2015-07-31 15:08:39 -0400 | [diff] [blame] | 25 | #include "contactmethod.h" |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 26 | |
| 27 | namespace Ui { |
| 28 | class ContactPicker; |
| 29 | } |
| 30 | |
Edric Milaret | be0aa5a | 2015-07-31 15:08:39 -0400 | [diff] [blame] | 31 | class OnlyPersonProxyModel : public QSortFilterProxyModel |
| 32 | { |
| 33 | public: |
| 34 | OnlyPersonProxyModel(QAbstractItemModel* parent) : QSortFilterProxyModel(parent) |
| 35 | { |
| 36 | setSourceModel(parent); |
| 37 | } |
| 38 | virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const |
| 39 | { |
| 40 | bool match = filterRegExp().indexIn(sourceModel()->index(source_row,0,source_parent).data(Qt::DisplayRole).toString()) != -1; |
| 41 | return match && !sourceModel()->index(source_row,0,source_parent).parent().isValid(); |
| 42 | } |
| 43 | }; |
| 44 | |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 45 | class ContactPicker : public QDialog |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | |
| 49 | public: |
Edric Milaret | be0aa5a | 2015-07-31 15:08:39 -0400 | [diff] [blame] | 50 | explicit ContactPicker(ContactMethod* number, QWidget *parent = 0); |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 51 | ~ContactPicker(); |
| 52 | |
Edric Milaret | be0aa5a | 2015-07-31 15:08:39 -0400 | [diff] [blame] | 53 | protected slots: |
| 54 | void accept(); |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 55 | |
| 56 | //UI SLOTS |
| 57 | private slots: |
| 58 | void on_contactView_doubleClicked(const QModelIndex &index); |
Edric Milaret | be0aa5a | 2015-07-31 15:08:39 -0400 | [diff] [blame] | 59 | void on_okButton_clicked(); |
| 60 | void on_createNewButton_clicked(); |
| 61 | |
| 62 | void on_searchBar_textChanged(const QString &arg1); |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 63 | |
| 64 | private: |
| 65 | Ui::ContactPicker *ui; |
| 66 | Person *personSelected_; |
Edric Milaret | be0aa5a | 2015-07-31 15:08:39 -0400 | [diff] [blame] | 67 | ContactMethod* number_; |
| 68 | OnlyPersonProxyModel* contactProxyModel_; |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 69 | }; |