File indexing completed on 2025-01-05 05:14:39

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "pushbutton.h"
0008 
0009 #include <QAction>
0010 
0011 PushButton::PushButton(QWidget *parent)
0012     : QPushButton(parent)
0013 {
0014 }
0015 
0016 QAction *PushButton::action() const
0017 {
0018     return mAction;
0019 }
0020 
0021 void PushButton::setAction(QAction *newAction)
0022 {
0023     if (mAction) {
0024         disconnect(mAction, &QAction::changed, this, &PushButton::updateButtonStatusFromAction);
0025         disconnect(this, &PushButton::clicked, mAction, &QAction::trigger);
0026     }
0027     mAction = newAction;
0028 
0029     connect(mAction, &QAction::changed, this, &PushButton::updateButtonStatusFromAction);
0030     connect(this, &PushButton::clicked, mAction, &QAction::trigger);
0031 
0032     updateButtonStatusFromAction();
0033 }
0034 
0035 void PushButton::updateButtonStatusFromAction()
0036 {
0037     if (!mAction)
0038         return;
0039     setText(mAction->text());
0040     setStatusTip(mAction->statusTip());
0041     setToolTip(mAction->toolTip());
0042     setIcon(mAction->icon());
0043     setEnabled(mAction->isEnabled());
0044     setCheckable(mAction->isCheckable());
0045     setChecked(mAction->isChecked());
0046 }
0047 
0048 #include "moc_pushbutton.cpp"