Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/KisNodeDelegate.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 98 | { | |||
---|---|---|---|---|---|
101 | style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, p, option.widget); | 101 | style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, p, option.widget); | ||
102 | 102 | | |||
103 | bool shouldGrayOut = index.data(KisNodeModel::ShouldGrayOutRole).toBool(); | 103 | bool shouldGrayOut = index.data(KisNodeModel::ShouldGrayOutRole).toBool(); | ||
104 | if (shouldGrayOut) { | 104 | if (shouldGrayOut) { | ||
105 | option.state &= ~QStyle::State_Enabled; | 105 | option.state &= ~QStyle::State_Enabled; | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | p->setFont(option.font); | 108 | p->setFont(option.font); | ||
109 | | ||||
110 | drawColorLabel(p, option, index); | 109 | drawColorLabel(p, option, index); | ||
111 | drawFrame(p, option, index); | 110 | drawFrame(p, option, index); | ||
112 | drawThumbnail(p, option, index); | 111 | drawThumbnail(p, option, index); | ||
113 | drawText(p, option, index); | 112 | drawText(p, option, index); // BUG: Creating group moves things around (RTL-layout alignment) | ||
114 | drawIcons(p, option, index); | 113 | drawIcons(p, option, index); | ||
115 | drawVisibilityIconHijack(p, option, index); | 114 | drawVisibilityIconHijack(p, option, index); // TODO hide when dragging | ||
116 | drawDecoration(p, option, index); | 115 | drawDecoration(p, option, index); | ||
117 | drawExpandButton(p, option, index); | 116 | drawExpandButton(p, option, index); | ||
118 | drawBranch(p, option, index); | 117 | drawBranch(p, option, index); | ||
119 | 118 | | |||
120 | drawProgressBar(p, option, index); | 119 | drawProgressBar(p, option, index); | ||
121 | } | 120 | } | ||
122 | p->restore(); | 121 | p->restore(); | ||
123 | } | 122 | } | ||
124 | 123 | | |||
125 | void KisNodeDelegate::drawBranch(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { | 124 | void KisNodeDelegate::drawBranch(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
126 | Q_UNUSED(index); | 125 | { | ||
126 | QModelIndex tmp = index.parent(); | ||||
127 | | ||||
128 | // there is no indention if we have no parent group, so don't draw a branch | ||||
129 | if (!tmp.isValid()) return; | ||||
127 | 130 | | |||
128 | KisNodeViewColorScheme scm; | 131 | KisNodeViewColorScheme scm; | ||
129 | const QPoint base = scm.relThumbnailRect().translated(option.rect.topLeft()).topLeft() - QPoint( scm.indentation(), 0); | | |||
130 | 132 | | |||
131 | // there is no indention if we are starting negative, so don't draw a branch | 133 | int rtlNum = (option.direction == Qt::RightToLeft) ? 1 : -1; | ||
132 | if (base.x() < 0) { | 134 | | ||
133 | return; | 135 | QRect baseRect = scm.relThumbnailRect(); | ||
136 | | ||||
137 | // Move to current index | ||||
138 | baseRect.moveTop(option.rect.topLeft().y()); | ||||
139 | // Move to correct location. | ||||
140 | if (option.direction == Qt::RightToLeft) { | ||||
141 | baseRect.moveLeft(option.rect.topRight().x()); | ||||
142 | } else { | ||||
143 | baseRect.moveRight(option.rect.topLeft().x()); | ||||
134 | } | 144 | } | ||
135 | 145 | | |||
146 | QPoint base = baseRect.adjusted(rtlNum*scm.indentation(), 0, | ||||
147 | rtlNum*scm.indentation(), 0).center() + QPoint(0, scm.iconSize()/4); | ||||
136 | 148 | | |||
137 | QPen oldPen = p->pen(); | 149 | QPen oldPen = p->pen(); | ||
138 | const qreal oldOpacity = p->opacity(); // remember previous opacity | 150 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||
139 | p->setOpacity(1.0); | 151 | p->setOpacity(1.0); | ||
140 | 152 | | |||
141 | QColor color = scm.gridColor(option, d->view); | 153 | QColor color = scm.gridColor(option, d->view); | ||
142 | QColor bgColor = option.state & QStyle::State_Selected ? | 154 | QColor bgColor = option.state & QStyle::State_Selected ? | ||
143 | qApp->palette().color(QPalette::Base) : | 155 | qApp->palette().color(QPalette::Base) : | ||
144 | qApp->palette().color(QPalette::Text); | 156 | qApp->palette().color(QPalette::Text); | ||
145 | color = KritaUtils::blendColors(color, bgColor, 0.9); | 157 | color = KritaUtils::blendColors(color, bgColor, 0.9); | ||
146 | 158 | | |||
147 | | ||||
148 | // TODO: if we are a mask type, use dotted lines for the branch style | 159 | // TODO: if we are a mask type, use dotted lines for the branch style | ||
149 | // p->setPen(QPen(p->pen().color(), 2, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin)); | 160 | // p->setPen(QPen(p->pen().color(), 2, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin)); | ||
150 | p->setPen(QPen(color, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); | 161 | p->setPen(QPen(color, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); | ||
151 | 162 | | |||
152 | QPoint p2 = base + QPoint(scm.iconSize() - scm.decorationMargin()*2, scm.iconSize()*0.45); | 163 | QPoint p2 = base - QPoint(rtlNum*(scm.iconSize()/2), 0); | ||
153 | QPoint p3 = base + QPoint(scm.iconSize() - scm.decorationMargin()*2, scm.iconSize()); | 164 | QPoint p3 = base - QPoint(0, scm.iconSize()/2); | ||
154 | QPoint p4 = base + QPoint(scm.iconSize()*1.4, scm.iconSize()); | 165 | p->drawLine(base, p2); | ||
155 | p->drawLine(p2, p3); | 166 | p->drawLine(base, p3); | ||
156 | p->drawLine(p3, p4); | | |||
157 | | ||||
158 | | ||||
159 | 167 | | |||
160 | // draw parent lines (keep drawing until x position is less than 0 | 168 | // draw parent lines (keep drawing until x position is less than 0 | ||
161 | QPoint p5 = p2 - QPoint(scm.indentation(), 0); | 169 | QPoint parentBase1 = base + QPoint(rtlNum*scm.indentation(), 0); | ||
162 | QPoint p6 = p3 - QPoint(scm.indentation(), 0); | 170 | QPoint parentBase2 = p3 + QPoint(rtlNum*scm.indentation(), 0); | ||
163 | | ||||
164 | QPoint parentBase1 = p5; | | |||
165 | QPoint parentBase2 = p6; | | |||
166 | 171 | | |||
167 | // indent lines needs to be very subtle to avoid making the docker busy looking | 172 | // indent lines needs to be very subtle to avoid making the docker busy looking | ||
168 | color = KritaUtils::blendColors(color, bgColor, 0.9); // makes it a little lighter than L lines | 173 | color = KritaUtils::blendColors(color, bgColor, 0.9); // makes it a little lighter than L lines | ||
169 | p->setPen(QPen(color, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); | 174 | p->setPen(QPen(color, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); | ||
170 | 175 | | |||
171 | while (parentBase1.x() > scm.visibilityColumnWidth()) { | 176 | if (tmp.isValid()) { | ||
172 | p->drawLine(parentBase1, parentBase2); | 177 | tmp = tmp.parent(); // Ignore the first group as it was already painted | ||
173 | | ||||
174 | parentBase1 = parentBase1 - QPoint(scm.indentation(), 0); | | |||
175 | parentBase2 = parentBase2 - QPoint(scm.indentation(), 0); | | |||
176 | } | 178 | } | ||
179 | while (tmp.isValid()) { | ||||
180 | p->drawLine(parentBase1, parentBase2); | ||||
177 | 181 | | |||
182 | parentBase1 += QPoint(rtlNum*scm.indentation(), 0); | ||||
183 | parentBase2 += QPoint(rtlNum*scm.indentation(), 0); | ||||
178 | 184 | | |||
179 | 185 | tmp = tmp.parent(); | |||
186 | } | ||||
180 | 187 | | |||
181 | p->setPen(oldPen); | 188 | p->setPen(oldPen); | ||
182 | p->setOpacity(oldOpacity); | 189 | p->setOpacity(oldOpacity); | ||
183 | } | 190 | } | ||
184 | 191 | | |||
185 | void KisNodeDelegate::drawColorLabel(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 192 | void KisNodeDelegate::drawColorLabel(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
186 | { | 193 | { | ||
187 | KisNodeViewColorScheme scm; | 194 | KisNodeViewColorScheme scm; | ||
188 | const int label = index.data(KisNodeModel::ColorLabelIndexRole).toInt(); | 195 | const int label = index.data(KisNodeModel::ColorLabelIndexRole).toInt(); | ||
189 | QColor color = scm.colorLabel(label); | 196 | QColor color = scm.colorLabel(label); | ||
190 | if (color.alpha() <= 0) return; | 197 | if (color.alpha() <= 0) return; | ||
191 | 198 | | |||
192 | QColor bgColor = qApp->palette().color(QPalette::Base); | 199 | QColor bgColor = qApp->palette().color(QPalette::Base); | ||
200 | if ((option.state & QStyle::State_MouseOver) && !(option.state & QStyle::State_Selected)) { | ||||
201 | color = KritaUtils::blendColors(color, bgColor, 0.6); | ||||
202 | } else { | ||||
193 | color = KritaUtils::blendColors(color, bgColor, 0.3); | 203 | color = KritaUtils::blendColors(color, bgColor, 0.3); | ||
204 | } | ||||
205 | | ||||
206 | QRect optionRect = option.rect.adjusted(0, 0, scm.indentation(), 0); | ||||
207 | if (option.state & QStyle::State_Selected) { | ||||
208 | optionRect = iconsRect(option, index); | ||||
209 | } | ||||
194 | 210 | | |||
195 | const QRect rect = option.state & QStyle::State_Selected ? | 211 | if (option.direction == Qt::RightToLeft) { | ||
196 | iconsRect(option, index) : | 212 | optionRect.moveLeft(option.rect.topLeft().x()); | ||
197 | option.rect.adjusted(-scm.indentation(), 0, 0, 0); | 213 | } else { | ||
214 | optionRect.moveRight(option.rect.topRight().x()); | ||||
215 | } | ||||
198 | 216 | | |||
199 | p->fillRect(rect, color); | 217 | p->fillRect(optionRect, color); | ||
200 | } | 218 | } | ||
201 | 219 | | |||
202 | void KisNodeDelegate::drawFrame(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 220 | void KisNodeDelegate::drawFrame(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
203 | { | 221 | { | ||
204 | KisNodeViewColorScheme scm; | 222 | KisNodeViewColorScheme scm; | ||
205 | 223 | | |||
206 | QPen oldPen = p->pen(); | 224 | QPen oldPen = p->pen(); | ||
207 | p->setPen(scm.gridColor(option, d->view)); | 225 | p->setPen(scm.gridColor(option, d->view)); | ||
208 | 226 | | |||
209 | const QPoint base = option.rect.topLeft(); | 227 | const QRect visibilityRect = visibilityClickRect(option, index); | ||
228 | const QRect thumbnailRect = thumbnailClickRect(option, index); | ||||
229 | const QRect decorationRect = decorationClickRect(option, index); | ||||
230 | const QRect iconsRectR = iconsRect(option, index); | ||||
210 | 231 | | |||
211 | QPoint p2 = base + QPoint(-scm.indentation() - 1, 0); | 232 | const float topY = thumbnailRect.topLeft().y(); | ||
212 | QPoint p3 = base + QPoint(2 * scm.decorationMargin() + scm.decorationSize(), 0); | 233 | const float bottomY = thumbnailRect.bottomLeft().y(); | ||
213 | QPoint p4 = base + QPoint(-1, 0); | 234 | | ||
214 | QPoint p5(iconsRect(option, | 235 | QPoint bottomLeftPoint; | ||
215 | index).left() - 1, base.y()); | 236 | QPoint bottomRightPoint; | ||
216 | QPoint p6(option.rect.right(), base.y()); | 237 | if (option.direction == Qt::RightToLeft) { | ||
217 | 238 | bottomLeftPoint = iconsRectR.bottomLeft(); | |||
218 | QPoint v(0, option.rect.height()); | 239 | bottomRightPoint = visibilityRect.bottomRight(); | ||
219 | 240 | } else { | |||
220 | 241 | bottomLeftPoint = visibilityRect.bottomLeft(); | |||
221 | // draw a line that goes the length of the entire frame. one for the | 242 | bottomRightPoint = iconsRectR.bottomRight(); | ||
222 | // top, and one for the bottom | | |||
223 | QPoint pTopLeft(0, option.rect.topLeft().y()); | | |||
224 | QPoint pTopRight(option.rect.bottomRight().x(),option.rect.topLeft().y() ); | | |||
225 | p->drawLine(pTopLeft, pTopRight); | | |||
226 | | ||||
227 | QPoint pBottomLeft(0, option.rect.topLeft().y() + scm.rowHeight()); | | |||
228 | QPoint pBottomRight(option.rect.bottomRight().x(),option.rect.topLeft().y() + scm.rowHeight() ); | | |||
229 | p->drawLine(pBottomLeft, pBottomRight); | | |||
230 | | ||||
231 | | ||||
232 | const bool paintForParent = | | |||
233 | index.parent().isValid() && | | |||
234 | !index.row(); | | |||
235 | | ||||
236 | if (paintForParent) { | | |||
237 | QPoint p1(-2 * scm.indentation() - 1, 0); | | |||
238 | p1 += base; | | |||
239 | p->drawLine(p1, p2); | | |||
240 | } | 243 | } | ||
241 | 244 | | |||
245 | // top running horizontal line, do not double at top | ||||
246 | // if (!index.row() != 0) | ||||
247 | // p->drawLine(bottomLeftPoint.x(), topY, | ||||
248 | // bottomRightPoint.x(), topY); | ||||
249 | | ||||
250 | // bottom running horizontal line | ||||
251 | p->drawLine(bottomLeftPoint.x(), bottomY, | ||||
252 | bottomRightPoint.x(), bottomY); | ||||
253 | | ||||
254 | // visiblity icon vertical line - left | ||||
255 | p->drawLine(visibilityRect.topLeft().x()-1, topY, | ||||
256 | visibilityRect.bottomLeft().x()-1, bottomY); | ||||
257 | | ||||
258 | // visiblity icon vertical line - right | ||||
259 | p->drawLine(visibilityRect.topRight().x()+1, topY, | ||||
260 | visibilityRect.bottomRight().x()+1, bottomY); | ||||
261 | | ||||
262 | // thumbnail vertical line - left | ||||
263 | p->drawLine(thumbnailRect.topLeft().x(), topY, | ||||
264 | thumbnailRect.bottomLeft().x(), bottomY); | ||||
265 | | ||||
266 | // thumbnail vertical line - right | ||||
267 | p->drawLine(thumbnailRect.topRight().x(), topY, | ||||
268 | thumbnailRect.bottomRight().x(), bottomY); | ||||
269 | | ||||
270 | // decoration vertical line - left | ||||
271 | p->drawLine(decorationRect.topLeft().x(), topY, | ||||
272 | decorationRect.bottomLeft().x(), bottomY); | ||||
273 | | ||||
274 | // decoration vertical line - right | ||||
275 | p->drawLine(decorationRect.topRight().x(), topY, | ||||
276 | decorationRect.bottomRight().x(), bottomY); | ||||
242 | 277 | | |||
243 | QPoint k0(0, base.y()); | 278 | // icons' lines are drawn by drawIcons | ||
244 | QPoint k1(1 * scm.border() + 2 * scm.visibilityMargin() + scm.visibilitySize(), base.y()); | | |||
245 | p->drawLine(k0, k1); | | |||
246 | p->drawLine(k0 + v, k1 + v); | | |||
247 | p->drawLine(k0, k0 + v); | | |||
248 | p->drawLine(k1, k1 + v); | | |||
249 | | ||||
250 | p->drawLine(p2, p6); | | |||
251 | p->drawLine(p2 + v, p6 + v); | | |||
252 | p->drawLine(p2, p2 + v); | | |||
253 | p->drawLine(p3, p3 + v); | | |||
254 | p->drawLine(p4, p4 + v); | | |||
255 | p->drawLine(p5, p5 + v); | | |||
256 | p->drawLine(p6, p6 + v); | | |||
257 | 279 | | |||
258 | //// For debugging purposes only | 280 | //// For debugging purposes only | ||
259 | //p->setPen(Qt::blue); | 281 | p->setPen(Qt::blue); | ||
260 | //KritaUtils::renderExactRect(p, iconsRect(option, index)); | 282 | //KritaUtils::renderExactRect(p, iconsRectR); | ||
261 | //KritaUtils::renderExactRect(p, textRect(option, index)); | 283 | //KritaUtils::renderExactRect(p, textRect(option, index)); | ||
262 | //KritaUtils::renderExactRect(p, scm.relThumbnailRect().translated(option.rect.topLeft())); | 284 | //KritaUtils::renderExactRect(p, visibilityRect); | ||
263 | 285 | | |||
264 | p->setPen(oldPen); | 286 | p->setPen(oldPen); | ||
265 | } | 287 | } | ||
266 | 288 | | |||
267 | QRect KisNodeDelegate::thumbnailClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 289 | QRect KisNodeDelegate::thumbnailClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
268 | { | 290 | { | ||
269 | Q_UNUSED(index); | 291 | Q_UNUSED(index); | ||
292 | KisNodeViewColorScheme scm; | ||||
270 | 293 | | |||
271 | int steps = 0; | 294 | QRect rc = scm.relThumbnailRect(); | ||
272 | QModelIndex tmp = index.parent(); | 295 | | ||
273 | while (tmp.isValid()) { | 296 | // Move to current index | ||
274 | steps++; | 297 | rc.moveTop(option.rect.topLeft().y()); | ||
275 | tmp = tmp.parent(); | 298 | // Move to correct location. | ||
299 | if (option.direction == Qt::RightToLeft) { | ||||
300 | rc.moveLeft(option.rect.topRight().x()); | ||||
301 | } else { | ||||
302 | rc.moveRight(option.rect.topLeft().x()); | ||||
276 | } | 303 | } | ||
277 | 304 | | |||
278 | KisNodeViewColorScheme scm; | 305 | return rc; | ||
279 | return QRect(scm.border() + | | |||
280 | 2 * scm.visibilityMargin() + scm.visibilitySize() + | | |||
281 | scm.border() + steps * scm.indentation(), | | |||
282 | scm.border() + option.rect.top(), | | |||
283 | 2 * scm.thumbnailMargin() + scm.thumbnailSize(), | | |||
284 | scm.rowHeight() - scm.border()); | | |||
285 | } | 306 | } | ||
286 | 307 | | |||
287 | void KisNodeDelegate::drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 308 | void KisNodeDelegate::drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
288 | { | 309 | { | ||
289 | KisNodeViewColorScheme scm; | 310 | KisNodeViewColorScheme scm; | ||
290 | 311 | | |||
291 | const int thumbSize = scm.thumbnailSize(); | 312 | const int thumbSize = scm.thumbnailSize(); | ||
292 | const qreal oldOpacity = p->opacity(); // remember previous opacity | 313 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||
293 | 314 | | |||
294 | QImage img = index.data(int(KisNodeModel::BeginThumbnailRole) + thumbSize).value<QImage>(); | 315 | QImage img = index.data(int(KisNodeModel::BeginThumbnailRole) + thumbSize).value<QImage>(); | ||
295 | if (!(option.state & QStyle::State_Enabled)) { | 316 | if (!(option.state & QStyle::State_Enabled)) { | ||
296 | p->setOpacity(0.35); | 317 | p->setOpacity(0.35); | ||
297 | } | 318 | } | ||
298 | 319 | | |||
299 | QRect fitRect = scm.relThumbnailRect().translated(option.rect.topLeft()); | 320 | QRect fitRect = thumbnailClickRect(option, index); | ||
300 | 321 | // Shrink to icon rect | |||
301 | QPoint offset; | 322 | fitRect = kisGrowRect(fitRect, -(scm.thumbnailMargin()+scm.border())); | ||
302 | offset.setX((fitRect.width() - img.width()) / 2); | | |||
303 | offset.setY((fitRect.height() - img.height()) / 2); | | |||
304 | offset += fitRect.topLeft(); | | |||
305 | 323 | | |||
306 | // paint in a checkerboard pattern behind the layer contents to represent transparent | 324 | // paint in a checkerboard pattern behind the layer contents to represent transparent | ||
307 | const int step = scm.thumbnailSize() / 6; | 325 | const int step = scm.thumbnailSize() / 6; | ||
308 | QImage checkers(2 * step, 2 * step, QImage::Format_ARGB32); | 326 | QImage checkers(2 * step, 2 * step, QImage::Format_ARGB32); | ||
309 | QPainter gc(&checkers); | 327 | QPainter gc(&checkers); | ||
310 | gc.fillRect(QRect(0, 0, step, step), d->checkersColor1); | 328 | gc.fillRect(QRect(0, 0, step, step), d->checkersColor1); | ||
311 | gc.fillRect(QRect(step, 0, step, step), d->checkersColor2); | 329 | gc.fillRect(QRect(step, 0, step, step), d->checkersColor2); | ||
312 | gc.fillRect(QRect(step, step, step, step), d->checkersColor1); | 330 | gc.fillRect(QRect(step, step, step, step), d->checkersColor1); | ||
313 | gc.fillRect(QRect(0, step, step, step), d->checkersColor2); | 331 | gc.fillRect(QRect(0, step, step, step), d->checkersColor2); | ||
314 | 332 | | |||
315 | QBrush brush(checkers); | 333 | QBrush brush(checkers); | ||
316 | p->setBrushOrigin(offset); | 334 | p->fillRect(fitRect, brush); | ||
317 | p->fillRect(img.rect().translated(offset), brush); | | |||
318 | 335 | | |||
319 | p->drawImage(offset, img); | 336 | p->drawImage(fitRect, img); | ||
320 | p->setOpacity(oldOpacity); // restore old opacity | 337 | p->setOpacity(oldOpacity); // restore old opacity | ||
321 | 338 | | |||
322 | QRect borderRect = kisGrowRect(img.rect(), 1).translated(offset); | 339 | QRect borderRect = kisGrowRect(fitRect, 1); | ||
323 | KritaUtils::renderExactRect(p, borderRect, scm.gridColor(option, d->view)); | 340 | KritaUtils::renderExactRect(p, borderRect, scm.gridColor(option, d->view)); | ||
324 | } | 341 | } | ||
325 | 342 | | |||
326 | QRect KisNodeDelegate::iconsRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 343 | QRect KisNodeDelegate::iconsRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
327 | { | 344 | { | ||
328 | KisNodeViewColorScheme scm; | 345 | KisNodeViewColorScheme scm; | ||
329 | 346 | | |||
330 | int propCount = d->numProperties(index); | 347 | int propCount = d->numProperties(index); | ||
331 | 348 | | |||
332 | const int iconsWidth = | 349 | const int iconsWidth = | ||
333 | propCount * (scm.iconSize() + 2 * scm.iconMargin()) + | 350 | propCount * (scm.iconSize() + 2 * scm.iconMargin()) + | ||
334 | (propCount - 1) * scm.border(); | 351 | (propCount + 1) * scm.border(); | ||
352 | | ||||
353 | QRect fitRect = QRect(0, 0, | ||||
354 | iconsWidth, scm.rowHeight() - scm.border()); | ||||
355 | // Move to current index | ||||
356 | fitRect.moveTop(option.rect.topLeft().y()); | ||||
357 | // Move to correct location. | ||||
358 | if (option.direction == Qt::RightToLeft) { | ||||
359 | fitRect.moveLeft(option.rect.topLeft().x()); | ||||
360 | } else { | ||||
361 | fitRect.moveRight(option.rect.topRight().x()); | ||||
362 | } | ||||
335 | 363 | | |||
336 | const int x = option.rect.x() + option.rect.width() | 364 | return fitRect; | ||
337 | - (iconsWidth + scm.border()); | | |||
338 | const int y = option.rect.y() + scm.border(); | | |||
339 | | ||||
340 | return QRect(x, y, | | |||
341 | iconsWidth, | | |||
342 | scm.rowHeight() - scm.border()); | | |||
343 | } | 365 | } | ||
344 | 366 | | |||
345 | QRect KisNodeDelegate::textRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 367 | QRect KisNodeDelegate::textRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
346 | { | 368 | { | ||
347 | KisNodeViewColorScheme scm; | 369 | KisNodeViewColorScheme scm; | ||
348 | 370 | | |||
349 | static QFont f; | 371 | static QFont f; | ||
350 | static int minbearing = 1337 + 666; //can be 0 or negative, 2003 is less likely | 372 | static int minbearing = 1337 + 666; //can be 0 or negative, 2003 is less likely | ||
351 | if (minbearing == 2003 || f != option.font) { | 373 | if (minbearing == 2003 || f != option.font) { | ||
352 | f = option.font; //getting your bearings can be expensive, so we cache them | 374 | f = option.font; //getting your bearings can be expensive, so we cache them | ||
353 | minbearing = option.fontMetrics.minLeftBearing() + option.fontMetrics.minRightBearing(); | 375 | minbearing = option.fontMetrics.minLeftBearing() + option.fontMetrics.minRightBearing(); | ||
354 | } | 376 | } | ||
355 | 377 | | |||
356 | const int decorationOffset = | 378 | const QRect decoRect = decorationClickRect(option, index); | ||
357 | 2 * scm.border() + | 379 | const QRect iconRect = iconsRect(option, index); | ||
358 | 2 * scm.decorationMargin() + | 380 | | ||
359 | scm.decorationSize(); | 381 | QRect rc = QRect((option.direction == Qt::RightToLeft) ? iconRect.topRight() : decoRect.topRight(), | ||
360 | 382 | (option.direction == Qt::RightToLeft) ? decoRect.bottomLeft() : iconRect.bottomLeft()); | |||
361 | const int width = | 383 | rc.adjust(-(scm.border()+minbearing), 0, | ||
362 | iconsRect(option, index).left() - option.rect.x() - | 384 | (scm.border()+minbearing), 0); | ||
363 | scm.border() + minbearing - decorationOffset; | 385 | | ||
364 | 386 | return rc; | |||
365 | return QRect(option.rect.x() - minbearing + decorationOffset, | | |||
366 | option.rect.y() + scm.border(), | | |||
367 | width, | | |||
368 | scm.rowHeight() - scm.border()); | | |||
369 | } | 387 | } | ||
370 | 388 | | |||
371 | void KisNodeDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 389 | void KisNodeDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
372 | { | 390 | { | ||
373 | KisNodeViewColorScheme scm; | 391 | KisNodeViewColorScheme scm; | ||
374 | const QRect rc = textRect(option, index) | 392 | const QRect rc = textRect(option, index).adjusted(scm.textMargin(), 0, | ||
375 | .adjusted(scm.textMargin(), 0, -scm.textMargin(), 0); | 393 | -scm.textMargin(), 0); | ||
376 | 394 | | |||
377 | QPen oldPen = p->pen(); | 395 | QPen oldPen = p->pen(); | ||
378 | const qreal oldOpacity = p->opacity(); // remember previous opacity | 396 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||
379 | 397 | | |||
380 | p->setPen(option.palette.color(QPalette::Active,QPalette::Text )); | 398 | p->setPen(option.palette.color(QPalette::Active,QPalette::Text )); | ||
381 | 399 | | |||
382 | | ||||
383 | | ||||
384 | if (!(option.state & QStyle::State_Enabled)) { | 400 | if (!(option.state & QStyle::State_Enabled)) { | ||
385 | p->setOpacity(0.55); | 401 | p->setOpacity(0.55); | ||
386 | } | 402 | } | ||
387 | 403 | | |||
388 | | ||||
389 | const QString text = index.data(Qt::DisplayRole).toString(); | 404 | const QString text = index.data(Qt::DisplayRole).toString(); | ||
390 | const QString elided = elidedText(p->fontMetrics(), rc.width(), Qt::ElideRight, text); | 405 | const QString elided = p->fontMetrics().elidedText(text, Qt::ElideRight, rc.width()); | ||
406 | p->setLayoutDirection(text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight); | ||||
391 | p->drawText(rc, Qt::AlignLeft | Qt::AlignVCenter, elided); | 407 | p->drawText(rc, Qt::AlignLeft | Qt::AlignVCenter, elided); | ||
392 | 408 | | |||
393 | p->setPen(oldPen); // restore pen settings | 409 | p->setPen(oldPen); // restore pen settings | ||
394 | p->setOpacity(oldOpacity); | 410 | p->setOpacity(oldOpacity); | ||
395 | } | 411 | } | ||
396 | 412 | | |||
397 | QList<OptionalProperty> KisNodeDelegate::Private::rightmostProperties(const KisBaseNode::PropertyList &props) const | 413 | QList<OptionalProperty> KisNodeDelegate::Private::rightmostProperties(const KisBaseNode::PropertyList &props) const | ||
398 | { | 414 | { | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 477 | { | |||
468 | } | 484 | } | ||
469 | 485 | | |||
470 | return 0; | 486 | return 0; | ||
471 | } | 487 | } | ||
472 | 488 | | |||
473 | void KisNodeDelegate::drawIcons(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 489 | void KisNodeDelegate::drawIcons(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
474 | { | 490 | { | ||
475 | KisNodeViewColorScheme scm; | 491 | KisNodeViewColorScheme scm; | ||
476 | const QRect r = iconsRect(option, index); | 492 | const QRect rc = iconsRect(option, index); | ||
493 | qDebug() << rc; | ||||
dkazakov: Please remove this debug before comitting :) | |||||
477 | 494 | | |||
478 | QTransform oldTransform = p->transform(); | 495 | QTransform oldTransform = p->transform(); | ||
479 | QPen oldPen = p->pen(); | 496 | QPen oldPen = p->pen(); | ||
480 | p->setTransform(QTransform::fromTranslate(r.x(), r.y())); | 497 | p->setTransform(QTransform::fromTranslate(rc.x(), rc.y())); | ||
481 | p->setPen(scm.gridColor(option, d->view)); | 498 | p->setPen(scm.gridColor(option, d->view)); | ||
482 | 499 | | |||
483 | int x = 0; | 500 | int x = 0; | ||
484 | const int y = (scm.rowHeight() - scm.border() - scm.iconSize()) / 2; | 501 | const int y = (scm.rowHeight() - scm.border() - scm.iconSize()) / 2; | ||
485 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | 502 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | ||
486 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | 503 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | ||
487 | 504 | | |||
505 | if (option.direction == Qt::RightToLeft) { | ||||
506 | std::reverse(realProps.begin(), realProps.end()); | ||||
507 | } | ||||
508 | | ||||
488 | Q_FOREACH (OptionalProperty prop, realProps) { | 509 | Q_FOREACH (OptionalProperty prop, realProps) { | ||
510 | if (option.direction == Qt::LeftToRight) | ||||
511 | p->drawLine(x, 0, x, scm.rowHeight() - scm.border()); | ||||
512 | | ||||
489 | x += scm.iconMargin(); | 513 | x += scm.iconMargin(); | ||
490 | if (prop) { | 514 | if (prop) { | ||
491 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | 515 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | ||
492 | bool fullColor = prop->state.toBool() && option.state & QStyle::State_Enabled; | 516 | bool fullColor = prop->state.toBool() && option.state & QStyle::State_Enabled; | ||
493 | const qreal oldOpacity = p->opacity(); // remember previous opacity | | |||
494 | | ||||
495 | 517 | | |||
518 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||||
496 | if (fullColor) { | 519 | if (fullColor) { | ||
497 | p->setOpacity(1.0); | 520 | p->setOpacity(1.0); | ||
498 | } | 521 | } | ||
499 | else { | 522 | else { | ||
500 | p->setOpacity(0.35); | 523 | p->setOpacity(0.35); | ||
501 | } | 524 | } | ||
502 | 525 | | |||
503 | p->drawPixmap(x, y, icon.pixmap(scm.iconSize(), QIcon::Normal)); | 526 | p->drawPixmap(x, y, icon.pixmap(scm.iconSize(), QIcon::Normal)); | ||
504 | p->setOpacity(oldOpacity); // restore old opacity | 527 | p->setOpacity(oldOpacity); // restore old opacity | ||
505 | | ||||
506 | | ||||
507 | } | 528 | } | ||
508 | x += scm.iconSize() + scm.iconMargin(); | 529 | x += scm.iconSize() + scm.iconMargin(); | ||
530 | | ||||
531 | if (!(option.direction == Qt::LeftToRight)) | ||||
509 | p->drawLine(x, 0, x, scm.rowHeight() - scm.border()); | 532 | p->drawLine(x, 0, x, scm.rowHeight() - scm.border()); | ||
510 | x += scm.border(); | 533 | x += scm.border(); | ||
511 | } | 534 | } | ||
512 | 535 | | |||
513 | p->setTransform(oldTransform); | 536 | p->setTransform(oldTransform); | ||
514 | p->setPen(oldPen); | 537 | p->setPen(oldPen); | ||
515 | } | 538 | } | ||
516 | 539 | | |||
517 | QRect KisNodeDelegate::visibilityClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 540 | QRect KisNodeDelegate::visibilityClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
518 | { | 541 | { | ||
519 | Q_UNUSED(index); | 542 | Q_UNUSED(index); | ||
520 | KisNodeViewColorScheme scm; | 543 | KisNodeViewColorScheme scm; | ||
521 | return QRect(scm.border(), scm.border() + option.rect.top(), | 544 | | ||
522 | 2 * scm.visibilityMargin() + scm.visibilitySize(), | 545 | QRect rc = scm.relVisibilityRect(); | ||
523 | scm.rowHeight() - scm.border()); | 546 | rc.setHeight(scm.rowHeight()); | ||
547 | | ||||
548 | // Move to current index | ||||
549 | rc.moveCenter(option.rect.center()); | ||||
550 | // Move to correct location. | ||||
551 | if (option.direction == Qt::RightToLeft) { | ||||
552 | // HACK: Without the -5, the right edge is outside the view | ||||
553 | rc.moveRight(d->view->width()-5); | ||||
554 | } else { | ||||
555 | rc.moveLeft(0); | ||||
556 | } | ||||
557 | | ||||
558 | return rc; | ||||
524 | } | 559 | } | ||
525 | 560 | | |||
526 | QRect KisNodeDelegate::decorationClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 561 | QRect KisNodeDelegate::decorationClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
527 | { | 562 | { | ||
528 | Q_UNUSED(option); | | |||
529 | Q_UNUSED(index); | 563 | Q_UNUSED(index); | ||
530 | KisNodeViewColorScheme scm; | 564 | KisNodeViewColorScheme scm; | ||
531 | 565 | | |||
532 | QRect realVisualRect = d->view->originalVisualRect(index); | 566 | QRect rc = scm.relDecorationRect(); | ||
533 | 567 | | |||
534 | return QRect(realVisualRect.left(), scm.border() + realVisualRect.top(), | 568 | // Move to current index | ||
535 | 2 * scm.decorationMargin() + scm.decorationSize(), | 569 | rc.moveTop(option.rect.topLeft().y()); | ||
536 | scm.rowHeight() - scm.border()); | 570 | rc.setHeight(scm.rowHeight()); | ||
571 | // Move to correct location. | ||||
572 | if (option.direction == Qt::RightToLeft) { | ||||
573 | rc.moveRight(option.rect.topRight().x()); | ||||
574 | } else { | ||||
575 | rc.moveLeft(option.rect.topLeft().x()); | ||||
576 | } | ||||
577 | | ||||
578 | return rc; | ||||
537 | } | 579 | } | ||
538 | 580 | | |||
539 | void KisNodeDelegate::drawVisibilityIconHijack(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 581 | void KisNodeDelegate::drawVisibilityIconHijack(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
540 | { | 582 | { | ||
541 | /** | 583 | /** | ||
542 | * Small hack Alert: | 584 | * Small hack Alert: | ||
543 | * | 585 | * | ||
544 | * Here wepaint over the area that sits basically outside our layer's | 586 | * Here wepaint over the area that sits basically outside our layer's | ||
545 | * row. Anyway, just update it later... | 587 | * row. Anyway, just update it later... | ||
546 | */ | 588 | */ | ||
547 | 589 | | |||
548 | KisNodeViewColorScheme scm; | 590 | KisNodeViewColorScheme scm; | ||
549 | 591 | | |||
550 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | 592 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | ||
551 | OptionalProperty prop = d->findVisibilityProperty(props); | 593 | OptionalProperty prop = d->findVisibilityProperty(props); | ||
552 | if (!prop) return; | 594 | if (!prop) return; | ||
553 | 595 | | |||
554 | const int x = scm.border() + scm.visibilityMargin(); | 596 | QRect fitRect = visibilityClickRect(option, index); | ||
555 | const int y = option.rect.top() + (scm.rowHeight() - scm.border() - scm.visibilitySize()) / 2; | 597 | // Shrink to icon rect | ||
598 | fitRect = kisGrowRect(fitRect, -(scm.visibilityMargin()+scm.border())); | ||||
556 | 599 | | |||
557 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | 600 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | ||
558 | 601 | | |||
559 | // if we are not showing the layer, make the icon slightly transparent like other inactive icons | 602 | // if we are not showing the layer, make the icon slightly transparent like other inactive icons | ||
560 | const qreal oldOpacity = p->opacity(); | 603 | const qreal oldOpacity = p->opacity(); | ||
561 | if (prop->state.toBool() == true) { | 604 | | ||
562 | p->setOpacity(1.0); | 605 | if (!prop->state.toBool()) { | ||
563 | } | | |||
564 | else { | | |||
565 | p->setOpacity(0.35); | 606 | p->setOpacity(0.35); | ||
566 | } | 607 | } | ||
567 | 608 | | |||
568 | p->drawPixmap(x, y, icon.pixmap(scm.visibilitySize(), QIcon::Normal)); | 609 | p->drawPixmap(fitRect.x(), fitRect.center().y() - scm.visibilitySize() / 2, | ||
610 | icon.pixmap(scm.visibilitySize(), QIcon::Normal)); | ||||
569 | p->setOpacity(oldOpacity); | 611 | p->setOpacity(oldOpacity); | ||
570 | 612 | | |||
571 | //// For debugging purposes only | 613 | //// For debugging purposes only | ||
572 | // p->save(); | 614 | // // // p->save(); | ||
573 | // p->setPen(Qt::blue); | 615 | // // // p->setPen(Qt::blue); | ||
574 | // KritaUtils::renderExactRect(p, visibilityClickRect(option, index)); | 616 | // // // KritaUtils::renderExactRect(p, visibilityClickRect(option, index)); | ||
575 | // p->restore(); | 617 | // // // p->restore(); | ||
576 | } | 618 | } | ||
577 | 619 | | |||
578 | void KisNodeDelegate::drawDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 620 | void KisNodeDelegate::drawDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
579 | { | 621 | { | ||
580 | KisNodeViewColorScheme scm; | 622 | KisNodeViewColorScheme scm; | ||
581 | QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); | 623 | QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); | ||
582 | 624 | | |||
583 | if (!icon.isNull()) { | 625 | if (!icon.isNull()) { | ||
584 | QPixmap pixmap = | 626 | QPixmap pixmap = icon.pixmap(scm.decorationSize(), | ||
585 | icon.pixmap(scm.decorationSize(), | | |||
586 | (option.state & QStyle::State_Enabled) ? | 627 | (option.state & QStyle::State_Enabled) ? | ||
587 | QIcon::Normal : QIcon::Disabled); | 628 | QIcon::Normal : QIcon::Disabled); | ||
588 | 629 | | |||
589 | const QRect rc = scm.relDecorationRect().translated(option.rect.topLeft()); | 630 | QRect rc = decorationClickRect(option, index); | ||
631 | | ||||
632 | // Shrink to icon rect | ||||
633 | rc = kisGrowRect(rc, -(scm.decorationMargin()+scm.border())); | ||||
634 | | ||||
590 | const qreal oldOpacity = p->opacity(); // remember previous opacity | 635 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||
591 | 636 | | |||
592 | if (!(option.state & QStyle::State_Enabled)) { | 637 | if (!(option.state & QStyle::State_Enabled)) { | ||
593 | p->setOpacity(0.35); | 638 | p->setOpacity(0.35); | ||
594 | } | 639 | } | ||
595 | 640 | | |||
596 | 641 | p->drawPixmap(rc.topLeft()-QPoint(0, 1), pixmap); | |||
597 | p->drawPixmap(rc.topLeft(), pixmap); | | |||
598 | p->setOpacity(oldOpacity); // restore old opacity | 642 | p->setOpacity(oldOpacity); // restore old opacity | ||
599 | } | 643 | } | ||
600 | } | 644 | } | ||
601 | 645 | | |||
602 | void KisNodeDelegate::drawExpandButton(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 646 | void KisNodeDelegate::drawExpandButton(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
603 | { | 647 | { | ||
604 | Q_UNUSED(index); | 648 | Q_UNUSED(index); | ||
605 | KisNodeViewColorScheme scm; | 649 | KisNodeViewColorScheme scm; | ||
606 | QRect rc = scm.relExpandButtonRect().translated(option.rect.topLeft()); | | |||
607 | rc = kisGrowRect(rc, 0); | | |||
608 | 650 | | |||
609 | if (!(option.state & QStyle::State_Children)) { | 651 | QRect rc = decorationClickRect(option, index); | ||
610 | return; | 652 | | ||
611 | } | 653 | // Move to current index | ||
654 | // rc.moveTop(option.rect.topLeft().y()); | ||||
655 | // Shrink to icon rect | ||||
656 | rc = kisGrowRect(rc, -(scm.decorationMargin()+scm.border())); | ||||
612 | 657 | | |||
613 | QString iconName = option.state & QStyle::State_Open ? "arrow-down" : "arrow-right"; | 658 | if (!(option.state & QStyle::State_Children)) return; | ||
659 | | ||||
660 | | ||||
661 | QString iconName = option.state & QStyle::State_Open ? | ||||
662 | "arrow-down" : ((option.direction == Qt::RightToLeft) ? "arrow-left" : "arrow-right"); | ||||
614 | QIcon icon = KisIconUtils::loadIcon(iconName); | 663 | QIcon icon = KisIconUtils::loadIcon(iconName); | ||
615 | QPixmap pixmap = icon.pixmap(rc.width(), | 664 | QPixmap pixmap = icon.pixmap(rc.width(), | ||
616 | (option.state & QStyle::State_Enabled) ? | 665 | (option.state & QStyle::State_Enabled) ? | ||
617 | QIcon::Normal : QIcon::Disabled); | 666 | QIcon::Normal : QIcon::Disabled); | ||
618 | p->drawPixmap(rc.topLeft(), pixmap); | 667 | p->drawPixmap(rc.bottomLeft()-QPoint(0, scm.decorationSize()-1), pixmap); | ||
619 | } | 668 | } | ||
620 | 669 | | |||
621 | void KisNodeDelegate::Private::toggleProperty(KisBaseNode::PropertyList &props, OptionalProperty clickedProperty, bool controlPressed, const QModelIndex &index) | 670 | void KisNodeDelegate::Private::toggleProperty(KisBaseNode::PropertyList &props, OptionalProperty clickedProperty, bool controlPressed, const QModelIndex &index) | ||
622 | { | 671 | { | ||
623 | QAbstractItemModel *model = view->model(); | 672 | QAbstractItemModel *model = view->model(); | ||
624 | 673 | | |||
625 | // Using Ctrl+click to enter stasis | 674 | // Using Ctrl+click to enter stasis | ||
626 | if (controlPressed && clickedProperty->canHaveStasis) { | 675 | if (controlPressed && clickedProperty->canHaveStasis) { | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
669 | } | 718 | } | ||
670 | } | 719 | } | ||
671 | 720 | | |||
672 | 721 | | |||
673 | bool KisNodeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) | 722 | bool KisNodeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) | ||
674 | { | 723 | { | ||
675 | KisNodeViewColorScheme scm; | 724 | KisNodeViewColorScheme scm; | ||
676 | 725 | | |||
726 | QStyleOptionViewItem newOption = option; | ||||
727 | newOption.rect = d->view->originalVisualRect(index); | ||||
728 | | ||||
677 | if ((event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) | 729 | if ((event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) | ||
678 | && (index.flags() & Qt::ItemIsEnabled)) | 730 | && (index.flags() & Qt::ItemIsEnabled)) | ||
679 | { | 731 | { | ||
680 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); | 732 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); | ||
681 | 733 | | |||
682 | /** | 734 | /** | ||
683 | * Small hack Alert: | 735 | * Small hack Alert: | ||
684 | * | 736 | * | ||
685 | * Here we handle clicking even when it happened outside | 737 | * Here we handle clicking even when it happened outside | ||
686 | * the rectangle of the current index. The point is, we | 738 | * the rectangle of the current index. The point is, we | ||
687 | * use some virtual scroling offset to move the tree to the | 739 | * use some virtual scroling offset to move the tree to the | ||
688 | * right of the visibility icon. So the icon itself is placed | 740 | * right of the visibility icon. So the icon itself is placed | ||
689 | * in an empty area that doesn't belong to any index. But we still | 741 | * in an empty area that doesn't belong to any index. But we still | ||
690 | * handle it. | 742 | * handle it. | ||
691 | */ | 743 | */ | ||
692 | 744 | | |||
693 | const QRect iconsRect = this->iconsRect(option, index); | 745 | const QRect visibilityRect = visibilityClickRect(newOption, index); | ||
694 | const bool iconsClicked = iconsRect.isValid() && | | |||
695 | iconsRect.contains(mouseEvent->pos()); | | |||
696 | | ||||
697 | const QRect visibilityRect = visibilityClickRect(option, index); | | |||
698 | const bool visibilityClicked = visibilityRect.isValid() && | 746 | const bool visibilityClicked = visibilityRect.isValid() && | ||
699 | visibilityRect.contains(mouseEvent->pos()); | 747 | visibilityRect.contains(mouseEvent->pos()); | ||
700 | 748 | | |||
701 | const QRect decorationRect = decorationClickRect(option, index); | 749 | const QRect thumbnailRect = thumbnailClickRect(newOption, index); | ||
750 | const bool thumbnailClicked = thumbnailRect.isValid() && | ||||
751 | thumbnailRect.contains(mouseEvent->pos()); | ||||
752 | | ||||
753 | const QRect decorationRect = decorationClickRect(newOption, index); | ||||
702 | const bool decorationClicked = decorationRect.isValid() && | 754 | const bool decorationClicked = decorationRect.isValid() && | ||
703 | decorationRect.contains(mouseEvent->pos()); | 755 | decorationRect.contains(mouseEvent->pos()); | ||
704 | 756 | | |||
705 | const bool leftButton = mouseEvent->buttons() & Qt::LeftButton; | 757 | const QRect iconsRect = this->iconsRect(newOption, index); | ||
758 | const bool iconsClicked = iconsRect.isValid() && | ||||
759 | iconsRect.contains(mouseEvent->pos()); | ||||
706 | 760 | | |||
707 | const QRect thumbnailRect = thumbnailClickRect(option, index); | 761 | const bool leftButton = mouseEvent->buttons() & Qt::LeftButton; | ||
708 | const bool thumbnailClicked = thumbnailRect.contains(mouseEvent->pos()); | | |||
709 | 762 | | |||
710 | if (leftButton && iconsClicked) { | 763 | if (leftButton && iconsClicked) { | ||
711 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | 764 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | ||
712 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | 765 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | ||
766 | if (newOption.direction == Qt::RightToLeft) { | ||||
767 | std::reverse(realProps.begin(), realProps.end()); | ||||
768 | } | ||||
713 | const int numProps = realProps.size(); | 769 | const int numProps = realProps.size(); | ||
714 | 770 | | |||
715 | const int iconWidth = scm.iconSize() + 2 * scm.iconMargin() + scm.border(); | 771 | const int iconWidth = scm.iconSize() + 2 * scm.iconMargin() + scm.border(); | ||
716 | const int xPos = mouseEvent->pos().x() - iconsRect.left(); | 772 | const int xPos = mouseEvent->pos().x() - iconsRect.left(); | ||
717 | const int clickedIcon = xPos / iconWidth; | 773 | const int clickedIcon = xPos / iconWidth; | ||
718 | const int distToBorder = qMin(xPos % iconWidth, iconWidth - xPos % iconWidth); | 774 | const int distToBorder = qMin(xPos % iconWidth, iconWidth - xPos % iconWidth); | ||
719 | 775 | | |||
720 | if (iconsClicked && | 776 | if (iconsClicked && | ||
Show All 34 Lines | 809 | } else if (mouseEvent->modifiers() == (Qt::ControlModifier | Qt::AltModifier)) { | |||
755 | hasCorrectModifier = true; | 811 | hasCorrectModifier = true; | ||
756 | } else if (mouseEvent->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier)) { | 812 | } else if (mouseEvent->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier)) { | ||
757 | action = SELECTION_INTERSECT; | 813 | action = SELECTION_INTERSECT; | ||
758 | hasCorrectModifier = true; | 814 | hasCorrectModifier = true; | ||
759 | } | 815 | } | ||
760 | 816 | | |||
761 | if (hasCorrectModifier) { | 817 | if (hasCorrectModifier) { | ||
762 | model->setData(index, QVariant(int(action)), KisNodeModel::SelectOpaqueRole); | 818 | model->setData(index, QVariant(int(action)), KisNodeModel::SelectOpaqueRole); | ||
763 | return true; | | |||
764 | } | 819 | } | ||
820 | return true; //If not here then the item is !expanded when reaching return false; | ||||
765 | } | 821 | } | ||
766 | 822 | | |||
767 | if (mouseEvent->button() == Qt::LeftButton && | 823 | if (mouseEvent->button() == Qt::LeftButton && | ||
768 | mouseEvent->modifiers() == Qt::AltModifier) { | 824 | mouseEvent->modifiers() == Qt::AltModifier) { | ||
769 | 825 | | |||
770 | d->view->setCurrentIndex(index); | 826 | d->view->setCurrentIndex(index); | ||
771 | model->setData(index, true, KisNodeModel::AlternateActiveRole); | 827 | model->setData(index, true, KisNodeModel::AlternateActiveRole); | ||
772 | return true; | 828 | return true; | ||
773 | } | 829 | } | ||
774 | } | 830 | } | ||
775 | else if (event->type() == QEvent::ToolTip) { | 831 | else if (event->type() == QEvent::ToolTip) { | ||
776 | if (!KisConfig(true).hidePopups()) { | 832 | if (!KisConfig(true).hidePopups()) { | ||
777 | QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event); | 833 | QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event); | ||
778 | d->tip.showTip(d->view, helpEvent->pos(), option, index); | 834 | d->tip.showTip(d->view, helpEvent->pos(), newOption, index); | ||
779 | } | 835 | } | ||
780 | return true; | 836 | return true; | ||
781 | } else if (event->type() == QEvent::Leave) { | 837 | } else if (event->type() == QEvent::Leave) { | ||
782 | d->tip.hide(); | 838 | d->tip.hide(); | ||
783 | } | 839 | } | ||
784 | 840 | | |||
785 | return false; | 841 | return false; | ||
786 | } | 842 | } | ||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | |||||
916 | { | 972 | { | ||
917 | QVariant value = index.data(KisNodeModel::ProgressRole); | 973 | QVariant value = index.data(KisNodeModel::ProgressRole); | ||
918 | if (!value.isNull() && (value.toInt() >= 0 && value.toInt() <= 100)) { | 974 | if (!value.isNull() && (value.toInt() >= 0 && value.toInt() <= 100)) { | ||
919 | 975 | | |||
920 | /// The progress bar will display under the layer name area. The bars have accurate data, so we | 976 | /// The progress bar will display under the layer name area. The bars have accurate data, so we | ||
921 | /// probably don't need to also show the actual number for % complete | 977 | /// probably don't need to also show the actual number for % complete | ||
922 | 978 | | |||
923 | KisNodeViewColorScheme scm; | 979 | KisNodeViewColorScheme scm; | ||
924 | const int width = textRect(option, index).width() + scm.iconSize()*2; | 980 | | ||
981 | const QRect thumbnailRect = thumbnailClickRect(option, index); | ||||
982 | const QRect iconsRectR = iconsRect(option, index); | ||||
925 | const int height = 5; | 983 | const int height = 5; | ||
926 | const QPoint base = option.rect.bottomLeft() - QPoint(0, height ); | 984 | const QRect rc = QRect( | ||
927 | const QRect r = QRect(base.x(), base.y(), width, height); | 985 | ((option.direction == Qt::RightToLeft) ? iconsRectR.bottomRight() | ||
986 | : thumbnailRect.bottomRight()) - QPoint(0, height), | ||||
987 | ((option.direction == Qt::RightToLeft) ? thumbnailRect.bottomLeft() | ||||
988 | : iconsRectR.bottomLeft())); | ||||
928 | 989 | | |||
929 | p->save(); | 990 | p->save(); | ||
930 | { | 991 | { | ||
931 | p->setClipRect(r); | 992 | p->setClipRect(rc); | ||
932 | QStyle* style = QApplication::style(); | 993 | QStyle* style = QApplication::style(); | ||
933 | QStyleOptionProgressBar opt; | 994 | QStyleOptionProgressBar opt; | ||
934 | 995 | | |||
935 | opt.minimum = 0; | 996 | opt.minimum = 0; | ||
936 | opt.maximum = 100; | 997 | opt.maximum = 100; | ||
937 | opt.progress = value.toInt(); | 998 | opt.progress = value.toInt(); | ||
938 | opt.textVisible = false; | 999 | opt.textVisible = false; | ||
939 | opt.textAlignment = Qt::AlignHCenter; | 1000 | opt.textAlignment = Qt::AlignHCenter; | ||
940 | opt.text = i18n("%1 %", opt.progress); | 1001 | opt.text = i18n("%1 %", opt.progress); | ||
941 | opt.rect = r; | | |||
942 | opt.orientation = Qt::Horizontal; | 1002 | opt.orientation = Qt::Horizontal; | ||
943 | opt.state = option.state; | 1003 | opt.state = option.state; | ||
944 | style->drawControl(QStyle::CE_ProgressBar, &opt, p, 0); | 1004 | style->drawControl(QStyle::CE_ProgressBar, &opt, p, 0); | ||
945 | } | 1005 | } | ||
946 | p->restore(); | 1006 | p->restore(); | ||
947 | } | 1007 | } | ||
948 | } | 1008 | } | ||
949 | 1009 | | |||
Show All 12 Lines |
Please remove this debug before comitting :)