]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QtView.C
* Positionable and dynamically visible toolbars for the XForms frontend.
[features.git] / src / frontends / qt2 / QtView.C
1 /**
2  * \file QtView.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "BufferView.h"
15 #include "lyx_cb.h"
16 #include "lyxfunc.h"
17 #include "MenuBackend.h"
18
19 #include "frontends/Toolbars.h"
20
21 #include "support/filetools.h"
22
23 #include <boost/bind.hpp>
24
25 #include "QtView.h"
26 #include "QLMenubar.h"
27 #include "qfont_loader.h"
28 #include "QCommandBuffer.h"
29 #include "qt_helpers.h"
30
31 #include <qapplication.h>
32 #include <qpixmap.h>
33 #include <qstatusbar.h>
34
35 using lyx::support::LibFileSearch;
36
37 using std::string;
38
39
40 namespace {
41
42 int const statusbar_timer_value = 3000;
43
44 } // namespace anon
45
46 qfont_loader fontloader;
47
48
49 QtView::QtView(unsigned int width, unsigned int height)
50         : QMainWindow(), LyXView(), commandbuffer_(0)
51 {
52         resize(width, height);
53
54         qApp->setMainWidget(this);
55
56         bufferview_.reset(new BufferView(this, width, height));
57
58         menubar_.reset(new QLMenubar(this, menubackend));
59         getToolbars().init();
60
61         statusBar()->setSizeGripEnabled(false);
62
63         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
64         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
65
66         //  assign an icon to main form
67         string const iconname = LibFileSearch("images", "lyx", "xpm");
68         if (!iconname.empty())
69                 setIcon(QPixmap(toqstr(iconname)));
70
71         // make sure the buttons are disabled if needed
72         updateToolbars();
73
74         // allowing the toolbars to tear off is too easily done,
75         // and we don't save their orientation anyway. Disable the handle.
76         setToolBarsMovable(false);
77 }
78
79
80 QtView::~QtView()
81 {
82 }
83
84
85 void QtView::setWindowTitle(string const & t, string const & it)
86 {
87         setCaption(toqstr(t));
88         setIconText(toqstr(it));
89 }
90
91
92 void QtView::addCommandBuffer(QWidget * parent)
93 {
94         commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
95         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
96 }
97
98
99 void QtView::message(string const & str)
100 {
101         statusBar()->message(toqstr(str));
102         statusbar_timer_.stop();
103         statusbar_timer_.start(statusbar_timer_value);
104 }
105
106
107 void QtView::clearMessage()
108 {
109         update_view_state_qt();
110 }
111
112
113 void QtView::focus_command_widget()
114 {
115         if (commandbuffer_)
116                 commandbuffer_->focus_command();
117 }
118
119
120 void QtView::update_view_state_qt()
121 {
122         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
123         statusbar_timer_.stop();
124 }
125
126
127 void QtView::update_view_state()
128 {
129         // let the user see the explicit message
130         if (statusbar_timer_.isActive())
131                 return;
132
133         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
134 }
135
136
137 void QtView::activated(FuncRequest const & func)
138 {
139         getLyXFunc().dispatch(func, true);
140 }
141
142
143 void QtView::closeEvent(QCloseEvent *)
144 {
145         QuitLyX();
146 }
147
148
149 void QtView::show()
150 {
151         setCaption(qt_("LyX"));
152         QMainWindow::show();
153 }
154
155
156 void QtView::busy(bool yes) const
157 {
158         if (yes)
159                 QApplication::setOverrideCursor(Qt::waitCursor);
160         else
161                 QApplication::restoreOverrideCursor();
162 }