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