]>
cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/actionwithwidget.h
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #ifndef ACTIONWITHWIDGET_H
9 #define ACTIONWITHWIDGET_H
15 class QAbstractButton
;
17 namespace SelectionMode
21 * @brief Small wrapper/helper class that contains an action and its widget.
23 * This class takes neither the responsibility for deleting its action() nor its widget().
25 * This class is only used from BottomBarContentsContainer currently.
26 * @see BottomBarContentsContainer
28 class ActionWithWidget
31 ActionWithWidget(QAction
*action
);
34 * Connect @p action and @p button using copyActionDataToButton() and
35 * wraps the two together in a ActionWithWidget object.
36 * ActionWithWidget doesn't take any ownership over the parameters.
38 * @see copyActionDataToButton()
40 * @param button the button to be styled and used to fit the @p action.
42 ActionWithWidget(QAction
*action
, QAbstractButton
*button
);
44 /** @returns the action of this object. */
45 inline QAction
*action()
47 Q_CHECK_PTR(m_action
);
51 /** @returns the widget of this object. */
52 inline QWidget
*widget()
58 * @returns a widget with parent @p parent for the action() of this object.
60 * For most actions some sort of button will be returned. For separators a vertical line will be returned.
61 * If this ActionWithWidget already has a widget(), this method will crash.
63 QWidget
*newWidget(QWidget
*parent
);
65 /** returns true if the widget exists and is visible. false otherwise. */
66 inline bool isWidgetVisible() const
68 return m_widget
&& m_widget
->isVisible();
72 QPointer
<QAction
> m_action
;
73 QPointer
<QWidget
> m_widget
;
77 * A small helper method.
78 * @return a button with the correct styling for the general mode of the BottomBarContentsContainer which can be added to its layout.
80 QAbstractButton
*newButtonForAction(QAction
*action
, QWidget
*parent
);
83 * Normally, if one wants a button that represents a QAction one would use a QToolButton
84 * and simply call QToolButton::setDefaultAction(action). However if one does this, all
85 * control over the style, text, etc. of the button is forfeited. One can't for example
86 * have text on the button then, if the action has a low QAction::priority().
88 * This method styles the @p button based on the @p action without using QToolButton::setDefaultAction().
90 * Another reason why this is necessary is because the actions have application-wide scope while
91 * these buttons belong to one ViewContainer.
93 void copyActionDataToButton(QAbstractButton
*button
, QAction
*action
);
97 #endif // ACTIONWITHWIDGET_H