9#include "TreeViewHeader.h"
13#include <QAbstractItemModel>
14#include <QFontMetrics>
16#include <QLinearGradient>
25#include "TreeViewContent.h"
26#include "AbstractTreeModel.h"
30 TreeViewHeader::TreeViewHeader(TreeViewContent *someContent,
34 m_headerText =
new QString(
"Header text");
36 m_filterProgressMin = 0;
37 m_filterProgressMax = 0;
38 m_rebuildProgress = 0;
39 m_rebuildProgressMin = 0;
40 m_rebuildProgressMax = 0;
47 TreeViewHeader::TreeViewHeader(
const TreeViewHeader &other) {
50 m_headerText =
new QString(*other.m_headerText);
54 TreeViewHeader::~TreeViewHeader() {
62 QSize TreeViewHeader::minimumSizeHint()
const {
63 return QSize(QFontMetrics(font()).horizontalAdvance(*m_headerText) + 15,
64 QFontMetrics(font()).height() + 6);
67 QString TreeViewHeader::getText() {
72 void TreeViewHeader::setText(QString text) {
79 TreeViewHeader &TreeViewHeader::operator=(
80 const TreeViewHeader &other) {
86 m_headerText =
new QString;
87 *m_headerText = *other.m_headerText;
94 void TreeViewHeader::setActive(
bool newActiveState) {
95 m_active = newActiveState;
99 void TreeViewHeader::handleFilterCountsChanged(
100 int visibleTopLevelItemCount,
int topLevelItemCount) {
101 m_visibleCount = visibleTopLevelItemCount;
102 m_totalCount = topLevelItemCount;
108 void TreeViewHeader::mouseReleaseEvent(QMouseEvent *event) {
115 void TreeViewHeader::paintEvent(QPaintEvent *event) {
116 QPainter painter(
this);
117 painter.setRenderHints(QPainter::Antialiasing |
118 QPainter::TextAntialiasing);
119 paintHeader(&painter, height());
120 painter.drawRect(0, 0, width(), height());
125 void TreeViewHeader::nullify() {
130 void TreeViewHeader::paintHeader(QPainter *painter,
int rowHeight) {
131 QRect rect(0, 0, width(), rowHeight);
133 int x = rect.center().x();
134 QLinearGradient gradient(x, rect.top(), x, rect.bottom());
137 bool selected =
false;
138 QColor color = selected ? palette().highlight().color() :
139 palette().button().color();
142 int adjustment = 100;
143 m_active ? adjustment += 7 : adjustment -= 3;
144 gradient.setColorAt(0, color.darker(adjustment));
145 gradient.setColorAt(0.5, color.lighter(adjustment));
146 gradient.setColorAt(1, color.darker(adjustment));
147 painter->fillRect(rect, gradient);
151 QBrush brush = painter->brush();
152 QPainter::CompositionMode compMode = painter->compositionMode();
153 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
156 painter->setBrush(QBrush(QColor(0, 70, 100, 30)));
157 paintProgress(painter, rect, m_filterProgressMin, m_filterProgressMax,
161 painter->setBrush(QBrush(QColor(100, 70, 0, 30)));
162 paintProgress(painter, rect, m_rebuildProgressMin, m_rebuildProgressMax,
166 painter->setBrush(brush);
167 painter->setCompositionMode(compMode);
168 painter->setPen(selected ? palette().highlightedText().color() :
169 palette().buttonText().color());
171 QString title(*m_headerText);
173 if (m_visibleCount >= 0) {
176 title += QLocale().toString(m_visibleCount);
179 title += QLocale().toString(m_totalCount);
183 painter->drawText(rect, title, QTextOption(Qt::AlignCenter));
187 void TreeViewHeader::paintProgress(QPainter *painter,
const QRect &rect,
188 int min,
int max,
int value) {
190 double progressPercent = 1.0;
191 int progressRange = max - min;
192 if (progressRange > 0)
193 progressPercent = ((double)(value - min)) / progressRange;
195 if (progressPercent < 1.0) {
196 QRect progressRect(rect);
197 progressRect.setWidth((
int)(progressRect.width() * progressPercent));
198 painter->fillRect(progressRect, painter->brush());
203 void TreeViewHeader::updateFilterProgress(
int newProgress) {
204 m_filterProgress = newProgress;
209 void TreeViewHeader::updateFilterProgressRange(
int min,
int max) {
210 m_filterProgressMin = min;
211 m_filterProgressMax = max;
216 void TreeViewHeader::updateRebuildProgress(
int newProgress) {
217 m_rebuildProgress = newProgress;
222 void TreeViewHeader::updateRebuildProgressRange(
int min,
int max) {
223 m_rebuildProgressMin = min;
224 m_rebuildProgressMax = max;
This is free and unencumbered software released into the public domain.