summaryrefslogtreecommitdiffstats
blob: 25e7d427e4d496018a7cdf8de4c78007c96e1099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Copyright (c) 2013 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2014 Kevin Smith and Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <QLineEdit>
#include <QTreeView>
#include <Swiften/Base/boost_bsignals.h>
#include <Swift/Controllers/Contact.h>

namespace Swift {

class ContactListDelegate;
class SettingsProvider;
class ContactListModel;

class QtSuggestingJIDInput : public QLineEdit {
	Q_OBJECT
	public:
		QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings);
		virtual ~QtSuggestingJIDInput();

		Contact::ref getContact();

		void setSuggestions(const std::vector<Contact::ref>& suggestions);

		boost::signal<void (const JID&)> onUserSelected;

	signals:
		void editingDone();

	protected:
		virtual void keyPressEvent(QKeyEvent* event);

	private:
		void handleSettingsChanged(const std::string& setting);

	private slots:
		void handleClicked(const QModelIndex& index);
		void handleApplicationFocusChanged(QWidget* old, QWidget* now);

	private:
		void positionPopup();
		void showPopup();
		void hidePopup();

	private:
		SettingsProvider* settings_;
		ContactListModel* contactListModel_;
		QTreeView* treeViewPopup_;
		ContactListDelegate* contactListDelegate_;
		Contact::ref currentContact_;
};

}