2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
|
* \file GuiView.cpp
|
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
|
2006-11-27 23:35:43 +00:00
|
|
|
|
* \author Peter K<EFBFBD>mmel
|
2006-03-05 17:24:44 +00:00
|
|
|
|
*
|
|
|
|
|
* 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"
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiKeySymbol.h"
|
|
|
|
|
#include "GuiMenubar.h"
|
|
|
|
|
#include "GuiToolbar.h"
|
2007-10-01 20:45:50 +00:00
|
|
|
|
#include "GuiToolbars.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "frontends/Application.h"
|
2007-08-21 07:33:46 +00:00
|
|
|
|
#include "frontends/Dialogs.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "frontends/Gui.h"
|
|
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/convert.h"
|
|
|
|
|
#include "support/lstrings.h"
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include "support/os.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include "Buffer.h"
|
2007-10-01 20:45:50 +00:00
|
|
|
|
#include "BufferParams.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "BufferList.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
|
#include "Cursor.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2007-10-01 20:45:50 +00:00
|
|
|
|
#include "Layout.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyX.h"
|
|
|
|
|
#include "LyXFunc.h"
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include "LyXRC.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "MenuBackend.h"
|
2007-10-01 20:45:50 +00:00
|
|
|
|
#include "Paragraph.h"
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include "Session.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
|
#include "TextClass.h"
|
2007-10-15 22:43:55 +00:00
|
|
|
|
#include "ToolbarBackend.h"
|
2007-08-21 07:33:46 +00:00
|
|
|
|
#include "version.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
|
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>
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
|
#include <QDropEvent>
|
|
|
|
|
#include <QList>
|
2007-09-28 23:26:59 +00:00
|
|
|
|
#include <QMenu>
|
2007-08-21 07:33:46 +00:00
|
|
|
|
#include <QPainter>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <QPixmap>
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include <QPushButton>
|
2007-08-21 07:33:46 +00:00
|
|
|
|
#include <QStackedWidget>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QToolBar>
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include <QUrl>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-10-18 09:24:16 +00:00
|
|
|
|
#include <boost/current_function.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 {
|
|
|
|
|
|
2007-02-28 21:48:04 +00:00
|
|
|
|
using support::makeDisplayPath;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-10-03 18:56:37 +00:00
|
|
|
|
extern bool quitting;
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
int const statusbar_timer_value = 3000;
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
class BackgroundWidget : public QWidget
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BackgroundWidget(QString const & file, QString const & text)
|
2007-06-11 14:53:36 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
splash_ = new QPixmap(file);
|
|
|
|
|
if (!splash_) {
|
|
|
|
|
lyxerr << "could not load splash screen: '" << fromqstr(file) << "'" << endl;
|
|
|
|
|
return;
|
2007-06-11 14:53:36 +00:00
|
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
QPainter pain(splash_);
|
|
|
|
|
pain.setPen(QColor(255, 255, 0));
|
|
|
|
|
QFont font;
|
|
|
|
|
// The font used to display the version info
|
|
|
|
|
font.setStyleHint(QFont::SansSerif);
|
|
|
|
|
font.setWeight(QFont::Bold);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
font.setPointSize(convert<int>(lyxrc.font_sizes[FONT_SIZE_LARGE]));
|
2007-08-21 07:33:46 +00:00
|
|
|
|
pain.setFont(font);
|
|
|
|
|
pain.drawText(260, 270, text);
|
2007-06-11 14:53:36 +00:00
|
|
|
|
}
|
2007-02-01 18:48:58 +00:00
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void paintEvent(QPaintEvent *)
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (!splash_)
|
|
|
|
|
return;
|
2007-06-11 14:53:36 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
int x = (width() - splash_->width()) / 2;
|
|
|
|
|
int y = (height() - splash_->height()) / 2;
|
|
|
|
|
QPainter pain(this);
|
|
|
|
|
pain.drawPixmap(x, y, *splash_);
|
2007-02-01 18:48:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
private:
|
|
|
|
|
QPixmap * splash_;
|
2006-10-31 14:12:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2007-08-23 08:56:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
struct GuiView::GuiViewPrivate
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{
|
2007-02-25 19:42:48 +00:00
|
|
|
|
string cur_title;
|
2007-02-01 18:48:58 +00:00
|
|
|
|
|
2006-11-09 09:13:04 +00:00
|
|
|
|
int posx_offset;
|
|
|
|
|
int posy_offset;
|
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
|
TabWorkArea * tab_widget_;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
QStackedWidget * stack_widget_;
|
|
|
|
|
BackgroundWidget * bg_widget_;
|
2007-08-23 12:44:21 +00:00
|
|
|
|
/// view's menubar
|
2007-08-31 05:53:55 +00:00
|
|
|
|
GuiMenubar * menubar_;
|
2007-10-01 20:45:50 +00:00
|
|
|
|
/// view's toolbars
|
|
|
|
|
GuiToolbars * toolbars_;
|
|
|
|
|
///
|
|
|
|
|
docstring current_layout;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
GuiViewPrivate() : posx_offset(0), posy_offset(0) {}
|
2006-11-27 23:35:43 +00:00
|
|
|
|
|
2006-11-29 10:04:35 +00:00
|
|
|
|
unsigned int smallIconSize;
|
|
|
|
|
unsigned int normalIconSize;
|
|
|
|
|
unsigned int bigIconSize;
|
|
|
|
|
// static needed by "New Window"
|
|
|
|
|
static unsigned int lastIconSize;
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
QMenu * toolBarPopup(GuiView * parent)
|
2006-11-29 10:04:35 +00:00
|
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// FIXME: translation
|
2007-08-31 05:53:55 +00:00
|
|
|
|
QMenu * menu = new QMenu(parent);
|
|
|
|
|
QActionGroup * iconSizeGroup = new QActionGroup(parent);
|
2006-11-29 10:04:35 +00:00
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
QAction * smallIcons = new QAction(iconSizeGroup);
|
2007-01-27 14:42:45 +00:00
|
|
|
|
smallIcons->setText(qt_("Small-sized icons"));
|
2006-11-29 10:04:35 +00:00
|
|
|
|
smallIcons->setCheckable(true);
|
2006-12-30 10:30:02 +00:00
|
|
|
|
QObject::connect(smallIcons, SIGNAL(triggered()), parent, SLOT(smallSizedIcons()));
|
2006-11-29 10:04:35 +00:00
|
|
|
|
menu->addAction(smallIcons);
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
QAction * normalIcons = new QAction(iconSizeGroup);
|
2007-01-27 14:42:45 +00:00
|
|
|
|
normalIcons->setText(qt_("Normal-sized icons"));
|
2006-11-29 10:04:35 +00:00
|
|
|
|
normalIcons->setCheckable(true);
|
2006-12-30 10:30:02 +00:00
|
|
|
|
QObject::connect(normalIcons, SIGNAL(triggered()), parent, SLOT(normalSizedIcons()));
|
2006-11-29 10:04:35 +00:00
|
|
|
|
menu->addAction(normalIcons);
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
QAction * bigIcons = new QAction(iconSizeGroup);
|
2007-01-27 14:42:45 +00:00
|
|
|
|
bigIcons->setText(qt_("Big-sized icons"));
|
2006-11-29 10:04:35 +00:00
|
|
|
|
bigIcons->setCheckable(true);
|
2006-12-30 10:30:02 +00:00
|
|
|
|
QObject::connect(bigIcons, SIGNAL(triggered()), parent, SLOT(bigSizedIcons()));
|
2006-11-29 10:04:35 +00:00
|
|
|
|
menu->addAction(bigIcons);
|
|
|
|
|
|
2006-11-29 21:52:56 +00:00
|
|
|
|
unsigned int cur = parent->iconSize().width();
|
2006-11-29 10:04:35 +00:00
|
|
|
|
if ( cur == parent->d.smallIconSize)
|
|
|
|
|
smallIcons->setChecked(true);
|
|
|
|
|
else if (cur == parent->d.normalIconSize)
|
|
|
|
|
normalIcons->setChecked(true);
|
|
|
|
|
else if (cur == parent->d.bigIconSize)
|
|
|
|
|
bigIcons->setChecked(true);
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
void initBackground()
|
|
|
|
|
{
|
|
|
|
|
bg_widget_ = 0;
|
|
|
|
|
LYXERR(Debug::GUI) << "show banner: " << lyxrc.show_banner << endl;
|
|
|
|
|
/// The text to be written on top of the pixmap
|
|
|
|
|
QString const text = lyx_version ? QString(lyx_version) : qt_("unknown version");
|
2007-10-17 18:28:45 +00:00
|
|
|
|
bg_widget_ = new BackgroundWidget(":/images/banner.png", text);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setBackground()
|
|
|
|
|
{
|
|
|
|
|
if (!bg_widget_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
stack_widget_->setCurrentWidget(bg_widget_);
|
|
|
|
|
bg_widget_->setUpdatesEnabled(true);
|
|
|
|
|
}
|
2006-10-31 14:12:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
unsigned int GuiView::GuiViewPrivate::lastIconSize = 0;
|
2006-11-27 23:35:43 +00:00
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
GuiView::GuiView(int id)
|
2007-08-24 07:13:07 +00:00
|
|
|
|
: QMainWindow(), LyXView(id), quitting_by_menu_(false),
|
2006-12-16 10:40:43 +00:00
|
|
|
|
d(*new GuiViewPrivate)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
|
// Qt bug? signal lastWindowClosed does not work
|
|
|
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
2006-12-03 13:09:57 +00:00
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2006-12-02 17:39:31 +00:00
|
|
|
|
|
2006-11-29 10:04:35 +00:00
|
|
|
|
// hardcode here the platform specific icon size
|
|
|
|
|
d.smallIconSize = 14; // scaling problems
|
|
|
|
|
d.normalIconSize = 20; // ok, default
|
|
|
|
|
d.bigIconSize = 26; // better for some math icons
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#ifndef Q_WS_MACX
|
2007-08-30 20:09:12 +00:00
|
|
|
|
// assign an icon to main form. We do not do it under Qt/Mac,
|
|
|
|
|
// since the icon is provided in the application bundle.
|
2007-10-17 18:28:45 +00:00
|
|
|
|
setWindowIcon(QPixmap(":/images/lyx.png"));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#endif
|
2007-08-14 13:14:47 +00:00
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
|
d.tab_widget_ = new TabWorkArea;
|
|
|
|
|
QObject::connect(d.tab_widget_, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
|
|
|
|
|
this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
d.initBackground();
|
|
|
|
|
if (d.bg_widget_) {
|
2007-09-14 06:33:53 +00:00
|
|
|
|
LYXERR(Debug::GUI) << "stack widget!" << endl;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
d.stack_widget_ = new QStackedWidget;
|
|
|
|
|
d.stack_widget_->addWidget(d.bg_widget_);
|
|
|
|
|
d.stack_widget_->addWidget(d.tab_widget_);
|
|
|
|
|
setCentralWidget(d.stack_widget_);
|
|
|
|
|
} else {
|
|
|
|
|
d.stack_widget_ = 0;
|
|
|
|
|
setCentralWidget(d.tab_widget_);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-14 13:14:47 +00:00
|
|
|
|
// For Drag&Drop.
|
|
|
|
|
setAcceptDrops(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
GuiView::~GuiView()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-08-23 12:44:21 +00:00
|
|
|
|
delete d.menubar_;
|
2007-10-01 20:45:50 +00:00
|
|
|
|
delete d.toolbars_;
|
2006-10-31 14:12:46 +00:00
|
|
|
|
delete &d;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::close()
|
2006-10-23 16:29:24 +00:00
|
|
|
|
{
|
2006-12-12 01:39:50 +00:00
|
|
|
|
quitting_by_menu_ = true;
|
2007-10-07 08:12:20 +00:00
|
|
|
|
d.tab_widget_->closeAll();
|
2006-10-23 16:29:24 +00:00
|
|
|
|
QMainWindow::close();
|
2006-12-12 01:39:50 +00:00
|
|
|
|
quitting_by_menu_ = false;
|
2006-10-23 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::setFocus()
|
2006-12-23 17:09:50 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (d.tab_widget_->count())
|
|
|
|
|
d.tab_widget_->currentWidget()->setFocus();
|
2006-12-23 17:09:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
QMenu* GuiView::createPopupMenu()
|
2006-11-08 23:10:46 +00:00
|
|
|
|
{
|
2006-11-29 10:04:35 +00:00
|
|
|
|
return d.toolBarPopup(this);
|
2006-11-08 23:10:46 +00:00
|
|
|
|
}
|
2006-10-23 16:29:24 +00:00
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::init()
|
2006-06-26 16:55:35 +00:00
|
|
|
|
{
|
2007-10-01 20:45:50 +00:00
|
|
|
|
// GuiToolbars *must* be initialised before GuiMenubar.
|
|
|
|
|
d.toolbars_ = new GuiToolbars(*this);
|
|
|
|
|
// FIXME: GuiToolbars::init() cannot be integrated in the ctor
|
|
|
|
|
// because LyXFunc::getStatus() needs a properly initialized
|
|
|
|
|
// GuiToolbars object (for LFUN_TOOLBAR_TOGGLE).
|
|
|
|
|
d.toolbars_->init();
|
2007-08-31 05:53:55 +00:00
|
|
|
|
d.menubar_ = new GuiMenubar(this, menubackend);
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
2007-02-12 19:34:14 +00:00
|
|
|
|
statusBar()->setSizeGripEnabled(true);
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
2006-12-30 10:30:02 +00:00
|
|
|
|
QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
|
|
|
|
|
this, SLOT(update_view_state_qt()));
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (d.stack_widget_)
|
|
|
|
|
d.stack_widget_->setCurrentWidget(d.bg_widget_);
|
2006-09-29 23:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 10:05:41 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::closeEvent(QCloseEvent * close_event)
|
2006-12-02 17:39:31 +00:00
|
|
|
|
{
|
2006-12-12 01:39:50 +00:00
|
|
|
|
// we may have been called through the close window button
|
|
|
|
|
// which bypasses the LFUN machinery.
|
2007-02-14 13:39:11 +00:00
|
|
|
|
if (!quitting_by_menu_ && theApp()->gui().viewIds().size() == 1) {
|
2006-12-12 01:39:50 +00:00
|
|
|
|
if (!theBufferList().quitWriteAll()) {
|
|
|
|
|
close_event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-02-14 13:39:11 +00:00
|
|
|
|
|
2007-07-17 09:21:52 +00:00
|
|
|
|
// Make sure that no LFUN use this close to be closed View.
|
|
|
|
|
theLyXFunc().setLyXView(0);
|
|
|
|
|
// Make sure the timer time out will not trigger a statusbar update.
|
|
|
|
|
statusbar_timer_.stop();
|
|
|
|
|
|
2007-02-14 13:39:11 +00:00
|
|
|
|
theApp()->gui().unregisterView(id());
|
|
|
|
|
if (!theApp()->gui().viewIds().empty()) {
|
|
|
|
|
// Just close the window and do nothing else if this is not the
|
|
|
|
|
// last window.
|
|
|
|
|
close_event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-19 10:48:16 +00:00
|
|
|
|
quitting = true;
|
|
|
|
|
|
2007-02-14 13:39:11 +00:00
|
|
|
|
// this is the place where we leave the frontend.
|
|
|
|
|
// it is the only point at which we start quitting.
|
|
|
|
|
saveGeometry();
|
2006-12-02 17:39:31 +00:00
|
|
|
|
close_event->accept();
|
2007-02-14 13:39:11 +00:00
|
|
|
|
// quit the event loop
|
|
|
|
|
qApp->quit();
|
2006-12-02 17:39:31 +00:00
|
|
|
|
}
|
2006-07-06 08:18:51 +00:00
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::dragEnterEvent(QDragEnterEvent * event)
|
2007-08-14 13:14:47 +00:00
|
|
|
|
{
|
|
|
|
|
if (event->mimeData()->hasUrls())
|
|
|
|
|
event->accept();
|
|
|
|
|
/// \todo Ask lyx-devel is this is enough:
|
|
|
|
|
/// if (event->mimeData()->hasFormat("text/plain"))
|
|
|
|
|
/// event->acceptProposedAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::dropEvent(QDropEvent* event)
|
2007-08-14 13:14:47 +00:00
|
|
|
|
{
|
|
|
|
|
QList<QUrl> files = event->mimeData()->urls();
|
|
|
|
|
if (files.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " got URLs!" << endl;
|
2007-08-31 05:53:55 +00:00
|
|
|
|
for (int i = 0; i != files.size(); ++i) {
|
2007-08-14 13:14:47 +00:00
|
|
|
|
string const file = support::os::internal_path(fromqstr(
|
|
|
|
|
files.at(i).toLocalFile()));
|
|
|
|
|
if (!file.empty())
|
|
|
|
|
dispatch(FuncRequest(LFUN_FILE_OPEN, file));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::saveGeometry()
|
2006-10-23 16:29:24 +00:00
|
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
|
static bool done = false;
|
|
|
|
|
if (done)
|
|
|
|
|
return;
|
|
|
|
|
else
|
|
|
|
|
done = true;
|
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
// 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;
|
2007-11-05 13:52:37 +00:00
|
|
|
|
// adjust GuiView::setGeometry()
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-03-17 12:28:26 +00:00
|
|
|
|
QRect normal_geometry;
|
|
|
|
|
int maximized;
|
2006-11-09 09:13:04 +00:00
|
|
|
|
#ifdef Q_WS_WIN
|
2007-03-17 12:28:26 +00:00
|
|
|
|
normal_geometry = normalGeometry();
|
|
|
|
|
if (isMaximized()) {
|
|
|
|
|
maximized = CompletelyMaximized;
|
|
|
|
|
} else {
|
|
|
|
|
maximized = NotMaximized;
|
|
|
|
|
}
|
2006-10-23 16:29:24 +00:00
|
|
|
|
#else
|
2007-03-17 12:28:26 +00:00
|
|
|
|
normal_geometry = updateFloatingGeometry();
|
|
|
|
|
|
|
|
|
|
QDesktopWidget& dw = *qApp->desktop();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
QRect desk = dw.availableGeometry(dw.primaryScreen());
|
2007-03-17 12:28:26 +00:00
|
|
|
|
// Qt bug on Linux: load completely maximized, vert max. save-> frameGeometry().height() is wrong
|
|
|
|
|
if (isMaximized() && desk.width() <= frameGeometry().width() && desk.height() <= frameGeometry().height()) {
|
|
|
|
|
maximized = CompletelyMaximized;
|
|
|
|
|
// maximizing does not work when the window is allready hor. or vert. maximized
|
|
|
|
|
// Tested only on KDE
|
2007-05-28 22:27:45 +00:00
|
|
|
|
int dh = frameGeometry().height() - height();
|
|
|
|
|
if (desk.height() <= normal_geometry.height() + dh)
|
2007-03-17 12:28:26 +00:00
|
|
|
|
normal_geometry.setHeight(normal_geometry.height() - 1);
|
|
|
|
|
int dw = frameGeometry().width() - width();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (desk.width() <= normal_geometry.width() + dw)
|
2007-03-17 12:28:26 +00:00
|
|
|
|
normal_geometry.setWidth(normal_geometry.width() - 1);
|
|
|
|
|
} else if (desk.height() <= frameGeometry().height()) {
|
2007-05-28 22:27:45 +00:00
|
|
|
|
maximized = VerticallyMaximized;
|
2007-03-17 12:28:26 +00:00
|
|
|
|
} else if (desk.width() <= frameGeometry().width()) {
|
|
|
|
|
maximized = HorizontallyMaximized;
|
|
|
|
|
} else {
|
|
|
|
|
maximized = NotMaximized;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
|
2007-03-17 12:28:26 +00:00
|
|
|
|
#endif
|
2006-10-23 16:29:24 +00:00
|
|
|
|
// save windows size and position
|
|
|
|
|
Session & session = LyX::ref().session();
|
2007-03-17 12:28:26 +00:00
|
|
|
|
session.sessionInfo().save("WindowWidth", convert<string>(normal_geometry.width()));
|
|
|
|
|
session.sessionInfo().save("WindowHeight", convert<string>(normal_geometry.height()));
|
|
|
|
|
session.sessionInfo().save("WindowMaximized", convert<string>(maximized));
|
2006-11-27 23:35:43 +00:00
|
|
|
|
session.sessionInfo().save("IconSizeXY", convert<string>(iconSize().width()));
|
2006-10-23 16:29:24 +00:00
|
|
|
|
if (lyxrc.geometry_xysaved) {
|
2007-03-17 12:28:26 +00:00
|
|
|
|
session.sessionInfo().save("WindowPosX", convert<string>(normal_geometry.x() + d.posx_offset));
|
|
|
|
|
session.sessionInfo().save("WindowPosY", convert<string>(normal_geometry.y() + d.posy_offset));
|
2006-10-23 16:29:24 +00:00
|
|
|
|
}
|
2007-10-01 20:45:50 +00:00
|
|
|
|
d.toolbars_->saveToolbarInfo();
|
2006-10-23 16:29:24 +00:00
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::setGeometry(unsigned int width,
|
2007-02-04 21:19:20 +00:00
|
|
|
|
unsigned int height,
|
|
|
|
|
int posx, int posy,
|
2007-03-17 12:28:26 +00:00
|
|
|
|
int maximized,
|
2007-02-04 21:19:20 +00:00
|
|
|
|
unsigned int iconSizeXY,
|
|
|
|
|
const string & geometryArg)
|
2006-09-29 23:10:17 +00:00
|
|
|
|
{
|
2006-11-29 10:04:35 +00:00
|
|
|
|
// use last value (not at startup)
|
|
|
|
|
if (d.lastIconSize != 0)
|
|
|
|
|
setIconSize(d.lastIconSize);
|
|
|
|
|
else if (iconSizeXY != 0)
|
|
|
|
|
setIconSize(iconSizeXY);
|
2006-11-27 23:35:43 +00:00
|
|
|
|
else
|
2006-11-29 10:04:35 +00:00
|
|
|
|
setIconSize(d.normalIconSize);
|
2006-11-27 23:35:43 +00:00
|
|
|
|
|
2006-09-29 23:10:17 +00:00
|
|
|
|
// only true when the -geometry option was NOT used
|
|
|
|
|
if (width != 0 && height != 0) {
|
|
|
|
|
if (posx != -1 && posy != -1) {
|
2007-04-13 13:42:59 +00:00
|
|
|
|
// if there are startup positioning problems:
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// http://doc.trolltech.com/4.2/qdesktopwidget.html
|
2006-10-27 08:40:08 +00:00
|
|
|
|
QDesktopWidget& dw = *qApp->desktop();
|
2007-04-13 13:42:59 +00:00
|
|
|
|
if (dw.isVirtualDesktop()) {
|
|
|
|
|
if(!dw.geometry().contains(posx, posy)) {
|
|
|
|
|
posx = 50;
|
|
|
|
|
posy = 50;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Which system doesn't use a virtual desktop?
|
|
|
|
|
// TODO save also last screen number and check if it is still availabe.
|
2007-03-28 21:12:50 +00:00
|
|
|
|
}
|
2006-10-02 18:21:48 +00:00
|
|
|
|
#ifdef Q_WS_WIN
|
2006-11-09 09:13:04 +00:00
|
|
|
|
// FIXME: use setGeometry only when Trolltech has fixed the qt4/X11 bug
|
|
|
|
|
QWidget::setGeometry(posx, posy, width, height);
|
2006-09-29 23:10:17 +00:00
|
|
|
|
#else
|
|
|
|
|
resize(width, height);
|
|
|
|
|
move(posx, posy);
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
resize(width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-17 12:28:26 +00:00
|
|
|
|
// remember original size
|
|
|
|
|
floatingGeometry_ = QRect(posx, posy, width, height);
|
|
|
|
|
|
|
|
|
|
if (maximized != NotMaximized) {
|
|
|
|
|
if (maximized == CompletelyMaximized) {
|
|
|
|
|
setWindowState(Qt::WindowMaximized);
|
|
|
|
|
} else {
|
|
|
|
|
#ifndef Q_WS_WIN
|
|
|
|
|
// TODO How to set by the window manager?
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// setWindowState(Qt::WindowVerticallyMaximized);
|
2007-03-17 12:28:26 +00:00
|
|
|
|
// is not possible
|
|
|
|
|
QDesktopWidget& dw = *qApp->desktop();
|
|
|
|
|
QRect desk = dw.availableGeometry(dw.primaryScreen());
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (maximized == VerticallyMaximized)
|
2007-03-17 12:28:26 +00:00
|
|
|
|
resize(width, desk.height());
|
|
|
|
|
if (maximized == HorizontallyMaximized)
|
|
|
|
|
resize(desk.width(), height);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-09-29 23:10:17 +00:00
|
|
|
|
}
|
2006-11-29 16:45:38 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2007-04-26 04:41:58 +00:00
|
|
|
|
// FIXME: move this code into parse_geometry() (LyX.cpp)
|
2006-11-29 16:45:38 +00:00
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
int x, y;
|
|
|
|
|
int w, h;
|
|
|
|
|
QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
|
2007-02-04 21:19:20 +00:00
|
|
|
|
re.indexIn(toqstr(geometryArg.c_str()));
|
|
|
|
|
w = re.cap(1).toInt();
|
|
|
|
|
h = re.cap(2).toInt();
|
|
|
|
|
x = re.cap(3).toInt();
|
|
|
|
|
y = re.cap(4).toInt();
|
2006-11-29 16:45:38 +00:00
|
|
|
|
QWidget::setGeometry( x, y, w, h );
|
2007-02-04 21:19:20 +00:00
|
|
|
|
#else
|
|
|
|
|
// silence warning
|
|
|
|
|
(void)geometryArg;
|
2006-11-29 16:45:38 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
d.setBackground();
|
|
|
|
|
|
2006-09-29 23:10:17 +00:00
|
|
|
|
show();
|
2006-11-05 15:34:18 +00:00
|
|
|
|
|
|
|
|
|
// For an unknown reason, the Window title update is not effective for
|
|
|
|
|
// the second windows up until it is shown on screen (Qt bug?).
|
|
|
|
|
updateWindowTitle();
|
2006-11-09 09:13:04 +00:00
|
|
|
|
|
|
|
|
|
// after show geometry() has changed (Qt bug?)
|
|
|
|
|
// we compensate the drift when storing the position
|
|
|
|
|
d.posx_offset = 0;
|
|
|
|
|
d.posy_offset = 0;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (width != 0 && height != 0)
|
2006-11-09 09:13:04 +00:00
|
|
|
|
if (posx != -1 && posy != -1) {
|
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
d.posx_offset = posx - normalGeometry().x();
|
|
|
|
|
d.posy_offset = posy - normalGeometry().y();
|
|
|
|
|
#else
|
2007-01-14 17:14:31 +00:00
|
|
|
|
#ifndef Q_WS_MACX
|
2007-03-17 12:28:26 +00:00
|
|
|
|
if (maximized == NotMaximized) {
|
2006-11-09 09:13:04 +00:00
|
|
|
|
d.posx_offset = posx - geometry().x();
|
|
|
|
|
d.posy_offset = posy - geometry().y();
|
|
|
|
|
}
|
2007-01-14 17:14:31 +00:00
|
|
|
|
#endif
|
2006-11-09 09:13:04 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2006-06-26 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 23:10:17 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::setWindowTitle(docstring const & t, docstring const & it)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-11-05 15:34:18 +00:00
|
|
|
|
QString title = windowTitle();
|
|
|
|
|
QString new_title = toqstr(t);
|
|
|
|
|
if (title != new_title) {
|
|
|
|
|
QMainWindow::setWindowTitle(new_title);
|
|
|
|
|
QMainWindow::setWindowIconText(toqstr(it));
|
|
|
|
|
}
|
2007-10-04 10:16:06 +00:00
|
|
|
|
if (Buffer const * buf = buffer())
|
|
|
|
|
d.tab_widget_->setTabText(d.tab_widget_->currentIndex(),
|
2007-11-03 17:37:37 +00:00
|
|
|
|
toqstr(buf->fileName().displayName(30)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::clearMessage()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
update_view_state_qt();
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::setIconSize(unsigned int size)
|
2006-11-29 10:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
d.lastIconSize = size;
|
|
|
|
|
QMainWindow::setIconSize(QSize(size, size));
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::smallSizedIcons()
|
2006-11-29 10:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
setIconSize(d.smallIconSize);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::normalSizedIcons()
|
2006-11-29 10:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
setIconSize(d.normalIconSize);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::bigSizedIcons()
|
2006-11-29 10:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
setIconSize(d.bigIconSize);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::update_view_state_qt()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-08-19 10:48:16 +00:00
|
|
|
|
if (!hasFocus())
|
|
|
|
|
return;
|
|
|
|
|
theLyXFunc().setLyXView(this);
|
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-12-03 13:17:35 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
disconnectBuffer();
|
|
|
|
|
disconnectBufferView();
|
2007-10-06 15:48:58 +00:00
|
|
|
|
connectBufferView(wa->bufferView());
|
|
|
|
|
connectBuffer(wa->bufferView().buffer());
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
updateToc();
|
|
|
|
|
// Buffer-dependent dialogs should be updated or
|
|
|
|
|
// hidden. This should go here because some dialogs (eg ToC)
|
|
|
|
|
// require bv_->text.
|
|
|
|
|
getDialogs().updateBufferDependent(true);
|
|
|
|
|
updateToolbars();
|
|
|
|
|
updateLayoutChoice();
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
updateStatusBar();
|
2006-10-31 14:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +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
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
QRect GuiView::updateFloatingGeometry()
|
2006-06-21 10:30:32 +00:00
|
|
|
|
{
|
2007-03-17 12:28:26 +00:00
|
|
|
|
QDesktopWidget& dw = *qApp->desktop();
|
|
|
|
|
QRect desk = dw.availableGeometry(dw.primaryScreen());
|
|
|
|
|
// remember only non-maximized sizes
|
|
|
|
|
if (!isMaximized() && desk.width() > frameGeometry().width() && desk.height() > frameGeometry().height()) {
|
2006-06-23 10:19:31 +00:00
|
|
|
|
floatingGeometry_ = QRect(x(), y(), width(), height());
|
2007-03-17 12:28:26 +00:00
|
|
|
|
}
|
|
|
|
|
return floatingGeometry_;
|
2006-06-21 10:30:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::resizeEvent(QResizeEvent *)
|
2006-06-21 10:30:32 +00:00
|
|
|
|
{
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::moveEvent(QMoveEvent *)
|
2006-06-21 10:30:32 +00:00
|
|
|
|
{
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
bool GuiView::event(QEvent * e)
|
2006-12-20 21:28:05 +00:00
|
|
|
|
{
|
|
|
|
|
switch (e->type())
|
|
|
|
|
{
|
2007-08-15 08:29:10 +00:00
|
|
|
|
// Useful debug code:
|
|
|
|
|
//case QEvent::ActivationChange:
|
|
|
|
|
//case QEvent::WindowDeactivate:
|
|
|
|
|
//case QEvent::Paint:
|
|
|
|
|
//case QEvent::Enter:
|
|
|
|
|
//case QEvent::Leave:
|
|
|
|
|
//case QEvent::HoverEnter:
|
|
|
|
|
//case QEvent::HoverLeave:
|
|
|
|
|
//case QEvent::HoverMove:
|
|
|
|
|
//case QEvent::StatusTip:
|
|
|
|
|
//case QEvent::DragEnter:
|
|
|
|
|
//case QEvent::DragLeave:
|
|
|
|
|
//case QEvent::Drop:
|
|
|
|
|
// break;
|
|
|
|
|
|
2007-10-16 06:50:09 +00:00
|
|
|
|
case QEvent::WindowActivate: {
|
2007-10-04 15:46:58 +00:00
|
|
|
|
theApp()->setCurrentView(*this);
|
2007-10-16 06:50:09 +00:00
|
|
|
|
GuiWorkArea * wa = d.tab_widget_->currentWorkArea();
|
|
|
|
|
if (wa) {
|
2007-10-03 07:17:58 +00:00
|
|
|
|
BufferView & bv = wa->bufferView();
|
|
|
|
|
connectBufferView(bv);
|
|
|
|
|
connectBuffer(bv.buffer());
|
2007-10-03 08:03:01 +00:00
|
|
|
|
// The document structure, name and dialogs might have
|
|
|
|
|
// changed in another view.
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
getDialogs().updateBufferDependent(true);
|
2007-10-03 07:17:58 +00:00
|
|
|
|
}
|
2007-10-03 07:12:28 +00:00
|
|
|
|
return QMainWindow::event(e);
|
2007-10-16 06:50:09 +00:00
|
|
|
|
}
|
2007-08-15 08:29:10 +00:00
|
|
|
|
case QEvent::ShortcutOverride: {
|
2006-12-20 21:28:05 +00:00
|
|
|
|
QKeyEvent * ke = static_cast<QKeyEvent*>(e);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (d.tab_widget_->count() == 0) {
|
|
|
|
|
theLyXFunc().setLyXView(this);
|
2007-09-17 18:41:03 +00:00
|
|
|
|
KeySymbol sym;
|
|
|
|
|
setKeySymbol(&sym, ke);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
|
|
|
|
|
e->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-12-22 16:13:19 +00:00
|
|
|
|
if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
|
2007-09-17 18:41:03 +00:00
|
|
|
|
KeySymbol sym;
|
|
|
|
|
setKeySymbol(&sym, ke);
|
2007-10-02 21:51:54 +00:00
|
|
|
|
currentWorkArea()->processKeySym(sym, NoModifier);
|
2006-12-20 21:28:05 +00:00
|
|
|
|
e->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-15 08:29:10 +00:00
|
|
|
|
default:
|
|
|
|
|
return QMainWindow::event(e);
|
|
|
|
|
}
|
2006-12-20 21:28:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
bool GuiView::focusNextPrevChild(bool /*next*/)
|
2006-12-22 16:13:19 +00:00
|
|
|
|
{
|
2006-12-23 17:09:50 +00:00
|
|
|
|
setFocus();
|
2006-12-22 16:13:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::showView()
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::setBusy(bool yes)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-10-16 06:50:09 +00:00
|
|
|
|
GuiWorkArea * wa = d.tab_widget_->currentWorkArea();
|
|
|
|
|
if (wa) {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
wa->setUpdatesEnabled(!yes);
|
|
|
|
|
if (yes)
|
|
|
|
|
wa->stopBlinkingCursor();
|
|
|
|
|
else
|
|
|
|
|
wa->startBlinkingCursor();
|
|
|
|
|
}
|
2006-10-26 13:29:10 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (yes)
|
2006-06-04 20:49:09 +00:00
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
else
|
2006-03-05 17:24:44 +00:00
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
GuiToolbar * GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
|
2006-09-10 11:03:21 +00:00
|
|
|
|
{
|
2007-08-31 05:53:55 +00:00
|
|
|
|
GuiToolbar * toolBar = new GuiToolbar(tbinfo, *this);
|
2006-09-10 11:03:21 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
if (tbinfo.flags & ToolbarInfo::TOP) {
|
2007-01-31 02:39:46 +00:00
|
|
|
|
if (newline)
|
|
|
|
|
addToolBarBreak(Qt::TopToolBarArea);
|
2007-08-31 05:53:55 +00:00
|
|
|
|
addToolBar(Qt::TopToolBarArea, toolBar);
|
2006-09-10 11:03:21 +00:00
|
|
|
|
}
|
2007-01-29 14:23:05 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
if (tbinfo.flags & ToolbarInfo::BOTTOM) {
|
2007-01-29 14:23:05 +00:00
|
|
|
|
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
|
|
|
|
#if (QT_VERSION >= 0x040202)
|
2007-01-31 02:39:46 +00:00
|
|
|
|
if (newline)
|
|
|
|
|
addToolBarBreak(Qt::BottomToolBarArea);
|
2007-01-29 14:23:05 +00:00
|
|
|
|
#endif
|
2007-08-31 05:53:55 +00:00
|
|
|
|
addToolBar(Qt::BottomToolBarArea, toolBar);
|
2006-09-10 11:03:21 +00:00
|
|
|
|
}
|
2007-01-29 14:23:05 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
if (tbinfo.flags & ToolbarInfo::LEFT) {
|
2007-01-29 14:23:05 +00:00
|
|
|
|
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
|
|
|
|
#if (QT_VERSION >= 0x040202)
|
2007-01-31 02:39:46 +00:00
|
|
|
|
if (newline)
|
|
|
|
|
addToolBarBreak(Qt::LeftToolBarArea);
|
2007-01-29 14:23:05 +00:00
|
|
|
|
#endif
|
2007-08-31 05:53:55 +00:00
|
|
|
|
addToolBar(Qt::LeftToolBarArea, toolBar);
|
2006-09-10 11:03:21 +00:00
|
|
|
|
}
|
2007-01-29 14:23:05 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
if (tbinfo.flags & ToolbarInfo::RIGHT) {
|
2007-01-29 14:23:05 +00:00
|
|
|
|
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
|
|
|
|
#if (QT_VERSION >= 0x040202)
|
2007-01-31 02:39:46 +00:00
|
|
|
|
if (newline)
|
|
|
|
|
addToolBarBreak(Qt::RightToolBarArea);
|
2007-01-29 14:23:05 +00:00
|
|
|
|
#endif
|
2007-08-31 05:53:55 +00:00
|
|
|
|
addToolBar(Qt::RightToolBarArea, toolBar);
|
2006-09-10 11:03:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
// The following does not work so I cannot restore to exact toolbar location
|
2007-01-27 20:54:17 +00:00
|
|
|
|
/*
|
2007-04-21 17:38:43 +00:00
|
|
|
|
ToolbarSection::ToolbarInfo & tbinfo = LyX::ref().session().toolbars().load(tbinfo.name);
|
2007-08-31 05:53:55 +00:00
|
|
|
|
toolBar->move(tbinfo.posx, tbinfo.posy);
|
2007-01-27 20:54:17 +00:00
|
|
|
|
*/
|
2007-01-29 14:23:05 +00:00
|
|
|
|
|
2007-09-19 22:37:22 +00:00
|
|
|
|
return toolBar;
|
2006-09-10 11:03:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
WorkArea * GuiView::workArea(Buffer & buffer)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
{
|
2007-10-16 06:50:09 +00:00
|
|
|
|
return d.tab_widget_->workArea(buffer);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
WorkArea * GuiView::addWorkArea(Buffer & buffer)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
{
|
|
|
|
|
GuiWorkArea * wa = new GuiWorkArea(buffer, *this);
|
2007-08-24 22:15:20 +00:00
|
|
|
|
wa->setUpdatesEnabled(false);
|
2007-11-03 17:37:37 +00:00
|
|
|
|
d.tab_widget_->addTab(wa, toqstr(buffer.fileName().displayName(30)));
|
2007-11-06 08:32:25 +00:00
|
|
|
|
wa->bufferView().updateMetrics();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (d.stack_widget_)
|
|
|
|
|
d.stack_widget_->setCurrentWidget(d.tab_widget_);
|
2007-08-23 08:56:13 +00:00
|
|
|
|
// Hide tabbar if there's only one tab.
|
|
|
|
|
d.tab_widget_->showBar(d.tab_widget_->count() > 1);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
return wa;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
WorkArea * GuiView::currentWorkArea()
|
2007-08-21 07:33:46 +00:00
|
|
|
|
{
|
2007-10-16 06:50:09 +00:00
|
|
|
|
return d.tab_widget_->currentWorkArea();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
WorkArea const * GuiView::currentWorkArea() const
|
2007-08-21 07:33:46 +00:00
|
|
|
|
{
|
2007-10-16 06:50:09 +00:00
|
|
|
|
return d.tab_widget_->currentWorkArea();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::setCurrentWorkArea(WorkArea * work_area)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(work_area);
|
|
|
|
|
|
|
|
|
|
// Changing work area can result from opening a file so
|
|
|
|
|
// update the toc in any case.
|
|
|
|
|
updateToc();
|
|
|
|
|
|
2007-10-16 06:50:09 +00:00
|
|
|
|
GuiWorkArea * wa = static_cast<GuiWorkArea *>(work_area);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BOOST_ASSERT(wa);
|
2007-10-07 08:05:02 +00:00
|
|
|
|
d.tab_widget_->setCurrentWorkArea(wa);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::removeWorkArea(WorkArea * work_area)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(work_area);
|
|
|
|
|
if (work_area == currentWorkArea()) {
|
|
|
|
|
disconnectBuffer();
|
|
|
|
|
disconnectBufferView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// removing a work area often results from closing a file so
|
|
|
|
|
// update the toc in any case.
|
|
|
|
|
updateToc();
|
|
|
|
|
|
2007-10-16 06:50:09 +00:00
|
|
|
|
GuiWorkArea * gwa = static_cast<GuiWorkArea *>(work_area);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BOOST_ASSERT(gwa);
|
2007-10-07 08:05:02 +00:00
|
|
|
|
d.tab_widget_->removeWorkArea(gwa);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
getDialogs().hideBufferDependent();
|
2007-10-07 08:05:02 +00:00
|
|
|
|
|
|
|
|
|
if (d.tab_widget_->count() == 0 && d.stack_widget_)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
// No more work area, switch to the background widget.
|
|
|
|
|
d.setBackground();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::showMiniBuffer(bool visible)
|
2007-08-23 12:21:47 +00:00
|
|
|
|
{
|
2007-10-02 06:59:02 +00:00
|
|
|
|
d.toolbars_->showCommandBuffer(visible);
|
2007-08-23 12:21:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 12:44:21 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::openMenu(docstring const & name)
|
2007-08-23 12:44:21 +00:00
|
|
|
|
{
|
2007-09-28 23:26:59 +00:00
|
|
|
|
d.menubar_->openByName(toqstr(name));
|
2007-08-23 12:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-01 20:45:50 +00:00
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::openLayoutList()
|
2007-10-01 20:45:50 +00:00
|
|
|
|
{
|
|
|
|
|
d.toolbars_->openLayoutList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::updateLayoutChoice()
|
2007-10-01 20:45:50 +00:00
|
|
|
|
{
|
|
|
|
|
// Don't show any layouts without a buffer
|
|
|
|
|
if (!buffer()) {
|
|
|
|
|
d.toolbars_->clearLayoutList();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the layout display
|
|
|
|
|
if (d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr())) {
|
|
|
|
|
d.current_layout = buffer()->params().getTextClass().defaultLayoutName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
docstring const & layout = currentWorkArea()->bufferView().cursor().
|
|
|
|
|
innerParagraph().layout()->name();
|
|
|
|
|
|
|
|
|
|
if (layout != d.current_layout) {
|
|
|
|
|
d.toolbars_->setLayout(layout);
|
|
|
|
|
d.current_layout = layout;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
bool GuiView::isToolbarVisible(std::string const & id)
|
2007-10-01 20:45:50 +00:00
|
|
|
|
{
|
|
|
|
|
return d.toolbars_->visible(id);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::updateToolbars()
|
2007-10-01 20:45:50 +00:00
|
|
|
|
{
|
|
|
|
|
WorkArea * wa = currentWorkArea();
|
|
|
|
|
if (wa) {
|
|
|
|
|
bool const math =
|
|
|
|
|
wa->bufferView().cursor().inMathed();
|
|
|
|
|
bool const table =
|
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
|
|
|
|
|
bool const review =
|
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
|
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true);
|
|
|
|
|
|
|
|
|
|
d.toolbars_->update(math, table, review);
|
|
|
|
|
} else
|
|
|
|
|
d.toolbars_->update(false, false, false);
|
|
|
|
|
|
|
|
|
|
// update read-only status of open dialogs.
|
|
|
|
|
getDialogs().checkStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
ToolbarInfo * GuiView::getToolbarInfo(string const & name)
|
2007-10-01 20:45:50 +00:00
|
|
|
|
{
|
|
|
|
|
return d.toolbars_->getToolbarInfo(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
void GuiView::toggleToolbarState(string const & name, bool allowauto)
|
2007-10-01 20:45:50 +00:00
|
|
|
|
{
|
|
|
|
|
// it is possible to get current toolbar status like this,...
|
|
|
|
|
// but I decide to obey the order of ToolbarBackend::flags
|
|
|
|
|
// and disregard real toolbar status.
|
|
|
|
|
// toolbars_->saveToolbarInfo();
|
|
|
|
|
//
|
|
|
|
|
// toggle state on/off/auto
|
|
|
|
|
d.toolbars_->toggleToolbarState(name, allowauto);
|
|
|
|
|
// update toolbar
|
|
|
|
|
updateToolbars();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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"
|