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"
|
|
|
|
|
2006-03-20 17:25:02 +00:00
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "frontends/Timeout.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QAbstractScrollArea>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QTimer>
|
2006-11-02 22:53:10 +00:00
|
|
|
#include <QPixmap>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
class QWidget;
|
|
|
|
class QDragEnterEvent;
|
|
|
|
class QDropEvent;
|
2006-10-22 17:58:09 +00:00
|
|
|
class QWheelEvent;
|
|
|
|
class QPaintEvent;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
class GuiView;
|
2006-10-23 08:46:09 +00:00
|
|
|
class QLPainter;
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// for emulating triple click
|
|
|
|
class double_click {
|
|
|
|
public:
|
|
|
|
int x;
|
|
|
|
int y;
|
2006-08-13 15:55:03 +00:00
|
|
|
Qt::MouseButton state;
|
2006-03-05 17:24:44 +00:00
|
|
|
bool active;
|
|
|
|
|
|
|
|
bool operator==(QMouseEvent const & e) {
|
|
|
|
return x == e.x() && y == e.y()
|
|
|
|
&& state == e.button();
|
|
|
|
}
|
|
|
|
|
|
|
|
double_click()
|
|
|
|
: x(0), y(0), state(Qt::NoButton), active(false) {}
|
|
|
|
|
|
|
|
double_click(QMouseEvent * e)
|
|
|
|
: x(e->x()), y(e->y()),
|
|
|
|
state(e->button()), active(true) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
int x_old;
|
|
|
|
int y_old;
|
|
|
|
double scrollbar_value_old;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Qt-specific implementation of the work area
|
|
|
|
* (buffer view GUI)
|
2006-03-12 17:29:34 +00:00
|
|
|
*/
|
2006-10-23 11:19:17 +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
|
|
|
///
|
2006-10-23 16:29:24 +00:00
|
|
|
GuiWorkArea(int width, int height, int id, LyXView & lyx_view);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-04 07:29:25 +00:00
|
|
|
///
|
|
|
|
bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// return the width of the content pane
|
2006-08-17 17:15:17 +00:00
|
|
|
virtual int width() const { return viewport()->width(); }
|
2006-03-05 17:24:44 +00:00
|
|
|
/// return the height of the content pane
|
2006-08-17 17:15:17 +00:00
|
|
|
virtual int height() const { return viewport()->height(); }
|
2006-03-05 17:24:44 +00:00
|
|
|
///
|
|
|
|
virtual void setScrollbarParams(int height, int pos, int line_height);
|
|
|
|
|
2006-03-20 10:43:21 +00:00
|
|
|
/// update the passed area.
|
2006-03-20 17:25:02 +00:00
|
|
|
void update(int x, int y, int w, int h);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-02 12:01:28 +00:00
|
|
|
/// copies specified area of pixmap to screen
|
|
|
|
virtual void expose(int x, int y, int exp_width, int exp_height);
|
|
|
|
|
|
|
|
/// paint the cursor and store the background
|
2006-06-26 16:55:35 +00:00
|
|
|
virtual void showCursor(int x, int y, int h, CursorShape shape);
|
2006-06-02 12:01:28 +00:00
|
|
|
|
|
|
|
/// hide the cursor
|
|
|
|
virtual void removeCursor();
|
2006-03-20 17:25:02 +00:00
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
private:
|
|
|
|
void doGreyOut(QLPainter & pain);
|
|
|
|
///
|
2006-10-23 11:19:17 +00:00
|
|
|
void dragEnterEvent(QDragEnterEvent * ev);
|
2006-10-23 08:46:09 +00:00
|
|
|
///
|
2006-10-23 11:19:17 +00:00
|
|
|
void dropEvent(QDropEvent * ev);
|
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);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-30 14:37:33 +00:00
|
|
|
public Q_SLOTS:
|
2006-03-20 17:25:02 +00:00
|
|
|
/// Adjust the LyX buffer view with the position of the scrollbar.
|
|
|
|
/**
|
|
|
|
* The action argument is not used in the the code, it is there
|
2006-04-05 23:56:29 +00:00
|
|
|
* only for the connection to the vertical srollbar signal which
|
2006-03-20 17:25:02 +00:00
|
|
|
* emits an 'int' action.
|
2006-03-14 14:50:00 +00:00
|
|
|
*/
|
|
|
|
void adjustViewWithScrollBar(int action = 0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// The slot connected to SyntheticMouseEvent::timeout.
|
|
|
|
void generateSyntheticMouseEvent();
|
|
|
|
|
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
|
|
|
///
|
2006-03-05 17:24:44 +00:00
|
|
|
double_click dc_event_;
|
2006-06-02 12:01:28 +00:00
|
|
|
|
2006-10-23 11:19:17 +00:00
|
|
|
///
|
|
|
|
CursorWidget * cursor_;
|
2006-11-02 22:53:10 +00:00
|
|
|
///
|
|
|
|
QPixmap screen_;
|
2006-03-05 17:24:44 +00:00
|
|
|
};
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // WORKAREA_H
|