]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Action.cpp
2cbe3d8e58c857b39fbad22a01abb818fab986c0
[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 "GuiView.h"
16 #include "qt_helpers.h"
17
18 #include "callback.h"
19 #include "LyXFunc.h"
20 #include "FuncStatus.h"
21 #include "debug.h"
22
23 #include "support/lstrings.h"
24
25 #include <boost/bind.hpp>
26
27 using std::string;
28 using std::endl;
29
30 namespace lyx {
31 namespace frontend {
32
33
34 Action::Action(GuiView & lyxView, docstring const & text,
35                 FuncRequest const & func, docstring const & tooltip)
36         : QAction(&lyxView), func_(func), lyxView_(lyxView)
37 {
38 #if QT_VERSION >= 0x040200
39         // only Qt/Mac handles that
40         setMenuRole(NoRole);
41 #endif
42         setText(toqstr(text));
43         setToolTip(toqstr(tooltip));
44         setStatusTip(toqstr(tooltip));
45         connect(this, SIGNAL(triggered()), this, SLOT(action()));
46         update();
47 }
48
49 Action::Action(GuiView & lyxView, string const & icon, docstring const & text,
50                 FuncRequest const & func, docstring const & tooltip)
51                 : QAction(&lyxView), func_(func), lyxView_(lyxView)
52 {
53         setIcon(QPixmap(icon.c_str()));
54         setText(toqstr(text));
55         setToolTip(toqstr(tooltip));
56         setStatusTip(toqstr(tooltip));
57         connect(this, SIGNAL(triggered()), this, SLOT(action()));
58         update();
59 }
60
61 /*
62 void Action::setAction(FuncRequest const & func)
63 {
64         func_=func;
65 }
66 */
67
68 void Action::update()
69 {
70         FuncStatus const status = getStatus(func_);
71
72         if (status.onoff(true)) {
73                 setCheckable(true);
74                 setChecked(true);
75         } else if (status.onoff(false)) {
76                 setCheckable(true);
77                 setChecked(false);
78         } else {
79                 setCheckable(false);
80         }
81
82         setEnabled(status.enabled());
83 }
84
85
86 void Action::action()
87 {
88 //      LYXERR(Debug::ACTION) << "calling LyXFunc::dispatch: func_: " << func_ << endl;
89
90         lyxView_.dispatch(func_);
91         triggered(this);
92 }
93
94 } // namespace frontend
95 } // namespace lyx
96
97 #include "Action_moc.cpp"