NDEVR
API Documentation
RibbonSubGroup.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: NDEVR
28File: RibbonSubGroup
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/RibbonLayoutMode.h>
34#include <NDEVR/Button.h>
35#include <NDEVR/QCustomLabel.h>
36class QGridLayout;
37namespace NDEVR
38{
39 class Button;
40 class QCustomLabel;
41 class Button;
47 class NDEVR_WIDGETS_API RibbonSubGroup : public QWidget
48 {
49 Q_OBJECT
50 friend class RibbonGroup;
51 public:
56 RibbonSubGroup(QWidget* parent = nullptr);
60 void init();
66 RibbonSubGroup(const TranslatedString& title, QWidget* parent = nullptr);
74 Button* addButton(Button* button, uint04 index = Constant<uint04>::Invalid, bool update_layout = false);
79 const Buffer<QPointer<Button>>& buttons() const { return m_buttons; }
84 void removeButton(Button* button);
93 void clear();
98 void setIgnoredSize(bool ignored);
103 QSize sizeHint() const override;
108 QSize minimumSizeHint() const override;
113 void setSpacing(int spacing);
118 int currentPrimary() const;
123 int currentSecondary() const;
132 bool isEmpty() const;
137 int largeButtonWidth() const;
142 int mediumButtonWidth() const;
147 void setIconSizeMultiplier(fltp04 size_multiplier);
158 virtual void setVisible(bool is_visible) override;
163 void setLayoutMode(RibbonLayoutMode layout_mode) { m_layout_mode = layout_mode; }
168 void setNumberOfRows(uint04 number_of_rows);
173 int marginThickness() const;
178 void setExpandingIcons(bool expanding);
188 const TranslatedString& title() const { return m_title; }
194 void resizeEvent(QResizeEvent* resize_event) override;
199 void setFixedNumOfRows(uint01 fixed_num_of_rows);
212 virtual void sortButtons(const std::function<bool(Button*, Button*)>& sorter);
217 void setVertical(bool is_vertical);
222 void setAvailableButtonStates(const Buffer<Button::ButtonState>& available_button_states);
223 signals:
225 private:
226 void updateButtonSize(uint04 button, int secondary_size, bool use_default);
227 bool event(QEvent* ev) override;
228 void customLayout();
229 void addToButtonSize(Button* button);
230 Vector<2, int> largeButtonSize() { return m_large_button_size; }
231 void updateLayout(QSize size);
232 int secondarySize();
233 void resetButtonState();
234 bool requestLarger();
235 bool requestLarger(int secondary_size);
236 bool requestSmaller(uint01 priority, uint04 col_count);
237 bool requestSmaller(uint01 priority, uint04 col_count, int secondary_size);
238 void autoFitIcons();
239 uint04 weight() const;
240 void updateLabel();
241 void _ribbonResizeEvent(int primary, int secondary);
242 protected:
245 QGridLayout* m_layout;
248 QWidget* m_button_panel;
253
257
263 };
264}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core widget that allows the user to click one of many button types.
Definition Button.h:68
Displays translated text.
Buffer< Button::ButtonState > m_available_button_states
Allowed button states for adaptive resizing.
int m_last_width
Last known width, used to detect resize changes.
virtual void sortButtons(const std::function< bool(Button *, Button *)> &sorter)
Sorts the buttons in this sub-group using the given comparison function.
Button * addButton(Button *button, uint04 index=Constant< uint04 >::Invalid, bool update_layout=false)
Adds a button to this sub-group at the specified index.
QSize sizeHint() const override
Returns the recommended size for this sub-group.
bool m_is_vertical
Whether the layout is vertical.
RibbonSubGroup(QWidget *parent=nullptr)
Constructs a ribbon sub-group widget.
Vector< 2, int > estimatedSize() const
Returns the estimated size of this sub-group.
void init()
Initializes the sub-group layout and label after construction.
void setIconSizeMultiplier(fltp04 size_multiplier)
Sets a multiplier applied to icon sizes in this sub-group.
void setExpandingIcons(bool expanding)
Sets whether icons should expand to fill available space.
Buffer< QPointer< Button > > m_buttons
Ordered list of buttons in the sub-group.
uint01 m_fixed_num_of_rows
Fixed number of rows, or 0 for automatic.
bool m_expanding_icons
Whether icons expand to fill available space.
const Buffer< QPointer< Button > > & buttons() const
Returns the list of buttons in this sub-group.
void cleanupEmpty()
Removes any buttons that have been destroyed or are empty.
void setAvailableButtonStates(const Buffer< Button::ButtonState > &available_button_states)
Sets the available button states that buttons may cycle through during resize.
Vector< 2, int > minSize() const
Returns the minimum size as a 2D vector (primary, secondary).
bool isEmpty() const
Returns whether this sub-group has no buttons.
bool m_ignored_size
Whether this sub-group's size is ignored during layout.
int mediumButtonWidth() const
Returns the width of a medium button in the current layout.
void setSpacing(int spacing)
Sets the spacing between buttons in the layout.
int largeButtonWidth() const
Returns the width of a large button in the current layout.
bool m_auto_fill_table
Whether to automatically fill the layout grid.
const TranslatedString & title() const
Returns the title of this sub-group.
QCustomLabel * m_label
Label displaying the sub-group title.
QWidget * m_button_panel
Panel widget containing the buttons.
Vector< 2, int > m_full_size
The full calculated size of the sub-group.
uint04 numOfColumns() const
Returns the number of columns in the current button layout.
void setNumberOfRows(uint04 number_of_rows)
Sets the number of rows used for laying out buttons.
QSize minimumSizeHint() const override
Returns the minimum recommended size for this sub-group.
Vector< 2, int > m_large_button_size
The size of a large button in the current layout.
int currentPrimary() const
Returns the current size along the primary layout axis.
void updateRibbonLayoutIfNeeded()
Updates the ribbon layout only if changes have been detected.
void updateRibbonLayout()
Updates the ribbon layout of this sub-group.
RibbonSubGroup(const TranslatedString &title, QWidget *parent=nullptr)
Constructs a ribbon sub-group with a title.
RibbonLayoutMode m_layout_mode
The current layout mode.
Vector< 2, int > calcSize() const
Calculates the ideal size for this sub-group based on its buttons.
void requestLayoutUpdate()
Signal emitted when the sub-group requests a parent layout update.
TranslatedString m_title
The displayed title of the sub-group.
uint01 m_num_of_rows
Current number of layout rows.
void setLayoutMode(RibbonLayoutMode layout_mode)
Sets the layout mode for button arrangement.
int currentSecondary() const
Returns the current size along the secondary layout axis.
void setFixedNumOfRows(uint01 fixed_num_of_rows)
Sets a fixed number of rows for the layout.
QGridLayout * m_layout
Grid layout managing button placement.
fltp04 m_icon_size_multiplier
Multiplier applied to icon sizes.
void setIgnoredSize(bool ignored)
Sets whether this sub-group's size should be ignored during layout calculations.
void removeButton(Button *button)
Removes a button from this sub-group.
Vector< 2, int > m_estimated_size
The estimated size used for layout planning.
void setVertical(bool is_vertical)
Sets whether the sub-group layout is vertical.
int marginThickness() const
Returns the margin thickness around the sub-group content.
void clear()
Removes all buttons from this sub-group.
void setTitle(const TranslatedString &title)
Sets the displayed title for this sub-group.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
RibbonLayoutMode
The orientations a ribbon can take on.