| 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 |
#include <QApplication> |
| 25 |
#include <QPainter> |
| 26 |
|
| 27 |
|
| 28 |
#include <QStyleOptionViewItem> |
| 29 |
|
| 30 |
#include "DAGRectItem.h" |
| 31 |
|
| 32 |
|
| 33 |
using namespace Gui; |
| 34 |
using namespace DAG; |
| 35 |
|
| 36 |
RectItem::RectItem(QGraphicsItem* parent) |
| 37 |
: QGraphicsRectItem(parent) |
| 38 |
{ |
| 39 |
selected = false; |
| 40 |
preSelected = false; |
| 41 |
editing = false; |
| 42 |
} |
| 43 |
|
| 44 |
void RectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) |
| 45 |
{ |
| 46 |
Q_UNUSED(option); |
| 47 |
Q_UNUSED(widget); |
| 48 |
painter->save(); |
| 49 |
|
| 50 |
QStyleOptionViewItem styleOption; |
| 51 |
|
| 52 |
styleOption.backgroundBrush = backgroundBrush; |
| 53 |
if (editing) { |
| 54 |
styleOption.backgroundBrush = editBrush; |
| 55 |
} |
| 56 |
else { |
| 57 |
styleOption.state |= QStyle::State_Enabled; |
| 58 |
if (selected) { |
| 59 |
styleOption.state |= QStyle::State_Selected; |
| 60 |
} |
| 61 |
if (preSelected) { |
| 62 |
if (!selected) { |
| 63 |
styleOption.state |= QStyle::State_Selected; |
| 64 |
QPalette palette = styleOption.palette; |
| 65 |
QColor tempColor = palette.color(QPalette::Active, QPalette::Highlight); |
| 66 |
tempColor.setAlphaF(0.15F); |
| 67 |
palette.setColor(QPalette::Inactive, QPalette::Highlight, tempColor); |
| 68 |
styleOption.palette = palette; |
| 69 |
} |
| 70 |
styleOption.state |= QStyle::State_MouseOver; |
| 71 |
} |
| 72 |
} |
| 73 |
styleOption.rect = this->rect().toRect(); |
| 74 |
|
| 75 |
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &styleOption, painter); |
| 76 |
|
| 77 |
painter->restore(); |
| 78 |
} |