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.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-06-04 20:49:09 +00:00
|
|
|
|
#undef QT3_SUPPORT
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#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"
|
|
|
|
|
|
|
|
|
|
#include "frontends/Toolbars.h"
|
|
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
|
2006-04-05 22:56:18 +00:00
|
|
|
|
#include "support/convert.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
#include "GuiView.h"
|
2006-06-26 16:55:35 +00:00
|
|
|
|
#include "GuiImplementation.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QLMenubar.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-06-26 16:55:35 +00:00
|
|
|
|
//#include <QMenu>
|
|
|
|
|
//#include <QMenuBar>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-06-26 16:55:35 +00:00
|
|
|
|
GuiView::GuiView(Gui & owner)
|
|
|
|
|
: QMainWindow(), LyXView(owner), commandbuffer_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-06-04 20:49:09 +00:00
|
|
|
|
mainWidget_ = this;
|
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);
|
|
|
|
|
|
|
|
|
|
view_state_changed.connect(boost::bind(&GuiView::update_view_state, this));
|
|
|
|
|
QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
|
|
|
|
|
|
|
|
|
|
// make sure the buttons are disabled if needed
|
|
|
|
|
updateToolbars();
|
|
|
|
|
|
|
|
|
|
LyXView::init();
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-20 09:33:01 +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-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::setWindowTitle(string const & t, string 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-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::message(string 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-06-20 09:33:01 +00:00
|
|
|
|
void GuiView::update_view_state()
|
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-06-21 10:30:32 +00:00
|
|
|
|
void GuiView::updateFloatingGeometry()
|
|
|
|
|
{
|
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-06-21 10:30:32 +00:00
|
|
|
|
// FIXME:
|
|
|
|
|
// change the ifdef to 'geometry = normalGeometry();' only
|
|
|
|
|
// when Trolltech has fixed the broken normalGeometry on X11.
|
|
|
|
|
// 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();
|
|
|
|
|
QRect geometry = floatingGeometry_;
|
|
|
|
|
#endif
|
|
|
|
|
|
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-06-23 10:19:31 +00:00
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
QMainWindow* GuiView::mainWidget()
|
2006-06-04 20:49:09 +00:00
|
|
|
|
{
|
|
|
|
|
return mainWidget_;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
QMainWindow* GuiView::mainWidget_ = 0;
|
2006-06-04 20:49:09 +00:00
|
|
|
|
|
|
|
|
|
|
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"
|