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