summaryrefslogtreecommitdiffstats
path: root/src/gui/osd.cpp
blob: 421f021328925a7cf7ec70c63a4142fc0e082b1a (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "osd.h"
#include <QtDebug>

#include <QDesktopWidget>
#include <QSettings>
#include <QApplication>
#include <QQuickView>
#include <QQuickItem>
#include <QQmlContext>

extern QSettings* g_gui_state;

OSD::OSD(QObject* parent)
	: QObject(parent)
{
	m_view = new QQuickView;
	m_view->setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::ToolTip);

	m_view->rootContext()->setContextProperty("viewerWidget", m_view);
	m_view->setSource(QUrl("qrc:/qml/osd.qml"));

	positionWindow();

	QObject* buttonHangup;
	buttonHangup = m_view->rootObject()->findChild<QObject*>("hangup");

	connect(buttonHangup, SIGNAL(clicked()), this, SLOT(onHangupClicked()));

	m_caller = m_view->rootObject()->findChild<QQuickItem*>("callerName");
	m_time = m_view->rootObject()->findChild<QQuickItem*>("callTime");
	m_mute = m_view->rootObject()->findChild<QQuickItem*>("mute");

	connect(m_mute, SIGNAL(clicked()), this, SLOT(onMuteClicked()));

	connect(m_view->rootObject(), SIGNAL(moved()), this, SLOT(saveState()));
}

OSD::~OSD()
{
	delete m_view;
}

void OSD::positionWindow()
{
	QDesktopWidget* desktop = QApplication::desktop();
	int x, y;
	int defaultX, defaultY;

	defaultX = desktop->width() - this->width() - 10;
	defaultY = 10;

	x = g_gui_state->value("osd/x", defaultX).toInt();
	y = g_gui_state->value("osd/y", defaultY).toInt();

	// Reset position if off screen
	if (x > desktop->width() || x < 0)
		x = defaultX;
	if (y > desktop->height() || y < 0)
		y = defaultY;

	m_view->setPosition(x, y);
}

void OSD::saveState()
{
	QPoint pos = m_view->position();
	g_gui_state->setValue("osd/x", pos.x());
	g_gui_state->setValue("osd/y", pos.y());
}

void OSD::onHangupClicked()
{
	emit hangupClicked();
}

void OSD::onMuteClicked()
{
	emit muteClicked();
}

void OSD::setMuted(bool muted)
{
	QString path;

	if (muted)
		path = "qrc:/icons/images/osd_mic_off.png";
	else
		path = "qrc:/icons/images/osd_mic_on.png";

	m_mute->setProperty("image", path);
}

void OSD::setCaller(const QString& text)
{
	m_caller->setProperty("text", text);
}

void OSD::setTime(const QString& timeText)
{
	m_time->setProperty("text", timeText);
}

void OSD::move(int x, int y)
{
	m_view->setPosition(x, y);
}

void OSD::show()
{
	m_view->show();
}

void OSD::hide()
{
	m_view->hide();
}

int OSD::width() const
{
	return m_view->width();
}

int OSD::height() const
{
	return m_view->height();
}