0029807: [Regression to 7.0.0] Impossible to cut cone from prism
[occt.git] / tools / DFBrowserPane / DFBrowserPane_ItemDelegateButton.cxx
CommitLineData
14bbbdcb 1// Created on: 2017-06-16
2// Created by: Natalia ERMOLAEVA
3// Copyright (c) 2017 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
0cb512c0 16#include <inspector/DFBrowserPane_ItemDelegateButton.hxx>
14bbbdcb 17
130eb114 18#include <Standard_WarningsDisable.hxx>
14bbbdcb 19#include <QAbstractItemModel>
20#include <QEvent>
21#include <QPainter>
130eb114 22#include <Standard_WarningsRestore.hxx>
14bbbdcb 23
0c80bdbf 24const int ICON_SIZE = 20;
25
14bbbdcb 26// =======================================================================
27// function : Constructor
28// purpose :
29// =======================================================================
30DFBrowserPane_ItemDelegateButton::DFBrowserPane_ItemDelegateButton (QObject* theParent, const QString& theIcon)
31: QStyledItemDelegate (theParent)
32{
33 myIcon = QIcon (theIcon);
34}
35
36// =======================================================================
37// function : paint
38// purpose :
39// =======================================================================
40void DFBrowserPane_ItemDelegateButton::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption,
41 const QModelIndex& theIndex) const
42{
0c80bdbf 43 if (myFreeRows.contains (theIndex.row()))
44 return;
45
46 int aWidth = std::min (theOption.rect.width(), ICON_SIZE);
47 int aHeight = std::min (theOption.rect.height(), ICON_SIZE);
48 QPoint aTopLeft = theOption.rect.topLeft();
49 thePainter->drawPixmap (QRect (theOption.rect.topLeft(), QPoint (aTopLeft.x() + aWidth, aTopLeft.y() + aHeight)),
50 myIcon.pixmap (ICON_SIZE, ICON_SIZE));
14bbbdcb 51}
52
53// =======================================================================
54// function : editorEvent
55// purpose :
56// =======================================================================
57bool DFBrowserPane_ItemDelegateButton::editorEvent (QEvent* theEvent, QAbstractItemModel* theModel,
58 const QStyleOptionViewItem& theOption, const QModelIndex& theIndex)
59{
60 if (theEvent->type() == QEvent::MouseButtonPress && !myFreeRows.contains (theIndex.row()))
61 emit buttonPressed (theIndex);
62
63 return QStyledItemDelegate::editorEvent (theEvent, theModel, theOption, theIndex);
64}