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