2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file Action.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-08-17 08:36:59 +00:00
|
|
|
#include "Action.h"
|
|
|
|
|
2015-07-16 07:45:45 +00:00
|
|
|
// DispatchResult.h is needed by the windows compiler because lyx::dispatch
|
|
|
|
// returns a DispatchResult const reference. Gcc does not complain. Weird...
|
|
|
|
#include "DispatchResult.h"
|
2007-09-28 23:14:33 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2015-07-16 07:45:45 +00:00
|
|
|
|
2007-09-28 23:14:33 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2016-08-03 21:06:20 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
2016-08-03 21:06:20 +00:00
|
|
|
Action::Action(FuncRequest func, QIcon const & icon, QString const & text,
|
|
|
|
QString const & tooltip, QObject * parent)
|
|
|
|
: QAction(parent), func_(make_shared<FuncRequest>(move(func)))
|
|
|
|
{
|
|
|
|
init(icon, text, tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Action::Action(shared_ptr<FuncRequest const> func,
|
|
|
|
QIcon const & icon, QString const & text,
|
|
|
|
QString const & tooltip, QObject * parent)
|
2013-05-02 17:22:10 +00:00
|
|
|
: QAction(parent), func_(func)
|
2016-08-03 21:06:20 +00:00
|
|
|
{
|
|
|
|
init(icon, text, tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Action::init(QIcon const & icon, QString const & text,
|
|
|
|
QString const & tooltip)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-02-26 19:54:41 +00:00
|
|
|
// only Qt/Mac handles that
|
|
|
|
setMenuRole(NoRole);
|
2007-10-15 22:43:55 +00:00
|
|
|
setIcon(icon);
|
2007-09-28 23:14:33 +00:00
|
|
|
setText(text);
|
|
|
|
setToolTip(tooltip);
|
|
|
|
setStatusTip(tooltip);
|
2006-12-30 10:30:02 +00:00
|
|
|
connect(this, SIGNAL(triggered()), this, SLOT(action()));
|
2006-08-22 09:38:03 +00:00
|
|
|
update();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-17 09:14:58 +00:00
|
|
|
void Action::update()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2016-08-03 21:06:20 +00:00
|
|
|
FuncStatus const status = getStatus(*func_);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2010-04-16 10:51:20 +00:00
|
|
|
if (status.onOff(true)) {
|
2006-08-22 09:38:03 +00:00
|
|
|
setCheckable(true);
|
|
|
|
setChecked(true);
|
2010-04-16 10:51:20 +00:00
|
|
|
} else if (status.onOff(false)) {
|
2006-08-22 09:38:03 +00:00
|
|
|
setCheckable(true);
|
|
|
|
setChecked(false);
|
|
|
|
} else {
|
|
|
|
setCheckable(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
setEnabled(status.enabled());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-17 09:14:58 +00:00
|
|
|
void Action::action()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2010-02-09 16:11:13 +00:00
|
|
|
//LYXERR(Debug::ACTION, "calling lyx::dispatch: func_: ");
|
2008-03-14 16:33:16 +00:00
|
|
|
|
2016-08-03 21:06:20 +00:00
|
|
|
lyx::dispatch(*func_);
|
2007-04-19 20:29:27 +00:00
|
|
|
triggered(this);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_Action.cpp"
|