3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 #include "BufferView.h"
18 #include "MenuBackend.h"
22 #include "frontends/Toolbars.h"
24 #include "support/filetools.h"
26 #include <boost/bind.hpp>
29 #include "QLMenubar.h"
30 #include "qfont_loader.h"
31 #include "QCommandBuffer.h"
32 #include "qt_helpers.h"
34 #include <QApplication>
38 #include <QCloseEvent>
43 #include "support/lstrings.h"
49 FontLoader fontloader;
54 using support::LibFileSearch;
60 int const statusbar_timer_value = 3000;
65 QtView::QtView(unsigned int width, unsigned int height)
66 : QMainWindow(), LyXView(), commandbuffer_(0)
68 resize(width, height);
70 qApp->setMainWidget(this);
72 // setToolButtonStyle(Qt::ToolButtonIconOnly);
73 // setIconSize(QSize(12,12));
75 bufferview_.reset(new BufferView(this, width, height));
77 menubar_.reset(new QLMenubar(this, menubackend));
78 connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
82 statusBar()->setSizeGripEnabled(false);
84 view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
85 connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
88 // assign an icon to main form. We do not do it under Qt/Mac,
89 // since the icon is provided in the application bundle.
90 string const iconname = LibFileSearch("images", "lyx", "xpm");
91 if (!iconname.empty())
92 setIcon(QPixmap(toqstr(iconname)));
95 // make sure the buttons are disabled if needed
104 void QtView::updateMenu(QAction *action)
109 void QtView::setWindowTitle(string const & t, string const & it)
111 QMainWindow::setWindowTitle(toqstr(t));
112 QMainWindow::setWindowIconText(toqstr(it));
116 void QtView::addCommandBuffer(QToolBar * toolbar)
118 commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
119 focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
120 toolbar->addWidget(commandbuffer_);
124 void QtView::message(string const & str)
126 statusBar()->message(toqstr(str));
127 statusbar_timer_.stop();
128 statusbar_timer_.start(statusbar_timer_value);
132 void QtView::clearMessage()
134 update_view_state_qt();
138 void QtView::focus_command_widget()
141 commandbuffer_->focus_command();
145 void QtView::update_view_state_qt()
147 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
148 statusbar_timer_.stop();
152 void QtView::update_view_state()
154 // let the user see the explicit message
155 if (statusbar_timer_.isActive())
158 statusBar()->message(toqstr(getLyXFunc().viewStatusMessage()));
162 void QtView::activated(FuncRequest const & func)
164 getLyXFunc().dispatch(func);
168 bool QtView::hasFocus() const
170 return qApp->activeWindow() == this;
174 void QtView::closeEvent(QCloseEvent *)
182 setCaption(qt_("LyX"));
187 void QtView::busy(bool yes) const
190 QApplication::setOverrideCursor(Qt::waitCursor);
192 QApplication::restoreOverrideCursor();
195 } // namespace frontend