]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QtView.C
the current_view patch
[features.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 Bjønnes
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 "ToolbarBackend.h"
21 #include "lyxfunc.h"
22 #include "BufferView.h"
23
24 #include "frontends/Toolbar.h"
25 #include "frontends/Menubar.h"
26 #include "frontends/Dialogs.h"
27 #include "frontends/Timeout.h"
28
29 #include <boost/bind.hpp>
30
31 #include "QtView.h"
32 #include "qfont_loader.h"
33 #include "QCommandBuffer.h"
34 #include "qt_helpers.h"
35
36 #include <qapplication.h>
37 #include <qcursor.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 statusbar_timer_value = 3000;
47
48 } // namespace anon
49
50 #warning FIXME Current_view is used here!
51 BufferView * current_view;
52
53 qfont_loader fontloader;
54
55
56 QtView::QtView(unsigned int width, unsigned int height)
57         : QMainWindow(), LyXView(), commandbuffer_(0)
58 {
59         resize(width, height);
60
61         qApp->setMainWidget(this);
62
63         bufferview_.reset(new BufferView(this, 0, 0, width, height));
64 #warning FIXME Current_view is used here!
65         ::current_view = bufferview_.get();
66
67         menubar_.reset(new Menubar(this, menubackend));
68         toolbar_.reset(new Toolbar(this, 0, 0));
69
70         statusBar()->setSizeGripEnabled(false);
71
72         view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
73         connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
74
75         //  assign an icon to main form
76         string const iconname = LibFileSearch("images", "lyx", "xpm");
77         if (!iconname.empty())
78                 setIcon(QPixmap(toqstr(iconname)));
79
80         // make sure the buttons are disabled if needed
81         updateToolbar();
82
83         // allowing the toolbars to tear off is too easily done,
84         // and we don't save their orientation anyway. Disable the handle.
85         setToolBarsMovable(false);
86 }
87
88
89 QtView::~QtView()
90 {
91 }
92
93
94 void QtView::setWindowTitle(string const & t, string const & it)
95 {
96         setCaption(toqstr(t));
97         setIconText(toqstr(it));
98 }
99
100
101 void QtView::addCommandBuffer(QWidget * parent)
102 {
103         commandbuffer_ = new QCommandBuffer(this, parent, *controlcommand_);
104         focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
105 }
106
107
108 void QtView::message(string const & str)
109 {
110         statusBar()->message(toqstr(str));
111         statusbar_timer_.stop();
112         statusbar_timer_.start(statusbar_timer_value);
113 }
114
115
116 void QtView::clearMessage()
117 {
118         update_view_state_qt();
119 }
120
121
122 void QtView::focus_command_widget()
123 {
124         if (commandbuffer_)
125                 commandbuffer_->focus_command();
126 }
127
128
129 void QtView::update_view_state_qt()
130 {
131         statusBar()->message(toqstr(getLyXFunc().view_status_message()));
132         statusbar_timer_.stop();
133 }
134
135
136 void QtView::update_view_state()
137 {
138         // let the user see the explicit message
139         if (statusbar_timer_.isActive())
140                 return;
141
142         statusBar()->message(toqstr(getLyXFunc().view_status_message()));
143 }
144
145
146 void QtView::activated(int id)
147 {
148         getLyXFunc().dispatch(id, true);
149 }
150
151
152 void QtView::closeEvent(QCloseEvent *)
153 {
154         QuitLyX();
155 }
156
157
158 void QtView::show()
159 {
160         setCaption(qt_("LyX"));
161         QMainWindow::show();
162 }
163
164
165 void QtView::busy(bool yes) const
166 {
167         if (yes)
168                 QApplication::setOverrideCursor(Qt::waitCursor);
169         else
170                 QApplication::restoreOverrideCursor();
171 }