]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Action.cpp
f7f12256d167e7ab6fa9c31e51e18178965e0456
[lyx.git] / src / frontends / qt4 / Action.cpp
1 /**
2  * \file Action.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Abdelrazak Younes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Action.h"
14
15 #include "debug.h"
16 #include "FuncRequest.h"
17 #include "FuncStatus.h"
18 #include "GuiView.h"
19 #include "LyXFunc.h"
20 #include "qt_helpers.h"
21
22 #include "support/lstrings.h"
23
24 namespace lyx {
25 namespace frontend {
26
27
28 Action::Action(GuiView & lyxView, QIcon const & icon,
29           QString const & text, FuncRequest const & func,
30           QString const & tooltip)
31         : QAction(&lyxView), func_(func), lyxView_(lyxView)
32 {
33 #if QT_VERSION >= 0x040200
34         // only Qt/Mac handles that
35         setMenuRole(NoRole);
36 #endif
37         setIcon(icon);
38         setText(text);
39         setToolTip(tooltip);
40         setStatusTip(tooltip);
41         connect(this, SIGNAL(triggered()), this, SLOT(action()));
42         update();
43 }
44
45
46 void Action::update()
47 {
48         FuncStatus const status = getStatus(func_);
49
50         if (status.onoff(true)) {
51                 setCheckable(true);
52                 setChecked(true);
53         } else if (status.onoff(false)) {
54                 setCheckable(true);
55                 setChecked(false);
56         } else {
57                 setCheckable(false);
58         }
59
60         setEnabled(status.enabled());
61 }
62
63
64 void Action::action()
65 {
66         //      LYXERR(Debug::ACTION) << "calling LyXFunc::dispatch: func_: "
67         //      "\n";
68         lyxView_.dispatch(func_);
69         triggered(this);
70 }
71
72 } // namespace frontend
73 } // namespace lyx
74
75 #include "Action_moc.cpp"