]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QtView.C
restore (14087) save/load geometry logic of qt3
[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         resize(width, height);
62
63         qApp->setMainWidget(this);
64
65         bufferview_.reset(new BufferView(this, width, height));
66
67         menubar_.reset(new QLMenubar(this, menubackend));
68         getToolbars().init();
69
70         statusBar()->setSizeGripEnabled(false);
71
72         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
73         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
74
75 #ifndef Q_WS_MACX
76         //  assign an icon to main form. We do not do it under Qt/Mac,
77         //  since the icon is provided in the application bundle.
78         string const iconname = libFileSearch("images", "lyx", "xpm");
79         if (!iconname.empty())
80                 setIcon(QPixmap(toqstr(iconname)));
81 #endif
82
83         // make sure the buttons are disabled if needed
84         updateToolbars();
85
86         // allowing the toolbars to tear off is too easily done,
87         // and we don't save their orientation anyway. Disable the handle.
88         setToolBarsMovable(false);
89 }
90
91
92 QtView::~QtView()
93 {
94 }
95
96
97 void QtView::setWindowTitle(string const & t, string const & it)
98 {
99         setCaption(toqstr(t));
100         setIconText(toqstr(it));
101 }
102
103
104 void QtView::addCommandBuffer(QWidget * parent)
105 {
106         commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
107         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
108 }
109
110
111 void QtView::message(string const & str)
112 {
113         statusBar()->message(toqstr(str));
114         statusbar_timer_.stop();
115         statusbar_timer_.start(statusbar_timer_value);
116 }
117
118
119 void QtView::clearMessage()
120 {
121         update_view_state_qt();
122 }
123
124
125 void QtView::focus_command_widget()
126 {
127         if (commandbuffer_)
128                 commandbuffer_->focus_command();
129 }
130
131
132 void QtView::update_view_state_qt()
133 {
134         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
135         statusbar_timer_.stop();
136 }
137
138
139 void QtView::update_view_state()
140 {
141         // let the user see the explicit message
142         if (statusbar_timer_.isActive())
143                 return;
144
145         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
146 }
147
148
149 void QtView::activated(FuncRequest const & func)
150 {
151         getLyXFunc().dispatch(func);
152 }
153
154
155 bool QtView::hasFocus() const
156 {
157         return qApp->activeWindow() == this;
158 }
159
160
161 void QtView::closeEvent(QCloseEvent *)
162 {
163         Session & session = LyX::ref().session();
164         session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
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