📄 qwt_picker.cpp
字号:
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/#include <qapplication.h>#include <qpainter.h>#include <qframe.h>#include <qcursor.h>#include "qwt_text.h"#include "qwt_painter.h"#include "qwt_picker_machine.h"#include "qwt_picker.h"/*! Constructor Creates an picker that is enabled, but where selection flags s set to NoSelection, rubberband and cursor label are disabled. \param parent Parent widget, that will be observed \param name Object name */QwtPicker::QwtPicker(QWidget *parent, const char *name): QObject(parent, name){ init(parent, NoSelection, NoRubberBand, AlwaysOff);}/*! Constructor \param selectionFlags Or磀 value of SelectionType, RectSelectionType and SelectionMode \param rubberBand Rubberband style \param cursorLabelMode Cursor label mode \param parent Parent widget, that will be observed \param name Object name */QwtPicker::QwtPicker(int selectionFlags, RubberBand rubberBand, DisplayMode cursorLabelMode, QWidget *parent, const char *name): QObject(parent, name){ init(parent, selectionFlags, rubberBand, cursorLabelMode);}//! DestructorQwtPicker::~QwtPicker(){ setMouseTracking(FALSE); delete d_stateMachine;}//! Init the picker, used by the constructorsvoid QwtPicker::init(QWidget *parent, int selectionFlags, RubberBand rubberBand, DisplayMode cursorLabelMode){ d_rubberBand = rubberBand; d_enabled = FALSE; d_resizeMode = Stretch; d_cursorLabelMode = cursorLabelMode; d_isActive = FALSE; d_labelPosition = QPoint(-1, -1); d_mouseTracking = FALSE; d_stateMachine = NULL; setSelectionFlags(selectionFlags); if ( parent ) { if ( parent->focusPolicy() == QWidget::NoFocus ) parent->setFocusPolicy(QWidget::WheelFocus); d_cursorLabelFont = parent->font(); d_mouseTracking = parent->hasMouseTracking(); setEnabled(TRUE); }}/*! Set a state machine and delete the previous one*/void QwtPicker::setStateMachine(QwtPickerMachine *stateMachine){ if ( d_stateMachine != stateMachine ) { if ( isActive() ) end(FALSE); delete d_stateMachine; d_stateMachine = stateMachine; if ( d_stateMachine ) d_stateMachine->reset(); }}/*! Create a state machine depending on the selection flags. - PointSelection | ClickSelection\n QwtPickerClickPointMachine() - PointSelection | DragSelection\n QwtPickerDragPointMachine() - RectSelection | ClickSelection\n QwtPickerClickRectMachine() - RectSelection | DragSelection\n QwtPickerDragRectMachine() - PolygonSelection\n QwtPickerPolygonMachine() \sa setSelectionFlags()*/QwtPickerMachine *QwtPicker::stateMachine(int flags) const{ if ( flags & PointSelection ) { if ( flags & ClickSelection ) return new QwtPickerClickPointMachine; else return new QwtPickerDragPointMachine; } if ( flags & RectSelection ) { if ( flags & ClickSelection ) return new QwtPickerClickRectMachine; else return new QwtPickerDragRectMachine; } if ( flags & PolygonSelection ) { return new QwtPickerPolygonMachine(); } return NULL;}//! Return the parent widget, where the selection happensQWidget *QwtPicker::parentWidget(){ QObject *obj = parent(); if ( obj && obj->isWidgetType() ) return (QWidget *)obj; return NULL;}//! Return the parent widget, where the selection happensconst QWidget *QwtPicker::parentWidget() const{ QObject *obj = parent(); if ( obj && obj->isWidgetType() ) return (QWidget *)obj; return NULL;}/*! Set the selection flags \param flags Or磀 value of SelectionType, RectSelectionType and SelectionMode. The default value is NoSelection. \sa selectionFlags(), SelectionType, RectSelectionType, SelectionMode*/void QwtPicker::setSelectionFlags(int flags){ d_selectionFlags = flags; setStateMachine(stateMachine(flags));}/*! \return Selection flags, an Or磀 value of SelectionType, RectSelectionType and SelectionMode. \sa setSelectionFlags(), SelectionType, RectSelectionType, SelectionMode*/int QwtPicker::selectionFlags() const{ return d_selectionFlags;}/*! Set the rubberband style \param rubberBand Rubberband style The default value is NoRubberBand. \sa rubberBand(), RubberBand, setRubberBandPen()*/void QwtPicker::setRubberBand(RubberBand rubberBand){ d_rubberBand = rubberBand;}/*! \return Rubberband style \sa setRubberBand(), RubberBand, rubberBandPen()*/QwtPicker::RubberBand QwtPicker::rubberBand() const{ return d_rubberBand;}/*! \brief Set the display mode of the cursor label. A cursor label dispays the current position of the cursor as a string. The display mode controls if the label has to be displayed whenever the observed widget has focus and cursor (AlwaysOn), never (AlwaysOff), or only when the selection is active (ActiveOnly). \param mode Cursor label display mode \warning In case of AlwaysOn, mouseTracking will be enabled for the observed widget. \sa cursorLabelMode(), DisplayMode*/void QwtPicker::setCursorLabelMode(DisplayMode mode){ if ( d_cursorLabelMode != mode ) { d_cursorLabelMode = mode; setMouseTracking(d_cursorLabelMode == AlwaysOn); }} /*! \return Cursor label display mode \sa setCursorLabelMode(), DisplayMode*/QwtPicker::DisplayMode QwtPicker::cursorLabelMode() const{ return d_cursorLabelMode;} /*! \brief Set the resize mode. The resize mode controls what to do with the selected points of an active selection when the observed widget is resized. Stretch means the points are scaled according to the new size, KeepSize means the points remain unchanged. The default mode is Stretch. \param mode Resize mode \sa resizeMode(), ResizeMode*/void QwtPicker::setResizeMode(ResizeMode mode){ d_resizeMode = mode;} /*! \return Resize mode \sa setResizeMode(), ResizeMode*/QwtPicker::ResizeMode QwtPicker::resizeMode() const{ return d_resizeMode;}/*! \brief En/disable the picker When enabled is TRUE an event filter is installed for the observed widget, otherwise the event filter is removed. \param enabled TRUE or FALSE \sa isEnabled(), eventFilter()*/void QwtPicker::setEnabled(bool enabled){ if ( d_enabled != enabled ) { QWidget *w = parentWidget(); if ( !w ) return; d_enabled = enabled; drawCursorLabel(); if ( d_enabled ) w->installEventFilter(this); else w->removeEventFilter(this); }}/*! \return TRUE when enabled, FALSE otherwise \sa setEnabled, eventFilter()*/bool QwtPicker::isEnabled() const{ return d_enabled;}/*! Set the font for the cursor label \param font Cursor label font \sa cursorLabelFont(), setCursorLabelMode(), setCursorLabelPen()*/void QwtPicker::setCursorLabelFont(const QFont &font){ if ( font != d_cursorLabelFont ) { if ( isEnabled() ) drawCursorLabel(); // erase d_cursorLabelFont = font; if ( isEnabled() ) drawCursorLabel(); // repaint }}/*! \return Cursor label font \sa setCursorLabelFont(), cursorLabelMode(), cursorLabelPen()*/QFont QwtPicker::cursorLabelFont() const{ return d_cursorLabelFont;}/*! Set the pen for the cursor label \param pen Cursor label pen \sa cursorLabelPen(), setCursorLabelMode(), setCursorLabelFont()*/void QwtPicker::setCursorLabelPen(const QPen &pen){ if ( pen != d_cursorLabelPen ) { if ( isEnabled() ) drawCursorLabel(); // erase d_cursorLabelPen = pen; if ( isEnabled() ) drawCursorLabel(); // repaint }}/*! \return Cursor label pen \sa setCursorLabelPen(), cursorLabelMode(), cursorLabelFont()*/QPen QwtPicker::cursorLabelPen() const{ return d_cursorLabelPen;}/*! Set the pen for the rubberband \param pen Rubberband pen \sa rubberBandPen(), setRubberBand()*/void QwtPicker::setRubberBandPen(const QPen &pen){ if ( pen != d_rubberBandPen ) { drawRubberBand(); // erase d_rubberBandPen = pen; drawRubberBand(); // repaint }}/*! \return Rubberband pen \sa setRubberBandPen(), rubberBand()*/QPen QwtPicker::rubberBandPen() const{ return d_rubberBandPen;}/*! \brief Return the label for a position In case of HLineRubberBand the label is the value of the y position, in case of VLineRubberBand the value of the x position. Otherwise the label contains x and y position separated by a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -