1 /*
2  *
3  *   Ophcrack is a Lanmanager/NTLM hash cracker based on the faster time-memory
4  *   trade-off using rainbow tables.
5  *
6  *   Created with the help of: Maxime Mueller, Luca Wullschleger, Claude
7  *   Hochreutiner, Andreas Huber and Etienne Dysli.
8  *
9  *   Copyright (c) 2008 Philippe Oechslin, Cedric Tissieres, Bertrand Mesot
10  *
11  *   Ophcrack is free software; you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation; either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   Ophcrack is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Ophcrack; if not, write to the Free Software
23  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  *
25  *   This program is released under the GPL with the additional exemption
26  *   that compiling, linking, and/or using OpenSSL is allowed.
27  *
28  *
29  *
30  *
31 */
32 #include <QModelIndex>
33 #include <QPainter>
34 #include <math.h>
35 
36 #include "progdelegate.h"
37 #include "misc.h"
38 //---------------------------------------------------------------------------
ProgDelegate(QObject * parent)39 ProgDelegate::ProgDelegate(QObject *parent) : QItemDelegate(parent) {
40 }
41 //---------------------------------------------------------------------------
paint(QPainter * painter,const QStyleOptionViewItem & option,const QModelIndex & index) const42 void ProgDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
43 			 const QModelIndex &index) const {
44 
45   QVariant data = index.data(Qt::DisplayRole);
46 
47   if (data.isNull()) {
48     static const QColor green = QColor(143, 196, 66);
49     static const QColor red   = QColor(169, 52, 52);
50     const QColor dark = option.palette.dark().color();
51 
52     // Store the current status of the painter.
53 
54     painter->save();
55 
56     // Compute the coordinates of the progress bar.
57 
58     QRect rect = option.rect;
59     int width  = rect.width();
60     int height = rect.height();
61 
62     int dx = MY_MAX(2, (int)ceil(0.02*width));
63     int dy = MY_MAX(2, (int)ceil(0.05*height));
64 
65     rect.adjust(dx, dy, -dx, -dy);
66 
67     // Display the outline of the progress bar.
68 
69     painter->setPen(dark);
70     painter->drawRect(rect);
71 
72     rect.adjust(1, 1, 0, 0);
73     width = rect.width();
74 
75     // Display the two progress bars.
76 
77     QVariant data = index.data(Qt::UserRole);
78 
79     if (!data.isNull()) {
80       QPoint pt = data.toPoint();
81 
82       int ratio_cmin = pt.x();
83       int ratio_cmax = pt.y();
84 
85       QRect pbar1 = rect;
86       int width1 = (ratio_cmin*width) / 1000;
87 
88       pbar1.setWidth(width1);
89       painter->fillRect(pbar1, red);
90 
91       QRect pbar2 = rect;
92       int width2 = (ratio_cmax*width) / 1000;
93 
94       pbar2.setWidth(width2);
95       painter->fillRect(pbar2, green);
96     }
97 
98     // Restore the old status of the painter.
99 
100     painter->restore();
101   }
102 
103   else
104     QItemDelegate::paint(painter, option, index);
105 }
106