blob: 6214ca80f0989cdf1695e8656e313b317fc4dbc5 (
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
|
/***************************************************************************
copyright : (C) 2005-2006 by Robby Stephenson
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License as *
* published by the Free Software Foundation; *
* *
***************************************************************************/
#include "overlaywidget.h"
#include <qlayout.h>
using Tellico::GUI::OverlayWidget;
OverlayWidget::OverlayWidget(QWidget* parent, QWidget* anchor) : QFrame(parent)
, m_anchor(anchor)
, m_corner(TopRight) {
m_anchor->installEventFilter(this);
reposition();
hide();
}
void OverlayWidget::setCorner(Corner corner_) {
if(corner_ == m_corner) {
return;
}
m_corner = corner_;
reposition();
}
void OverlayWidget::addWidget(QWidget* widget_) {
layout()->add(widget_);
adjustSize();
}
void OverlayWidget::reposition() {
if(!m_anchor) {
return;
}
setMaximumSize(parentWidget()->size());
adjustSize();
QPoint p;
switch(m_corner) {
case BottomLeft:
p.setX(0);
p.setY(m_anchor->height());
break;
case BottomRight:
p.setX(m_anchor->width() - width());
p.setY(m_anchor->height());
break;
case TopLeft:
p.setX(0);
p.setY(-1 * height());
break;
case TopRight:
p.setX(m_anchor->width() - width());
p.setY(-1 * height());
}
// Position in the toplevelwidget's coordinates
QPoint pTopLevel = m_anchor->mapTo(topLevelWidget(), p);
// Position in the widget's parentWidget coordinates
QPoint pParent = parentWidget()->mapFrom(topLevelWidget(), pTopLevel);
// keep it on the screen
if(pParent.x() < 0) {
pParent.rx() = 0;
}
move(pParent);
}
bool OverlayWidget::eventFilter(QObject* object_, QEvent* event_) {
if(object_ == m_anchor && (event_->type() == QEvent::Move || event_->type() == QEvent::Resize)) {
reposition();
}
return QFrame::eventFilter(object_, event_);
}
void OverlayWidget::resizeEvent(QResizeEvent* event_) {
reposition();
QFrame::resizeEvent(event_);
}
bool OverlayWidget::event(QEvent* event_) {
if(event_->type() == QEvent::ChildInserted) {
adjustSize();
}
return QFrame::event(event_);
}
#include "overlaywidget.moc"
|