]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QtView.C
This new citation dialog follows a new design similar to lyx-1.3:
[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 #include <config.h>
14
15 #include "BufferView.h"
16 #include "lyx_cb.h"
17 #include "lyxfunc.h"
18 #include "MenuBackend.h"
19
20 #include "debug.h"
21
22 #include "frontends/Toolbars.h"
23
24 #include "support/filetools.h"
25
26 #include <boost/bind.hpp>
27
28 #include "QtView.h"
29 #include "QLMenubar.h"
30 #include "qfont_loader.h"
31 #include "QCommandBuffer.h"
32 #include "qt_helpers.h"
33
34 #include <QApplication>
35 #include <QPixmap>
36 #include <QStatusBar>
37 #include <QToolBar>
38 #include <QCloseEvent>
39 #include <QAction>
40 #include <QMenu>
41 #include <QMenuBar>
42
43 #include "support/lstrings.h"
44
45
46 using std::string;
47 using std::endl;
48
49 FontLoader fontloader;
50
51 namespace lyx {
52
53 using support::subst;
54 using support::LibFileSearch;
55
56 namespace frontend {
57
58 namespace {
59
60 int const statusbar_timer_value = 3000;
61
62 } // namespace anon
63
64
65 QtView::QtView(unsigned int width, unsigned int height)
66         : QMainWindow(), LyXView(), commandbuffer_(0)
67 {
68         resize(width, height);
69
70         qApp->setMainWidget(this);
71
72 //      setToolButtonStyle(Qt::ToolButtonIconOnly);
73 //      setIconSize(QSize(12,12));
74
75         bufferview_.reset(new BufferView(this, width, height));
76
77         menubar_.reset(new QLMenubar(this, menubackend));
78         connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
79
80         getToolbars().init();
81
82         statusBar()->setSizeGripEnabled(false);
83
84         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
85         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
86
87 #ifndef Q_WS_MACX
88         //  assign an icon to main form. We do not do it under Qt/Mac,
89         //  since the icon is provided in the application bundle.
90         string const iconname = LibFileSearch("images", "lyx", "xpm");
91         if (!iconname.empty())
92                 setIcon(QPixmap(toqstr(iconname)));
93 #endif
94
95         // make sure the buttons are disabled if needed
96         updateToolbars();
97 }
98
99
100 QtView::~QtView()
101 {
102 }
103
104 void QtView::updateMenu(QAction *action)
105 {
106         menubar_->update();
107 }
108
109 void QtView::setWindowTitle(string const & t, string const & it)
110 {
111         QMainWindow::setWindowTitle(toqstr(t));
112         QMainWindow::setWindowIconText(toqstr(it));
113 }
114
115
116 void QtView::addCommandBuffer(QToolBar * toolbar)
117 {
118         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
119         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
120         toolbar->addWidget(commandbuffer_);
121 }
122
123
124 void QtView::message(string const & str)
125 {
126         statusBar()->message(toqstr(str));
127         statusbar_timer_.stop();
128         statusbar_timer_.start(statusbar_timer_value);
129 }
130
131
132 void QtView::clearMessage()
133 {
134         update_view_state_qt();
135 }
136
137
138 void QtView::focus_command_widget()
139 {
140         if (commandbuffer_)
141                 commandbuffer_->focus_command();
142 }
143
144
145 void QtView::update_view_state_qt()
146 {
147         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
148         statusbar_timer_.stop();
149 }
150
151
152 void QtView::update_view_state()
153 {
154         // let the user see the explicit message
155         if (statusbar_timer_.isActive())
156                 return;
157
158         statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
159 }
160
161
162 void QtView::activated(FuncRequest const & func)
163 {
164         getLyXFunc().dispatch(func);
165 }
166
167
168 bool QtView::hasFocus() const
169 {
170         return qApp->activeWindow() == this;
171 }
172
173
174 void QtView::closeEvent(QCloseEvent *)
175 {
176         QuitLyX(false);
177 }
178
179
180 void QtView::show()
181 {
182         setCaption(qt_("LyX"));
183         QMainWindow::show();
184 }
185
186
187 void QtView::busy(bool yes) const
188 {
189         if (yes)
190                 QApplication::setOverrideCursor(Qt::waitCursor);
191         else
192                 QApplication::restoreOverrideCursor();
193 }
194
195 } // namespace frontend
196 } // namespace lyx