1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef DFBrowserPane_ItemDelegateButton_H
17 #define DFBrowserPane_ItemDelegateButton_H
19 #include <Standard.hxx>
20 #include <Standard_Macro.hxx>
23 #pragma warning(disable : 4127) // conditional expression is constant
25 #include <QStyledItemDelegate>
26 #include <QStyleOptionViewItem>
27 #include <QModelIndex>
34 class QAbstractItemModel;
36 //! \class DFBrowserPane_ItemDelegateButton
37 //! \brief It paints an icon in all rows of the view in a separate column.
38 //! It is possible to set rows where this icon is not shown.
39 //! Click on the cell where the icon exists emits buttonPressed signal
40 class DFBrowserPane_ItemDelegateButton : public QStyledItemDelegate
46 Standard_EXPORT DFBrowserPane_ItemDelegateButton (QObject* theParent, const QString& theIcon);
49 virtual ~DFBrowserPane_ItemDelegateButton() {}
53 //! Stores indices of rows where the icon should not be shown
54 //! \param theRows an indices of rows
55 void SetFreeRows (const QList<int>& theRows) { myFreeRows = theRows; }
57 //! Draw an icon in the cell
58 //! \param thePainter a painter
59 //! \param theOption a paint options
60 //! \param theIndex a view index
61 Standard_EXPORT virtual void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption,
62 const QModelIndex& theIndex) const Standard_OVERRIDE;
64 //! Emits pressed signal if event type is mouse button pressed and there is icon for this index
65 //! After signal it calls the parent method
66 //! \param theEvent a processed event
67 //! \param theModel a current view model
68 //! \param theOption display options
69 //! \param theIndex an edited item
70 Standard_EXPORT virtual bool editorEvent (QEvent* theEvent, QAbstractItemModel* theModel,
71 const QStyleOptionViewItem& theOption, const QModelIndex& theIndex) Standard_OVERRIDE;
74 //! Signal about button pressing
75 //! \param theIndex an index of clicked item
76 void buttonPressed (const QModelIndex& theIndex);
80 QIcon myIcon; //!< an item icon
81 QList<int> myFreeRows; //!< container of row indices where icon is not used