]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/Action.cpp
Rename frontend qt4 to qt
[lyx.git] / src / frontends / qt / 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 // DispatchResult.h is needed by the windows compiler because lyx::dispatch
16 // returns a DispatchResult const reference. Gcc does not complain. Weird...
17 #include "DispatchResult.h"
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
20 #include "LyX.h"
21
22 #include "qt_helpers.h"
23
24 #include "support/debug.h"
25 #include "support/lstrings.h"
26
27 using namespace std;
28
29
30 namespace lyx {
31 namespace frontend {
32
33
34 Action::Action(FuncRequest func, QIcon const & icon, QString const & text,
35                QString const & tooltip, QObject * parent)
36         : QAction(parent), func_(make_shared<FuncRequest>(move(func)))
37 {
38         init(icon, text, tooltip);
39 }
40
41
42 Action::Action(shared_ptr<FuncRequest const> func,
43                QIcon const & icon, QString const & text,
44                QString const & tooltip, QObject * parent)
45         : QAction(parent), func_(func)
46 {
47         init(icon, text, tooltip);
48 }
49
50
51 void Action::init(QIcon const & icon, QString const & text,
52                   QString const & tooltip)
53 {
54         // only Qt/Mac handles that
55         setMenuRole(NoRole);
56         setIcon(icon);
57         setText(text);
58         setToolTip(tooltip);
59         setStatusTip(tooltip);
60         connect(this, SIGNAL(triggered()), this, SLOT(action()));
61         update();
62 }
63
64
65 void Action::update()
66 {
67         FuncStatus const status = getStatus(*func_);
68
69         if (status.onOff(true)) {
70                 setCheckable(true);
71                 setChecked(true);
72         } else if (status.onOff(false)) {
73                 setCheckable(true);
74                 setChecked(false);
75         } else {
76                 setCheckable(false);
77         }
78
79         setEnabled(status.enabled());
80 }
81
82
83 void Action::action()
84 {
85         //LYXERR(Debug::ACTION, "calling lyx::dispatch: func_: ");
86
87         lyx::dispatch(*func_);
88         triggered(this);
89 }
90
91 } // namespace frontend
92 } // namespace lyx
93
94 #include "moc_Action.cpp"