]>
Commit | Line | Data |
---|---|---|
6e3f046e JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
6e3f046e JH |
18 | */ |
19 | ||
7a01bd36 JH |
20 | #ifndef PULSEVIEW_PV_WIDGETS_POPUP_HPP |
21 | #define PULSEVIEW_PV_WIDGETS_POPUP_HPP | |
6e3f046e | 22 | |
f52ffd9d | 23 | #include <QScrollArea> |
6e3f046e JH |
24 | #include <QWidget> |
25 | ||
26 | namespace pv { | |
27 | namespace widgets { | |
28 | ||
f52ffd9d SA |
29 | |
30 | // A regular QScrollArea has a fixed size and provides scroll bars when the | |
31 | // content can't be shown in its entirety. However, we want no horizontal | |
32 | // scroll bar and want the scroll area to adjust its width to fit the content | |
33 | // instead. | |
34 | // Inspired by https://stackoverflow.com/questions/21253755/qscrollarea-with-dynamically-changing-contents?answertab=votes#tab-top | |
35 | class QWidthAdjustingScrollArea : public QScrollArea | |
36 | { | |
37 | Q_OBJECT | |
38 | ||
39 | public: | |
c409988b | 40 | QWidthAdjustingScrollArea(QWidget* parent = nullptr); |
f52ffd9d SA |
41 | void setWidget(QWidget* w); |
42 | bool eventFilter(QObject* obj, QEvent* ev); | |
43 | }; | |
44 | ||
45 | ||
6e3f046e JH |
46 | class Popup : public QWidget |
47 | { | |
0bce8609 JH |
48 | Q_OBJECT |
49 | ||
6e3f046e JH |
50 | public: |
51 | enum Position | |
52 | { | |
53 | Right, | |
54 | Top, | |
55 | Left, | |
56 | Bottom | |
57 | }; | |
58 | ||
59 | private: | |
60 | static const unsigned int ArrowLength; | |
61 | static const unsigned int ArrowOverlap; | |
62 | static const unsigned int MarginWidth; | |
63 | ||
64 | public: | |
65 | Popup(QWidget *parent); | |
66 | ||
67 | const QPoint& point() const; | |
68 | Position position() const; | |
69 | ||
70 | void set_position(const QPoint point, Position pos); | |
71 | ||
d9ea9628 | 72 | bool eventFilter(QObject *obj, QEvent *event); |
0715fb8c | 73 | |
dbed5609 | 74 | virtual void show(); |
0715fb8c | 75 | |
6e3f046e | 76 | private: |
092e2a0a JH |
77 | bool space_for_arrow() const; |
78 | ||
6e3f046e JH |
79 | QPolygon arrow_polygon() const; |
80 | ||
81 | QRegion arrow_region() const; | |
82 | ||
83 | QRect bubble_rect() const; | |
84 | ||
85 | QRegion bubble_region() const; | |
86 | ||
87 | QRegion popup_region() const; | |
88 | ||
89 | void reposition_widget(); | |
90 | ||
0bce8609 JH |
91 | private: |
92 | void closeEvent(QCloseEvent*); | |
93 | ||
6e3f046e JH |
94 | void paintEvent(QPaintEvent*); |
95 | ||
96 | void resizeEvent(QResizeEvent*); | |
97 | ||
d9ea9628 | 98 | void mouseReleaseEvent(QMouseEvent *event); |
6e3f046e | 99 | |
b7b659aa | 100 | protected: |
d9ea9628 | 101 | void showEvent(QShowEvent *); |
b7b659aa | 102 | |
e9213170 | 103 | Q_SIGNALS: |
0bce8609 JH |
104 | void closed(); |
105 | ||
6e3f046e | 106 | private: |
8dbbc7f0 JH |
107 | QPoint point_; |
108 | Position pos_; | |
6e3f046e JH |
109 | }; |
110 | ||
111 | } // namespace widgets | |
112 | } // namespace pv | |
113 | ||
7a01bd36 | 114 | #endif // PULSEVIEW_PV_WIDGETS_POPUP_HPP |