forked from 2600hz/kazoo-popup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
informerdialog.cpp
137 lines (118 loc) · 3.68 KB
/
informerdialog.cpp
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
127
128
129
130
131
132
133
134
135
136
137
#include "informerdialog.h"
#include "ui_informerdialog.h"
#include "caller.h"
#include <QMouseEvent>
#include <QDesktopServices>
#include <QDesktopWidget>
static const char * const kStyleSheetRinging = "QDialog {\nbackground-color: #FFFFBF;\n}";
static const char * const kStyleSheetAnswered = "QDialog {\nbackground-color: #63C248;\n}";
static const char * const kStyleSheetAnsweredAnother = "QDialog {\nbackground-color: #FFBA66;\n}";
static const char * const kStyleSheetAttached = "QDialog {\nbackground-color: #BFDFFF;\n}";
InformerDialog::InformerDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::InformerDialog)
{
ui->setupUi(this);
setWindowFlags(Qt::SplashScreen | Qt::WindowStaysOnTopHint);
connect(ui->closeToolButton, &QToolButton::clicked,
this, &InformerDialog::hide);
connect(ui->attachToolButton, &QToolButton::clicked,
this, &InformerDialog::processAttach);
connect(ui->openUrlToolButton, &QToolButton::clicked,
this, &InformerDialog::openCallerUrl);
}
InformerDialog::~InformerDialog()
{
delete ui;
}
void InformerDialog::setCaller(const Caller &caller)
{
ui->informationLabel->setText(caller.callerInfo());
m_callerUrl = caller.callerUrl();
}
void InformerDialog::setCallee(const QString &calleeNumber, const QString &calleeName)
{
QString text = ui->informationLabel->text();
text.append("\nCallee number: " + calleeNumber + "\nCallee name: " + calleeName);
ui->informationLabel->setText(text);
adjustSize();
QRect rect = qApp->desktop()->availableGeometry();
setGeometry(rect.width() - width(),
rect.height() - height(),
width(),
height());
}
void InformerDialog::setState(State state)
{
if (state == kStateAnswered)
{
setStyleSheet(kStyleSheetAnswered);
ui->stateLabel->setText(tr("State: Answered"));
}
else if (state == kStateAnsweredAnother)
{
setStyleSheet(kStyleSheetAnsweredAnother);
ui->stateLabel->setText(tr("State: Answered by another user"));
}
else if (state == kStateRinging)
{
setStyleSheet(kStyleSheetRinging);
ui->stateLabel->setText(tr("State: Ringing"));
}
}
bool InformerDialog::isAnsweredAnother() const
{
return styleSheet() == kStyleSheetAnsweredAnother;
}
void InformerDialog::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
if (rect().contains(event->pos()))
{
m_dragging = true;
setCursor(Qt::SizeAllCursor);
m_dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
}
void InformerDialog::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
m_dragging = false;
setCursor(Qt::ArrowCursor);
}
void InformerDialog::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
if (m_dragging)
{
move(event->globalPos() - m_dragPosition);
event->accept();
}
}
}
bool InformerDialog::isAttached() const
{
return ui->attachToolButton->isChecked();
}
void InformerDialog::processAttach(bool checked)
{
emit dialogAttached(checked);
if (checked)
{
setStyleSheet(kStyleSheetAttached);
ui->stateLabel->setText(tr("State: Attached"));
}
else
{
ui->stateLabel->setText(tr("State: Detached"));
}
}
void InformerDialog::openCallerUrl()
{
qDebug("Info url: %s", m_callerUrl.toLatin1().data());
QDesktopServices::openUrl(QUrl(m_callerUrl));
}