2006-03-05 17:24:44 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2006-06-20 08:39:16 +00:00
|
|
|
* \file GuiWorkArea.h
|
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.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
#ifndef WORKAREA_H
|
|
|
|
#define WORKAREA_H
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
#include "DocIterator.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2008-02-21 19:42:34 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "support/docstring.h"
|
2007-08-11 22:37:09 +00:00
|
|
|
#include "support/Timeout.h"
|
2006-03-20 17:25:02 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QAbstractScrollArea>
|
|
|
|
#include <QMouseEvent>
|
2007-10-06 15:48:58 +00:00
|
|
|
#include <QPixmap>
|
2008-03-15 02:13:01 +00:00
|
|
|
#include <QTabBar>
|
2007-10-06 15:48:58 +00:00
|
|
|
#include <QTabWidget>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QTimer>
|
|
|
|
|
2007-12-25 20:12:07 +00:00
|
|
|
class QContextMenuEvent;
|
2006-03-05 17:24:44 +00:00
|
|
|
class QDragEnterEvent;
|
|
|
|
class QDropEvent;
|
2007-11-21 20:32:17 +00:00
|
|
|
class QKeyEvent;
|
2006-10-22 17:58:09 +00:00
|
|
|
class QPaintEvent;
|
2011-02-13 10:03:05 +00:00
|
|
|
class QResizeEvent;
|
2009-03-08 10:21:33 +00:00
|
|
|
class QToolButton;
|
2011-02-13 10:03:05 +00:00
|
|
|
class QWheelEvent;
|
2007-12-25 20:12:07 +00:00
|
|
|
class QWidget;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-08 19:36:15 +00:00
|
|
|
#ifdef CursorShape
|
|
|
|
#undef CursorShape
|
|
|
|
#endif
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace lyx {
|
2007-11-12 22:15:51 +00:00
|
|
|
|
|
|
|
class Buffer;
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2008-04-21 19:12:15 +00:00
|
|
|
class GuiCompleter;
|
2007-11-13 09:52:28 +00:00
|
|
|
class GuiView;
|
2008-02-21 19:42:34 +00:00
|
|
|
class GuiWorkArea;
|
2007-11-12 22:15:51 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// for emulating triple click
|
2007-11-12 22:15:51 +00:00
|
|
|
class DoubleClick {
|
2006-03-05 17:24:44 +00:00
|
|
|
public:
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
|
|
|
DoubleClick() : state(Qt::NoButton), active(false) {}
|
|
|
|
///
|
|
|
|
DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
|
|
|
|
///
|
|
|
|
bool operator==(QMouseEvent const & e) { return state == e.button(); }
|
|
|
|
///
|
|
|
|
public:
|
|
|
|
///
|
2006-08-13 15:55:03 +00:00
|
|
|
Qt::MouseButton state;
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
2006-03-05 17:24:44 +00:00
|
|
|
bool active;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Qt only emits mouse events when the mouse is being moved, but
|
|
|
|
* we want to generate 'pseudo' mouse events when the mouse button is
|
|
|
|
* pressed and the mouse cursor is below the bottom, or above the top
|
|
|
|
* of the work area. In this way, we'll be able to continue scrolling
|
|
|
|
* (and selecting) the text.
|
|
|
|
*
|
|
|
|
* This class stores all the parameters needed to make this happen.
|
|
|
|
*/
|
|
|
|
class SyntheticMouseEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SyntheticMouseEvent();
|
|
|
|
|
|
|
|
FuncRequest cmd;
|
|
|
|
Timeout timeout;
|
|
|
|
bool restart_timeout;
|
|
|
|
};
|
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-11-12 22:15:51 +00:00
|
|
|
* Implementation of the work area (buffer view GUI)
|
2006-03-12 17:29:34 +00:00
|
|
|
*/
|
2007-11-12 22:15:51 +00:00
|
|
|
class CursorWidget;
|
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
class GuiWorkArea : public QAbstractScrollArea, public WorkArea
|
2006-08-17 17:15:17 +00:00
|
|
|
{
|
2006-03-05 17:24:44 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2006-10-22 17:58:09 +00:00
|
|
|
///
|
2008-11-15 22:34:52 +00:00
|
|
|
GuiWorkArea(QWidget *);
|
|
|
|
///
|
|
|
|
GuiWorkArea(Buffer & buffer, GuiView & gv);
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
|
|
|
~GuiWorkArea();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-11-22 14:45:47 +00:00
|
|
|
///
|
|
|
|
void init();
|
2008-11-15 22:34:52 +00:00
|
|
|
///
|
|
|
|
void setBuffer(Buffer &);
|
|
|
|
///
|
|
|
|
void setGuiView(GuiView &);
|
2008-02-09 18:03:53 +00:00
|
|
|
///
|
|
|
|
void setFullScreen(bool full_screen);
|
2010-02-09 17:06:40 +00:00
|
|
|
/// is GuiView in fullscreen mode?
|
2008-02-27 21:04:33 +00:00
|
|
|
bool isFullScreen();
|
2006-11-04 07:29:25 +00:00
|
|
|
///
|
2007-11-13 09:52:28 +00:00
|
|
|
void scheduleRedraw() { schedule_redraw_ = true; }
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
|
|
|
BufferView & bufferView();
|
|
|
|
///
|
|
|
|
BufferView const & bufferView() const;
|
|
|
|
///
|
2010-01-08 02:03:54 +00:00
|
|
|
void redraw(bool update_metrics);
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
|
|
|
void stopBlinkingCursor();
|
|
|
|
///
|
|
|
|
void startBlinkingCursor();
|
2007-11-13 09:52:28 +00:00
|
|
|
/// Process Key pressed event.
|
|
|
|
/// This needs to be public because it is accessed externally by GuiView.
|
2007-11-12 22:15:51 +00:00
|
|
|
void processKeySym(KeySymbol const & key, KeyModifier mod);
|
2007-11-19 10:04:14 +00:00
|
|
|
///
|
|
|
|
void resizeBufferView();
|
2006-03-20 17:25:02 +00:00
|
|
|
|
2008-11-16 13:48:30 +00:00
|
|
|
bool inDialogMode() const { return dialog_mode_; }
|
2008-11-15 22:58:19 +00:00
|
|
|
void setDialogMode(bool mode) { dialog_mode_ = mode; }
|
2008-11-15 22:34:52 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
2008-04-21 19:12:15 +00:00
|
|
|
GuiCompleter & completer() { return *completer_; }
|
2008-11-15 22:34:52 +00:00
|
|
|
|
2010-10-23 10:49:45 +00:00
|
|
|
Qt::CursorShape cursorShape() const;
|
|
|
|
void setCursorShape(Qt::CursorShape shape);
|
|
|
|
|
2010-10-24 22:14:31 +00:00
|
|
|
/// Change the cursor when the mouse hovers over a clickable inset
|
|
|
|
void updateCursorShape();
|
2008-11-15 22:34:52 +00:00
|
|
|
|
|
|
|
/// Return the GuiView this workArea belongs to
|
|
|
|
GuiView const & view() const { return *lyx_view_; }
|
|
|
|
GuiView & view() { return *lyx_view_; }
|
|
|
|
|
2007-11-14 17:39:16 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
///
|
|
|
|
void titleChanged(GuiWorkArea *);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2008-01-29 12:54:23 +00:00
|
|
|
/// Scroll the BufferView.
|
2007-11-12 22:15:51 +00:00
|
|
|
/**
|
2008-01-29 12:54:23 +00:00
|
|
|
* This is a slot for the valueChanged() signal of the vertical scrollbar.
|
|
|
|
* \p value value of the scrollbar.
|
2007-11-12 22:15:51 +00:00
|
|
|
*/
|
2008-01-29 12:54:23 +00:00
|
|
|
void scrollTo(int value);
|
2007-11-12 22:15:51 +00:00
|
|
|
/// timer to limit triple clicks
|
|
|
|
void doubleClickTimeout();
|
2007-11-21 21:15:23 +00:00
|
|
|
/// toggle the cursor's visibility
|
|
|
|
void toggleCursor();
|
2007-11-12 22:15:51 +00:00
|
|
|
/// close this work area.
|
|
|
|
/// Slot for Buffer::closing signal.
|
|
|
|
void close();
|
2008-04-06 11:52:11 +00:00
|
|
|
/// Slot to restore proper scrollbar behaviour.
|
|
|
|
void fixVerticalScrollBar();
|
2007-11-11 22:30:21 +00:00
|
|
|
|
2007-11-14 17:39:16 +00:00
|
|
|
private:
|
2008-02-21 19:42:34 +00:00
|
|
|
friend class GuiCompleter;
|
|
|
|
|
2007-11-14 17:39:16 +00:00
|
|
|
/// update the passed area.
|
|
|
|
void update(int x, int y, int w, int h);
|
2007-11-11 22:30:21 +00:00
|
|
|
///
|
2007-11-14 17:39:16 +00:00
|
|
|
void updateScreen();
|
|
|
|
|
|
|
|
/// paint the cursor and store the background
|
2008-02-28 12:41:43 +00:00
|
|
|
virtual void showCursor(int x, int y, int h,
|
|
|
|
bool l_shape, bool rtl, bool completable);
|
2007-11-14 17:39:16 +00:00
|
|
|
|
|
|
|
/// hide the cursor
|
|
|
|
virtual void removeCursor();
|
2007-11-11 22:30:21 +00:00
|
|
|
|
2010-01-25 13:31:07 +00:00
|
|
|
/// This function should be called to update the buffer readonly status.
|
2007-11-12 22:15:51 +00:00
|
|
|
void setReadOnly(bool);
|
|
|
|
|
|
|
|
/// Update window titles of all users.
|
|
|
|
void updateWindowTitle();
|
2006-10-23 08:46:09 +00:00
|
|
|
///
|
2007-12-25 18:53:38 +00:00
|
|
|
bool event(QEvent *);
|
|
|
|
///
|
2007-12-25 20:12:07 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent *);
|
|
|
|
///
|
2006-10-27 23:26:52 +00:00
|
|
|
void focusInEvent(QFocusEvent *);
|
|
|
|
///
|
|
|
|
void focusOutEvent(QFocusEvent *);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// repaint part of the widget
|
2006-10-23 11:19:17 +00:00
|
|
|
void paintEvent(QPaintEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// widget has been resized
|
2006-10-23 11:19:17 +00:00
|
|
|
void resizeEvent(QResizeEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse button press
|
2006-10-23 11:19:17 +00:00
|
|
|
void mousePressEvent(QMouseEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse button release
|
2006-10-23 11:19:17 +00:00
|
|
|
void mouseReleaseEvent(QMouseEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse double click of button
|
2006-10-23 11:19:17 +00:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse motion
|
2006-10-23 11:19:17 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// wheel event
|
2006-10-23 11:19:17 +00:00
|
|
|
void wheelEvent(QWheelEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// key press
|
2006-10-23 11:19:17 +00:00
|
|
|
void keyPressEvent(QKeyEvent * ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
/// IM events
|
2006-10-23 11:19:17 +00:00
|
|
|
void inputMethodEvent(QInputMethodEvent * ev);
|
2007-04-01 09:14:08 +00:00
|
|
|
/// IM query
|
|
|
|
QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// The slot connected to SyntheticMouseEvent::timeout.
|
|
|
|
void generateSyntheticMouseEvent();
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
|
|
|
void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
|
|
|
|
/// hide the visible cursor, if it is visible
|
|
|
|
void hideCursor();
|
|
|
|
/// show the cursor if it is not visible
|
|
|
|
void showCursor();
|
|
|
|
///
|
|
|
|
void updateScrollbar();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
|
|
|
BufferView * buffer_view_;
|
2010-01-25 13:31:07 +00:00
|
|
|
/// Read only Buffer status cache.
|
|
|
|
bool read_only_;
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
2007-11-13 09:52:28 +00:00
|
|
|
GuiView * lyx_view_;
|
2007-11-12 22:15:51 +00:00
|
|
|
/// is the cursor currently displayed
|
|
|
|
bool cursor_visible_;
|
|
|
|
|
|
|
|
///
|
2007-11-21 21:15:23 +00:00
|
|
|
QTimer cursor_timeout_;
|
2006-03-20 17:25:02 +00:00
|
|
|
///
|
2006-03-05 17:24:44 +00:00
|
|
|
SyntheticMouseEvent synthetic_mouse_event_;
|
2006-10-23 11:19:17 +00:00
|
|
|
///
|
2007-11-12 22:15:51 +00:00
|
|
|
DoubleClick dc_event_;
|
2006-06-02 12:01:28 +00:00
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
///
|
2006-10-23 11:19:17 +00:00
|
|
|
CursorWidget * cursor_;
|
2006-11-02 22:53:10 +00:00
|
|
|
///
|
|
|
|
QPixmap screen_;
|
2007-01-04 12:36:17 +00:00
|
|
|
///
|
|
|
|
bool need_resize_;
|
2007-01-16 15:16:09 +00:00
|
|
|
///
|
2007-01-18 21:47:27 +00:00
|
|
|
bool schedule_redraw_;
|
2007-04-01 09:14:08 +00:00
|
|
|
///
|
|
|
|
int preedit_lines_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
///
|
2008-04-21 19:12:15 +00:00
|
|
|
GuiCompleter * completer_;
|
2008-11-15 22:34:52 +00:00
|
|
|
|
|
|
|
/// Special mode in which Esc and Enter (with or without Shift)
|
|
|
|
/// are ignored
|
2008-11-15 22:58:19 +00:00
|
|
|
bool dialog_mode_;
|
2011-02-14 21:30:12 +00:00
|
|
|
/// store the name of the context menu when the mouse is
|
2009-07-30 18:12:29 +00:00
|
|
|
/// pressed. This is used to get the correct context menu
|
2011-02-14 21:30:12 +00:00
|
|
|
/// when the menu is actually shown (after releasing on Windows)
|
|
|
|
/// and after the DEPM has done its job.
|
|
|
|
docstring context_menu_name_;
|
2007-11-12 22:15:51 +00:00
|
|
|
}; // GuiWorkArea
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
|
2008-11-22 14:45:47 +00:00
|
|
|
class EmbeddedWorkArea : public GuiWorkArea
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
EmbeddedWorkArea(QWidget *);
|
|
|
|
~EmbeddedWorkArea();
|
|
|
|
|
|
|
|
/// Dummy methods for Designer.
|
|
|
|
void setWidgetResizable(bool) {}
|
|
|
|
void setWidget(QWidget *) {}
|
|
|
|
|
2010-03-21 11:50:13 +00:00
|
|
|
QSize sizeHint () const;
|
2008-11-22 15:21:45 +00:00
|
|
|
///
|
|
|
|
void disable();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
///
|
2008-11-22 17:35:17 +00:00
|
|
|
void closeEvent(QCloseEvent * ev);
|
|
|
|
///
|
|
|
|
void hideEvent(QHideEvent *ev);
|
2008-11-22 15:21:45 +00:00
|
|
|
|
2008-11-22 14:45:47 +00:00
|
|
|
private:
|
|
|
|
/// Embedded Buffer.
|
|
|
|
Buffer * buffer_;
|
|
|
|
}; // EmbeddedWorkArea
|
|
|
|
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
/// A tabbed set of GuiWorkAreas.
|
|
|
|
class TabWorkArea : public QTabWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
TabWorkArea(QWidget * parent = 0);
|
2007-11-11 22:30:21 +00:00
|
|
|
|
2008-02-09 18:29:15 +00:00
|
|
|
///
|
|
|
|
void setFullScreen(bool full_screen);
|
2007-10-06 15:48:58 +00:00
|
|
|
void showBar(bool show);
|
2007-10-07 08:12:20 +00:00
|
|
|
void closeAll();
|
2007-10-07 08:05:02 +00:00
|
|
|
bool setCurrentWorkArea(GuiWorkArea *);
|
2007-11-19 10:04:14 +00:00
|
|
|
GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
|
2007-10-07 08:05:02 +00:00
|
|
|
bool removeWorkArea(GuiWorkArea *);
|
2007-10-16 06:50:09 +00:00
|
|
|
GuiWorkArea * currentWorkArea();
|
|
|
|
GuiWorkArea * workArea(Buffer & buffer);
|
2010-10-23 10:49:45 +00:00
|
|
|
GuiWorkArea * workArea(int index);
|
2007-10-06 15:48:58 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
///
|
|
|
|
void currentWorkAreaChanged(GuiWorkArea *);
|
2008-03-14 23:24:59 +00:00
|
|
|
///
|
|
|
|
void lastWorkAreaRemoved();
|
2007-10-06 15:48:58 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2008-03-15 01:00:25 +00:00
|
|
|
/// close current buffer, or the one given by \c clicked_tab_
|
2008-02-21 12:29:26 +00:00
|
|
|
void closeCurrentBuffer();
|
2009-10-31 18:14:21 +00:00
|
|
|
/// hide current tab, or the one given by \c clicked_tab_
|
|
|
|
void hideCurrentTab();
|
2009-10-31 18:10:18 +00:00
|
|
|
/// close the tab given by \c index
|
|
|
|
void closeTab(int index);
|
2007-11-11 22:30:21 +00:00
|
|
|
///
|
2008-04-29 15:44:07 +00:00
|
|
|
void updateTabTexts();
|
2008-03-15 01:00:25 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2008-03-15 02:13:01 +00:00
|
|
|
///
|
|
|
|
void on_currentTabChanged(int index);
|
2008-03-15 01:00:25 +00:00
|
|
|
///
|
|
|
|
void showContextMenu(const QPoint & pos);
|
2008-03-15 02:13:01 +00:00
|
|
|
///
|
|
|
|
void moveTab(int fromIndex, int toIndex);
|
2010-04-18 11:30:20 +00:00
|
|
|
///
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent * event);
|
2008-03-15 01:00:25 +00:00
|
|
|
|
|
|
|
private:
|
2009-03-08 10:21:33 +00:00
|
|
|
///
|
2008-03-15 01:00:25 +00:00
|
|
|
int clicked_tab_;
|
2009-03-08 10:21:33 +00:00
|
|
|
///
|
|
|
|
QToolButton * closeBufferButton;
|
2007-10-06 15:48:58 +00:00
|
|
|
}; // TabWorkArea
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-15 02:13:01 +00:00
|
|
|
|
|
|
|
class DragTabBar : public QTabBar
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
///
|
2008-04-21 13:47:01 +00:00
|
|
|
DragTabBar(QWidget * parent = 0);
|
2008-03-15 02:13:01 +00:00
|
|
|
|
|
|
|
#if QT_VERSION < 0x040300
|
|
|
|
///
|
|
|
|
int tabAt(QPoint const & position) const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
void mousePressEvent(QMouseEvent * event);
|
|
|
|
///
|
|
|
|
void mouseMoveEvent(QMouseEvent * event);
|
|
|
|
///
|
|
|
|
void dragEnterEvent(QDragEnterEvent * event);
|
|
|
|
///
|
|
|
|
void dropEvent(QDropEvent * event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
QPoint dragStartPos_;
|
|
|
|
///
|
|
|
|
int dragCurrentIndex_;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
///
|
|
|
|
void tabMoveRequested(int fromIndex, int toIndex);
|
|
|
|
};
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // WORKAREA_H
|