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 | // bottom running horizontal line | ||||
246 | p->drawLine(bottomLeftPoint.x(), bottomY, | ||||
247 | bottomRightPoint.x(), bottomY); | ||||
248 | | ||||
249 | // visiblity icon vertical line - left | ||||
250 | p->drawLine(visibilityRect.topLeft().x()-1, topY, | ||||
251 | visibilityRect.bottomLeft().x()-1, bottomY); | ||||
242 | 252 | | |||
243 | QPoint k0(0, base.y()); | 253 | // visiblity icon vertical line - right | ||
244 | QPoint k1(1 * scm.border() + 2 * scm.visibilityMargin() + scm.visibilitySize(), base.y()); | 254 | p->drawLine(visibilityRect.topRight().x()+1, topY, | ||
245 | p->drawLine(k0, k1); | 255 | visibilityRect.bottomRight().x()+1, bottomY); | ||
246 | p->drawLine(k0 + v, k1 + v); | 256 | | ||
247 | p->drawLine(k0, k0 + v); | 257 | // thumbnail vertical line - left | ||
248 | p->drawLine(k1, k1 + v); | 258 | p->drawLine(thumbnailRect.topLeft().x(), topY, | ||
249 | 259 | thumbnailRect.bottomLeft().x(), bottomY); | |||
250 | p->drawLine(p2, p6); | 260 | | ||
251 | p->drawLine(p2 + v, p6 + v); | 261 | // thumbnail vertical line - right | ||
252 | p->drawLine(p2, p2 + v); | 262 | p->drawLine(thumbnailRect.topRight().x(), topY, | ||
253 | p->drawLine(p3, p3 + v); | 263 | thumbnailRect.bottomRight().x(), bottomY); | ||
254 | p->drawLine(p4, p4 + v); | 264 | | ||
255 | p->drawLine(p5, p5 + v); | 265 | // decoration vertical line - left | ||
256 | p->drawLine(p6, p6 + v); | 266 | p->drawLine(decorationRect.topLeft().x(), topY, | ||
267 | decorationRect.bottomLeft().x(), bottomY); | ||||
268 | | ||||
269 | // decoration vertical line - right | ||||
270 | p->drawLine(decorationRect.topRight().x(), topY, | ||||
271 | decorationRect.bottomRight().x(), bottomY); | ||||
272 | | ||||
273 | // icons' lines are drawn by drawIcons | ||||
257 | 274 | | |||
258 | //// For debugging purposes only | 275 | //// For debugging purposes only | ||
259 | //p->setPen(Qt::blue); | 276 | p->setPen(Qt::blue); | ||
260 | //KritaUtils::renderExactRect(p, iconsRect(option, index)); | 277 | //KritaUtils::renderExactRect(p, iconsRectR); | ||
261 | //KritaUtils::renderExactRect(p, textRect(option, index)); | 278 | //KritaUtils::renderExactRect(p, textRect(option, index)); | ||
262 | //KritaUtils::renderExactRect(p, scm.relThumbnailRect().translated(option.rect.topLeft())); | 279 | //KritaUtils::renderExactRect(p, visibilityRect); | ||
263 | 280 | | |||
264 | p->setPen(oldPen); | 281 | p->setPen(oldPen); | ||
265 | } | 282 | } | ||
266 | 283 | | |||
267 | QRect KisNodeDelegate::thumbnailClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 284 | QRect KisNodeDelegate::thumbnailClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
268 | { | 285 | { | ||
269 | Q_UNUSED(index); | 286 | Q_UNUSED(index); | ||
287 | KisNodeViewColorScheme scm; | ||||
270 | 288 | | |||
271 | int steps = 0; | 289 | QRect rc = scm.relThumbnailRect(); | ||
272 | QModelIndex tmp = index.parent(); | 290 | | ||
273 | while (tmp.isValid()) { | 291 | // Move to current index | ||
274 | steps++; | 292 | rc.moveTop(option.rect.topLeft().y()); | ||
275 | tmp = tmp.parent(); | 293 | // Move to correct location. | ||
294 | if (option.direction == Qt::RightToLeft) { | ||||
295 | rc.moveLeft(option.rect.topRight().x()); | ||||
296 | } else { | ||||
297 | rc.moveRight(option.rect.topLeft().x()); | ||||
276 | } | 298 | } | ||
277 | 299 | | |||
278 | KisNodeViewColorScheme scm; | 300 | 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 | } | 301 | } | ||
286 | 302 | | |||
287 | void KisNodeDelegate::drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 303 | void KisNodeDelegate::drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
288 | { | 304 | { | ||
289 | KisNodeViewColorScheme scm; | 305 | KisNodeViewColorScheme scm; | ||
290 | 306 | | |||
291 | const int thumbSize = scm.thumbnailSize(); | 307 | const int thumbSize = scm.thumbnailSize(); | ||
292 | const qreal oldOpacity = p->opacity(); // remember previous opacity | 308 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||
293 | 309 | | |||
294 | QImage img = index.data(int(KisNodeModel::BeginThumbnailRole) + thumbSize).value<QImage>(); | 310 | QImage img = index.data(int(KisNodeModel::BeginThumbnailRole) + thumbSize).value<QImage>(); | ||
295 | if (!(option.state & QStyle::State_Enabled)) { | 311 | if (!(option.state & QStyle::State_Enabled)) { | ||
296 | p->setOpacity(0.35); | 312 | p->setOpacity(0.35); | ||
297 | } | 313 | } | ||
298 | 314 | | |||
299 | QRect fitRect = scm.relThumbnailRect().translated(option.rect.topLeft()); | 315 | QRect fitRect = thumbnailClickRect(option, index); | ||
300 | 316 | // Shrink to icon rect | |||
301 | QPoint offset; | 317 | 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 | 318 | | |||
306 | // paint in a checkerboard pattern behind the layer contents to represent transparent | 319 | // paint in a checkerboard pattern behind the layer contents to represent transparent | ||
307 | const int step = scm.thumbnailSize() / 6; | 320 | const int step = scm.thumbnailSize() / 6; | ||
308 | QImage checkers(2 * step, 2 * step, QImage::Format_ARGB32); | 321 | QImage checkers(2 * step, 2 * step, QImage::Format_ARGB32); | ||
309 | QPainter gc(&checkers); | 322 | QPainter gc(&checkers); | ||
310 | gc.fillRect(QRect(0, 0, step, step), d->checkersColor1); | 323 | gc.fillRect(QRect(0, 0, step, step), d->checkersColor1); | ||
311 | gc.fillRect(QRect(step, 0, step, step), d->checkersColor2); | 324 | gc.fillRect(QRect(step, 0, step, step), d->checkersColor2); | ||
312 | gc.fillRect(QRect(step, step, step, step), d->checkersColor1); | 325 | gc.fillRect(QRect(step, step, step, step), d->checkersColor1); | ||
313 | gc.fillRect(QRect(0, step, step, step), d->checkersColor2); | 326 | gc.fillRect(QRect(0, step, step, step), d->checkersColor2); | ||
314 | 327 | | |||
315 | QBrush brush(checkers); | 328 | QBrush brush(checkers); | ||
316 | p->setBrushOrigin(offset); | 329 | p->fillRect(fitRect, brush); | ||
317 | p->fillRect(img.rect().translated(offset), brush); | | |||
318 | 330 | | |||
319 | p->drawImage(offset, img); | 331 | p->drawImage(fitRect, img); | ||
320 | p->setOpacity(oldOpacity); // restore old opacity | 332 | p->setOpacity(oldOpacity); // restore old opacity | ||
321 | 333 | | |||
322 | QRect borderRect = kisGrowRect(img.rect(), 1).translated(offset); | 334 | QRect borderRect = kisGrowRect(fitRect, 1); | ||
323 | KritaUtils::renderExactRect(p, borderRect, scm.gridColor(option, d->view)); | 335 | KritaUtils::renderExactRect(p, borderRect, scm.gridColor(option, d->view)); | ||
324 | } | 336 | } | ||
325 | 337 | | |||
326 | QRect KisNodeDelegate::iconsRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 338 | QRect KisNodeDelegate::iconsRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
327 | { | 339 | { | ||
328 | KisNodeViewColorScheme scm; | 340 | KisNodeViewColorScheme scm; | ||
329 | 341 | | |||
330 | int propCount = d->numProperties(index); | 342 | int propCount = d->numProperties(index); | ||
331 | 343 | | |||
332 | const int iconsWidth = | 344 | const int iconsWidth = | ||
333 | propCount * (scm.iconSize() + 2 * scm.iconMargin()) + | 345 | propCount * (scm.iconSize() + 2 * scm.iconMargin()) + | ||
334 | (propCount - 1) * scm.border(); | 346 | (propCount + 1) * scm.border(); | ||
347 | | ||||
348 | QRect fitRect = QRect(0, 0, | ||||
349 | iconsWidth, scm.rowHeight() - scm.border()); | ||||
350 | // Move to current index | ||||
351 | fitRect.moveTop(option.rect.topLeft().y()); | ||||
352 | // Move to correct location. | ||||
353 | if (option.direction == Qt::RightToLeft) { | ||||
354 | fitRect.moveLeft(option.rect.topLeft().x()); | ||||
355 | } else { | ||||
356 | fitRect.moveRight(option.rect.topRight().x()); | ||||
357 | } | ||||
335 | 358 | | |||
336 | const int x = option.rect.x() + option.rect.width() | 359 | 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 | } | 360 | } | ||
344 | 361 | | |||
345 | QRect KisNodeDelegate::textRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 362 | QRect KisNodeDelegate::textRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
346 | { | 363 | { | ||
347 | KisNodeViewColorScheme scm; | 364 | KisNodeViewColorScheme scm; | ||
348 | 365 | | |||
349 | static QFont f; | 366 | static QFont f; | ||
350 | static int minbearing = 1337 + 666; //can be 0 or negative, 2003 is less likely | 367 | static int minbearing = 1337 + 666; //can be 0 or negative, 2003 is less likely | ||
351 | if (minbearing == 2003 || f != option.font) { | 368 | if (minbearing == 2003 || f != option.font) { | ||
352 | f = option.font; //getting your bearings can be expensive, so we cache them | 369 | f = option.font; //getting your bearings can be expensive, so we cache them | ||
353 | minbearing = option.fontMetrics.minLeftBearing() + option.fontMetrics.minRightBearing(); | 370 | minbearing = option.fontMetrics.minLeftBearing() + option.fontMetrics.minRightBearing(); | ||
354 | } | 371 | } | ||
355 | 372 | | |||
356 | const int decorationOffset = | 373 | const QRect decoRect = decorationClickRect(option, index); | ||
357 | 2 * scm.border() + | 374 | const QRect iconRect = iconsRect(option, index); | ||
358 | 2 * scm.decorationMargin() + | 375 | | ||
359 | scm.decorationSize(); | 376 | QRect rc = QRect((option.direction == Qt::RightToLeft) ? iconRect.topRight() : decoRect.topRight(), | ||
360 | 377 | (option.direction == Qt::RightToLeft) ? decoRect.bottomLeft() : iconRect.bottomLeft()); | |||
361 | const int width = | 378 | rc.adjust(-(scm.border()+minbearing), 0, | ||
362 | iconsRect(option, index).left() - option.rect.x() - | 379 | (scm.border()+minbearing), 0); | ||
363 | scm.border() + minbearing - decorationOffset; | 380 | | ||
364 | 381 | return rc; | |||
365 | return QRect(option.rect.x() - minbearing + decorationOffset, | | |||
366 | option.rect.y() + scm.border(), | | |||
367 | width, | | |||
368 | scm.rowHeight() - scm.border()); | | |||
369 | } | 382 | } | ||
370 | 383 | | |||
371 | void KisNodeDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 384 | void KisNodeDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
372 | { | 385 | { | ||
373 | KisNodeViewColorScheme scm; | 386 | KisNodeViewColorScheme scm; | ||
374 | const QRect rc = textRect(option, index) | 387 | const QRect rc = textRect(option, index).adjusted(scm.textMargin(), 0, | ||
375 | .adjusted(scm.textMargin(), 0, -scm.textMargin(), 0); | 388 | -scm.textMargin(), 0); | ||
376 | 389 | | |||
377 | QPen oldPen = p->pen(); | 390 | QPen oldPen = p->pen(); | ||
378 | const qreal oldOpacity = p->opacity(); // remember previous opacity | 391 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||
379 | 392 | | |||
380 | p->setPen(option.palette.color(QPalette::Active,QPalette::Text )); | 393 | p->setPen(option.palette.color(QPalette::Active,QPalette::Text )); | ||
381 | 394 | | |||
382 | | ||||
383 | | ||||
384 | if (!(option.state & QStyle::State_Enabled)) { | 395 | if (!(option.state & QStyle::State_Enabled)) { | ||
385 | p->setOpacity(0.55); | 396 | p->setOpacity(0.55); | ||
386 | } | 397 | } | ||
387 | 398 | | |||
388 | | ||||
389 | const QString text = index.data(Qt::DisplayRole).toString(); | 399 | const QString text = index.data(Qt::DisplayRole).toString(); | ||
390 | const QString elided = elidedText(p->fontMetrics(), rc.width(), Qt::ElideRight, text); | 400 | const QString elided = p->fontMetrics().elidedText(text, Qt::ElideRight, rc.width()); | ||
391 | p->drawText(rc, Qt::AlignLeft | Qt::AlignVCenter, elided); | 401 | p->drawText(rc, Qt::AlignLeft | Qt::AlignVCenter, elided); | ||
392 | 402 | | |||
393 | p->setPen(oldPen); // restore pen settings | 403 | p->setPen(oldPen); // restore pen settings | ||
394 | p->setOpacity(oldOpacity); | 404 | p->setOpacity(oldOpacity); | ||
395 | } | 405 | } | ||
396 | 406 | | |||
397 | QList<OptionalProperty> KisNodeDelegate::Private::rightmostProperties(const KisBaseNode::PropertyList &props) const | 407 | QList<OptionalProperty> KisNodeDelegate::Private::rightmostProperties(const KisBaseNode::PropertyList &props) const | ||
398 | { | 408 | { | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 471 | { | |||
468 | } | 478 | } | ||
469 | 479 | | |||
470 | return 0; | 480 | return 0; | ||
471 | } | 481 | } | ||
472 | 482 | | |||
473 | void KisNodeDelegate::drawIcons(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 483 | void KisNodeDelegate::drawIcons(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
474 | { | 484 | { | ||
475 | KisNodeViewColorScheme scm; | 485 | KisNodeViewColorScheme scm; | ||
476 | const QRect r = iconsRect(option, index); | 486 | const QRect rc = iconsRect(option, index); | ||
477 | 487 | | |||
dkazakov: Please remove this debug before comitting :) | |||||
478 | QTransform oldTransform = p->transform(); | 488 | QTransform oldTransform = p->transform(); | ||
479 | QPen oldPen = p->pen(); | 489 | QPen oldPen = p->pen(); | ||
480 | p->setTransform(QTransform::fromTranslate(r.x(), r.y())); | 490 | p->setTransform(QTransform::fromTranslate(rc.x(), rc.y())); | ||
481 | p->setPen(scm.gridColor(option, d->view)); | 491 | p->setPen(scm.gridColor(option, d->view)); | ||
482 | 492 | | |||
483 | int x = 0; | 493 | int x = 0; | ||
484 | const int y = (scm.rowHeight() - scm.border() - scm.iconSize()) / 2; | 494 | const int y = (scm.rowHeight() - scm.border() - scm.iconSize()) / 2; | ||
485 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | 495 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | ||
486 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | 496 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | ||
487 | 497 | | |||
498 | if (option.direction == Qt::RightToLeft) { | ||||
499 | std::reverse(realProps.begin(), realProps.end()); | ||||
500 | } | ||||
501 | | ||||
488 | Q_FOREACH (OptionalProperty prop, realProps) { | 502 | Q_FOREACH (OptionalProperty prop, realProps) { | ||
503 | if (option.direction == Qt::LeftToRight) | ||||
504 | p->drawLine(x, 0, x, scm.rowHeight() - scm.border()); | ||||
505 | | ||||
489 | x += scm.iconMargin(); | 506 | x += scm.iconMargin(); | ||
490 | if (prop) { | 507 | if (prop) { | ||
491 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | 508 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | ||
492 | bool fullColor = prop->state.toBool() && option.state & QStyle::State_Enabled; | 509 | bool fullColor = prop->state.toBool() && option.state & QStyle::State_Enabled; | ||
493 | const qreal oldOpacity = p->opacity(); // remember previous opacity | | |||
494 | | ||||
495 | 510 | | |||
511 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||||
496 | if (fullColor) { | 512 | if (fullColor) { | ||
497 | p->setOpacity(1.0); | 513 | p->setOpacity(1.0); | ||
498 | } | 514 | } | ||
499 | else { | 515 | else { | ||
500 | p->setOpacity(0.35); | 516 | p->setOpacity(0.35); | ||
501 | } | 517 | } | ||
502 | 518 | | |||
503 | p->drawPixmap(x, y, icon.pixmap(scm.iconSize(), QIcon::Normal)); | 519 | p->drawPixmap(x, y, icon.pixmap(scm.iconSize(), QIcon::Normal)); | ||
504 | p->setOpacity(oldOpacity); // restore old opacity | 520 | p->setOpacity(oldOpacity); // restore old opacity | ||
505 | | ||||
506 | | ||||
507 | } | 521 | } | ||
508 | x += scm.iconSize() + scm.iconMargin(); | 522 | x += scm.iconSize() + scm.iconMargin(); | ||
523 | | ||||
524 | if (!(option.direction == Qt::LeftToRight)) | ||||
509 | p->drawLine(x, 0, x, scm.rowHeight() - scm.border()); | 525 | p->drawLine(x, 0, x, scm.rowHeight() - scm.border()); | ||
510 | x += scm.border(); | 526 | x += scm.border(); | ||
511 | } | 527 | } | ||
512 | 528 | | |||
513 | p->setTransform(oldTransform); | 529 | p->setTransform(oldTransform); | ||
514 | p->setPen(oldPen); | 530 | p->setPen(oldPen); | ||
515 | } | 531 | } | ||
516 | 532 | | |||
517 | QRect KisNodeDelegate::visibilityClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 533 | QRect KisNodeDelegate::visibilityClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
518 | { | 534 | { | ||
519 | Q_UNUSED(index); | 535 | Q_UNUSED(index); | ||
520 | KisNodeViewColorScheme scm; | 536 | KisNodeViewColorScheme scm; | ||
521 | return QRect(scm.border(), scm.border() + option.rect.top(), | 537 | | ||
522 | 2 * scm.visibilityMargin() + scm.visibilitySize(), | 538 | QRect rc = scm.relVisibilityRect(); | ||
523 | scm.rowHeight() - scm.border()); | 539 | rc.setHeight(scm.rowHeight()); | ||
540 | | ||||
541 | // Move to current index | ||||
542 | rc.moveCenter(option.rect.center()); | ||||
543 | // Move to correct location. | ||||
544 | if (option.direction == Qt::RightToLeft) { | ||||
545 | // HACK: Without the -5, the right edge is outside the view | ||||
546 | rc.moveRight(d->view->width()-5); | ||||
547 | } else { | ||||
548 | rc.moveLeft(0); | ||||
549 | } | ||||
550 | | ||||
551 | return rc; | ||||
524 | } | 552 | } | ||
525 | 553 | | |||
526 | QRect KisNodeDelegate::decorationClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | 554 | QRect KisNodeDelegate::decorationClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
527 | { | 555 | { | ||
528 | Q_UNUSED(option); | | |||
529 | Q_UNUSED(index); | 556 | Q_UNUSED(index); | ||
530 | KisNodeViewColorScheme scm; | 557 | KisNodeViewColorScheme scm; | ||
531 | 558 | | |||
532 | QRect realVisualRect = d->view->originalVisualRect(index); | 559 | QRect rc = scm.relDecorationRect(); | ||
533 | 560 | | |||
534 | return QRect(realVisualRect.left(), scm.border() + realVisualRect.top(), | 561 | // Move to current index | ||
535 | 2 * scm.decorationMargin() + scm.decorationSize(), | 562 | rc.moveTop(option.rect.topLeft().y()); | ||
536 | scm.rowHeight() - scm.border()); | 563 | rc.setHeight(scm.rowHeight()); | ||
564 | // Move to correct location. | ||||
565 | if (option.direction == Qt::RightToLeft) { | ||||
566 | rc.moveRight(option.rect.topRight().x()); | ||||
567 | } else { | ||||
568 | rc.moveLeft(option.rect.topLeft().x()); | ||||
569 | } | ||||
570 | | ||||
571 | return rc; | ||||
537 | } | 572 | } | ||
538 | 573 | | |||
539 | void KisNodeDelegate::drawVisibilityIconHijack(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 574 | void KisNodeDelegate::drawVisibilityIconHijack(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
540 | { | 575 | { | ||
541 | /** | 576 | /** | ||
542 | * Small hack Alert: | 577 | * Small hack Alert: | ||
543 | * | 578 | * | ||
544 | * Here wepaint over the area that sits basically outside our layer's | 579 | * Here wepaint over the area that sits basically outside our layer's | ||
545 | * row. Anyway, just update it later... | 580 | * row. Anyway, just update it later... | ||
546 | */ | 581 | */ | ||
547 | 582 | | |||
548 | KisNodeViewColorScheme scm; | 583 | KisNodeViewColorScheme scm; | ||
549 | 584 | | |||
550 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | 585 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | ||
551 | OptionalProperty prop = d->findVisibilityProperty(props); | 586 | OptionalProperty prop = d->findVisibilityProperty(props); | ||
552 | if (!prop) return; | 587 | if (!prop) return; | ||
553 | 588 | | |||
554 | const int x = scm.border() + scm.visibilityMargin(); | 589 | QRect fitRect = visibilityClickRect(option, index); | ||
555 | const int y = option.rect.top() + (scm.rowHeight() - scm.border() - scm.visibilitySize()) / 2; | 590 | // Shrink to icon rect | ||
591 | fitRect = kisGrowRect(fitRect, -(scm.visibilityMargin()+scm.border())); | ||||
556 | 592 | | |||
557 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | 593 | QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon; | ||
558 | 594 | | |||
559 | // if we are not showing the layer, make the icon slightly transparent like other inactive icons | 595 | // if we are not showing the layer, make the icon slightly transparent like other inactive icons | ||
560 | const qreal oldOpacity = p->opacity(); | 596 | const qreal oldOpacity = p->opacity(); | ||
561 | if (prop->state.toBool() == true) { | 597 | | ||
562 | p->setOpacity(1.0); | 598 | if (!prop->state.toBool()) { | ||
563 | } | | |||
564 | else { | | |||
565 | p->setOpacity(0.35); | 599 | p->setOpacity(0.35); | ||
566 | } | 600 | } | ||
567 | 601 | | |||
568 | p->drawPixmap(x, y, icon.pixmap(scm.visibilitySize(), QIcon::Normal)); | 602 | p->drawPixmap(fitRect.x(), fitRect.center().y() - scm.visibilitySize() / 2, | ||
603 | icon.pixmap(scm.visibilitySize(), QIcon::Normal)); | ||||
569 | p->setOpacity(oldOpacity); | 604 | p->setOpacity(oldOpacity); | ||
570 | 605 | | |||
571 | //// For debugging purposes only | 606 | //// For debugging purposes only | ||
572 | // p->save(); | 607 | // // // p->save(); | ||
573 | // p->setPen(Qt::blue); | 608 | // // // p->setPen(Qt::blue); | ||
574 | // KritaUtils::renderExactRect(p, visibilityClickRect(option, index)); | 609 | // // // KritaUtils::renderExactRect(p, visibilityClickRect(option, index)); | ||
575 | // p->restore(); | 610 | // // // p->restore(); | ||
576 | } | 611 | } | ||
577 | 612 | | |||
578 | void KisNodeDelegate::drawDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 613 | void KisNodeDelegate::drawDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
579 | { | 614 | { | ||
580 | KisNodeViewColorScheme scm; | 615 | KisNodeViewColorScheme scm; | ||
581 | QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); | 616 | QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); | ||
582 | 617 | | |||
583 | if (!icon.isNull()) { | 618 | if (!icon.isNull()) { | ||
584 | QPixmap pixmap = | 619 | QPixmap pixmap = icon.pixmap(scm.decorationSize(), | ||
585 | icon.pixmap(scm.decorationSize(), | | |||
586 | (option.state & QStyle::State_Enabled) ? | 620 | (option.state & QStyle::State_Enabled) ? | ||
587 | QIcon::Normal : QIcon::Disabled); | 621 | QIcon::Normal : QIcon::Disabled); | ||
588 | 622 | | |||
589 | const QRect rc = scm.relDecorationRect().translated(option.rect.topLeft()); | 623 | QRect rc = decorationClickRect(option, index); | ||
624 | | ||||
625 | // Shrink to icon rect | ||||
626 | rc = kisGrowRect(rc, -(scm.decorationMargin()+scm.border())); | ||||
627 | | ||||
590 | const qreal oldOpacity = p->opacity(); // remember previous opacity | 628 | const qreal oldOpacity = p->opacity(); // remember previous opacity | ||
591 | 629 | | |||
592 | if (!(option.state & QStyle::State_Enabled)) { | 630 | if (!(option.state & QStyle::State_Enabled)) { | ||
593 | p->setOpacity(0.35); | 631 | p->setOpacity(0.35); | ||
594 | } | 632 | } | ||
595 | 633 | | |||
596 | 634 | p->drawPixmap(rc.topLeft()-QPoint(0, 1), pixmap); | |||
597 | p->drawPixmap(rc.topLeft(), pixmap); | | |||
598 | p->setOpacity(oldOpacity); // restore old opacity | 635 | p->setOpacity(oldOpacity); // restore old opacity | ||
599 | } | 636 | } | ||
600 | } | 637 | } | ||
601 | 638 | | |||
602 | void KisNodeDelegate::drawExpandButton(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | 639 | void KisNodeDelegate::drawExpandButton(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
603 | { | 640 | { | ||
604 | Q_UNUSED(index); | 641 | Q_UNUSED(index); | ||
605 | KisNodeViewColorScheme scm; | 642 | KisNodeViewColorScheme scm; | ||
606 | QRect rc = scm.relExpandButtonRect().translated(option.rect.topLeft()); | | |||
607 | rc = kisGrowRect(rc, 0); | | |||
608 | 643 | | |||
609 | if (!(option.state & QStyle::State_Children)) { | 644 | QRect rc = decorationClickRect(option, index); | ||
610 | return; | 645 | | ||
611 | } | 646 | // Move to current index | ||
647 | // rc.moveTop(option.rect.topLeft().y()); | ||||
648 | // Shrink to icon rect | ||||
649 | rc = kisGrowRect(rc, -(scm.decorationMargin()+scm.border())); | ||||
612 | 650 | | |||
613 | QString iconName = option.state & QStyle::State_Open ? "arrow-down" : "arrow-right"; | 651 | if (!(option.state & QStyle::State_Children)) return; | ||
652 | | ||||
653 | | ||||
654 | QString iconName = option.state & QStyle::State_Open ? | ||||
655 | "arrow-down" : ((option.direction == Qt::RightToLeft) ? "arrow-left" : "arrow-right"); | ||||
614 | QIcon icon = KisIconUtils::loadIcon(iconName); | 656 | QIcon icon = KisIconUtils::loadIcon(iconName); | ||
615 | QPixmap pixmap = icon.pixmap(rc.width(), | 657 | QPixmap pixmap = icon.pixmap(rc.width(), | ||
616 | (option.state & QStyle::State_Enabled) ? | 658 | (option.state & QStyle::State_Enabled) ? | ||
617 | QIcon::Normal : QIcon::Disabled); | 659 | QIcon::Normal : QIcon::Disabled); | ||
618 | p->drawPixmap(rc.topLeft(), pixmap); | 660 | p->drawPixmap(rc.bottomLeft()-QPoint(0, scm.decorationSize()-1), pixmap); | ||
619 | } | 661 | } | ||
620 | 662 | | |||
621 | void KisNodeDelegate::Private::toggleProperty(KisBaseNode::PropertyList &props, OptionalProperty clickedProperty, bool controlPressed, const QModelIndex &index) | 663 | void KisNodeDelegate::Private::toggleProperty(KisBaseNode::PropertyList &props, OptionalProperty clickedProperty, bool controlPressed, const QModelIndex &index) | ||
622 | { | 664 | { | ||
623 | QAbstractItemModel *model = view->model(); | 665 | QAbstractItemModel *model = view->model(); | ||
624 | 666 | | |||
625 | // Using Ctrl+click to enter stasis | 667 | // Using Ctrl+click to enter stasis | ||
626 | if (controlPressed && clickedProperty->canHaveStasis) { | 668 | if (controlPressed && clickedProperty->canHaveStasis) { | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
669 | } | 711 | } | ||
670 | } | 712 | } | ||
671 | 713 | | |||
672 | 714 | | |||
673 | bool KisNodeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) | 715 | bool KisNodeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) | ||
674 | { | 716 | { | ||
675 | KisNodeViewColorScheme scm; | 717 | KisNodeViewColorScheme scm; | ||
676 | 718 | | |||
719 | QStyleOptionViewItem newOption = option; | ||||
720 | newOption.rect = d->view->originalVisualRect(index); | ||||
721 | | ||||
677 | if ((event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) | 722 | if ((event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) | ||
678 | && (index.flags() & Qt::ItemIsEnabled)) | 723 | && (index.flags() & Qt::ItemIsEnabled)) | ||
679 | { | 724 | { | ||
680 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); | 725 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); | ||
681 | 726 | | |||
682 | /** | 727 | /** | ||
683 | * Small hack Alert: | 728 | * Small hack Alert: | ||
684 | * | 729 | * | ||
685 | * Here we handle clicking even when it happened outside | 730 | * Here we handle clicking even when it happened outside | ||
686 | * the rectangle of the current index. The point is, we | 731 | * the rectangle of the current index. The point is, we | ||
687 | * use some virtual scroling offset to move the tree to the | 732 | * use some virtual scroling offset to move the tree to the | ||
688 | * right of the visibility icon. So the icon itself is placed | 733 | * 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 | 734 | * in an empty area that doesn't belong to any index. But we still | ||
690 | * handle it. | 735 | * handle it. | ||
691 | */ | 736 | */ | ||
692 | 737 | | |||
693 | const QRect iconsRect = this->iconsRect(option, index); | 738 | 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() && | 739 | const bool visibilityClicked = visibilityRect.isValid() && | ||
699 | visibilityRect.contains(mouseEvent->pos()); | 740 | visibilityRect.contains(mouseEvent->pos()); | ||
700 | 741 | | |||
701 | const QRect decorationRect = decorationClickRect(option, index); | 742 | const QRect thumbnailRect = thumbnailClickRect(newOption, index); | ||
743 | const bool thumbnailClicked = thumbnailRect.isValid() && | ||||
744 | thumbnailRect.contains(mouseEvent->pos()); | ||||
745 | | ||||
746 | const QRect decorationRect = decorationClickRect(newOption, index); | ||||
702 | const bool decorationClicked = decorationRect.isValid() && | 747 | const bool decorationClicked = decorationRect.isValid() && | ||
703 | decorationRect.contains(mouseEvent->pos()); | 748 | decorationRect.contains(mouseEvent->pos()); | ||
704 | 749 | | |||
705 | const bool leftButton = mouseEvent->buttons() & Qt::LeftButton; | 750 | const QRect iconsRect = this->iconsRect(newOption, index); | ||
751 | const bool iconsClicked = iconsRect.isValid() && | ||||
752 | iconsRect.contains(mouseEvent->pos()); | ||||
706 | 753 | | |||
707 | const QRect thumbnailRect = thumbnailClickRect(option, index); | 754 | const bool leftButton = mouseEvent->buttons() & Qt::LeftButton; | ||
708 | const bool thumbnailClicked = thumbnailRect.contains(mouseEvent->pos()); | | |||
709 | 755 | | |||
710 | if (leftButton && iconsClicked) { | 756 | if (leftButton && iconsClicked) { | ||
711 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | 757 | KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>(); | ||
712 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | 758 | QList<OptionalProperty> realProps = d->rightmostProperties(props); | ||
759 | if (newOption.direction == Qt::RightToLeft) { | ||||
760 | std::reverse(realProps.begin(), realProps.end()); | ||||
761 | } | ||||
713 | const int numProps = realProps.size(); | 762 | const int numProps = realProps.size(); | ||
714 | 763 | | |||
715 | const int iconWidth = scm.iconSize() + 2 * scm.iconMargin() + scm.border(); | 764 | const int iconWidth = scm.iconSize() + 2 * scm.iconMargin() + scm.border(); | ||
716 | const int xPos = mouseEvent->pos().x() - iconsRect.left(); | 765 | const int xPos = mouseEvent->pos().x() - iconsRect.left(); | ||
717 | const int clickedIcon = xPos / iconWidth; | 766 | const int clickedIcon = xPos / iconWidth; | ||
718 | const int distToBorder = qMin(xPos % iconWidth, iconWidth - xPos % iconWidth); | 767 | const int distToBorder = qMin(xPos % iconWidth, iconWidth - xPos % iconWidth); | ||
719 | 768 | | |||
720 | if (iconsClicked && | 769 | if (iconsClicked && | ||
Show All 34 Lines | 802 | } else if (mouseEvent->modifiers() == (Qt::ControlModifier | Qt::AltModifier)) { | |||
755 | hasCorrectModifier = true; | 804 | hasCorrectModifier = true; | ||
756 | } else if (mouseEvent->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier)) { | 805 | } else if (mouseEvent->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier)) { | ||
757 | action = SELECTION_INTERSECT; | 806 | action = SELECTION_INTERSECT; | ||
758 | hasCorrectModifier = true; | 807 | hasCorrectModifier = true; | ||
759 | } | 808 | } | ||
760 | 809 | | |||
761 | if (hasCorrectModifier) { | 810 | if (hasCorrectModifier) { | ||
762 | model->setData(index, QVariant(int(action)), KisNodeModel::SelectOpaqueRole); | 811 | model->setData(index, QVariant(int(action)), KisNodeModel::SelectOpaqueRole); | ||
763 | return true; | | |||
764 | } | 812 | } | ||
813 | return true; //If not here then the item is !expanded when reaching return false; | ||||
765 | } | 814 | } | ||
766 | 815 | | |||
767 | if (mouseEvent->button() == Qt::LeftButton && | 816 | if (mouseEvent->button() == Qt::LeftButton && | ||
768 | mouseEvent->modifiers() == Qt::AltModifier) { | 817 | mouseEvent->modifiers() == Qt::AltModifier) { | ||
769 | 818 | | |||
770 | d->view->setCurrentIndex(index); | 819 | d->view->setCurrentIndex(index); | ||
771 | model->setData(index, true, KisNodeModel::AlternateActiveRole); | 820 | model->setData(index, true, KisNodeModel::AlternateActiveRole); | ||
772 | return true; | 821 | return true; | ||
773 | } | 822 | } | ||
774 | } | 823 | } | ||
775 | else if (event->type() == QEvent::ToolTip) { | 824 | else if (event->type() == QEvent::ToolTip) { | ||
776 | if (!KisConfig(true).hidePopups()) { | 825 | if (!KisConfig(true).hidePopups()) { | ||
777 | QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event); | 826 | QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event); | ||
778 | d->tip.showTip(d->view, helpEvent->pos(), option, index); | 827 | d->tip.showTip(d->view, helpEvent->pos(), newOption, index); | ||
779 | } | 828 | } | ||
780 | return true; | 829 | return true; | ||
781 | } else if (event->type() == QEvent::Leave) { | 830 | } else if (event->type() == QEvent::Leave) { | ||
782 | d->tip.hide(); | 831 | d->tip.hide(); | ||
783 | } | 832 | } | ||
784 | 833 | | |||
785 | return false; | 834 | return false; | ||
786 | } | 835 | } | ||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Line(s) | |||||
917 | { | 966 | { | ||
918 | QVariant value = index.data(KisNodeModel::ProgressRole); | 967 | QVariant value = index.data(KisNodeModel::ProgressRole); | ||
919 | if (!value.isNull() && (value.toInt() >= 0 && value.toInt() <= 100)) { | 968 | if (!value.isNull() && (value.toInt() >= 0 && value.toInt() <= 100)) { | ||
920 | 969 | | |||
921 | /// The progress bar will display under the layer name area. The bars have accurate data, so we | 970 | /// The progress bar will display under the layer name area. The bars have accurate data, so we | ||
922 | /// probably don't need to also show the actual number for % complete | 971 | /// probably don't need to also show the actual number for % complete | ||
923 | 972 | | |||
924 | KisNodeViewColorScheme scm; | 973 | KisNodeViewColorScheme scm; | ||
925 | const int width = textRect(option, index).width() + scm.iconSize()*2; | 974 | | ||
975 | const QRect thumbnailRect = thumbnailClickRect(option, index); | ||||
976 | const QRect iconsRectR = iconsRect(option, index); | ||||
926 | const int height = 5; | 977 | const int height = 5; | ||
927 | const QPoint base = option.rect.bottomLeft() - QPoint(0, height ); | 978 | const QRect rc = QRect( | ||
928 | const QRect r = QRect(base.x(), base.y(), width, height); | 979 | ((option.direction == Qt::RightToLeft) ? iconsRectR.bottomRight() | ||
980 | : thumbnailRect.bottomRight()) - QPoint(0, height), | ||||
981 | ((option.direction == Qt::RightToLeft) ? thumbnailRect.bottomLeft() | ||||
982 | : iconsRectR.bottomLeft())); | ||||
929 | 983 | | |||
930 | p->save(); | 984 | p->save(); | ||
931 | { | 985 | { | ||
932 | p->setClipRect(r); | 986 | p->setClipRect(rc); | ||
933 | QStyle* style = QApplication::style(); | 987 | QStyle* style = QApplication::style(); | ||
934 | QStyleOptionProgressBar opt; | 988 | QStyleOptionProgressBar opt; | ||
935 | 989 | | |||
936 | opt.minimum = 0; | 990 | opt.minimum = 0; | ||
937 | opt.maximum = 100; | 991 | opt.maximum = 100; | ||
938 | opt.progress = value.toInt(); | 992 | opt.progress = value.toInt(); | ||
939 | opt.textVisible = false; | 993 | opt.textVisible = false; | ||
940 | opt.textAlignment = Qt::AlignHCenter; | 994 | opt.textAlignment = Qt::AlignHCenter; | ||
941 | opt.text = i18n("%1 %", opt.progress); | 995 | opt.text = i18n("%1 %", opt.progress); | ||
942 | opt.rect = r; | | |||
943 | opt.orientation = Qt::Horizontal; | 996 | opt.orientation = Qt::Horizontal; | ||
944 | opt.state = option.state; | 997 | opt.state = option.state; | ||
945 | style->drawControl(QStyle::CE_ProgressBar, &opt, p, 0); | 998 | style->drawControl(QStyle::CE_ProgressBar, &opt, p, 0); | ||
946 | } | 999 | } | ||
947 | p->restore(); | 1000 | p->restore(); | ||
948 | } | 1001 | } | ||
949 | } | 1002 | } | ||
950 | 1003 | | |||
Show All 12 Lines |
Please remove this debug before comitting :)