28 #include <QApplication>
29 #include <QModelIndex>
30 #include <QMouseEvent>
33 #include <QStyleOptionViewItem>
44 QStyledItemDelegate(parent),
45 startPixmap(
":/icons/media-playback-start.ico"),
46 stopPixmap(
":/icons/process-stop-7.ico"),
47 restartPixmap(
":/icons/view-refresh-7.png")
54 QStyledItemDelegate::setEditorData(editor,
index);
59 QAbstractItemModel* model,
60 const QModelIndex&
index)
const
62 QStyledItemDelegate::setModelData(editor, model,
index);
67 const QStyleOptionViewItem&
option,
68 const QModelIndex&
index)
const
70 QStyleOptionButton button;
74 button.features = QStyleOptionButton::AutoDefaultButton;
76 int size = appIconSize;
77 if (!
index.parent().isValid())
79 size = scenarioIconSize;
81 if (
index.data().toString().compare(
"Start") == 0)
83 button.icon = startPixmap;
85 button.iconSize = QSize(size, size);
87 else if (
index.data().toString().compare(
"Stop") == 0)
89 button.icon = stopPixmap;
90 button.iconSize = QSize(size, size);
92 else if (
index.data().toString().compare(
"Restart") == 0)
94 button.icon = restartPixmap;
95 button.iconSize = QSize(size, size);
99 button.text =
index.data().toString();
102 if (
index.data().toString().compare(
"HIDE") == 0)
115 QStyle::State_Raised | QStyle::State_Enabled;
119 QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter, 0);
124 QAbstractItemModel* model,
125 const QStyleOptionViewItem&
option,
126 const QModelIndex&
index)
129 if ((buttonStates[
index] & QStyle::State_Enabled) == 0)
134 if (event->type() == QEvent::MouseButtonPress)
136 buttonStates[
index] = QStyle::State_Sunken | QStyle::State_Enabled;
140 else if (event->type() == QEvent::MouseButtonRelease)
142 buttonStates[
index] = QStyle::State_Raised | QStyle::State_Enabled;
144 <<
" " <<
index.column();
167 return scenarioIconSize;
173 scenarioIconSize =
value;
179 int size = appIconSize;
180 if (!
index.parent().isValid())
182 size = scenarioIconSize;
184 return QSize(
option.rect.width(),
option.rect.height() + size + 6);