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