0029559: Samples - wrong copyright statement in FuncDemo
[occt.git] / tools / DFBrowserPane / DFBrowserPane_ItemDelegateButton.hxx
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
16 #ifndef DFBrowserPane_ItemDelegateButton_H
17 #define DFBrowserPane_ItemDelegateButton_H
18
19 #include <Standard.hxx>
20 #include <Standard_Macro.hxx>
21
22 #ifdef _MSC_VER
23 #pragma warning(disable : 4127) // conditional expression is constant
24 #endif
25 #include <QStyledItemDelegate>
26 #include <QStyleOptionViewItem>
27 #include <QModelIndex>
28 #include <QString>
29 #include <QIcon>
30
31 class QObject;
32 class QPainter;
33 class QEvent;
34 class QAbstractItemModel;
35
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
41 {
42   Q_OBJECT
43 public:
44
45   //! Constructor
46   Standard_EXPORT DFBrowserPane_ItemDelegateButton (QObject* theParent, const QString& theIcon);
47
48   //! Destructor
49   virtual ~DFBrowserPane_ItemDelegateButton() {}
50
51 public:
52
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; }
56
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;
63
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;
72 signals:
73
74   //! Signal about button pressing
75   //! \param theIndex an index of clicked item
76   void buttonPressed (const QModelIndex& theIndex);
77
78 private:
79
80   QIcon myIcon; //!< an item icon
81   QList<int> myFreeRows; //!< container of row indices where icon is not used
82 };
83
84 #endif