]>
cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/actionwithwidget.h
722fdf2843c1352e41c6bd0c8fc0845269e6025f
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <fe.a.ernst@gmail.com>
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
;
18 * @brief Small wrapper/helper class that contains an action and its widget.
20 * This class takes neither the responsibility for deleting its action() nor its widget().
22 class ActionWithWidget
25 ActionWithWidget(QAction
*action
);
28 * Connect @p action and @p button using copyActionDataToButton() and the
29 * wraps the two together in the ActionWithWidget object.
30 * ActionWithWidget doesn't take any ownership.
32 * @see copyActionDataToButton()
34 * @param button the button to be styled and used to fit the @p action.
36 ActionWithWidget(QAction
*action
, QAbstractButton
*button
);
38 /** @returns the action of this object. Crashes if that action has been deleted elsewhere in the meantime. */
39 inline QAction
*action() {
40 Q_CHECK_PTR(m_action
);
44 /** @returns the widget of this object. */
45 inline QWidget
*widget() {
50 * @returns a widget with parent @p parent for the action() of this object.
52 * For most actions some sort of button will be returned. For separators a vertical line will be returned.
53 * If this ActionWithWidget already has a widget(), this method will crash.
55 QWidget
*newWidget(QWidget
*parent
);
57 /** returns true if the widget exists and is visible. false otherwise. */
58 inline bool isWidgetVisible() const {
59 return m_widget
&& m_widget
->isVisible();
63 QPointer
<QAction
> m_action
;
64 QPointer
<QWidget
> m_widget
;
68 * A small helper method.
69 * @return a button with the correct styling for the general mode of the SelectionModeBottomBar which can be added to its layout.
71 QAbstractButton
*newButtonForAction(QAction
*action
, QWidget
*parent
);
74 * Normally, if one wants a button that represents a QAction one would use a QToolButton
75 * and simply call QToolButton::setDefaultAction(action). However if one does this, all
76 * control over the style, text, etc. of the button is forfeited. One can't for example
77 * have text on the button then, if the action has a low QAction::priority().
79 * This method styles the @p button based on the @p action without using QToolButton::setDefaultAction().
81 * Another reason why this is necessary is because the actions have application-wide scope while
82 * these buttons belong to one ViewContainer.
84 void copyActionDataToButton(QAbstractButton
*button
, QAction
*action
);
86 #endif // ACTIONWITHWIDGET_H