2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
2006-06-20 09:33:01 +00:00
|
|
|
|
* \file GuiView.C
|
2006-03-05 17:24:44 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2006-06-20 08:39:16 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2006-03-05 17:24:44 +00:00
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "lyx_cb.h"
|
2006-04-07 12:01:11 +00:00
|
|
|
|
#include "lyxrc.h"
|
2006-04-05 22:56:18 +00:00
|
|
|
|
#include "lyx_main.h"
|
|
|
|
|
#include "session.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
#include "MenuBackend.h"
|
2006-04-05 22:56:18 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "funcrequest.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
#include "frontends/WorkArea.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "support/filetools.h"
|
2006-04-05 22:56:18 +00:00
|
|
|
|
#include "support/convert.h"
|
2006-07-13 16:37:55 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
// This include must be declared before everything else because
|
|
|
|
|
// of boost/Qt/LyX clash...
|
2006-06-26 16:55:35 +00:00
|
|
|
|
#include "GuiImplementation.h"
|
2006-07-13 16:37:55 +00:00
|
|
|
|
|
|
|
|
|
#include "GuiView.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QLMenubar.h"
|
2006-09-10 11:03:21 +00:00
|
|
|
|
#include "QLToolbar.h"
|
2006-06-17 09:14:58 +00:00
|
|
|
|
#include "FontLoader.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QCommandBuffer.h"
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::subst;
|
2006-04-09 08:42:58 +00:00
|
|
|
|
using support::libFileSearch;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
int const statusbar_timer_value = 3000;
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2006-09-22 15:02:41 +00:00
|
|
|
|
GuiView::GuiView()
|
|
|
|
|
: QMainWindow(), LyXView(), commandbuffer_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
// setToolButtonStyle(Qt::ToolButtonIconOnly);
|
|
|
|
|
// setIconSize(QSize(12,12));
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
// bufferview_.reset(new BufferView(this, width, height));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#ifndef Q_WS_MACX
|
|
|
|
|
// assign an icon to main form. We do not do it under Qt/Mac,
|
|
|
|
|
// since the icon is provided in the application bundle.
|
2006-04-09 08:42:58 +00:00
|
|
|
|
string const iconname = libFileSearch("images", "lyx", "xpm");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
if (!iconname.empty())
|
2006-06-04 20:49:09 +00:00
|
|
|
|
setWindowIcon(QPixmap(toqstr(iconname)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
GuiView::~GuiView()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
|
|
void GuiView::init()
|
|
|
|
|
{
|
|
|
|
|
menubar_.reset(new QLMenubar(this, menubackend));
|
|
|
|
|
QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
|
|
|
|
|
|
|
|
|
|
getToolbars().init();
|
|
|
|
|
|
|
|
|
|
statusBar()->setSizeGripEnabled(false);
|
|
|
|
|
|
|
|
|
|
QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
|
|
|
|
|
|
|
|
|
|
// make sure the buttons are disabled if needed
|
|
|
|
|
updateToolbars();
|
2006-07-06 08:18:51 +00:00
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
LyXView::init();
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
|
void GuiView::updateMenu(QAction * /*action*/)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
menubar_->update();
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
|
void GuiView::setWindowTitle(docstring const & t, docstring const & it)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
QMainWindow::setWindowTitle(toqstr(t));
|
|
|
|
|
QMainWindow::setWindowIconText(toqstr(it));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::addCommandBuffer(QToolBar * toolbar)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
|
2006-06-20 09:33:01 +00:00
|
|
|
|
focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
toolbar->addWidget(commandbuffer_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
|
void GuiView::message(docstring const & str)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-06-04 20:49:09 +00:00
|
|
|
|
statusBar()->showMessage(toqstr(str));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
statusbar_timer_.stop();
|
|
|
|
|
statusbar_timer_.start(statusbar_timer_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::clearMessage()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
update_view_state_qt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::focus_command_widget()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (commandbuffer_)
|
|
|
|
|
commandbuffer_->focus_command();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::update_view_state_qt()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-06-04 20:49:09 +00:00
|
|
|
|
statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
statusbar_timer_.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
void GuiView::updateStatusBar()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
// let the user see the explicit message
|
|
|
|
|
if (statusbar_timer_.isActive())
|
|
|
|
|
return;
|
|
|
|
|
|
2006-06-04 20:49:09 +00:00
|
|
|
|
statusBar()->showMessage(toqstr(getLyXFunc().viewStatusMessage()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::activated(FuncRequest const & func)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
getLyXFunc().dispatch(func);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
bool GuiView::hasFocus() const
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
return qApp->activeWindow() == this;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
|
void GuiView::updateFloatingGeometry()
|
2006-06-21 10:30:32 +00:00
|
|
|
|
{
|
2006-06-23 10:19:31 +00:00
|
|
|
|
if (!isMaximized())
|
|
|
|
|
floatingGeometry_ = QRect(x(), y(), width(), height());
|
2006-06-21 10:30:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2006-06-21 10:30:32 +00:00
|
|
|
|
void GuiView::resizeEvent(QResizeEvent *)
|
|
|
|
|
{
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2006-06-21 10:30:32 +00:00
|
|
|
|
void GuiView::moveEvent(QMoveEvent *)
|
|
|
|
|
{
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::closeEvent(QCloseEvent *)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-07-06 08:18:51 +00:00
|
|
|
|
// FIXME:
|
2006-06-21 10:30:32 +00:00
|
|
|
|
// change the ifdef to 'geometry = normalGeometry();' only
|
2006-06-27 07:53:44 +00:00
|
|
|
|
// when Trolltech has fixed the broken normalGeometry on X11:
|
|
|
|
|
// http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
|
2006-06-21 10:30:32 +00:00
|
|
|
|
// Then also the moveEvent, resizeEvent, and the
|
|
|
|
|
// code for floatingGeometry_ can be removed;
|
|
|
|
|
// adjust lyx_gui::start
|
|
|
|
|
#ifdef Q_OS_WIN32
|
2006-06-14 14:32:39 +00:00
|
|
|
|
QRect geometry = normalGeometry();
|
2006-06-21 10:30:32 +00:00
|
|
|
|
#else
|
|
|
|
|
updateFloatingGeometry();
|
2006-07-06 08:18:51 +00:00
|
|
|
|
QRect geometry = floatingGeometry_;
|
2006-06-21 10:30:32 +00:00
|
|
|
|
#endif
|
2006-07-06 08:18:51 +00:00
|
|
|
|
|
2006-04-05 22:56:18 +00:00
|
|
|
|
// save windows size and position
|
2006-06-21 10:30:32 +00:00
|
|
|
|
Session & session = LyX::ref().session();
|
2006-06-14 14:32:39 +00:00
|
|
|
|
session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
|
|
|
|
|
session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
|
|
|
|
|
session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
|
2006-04-05 22:56:18 +00:00
|
|
|
|
if (lyxrc.geometry_xysaved) {
|
2006-06-14 14:32:39 +00:00
|
|
|
|
session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
|
|
|
|
|
session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
|
2006-04-05 22:56:18 +00:00
|
|
|
|
}
|
2006-05-05 20:23:12 +00:00
|
|
|
|
// trigger LFUN_LYX_QUIT instead of quit directly
|
|
|
|
|
// since LFUN_LYX_QUIT may have more cleanup stuff
|
|
|
|
|
getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::show()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-06-04 20:49:09 +00:00
|
|
|
|
QMainWindow::setWindowTitle(qt_("LyX"));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
QMainWindow::show();
|
2006-06-21 10:30:32 +00:00
|
|
|
|
updateFloatingGeometry();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::busy(bool yes) const
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (yes)
|
2006-06-04 20:49:09 +00:00
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
else
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
|
|
|
|
|
Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
|
|
|
|
|
{
|
|
|
|
|
QLToolbar * Tb = new QLToolbar(tbb, *this);
|
|
|
|
|
static QLToolbar * lastTb = 0;
|
|
|
|
|
|
|
|
|
|
if (tbb.flags & ToolbarBackend::TOP) {
|
|
|
|
|
addToolBar(Qt::TopToolBarArea, Tb);
|
|
|
|
|
addToolBarBreak(Qt::TopToolBarArea);
|
|
|
|
|
}
|
|
|
|
|
if (tbb.flags & ToolbarBackend::BOTTOM) {
|
|
|
|
|
addToolBar(Qt::BottomToolBarArea, Tb);
|
|
|
|
|
if (lastTb)
|
|
|
|
|
insertToolBarBreak(lastTb);
|
|
|
|
|
lastTb = Tb;
|
|
|
|
|
}
|
|
|
|
|
if (tbb.flags & ToolbarBackend::LEFT) {
|
|
|
|
|
addToolBar(Qt::LeftToolBarArea, Tb);
|
|
|
|
|
}
|
|
|
|
|
if (tbb.flags & ToolbarBackend::RIGHT) {
|
|
|
|
|
addToolBar(Qt::RightToolBarArea, Tb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Toolbars::ToolbarPtr(Tb);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
#include "GuiView_moc.cpp"
|