]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QtView.C
Joao latest bits
[lyx.git] / src / frontends / qt2 / 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  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "lyx_cb.h"
15 #include "support/filetools.h"
16 #include "MenuBackend.h"
17 #include "lyxfunc.h"
18 #include "BufferView.h"
19
20 #include <boost/bind.hpp>
21
22 #include "QtView.h"
23 #include "QLToolbar.h"
24 #include "QLMenubar.h"
25 #include "qfont_loader.h"
26 #include "QCommandBuffer.h"
27
28 #include <qapplication.h>
29 #include <qstatusbar.h>
30
31 using lyx::support::LibFileSearch;
32
33 using std::string;
34
35
36 namespace {
37
38 int const statusbar_timer_value = 3000;
39
40 } // namespace anon
41
42 qfont_loader fontloader;
43
44
45 QtView::QtView(unsigned int width, unsigned int height)
46         : QMainWindow(), LyXView(), commandbuffer_(0)
47 {
48         resize(width, height);
49
50         qApp->setMainWidget(this);
51
52         bufferview_.reset(new BufferView(this, 0, 0, width, height));
53
54         menubar_.reset(new QLMenubar(this, menubackend));
55         toolbar_.reset(new QLToolbar(this));
56         toolbar_->init();
57
58         statusBar()->setSizeGripEnabled(false);
59
60         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
61         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
62
63         //  assign an icon to main form
64         string const iconname = LibFileSearch("images", "lyx", "xpm");
65         if (!iconname.empty())
66                 setIcon(QPixmap(toqstr(iconname)));
67
68         // make sure the buttons are disabled if needed
69         updateToolbar();
70
71         // allowing the toolbars to tear off is too easily done,
72         // and we don't save their orientation anyway. Disable the handle.
73         setToolBarsMovable(false);
74 }
75
76
77 QtView::~QtView()
78 {
79 }
80
81
82 void QtView::setWindowTitle(string const & t, string const & it)
83 {
84         setCaption(toqstr(t));
85         setIconText(toqstr(it));
86 }
87
88
89 void QtView::addCommandBuffer(QWidget * parent)
90 {
91         commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
92         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
93 }
94
95
96 void QtView::message(string const & str)
97 {
98         statusBar()->message(toqstr(str));
99         statusbar_timer_.stop();
100         statusbar_timer_.start(statusbar_timer_value);
101 }
102
103
104 void QtView::clearMessage()
105 {
106         update_view_state_qt();
107 }
108
109
110 void QtView::focus_command_widget()
111 {
112         if (commandbuffer_)
113                 commandbuffer_->focus_command();
114 }
115
116
117 void QtView::update_view_state_qt()
118 {
119         statusBar()->message(toqstr(getLyXFunc().view_status_message()));
120         statusbar_timer_.stop();
121 }
122
123
124 void QtView::update_view_state()
125 {
126         // let the user see the explicit message
127         if (statusbar_timer_.isActive())
128                 return;
129
130         statusBar()->message(toqstr(getLyXFunc().view_status_message()));
131 }
132
133
134 void QtView::activated(FuncRequest const & func)
135 {
136         getLyXFunc().dispatch(func, true);
137 }
138
139
140 void QtView::closeEvent(QCloseEvent *)
141 {
142         QuitLyX();
143 }
144
145
146 void QtView::show()
147 {
148         setCaption(qt_("LyX"));
149         QMainWindow::show();
150 }
151
152
153 void QtView::busy(bool yes) const
154 {
155         if (yes)
156                 QApplication::setOverrideCursor(Qt::waitCursor);
157         else
158                 QApplication::restoreOverrideCursor();
159 }