2
* This file is part of the Polkit-qt project
3
* Copyright (C) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
4
* Copyright (C) 2009 Dario Freddi <drf@kde.org>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public License
17
* along with this library; see the file COPYING.LIB. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
22
#include "polkitqt1-gui-actionbutton.h"
24
#include "polkitqt1-gui-actionbutton_p.h"
32
ActionButton::ActionButton(QAbstractButton *button, const QString &actionId, QObject *parent)
33
: Action(actionId, parent)
34
, d_ptr(new ActionButtonPrivate(QList<QAbstractButton *>() << button))
39
connect(this, SIGNAL(dataChanged()), SLOT(updateButton()));
42
ActionButton::ActionButton(ActionButtonPrivate &dd, const QString &actionId, QObject *parent)
43
: Action(actionId, parent)
48
connect(this, SIGNAL(dataChanged()), SLOT(updateButton()));
51
ActionButton::~ActionButton()
56
void ActionButtonPrivate::updateButton()
60
foreach(QAbstractButton *ent, buttons) {
61
ent->setVisible(q->isVisible());
62
ent->setEnabled(q->isEnabled());
63
ent->setText(q->text());
64
if (!q->toolTip().isNull()) {
65
ent->setToolTip(q->toolTip());
67
if (!q->whatsThis().isNull()) {
68
ent->setWhatsThis(q->whatsThis());
70
ent->setIcon(q->icon());
71
// if the item cannot do the action anymore
72
// lets revert to the initial state
73
if (ent->isCheckable()) {
74
ent->setChecked(q->isChecked());
79
bool ActionButton::activate()
84
foreach(QAbstractButton *ent, d->buttons) {
85
if (ent->isCheckable()) {
86
// we set the the current Action state
87
ent->setChecked(isChecked());
88
// toggle the action cause we are not directly connected there..
97
return Action::activate();
100
void ActionButton::setButton(QAbstractButton *button)
104
// First, let's clear the list
105
foreach(QAbstractButton *ent, d->buttons) {
106
d->removeButton(ent);
110
d->addButton(button);
113
void ActionButtonPrivate::addButton(QAbstractButton *button)
117
buttons.append(button);
118
QObject::connect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool)));
119
QObject::connect(q, SIGNAL(toggled(bool)), button, SLOT(toggle()));
120
if (q->isCheckable()) {
121
// the button should follow our first buttons
122
button->setCheckable(true);
123
} else if (button->isCheckable()) {
124
// if we are not checkable BUT the button
125
// is (eg a QCheckBox) we should set all buttons to
127
foreach(QAbstractButton *ent, buttons) {
128
ent->setCheckable(true);
130
// set the checkable state of Action to store the initial state
131
q->setCheckable(true);
133
// call this after m_activateOnCheck receives the value
137
void ActionButtonPrivate::removeButton(QAbstractButton *button)
141
if (buttons.contains(button)) {
142
QObject::disconnect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool)));
143
QObject::disconnect(q, SIGNAL(toggled(bool)), button, SLOT(toggle()));
144
buttons.removeOne(button);
148
QAbstractButton *ActionButton::button() const
150
Q_D(const ActionButton);
152
return d->buttons.first();
155
void ActionButtonPrivate::streamClicked(bool c)
159
emit q->clicked(qobject_cast<QAbstractButton *>(q->sender()), c);
166
#include "polkitqt1-gui-actionbutton.moc"