]>
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@zohomail.eu>
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 class ActionWithWidget
28 ActionWithWidget(QAction
*action
);
31 * Connect @p action and @p button using copyActionDataToButton() and the
32 * wraps the two together in the ActionWithWidget object.
33 * ActionWithWidget doesn't take any ownership.
35 * @see copyActionDataToButton()
37 * @param button the button to be styled and used to fit the @p action.
39 ActionWithWidget(QAction
*action
, QAbstractButton
*button
);
41 /** @returns the action of this object. Crashes if that action has been deleted elsewhere in the meantime. */
42 inline QAction
*action() {
43 Q_CHECK_PTR(m_action
);
47 /** @returns the widget of this object. */
48 inline QWidget
*widget() {
53 * @returns a widget with parent @p parent for the action() of this object.
55 * For most actions some sort of button will be returned. For separators a vertical line will be returned.
56 * If this ActionWithWidget already has a widget(), this method will crash.
58 QWidget
*newWidget(QWidget
*parent
);
60 /** returns true if the widget exists and is visible. false otherwise. */
61 inline bool isWidgetVisible() const {
62 return m_widget
&& m_widget
->isVisible();
66 QPointer
<QAction
> m_action
;
67 QPointer
<QWidget
> m_widget
;
71 * A small helper method.
72 * @return a button with the correct styling for the general mode of the SelectionModeBottomBar which can be added to its layout.
74 QAbstractButton
*newButtonForAction(QAction
*action
, QWidget
*parent
);
77 * Normally, if one wants a button that represents a QAction one would use a QToolButton
78 * and simply call QToolButton::setDefaultAction(action). However if one does this, all
79 * control over the style, text, etc. of the button is forfeited. One can't for example
80 * have text on the button then, if the action has a low QAction::priority().
82 * This method styles the @p button based on the @p action without using QToolButton::setDefaultAction().
84 * Another reason why this is necessary is because the actions have application-wide scope while
85 * these buttons belong to one ViewContainer.
87 void copyActionDataToButton(QAbstractButton
*button
, QAction
*action
);
91 #endif // ACTIONWITHWIDGET_H