]>
cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/actionwithwidget.h
14db6df2224196d51f4fcaae2af49b47498a44e9
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 * 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() {
46 Q_CHECK_PTR(m_action
);
50 /** @returns the widget of this object. */
51 inline QWidget
*widget() {
56 * @returns a widget with parent @p parent for the action() of this object.
58 * For most actions some sort of button will be returned. For separators a vertical line will be returned.
59 * If this ActionWithWidget already has a widget(), this method will crash.
61 QWidget
*newWidget(QWidget
*parent
);
63 /** returns true if the widget exists and is visible. false otherwise. */
64 inline bool isWidgetVisible() const {
65 return m_widget
&& m_widget
->isVisible();
69 QPointer
<QAction
> m_action
;
70 QPointer
<QWidget
> m_widget
;
74 * A small helper method.
75 * @return a button with the correct styling for the general mode of the BottomBarContentsContainer which can be added to its layout.
77 QAbstractButton
*newButtonForAction(QAction
*action
, QWidget
*parent
);
80 * Normally, if one wants a button that represents a QAction one would use a QToolButton
81 * and simply call QToolButton::setDefaultAction(action). However if one does this, all
82 * control over the style, text, etc. of the button is forfeited. One can't for example
83 * have text on the button then, if the action has a low QAction::priority().
85 * This method styles the @p button based on the @p action without using QToolButton::setDefaultAction().
87 * Another reason why this is necessary is because the actions have application-wide scope while
88 * these buttons belong to one ViewContainer.
90 void copyActionDataToButton(QAbstractButton
*button
, QAction
*action
);
94 #endif // ACTIONWITHWIDGET_H