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