]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QtView.C
843f609c1a552046d1484291a722cf5c9e5214f0
[lyx.git] / src / frontends / qt3 / 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 "lyxrc.h"
17 #include "lyx_main.h"
18 #include "session.h"
19 #include "lyxfunc.h"
20 #include "MenuBackend.h"
21 #include "funcrequest.h"
22
23 #include "frontends/Toolbars.h"
24
25 #include "support/filetools.h"
26 #include "support/convert.h"
27
28 #include <boost/bind.hpp>
29
30 #include "QtView.h"
31 #include "QLMenubar.h"
32 #include "qfont_loader.h"
33 #include "QCommandBuffer.h"
34 #include "qt_helpers.h"
35
36 #include <qapplication.h>
37 #include <qpixmap.h>
38 #include <qstatusbar.h>
39
40 using std::string;
41
42 FontLoader fontloader;
43
44 namespace lyx {
45
46 using support::libFileSearch;
47
48 namespace frontend {
49
50 namespace {
51
52 int const statusbar_timer_value = 3000;
53
54 } // namespace anon
55
56
57
58 QtView::QtView(unsigned int width, unsigned int height, bool maximize)
59         : QMainWindow(), LyXView(), commandbuffer_(0)
60 {
61         resize(width, height);
62         
63         if (maximize)
64                 this->setWindowState(WindowMaximized);
65
66         qApp->setMainWidget(this);
67
68         bufferview_.reset(new BufferView(this, width, height));
69
70         menubar_.reset(new QLMenubar(this, menubackend));
71         getToolbars().init();
72
73         statusBar()->setSizeGripEnabled(false);
74
75         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
76         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
77
78 #ifndef Q_WS_MACX
79         //  assign an icon to main form. We do not do it under Qt/Mac,
80         //  since the icon is provided in the application bundle.
81         string const iconname = libFileSearch("images", "lyx", "xpm");
82         if (!iconname.empty())
83                 setIcon(QPixmap(toqstr(iconname)));
84 #endif
85
86         // make sure the buttons are disabled if needed
87         updateToolbars();
88
89         // allowing the toolbars to tear off is too easily done,
90         // and we don't save their orientation anyway. Disable the handle.
91         setToolBarsMovable(false);
92 }
93
94
95 QtView::~QtView()
96 {
97 }
98
99
100 void QtView::setWindowTitle(string const & t, string const & it)
101 {
102         setCaption(toqstr(t));
103         setIconText(toqstr(it));
104 }
105
106
107 void QtView::addCommandBuffer(QWidget * parent)
108 {
109         commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
110         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
111 }
112
113
114 void QtView::message(string const & str)
115 {
116         statusBar()->message(toqstr(str));
117         statusbar_timer_.stop();
118         statusbar_timer_.start(statusbar_timer_value);
119 }
120
121
122 void QtView::clearMessage()
123 {
124         update_view_state_qt();
125 }
126
127
128 void QtView::focus_command_widget()
129 {
130         if (commandbuffer_)
131                 commandbuffer_->focus_command();
132 }
133
134
135 void QtView::update_view_state_qt()
136 {
137         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
138         statusbar_timer_.stop();
139 }
140
141
142 void QtView::update_view_state()
143 {
144         // let the user see the explicit message
145         if (statusbar_timer_.isActive())
146                 return;
147
148         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
149 }
150
151
152 void QtView::activated(FuncRequest const & func)
153 {
154         getLyXFunc().dispatch(func);
155 }
156
157
158 bool QtView::hasFocus() const
159 {
160         return qApp->activeWindow() == this;
161 }
162
163
164 void QtView::closeEvent(QCloseEvent *)
165 {
166         LyX::ref().session().saveSessionInfo("WindowIsMaximized", (this->isMaximized() ? "yes" : "no"));
167         // don't save maximized values
168         this->showNormal();
169         // save windows size and position
170         LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(width()));
171         LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(height()));
172         if (lyxrc.geometry_xysaved) {
173                 LyX::ref().session().saveSessionInfo("WindowPosX", convert<string>(x()));
174                 LyX::ref().session().saveSessionInfo("WindowPosY", convert<string>(y()));
175         }
176         // trigger LFUN_LYX_QUIT instead of quit directly
177         // since LFUN_LYX_QUIT may have more cleanup stuff
178         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
179 }
180
181
182 void QtView::show()
183 {
184         setCaption(qt_("LyX"));
185         QMainWindow::show();
186 }
187
188
189 void QtView::busy(bool yes) const
190 {
191         if (yes)
192                 QApplication::setOverrideCursor(Qt::waitCursor);
193         else
194                 QApplication::restoreOverrideCursor();
195 }
196
197 } // namespace frontend
198 } // namespace lyx