| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2024 Pierre-Louis Boyer <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#ifndef GUI_ToolHandler_H |
| 24 |
#define GUI_ToolHandler_H |
| 25 |
|
| 26 |
#include <QCursor> |
| 27 |
#include <QPixmap> |
| 28 |
|
| 29 |
#include <Base/Parameter.h> |
| 30 |
#include <Base/Tools2D.h> |
| 31 |
|
| 32 |
#include "Selection/Selection.h" |
| 33 |
|
| 34 |
|
| 35 |
namespace Gui |
| 36 |
{ |
| 37 |
class View3DInventorViewer; |
| 38 |
struct InputHint; |
| 39 |
|
| 40 |
class GuiExport ToolHandler |
| 41 |
{ |
| 42 |
public: |
| 43 |
ToolHandler() = default; |
| 44 |
virtual ~ToolHandler() = default; |
| 45 |
|
| 46 |
bool activate(); |
| 47 |
virtual void deactivate(); |
| 48 |
|
| 49 |
virtual void quit() |
| 50 |
{} |
| 51 |
|
| 52 |
/// updates the actCursor with the icon by calling getCrosshairCursorSVGName(), |
| 53 |
/// enabling to set data member dependent icons (i.e. for different construction methods) |
| 54 |
void updateCursor(); |
| 55 |
|
| 56 |
virtual std::list<InputHint> getToolHints() const; |
| 57 |
void updateHint() const; |
| 58 |
|
| 59 |
private: // NVI |
| 60 |
virtual void preActivated() |
| 61 |
{} |
| 62 |
virtual void activated() |
| 63 |
{} |
| 64 |
virtual void deactivated() |
| 65 |
{} |
| 66 |
virtual void postDeactivated() |
| 67 |
{} |
| 68 |
|
| 69 |
protected: // NVI requiring base implementation |
| 70 |
virtual QString getCrosshairCursorSVGName() const; |
| 71 |
|
| 72 |
|
| 73 |
protected: |
| 74 |
// helpers |
| 75 |
/** |
| 76 |
* Sets a cursor for 3D inventor view. |
| 77 |
* pixmap as a cursor image in device independent pixels. |
| 78 |
* |
| 79 |
* \param autoScale - set this to false if pixmap already scaled for HiDPI |
| 80 |
**/ |
| 81 |
|
| 82 |
/** @name Icon helpers */ |
| 83 |
//@{ |
| 84 |
void setCursor(const QPixmap& pixmap, int x, int y, bool autoScale = true); |
| 85 |
|
| 86 |
|
| 87 |
void unsetCursor(); |
| 88 |
|
| 89 |
/// restitutes the DSH cached cursor (without any tail due to autoconstraints, ...) |
| 90 |
void applyCursor(); |
| 91 |
|
| 92 |
void addCursorTail(std::vector<QPixmap>& pixmaps); |
| 93 |
|
| 94 |
/// returns the color to be used for the crosshair (configurable as a parameter) |
| 95 |
unsigned long getCrosshairColor(); |
| 96 |
|
| 97 |
/// functions to set the cursor to a given svgName (to be migrated to NVI style) |
| 98 |
|
| 99 |
qreal devicePixelRatio(); |
| 100 |
//@} |
| 101 |
|
| 102 |
View3DInventorViewer* getViewer(); |
| 103 |
|
| 104 |
virtual QWidget* getCursorWidget(); |
| 105 |
|
| 106 |
virtual void setWidgetCursor(QCursor cursor); |
| 107 |
|
| 108 |
private: |
| 109 |
void setSvgCursor( |
| 110 |
const QString& svgName, |
| 111 |
int x, |
| 112 |
int y, |
| 113 |
const std::map<unsigned long, unsigned long>& colorMapping |
| 114 |
= std::map<unsigned long, unsigned long>() |
| 115 |
); |
| 116 |
|
| 117 |
|
| 118 |
void applyCursor(QCursor& newCursor); |
| 119 |
|
| 120 |
void setCrosshairCursor(const QString& svgName); |
| 121 |
void setCrosshairCursor(const char* svgName); |
| 122 |
|
| 123 |
protected: |
| 124 |
QCursor oldCursor; |
| 125 |
QCursor actCursor; |
| 126 |
QPixmap actCursorPixmap; |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
} // namespace Gui |
| 131 |
|
| 132 |
|
| 133 |
#endif // GUI_ToolHandler_H |