File indexing completed on 2025-02-02 14:20:12
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org> 0004 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0005 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org> 0006 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> 0007 SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org> 0008 SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org> 0009 SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org> 0010 SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org> 0011 SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org> 0012 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> 0013 0014 SPDX-License-Identifier: LGPL-2.0-only 0015 */ 0016 0017 #include "ktoggleaction.h" 0018 #include "ktoggleaction_p.h" 0019 0020 KToggleAction::KToggleAction(QObject *parent) 0021 : KToggleAction(*new KToggleActionPrivate(this), parent) 0022 { 0023 } 0024 0025 KToggleAction::KToggleAction(KToggleActionPrivate &dd, QObject *parent) 0026 : QAction(parent) 0027 , d(&dd) 0028 { 0029 Q_D(KToggleAction); 0030 0031 d->init(); 0032 } 0033 0034 KToggleAction::KToggleAction(const QString &text, QObject *parent) 0035 : QAction(parent) 0036 , d(new KToggleActionPrivate(this)) 0037 { 0038 Q_D(KToggleAction); 0039 0040 setText(text); 0041 d->init(); 0042 } 0043 0044 KToggleAction::KToggleAction(const QIcon &icon, const QString &text, QObject *parent) 0045 : QAction(parent) 0046 , d(new KToggleActionPrivate(this)) 0047 { 0048 Q_D(KToggleAction); 0049 0050 setIcon(icon); 0051 setText(text); 0052 d->init(); 0053 } 0054 0055 KToggleAction::~KToggleAction() = default; 0056 0057 void KToggleAction::setCheckedState(const KGuiItem &checkedItem) 0058 { 0059 Q_D(KToggleAction); 0060 0061 delete d->checkedGuiItem; 0062 d->checkedGuiItem = new KGuiItem(checkedItem); 0063 } 0064 0065 void KToggleAction::slotToggled(bool) 0066 { 0067 Q_D(KToggleAction); 0068 0069 if (d->checkedGuiItem) { 0070 QString string = d->checkedGuiItem->text(); 0071 d->checkedGuiItem->setText(text()); 0072 setText(string); 0073 0074 string = d->checkedGuiItem->toolTip(); 0075 d->checkedGuiItem->setToolTip(toolTip()); 0076 setToolTip(string); 0077 0078 if (d->checkedGuiItem->hasIcon()) { 0079 QIcon icon = d->checkedGuiItem->icon(); 0080 d->checkedGuiItem->setIcon(this->icon()); 0081 QAction::setIcon(icon); 0082 } 0083 } 0084 } 0085 0086 #include "moc_ktoggleaction.cpp"