]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QtView.C
remove QT3_SUPPORT macro dependency by Peter Kummel (syntheticpp@gmx.net)
[lyx.git] / src / frontends / qt4 / 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  * \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 "QtView.h"
37 #include "QLMenubar.h"
38 #include "qfont_loader.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 QtView::QtView(unsigned int width, unsigned int height)
74         : QMainWindow(), LyXView(), commandbuffer_(0)
75 {
76         resize(width, height);
77
78         mainWidget_ = this;
79
80 //      setToolButtonStyle(Qt::ToolButtonIconOnly);
81 //      setIconSize(QSize(12,12));
82
83         bufferview_.reset(new BufferView(this, width, height));
84
85         menubar_.reset(new QLMenubar(this, menubackend));
86         connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
87
88         getToolbars().init();
89
90         statusBar()->setSizeGripEnabled(false);
91
92         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
93         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
94
95 #ifndef Q_WS_MACX
96         //  assign an icon to main form. We do not do it under Qt/Mac,
97         //  since the icon is provided in the application bundle.
98         string const iconname = libFileSearch("images", "lyx", "xpm");
99         if (!iconname.empty())
100                 setWindowIcon(QPixmap(toqstr(iconname)));
101 #endif
102
103         // make sure the buttons are disabled if needed
104         updateToolbars();
105 }
106
107
108 QtView::~QtView()
109 {
110 }
111
112 void QtView::updateMenu(QAction *action)
113 {
114         menubar_->update();
115 }
116
117 void QtView::setWindowTitle(string const & t, string const & it)
118 {
119         QMainWindow::setWindowTitle(toqstr(t));
120         QMainWindow::setWindowIconText(toqstr(it));
121 }
122
123
124 void QtView::addCommandBuffer(QToolBar * toolbar)
125 {
126         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
127         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
128         toolbar->addWidget(commandbuffer_);
129 }
130
131
132 void QtView::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 QtView::clearMessage()
141 {
142         update_view_state_qt();
143 }
144
145
146 void QtView::focus_command_widget()
147 {
148         if (commandbuffer_)
149                 commandbuffer_->focus_command();
150 }
151
152
153 void QtView::update_view_state_qt()
154 {
155         statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
156         statusbar_timer_.stop();
157 }
158
159
160 void QtView::update_view_state()
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 QtView::activated(FuncRequest const & func)
171 {
172         getLyXFunc().dispatch(func);
173 }
174
175
176 bool QtView::hasFocus() const
177 {
178         return qApp->activeWindow() == this;
179 }
180
181
182 void QtView::closeEvent(QCloseEvent *)
183 {
184         // save windows size and position
185         LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(width()));
186         LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(height()));
187         if (lyxrc.geometry_xysaved) {
188                 LyX::ref().session().saveSessionInfo("WindowPosX", convert<string>(x()));
189                 LyX::ref().session().saveSessionInfo("WindowPosY", convert<string>(y()));
190         }
191         // trigger LFUN_LYX_QUIT instead of quit directly
192         // since LFUN_LYX_QUIT may have more cleanup stuff
193         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
194 }
195
196
197 void QtView::show()
198 {
199         QMainWindow::setWindowTitle(qt_("LyX"));
200         QMainWindow::show();
201 }
202
203
204 void QtView::busy(bool yes) const
205 {
206         if (yes)
207                 QApplication::setOverrideCursor(Qt::WaitCursor);
208         else
209                 QApplication::restoreOverrideCursor();
210 }
211
212 QMainWindow* QtView::mainWidget()
213 {
214         return mainWidget_;
215 }
216
217 QMainWindow* QtView::mainWidget_ = 0;
218
219
220 } // namespace frontend
221 } // namespace lyx
222
223 #include "QtView_moc.cpp"