]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Action.cpp
Use QFontMetrics information for underlines (and friends) width and position
[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 // 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 namespace lyx {
28 namespace frontend {
29
30
31 Action::Action(QIcon const & icon,
32           QString const & text, FuncRequest const & func,
33           QString const & tooltip, QObject * parent)
34         : QAction(parent), func_(func)
35 {
36         // only Qt/Mac handles that
37         setMenuRole(NoRole);
38         setIcon(icon);
39         setText(text);
40         setToolTip(tooltip);
41         setStatusTip(tooltip);
42         connect(this, SIGNAL(triggered()), this, SLOT(action()));
43         update();
44 }
45
46
47 void Action::update()
48 {
49         FuncStatus const status = getStatus(func_);
50
51         if (status.onOff(true)) {
52                 setCheckable(true);
53                 setChecked(true);
54         } else if (status.onOff(false)) {
55                 setCheckable(true);
56                 setChecked(false);
57         } else {
58                 setCheckable(false);
59         }
60
61         setEnabled(status.enabled());
62 }
63
64
65 void Action::action()
66 {
67         //LYXERR(Debug::ACTION, "calling lyx::dispatch: func_: ");
68
69         lyx::dispatch(func_);
70         triggered(this);
71 }
72
73 } // namespace frontend
74 } // namespace lyx
75
76 #include "moc_Action.cpp"