]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QtView.C
reverse last change
[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 Bjornes
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "debug.h"
19 #include "intl.h"
20 #include "lyx_cb.h"
21 #include "support/filetools.h"
22 #include "MenuBackend.h"
23 #include "ToolbarDefaults.h"
24 #include "lyxfunc.h"
25 #include "bufferview_funcs.h"
26 #include "BufferView.h"
27
28 #include "frontends/Toolbar.h"
29 #include "frontends/Menubar.h"
30 #include "frontends/Dialogs.h"
31 #include "frontends/Timeout.h"
32
33 #include <boost/bind.hpp>
34
35 #include "QtView.h"
36 #include "qfont_loader.h"
37 #include "QCommandBuffer.h"
38 #include "qt_helpers.h"
39
40 #include <qapplication.h>
41 #include <qpixmap.h>
42 #include <qmenubar.h>
43 #include <qstatusbar.h>
44
45 using std::endl;
46
47 namespace {
48
49 int const idle_timer_value = 3000;
50
51 } // namespace anon
52
53 // FIXME: this has to go away
54 BufferView * current_view;
55
56 qfont_loader fontloader;
57
58
59 QtView::QtView(unsigned int width, unsigned int height)
60         : QMainWindow(), LyXView()
61 {
62         resize(width, height);
63
64         qApp->setMainWidget(this);
65
66         bufferview_.reset(new BufferView(this, 0, 0, width, height));
67         ::current_view = bufferview_.get();
68
69         menubar_.reset(new Menubar(this, menubackend));
70         toolbar_.reset(new Toolbar(this, 0, 0, toolbardefaults));
71
72         statusBar()->setSizeGripEnabled(false);
73
74         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
75         connect(&idle_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
76
77         idle_timer_.start(idle_timer_value);
78
79         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
80
81         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
82
83         addToolBar(commandbuffer_, Bottom, true);
84
85         //  assign an icon to main form
86         string const iconname = LibFileSearch("images", "lyx", "xpm");
87         if (!iconname.empty())
88                 setIcon(QPixmap(toqstr(iconname)));
89
90         // make sure the buttons are disabled if needed
91         updateToolbar();
92 }
93
94
95 QtView::~QtView()
96 {
97 }
98
99
100 void QtView::setWindowTitle(string const & t, string const & it)
101 {
102         setCaption(toqstr(t));
103         setIconText(toqstr(it));
104 }
105
106
107 void QtView::message(string const & str)
108 {
109         statusBar()->message(toqstr(str));
110         idle_timer_.stop();
111         idle_timer_.start(idle_timer_value);
112 }
113
114
115 void QtView::focus_command_widget()
116 {
117         commandbuffer_->focus_command();
118 }
119
120
121 void QtView::update_view_state_qt()
122 {
123         statusBar()->message(toqstr(currentState(view().get())));
124 }
125
126
127 void QtView::update_view_state()
128 {
129         statusBar()->message(toqstr(currentState(view().get())));
130 }
131
132
133 void QtView::activated(int id)
134 {
135         getLyXFunc().dispatch(id, true);
136 }
137
138
139 void QtView::closeEvent(QCloseEvent *)
140 {
141         QuitLyX();
142 }
143
144
145 void QtView::show()
146 {
147         setCaption(qt_("LyX"));
148         QMainWindow::show();
149 }
150
151
152 // it's not at all clear that these are actually
153 // needed anywhere in the source. Something to
154 // check on a rainy day.
155 void QtView::prohibitInput() const
156 {
157         //setFocusPolicy(QWidget::NoFocus);
158 }
159
160
161 void QtView::allowInput() const
162 {
163         //setFocusPolicy(QWidget::strongFocus);
164 }