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 | |
16 | #include <TInspectorEXE_OpenFileViewModel.hxx> |
17 | |
6822a3be |
18 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
19 | #include <QApplication> |
20 | #include <QFileInfo> |
21 | #include <QIcon> |
22 | #include <QPainter> |
6822a3be |
23 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
24 | |
25 | const int ICON_SIZE = 40; |
26 | |
27 | // ======================================================================= |
28 | // function : paint |
29 | // purpose : |
30 | // ======================================================================= |
31 | void TInspectorEXE_OpenFileItemDelegate::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, |
32 | const QModelIndex& theIndex) const |
33 | { |
34 | // highlight cell |
35 | if (theOption.state & QStyle::State_MouseOver) |
36 | thePainter->fillRect (theOption.rect, myColor); |
37 | |
38 | // action icon for all indices before the last one |
39 | QIcon anIcon (":/icons/folder_import.png"); |
40 | QSize anIconSize (ICON_SIZE, ICON_SIZE); |
6822a3be |
41 | int aDX = (theOption.rect.width() - anIconSize.width()) / 2; |
14bbbdcb |
42 | int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); |
6822a3be |
43 | thePainter->drawPixmap (QRect (theOption.rect.left() + aDX, |
14bbbdcb |
44 | theOption.rect.top() + aMargin, |
45 | anIconSize.width(), |
46 | anIconSize.height()), |
47 | anIcon.pixmap(anIconSize.width(), anIconSize.height())); |
48 | // default paint |
49 | QItemDelegate::paint (thePainter, theOption, theIndex); |
50 | } |
51 | |
52 | // ======================================================================= |
53 | // function : Init |
54 | // purpose : |
55 | // ======================================================================= |
56 | void TInspectorEXE_OpenFileViewModel::Init (const QStringList& theValues) |
57 | { |
58 | myValues = theValues; |
59 | } |
60 | |
61 | // ======================================================================= |
62 | // function : data |
63 | // purpose : |
64 | // ======================================================================= |
65 | QVariant TInspectorEXE_OpenFileViewModel::data (const QModelIndex& theIndex, int theRole) const |
66 | { |
67 | switch (theRole) |
68 | { |
69 | case Qt::DisplayRole: return QFileInfo (myValues[theIndex.column()]).fileName(); |
70 | case Qt::ToolTipRole: return myValues[theIndex.column()]; |
71 | case Qt::TextAlignmentRole: return QVariant (Qt::AlignBottom | Qt::AlignHCenter); |
72 | default: break; |
73 | } |
74 | return QVariant(); |
75 | } |