OSDN Git Service

Ver0.16
[gefu/Gefu.git] / colorsamplemodel.cpp
1 #include "colorsamplemodel.h"
2
3 #include <QBrush>
4
5 ColorSampleModel::ColorSampleModel(QObject *parent) :
6     QAbstractTableModel(parent)
7 {
8 }
9
10 void ColorSampleModel::setFont(const QFont &font)
11 {
12     m_font = font;
13 }
14
15 int ColorSampleModel::rowCount(const QModelIndex &parent) const
16 {
17     Q_UNUSED(parent);
18     return 5;
19 }
20
21 int ColorSampleModel::columnCount(const QModelIndex &parent) const
22 {
23     Q_UNUSED(parent);
24     return 3;
25 }
26
27 QVariant ColorSampleModel::data(const QModelIndex &index, int role) const
28 {
29     if (!index.isValid()) {
30         return QVariant();
31     }
32
33     const QString strText[5][3] = {
34         { tr("通常"), tr("<DIR>"), tr("12/34/56 78:90") },
35         { tr("マーク"), tr("123B"), tr("12/34/56 78:90") },
36         { tr("システム"), tr("456KB"), tr("12/34/56 78:90") },
37         { tr("隠し属性"), tr("789MB"), tr("12/34/56 78:90") },
38         { tr("読取専用"), tr("10.2GB"), tr("12/34/56 78:90") }
39     };
40
41     switch (role) {
42     case Qt::DisplayRole:
43         return strText[index.row()][index.column()];
44
45     case Qt::FontRole:
46         return m_font;
47         break;
48
49     case Qt::BackgroundRole:
50         if (index.row() == 1) {
51             return QBrush(m_colorMap->value("clrBgMark"));
52         }
53         else {
54             return QBrush(m_colorMap->value("clrBgNormal"));
55         }
56         break;
57
58     case Qt::ForegroundRole:
59         switch (index.row()) {
60         case 0: return QBrush(m_colorMap->value("clrFgNormal"));
61         case 1: return QBrush(m_colorMap->value("clrFgMark"));
62         case 2: return QBrush(m_colorMap->value("clrFgSystem"));
63         case 3: return QBrush(m_colorMap->value("clrFgHidden"));
64         case 4: return QBrush(m_colorMap->value("clrFgReadonly"));
65         break;
66         }
67     }
68
69     return QVariant();
70 }