2002-06-19 03:38:44 +00:00
|
|
|
/**
|
|
|
|
* \file QtView.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-19 03:38:44 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author Lars Gullik Bjornes
|
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-06-19 03:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include "intl.h"
|
|
|
|
#include "lyx_cb.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "MenuBackend.h"
|
2003-04-02 18:08:05 +00:00
|
|
|
#include "ToolbarBackend.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "lyxfunc.h"
|
2002-07-17 04:13:41 +00:00
|
|
|
#include "bufferview_funcs.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
|
|
|
|
#include "frontends/Toolbar.h"
|
|
|
|
#include "frontends/Menubar.h"
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
#include "frontends/Timeout.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
#include <boost/bind.hpp>
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QtView.h"
|
|
|
|
#include "qfont_loader.h"
|
2002-07-19 23:04:55 +00:00
|
|
|
#include "QCommandBuffer.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include <qapplication.h>
|
2003-02-14 14:49:51 +00:00
|
|
|
#include <qcursor.h>
|
2002-06-19 03:38:44 +00:00
|
|
|
#include <qpixmap.h>
|
|
|
|
#include <qmenubar.h>
|
2002-07-13 01:42:15 +00:00
|
|
|
#include <qstatusbar.h>
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
using std::endl;
|
2003-04-03 00:36:31 +00:00
|
|
|
using namespace bv_funcs;
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2002-07-22 18:22:35 +00:00
|
|
|
namespace {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
int const idle_timer_value = 3000;
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
// FIXME: this has to go away
|
|
|
|
BufferView * current_view;
|
|
|
|
|
|
|
|
qfont_loader fontloader;
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
QtView::QtView(unsigned int width, unsigned int height)
|
|
|
|
: QMainWindow(), LyXView()
|
|
|
|
{
|
|
|
|
resize(width, height);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
qApp->setMainWidget(this);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-22 01:53:26 +00:00
|
|
|
bufferview_.reset(new BufferView(this, 0, 0, width, height));
|
|
|
|
::current_view = bufferview_.get();
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
menubar_.reset(new Menubar(this, menubackend));
|
2003-04-02 18:08:05 +00:00
|
|
|
toolbar_.reset(new Toolbar(this, 0, 0, toolbarbackend));
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2002-07-13 01:42:15 +00:00
|
|
|
statusBar()->setSizeGripEnabled(false);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
|
2002-07-19 23:04:55 +00:00
|
|
|
connect(&idle_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
idle_timer_.start(idle_timer_value);
|
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
focus_command_buffer.connect(boost::bind(&QtView::focus_command_widget, this));
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
addToolBar(commandbuffer_, Bottom, true);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
// assign an icon to main form
|
2002-06-19 03:38:44 +00:00
|
|
|
string const iconname = LibFileSearch("images", "lyx", "xpm");
|
|
|
|
if (!iconname.empty())
|
2002-12-17 20:37:13 +00:00
|
|
|
setIcon(QPixmap(toqstr(iconname)));
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
// make sure the buttons are disabled if needed
|
|
|
|
updateToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QtView::~QtView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
void QtView::setWindowTitle(string const & t, string const & it)
|
|
|
|
{
|
|
|
|
setCaption(toqstr(t));
|
|
|
|
setIconText(toqstr(it));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
void QtView::message(string const & str)
|
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
statusBar()->message(toqstr(str));
|
2002-07-21 01:38:24 +00:00
|
|
|
idle_timer_.stop();
|
2002-07-22 18:22:35 +00:00
|
|
|
idle_timer_.start(idle_timer_value);
|
2002-07-19 23:04:55 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
void QtView::focus_command_widget()
|
|
|
|
{
|
|
|
|
commandbuffer_->focus_command();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QtView::update_view_state_qt()
|
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
statusBar()->message(toqstr(currentState(view().get())));
|
2002-07-19 23:04:55 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
void QtView::update_view_state()
|
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
statusBar()->message(toqstr(currentState(view().get())));
|
2002-07-17 04:13:41 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QtView::activated(int id)
|
|
|
|
{
|
2002-08-13 14:40:38 +00:00
|
|
|
getLyXFunc().dispatch(id, true);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QtView::closeEvent(QCloseEvent *)
|
|
|
|
{
|
|
|
|
QuitLyX();
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-01-05 22:38:42 +00:00
|
|
|
void QtView::show()
|
2002-06-19 03:38:44 +00:00
|
|
|
{
|
2003-01-05 22:38:42 +00:00
|
|
|
setCaption(qt_("LyX"));
|
2002-06-19 03:38:44 +00:00
|
|
|
QMainWindow::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
void QtView::busy(bool yes) const
|
2002-06-19 03:38:44 +00:00
|
|
|
{
|
2003-02-14 14:49:51 +00:00
|
|
|
if (yes)
|
|
|
|
QApplication::setOverrideCursor(Qt::waitCursor);
|
|
|
|
else
|
|
|
|
QApplication::restoreOverrideCursor();
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|