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
|
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"
|
2006-12-20 21:28:05 +00:00
|
|
|
|
#include "QLyXKeySym.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QLMenubar.h"
|
2006-09-10 11:03:21 +00:00
|
|
|
|
#include "QLToolbar.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QCommandBuffer.h"
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
2006-10-24 15:01:07 +00:00
|
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
#include "frontends/Gui.h"
|
|
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/convert.h"
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "bufferlist.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "lyx_cb.h"
|
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyx_main.h"
|
|
|
|
|
#include "session.h"
|
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
#include "MenuBackend.h"
|
2006-10-31 14:12:46 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferlist.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>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QToolBar>
|
2006-10-31 14:46:38 +00:00
|
|
|
|
#include <QTabBar>
|
2006-10-27 11:47:59 +00:00
|
|
|
|
#include <QDesktopWidget>
|
2006-10-31 14:57:25 +00:00
|
|
|
|
#include <QVBoxLayout>
|
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;
|
|
|
|
|
using support::onlyFilename;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2007-02-01 18:48:58 +00:00
|
|
|
|
class TabWidget : public QWidget
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QTabBar* tabbar;
|
2007-02-01 18:48:58 +00:00
|
|
|
|
|
|
|
|
|
TabWidget(QWidget* w, bool topTabBar)
|
2006-10-31 14:12:46 +00:00
|
|
|
|
{
|
|
|
|
|
tabbar = new QTabBar;
|
2007-02-01 18:48:58 +00:00
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout;
|
|
|
|
|
if (topTabBar) {
|
|
|
|
|
layout->addWidget(tabbar);
|
|
|
|
|
layout->addWidget(w);
|
|
|
|
|
} else {
|
|
|
|
|
tabbar->setShape(QTabBar::RoundedSouth);
|
|
|
|
|
layout->addWidget(w);
|
|
|
|
|
layout->addWidget(tabbar);
|
|
|
|
|
}
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
setLayout(layout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearTabbar()
|
|
|
|
|
{
|
|
|
|
|
for (int i = tabbar->count() - 1; i >= 0; --i)
|
|
|
|
|
tabbar->removeTab(i);
|
2006-10-31 14:12: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-04 21:19:20 +00:00
|
|
|
|
std::vector<std::string> tabnames;
|
2007-02-01 18:48:58 +00:00
|
|
|
|
|
|
|
|
|
TabWidget* tabWidget;
|
2006-10-31 14:12:46 +00:00
|
|
|
|
|
2006-11-09 09:13:04 +00:00
|
|
|
|
int posx_offset;
|
|
|
|
|
int posy_offset;
|
|
|
|
|
|
2007-02-01 18:48:58 +00:00
|
|
|
|
GuiViewPrivate() : tabWidget(0), 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)
|
|
|
|
|
{
|
2006-11-29 10:25:46 +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;
|
|
|
|
|
}
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-01-02 10:36:34 +00:00
|
|
|
|
BOOST_ASSERT(work_area_);
|
2006-12-23 17:09:50 +00:00
|
|
|
|
static_cast<GuiWorkArea *>(work_area_)->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-01-02 10:36:34 +00:00
|
|
|
|
BOOST_ASSERT(work_area_);
|
2006-11-01 22:57:32 +00:00
|
|
|
|
if (!work_area_->bufferView().buffer() && !theBufferList().empty())
|
|
|
|
|
setBuffer(theBufferList().first());
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
// make sure the buttons are disabled if needed
|
|
|
|
|
updateToolbars();
|
2006-09-29 23:10:17 +00:00
|
|
|
|
updateLayoutChoice();
|
|
|
|
|
updateMenubar();
|
|
|
|
|
}
|
|
|
|
|
|
2006-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
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-12 01:39:50 +00:00
|
|
|
|
if (view()->buffer()) {
|
|
|
|
|
// save cursor position for opened files to .lyx/session
|
|
|
|
|
LyX::ref().session().lastFilePos().save(
|
|
|
|
|
FileName(buffer()->fileName()),
|
|
|
|
|
boost::tie(view()->cursor().pit(),
|
|
|
|
|
view()->cursor().pos()));
|
|
|
|
|
}
|
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
|
|
|
|
|
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()
|
2006-11-09 09:13:04 +00:00
|
|
|
|
#ifdef Q_WS_WIN
|
2006-10-23 16:29:24 +00:00
|
|
|
|
QRect geometry = normalGeometry();
|
|
|
|
|
#else
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
QRect geometry = floatingGeometry_;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// save windows size and position
|
|
|
|
|
Session & session = LyX::ref().session();
|
2006-10-29 20:01:00 +00:00
|
|
|
|
session.sessionInfo().save("WindowWidth", convert<string>(geometry.width()));
|
|
|
|
|
session.sessionInfo().save("WindowHeight", convert<string>(geometry.height()));
|
|
|
|
|
session.sessionInfo().save("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
|
2006-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) {
|
2006-11-09 09:13:04 +00:00
|
|
|
|
session.sessionInfo().save("WindowPosX", convert<string>(geometry.x() + d.posx_offset));
|
|
|
|
|
session.sessionInfo().save("WindowPosY", convert<string>(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
|
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
|
|
bool maximize,
|
|
|
|
|
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) {
|
2006-10-27 08:40:08 +00:00
|
|
|
|
// if there are ever startup positioning problems
|
|
|
|
|
// on a virtual desktop then check the 6 lines below
|
|
|
|
|
// http://doc.trolltech.com/4.2/qdesktopwidget.html
|
|
|
|
|
QDesktopWidget& dw = *qApp->desktop();
|
|
|
|
|
QRect desk = dw.availableGeometry(dw.primaryScreen());
|
2006-10-28 17:14:51 +00:00
|
|
|
|
(posx >= desk.width() ? posx = 50 : true);
|
|
|
|
|
(posy >= desk.height()? posy = 50 : true);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maximize)
|
|
|
|
|
setWindowState(Qt::WindowMaximized);
|
|
|
|
|
}
|
2006-11-29 16:45:38 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// FIXME: move this code into parse_geometry() (lyx_main.C)
|
|
|
|
|
#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
|
|
|
|
|
}
|
2006-11-09 09:13:04 +00:00
|
|
|
|
|
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;
|
|
|
|
|
if (width != 0 && height != 0)
|
|
|
|
|
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
|
2006-11-09 09:13:04 +00:00
|
|
|
|
if (!maximize) {
|
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
|
|
2006-10-31 14:12:46 +00:00
|
|
|
|
void GuiView::initTab(QWidget* workarea)
|
|
|
|
|
{
|
2007-02-01 18:48:58 +00:00
|
|
|
|
// construct the TabWidget with 'false' to have the tabbar at the bottom
|
|
|
|
|
d.tabWidget = new TabWidget(workarea, true);
|
|
|
|
|
setCentralWidget(d.tabWidget);
|
|
|
|
|
QObject::connect(d.tabWidget->tabbar, SIGNAL(currentChanged(int)),
|
2006-12-30 10:30:02 +00:00
|
|
|
|
this, SLOT(currentTabChanged(int)));
|
2006-10-31 14:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
|
2006-10-31 14:12:46 +00:00
|
|
|
|
void GuiView::updateTab()
|
|
|
|
|
{
|
2007-02-04 21:19:20 +00:00
|
|
|
|
std::vector<string> const & names = theBufferList().getFileNames();
|
2006-10-31 14:12:46 +00:00
|
|
|
|
|
2007-02-01 18:48:58 +00:00
|
|
|
|
// avoid unnecessary tabbar rebuild:
|
|
|
|
|
// check if something has changed
|
2007-02-04 21:19:20 +00:00
|
|
|
|
if (d.tabnames == names)
|
2007-02-01 18:48:58 +00:00
|
|
|
|
return;
|
2007-02-04 21:19:20 +00:00
|
|
|
|
d.tabnames = names;
|
2006-10-31 14:12:46 +00:00
|
|
|
|
|
2007-02-04 21:19:20 +00:00
|
|
|
|
QTabBar & tabbar = *d.tabWidget->tabbar;
|
2006-10-31 14:12:46 +00:00
|
|
|
|
|
2007-02-04 21:19:20 +00:00
|
|
|
|
// update when all is done
|
2007-02-01 18:48:58 +00:00
|
|
|
|
tabbar.blockSignals(true);
|
2006-10-31 14:12:46 +00:00
|
|
|
|
|
2007-02-04 21:19:20 +00:00
|
|
|
|
// remove all tab bars
|
2007-02-01 18:48:58 +00:00
|
|
|
|
d.tabWidget->clearTabbar();
|
2006-10-31 14:12:46 +00:00
|
|
|
|
|
2007-02-01 18:48:58 +00:00
|
|
|
|
string cur_title;
|
|
|
|
|
if (view()->buffer()) {
|
|
|
|
|
cur_title = view()->buffer()->fileName();
|
2006-10-31 14:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-01 18:48:58 +00:00
|
|
|
|
// rebuild tabbar and function map from scratch
|
2007-02-04 21:19:20 +00:00
|
|
|
|
if (names.size() > 1) {
|
2007-02-01 18:48:58 +00:00
|
|
|
|
for(size_t i = 0; i < names.size(); i++) {
|
2007-02-04 21:19:20 +00:00
|
|
|
|
tabbar.addTab(toqstr(onlyFilename(names[i])));
|
2007-02-01 18:48:58 +00:00
|
|
|
|
// set current tab
|
2007-02-04 21:19:20 +00:00
|
|
|
|
if (names[i] == cur_title)
|
2007-02-01 18:48:58 +00:00
|
|
|
|
tabbar.setCurrentIndex(i);
|
2006-10-31 14:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-02-01 18:48:58 +00:00
|
|
|
|
tabbar.blockSignals(false);
|
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-02-04 21:19:20 +00:00
|
|
|
|
BOOST_ASSERT(i >= 0 && size_type(i) < d.tabnames.size());
|
|
|
|
|
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, d.tabnames[i]));
|
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
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
|
void GuiView::updateFloatingGeometry()
|
2006-06-21 10:30:32 +00:00
|
|
|
|
{
|
2006-06-23 10:19:31 +00:00
|
|
|
|
if (!isMaximized())
|
|
|
|
|
floatingGeometry_ = QRect(x(), y(), width(), height());
|
2006-06-21 10:30:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2006-06-21 10:30:32 +00:00
|
|
|
|
void GuiView::resizeEvent(QResizeEvent *)
|
|
|
|
|
{
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-23 10:19:31 +00:00
|
|
|
|
|
2006-06-21 10:30:32 +00:00
|
|
|
|
void GuiView::moveEvent(QMoveEvent *)
|
|
|
|
|
{
|
|
|
|
|
updateFloatingGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-12-20 21:28:05 +00:00
|
|
|
|
bool GuiView::event(QEvent * e)
|
|
|
|
|
{
|
|
|
|
|
// Useful debug code:
|
|
|
|
|
/*
|
|
|
|
|
switch (e->type())
|
|
|
|
|
{
|
|
|
|
|
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:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (e->type() == QEvent::ShortcutOverride) {
|
|
|
|
|
QKeyEvent * ke = static_cast<QKeyEvent*>(e);
|
2006-12-22 16:13:19 +00:00
|
|
|
|
if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
|
2006-12-20 21:28:05 +00:00
|
|
|
|
boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
|
|
|
|
|
sym->set(ke);
|
2007-01-02 10:36:34 +00:00
|
|
|
|
BOOST_ASSERT(work_area_);
|
2006-12-20 21:28:05 +00:00
|
|
|
|
work_area_->processKeySym(sym, key_modifier::none);
|
|
|
|
|
e->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//} for the debug switch above.
|
|
|
|
|
|
|
|
|
|
return QMainWindow::event(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-01-02 10:36:34 +00:00
|
|
|
|
BOOST_ASSERT(work_area_);
|
2006-10-26 13:29:10 +00:00
|
|
|
|
static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
|
|
|
|
|
|
|
|
|
|
if (yes) {
|
|
|
|
|
work_area_->stopBlinkingCursor();
|
2006-06-04 20:49:09 +00:00
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2006-10-26 13:29:10 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
work_area_->startBlinkingCursor();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
QApplication::restoreOverrideCursor();
|
2006-10-26 13:29:10 +00:00
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
|
2007-01-31 02:39:46 +00:00
|
|
|
|
Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb, bool newline)
|
2006-09-10 11:03:21 +00:00
|
|
|
|
{
|
|
|
|
|
QLToolbar * Tb = new QLToolbar(tbb, *this);
|
|
|
|
|
|
|
|
|
|
if (tbb.flags & ToolbarBackend::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
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
if (tbb.flags & ToolbarBackend::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
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
if (tbb.flags & ToolbarBackend::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
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
if (tbb.flags & ToolbarBackend::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-01-31 02:39:46 +00:00
|
|
|
|
// The following does not work so I can not restore to exact toolbar location
|
2007-01-27 20:54:17 +00:00
|
|
|
|
/*
|
|
|
|
|
ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbb.name);
|
|
|
|
|
Tb->move(info.posx, info.posy);
|
|
|
|
|
*/
|
2007-01-29 14:23:05 +00:00
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
return Toolbars::ToolbarPtr(Tb);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
#include "GuiView_moc.cpp"
|