00001 /****************************************************************************************************** 00002 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released * 00003 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file * 00004 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. * 00005 ******************************************************************************************************/ 00006 00007 #ifndef DIGITIZE_STATE_SELECT_H 00008 #define DIGITIZE_STATE_SELECT_H 00009 00010 #include "DigitizeStateAbstractBase.h" 00011 00013 class DigitizeStateSelect : public DigitizeStateAbstractBase 00014 { 00015 public: 00017 DigitizeStateSelect(DigitizeStateContext &context); 00018 virtual ~DigitizeStateSelect(); 00019 00020 virtual QString activeCurve () const; 00021 virtual void begin(CmdMediator *cmdMediator, 00022 DigitizeState previousState); 00023 virtual QCursor cursor (CmdMediator *cmdMediator) const; 00024 virtual void end(); 00025 virtual void handleCurveChange(CmdMediator *cmdMediator); 00026 virtual void handleKeyPress (CmdMediator *cmdMediator, 00027 Qt::Key key, 00028 bool atLeastOneSelectedItem); 00029 virtual void handleMouseMove (CmdMediator *cmdMediator, 00030 QPointF posScreen); 00031 virtual void handleMousePress (CmdMediator *cmdMediator, 00032 QPointF posScreen); 00033 virtual void handleMouseRelease (CmdMediator *cmdMediator, 00034 QPointF posScreen); 00035 virtual QString state() const; 00036 virtual void updateModelDigitizeCurve (CmdMediator *cmdMediator, 00037 const DocumentModelDigitizeCurve &modelDigitizeCurve); 00038 virtual void updateModelSegments(const DocumentModelSegments &modelSegments); 00039 00040 private: 00041 DigitizeStateSelect(); 00042 00043 void keyPressArrow (CmdMediator *cmdMediator, 00044 Qt::Key key); 00045 QString moveTextFromDeltaScreen (const QPointF &deltaScreen); 00046 void setCursorForPoints(); 00047 void unsetCursorForPoints(); 00048 double zoomedToUnzoomedScreenX () const; 00049 double zoomedToUnzoomedScreenY () const; 00050 00051 // Click and drag cases are: 00052 // 1) rubber band selection 00053 // Result = selection of any items inside the rubber band but no movement 00054 // 2) selection and moving with no initially selected items. 00055 // Result = selection and movement of item under cursor 00056 // 3) selection and moving with only item under cursor initially selected 00057 // Result = same result as case #2 00058 // 4) selection and moving with item under cursor not initially selected but other item(s) selected 00059 // Result = other items get unselected so the result is the same as case #2 but with some items now unselected 00060 // 5) selection and moving with item under cursor initially selected along with other selected items 00061 // Result = all selected items get moved 00062 // Originally, determining if any object was under the cursor during mousePressEvent was done with various hit tests, but 00063 // none were 100% consistent with the internal hit test done by the QGraphicsView. The solution was to simply: 00064 // 1) Mark all items as unmoved when the mousePressEvent occurs 00065 // 2) Mark items that undergo QGraphicsItem::ItemScaleHasChanged as having moved 00066 // 3) Harvest the results when the mouseReleaseEvent occurs 00067 // All moved items then have the currentCursorPosition - m_movingStart translation applied to them 00068 QPointF m_movingStart; 00069 }; 00070 00071 #endif // DIGITIZE_STATE_SELECT_H