summaryrefslogtreecommitdiffstats
blob: 12d34f5c76f89759ac3d7683d3d792626d77f1ec (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (c) 2010-2014 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <QDragEnterEvent>
#include <QDropEvent>
#include <QDragMoveEvent>
#include <QModelIndex>
#include <QTreeView>
 
#include <Swift/QtUI/Roster/RosterDelegate.h>
#include <Swift/QtUI/Roster/RosterModel.h>

#include <Swift/Controllers/UIInterfaces/ChatWindow.h>

namespace Swift {
class UIEventStream;
class SettingsProvider;

class QtTreeWidget : public QTreeView {
	Q_OBJECT
	public:
		enum MessageTarget {MessageDefaultJID, MessageDisplayJID};

		QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget messageTarget, QWidget* parent = 0);
		~QtTreeWidget();
		void show();
		QtTreeWidgetItem* getRoot();
		void setRosterModel(Roster* roster);
		Roster* getRoster() {return roster_;}
		void refreshTooltip();
		void setMessageTarget(MessageTarget messageTarget);
		JID jidFromIndex(const QModelIndex& index) const;
		JID selectedJID() const;
		void setOnline(bool isOnline);

	public:
		boost::signal<void (RosterItem*)> onSomethingSelectedChanged;

	private slots:
		void handleItemActivated(const QModelIndex&);
		void handleModelItemExpanded(const QModelIndex&, bool expanded);
		void handleExpanded(const QModelIndex&);
		void handleCollapsed(const QModelIndex&);
		void handleClicked(const QModelIndex&);
		void handleSettingChanged(const std::string& setting);
		void handleRefreshTooltip();

	protected:
		void dragEnterEvent(QDragEnterEvent* event);
		void dropEvent(QDropEvent* event);
		void dragMoveEvent(QDragMoveEvent* event);
		bool event(QEvent* event);
		QModelIndexList getSelectedIndexes() const;
		bool isOnline() const;

	private:
		void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;

	protected slots:
		virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
	protected:
		UIEventStream* eventStream_;

	private:
		RosterModel* model_;
		Roster* roster_;
		RosterDelegate* delegate_;
		QtTreeWidgetItem* treeRoot_;
		SettingsProvider* settings_;
		bool tooltipShown_;
		MessageTarget messageTarget_;
		bool isOnline_;
};

}