]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.C
QtView renamed to GuiView
[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 "QLMenubar.h"
38 #include "FontLoader.h"
39 #include "QCommandBuffer.h"
40 #include "qt_helpers.h"
41
42 #include <QApplication>
43 #include <QPixmap>
44 #include <QStatusBar>
45 #include <QToolBar>
46 #include <QCloseEvent>
47 #include <QAction>
48 //#include <QMenu>
49 //#include <QMenuBar>
50
51 #include "support/lstrings.h"
52
53
54 using std::string;
55 using std::endl;
56
57 FontLoader fontloader;
58
59 namespace lyx {
60
61 using support::subst;
62 using support::libFileSearch;
63
64 namespace frontend {
65
66 namespace {
67
68 int const statusbar_timer_value = 3000;
69
70 } // namespace anon
71
72
73 GuiView::GuiView(unsigned int width, unsigned int height)
74         : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this)
75 {
76         mainWidget_ = this;
77
78 //      setToolButtonStyle(Qt::ToolButtonIconOnly);
79 //      setIconSize(QSize(12,12));
80
81         bufferview_.reset(new BufferView(this, width, height));
82
83         menubar_.reset(new QLMenubar(this, menubackend));
84         connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
85
86         getToolbars().init();
87
88         statusBar()->setSizeGripEnabled(false);
89
90         view_state_changed.connect(boost::bind(&GuiView::update_view_state, this));
91         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
92
93 #ifndef Q_WS_MACX
94         //  assign an icon to main form. We do not do it under Qt/Mac,
95         //  since the icon is provided in the application bundle.
96         string const iconname = libFileSearch("images", "lyx", "xpm");
97         if (!iconname.empty())
98                 setWindowIcon(QPixmap(toqstr(iconname)));
99 #endif
100
101         // make sure the buttons are disabled if needed
102         updateToolbars();
103 }
104
105
106 GuiView::~GuiView()
107 {
108 }
109
110 void GuiView::updateMenu(QAction *action)
111 {
112         menubar_->update();
113 }
114
115 void GuiView::setWindowTitle(string const & t, string const & it)
116 {
117         QMainWindow::setWindowTitle(toqstr(t));
118         QMainWindow::setWindowIconText(toqstr(it));
119 }
120
121
122 void GuiView::addCommandBuffer(QToolBar * toolbar)
123 {
124         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
125         focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
126         toolbar->addWidget(commandbuffer_);
127 }
128
129
130 void GuiView::message(string const & str)
131 {
132         statusBar()->showMessage(toqstr(str));
133         statusbar_timer_.stop();
134         statusbar_timer_.start(statusbar_timer_value);
135 }
136
137
138 void GuiView::clearMessage()
139 {
140         update_view_state_qt();
141 }
142
143
144 void GuiView::focus_command_widget()
145 {
146         if (commandbuffer_)
147                 commandbuffer_->focus_command();
148 }
149
150
151 void GuiView::update_view_state_qt()
152 {
153         statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
154         statusbar_timer_.stop();
155 }
156
157
158 void GuiView::update_view_state()
159 {
160         // let the user see the explicit message
161         if (statusbar_timer_.isActive())
162                 return;
163
164         statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
165 }
166
167
168 void GuiView::activated(FuncRequest const & func)
169 {
170         getLyXFunc().dispatch(func);
171 }
172
173
174 bool GuiView::hasFocus() const
175 {
176         return qApp->activeWindow() == this;
177 }
178
179
180 void GuiView::closeEvent(QCloseEvent *)
181 {
182         QRect geometry = normalGeometry();
183         Session & session = LyX::ref().session();
184         // save windows size and position
185         session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
186         session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
187         session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
188         if (lyxrc.geometry_xysaved) {
189                 session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
190                 session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
191         }
192         // trigger LFUN_LYX_QUIT instead of quit directly
193         // since LFUN_LYX_QUIT may have more cleanup stuff
194         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
195 }
196
197
198 void GuiView::show()
199 {
200         QMainWindow::setWindowTitle(qt_("LyX"));
201         QMainWindow::show();
202 }
203
204
205 void GuiView::busy(bool yes) const
206 {
207         if (yes)
208                 QApplication::setOverrideCursor(Qt::WaitCursor);
209         else
210                 QApplication::restoreOverrideCursor();
211 }
212
213 QMainWindow* GuiView::mainWidget()
214 {
215         return mainWidget_;
216 }
217
218 QMainWindow* GuiView::mainWidget_ = 0;
219
220
221 } // namespace frontend
222 } // namespace lyx
223
224 #include "GuiView_moc.cpp"