2015-06-06 09:40:08 +08:00
|
|
|
/*
|
|
|
|
Copyright © 2015 by The qTox Project
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-01-25 11:57:20 +08:00
|
|
|
#include "callconfirmwidget.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/widget/gui.h"
|
2015-02-07 02:01:31 +08:00
|
|
|
#include <assert.h>
|
2015-01-25 11:57:20 +08:00
|
|
|
#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) :
|
2015-02-07 02:01:31 +08:00
|
|
|
QWidget(GUI::getMainWidget()), anchor(Anchor),
|
2015-01-26 02:12:36 +08:00
|
|
|
rectW{120}, rectH{85},
|
2015-01-25 23:46:33 +08:00
|
|
|
spikeW{30}, spikeH{15},
|
2015-01-27 01:29:13 +08:00
|
|
|
roundedFactor{20},
|
|
|
|
rectRatio{static_cast<qreal>(rectH)/static_cast<qreal>(rectW)}
|
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);
|
2015-01-29 21:57:30 +08:00
|
|
|
QLabel *callLabel = new QLabel(QObject::tr("Incoming call..."), this);
|
2015-02-20 04:32:11 +08:00
|
|
|
callLabel->setWordWrap(true);
|
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-26 02:12:36 +08:00
|
|
|
QPushButton *accept = new QPushButton(this), *reject = new QPushButton(this);
|
|
|
|
accept->setFlat(true);
|
|
|
|
reject->setFlat(true);
|
|
|
|
accept->setStyleSheet("QPushButton{border:none;}");
|
|
|
|
reject->setStyleSheet("QPushButton{border:none;}");
|
2015-02-12 20:18:04 +08:00
|
|
|
accept->setIcon(QIcon(":/ui/acceptCall/acceptCall.svg"));
|
|
|
|
reject->setIcon(QIcon(":/ui/rejectCall/rejectCall.svg"));
|
2015-01-26 02:12:36 +08:00
|
|
|
accept->setIconSize(accept->size());
|
|
|
|
reject->setIconSize(reject->size());
|
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-02-07 02:01:31 +08:00
|
|
|
connect(&GUI::getInstance(), &GUI::resized, this, &CallConfirmWidget::reposition);
|
2015-01-26 01:43:30 +08:00
|
|
|
|
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()
|
|
|
|
{
|
2015-02-07 02:01:31 +08:00
|
|
|
QWidget* w = GUI::getMainWidget();
|
2015-01-26 01:43:30 +08:00
|
|
|
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);
|
|
|
|
|
2015-01-27 01:29:13 +08:00
|
|
|
painter.drawRoundRect(mainRect, roundedFactor*rectRatio, roundedFactor);
|
2015-01-25 23:46:33 +08:00
|
|
|
painter.drawPolygon(spikePoly);
|
|
|
|
}
|
2015-01-26 01:43:30 +08:00
|
|
|
|
|
|
|
void CallConfirmWidget::showEvent(QShowEvent*)
|
|
|
|
{
|
|
|
|
reposition();
|
|
|
|
update();
|
|
|
|
}
|