139584554faf297227c9eeefb2014cc4731cacfb
[occt.git] / tools / DFBrowser / DFBrowser_TreeLevelLineDelegate.cxx
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 #include <DFBrowser_TreeLevelLineDelegate.hxx>
17 #include <DFBrowser_Window.hxx>
18
19 #include <QPainter>
20
21 // =======================================================================
22 // function : Constructor
23 // purpose :
24 // =======================================================================
25 DFBrowser_TreeLevelLineDelegate::DFBrowser_TreeLevelLineDelegate (QObject* theParent)
26 : QItemDelegate (theParent)
27 {
28 }
29
30 // =======================================================================
31 // function : paint
32 // purpose :
33 // =======================================================================
34 void DFBrowser_TreeLevelLineDelegate::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption,
35                                              const QModelIndex& theIndex) const
36 {
37   // highlight cell
38   if (theOption.state & QStyle::State_MouseOver)
39     thePainter->fillRect (theOption.rect, DFBrowser_Window::LightHighlightColor());
40
41   // action icon for all indices before the last one
42   if (theIndex.column() < theIndex.model()->columnCount()-1)
43   {
44     QIcon anIcon (":/icons/level_change.png");
45     QSize anIconSize (10, 20);
46     thePainter->drawPixmap (QRect (theOption.rect.right() - anIconSize.width(), theOption.rect.top(),
47                                    anIconSize.width(), anIconSize.height()),
48                             anIcon.pixmap (anIconSize.width(), anIconSize.height()));
49   }
50   // default paint
51   QItemDelegate::paint (thePainter, theOption, theIndex);
52 }