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>
|
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
#include "GuiView.h"
|
2006-10-26 13:29:10 +00:00
|
|
|
|
|
|
|
|
|
#include "GuiImplementation.h"
|
|
|
|
|
#include "GuiWorkArea.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QLMenubar.h"
|
2006-09-10 11:03:21 +00:00
|
|
|
|
#include "QLToolbar.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QCommandBuffer.h"
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
#include "frontends/Gui.h"
|
|
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/convert.h"
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "bufferlist.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "lyx_cb.h"
|
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyx_main.h"
|
|
|
|
|
#include "session.h"
|
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
#include "MenuBackend.h"
|
|
|
|
|
|
2006-10-22 14:37:32 +00:00
|
|
|
|
#include <QAction>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <QApplication>
|
2006-10-22 14:37:32 +00:00
|
|
|
|
#include <QCloseEvent>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QToolBar>
|
2006-10-27 11:47:59 +00:00
|
|
|
|
#include <QDesktopWidget>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
using std::endl;
|
2006-10-24 15:01:07 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
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-10-23 16:29:24 +00:00
|
|
|
|
GuiView::GuiView(int id)
|
|
|
|
|
: QMainWindow(), LyXView(id), commandbuffer_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-10-23 16:29:24 +00:00
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
setAttribute(Qt::WA_QuitOnClose, true);
|
|
|
|
|
|
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
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
void GuiView::close()
|
|
|
|
|
{
|
|
|
|
|
QMainWindow::close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
void GuiView::init()
|
|
|
|
|
{
|
|
|
|
|
menubar_.reset(new QLMenubar(this, menubackend));
|
2006-10-22 14:37:32 +00:00
|
|
|
|
QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
|
|
|
|
|
this, SLOT(updateMenu(QAction *)));
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
|
|
getToolbars().init();
|
|
|
|
|
|
|
|
|
|
statusBar()->setSizeGripEnabled(false);
|
|
|
|
|
|
2006-10-22 14:37:32 +00:00
|
|
|
|
QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
|
|
|
|
|
this, SLOT(update_view_state_qt()));
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
|
|
// make sure the buttons are disabled if needed
|
|
|
|
|
updateToolbars();
|
2006-09-29 23:10:17 +00:00
|
|
|
|
updateLayoutChoice();
|
|
|
|
|
updateMenubar();
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
void GuiView::saveGeometry()
|
|
|
|
|
{
|
|
|
|
|
// FIXME:
|
|
|
|
|
// change the ifdef to 'geometry = normalGeometry();' only
|
|
|
|
|
// when Trolltech has fixed the broken normalGeometry on X11:
|
|
|
|
|
// http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
|
|
|
|
|
// Then also the moveEvent, resizeEvent, and the
|
|
|
|
|
// code for floatingGeometry_ can be removed;
|
|
|
|
|
// adjust GuiView::setGeometry()
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
|
QRect geometry = normalGeometry();
|
|
|
|
|
#else
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
QRect geometry = floatingGeometry_;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// save windows size and position
|
|
|
|
|
Session & session = LyX::ref().session();
|
2006-10-27 14:18:03 +00:00
|
|
|
|
session.SessionInfo().save("WindowWidth", convert<string>(geometry.width()));
|
|
|
|
|
session.SessionInfo().save("WindowHeight", convert<string>(geometry.height()));
|
|
|
|
|
session.SessionInfo().save("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
|
2006-10-23 16:29:24 +00:00
|
|
|
|
if (lyxrc.geometry_xysaved) {
|
2006-10-27 14:18:03 +00:00
|
|
|
|
session.SessionInfo().save("WindowPosX", convert<string>(geometry.x()));
|
|
|
|
|
session.SessionInfo().save("WindowPosY", convert<string>(geometry.y()));
|
2006-10-23 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 23:10:17 +00:00
|
|
|
|
void GuiView::setGeometry(unsigned int width,
|
|
|
|
|
unsigned int height,
|
|
|
|
|
int posx, int posy,
|
|
|
|
|
bool maximize)
|
|
|
|
|
{
|
|
|
|
|
// only true when the -geometry option was NOT used
|
|
|
|
|
if (width != 0 && height != 0) {
|
|
|
|
|
if (posx != -1 && posy != -1) {
|
2006-10-27 08:40:08 +00:00
|
|
|
|
// if there are ever startup positioning problems
|
|
|
|
|
// on a virtual desktop then check the 6 lines below
|
|
|
|
|
// http://doc.trolltech.com/4.2/qdesktopwidget.html
|
|
|
|
|
QDesktopWidget& dw = *qApp->desktop();
|
|
|
|
|
QRect desk = dw.availableGeometry(dw.primaryScreen());
|
|
|
|
|
if (posx >= desk.width())
|
|
|
|
|
posx = 0.1 * desk.width();
|
|
|
|
|
if (posy >= desk.height())
|
|
|
|
|
posy = 0.1 * desk.height();
|
2006-10-02 18:21:48 +00:00
|
|
|
|
#ifdef Q_WS_WIN
|
2006-09-29 23:10:17 +00:00
|
|
|
|
// FIXME: use only setGeoemtry when Trolltech has
|
|
|
|
|
// fixed the qt4/X11 bug
|
|
|
|
|
QMainWindow::setGeometry(posx, posy,width, height);
|
|
|
|
|
#else
|
|
|
|
|
resize(width, height);
|
|
|
|
|
move(posx, posy);
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
resize(width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maximize)
|
|
|
|
|
setWindowState(Qt::WindowMaximized);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
show();
|
2006-06-26 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 23:10:17 +00:00
|
|
|
|
|
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-10-11 17:24:46 +00:00
|
|
|
|
statusBar()->showMessage(toqstr(theLyXFunc().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-10-11 17:24:46 +00:00
|
|
|
|
statusBar()->showMessage(toqstr(theLyXFunc().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
|
|
|
|
{
|
2006-10-11 17:24:46 +00:00
|
|
|
|
dispatch(func);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-10-24 15:01:07 +00:00
|
|
|
|
void GuiView::closeEvent(QCloseEvent * close_event)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-10-24 15:01:07 +00:00
|
|
|
|
GuiImplementation & gui
|
|
|
|
|
= static_cast<GuiImplementation &>(theApp->gui());
|
|
|
|
|
|
|
|
|
|
vector<int> const & view_ids = gui.viewIds();
|
|
|
|
|
|
|
|
|
|
if (view_ids.size() == 1 && !theBufferList().quitWriteAll()) {
|
|
|
|
|
close_event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
saveGeometry();
|
2006-10-24 15:01:07 +00:00
|
|
|
|
gui.unregisterView(this);
|
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-10-26 13:29:10 +00:00
|
|
|
|
void GuiView::busy(bool yes)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-10-26 13:29:10 +00:00
|
|
|
|
static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
|
|
|
|
|
|
|
|
|
|
if (yes) {
|
|
|
|
|
work_area_->stopBlinkingCursor();
|
2006-06-04 20:49:09 +00:00
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2006-10-26 13:29:10 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
work_area_->startBlinkingCursor();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
QApplication::restoreOverrideCursor();
|
2006-10-26 13:29:10 +00:00
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
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"
|