QWT 7.0.1
Loading...
Searching...
No Matches
qwt_picker.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *
9 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_PICKER
28#define QWT_PICKER
29
30#include "qwt_global.h"
31#include "qwt_event_pattern.h"
32
33#include <qobject.h>
34#include <QPen>
35#include <QFont>
36#include <QPainterPath>
37#include <QPoint>
38#include <QPolygon>
39#include <QSize>
40#include <QRect>
41#include <QRegion>
44class QwtText;
45class QWidget;
46class QMouseEvent;
47class QWheelEvent;
48class QKeyEvent;
49class QPainter;
50
150class QWT_EXPORT QwtPicker : public QObject, public QwtEventPattern
151{
152 Q_OBJECT
153
155
156 Q_PROPERTY(bool isEnabled READ isEnabled WRITE setEnabled)
157 Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode)
158
159 Q_PROPERTY(DisplayMode trackerMode READ trackerMode WRITE setTrackerMode)
160 Q_PROPERTY(QPen trackerPen READ trackerPen WRITE setTrackerPen)
161 Q_PROPERTY(QFont trackerFont READ trackerFont WRITE setTrackerFont)
162
163 Q_PROPERTY(RubberBand rubberBand READ rubberBand WRITE setRubberBand)
164 Q_PROPERTY(QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen)
165
166public:
175 {
177 NoRubberBand = 0,
178
181
184
187
190
193
196
201 UserRubberBand = 100
202 };
203
209 {
212
215
217 ActiveOnly
218 };
219
229 {
232
234 KeepSize
235 };
236
237 explicit QwtPicker(QWidget* parent);
238 explicit QwtPicker(RubberBand rubberBand, DisplayMode trackerMode, QWidget*);
239
240 virtual ~QwtPicker();
241
242 void setStateMachine(QwtPickerMachine*);
243 const QwtPickerMachine* stateMachine() const;
244 QwtPickerMachine* stateMachine();
245
246 void setRubberBand(RubberBand);
247 RubberBand rubberBand() const;
248
249 void setTrackerMode(DisplayMode);
250 DisplayMode trackerMode() const;
251
252 void setResizeMode(ResizeMode);
253 ResizeMode resizeMode() const;
254
255 void setRubberBandPen(const QPen&);
256 QPen rubberBandPen() const;
257
258 void setTrackerPen(const QPen&);
259 QPen trackerPen() const;
260
261 void setTrackerFont(const QFont&);
262 QFont trackerFont() const;
263
264 bool isEnabled() const;
265 bool isActive() const;
266
267 virtual bool eventFilter(QObject*, QEvent*) QWT_OVERRIDE;
268
269 QWidget* parentWidget();
270 const QWidget* parentWidget() const;
271
272 virtual QPainterPath pickArea() const;
273
274 virtual void drawRubberBand(QPainter*) const;
275 virtual void drawTracker(QPainter*) const;
276
277 virtual QRegion trackerMask() const;
278 virtual QRegion rubberBandMask() const;
279
280 virtual QwtText trackerText(const QPoint& pos) const;
281 virtual QRect trackerRect(const QFont&) const;
282 // 强制设置trackerPosition,正常这个不需要调用,但有时候没有鼠标也想显示picker可以通过此函数来设置
283 virtual void setTrackerPosition(const QPoint& pos);
284 QPoint trackerPosition() const;
285 QPolygon selection() const;
286 // 更新显示
287 void update();
288 // 手动设置激活
289 void setActive(bool on);
290public Q_SLOTS:
291 void setEnabled(bool);
292
293Q_SIGNALS:
301 void activated(bool on);
302
309 void selected(const QPolygon& polygon);
310
317 void appended(const QPoint& pos);
318
326 void moved(const QPoint& pos);
327
335 void removed(const QPoint& pos);
343 void changed(const QPolygon& selection);
344
345protected:
346 virtual QPolygon adjustedPoints(const QPolygon&) const;
347
348 virtual void transition(const QEvent*);
349
350 virtual void begin();
351 virtual void append(const QPoint&);
352 virtual void move(const QPoint&);
353 virtual void remove();
354 virtual bool end(bool ok = true);
355
356 virtual bool accept(QPolygon&) const;
357 virtual void reset();
358
359 virtual void widgetMousePressEvent(QMouseEvent*);
360 virtual void widgetMouseReleaseEvent(QMouseEvent*);
361 virtual void widgetMouseDoubleClickEvent(QMouseEvent*);
362 virtual void widgetMouseMoveEvent(QMouseEvent*);
363 virtual void widgetWheelEvent(QWheelEvent*);
364 virtual void widgetKeyPressEvent(QKeyEvent*);
365 virtual void widgetKeyReleaseEvent(QKeyEvent*);
366 virtual void widgetEnterEvent(QEvent*);
367 virtual void widgetLeaveEvent(QEvent*);
368
369 virtual void stretchSelection(const QSize& oldSize, const QSize& newSize);
370
371 virtual void updateDisplay();
372
373 const QwtWidgetOverlay* rubberBandOverlay() const;
374 const QwtWidgetOverlay* trackerOverlay() const;
375
376 const QPolygon& pickedPoints() const;
377
378private:
379 void init(QWidget*, RubberBand rubberBand, DisplayMode trackerMode);
380
381 void setMouseTracking(bool);
382
383 class PrivateData;
384 PrivateData* m_data;
385};
386
387#endif
A collection of event patterns.
Definition qwt_event_pattern.h:48
A state machine for QwtPicker selections.
Definition qwt_picker_machine.h:46
QwtPicker provides selections on a widget / QwtPicker 在一个部件(widget)上提供选择功能
Definition qwt_picker.h:151
DisplayMode
Display mode.
Definition qwt_picker.h:209
@ AlwaysOn
Display always.
Definition qwt_picker.h:214
@ AlwaysOff
Display never.
Definition qwt_picker.h:211
void selected(const QPolygon &polygon)
A signal emitting the selected points, at the end of a selection.
void activated(bool on)
A signal indicating, when the picker has been activated.
RubberBand
Rubber band style.
Definition qwt_picker.h:175
@ VLineRubberBand
A vertical line ( only for QwtPickerMachine::PointSelection )
Definition qwt_picker.h:183
@ CrossRubberBand
A crosshair ( only for QwtPickerMachine::PointSelection )
Definition qwt_picker.h:186
@ EllipseRubberBand
An ellipse ( only for QwtPickerMachine::RectSelection )
Definition qwt_picker.h:192
@ PolygonRubberBand
A polygon ( only for QwtPickerMachine::PolygonSelection )
Definition qwt_picker.h:195
@ HLineRubberBand
A horizontal line ( only for QwtPickerMachine::PointSelection )
Definition qwt_picker.h:180
@ RectRubberBand
A rectangle ( only for QwtPickerMachine::RectSelection )
Definition qwt_picker.h:189
ResizeMode
Controls what to do with the selected points of an active selection when the observed widget is resiz...
Definition qwt_picker.h:229
@ Stretch
All points are scaled according to the new size,.
Definition qwt_picker.h:231
void appended(const QPoint &pos)
A signal emitted when a point has been appended to the selection.
void moved(const QPoint &pos)
A signal emitted whenever the last appended point of the selection has been moved.
void removed(const QPoint &pos)
A signal emitted whenever the last appended point of the selection has been removed.
void changed(const QPolygon &selection)
A signal emitted when the active selection has been changed.
A class representing a text.
Definition qwt_text.h:69
An overlay for a widget.
Definition qwt_widget_overlay.h:58