OSDN Git Service

Ver0.09pre
[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 3;
19 }
20
21 int ColorSampleModel::columnCount(const QModelIndex &parent) const
22 {
23     Q_UNUSED(parent);
24     return 2;
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[3][2] = {
34         { tr("通常"), tr("システム") },
35         { tr("マーク"), tr("隠し属性") },
36         { tr(""), tr("読取専用") }
37     };
38
39     switch (role) {
40     case Qt::DisplayRole:
41         return strText[index.row()][index.column()];
42
43     case Qt::FontRole:
44         return m_font;
45         break;
46
47     case Qt::BackgroundRole:
48         switch (index.column()) {
49         case 0:
50             switch (index.row()) {
51             case 0: return QBrush(m_colorMap->value("clrBgNormal"));
52             case 1: return QBrush(m_colorMap->value("clrBgMark"));
53             }
54             break;
55
56         case 1:
57             switch (index.row()) {
58             case 0:
59             case 1:
60             case 2:
61                 return QBrush(m_colorMap->value("clrBgNormal"));
62             }
63             break;
64         }
65         break;
66
67     case Qt::ForegroundRole:
68         switch (index.column()) {
69         case 0:
70             switch (index.row()) {
71             case 0: return QBrush(m_colorMap->value("clrFgNormal"));
72             case 1: return QBrush(m_colorMap->value("clrFgMark"));
73             }
74             break;
75
76         case 1:
77             switch (index.row()) {
78             case 0: return QBrush(m_colorMap->value("clrFgSystem"));
79             case 1: return QBrush(m_colorMap->value("clrFgHidden"));
80             case 2: return QBrush(m_colorMap->value("clrFgReadonly"));
81             }
82             break;
83         }
84         break;
85     }
86
87     return QVariant();
88 }