// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
SyntheticMouseEvent::SyntheticMouseEvent()
: timeout(200), restart_timeout(true),
- x_old(-1), y_old(-1), min_scrollbar_old(-1.0), max_scrollbar_old(-1.0)
+ x_old(-1), y_old(-1), min_scrollbar_old(-1), max_scrollbar_old(-1)
{}
: buffer_view_(0), lyx_view_(0),
cursor_visible_(false),
need_resize_(false), schedule_redraw_(false),
- preedit_lines_(1), completer_(new GuiCompleter(this))
+ preedit_lines_(1), completer_(new GuiCompleter(this)),
+ context_target_pos_()
{
}
: buffer_view_(0), lyx_view_(0),
cursor_visible_(false),
need_resize_(false), schedule_redraw_(false),
- preedit_lines_(1), completer_(new GuiCompleter(this))
+ preedit_lines_(1), completer_(new GuiCompleter(this)),
+ context_target_pos_()
{
setGuiView(gv);
setBuffer(buffer);
void GuiWorkArea::setFullScreen(bool full_screen)
{
buffer_view_->setFullScreen(full_screen);
+ setFrameStyle(QFrame::NoFrame);
if (full_screen) {
setFrameStyle(QFrame::NoFrame);
if (lyxrc.full_screen_scrollbar)
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- } else {
-#ifdef Q_WS_MACX
- setFrameStyle(QFrame::NoFrame);
-#else
- setFrameStyle(QFrame::Box);
-#endif
+ } else
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- }
}
void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
{
- if (lyx_view_->isFullScreen() && lyx_view_->menuBar()->isVisible()) {
+ if (lyx_view_->isFullScreen() && lyx_view_->menuBar()->isVisible()
+ && lyxrc.full_screen_menubar) {
// FIXME HACK: we should not have to do this here. See related comment
// in GuiView::event() (QEvent::ShortcutOverride)
lyx_view_->menuBar()->hide();
void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
{
- QPoint pos = e->pos();
+ QPoint pos;
+ if (e->reason() == QContextMenuEvent::Mouse)
+ // the position is set on mouse press
+ pos = context_target_pos_;
+ else
+ pos = e->pos();
+ Cursor const & cur = buffer_view_->cursor();
+ if (e->reason() == QContextMenuEvent::Keyboard && cur.inTexted()) {
+ // Do not access the context menu of math right in front of before
+ // the cursor. This does not work when the cursor is in text.
+ Inset * inset = cur.paragraph().getInset(cur.pos());
+ if (inset && inset->asInsetMath())
+ --pos.rx();
+ else if (cur.pos() > 0) {
+ Inset * inset = cur.paragraph().getInset(cur.pos() - 1);
+ if (inset)
+ ++pos.rx();
+ }
+ }
docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
if (name.empty()) {
QAbstractScrollArea::contextMenuEvent(e);
return;
}
+ if (e->button() == Qt::RightButton)
+ context_target_pos_ = e->pos();
+
inputContext()->reset();
FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
KeySymbol sym;
setKeySymbol(&sym, ev);
- processKeySym(sym, q_key_state(ev->modifiers()));
- ev->accept();
+ if (sym.isOK()) {
+ processKeySym(sym, q_key_state(ev->modifiers()));
+ ev->accept();
+ } else {
+ ev->ignore();
+ }
}
{
QRect cur_r(0, 0, 0, 0);
switch (query) {
- // this is the CJK-specific composition window position.
+ // this is the CJK-specific composition window position and
+ // the context menu position when the menu key is pressed.
case Qt::ImMicroFocus:
cur_r = cursor_->rect();
if (preedit_lines_ != 1)
cur_r.moveLeft(10);
- cur_r.moveBottom(cur_r.bottom() + cur_r.height() * preedit_lines_);
+ cur_r.moveBottom(cur_r.bottom()
+ + cur_r.height() * (preedit_lines_ - 1));
// return lower right of cursor in LyX.
return cur_r;
default:
QObject::connect(this, SIGNAL(currentChanged(int)),
this, SLOT(on_currentTabChanged(int)));
+#if QT_VERSION < 0x040500
closeBufferButton = new QToolButton(this);
closeBufferButton->setPalette(pal);
// FIXME: rename the icon to closebuffer.png
QObject::connect(closeBufferButton, SIGNAL(clicked()),
this, SLOT(closeCurrentBuffer()));
setCornerWidget(closeBufferButton, Qt::TopRightCorner);
+#endif
// setup drag'n'drop
QTabBar* tb = new DragTabBar;
tb->setContextMenuPolicy(Qt::CustomContextMenu);
connect(tb, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
+#if QT_VERSION >= 0x040500
+ connect(tb, SIGNAL(tabCloseRequested(int)),
+ tb, SLOT(on_tabCloseRequested(int)));
+#endif
setUsesScrollButtons(true);
}
}
if (lyxrc.full_screen_tabbar)
- showBar(!full_screen && count()>1);
+ showBar(!full_screen && count() > 1);
}
{
tabBar()->setEnabled(show);
tabBar()->setVisible(show);
+#if QT_VERSION < 0x040500
closeBufferButton->setVisible(show);
+#endif
}
if (currentWorkArea() && currentWorkArea()->isFullScreen())
setFullScreen(true);
else
- // Hide tabbar if there's only one tab.
+ // Show tabbar only if there's more than one tab.
showBar(count() > 1);
- } else {
+ } else
lastWorkAreaRemoved();
- }
updateTabTexts();
void TabWorkArea::closeCurrentBuffer()
{
- if (clicked_tab_ != -1)
- setCurrentIndex(clicked_tab_);
- else
- // Before dispatching the LFUN we should be sure this
- // is the current workarea.
- currentWorkAreaChanged(currentWorkArea());
-
- lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
+ GuiWorkArea * wa;
+ if (clicked_tab_ == -1)
+ wa = currentWorkArea();
+ else {
+ wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+ LASSERT(wa, /**/);
+ }
+ wa->view().closeWorkArea(wa);
}
void TabWorkArea::closeCurrentTab()
{
+ GuiWorkArea * wa;
if (clicked_tab_ == -1)
- removeWorkArea(currentWorkArea());
+ wa = currentWorkArea();
else {
- GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+ wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
LASSERT(wa, /**/);
- removeWorkArea(wa);
}
+ wa->view().hideWorkArea(wa);
}
///
DisplayPath(int tab, FileName const & filename)
: tab_(tab)
{
- filename_ = toqstr(filename.onlyFileNameWithoutExt());
+ filename_ = (filename.extension() == "lyx") ?
+ toqstr(filename.onlyFileNameWithoutExt())
+ : toqstr(filename.onlyFileName());
postfix_ = toqstr(filename.absoluteFilePath()).
split("/", QString::SkipEmptyParts);
postfix_.pop_back();
: QTabBar(parent)
{
setAcceptDrops(true);
+#if QT_VERSION >= 0x040500
+ setTabsClosable(true);
+#endif
+}
+
+
+void DragTabBar::on_tabCloseRequested(int index)
+{
+ setCurrentIndex(index);
+ lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
}