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