2009-04-24 10:55:31 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright 2009 by Aaron Seigo <aseigo@kde.org> *
|
|
|
|
* *
|
|
|
|
* This library is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Library General Public *
|
|
|
|
* License as published by the Free Software Foundation; either *
|
|
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This library is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
|
|
* Library General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Library General Public License *
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to *
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
|
|
|
* Boston, MA 02110-1301, USA. *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2009-04-24 10:44:06 +02:00
|
|
|
#ifndef ACTIONWIDGETINTERFACE_P_H
|
2009-04-24 10:55:31 +02:00
|
|
|
#define ACTIONWIDGETINTERFACE_P_H
|
|
|
|
|
2009-04-24 10:44:06 +02:00
|
|
|
#include <QAction>
|
|
|
|
|
2010-10-22 02:25:17 +02:00
|
|
|
#include "private/themedwidgetinterface_p.h"
|
|
|
|
|
2009-04-24 10:44:06 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class T>
|
2010-10-22 02:25:17 +02:00
|
|
|
class ActionWidgetInterface : public ThemedWidgetInterface<T>
|
2009-04-24 10:44:06 +02:00
|
|
|
{
|
|
|
|
public:
|
2010-10-22 02:25:17 +02:00
|
|
|
ActionWidgetInterface(T *parent)
|
2010-10-22 14:29:35 +02:00
|
|
|
: ThemedWidgetInterface<T>(parent),
|
2009-04-24 10:44:06 +02:00
|
|
|
action(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ActionWidgetInterface()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void changed()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearAction()
|
|
|
|
{
|
|
|
|
action = 0;
|
|
|
|
syncToAction();
|
|
|
|
changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void syncToAction()
|
|
|
|
{
|
|
|
|
if (!action) {
|
2010-10-22 21:52:05 +02:00
|
|
|
this->q->setIcon(QIcon());
|
|
|
|
this->q->setText(QString());
|
|
|
|
this->q->setEnabled(false);
|
2009-04-24 10:44:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//we don't get told *what* changed, just that something changed
|
|
|
|
//so we update everything we care about
|
2010-10-22 21:52:05 +02:00
|
|
|
this->q->setIcon(action->icon());
|
|
|
|
this->q->setText(action->iconText());
|
|
|
|
this->q->setEnabled(action->isEnabled());
|
|
|
|
this->q->setVisible(action->isVisible());
|
2009-04-24 10:44:06 +02:00
|
|
|
|
2010-10-22 21:52:05 +02:00
|
|
|
if (!this->q->toolTip().isEmpty()) {
|
|
|
|
this->q->setToolTip(action->text());
|
2009-04-24 10:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAction(QAction *a)
|
|
|
|
{
|
|
|
|
if (action) {
|
2010-10-22 21:52:05 +02:00
|
|
|
QObject::disconnect(action, 0, this->q, 0);
|
|
|
|
QObject::disconnect(this->q, 0, action, 0);
|
2009-04-24 10:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
action = a;
|
|
|
|
|
|
|
|
if (action) {
|
2010-10-22 21:52:05 +02:00
|
|
|
QObject::connect(action, SIGNAL(changed()), this->q, SLOT(syncToAction()));
|
|
|
|
QObject::connect(action, SIGNAL(destroyed(QObject*)), this->q, SLOT(clearAction()));
|
|
|
|
QObject::connect(this->q, SIGNAL(clicked()), action, SLOT(trigger()));
|
2009-04-24 10:44:06 +02:00
|
|
|
syncToAction();
|
|
|
|
}
|
|
|
|
}
|
2010-10-22 21:52:05 +02:00
|
|
|
|
|
|
|
QAction *action;
|
2009-04-24 10:44:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
#endif
|
|
|
|
|