| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/*************************************************************************** |
| 3 |
* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> * |
| 4 |
* * |
| 5 |
* This file is part of the FreeCAD CAx development system. * |
| 6 |
* * |
| 7 |
* This library is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU Library General Public * |
| 9 |
* License as published by the Free Software Foundation; either * |
| 10 |
* version 2 of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This library is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Library General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Library General Public * |
| 18 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 19 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 20 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
#ifndef DAGRECTITEM_H |
| 25 |
#define DAGRECTITEM_H |
| 26 |
|
| 27 |
#include <QBrush> |
| 28 |
#include <QGraphicsRectItem> |
| 29 |
|
| 30 |
|
| 31 |
namespace Gui |
| 32 |
{ |
| 33 |
namespace DAG |
| 34 |
{ |
| 35 |
/*all right I give up! the parenting combined with the zvalues is fubar! |
| 36 |
* you can't control any kind of layering between children of separate parents |
| 37 |
*/ |
| 38 |
class RectItem: public QGraphicsRectItem |
| 39 |
{ |
| 40 |
public: |
| 41 |
explicit RectItem(QGraphicsItem* parent = nullptr); |
| 42 |
void setBackgroundBrush(const QBrush& brushIn) |
| 43 |
{ |
| 44 |
backgroundBrush = brushIn; |
| 45 |
} |
| 46 |
void setEditingBrush(const QBrush& brushIn) |
| 47 |
{ |
| 48 |
editBrush = brushIn; |
| 49 |
} |
| 50 |
void preHighlightOn() |
| 51 |
{ |
| 52 |
preSelected = true; |
| 53 |
} |
| 54 |
void preHighlightOff() |
| 55 |
{ |
| 56 |
preSelected = false; |
| 57 |
} |
| 58 |
void selectionOn() |
| 59 |
{ |
| 60 |
selected = true; |
| 61 |
} |
| 62 |
void selectionOff() |
| 63 |
{ |
| 64 |
selected = false; |
| 65 |
} |
| 66 |
bool isSelected() |
| 67 |
{ |
| 68 |
return selected; |
| 69 |
} |
| 70 |
bool isPreSelected() |
| 71 |
{ |
| 72 |
return preSelected; |
| 73 |
} |
| 74 |
void editingStart() |
| 75 |
{ |
| 76 |
editing = true; |
| 77 |
} |
| 78 |
void editingFinished() |
| 79 |
{ |
| 80 |
editing = false; |
| 81 |
} |
| 82 |
bool isEditing() |
| 83 |
{ |
| 84 |
return editing; |
| 85 |
} |
| 86 |
|
| 87 |
protected: |
| 88 |
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; |
| 89 |
|
| 90 |
private: |
| 91 |
QBrush backgroundBrush; //!< brush used for background. not used yet. |
| 92 |
QBrush editBrush; //!< brush used when object is in edit mode. |
| 93 |
// start with booleans, may expand to state. |
| 94 |
bool selected; |
| 95 |
bool preSelected; |
| 96 |
bool editing; |
| 97 |
}; |
| 98 |
} // namespace DAG |
| 99 |
} // namespace Gui |
| 100 |
|
| 101 |
#endif // DAGRECTITEM_H |