38261d0800
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines Signed-off-by: Steve Pham <spham@amazon.com>
176 lines
6.8 KiB
C++
176 lines
6.8 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
#if !defined(Q_MOC_RUN)
|
|
#include <AzQtComponents/AzQtComponentsAPI.h>
|
|
#include <AzQtComponents/Components/Widgets/ElidingLabel.h>
|
|
|
|
#include <QFrame>
|
|
#include <QIcon>
|
|
#include <QString>
|
|
#endif
|
|
|
|
class QCheckBox;
|
|
class QHBoxLayout;
|
|
class QVBoxLayout;
|
|
class QPushButton;
|
|
class QLabel;
|
|
|
|
namespace AzQtComponents
|
|
{
|
|
//! Header bar for Card widgets.
|
|
//! Provides a bar with an expander arrow, a text title and a button to trigger a context menu.
|
|
//! Also has an optional icon and help button.
|
|
//! Sub widgets are hidden by default and will show once they're configured via the appropriate setter.
|
|
//! For example, setIcon will cause the icon widget to appear.
|
|
class AZ_QT_COMPONENTS_API CardHeader
|
|
: public QFrame
|
|
{
|
|
Q_OBJECT
|
|
//! Enable warning styling.
|
|
Q_PROPERTY(bool warning READ isWarning WRITE setWarning NOTIFY warningChanged)
|
|
//! Enable read-only styling.
|
|
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
|
|
//! Enable content modified styling.
|
|
Q_PROPERTY(bool contentModified READ isContentModified WRITE setContentModified NOTIFY contentModifiedChanged)
|
|
public:
|
|
//! Enum used to determine which icon to use for the context menu button.
|
|
enum ContextMenuIcon
|
|
{
|
|
Standard, //!< Hamburger menu button.
|
|
Plus //!< Plus button, usually tied to add actions.
|
|
};
|
|
|
|
CardHeader(QWidget* parent = nullptr);
|
|
|
|
//! Sets the Card Header title. Passing an empty string will hide the Card Header.
|
|
void setTitle(const QString& title);
|
|
//! Returns the current title.
|
|
QString title() const;
|
|
//! Returns a direct pointer to the title label.
|
|
AzQtComponents::ElidingLabel* titleLabel() const;
|
|
|
|
//! Sets the filter string. If the title contains the filter string, it will be highlighted.
|
|
//! Used to enhance searches.
|
|
void setFilter(const QString& filterString);
|
|
|
|
//! Sets a custom property to the title label.
|
|
//! Can be used to
|
|
void setTitleProperty(const char *name, const QVariant &value);
|
|
//! Forces a repaint of the title.
|
|
//! Can be used to refresh the widget after style or property changes are applied.
|
|
void refreshTitle();
|
|
|
|
//! Sets the icon. Passing a null icon will hide the current icon.
|
|
void setIcon(const QIcon& icon);
|
|
|
|
//! Set whether the header displays an expander button.
|
|
//! Note that the header itself will not change size or hide, it simply causes
|
|
//! the onExpanderChanged signal to fire.
|
|
void setExpandable(bool expandable);
|
|
//! Returns true if the Card Header is showing and expander button, false otherwise.
|
|
bool isExpandable() const;
|
|
|
|
//! Sets the parent Card's expanded state.
|
|
void setExpanded(bool expanded);
|
|
//! Returns the parent Card's expanded state.
|
|
bool isExpanded() const;
|
|
|
|
//! Sets the warning state on the Card Header.
|
|
void setWarning(bool warning);
|
|
//! Returns true if the Card Header's warning state is set, false otherwise.
|
|
bool isWarning() const;
|
|
//! Sets a new QIcon for the warning state.
|
|
void setWarningIcon(const QIcon& icon);
|
|
|
|
//! Sets the read only state on the Card Header.
|
|
void setReadOnly(bool readOnly);
|
|
//! Returns true if the Card Header's read only state is set, false otherwise.
|
|
bool isReadOnly() const;
|
|
|
|
//! Sets the modified state on the Card Header.
|
|
void setContentModified(bool modified);
|
|
//! Returns true if the Card Header's modified state is set, false otherwise.
|
|
bool isContentModified() const;
|
|
|
|
//! Sets whether the header has a context menu widget.
|
|
//! This determines whether or not the contextMenuRequested signal fires on right-click, or when
|
|
//! the context menu button is pressed.
|
|
void setHasContextMenu(bool showContextMenu);
|
|
|
|
//! Sets the help url on the Card Header.
|
|
//! If a url is set, a question mark icon will be displayed on the right and it will open the
|
|
//! default browser on the url provided on click.
|
|
void setHelpURL(const QString& url);
|
|
//! Resets the help url and hides the question mark button.
|
|
void clearHelpURL();
|
|
//! Returns the help url for this Card Header if set.
|
|
QString helpURL() const;
|
|
|
|
//! Forces a refresh of the icon and warning icon on the Card Header.
|
|
void configSettingsChanged();
|
|
|
|
//! Sets the mock disabled state.
|
|
//! This will make the Card Header look disabled, but the buttons will still work.
|
|
void mockDisabledState(bool disabled);
|
|
|
|
//! Sets the size of the Card header's icon.
|
|
static void setIconSize(int iconSize);
|
|
|
|
//! Returns the default size for the Card Header's icon.
|
|
static int defaultIconSize();
|
|
|
|
//! Sets the icon to be displayed for the context menu.
|
|
void setContextMenuIcon(ContextMenuIcon iconType);
|
|
|
|
Q_SIGNALS:
|
|
//! Triggered when the context menu button is clicked, or on a right click.
|
|
void contextMenuRequested(const QPoint& position);
|
|
//! Triggered when the expander state is changed.
|
|
void expanderChanged(bool expanded);
|
|
//! Triggered when the warning state is changed.
|
|
void warningChanged(bool warning);
|
|
//! Triggered when the read only state is changed.
|
|
void readOnlyChanged(bool readOnly);
|
|
//! Triggered when the content modified state is changed.
|
|
void contentModifiedChanged(bool modified);
|
|
|
|
protected:
|
|
friend class Card;
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent* event) override;
|
|
void contextMenuEvent(QContextMenuEvent* event) override;
|
|
void triggerContextMenuUnderButton();
|
|
void triggerHelpButton();
|
|
|
|
static bool isCardHeaderIcon(const QWidget* widget);
|
|
static bool isCardHeaderMenuButton(const QWidget* widget);
|
|
|
|
// Widgets in header
|
|
QVBoxLayout* m_mainLayout = nullptr;
|
|
QHBoxLayout* m_backgroundLayout = nullptr;
|
|
QFrame* m_backgroundFrame = nullptr;
|
|
QCheckBox* m_expanderButton = nullptr;
|
|
QLabel* m_iconLabel = nullptr;
|
|
AzQtComponents::ElidingLabel* m_titleLabel = nullptr;
|
|
QLabel* m_warningLabel = nullptr;
|
|
QPushButton* m_contextMenuButton = nullptr;
|
|
QPushButton* m_helpButton = nullptr;
|
|
bool m_warning = false;
|
|
bool m_readOnly = false;
|
|
bool m_modified = false;
|
|
|
|
QIcon m_warningIcon;
|
|
QIcon m_icon;
|
|
QString m_helpUrl;
|
|
|
|
static int s_iconSize;
|
|
};
|
|
} // namespace AzQtComponents
|