]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QtView.C
Some string(widget->text()) fixes. Weirdness
[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
48 int const idle_timer_value = 3000;
49
50 } // namespace anon
51
52 // FIXME: this has to go away
53 BufferView * current_view;
54
55 qfont_loader fontloader;
56
57
58 QtView::QtView(unsigned int width, unsigned int height)
59         : QMainWindow(), LyXView()
60 {
61         resize(width, height);
62
63         qApp->setMainWidget(this);
64
65         bufferview_.reset(new BufferView(this, 0, 0, width, height));
66         ::current_view = bufferview_.get();
67
68         menubar_.reset(new Menubar(this, menubackend));
69         toolbar_.reset(new Toolbar(this, 0, 0, toolbardefaults));
70
71         statusBar()->setSizeGripEnabled(false);
72
73         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
74         connect(&idle_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
75
76         idle_timer_.start(idle_timer_value);
77
78         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
79
80         commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
81
82         addToolBar(commandbuffer_, Bottom, true);
83
84         //  assign an icon to main form
85         string const iconname = LibFileSearch("images", "lyx", "xpm");
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         idle_timer_.stop();
103         idle_timer_.start(idle_timer_value);
104 }
105
106
107 void QtView::focus_command_widget()
108 {
109         commandbuffer_->focus_command();
110 }
111
112
113 void QtView::update_view_state_qt()
114 {
115         statusBar()->message(currentState(view().get()).c_str());
116 }
117
118
119 void QtView::update_view_state()
120 {
121         statusBar()->message(currentState(view().get()).c_str());
122 }
123
124
125 void QtView::activated(int id)
126 {
127         getLyXFunc().dispatch(id, true);
128 }
129
130
131 void QtView::closeEvent(QCloseEvent *)
132 {
133         QuitLyX();
134 }
135
136
137 void QtView::show(int x, int y, string const & title)
138 {
139         move(x, y);
140         setCaption(title.c_str());
141         QMainWindow::show();
142 }
143
144
145 // it's not at all clear that these are actually
146 // needed anywhere in the source. Something to
147 // check on a rainy day.
148 void QtView::prohibitInput() const
149 {
150         //setFocusPolicy(QWidget::NoFocus);
151 }
152
153
154 void QtView::allowInput() const
155 {
156         //setFocusPolicy(QWidget::strongFocus);
157 }