地面站终端 App
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
0 B

15 years ago
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
15 years ago
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_PICKER
#define QWT_PICKER 1
#include "qwt_global.h"
#include "qwt_text.h"
#include "qwt_event_pattern.h"
15 years ago
#include <qobject.h>
#include <qpen.h>
#include <qfont.h>
#include <qrect.h>
#include <qpainterpath.h>
15 years ago
class QWidget;
class QMouseEvent;
class QWheelEvent;
class QKeyEvent;
class QwtPickerMachine;
class QwtWidgetOverlay;
15 years ago
/*!
\brief QwtPicker provides selections on a widget
QwtPicker filters all enter, leave, mouse and keyboard events of a widget
and translates them into an array of selected points.
The way how the points are collected depends on type of state machine
that is connected to the picker. Qwt offers a couple of predefined
state machines for selecting:
15 years ago
- Nothing\n
QwtPickerTrackerMachine
- Single points\n
QwtPickerClickPointMachine, QwtPickerDragPointMachine
- Rectangles\n
QwtPickerClickRectMachine, QwtPickerDragRectMachine
- Polygons\n
QwtPickerPolygonMachine
While these state machines cover the most common ways to collect points
it is also possible to implement individual machines as well.
QwtPicker translates the picked points into a selection using the
adjustedPoints() method. adjustedPoints() is intended to be reimplemented
to fix up the selection according to application specific requirements.
(F.e. when an application accepts rectangles of a fixed aspect ratio only.)
Optionally QwtPicker support the process of collecting points by a
rubber band and tracker displaying a text for the current mouse
position.
15 years ago
\par Example
15 years ago
\verbatim #include <qwt_picker.h>
#include <qwt_picker_machine.h>
15 years ago
QwtPicker *picker = new QwtPicker(widget);
picker->setStateMachine(new QwtPickerDragRectMachine);
15 years ago
picker->setTrackerMode(QwtPicker::ActiveOnly);
picker->setRubberBand(QwtPicker::RectRubberBand); \endverbatim\n
The state machine triggers the following commands:
15 years ago
- begin()\n
Activate/Initialize the selection.
- append()\n
Add a new point
- move() \n
Change the position of the last point.
- remove()\n
Remove the last point.
- end()\n
Terminate the selection and call accept to validate the picked points.
15 years ago
The picker is active (isActive()), between begin() and end().
In active state the rubber band is displayed, and the tracker is visible
15 years ago
in case of trackerMode is ActiveOnly or AlwaysOn.
The cursor can be moved using the arrow keys. All selections can be aborted
using the abort key. (QwtEventPattern::KeyPatternCode)
\warning In case of QWidget::NoFocus the focus policy of the observed
widget is set to QWidget::WheelFocus and mouse tracking
will be manipulated while the picker is active,
15 years ago
or if trackerMode() is AlwayOn.
*/
class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern
{
Q_OBJECT
Q_ENUMS( RubberBand DisplayMode ResizeMode )
15 years ago
Q_PROPERTY( bool isEnabled READ isEnabled WRITE setEnabled )
Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
15 years ago
Q_PROPERTY( DisplayMode trackerMode READ trackerMode WRITE setTrackerMode )
Q_PROPERTY( QPen trackerPen READ trackerPen WRITE setTrackerPen )
Q_PROPERTY( QFont trackerFont READ trackerFont WRITE setTrackerFont )
15 years ago
Q_PROPERTY( RubberBand rubberBand READ rubberBand WRITE setRubberBand )
Q_PROPERTY( QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen )
15 years ago
public:
/*!
Rubber band style
15 years ago
The default value is QwtPicker::NoRubberBand.
\sa setRubberBand(), rubberBand()
15 years ago
*/
enum RubberBand
{
//! No rubberband.
15 years ago
NoRubberBand = 0,
//! A horizontal line ( only for QwtPickerMachine::PointSelection )
15 years ago
HLineRubberBand,
//! A vertical line ( only for QwtPickerMachine::PointSelection )
15 years ago
VLineRubberBand,
//! A crosshair ( only for QwtPickerMachine::PointSelection )
15 years ago
CrossRubberBand,
//! A rectangle ( only for QwtPickerMachine::RectSelection )
15 years ago
RectRubberBand,
//! An ellipse ( only for QwtPickerMachine::RectSelection )
15 years ago
EllipseRubberBand,
//! A polygon ( only for QwtPickerMachine::PolygonSelection )
15 years ago
PolygonRubberBand,
/*!
Values >= UserRubberBand can be used to define additional
rubber bands.
*/
15 years ago
UserRubberBand = 100
};
/*!
\brief Display mode
\sa setTrackerMode(), trackerMode(), isActive()
15 years ago
*/
enum DisplayMode
{
//! Display never
15 years ago
AlwaysOff,
//! Display always
15 years ago
AlwaysOn,
//! Display only when the selection is active
15 years ago
ActiveOnly
};
/*!
15 years ago
Controls what to do with the selected points of an active
selection when the observed widget is resized.
The default value is QwtPicker::Stretch.
\sa setResizeMode()
15 years ago
*/
enum ResizeMode
{
//! All points are scaled according to the new size,
15 years ago
Stretch,
//! All points remain unchanged.
15 years ago
KeepSize
};
explicit QwtPicker( QWidget *parent );
explicit QwtPicker( RubberBand rubberBand,
DisplayMode trackerMode, QWidget * );
15 years ago
virtual ~QwtPicker();
void setStateMachine( QwtPickerMachine * );
const QwtPickerMachine *stateMachine() const;
QwtPickerMachine *stateMachine();
15 years ago
void setRubberBand( RubberBand );
15 years ago
RubberBand rubberBand() const;
void setTrackerMode( DisplayMode );
15 years ago
DisplayMode trackerMode() const;
void setResizeMode( ResizeMode );
15 years ago
ResizeMode resizeMode() const;
void setRubberBandPen( const QPen & );
15 years ago
QPen rubberBandPen() const;
void setTrackerPen( const QPen & );
15 years ago
QPen trackerPen() const;
void setTrackerFont( const QFont & );
15 years ago
QFont trackerFont() const;
bool isEnabled() const;
bool isActive() const;
virtual bool eventFilter( QObject *, QEvent * );
15 years ago
QWidget *parentWidget();
const QWidget *parentWidget() const;
virtual QPainterPath pickArea() const;
virtual void drawRubberBand( QPainter * ) const;
virtual void drawTracker( QPainter * ) const;
15 years ago
virtual QRegion rubberBandMask() const;
15 years ago
virtual QwtText trackerText( const QPoint &pos ) const;
15 years ago
QPoint trackerPosition() const;
virtual QRect trackerRect( const QFont & ) const;
15 years ago
QPolygon selection() const;
public Q_SLOTS:
void setEnabled( bool );
Q_SIGNALS:
/*!
A signal indicating, when the picker has been activated.
Together with setEnabled() it can be used to implement
selections with more than one picker.
\param on True, when the picker has been activated
*/
void activated( bool on );
15 years ago
/*!
A signal emitting the selected points,
15 years ago
at the end of a selection.
\param polygon Selected points
15 years ago
*/
void selected( const QPolygon &polygon );
15 years ago
/*!
A signal emitted when a point has been appended to the selection
\param pos Position of the appended point.
\sa append(). moved()
*/
void appended( const QPoint &pos );
15 years ago
/*!
A signal emitted whenever the last appended point of the
15 years ago
selection has been moved.
\param pos Position of the moved last point of the selection.
\sa move(), appended()
*/
void moved( const QPoint &pos );
/*!
A signal emitted whenever the last appended point of the
selection has been removed.
15 years ago
\param pos Position of the point, that has been removed
\sa remove(), appended()
*/
void removed( const QPoint &pos );
15 years ago
/*!
A signal emitted when the active selection has been changed.
This might happen when the observed widget is resized.
\param selection Changed selection
15 years ago
\sa stretchSelection()
*/
void changed( const QPolygon &selection );
15 years ago
protected:
virtual QPolygon adjustedPoints( const QPolygon & ) const;
15 years ago
virtual void transition( const QEvent * );
15 years ago
virtual void begin();
virtual void append( const QPoint & );
virtual void move( const QPoint & );
virtual void remove();
virtual bool end( bool ok = true );
15 years ago
virtual bool accept( QPolygon & ) const;
15 years ago
virtual void reset();
virtual void widgetMousePressEvent( QMouseEvent * );
virtual void widgetMouseReleaseEvent( QMouseEvent * );
virtual void widgetMouseDoubleClickEvent( QMouseEvent * );
virtual void widgetMouseMoveEvent( QMouseEvent * );
virtual void widgetWheelEvent( QWheelEvent * );
virtual void widgetKeyPressEvent( QKeyEvent * );
virtual void widgetKeyReleaseEvent( QKeyEvent * );
virtual void widgetEnterEvent( QEvent * );
virtual void widgetLeaveEvent( QEvent * );
15 years ago
virtual void stretchSelection( const QSize &oldSize,
const QSize &newSize );
15 years ago
virtual void updateDisplay();
const QwtWidgetOverlay *rubberBandOverlay() const;
const QwtWidgetOverlay *trackerOverlay() const;
const QPolygon &pickedPoints() const;
15 years ago
private:
void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode );
15 years ago
void setMouseTracking( bool );
15 years ago
class PrivateData;
PrivateData *d_data;
};
15 years ago
#endif