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