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