API Documentation
Loading...
Searching...
No Matches
SelectionHighlightBar.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: SelectionHighlightBar
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/WidgetOptions.h>
34#include <NDEVR/Bounds.h>
35#include <NDEVR/VectorFunctions.h>
36#include <QPainter>
37#include <QApplication>
38#include <QStylePainter>
39#include <QPropertyAnimation>
40#include <QWidget>
41namespace NDEVR
42{
43 class SelectionHighlightBar : public QWidget
44 {
45 Q_OBJECT
47 public:
48 SelectionHighlightBar(QWidget* parent = nullptr)
49 : QWidget(parent)
50 , m_move_animation(nullptr)
51 , m_old_draw_bounds(Vector<1, int>(0))
52 , m_draw_bounds(Vector<1, int>(0))
53 , m_animation_type(QEasingCurve::OutQuad)
54 , m_is_vertical(false)
55 , m_speed(300)
57 {
58 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
59 QPalette palette;
60 }
61 double animationPercent() const { return m_animation_percent; }
67 void moveHighlight(QWidget* widget)
68 {
69 Bounds<1, int> bounds;
70 if (widget != nullptr)
71 {
72 QPoint pos = mapFromGlobal(widget->mapToGlobal(QPoint(0,0)));
73 QRect geometry(pos, widget->size());
74
75 if (m_is_vertical)
76 bounds = { geometry.y(), geometry.bottomRight().y() };
77 else
78 bounds = { geometry.x(), geometry.bottomRight().x() };
79 }
80 else
81 {
82 bounds = Bounds<1, int>(currentBounds().center());
83
84 }
85 moveHighlight(bounds);
86 }
87 void moveHighlight(const Bounds<1, int>& bounds)
88 {
89 if (isVisible())
90 {
92 m_draw_bounds = bounds;
94 }
95 else
96 {
97 m_draw_bounds = bounds;
98 m_old_draw_bounds = bounds;
99 }
100 }
101
102 void setVertical(bool vertical)
103 {
104 m_is_vertical = vertical;
105 if(m_is_vertical)
106 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
107 else
108 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
109 updateGeometry();
110 update();
111 }
113 {
114 Bounds<1, int> draw_bounds;
119 return draw_bounds;
120 }
121 void paintEvent(QPaintEvent*) override
122 {
123 Bounds<1, int> draw_bounds = currentBounds();
124 QRect draw_rect;
125 if (m_is_vertical)
126 {
127 draw_rect = QRect(
128 QPoint(width() / 4, draw_bounds[MIN] - width())
129 , QPoint(width() / 1, draw_bounds[MAX] + width()));
130 }
131 else
132 {
133 draw_rect = QRect(
134 QPoint(draw_bounds[MIN] - height(), height() / 4)
135 , QPoint(draw_bounds[MAX] + height(), height() / 1));
136 }
137 QPainter p(this);
138
139
140
141 QColor highlight = palette().color(QPalette::ColorRole::Highlight);
142 QColor background = highlight.darker();
143 background.setAlphaF(0.2f);
144 QPen pen(QColor(0, 0, 0));
145 pen.setWidthF(0.5);
146 p.setPen(pen);
147 p.setBrush(background);
148 QRect entire_rect(QPoint(0, 0), size());
149 p.drawRect(entire_rect);
150 p.setPen(Qt::NoPen);
151 QLinearGradient linear;
152 linear.setColorAt(0.0, QColor(0, 0, 0, 0));
153 linear.setColorAt(0.2, highlight);
154 linear.setColorAt(0.8, highlight);
155 linear.setColorAt(1.0, QColor(0, 0, 0, 0));
156 linear.setStart(draw_rect.topLeft());
157 linear.setFinalStop(draw_rect.bottomRight());
158 p.setBrush(linear);
159
160 p.drawRect(draw_rect);
161 }
162 QSize sizeHint() const override
163 {
164 int thickness = getMax(2, style()->pixelMetric(QStyle::PixelMetric::PM_SmallIconSize) / 8);
165 if (m_is_vertical)
166 {
167 return QSize(thickness, 0);
168 }
169 else
170 {
171 return QSize(0, thickness);
172 }
173 }
174
175
176 protected:
178 {
179 if (m_move_animation == nullptr)
180 {
181 m_move_animation = new QPropertyAnimation(this, "animation_percent", this);
182 m_move_animation->setStartValue(0.0);
183 m_move_animation->setEndValue(1.0);
184 }
187 m_move_animation->setEasingCurve(m_animation_type);
189 m_move_animation->start();
190 }
191 protected:
192
193 QPropertyAnimation* m_move_animation;
196 enum QEasingCurve::Type m_animation_type;
200 };
201}
202
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
Definition SelectionHighlightBar.h:44
void setAnimationPercent(double animation_percent)
Definition SelectionHighlightBar.h:62
void paintEvent(QPaintEvent *) override
Definition SelectionHighlightBar.h:121
double animation_percent
Definition SelectionHighlightBar.h:46
Bounds< 1, int > m_old_draw_bounds
Definition SelectionHighlightBar.h:194
QSize sizeHint() const override
Definition SelectionHighlightBar.h:162
double m_animation_percent
Definition SelectionHighlightBar.h:199
void moveHighlight(QWidget *widget)
Definition SelectionHighlightBar.h:67
bool m_is_vertical
Definition SelectionHighlightBar.h:197
Bounds< 1, int > m_draw_bounds
Definition SelectionHighlightBar.h:195
int m_speed
Definition SelectionHighlightBar.h:198
double animationPercent() const
Definition SelectionHighlightBar.h:61
SelectionHighlightBar(QWidget *parent=nullptr)
Definition SelectionHighlightBar.h:48
void moveHighlight(const Bounds< 1, int > &bounds)
Definition SelectionHighlightBar.h:87
QPropertyAnimation * m_move_animation
Definition SelectionHighlightBar.h:193
void startAnimation()
Definition SelectionHighlightBar.h:177
enum QEasingCurve::Type m_animation_type
Definition SelectionHighlightBar.h:196
Bounds< 1, int > currentBounds() const
Definition SelectionHighlightBar.h:112
void setVertical(bool vertical)
Definition SelectionHighlightBar.h:102
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
static ApplicationOption< fltp08 > animation_scale
Definition WidgetOptions.h:43
Definition ACIColor.h:37
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator.
Definition BaseFunctions.hpp:116
@ MIN
Definition BaseValues.hpp:226
@ MAX
Definition BaseValues.hpp:227
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514