]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.C
Remove quite a few compiler warnings:
[lyx.git] / src / frontends / qt4 / GuiView.C
1 /**
2  * \file GuiView.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  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #undef QT3_SUPPORT
14
15 #include <config.h>
16
17 #include "BufferView.h"
18 #include "lyx_cb.h"
19 #include "lyxrc.h"
20 #include "lyx_main.h"
21 #include "session.h"
22 #include "lyxfunc.h"
23 #include "MenuBackend.h"
24 #include "funcrequest.h"
25 #include "funcrequest.h"
26
27 #include "debug.h"
28
29 #include "frontends/Toolbars.h"
30
31 #include "support/filetools.h"
32
33 #include "support/convert.h"
34 #include <boost/bind.hpp>
35
36 #include "GuiView.h"
37 #include "GuiImplementation.h"
38 #include "QLMenubar.h"
39 #include "FontLoader.h"
40 #include "QCommandBuffer.h"
41 #include "qt_helpers.h"
42
43 #include <QApplication>
44 #include <QPixmap>
45 #include <QStatusBar>
46 #include <QToolBar>
47 #include <QCloseEvent>
48 #include <QAction>
49 //#include <QMenu>
50 //#include <QMenuBar>
51
52 #include "support/lstrings.h"
53
54
55 using std::string;
56 using std::endl;
57
58 namespace lyx {
59
60 using support::subst;
61 using support::libFileSearch;
62
63 namespace frontend {
64
65 namespace {
66
67 int const statusbar_timer_value = 3000;
68
69 } // namespace anon
70
71
72 GuiView::GuiView(Gui & owner)
73         : QMainWindow(), LyXView(owner), commandbuffer_(0)
74 {
75         mainWidget_ = this;
76
77 //      setToolButtonStyle(Qt::ToolButtonIconOnly);
78 //      setIconSize(QSize(12,12));
79
80 //      bufferview_.reset(new BufferView(this, width, height));
81
82 #ifndef Q_WS_MACX
83         //  assign an icon to main form. We do not do it under Qt/Mac,
84         //  since the icon is provided in the application bundle.
85         string const iconname = libFileSearch("images", "lyx", "xpm");
86         if (!iconname.empty())
87                 setWindowIcon(QPixmap(toqstr(iconname)));
88 #endif
89 }
90
91
92 GuiView::~GuiView()
93 {
94 }
95
96
97 void GuiView::init()
98 {
99         menubar_.reset(new QLMenubar(this, menubackend));
100         QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
101
102         getToolbars().init();
103
104         statusBar()->setSizeGripEnabled(false);
105
106         view_state_changed.connect(boost::bind(&GuiView::update_view_state, this));
107         QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
108
109         // make sure the buttons are disabled if needed
110         updateToolbars();
111
112         LyXView::init();
113 }
114
115 void GuiView::updateMenu(QAction * /*action*/)
116 {
117         menubar_->update();
118 }
119
120
121 void GuiView::setWindowTitle(string const & t, string const & it)
122 {
123         QMainWindow::setWindowTitle(toqstr(t));
124         QMainWindow::setWindowIconText(toqstr(it));
125 }
126
127
128 void GuiView::addCommandBuffer(QToolBar * toolbar)
129 {
130         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
131         focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
132         toolbar->addWidget(commandbuffer_);
133 }
134
135
136 void GuiView::message(string const & str)
137 {
138         statusBar()->showMessage(toqstr(str));
139         statusbar_timer_.stop();
140         statusbar_timer_.start(statusbar_timer_value);
141 }
142
143
144 void GuiView::clearMessage()
145 {
146         update_view_state_qt();
147 }
148
149
150 void GuiView::focus_command_widget()
151 {
152         if (commandbuffer_)
153                 commandbuffer_->focus_command();
154 }
155
156
157 void GuiView::update_view_state_qt()
158 {
159         statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
160         statusbar_timer_.stop();
161 }
162
163
164 void GuiView::update_view_state()
165 {
166         // let the user see the explicit message
167         if (statusbar_timer_.isActive())
168                 return;
169
170         statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
171 }
172
173
174 void GuiView::activated(FuncRequest const & func)
175 {
176         getLyXFunc().dispatch(func);
177 }
178
179
180 bool GuiView::hasFocus() const
181 {
182         return qApp->activeWindow() == this;
183 }
184
185
186 void  GuiView::updateFloatingGeometry()
187 {
188         if (!isMaximized())
189                 floatingGeometry_ = QRect(x(), y(), width(), height());
190 }
191
192
193 void GuiView::resizeEvent(QResizeEvent *)
194 {
195         updateFloatingGeometry();
196 }
197
198
199 void GuiView::moveEvent(QMoveEvent *)
200 {
201         updateFloatingGeometry();
202 }
203
204
205 void GuiView::closeEvent(QCloseEvent *)
206 {
207         // FIXME:
208         // change the ifdef to 'geometry = normalGeometry();' only
209         // when Trolltech has fixed the broken normalGeometry on X11:
210         // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
211         // Then also the moveEvent, resizeEvent, and the
212         // code for floatingGeometry_ can be removed;
213         // adjust lyx_gui::start
214 #ifdef Q_OS_WIN32
215         QRect geometry = normalGeometry();
216 #else
217         updateFloatingGeometry();
218         QRect geometry = floatingGeometry_;
219 #endif
220
221         // save windows size and position
222         Session & session = LyX::ref().session();
223         session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
224         session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
225         session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
226         if (lyxrc.geometry_xysaved) {
227                 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
228                 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
229         }
230         // trigger LFUN_LYX_QUIT instead of quit directly
231         // since LFUN_LYX_QUIT may have more cleanup stuff
232         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
233 }
234
235
236 void GuiView::show()
237 {
238         QMainWindow::setWindowTitle(qt_("LyX"));
239         QMainWindow::show();
240         updateFloatingGeometry();
241 }
242
243
244 void GuiView::busy(bool yes) const
245 {
246         if (yes)
247                 QApplication::setOverrideCursor(Qt::WaitCursor);
248         else
249                 QApplication::restoreOverrideCursor();
250 }
251
252
253 QMainWindow* GuiView::mainWidget()
254 {
255         return mainWidget_;
256 }
257
258 QMainWindow* GuiView::mainWidget_ = 0;
259
260
261 } // namespace frontend
262 } // namespace lyx
263
264 #include "GuiView_moc.cpp"