NDEVR
API Documentation
QCustomStackedWidget.h
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: QCustomStackedWidget
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/PopupInfo.h>
35#include <NDEVR/ApplicationOptions.h>
36#include <NDEVR/Buffer.h>
37#include <QEasingCurve>
38#include <QWidget>
39#include <QPropertyAnimation>
40#include <QPointer>
41namespace NDEVR
42{
43 class ImageView;
44
50 class NDEVR_WIDGETS_API QCustomStackedWidgetBase : public QWidget
51 {
52 Q_OBJECT
53 Q_PROPERTY(double animation_percent READ animationPercent WRITE setAnimationPercent)
54 public:
66
70 void setSpeed(int speed);
75 void setAnimation(enum QEasingCurve::Type animationtype);
80 void setVerticalMode(bool vertical = true);
85 void setWrap(bool wrap);
90 void setCustomPixmap(QPixmap* pixmap);
95 QSize sizeHint() const override;
100 QSize minimumSizeHint() const override;
105 virtual void setCurrentIdx(uint04 current_index);
106 protected:
111 explicit QCustomStackedWidgetBase(QWidget *parent = nullptr);
117 void resizeEvent(QResizeEvent* event) override;
122 void showEvent(QShowEvent* event) override;
127 void setAnimationPercent(double animation_percent);
132 double animationPercent() const { return m_animation_percent; }
137 void paintEvent(QPaintEvent*) override;
143 virtual void swapIndices(uint04 a, uint04 b);
149 virtual void moveContent(uint04 from, uint04 to);
155 virtual uint04 addWidget(QWidget* w);
161 void insertWidget(uint04 index, QWidget *w);
166 void removeWidget(QWidget* widget);
172 void removeWidget(QWidget* widget, QWidget* slide_to_if_active);
179 bool eventFilter(QObject* object, QEvent* event) override;
189 QWidget* activeWidget() const;
194 QWidget* currentWidget() const;
200 QWidget* widget(uint04 index) const;
206 uint04 indexOf(QWidget* widget) const;
216 uint04 count() const;
220 virtual void slideInNext();
224 virtual void slideInPrev();
232 virtual void slideInIdx(uint04 idx, PopupInfo origin_rect, int delay_time = 0, enum StackAnimationDirection direction = e_automatic);
239 virtual void slideInIdx(uint04 idx, int delay_time = 0, enum StackAnimationDirection direction = e_automatic);
245 virtual void slideInIdx(uint04 idx, enum StackAnimationDirection direction);
252 virtual void slideInAnimation(PopupInfo origin_rect, enum StackAnimationDirection direction = e_automatic, bool cache_in_image = false);
258 virtual void slideInAnimation(enum StackAnimationDirection direction = e_automatic, bool cache_in_image = false);
265 virtual void slideInWgt(QWidget* widget, enum StackAnimationDirection direction = e_automatic, bool force_slide = false);
266 public:
268 signals:
273
274 protected slots:
284
285 protected:
287 enum QEasingCurve::Type m_animationtype;
292 QPoint m_offset;
294
298 QPointer<QPropertyAnimation> m_move_animation;
301 bool m_wrap = false;
302 private:
303 QPixmap* m_cached_resize_image_out;
304 QPixmap* m_cached_resize_image_in;
305 QPixmap* m_resize_image_in_blend;
306 QPixmap* m_custom_pixmap;
307 };
308
314 {
315 public:
320 explicit QCustomStackedWidget(QWidget* parent = nullptr)
322 {}
323
324 virtual uint04 addWidget(QWidget* w) override
325 {
327 };
328
330 virtual void slideInNext() override {
332 }
333
334 virtual void slideInPrev() override {
336 }
337
345
346 void slideInIdx(uint04 idx, PopupInfo origin_rect, int delay_time = 0, enum StackAnimationDirection direction = e_automatic) override
347 {
348 QCustomStackedWidgetBase::slideInIdx(idx, origin_rect, delay_time, direction);
349 }
350
351 void slideInIdx(uint04 idx, int delay_time = 0, enum StackAnimationDirection direction = e_automatic) override {
352 QCustomStackedWidgetBase::slideInIdx(idx, delay_time, direction);
353 }
354
355 void slideInIdx(uint04 idx, enum StackAnimationDirection direction) override {
357 }
358
359 void slideInAnimation(PopupInfo origin_rect, enum StackAnimationDirection direction = e_automatic, bool cache_in_image = false)override {
360 QCustomStackedWidgetBase::slideInAnimation(origin_rect, direction, cache_in_image);
361 }
362
363 void slideInAnimation(enum StackAnimationDirection direction = e_automatic, bool cache_in_image = false) override {
364 QCustomStackedWidgetBase::slideInAnimation(direction, cache_in_image);
365 }
366
367 void slideInWgt(QWidget* widget, enum StackAnimationDirection direction = e_automatic, bool force_slide = false) override {
368 QCustomStackedWidgetBase::slideInWgt(widget, direction, force_slide);
369 }
370
378
383 void removeWidget(QWidget* widget, QWidget* slide_in)
384 {
386 }
387
392 QWidget* widget(uint04 idx) const
393 {
395 }
396
401 void insertWidget(uint04 index, QWidget* w)
402 {
404 }
405
406 void moveContent(uint04 from, uint04 to) override
407 {
409 }
410
411 void swapIndices(uint04 a, uint04 b) override
412 {
414 }
415
422
426 QWidget* activeWidget() const {
428 }
429
433 uint04 count() const {
435 }
436
441 bool hasWidget(QWidget* widget) const
442 {
444 }
445
461 };
462}
The default object to store data of any type that should persist through sessions of the application.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A widget that shows a raster image or icon.
Definition ImageView.h:44
virtual void slideInIdx(uint04 idx, PopupInfo origin_rect, int delay_time=0, enum StackAnimationDirection direction=e_automatic)
Slides to the page at the given index with animation and popup origin info.
void setSpeed(int speed)
Sets the animation duration in milliseconds for slide transitions.
static ApplicationOption< sint04 > default_stack_animation_speed
Default time in milliseconds to animate a slide transition.
virtual void slideInAnimation(PopupInfo origin_rect, enum StackAnimationDirection direction=e_automatic, bool cache_in_image=false)
Executes the slide animation using popup origin information.
uint04 currentIndex() const
Returns the index of the currently displayed page.
StackAnimationDirection
Defines the direction of slide animations between stacked pages.
@ e_automatic
Automatically determine direction based on index order.
@ e_right_to_left
Slide from right to left.
@ e_top_to_bottom
Slide from top to bottom.
@ e_left_to_right
Slide from left to right.
@ e_bottom_to_top
Slide from bottom to top.
Buffer< QWidget * > m_child_widgets
The list of child page widgets.
virtual uint04 addWidget(QWidget *w)
Adds a widget as a new page in the stacked widget.
void setCustomPixmap(QPixmap *pixmap)
Sets a custom pixmap to render during slide transitions instead of widget captures.
uint04 m_last
The index of the previously displayed page.
void setAnimation(enum QEasingCurve::Type animationtype)
Sets the easing curve type used for slide animations.
virtual void slideInIdx(uint04 idx, enum StackAnimationDirection direction)
Slides to the page at the given index with the specified direction.
QSize minimumSizeHint() const override
Returns the minimum recommended size for the stacked widget.
uint04 indexOf(QWidget *widget) const
Returns the index of the given widget in the stacked widget.
void animationDoneSlot()
Slot called when the slide animation completes to finalize the transition.
PopupInfo m_popup_info
The popup info used for animation origin calculations.
void showEvent(QShowEvent *event) override
Handles show events to ensure proper layout of the active widget.
void insertWidget(uint04 index, QWidget *w)
Inserts a widget at a specific index in the stacked widget.
void paintEvent(QPaintEvent *) override
Custom paint event that renders slide transition animations.
QPointer< QPropertyAnimation > m_move_animation
The property animation driving slide transitions.
void childDestroyedSlot(QObject *widget)
Slot called when a child widget is destroyed, to remove it from the page list.
void animationFinished()
Signal emitted when a slide animation completes.
void removeWidget(QWidget *widget)
Removes a widget from the stacked widget.
QCustomStackedWidgetBase(QWidget *parent=nullptr)
Constructs the stacked widget base.
virtual void slideInIdx(uint04 idx, int delay_time=0, enum StackAnimationDirection direction=e_automatic)
Slides to the page at the given index with animation.
double animationPercent() const
Returns the current animation interpolation percent.
bool m_wrap
Whether page navigation wraps around at boundaries.
uint04 activeIndex() const
Returns the index of the currently active (or animating-to) widget.
QSize sizeHint() const override
Returns the recommended size for the stacked widget.
virtual void slideInWgt(QWidget *widget, enum StackAnimationDirection direction=e_automatic, bool force_slide=false)
Slides to a specific widget with animation.
uint04 m_current_index
The index of the currently displayed page.
int m_speed
The animation duration in milliseconds.
virtual void swapIndices(uint04 a, uint04 b)
Swaps two child widgets at the given indices.
uint04 m_next
The index of the page being animated to.
enum QEasingCurve::Type m_animationtype
The easing curve type for slide animations.
double m_animation_percent
The current animation interpolation percent (0.0 to 1.0).
bool m_vertical
Whether slide animations are in vertical mode.
QPoint m_offset
The pixel offset used during slide animation rendering.
uint04 count() const
Returns the number of pages in the stacked widget.
void setVerticalMode(bool vertical=true)
Enables or disables vertical slide animation mode.
QWidget * activeWidget() const
Returns the currently active (or animating-to) widget.
virtual void moveContent(uint04 from, uint04 to)
Moves a child widget from one index to another.
QWidget * widget(uint04 index) const
Returns the widget at the given index.
int m_last_animation_time
The duration of the last animation in milliseconds.
void setAnimationPercent(double animation_percent)
Sets the current animation interpolation percent for the Q_PROPERTY system.
bool m_is_animating
Whether a slide animation is currently in progress.
virtual void setCurrentIdx(uint04 current_index)
Sets the current visible page index without animation.
bool eventFilter(QObject *object, QEvent *event) override
Filters events for child widgets to handle layout and visibility changes.
QWidget * currentWidget() const
Returns the currently displayed widget.
void resizeEvent(QResizeEvent *event) override
Handles resize events to update child widget geometries.
virtual void slideInAnimation(enum StackAnimationDirection direction=e_automatic, bool cache_in_image=false)
Executes the slide animation between the current and next pages.
virtual void slideInPrev()
Slides to the previous page with animation.
void setWrap(bool wrap)
Sets whether page navigation wraps around from last to first and vice versa.
uint04 m_now
The index of the currently displayed page during animation.
void removeWidget(QWidget *widget, QWidget *slide_to_if_active)
Removes a widget and slides to a replacement widget if it was the active page.
virtual void slideInNext()
Slides to the next page with animation.
void slideInAnimation(PopupInfo origin_rect, enum StackAnimationDirection direction=e_automatic, bool cache_in_image=false) override
Executes the slide animation using popup origin information.
void moveContent(uint04 from, uint04 to) override
Moves a child widget from one index to another.
virtual uint04 addWidget(QWidget *w) override
Adds a widget as a new page in the stacked widget.
void slideInWgt(QWidget *widget, enum StackAnimationDirection direction=e_automatic, bool force_slide=false) override
Slides to a specific widget with animation.
uint04 currentIndex() const
Returns the index of the currently displayed page.
void slideInAnimation(enum StackAnimationDirection direction=e_automatic, bool cache_in_image=false) override
Executes the slide animation between the current and next pages.
QWidget * widget(uint04 idx) const
Returns the widget at the given index.
uint04 count() const
Returns the number of pages in the stacked widget.
QWidget * activeWidget() const
Returns the currently active (or animating-to) widget.
QWidget * currentWidget() const
Returns the currently displayed widget.
virtual void slideInNext() override
Slides to the next page with animation.
uint04 activeIndex() const
Returns the index of the currently active (or animating-to) widget.
uint04 indexOf(QWidget *widget) const
Returns the index of the given widget.
void removeWidget(QWidget *widget, QWidget *slide_in)
Removes a widget and slides to a replacement widget if it was active.
void slideInIdx(uint04 idx, enum StackAnimationDirection direction) override
Slides to the page at the given index with the specified direction.
void slideInIdx(uint04 idx, int delay_time=0, enum StackAnimationDirection direction=e_automatic) override
Slides to the page at the given index with animation.
bool hasWidget(QWidget *widget) const
Checks whether the given widget is contained in the stacked widget.
void removeWidget(QWidget *widget)
Removes a widget from the stacked widget.
void setCurrentIndex(uint04 idx)
Sets the current visible page index without animation.
void slideInIdx(uint04 idx, PopupInfo origin_rect, int delay_time=0, enum StackAnimationDirection direction=e_automatic) override
Slides to the page at the given index with animation and popup origin info.
QCustomStackedWidget(QWidget *parent=nullptr)
Constructs a stacked widget.
void swapIndices(uint04 a, uint04 b) override
Swaps two child widgets at the given indices.
void insertWidget(uint04 index, QWidget *w)
Inserts a widget at a specific index.
virtual void slideInPrev() override
Slides to the previous page with animation.
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
Definition Angle.h:398
T wrap(T l, T x, T u)
wrap x to be in the interval [l, u]
Definition misc.h:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16