2015-01-25 11:57:20 +08:00
|
|
|
#include "callconfirmwidget.h"
|
|
|
|
#include "widget.h"
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QDialogButtonBox>
|
2015-01-25 23:46:33 +08:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPaintEvent>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QPalette>
|
2015-01-25 11:57:20 +08:00
|
|
|
|
2015-01-26 01:43:30 +08:00
|
|
|
CallConfirmWidget::CallConfirmWidget(const QWidget *Anchor) :
|
|
|
|
QWidget(Widget::getInstance()), anchor(Anchor),
|
2015-01-25 23:46:33 +08:00
|
|
|
rectW{130}, rectH{90},
|
|
|
|
spikeW{30}, spikeH{15},
|
|
|
|
roundedFactor{15}
|
2015-01-25 11:57:20 +08:00
|
|
|
{
|
|
|
|
setWindowFlags(Qt::SubWindow);
|
2015-01-25 23:46:33 +08:00
|
|
|
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
setPalette(palette);
|
2015-01-25 11:57:20 +08:00
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
QLabel *callLabel = new QLabel(tr("Incoming call..."), this);
|
2015-01-25 23:46:33 +08:00
|
|
|
callLabel->setAlignment(Qt::AlignHCenter);
|
2015-01-25 11:57:20 +08:00
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
|
2015-01-25 23:46:33 +08:00
|
|
|
QPushButton *accept = new QPushButton("Accept", this), *reject = new QPushButton("Reject", this);
|
2015-01-25 11:57:20 +08:00
|
|
|
|
|
|
|
buttonBox->addButton(accept, QDialogButtonBox::AcceptRole);
|
|
|
|
buttonBox->addButton(reject, QDialogButtonBox::RejectRole);
|
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::accepted, this, &CallConfirmWidget::accepted);
|
|
|
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &CallConfirmWidget::rejected);
|
|
|
|
|
2015-01-26 01:43:30 +08:00
|
|
|
connect(Widget::getInstance(), &Widget::resized, this, &CallConfirmWidget::reposition);
|
|
|
|
|
2015-01-25 23:46:33 +08:00
|
|
|
layout->setMargin(12);
|
|
|
|
layout->addSpacing(spikeH);
|
2015-01-25 11:57:20 +08:00
|
|
|
layout->addWidget(callLabel);
|
|
|
|
layout->addWidget(buttonBox);
|
|
|
|
|
2015-01-26 01:43:30 +08:00
|
|
|
setFixedSize(rectW,rectH+spikeH);
|
|
|
|
reposition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CallConfirmWidget::reposition()
|
|
|
|
{
|
|
|
|
Widget* w = Widget::getInstance();
|
|
|
|
QPoint pos = anchor->mapToGlobal({(anchor->width()-rectW)/2,anchor->height()})-w->mapToGlobal({0,0});
|
|
|
|
|
|
|
|
// We don't want the widget to overflow past the right of the screen
|
2015-01-26 00:53:37 +08:00
|
|
|
int xOverflow=0;
|
|
|
|
if (pos.x() + rectW > w->width())
|
|
|
|
xOverflow = pos.x() + rectW - w->width();
|
|
|
|
pos.rx() -= xOverflow;
|
|
|
|
|
2015-01-25 23:46:33 +08:00
|
|
|
mainRect = {0,spikeH,rectW,rectH};
|
|
|
|
brush = QBrush(QColor(65,65,65));
|
2015-01-26 01:43:30 +08:00
|
|
|
spikePoly = QPolygon({{(rectW-spikeW)/2+xOverflow,spikeH},
|
|
|
|
{rectW/2+xOverflow,0},
|
|
|
|
{(rectW+spikeW)/2+xOverflow,spikeH}});
|
2015-01-25 23:46:33 +08:00
|
|
|
|
2015-01-26 00:53:37 +08:00
|
|
|
move(pos);
|
2015-01-26 01:43:30 +08:00
|
|
|
update();
|
2015-01-25 11:57:20 +08:00
|
|
|
}
|
2015-01-25 23:46:33 +08:00
|
|
|
|
|
|
|
void CallConfirmWidget::paintEvent(QPaintEvent*)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setBrush(brush);
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
|
|
|
|
painter.drawRoundRect(mainRect, roundedFactor, roundedFactor);
|
|
|
|
painter.drawPolygon(spikePoly);
|
|
|
|
}
|
2015-01-26 01:43:30 +08:00
|
|
|
|
|
|
|
void CallConfirmWidget::showEvent(QShowEvent*)
|
|
|
|
{
|
|
|
|
reposition();
|
|
|
|
update();
|
|
|
|
}
|