MCPcopy Create free account
hub / github.com/davy7125/polyphone / drawRoot

Method drawRoot

sources/editor/tree/treeitemdelegate.cpp:136–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void TreeItemDelegate::drawRoot(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, bool expandable) const
137{
138 // Background
139 QRect rect = option.rect;
140 if (expandable)
141 rect.adjust(MARGIN - 2, MARGIN / 2, -MARGIN, -MARGIN / 2);
142 else
143 rect.adjust(MARGIN - 2, MARGIN, -MARGIN, -MARGIN / 2);
144 QPainterPath path;
145 path.addRoundedRect(rect, 2, 2);
146
147 bool highlighted = option.state & QStyle::State_Selected;
148 if (highlighted)
149 {
150 painter->fillPath(path, s_colors->_highlightColorBackground);
151
152 QPen pen(s_colors->_highlightColorBackground, 1);
153 painter->setPen(pen);
154 painter->drawPath(path);
155 }
156 else
157 {
158 painter->fillPath(path, s_colors->_alternateColor);
159
160 QPen pen(s_colors->_borderColor, 1);
161 painter->setPen(pen);
162 painter->drawPath(path);
163 }
164
165 // Right arrow
166 int rightAreaWidth = 0;
167 if (expandable)
168 {
169 const TreeView* view = qobject_cast<const TreeView*>(option.widget);
170 QPixmap pix = s_icons->getPixmap(view->isExpanded(index) ? "arrow_down" : "arrow_up",
171 highlighted ? ThemeManager::HIGHLIGHTED_TEXT : ThemeManager::LIST_TEXT, false);
172 int x = rect.right() - pix.width();
173 int y = rect.top() + (rect.height() - pix.height()) / 2;
174 painter->drawPixmap(x - MARGIN, y, pix);
175
176 painter->setPen(QPen(s_colors->_borderColor, 1));
177 painter->drawLine(x - 2 * MARGIN, rect.top(), x - 2 * MARGIN, rect.bottom());
178
179 rightAreaWidth = pix.width() + 2 * MARGIN;
180 }
181
182 // Font
183 QFont font = option.font;
184 font.setBold(true);
185 font.setPointSizeF(font.pointSizeF() * 1.2);
186
187 // Rect
188 QRect rectText = rect;
189 rectText.adjust(MARGIN, 0, -MARGIN - rightAreaWidth, 0);
190
191 // Text
192 QString text = index.data().toString();
193 QFontMetrics metrics(font);

Callers

nothing calls this directly

Calls 3

getPixmapMethod · 0.45
toStringMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected