Changeset View
Changeset View
Standalone View
Standalone View
plugins/dockers/animation/timeline_layers_header.cpp
Context not available. | |||||
23 | #include <QPainter> | 23 | #include <QPainter> | ||
---|---|---|---|---|---|
24 | #include <QHelpEvent> | 24 | #include <QHelpEvent> | ||
25 | #include <QToolTip> | 25 | #include <QToolTip> | ||
26 | #include <QString> | ||||
27 | #include <QStyle> | ||||
28 | #include <QStyleOptionFrame> | ||||
26 | 29 | | |||
27 | #include "timeline_frames_model.h" | 30 | #include "timeline_frames_model.h" | ||
28 | #include "timeline_color_scheme.h" | 31 | #include "timeline_color_scheme.h" | ||
29 | 32 | | |||
33 | #include "kis_node_view_color_scheme.h" | ||||
34 | #include "krita_utils.h" | ||||
35 | | ||||
30 | 36 | | |||
31 | struct TimelineLayersHeader::Private | 37 | struct TimelineLayersHeader::Private | ||
32 | { | 38 | { | ||
Context not available. | |||||
39 | int iconAt(int logicalIndex, const QPoint &pt); | 45 | int iconAt(int logicalIndex, const QPoint &pt); | ||
40 | 46 | | |||
41 | TimelineFramesModel::Property* getPropertyAt(TimelineFramesModel::PropertyList &props, int index); | 47 | TimelineFramesModel::Property* getPropertyAt(TimelineFramesModel::PropertyList &props, int index); | ||
48 | bool isSectionSelected(int visualIndex) const; | ||||
49 | bool isFirstVisibleSection(int visualIndex) const; | ||||
50 | bool isLastVisibleSection(int visualIndex) const; | ||||
42 | }; | 51 | }; | ||
43 | 52 | | |||
44 | 53 | | |||
Context not available. | |||||
87 | return result; | 96 | return result; | ||
88 | } | 97 | } | ||
89 | 98 | | |||
99 | | ||||
100 | bool TimelineLayersHeader::Private::isSectionSelected(int logicalIndex) const | ||||
101 | { | ||||
102 | //change in future to allow multiple selection support | ||||
103 | return q->model()->headerData(logicalIndex, q->orientation(), TimelineFramesModel::ActiveLayerRole).toBool(); | ||||
104 | } | ||||
105 | | ||||
106 | bool TimelineLayersHeader::Private::isFirstVisibleSection(int visualIndex) const | ||||
107 | { | ||||
108 | return q->visualIndexAt(0) == visualIndex; | ||||
109 | } | ||||
110 | | ||||
111 | bool TimelineLayersHeader::Private::isLastVisibleSection(int visualIndex) const | ||||
112 | { | ||||
113 | return q->visualIndexAt( q->count() - q->hiddenSectionCount() -1 ) == visualIndex; | ||||
114 | } | ||||
115 | | ||||
90 | QSize TimelineLayersHeader::sectionSizeFromContents(int logicalIndex) const | 116 | QSize TimelineLayersHeader::sectionSizeFromContents(int logicalIndex) const | ||
91 | { | 117 | { | ||
92 | QSize baseSize = QHeaderView::sectionSizeFromContents(logicalIndex); | 118 | QSize baseSize = QHeaderView::sectionSizeFromContents(logicalIndex); | ||
Context not available. | |||||
113 | 139 | | |||
114 | void TimelineLayersHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const | 140 | void TimelineLayersHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const | ||
115 | { | 141 | { | ||
142 | KisNodeViewColorScheme scm; | ||||
143 | int colorIndex = model()->headerData(logicalIndex, orientation(), | ||||
144 | TimelineFramesModel::LayerColorLabelIndexRole | ||||
145 | ).toInt(); | ||||
146 | QColor color = scm.colorLabel(colorIndex); | ||||
147 | QPalette plt = QWidget::palette(); | ||||
148 | | ||||
149 | if (color.alpha()>0){ | ||||
150 | QPalette::ColorRole rolesToChange[] = {QPalette::Light,QPalette::Midlight , QPalette::Button, | ||||
151 | QPalette::Dark ,QPalette::Mid , QPalette::Window, | ||||
152 | QPalette::Base ,QPalette::AlternateBase}; | ||||
153 | QColor oldColor, newcolor; | ||||
154 | for (QPalette::ColorRole role : rolesToChange) | ||||
155 | { | ||||
156 | oldColor = plt.color(plt.currentColorGroup(), role); | ||||
157 | newcolor = KritaUtils::blendColors(color, oldColor, 0.3); | ||||
158 | plt.setColor(plt.currentColorGroup(), role, newcolor); | ||||
159 | } | ||||
160 | | ||||
161 | } | ||||
116 | painter->save(); | 162 | painter->save(); | ||
117 | QHeaderView::paintSection(painter, rect, logicalIndex); | 163 | paintSectionWithCustomPalette(painter, rect, logicalIndex, plt); | ||
118 | painter->restore(); | 164 | painter->restore(); | ||
119 | 165 | | |||
120 | bool isLayerActive = model()->headerData(logicalIndex, orientation(), TimelineFramesModel::ActiveLayerRole).toBool(); | 166 | bool isLayerActive = model()->headerData(logicalIndex, orientation(), TimelineFramesModel::ActiveLayerRole).toBool(); | ||
Context not available. | |||||
132 | const int x0 = rect.x(); | 178 | const int x0 = rect.x(); | ||
133 | const int y0 = rect.y(); | 179 | const int y0 = rect.y(); | ||
134 | const int x1 = rect.right(); | 180 | const int x1 = rect.right(); | ||
135 | const int y1 = rect.bottom(); | 181 | const int y1 = rect.bottom()+1; | ||
136 | 182 | | |||
137 | QVector<QLine> lines; | 183 | QVector<QLine> lines; | ||
138 | lines << QLine(x0, y0 + lineWidth / 2, x1, y0 + lineWidth / 2); | 184 | lines << QLine(x0, y0 + lineWidth / 2, x1, y0 + lineWidth / 2); | ||
139 | lines << QLine(x0, y1 - lineWidth / 2, x1, y1 - lineWidth / 2); | 185 | lines << QLine(x0, y1 - lineWidth / 2, x1, y1 - lineWidth / 2); | ||
140 | 186 | | |||
141 | painter->drawLines(lines); | 187 | painter->drawLines(lines); | ||
142 | 188 | | |||
Context not available. | |||||
159 | } | 205 | } | ||
160 | } | 206 | } | ||
161 | 207 | | |||
208 | | ||||
209 | void TimelineLayersHeader::paintSectionWithCustomPalette(QPainter *painter, const QRect &rect, | ||||
210 | int logicalIndex, const QPalette & customPalette) const | ||||
211 | { | ||||
212 | //"fork" of QHeaderView::paintSection method, but it changed to use custom palette | ||||
213 | //and it does not use QHeaderViewPrivate (because I can't access it) | ||||
214 | //also it ignores whether or not mouse pointer is over it|mouse button is pressed | ||||
215 | if (!rect.isValid()) | ||||
216 | return; | ||||
217 | | ||||
218 | // get the state of the section | ||||
219 | QStyleOptionHeader opt; | ||||
220 | initStyleOption(&opt); | ||||
221 | opt.palette = customPalette; | ||||
222 | QStyle::State state = QStyle::State_None; | ||||
223 | if (isEnabled()) | ||||
224 | state |= QStyle::State_Enabled; | ||||
225 | if (window()->isActiveWindow()) | ||||
226 | state |= QStyle::State_Active; | ||||
227 | | ||||
228 | if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex) | ||||
229 | opt.sortIndicator = (sortIndicatorOrder() == Qt::AscendingOrder) | ||||
230 | ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp; | ||||
231 | | ||||
232 | // setup the style options structure | ||||
233 | QVariant textAlignment = this->model()->headerData(logicalIndex, this->orientation(), | ||||
234 | Qt::TextAlignmentRole); | ||||
235 | opt.rect = rect; | ||||
236 | opt.section = logicalIndex; | ||||
237 | opt.state |= state; | ||||
238 | opt.textAlignment = Qt::Alignment(textAlignment.isValid() | ||||
239 | ? Qt::Alignment(textAlignment.toInt()) | ||||
240 | : this->defaultAlignment()); | ||||
241 | | ||||
242 | opt.iconAlignment = Qt::AlignVCenter; | ||||
243 | opt.text = this->model()->headerData(logicalIndex, this->orientation(), | ||||
244 | Qt::DisplayRole).toString(); | ||||
245 | | ||||
246 | int margin = 2 * style()->pixelMetric(QStyle::PM_HeaderMargin, 0, this); | ||||
247 | | ||||
248 | const Qt::Alignment headerArrowAlignment = static_cast<Qt::Alignment>(style()->styleHint(QStyle::SH_Header_ArrowAlignment, 0, this)); | ||||
249 | const bool isHeaderArrowOnTheSide = headerArrowAlignment & Qt::AlignVCenter; | ||||
250 | if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex && isHeaderArrowOnTheSide) | ||||
251 | margin += style()->pixelMetric(QStyle::PM_HeaderMarkSize, 0, this); | ||||
252 | | ||||
253 | if (this->textElideMode() != Qt::ElideNone) | ||||
254 | opt.text = opt.fontMetrics.elidedText(opt.text, this->textElideMode() , rect.width() - margin); | ||||
255 | | ||||
256 | QVariant variant = this->model()->headerData(logicalIndex, this->orientation(), | ||||
257 | Qt::DecorationRole); | ||||
258 | opt.icon = qvariant_cast<QIcon>(variant); | ||||
259 | if (opt.icon.isNull()) | ||||
260 | opt.icon = qvariant_cast<QPixmap>(variant); | ||||
261 | QVariant foregroundBrush = this->model()->headerData(logicalIndex, this->orientation(), | ||||
262 | Qt::ForegroundRole); | ||||
263 | if (foregroundBrush.canConvert<QBrush>()) | ||||
264 | opt.palette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(foregroundBrush)); | ||||
265 | | ||||
266 | QPointF oldBO = painter->brushOrigin(); | ||||
267 | QVariant backgroundBrush = this->model()->headerData(logicalIndex, this->orientation(), | ||||
268 | Qt::BackgroundRole); | ||||
269 | if (backgroundBrush.canConvert<QBrush>()) { | ||||
270 | opt.palette.setBrush(QPalette::Button, qvariant_cast<QBrush>(backgroundBrush)); | ||||
271 | opt.palette.setBrush(QPalette::Window, qvariant_cast<QBrush>(backgroundBrush)); | ||||
272 | painter->setBrushOrigin(opt.rect.topLeft()); | ||||
273 | } | ||||
274 | | ||||
275 | // the section position | ||||
276 | int visual = visualIndex(logicalIndex); | ||||
277 | Q_ASSERT(visual != -1); | ||||
278 | bool first = m_d->isFirstVisibleSection(visual); | ||||
279 | bool last = m_d->isLastVisibleSection(visual); | ||||
280 | if (first && last) | ||||
281 | opt.position = QStyleOptionHeader::OnlyOneSection; | ||||
282 | else if (first) | ||||
283 | opt.position = QStyleOptionHeader::Beginning; | ||||
284 | else if (last) | ||||
285 | opt.position = QStyleOptionHeader::End; | ||||
286 | else | ||||
287 | opt.position = QStyleOptionHeader::Middle; | ||||
288 | opt.orientation = this->orientation(); | ||||
289 | // the selected position | ||||
290 | bool previousSelected = m_d->isSectionSelected(this->logicalIndex(visual - 1)); | ||||
291 | bool nextSelected = m_d->isSectionSelected(this->logicalIndex(visual + 1)); | ||||
292 | if (previousSelected && nextSelected) | ||||
293 | opt.selectedPosition = QStyleOptionHeader::NextAndPreviousAreSelected; | ||||
294 | else if (previousSelected) | ||||
295 | opt.selectedPosition = QStyleOptionHeader::PreviousIsSelected; | ||||
296 | else if (nextSelected) | ||||
297 | opt.selectedPosition = QStyleOptionHeader::NextIsSelected; | ||||
298 | else | ||||
299 | opt.selectedPosition = QStyleOptionHeader::NotAdjacent; | ||||
300 | // draw the section | ||||
301 | style()->drawControl(QStyle::CE_Header, &opt, painter, this); | ||||
302 | | ||||
303 | painter->setBrushOrigin(oldBO); | ||||
304 | } | ||||
305 | | ||||
306 | | ||||
162 | int TimelineLayersHeader::Private::iconAt(int logicalIndex, const QPoint &pt) | 307 | int TimelineLayersHeader::Private::iconAt(int logicalIndex, const QPoint &pt) | ||
163 | { | 308 | { | ||
164 | QPoint sectionTopLeft(0, | 309 | QPoint sectionTopLeft(0, | ||
Context not available. |