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-04-27 08:43:38 +00:00
|
|
|
|
#include "QKeySymbol.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"
|
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"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "BufferList.h"
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include "callback.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
#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-08-14 13:14:47 +00:00
|
|
|
|
#include "Session.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>
|
|
|
|
|
#include <QMimeData>
|
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-21 07:33:46 +00:00
|
|
|
|
#include <QTabWidget>
|
2007-08-14 13:14:47 +00:00
|
|
|
|
#include <QUrl>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-07-13 16:37:55 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2006-12-20 21:28:05 +00:00
|
|
|
|
#include <boost/shared_ptr.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 {
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::FileName;
|
2006-04-09 08:42:58 +00:00
|
|
|
|
using support::libFileSearch;
|
2007-02-28 21:48:04 +00:00
|
|
|
|
using support::makeDisplayPath;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
int const statusbar_timer_value = 3000;
|
|
|
|
|
|
2007-08-21 07:33:46 +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);
|
|
|
|
|
font.setPointSize(convert<int>(lyxrc.font_sizes[Font::SIZE_LARGE]));
|
|
|
|
|
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-21 07:33:46 +00:00
|
|
|
|
void paintEvent(QPaintEvent * ev)
|
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-21 07:33:46 +00:00
|
|
|
|
|
2007-02-01 18:48:58 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2006-10-31 14:12:46 +00:00
|
|
|
|
struct GuiView::GuiViewPrivate
|
|
|
|
|
{
|
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-08-21 07:33:46 +00:00
|
|
|
|
QTabWidget * tab_widget_;
|
|
|
|
|
QStackedWidget * stack_widget_;
|
|
|
|
|
BackgroundWidget * bg_widget_;
|
|
|
|
|
|
|
|
|
|
GuiViewPrivate() : posx_offset(0), posy_offset(0)
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{}
|
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;
|
|
|
|
|
|
|
|
|
|
QMenu* toolBarPopup(GuiView *parent)
|
|
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// FIXME: translation
|
2006-11-29 10:04:35 +00:00
|
|
|
|
QMenu* menu = new QMenu(parent);
|
|
|
|
|
QActionGroup *iconSizeGroup = new QActionGroup(parent);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
FileName const file = support::libFileSearch("images", "banner", "png");
|
|
|
|
|
if (file.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bg_widget_ = new BackgroundWidget(toqstr(file.absFilename()), text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2006-11-29 10:04:35 +00:00
|
|
|
|
unsigned int GuiView::GuiViewPrivate::lastIconSize = 0;
|
2006-11-27 23:35:43 +00:00
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
GuiView::GuiView(int id)
|
2006-12-16 10:40:43 +00:00
|
|
|
|
: QMainWindow(), LyXView(id), commandbuffer_(0), quitting_by_menu_(false),
|
|
|
|
|
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
|
|
|
|
|
// assign an icon to main form. We do not do it under Qt/Mac,
|
|
|
|
|
// since the icon is provided in the application bundle.
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const iconname = libFileSearch("images", "lyx", "xpm");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
if (!iconname.empty())
|
2006-11-26 21:30:39 +00:00
|
|
|
|
setWindowIcon(QPixmap(toqstr(iconname.absFilename())));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#endif
|
2007-08-14 13:14:47 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
d.tab_widget_ = new QTabWidget;
|
|
|
|
|
|
|
|
|
|
QPushButton * closeTabButton = new QPushButton(this);
|
|
|
|
|
FileName const file = support::libFileSearch("images", "closetab", "xpm");
|
|
|
|
|
if (!file.empty()) {
|
|
|
|
|
QPixmap pm(toqstr(file.absFilename()));
|
|
|
|
|
closeTabButton->setIcon(QIcon(pm));
|
|
|
|
|
closeTabButton->setMaximumSize(pm.size());
|
|
|
|
|
closeTabButton->setFlat(true);
|
|
|
|
|
} else {
|
|
|
|
|
closeTabButton->setText("Close");
|
|
|
|
|
}
|
|
|
|
|
closeTabButton->setCursor(Qt::ArrowCursor);
|
|
|
|
|
closeTabButton->setToolTip(tr("Close tab"));
|
|
|
|
|
closeTabButton->setEnabled(true);
|
|
|
|
|
|
|
|
|
|
QObject::connect(d.tab_widget_, SIGNAL(currentChanged(int)),
|
|
|
|
|
this, SLOT(currentTabChanged(int)));
|
|
|
|
|
QObject::connect(closeTabButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(closeCurrentTab()));
|
|
|
|
|
|
|
|
|
|
d.tab_widget_->setCornerWidget(closeTabButton);
|
|
|
|
|
#if QT_VERSION >= 0x040200
|
|
|
|
|
d.tab_widget_->setUsesScrollButtons(true);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
d.initBackground();
|
|
|
|
|
if (d.bg_widget_) {
|
|
|
|
|
lyxerr << "stack widget!" << endl;
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
GuiView::~GuiView()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2006-12-03 13:09:57 +00:00
|
|
|
|
menubar_.reset();
|
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
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
void GuiView::close()
|
|
|
|
|
{
|
2006-12-12 01:39:50 +00:00
|
|
|
|
quitting_by_menu_ = true;
|
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
|
|
|
|
|
2006-12-23 17:09:50 +00:00
|
|
|
|
void GuiView::setFocus()
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-08 23:10:46 +00:00
|
|
|
|
QMenu* GuiView::createPopupMenu()
|
|
|
|
|
{
|
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
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
void GuiView::init()
|
|
|
|
|
{
|
|
|
|
|
menubar_.reset(new QLMenubar(this, menubackend));
|
2006-12-30 10:30:02 +00:00
|
|
|
|
QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
|
|
|
|
|
this, SLOT(updateMenu(QAction *)));
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
|
|
getToolbars().init();
|
|
|
|
|
|
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
|
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
|
void GuiView::closeEvent(QCloseEvent * close_event)
|
|
|
|
|
{
|
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-08-14 13:14:47 +00:00
|
|
|
|
void GuiView::dragEnterEvent(QDragEnterEvent * event)
|
|
|
|
|
{
|
|
|
|
|
if (event->mimeData()->hasUrls())
|
|
|
|
|
event->accept();
|
|
|
|
|
/// \todo Ask lyx-devel is this is enough:
|
|
|
|
|
/// if (event->mimeData()->hasFormat("text/plain"))
|
|
|
|
|
/// event->acceptProposedAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::dropEvent(QDropEvent* event)
|
|
|
|
|
{
|
|
|
|
|
QList<QUrl> files = event->mimeData()->urls();
|
|
|
|
|
if (files.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " got URLs!" << endl;
|
|
|
|
|
for (int i = 0; i!=files.size(); ++i) {
|
|
|
|
|
string const file = support::os::internal_path(fromqstr(
|
|
|
|
|
files.at(i).toLocalFile()));
|
|
|
|
|
if (!file.empty())
|
|
|
|
|
dispatch(FuncRequest(LFUN_FILE_OPEN, file));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
void GuiView::saveGeometry()
|
|
|
|
|
{
|
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;
|
|
|
|
|
// 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
|
|
|
|
}
|
2006-11-02 16:01:36 +00:00
|
|
|
|
getToolbars().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
|
|
|
|
|
2006-09-29 23:10:17 +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
|
|
|
|
|
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
|
|
|
|
{
|
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));
|
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-12-03 13:17:35 +00:00
|
|
|
|
|
2006-11-29 10:04:35 +00:00
|
|
|
|
void GuiView::setIconSize(unsigned int size)
|
|
|
|
|
{
|
|
|
|
|
d.lastIconSize = size;
|
|
|
|
|
QMainWindow::setIconSize(QSize(size, size));
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2006-11-29 10:04:35 +00:00
|
|
|
|
void GuiView::smallSizedIcons()
|
|
|
|
|
{
|
|
|
|
|
setIconSize(d.smallIconSize);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2006-11-29 10:04:35 +00:00
|
|
|
|
void GuiView::normalSizedIcons()
|
|
|
|
|
{
|
|
|
|
|
setIconSize(d.normalIconSize);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2006-11-29 10:04:35 +00:00
|
|
|
|
void GuiView::bigSizedIcons()
|
|
|
|
|
{
|
|
|
|
|
setIconSize(d.bigIconSize);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
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-06-11 14:53:36 +00:00
|
|
|
|
void GuiView::closeCurrentTab()
|
|
|
|
|
{
|
|
|
|
|
dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
|
2006-10-31 14:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2007-02-04 21:19:20 +00:00
|
|
|
|
void GuiView::currentTabChanged(int i)
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
disconnectBuffer();
|
|
|
|
|
disconnectBufferView();
|
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(d.tab_widget_->widget(i));
|
|
|
|
|
BOOST_ASSERT(wa);
|
|
|
|
|
BufferView & bv = wa->bufferView();
|
|
|
|
|
connectBufferView(bv);
|
2007-08-21 13:03:55 +00:00
|
|
|
|
connectBuffer(bv.buffer());
|
2007-08-21 07:33:46 +00:00
|
|
|
|
bv.updateMetrics(false);
|
|
|
|
|
bv.cursor().fixIfBroken();
|
|
|
|
|
wa->setUpdatesEnabled(true);
|
|
|
|
|
wa->redraw();
|
|
|
|
|
wa->setFocus();
|
|
|
|
|
|
|
|
|
|
updateToc();
|
|
|
|
|
// Buffer-dependent dialogs should be updated or
|
|
|
|
|
// hidden. This should go here because some dialogs (eg ToC)
|
|
|
|
|
// require bv_->text.
|
|
|
|
|
getDialogs().updateBufferDependent(true);
|
|
|
|
|
updateMenubar();
|
|
|
|
|
updateToolbars();
|
|
|
|
|
updateLayoutChoice();
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
updateStatusBar();
|
|
|
|
|
|
|
|
|
|
lyxerr << "currentTabChanged " << i
|
2007-08-21 13:03:55 +00:00
|
|
|
|
<< "File" << bv.buffer().fileName() << endl;
|
2006-10-31 14:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
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
|
|
|
|
|
2007-03-17 12:28:26 +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
|
|
|
|
|
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-12-20 21:28:05 +00:00
|
|
|
|
bool GuiView::event(QEvent * e)
|
|
|
|
|
{
|
|
|
|
|
switch (e->type())
|
|
|
|
|
{
|
2007-08-15 08:29:10 +00:00
|
|
|
|
// Useful debug code:
|
|
|
|
|
//case QEvent::WindowActivate:
|
|
|
|
|
//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;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
boost::shared_ptr<QKeySymbol> sym(new QKeySymbol);
|
|
|
|
|
sym->set(ke);
|
|
|
|
|
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-04-27 08:43:38 +00:00
|
|
|
|
boost::shared_ptr<QKeySymbol> sym(new QKeySymbol);
|
2006-12-20 21:28:05 +00:00
|
|
|
|
sym->set(ke);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
currentWorkArea()->processKeySym(sym, key_modifier::none);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-22 16:13:19 +00:00
|
|
|
|
bool GuiView::focusNextPrevChild(bool /*next*/)
|
|
|
|
|
{
|
2006-12-23 17:09:50 +00:00
|
|
|
|
setFocus();
|
2006-12-22 16:13:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (d.tab_widget_->count()) {
|
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(d.tab_widget_->currentWidget());
|
|
|
|
|
BOOST_ASSERT(wa);
|
|
|
|
|
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-04-21 17:38:43 +00:00
|
|
|
|
Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
|
2006-09-10 11:03:21 +00:00
|
|
|
|
{
|
2007-04-21 17:38:43 +00:00
|
|
|
|
QLToolbar * Tb = new QLToolbar(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-01-27 20:54:17 +00:00
|
|
|
|
addToolBar(Qt::TopToolBarArea, Tb);
|
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-01-31 02:39:46 +00:00
|
|
|
|
addToolBar(Qt::BottomToolBarArea, Tb);
|
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-01-31 02:39:46 +00:00
|
|
|
|
addToolBar(Qt::LeftToolBarArea, Tb);
|
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-01-31 02:39:46 +00:00
|
|
|
|
addToolBar(Qt::RightToolBarArea, Tb);
|
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);
|
|
|
|
|
Tb->move(tbinfo.posx, tbinfo.posy);
|
2007-01-27 20:54:17 +00:00
|
|
|
|
*/
|
2007-01-29 14:23:05 +00:00
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
return Toolbars::ToolbarPtr(Tb);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
|
|
WorkArea * GuiView::workArea(Buffer & buffer)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i != d.tab_widget_->count(); ++i) {
|
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(d.tab_widget_->widget(i));
|
|
|
|
|
BOOST_ASSERT(wa);
|
2007-08-21 13:03:55 +00:00
|
|
|
|
if (&wa->bufferView().buffer() == &buffer)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
return wa;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorkArea * GuiView::addWorkArea(Buffer & buffer)
|
|
|
|
|
{
|
|
|
|
|
GuiWorkArea * wa = new GuiWorkArea(buffer, *this);
|
|
|
|
|
d.tab_widget_->addTab(wa, toqstr(makeDisplayPath(buffer.fileName(), 30)));
|
|
|
|
|
wa->bufferView().updateMetrics(false);
|
|
|
|
|
if (d.stack_widget_)
|
|
|
|
|
d.stack_widget_->setCurrentWidget(d.tab_widget_);
|
|
|
|
|
return wa;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorkArea * GuiView::currentWorkArea()
|
|
|
|
|
{
|
|
|
|
|
if (d.tab_widget_->count() == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
BOOST_ASSERT(dynamic_cast<GuiWorkArea *>(d.tab_widget_->currentWidget()));
|
|
|
|
|
return dynamic_cast<GuiWorkArea *>(d.tab_widget_->currentWidget());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorkArea const * GuiView::currentWorkArea() const
|
|
|
|
|
{
|
|
|
|
|
if (d.tab_widget_->count() == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
BOOST_ASSERT(dynamic_cast<GuiWorkArea const *>(d.tab_widget_->currentWidget()));
|
|
|
|
|
return dynamic_cast<GuiWorkArea const *>(d.tab_widget_->currentWidget());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::setCurrentWorkArea(WorkArea * work_area)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(work_area);
|
|
|
|
|
|
|
|
|
|
// Changing work area can result from opening a file so
|
|
|
|
|
// update the toc in any case.
|
|
|
|
|
updateToc();
|
|
|
|
|
|
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(work_area);
|
|
|
|
|
BOOST_ASSERT(wa);
|
2007-08-22 08:48:01 +00:00
|
|
|
|
if (wa != d.tab_widget_->currentWidget())
|
|
|
|
|
// Switch to the work area.
|
|
|
|
|
d.tab_widget_->setCurrentWidget(wa);
|
|
|
|
|
else
|
|
|
|
|
// Make sure the work area is up to date.
|
|
|
|
|
currentTabChanged(d.tab_widget_->currentIndex());
|
2007-08-21 07:33:46 +00:00
|
|
|
|
wa->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::removeWorkArea(WorkArea * work_area)
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
GuiWorkArea * gwa = dynamic_cast<GuiWorkArea *>(work_area);
|
|
|
|
|
BOOST_ASSERT(gwa);
|
|
|
|
|
int index = d.tab_widget_->indexOf(gwa);
|
|
|
|
|
d.tab_widget_->removeTab(index);
|
|
|
|
|
|
|
|
|
|
delete gwa;
|
|
|
|
|
|
|
|
|
|
if (d.tab_widget_->count()) {
|
|
|
|
|
// make sure the next work area is enabled.
|
|
|
|
|
d.tab_widget_->currentWidget()->setUpdatesEnabled(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDialogs().hideBufferDependent();
|
|
|
|
|
if (d.stack_widget_) {
|
|
|
|
|
// No more work area, switch to the background widget.
|
|
|
|
|
d.setBackground();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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"
|