1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

CallConfirmWidget: track anchor's position

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2015-01-25 18:43:30 +01:00
parent b10edb9baf
commit 279debdab9
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
4 changed files with 39 additions and 11 deletions

View File

@ -10,14 +10,12 @@
#include <QRect>
#include <QPalette>
CallConfirmWidget::CallConfirmWidget(QWidget *anchor) :
QWidget(Widget::getInstance()),
CallConfirmWidget::CallConfirmWidget(const QWidget *Anchor) :
QWidget(Widget::getInstance()), anchor(Anchor),
rectW{130}, rectH{90},
spikeW{30}, spikeH{15},
roundedFactor{15}
{
Widget* w = Widget::getInstance();
setWindowFlags(Qt::SubWindow);
QPalette palette;
@ -36,12 +34,23 @@ CallConfirmWidget::CallConfirmWidget(QWidget *anchor) :
connect(buttonBox, &QDialogButtonBox::accepted, this, &CallConfirmWidget::accepted);
connect(buttonBox, &QDialogButtonBox::rejected, this, &CallConfirmWidget::rejected);
connect(Widget::getInstance(), &Widget::resized, this, &CallConfirmWidget::reposition);
layout->setMargin(12);
layout->addSpacing(spikeH);
layout->addWidget(callLabel);
layout->addWidget(buttonBox);
QPoint pos = anchor->mapToGlobal({(anchor->width()-width())/2,anchor->height()})-w->mapToGlobal({0,0});
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
int xOverflow=0;
if (pos.x() + rectW > w->width())
xOverflow = pos.x() + rectW - w->width();
@ -49,12 +58,12 @@ CallConfirmWidget::CallConfirmWidget(QWidget *anchor) :
mainRect = {0,spikeH,rectW,rectH};
brush = QBrush(QColor(65,65,65));
spikePoly = QPolygon({{(rectW-spikeW+xOverflow)/2,spikeH},
{(rectW+xOverflow)/2,0},
{(rectW+spikeW+xOverflow)/2,spikeH}});
spikePoly = QPolygon({{(rectW-spikeW)/2+xOverflow,spikeH},
{rectW/2+xOverflow,0},
{(rectW+spikeW)/2+xOverflow,spikeH}});
setFixedSize(rectW,rectH+spikeH);
move(pos);
update();
}
void CallConfirmWidget::paintEvent(QPaintEvent*)
@ -67,3 +76,9 @@ void CallConfirmWidget::paintEvent(QPaintEvent*)
painter.drawRoundRect(mainRect, roundedFactor, roundedFactor);
painter.drawPolygon(spikePoly);
}
void CallConfirmWidget::showEvent(QShowEvent*)
{
reposition();
update();
}

View File

@ -7,12 +7,16 @@
#include <QBrush>
class QPaintEvent;
class QShowEvent;
/// This is a widget with dialog buttons to accept/reject a call
/// It tracks the position of another widget called the anchor
/// and looks like a bubble at the bottom of that widget.
class CallConfirmWidget : public QWidget
{
Q_OBJECT
public:
explicit CallConfirmWidget(QWidget *anchor);
explicit CallConfirmWidget(const QWidget *Anchor);
signals:
void accepted();
@ -20,15 +24,21 @@ signals:
protected:
virtual void paintEvent(QPaintEvent* event) override;
virtual void showEvent(QShowEvent * event) override;
protected slots:
void reposition(); ///< Recalculate our positions to track the anchor
private:
const QWidget* anchor; ///< The widget we're going to be tracking
QRect mainRect;
QPolygon spikePoly;
QBrush brush;
const int rectW, rectH;
const int spikeW, spikeH;
const int roundedFactor;
const int roundedFactor; ///< By how much are the corners of the main rect rounded
};
#endif // CALLCONFIRMWIDGET_H

View File

@ -377,6 +377,8 @@ void Widget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
saveWindowGeometry();
emit resized();
}
QString Widget::detectProfile()

View File

@ -90,6 +90,7 @@ signals:
void usernameChanged(const QString& username);
void statusMessageChanged(const QString& statusMessage);
void changeProfile(const QString& profile);
void resized();
private slots:
void onConnected();