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