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