]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Action.cpp
shuffle some code around
[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 "frontends/LyXView.h"
16
17 #include "debug.h"
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
20 #include "GuiView.h"
21 #include "LyXFunc.h"
22 #include "qt_helpers.h"
23
24 #include "support/lstrings.h"
25
26 namespace lyx {
27 namespace frontend {
28
29
30 Action::Action(GuiViewBase & lyxView, QString const & icon,
31           QString const & text, FuncRequest const & func,
32           QString const & tooltip)
33         : QAction(&lyxView), func_(func), lyxView_(lyxView)
34 {
35 #if QT_VERSION >= 0x040200
36         // only Qt/Mac handles that
37         setMenuRole(NoRole);
38 #endif
39         setIcon(QPixmap(icon));
40         setText(text);
41         setToolTip(tooltip);
42         setStatusTip(tooltip);
43         connect(this, SIGNAL(triggered()), this, SLOT(action()));
44         update();
45 }
46
47
48 void Action::update()
49 {
50         FuncStatus const status = getStatus(func_);
51
52         if (status.onoff(true)) {
53                 setCheckable(true);
54                 setChecked(true);
55         } else if (status.onoff(false)) {
56                 setCheckable(true);
57                 setChecked(false);
58         } else {
59                 setCheckable(false);
60         }
61
62         setEnabled(status.enabled());
63 }
64
65
66 void Action::action()
67 {
68         //      LYXERR(Debug::ACTION) << "calling LyXFunc::dispatch: func_: "
69         //      "\n";
70         lyxView_.dispatch(func_);
71         triggered(this);
72 }
73
74 } // namespace frontend
75 } // namespace lyx
76
77 #include "Action_moc.cpp"