11 #include "TreeViewHeader.h"
15 #include <QAbstractItemModel>
16 #include <QFontMetrics>
18 #include <QLinearGradient>
24 #include <QVBoxLayout>
27 #include "TreeViewContent.h"
28 #include "AbstractTreeModel.h"
32 TreeViewHeader::TreeViewHeader(TreeViewContent *someContent,
38 m_headerText =
new QString(
"Header text");
40 m_filterProgressMin = 0;
41 m_filterProgressMax = 0;
42 m_rebuildProgress = 0;
43 m_rebuildProgressMin = 0;
44 m_rebuildProgressMax = 0;
51 TreeViewHeader::TreeViewHeader(
const TreeViewHeader &other) {
54 m_headerText =
new QString(*other.m_headerText);
58 TreeViewHeader::~TreeViewHeader() {
66 QSize TreeViewHeader::minimumSizeHint()
const {
67 return QSize(QFontMetrics(font()).width(*m_headerText) + 15,
68 QFontMetrics(font()).height() + 6);
71 QString TreeViewHeader::getText() {
77 void TreeViewHeader::setText(QString text) {
85 TreeViewHeader &TreeViewHeader::operator=(
86 const TreeViewHeader &other) {
92 m_headerText =
new QString;
93 *m_headerText = *other.m_headerText;
100 void TreeViewHeader::setActive(
bool newActiveState) {
101 m_active = newActiveState;
105 void TreeViewHeader::handleFilterCountsChanged(
106 int visibleTopLevelItemCount,
int topLevelItemCount) {
107 m_visibleCount = visibleTopLevelItemCount;
108 m_totalCount = topLevelItemCount;
114 void TreeViewHeader::mouseReleaseEvent(QMouseEvent *event) {
121 void TreeViewHeader::paintEvent(QPaintEvent *event) {
122 QPainter painter(
this);
123 painter.setRenderHints(QPainter::Antialiasing |
124 QPainter::TextAntialiasing);
125 paintHeader(&painter, height());
126 painter.drawRect(0, 0, width(), height());
131 void TreeViewHeader::nullify() {
136 void TreeViewHeader::paintHeader(QPainter *painter,
int rowHeight) {
137 QRect rect(0, 0, width(), rowHeight);
139 int x = rect.center().x();
140 QLinearGradient gradient(x, rect.top(), x, rect.bottom());
143 bool selected =
false;
144 QColor color = selected ? palette().highlight().color() :
145 palette().button().color();
148 int adjustment = 100;
149 m_active ? adjustment += 7 : adjustment -= 3;
150 gradient.setColorAt(0, color.darker(adjustment));
151 gradient.setColorAt(0.5, color.lighter(adjustment));
152 gradient.setColorAt(1, color.darker(adjustment));
153 painter->fillRect(rect, gradient);
157 QBrush brush = painter->brush();
158 QPainter::CompositionMode compMode = painter->compositionMode();
159 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
162 painter->setBrush(QBrush(QColor(0, 70, 100, 30)));
163 paintProgress(painter, rect, m_filterProgressMin, m_filterProgressMax,
167 painter->setBrush(QBrush(QColor(100, 70, 0, 30)));
168 paintProgress(painter, rect, m_rebuildProgressMin, m_rebuildProgressMax,
172 painter->setBrush(brush);
173 painter->setCompositionMode(compMode);
174 painter->setPen(selected ? palette().highlightedText().color() :
175 palette().buttonText().color());
177 QString title(*m_headerText);
179 if (m_visibleCount >= 0) {
182 title += QLocale().toString(m_visibleCount);
185 title += QLocale().toString(m_totalCount);
189 painter->drawText(rect, title, QTextOption(Qt::AlignCenter));
193 void TreeViewHeader::paintProgress(QPainter *painter,
const QRect &rect,
194 int min,
int max,
int value) {
196 double progressPercent = 1.0;
197 int progressRange = max - min;
198 if (progressRange > 0)
199 progressPercent = ((double)(value - min)) / progressRange;
201 if (progressPercent < 1.0) {
202 QRect progressRect(rect);
203 progressRect.setWidth((
int)(progressRect.width() * progressPercent));
204 painter->fillRect(progressRect, painter->brush());
209 void TreeViewHeader::updateFilterProgress(
int newProgress) {
210 m_filterProgress = newProgress;
215 void TreeViewHeader::updateFilterProgressRange(
int min,
int max) {
216 m_filterProgressMin = min;
217 m_filterProgressMax = max;
222 void TreeViewHeader::updateRebuildProgress(
int newProgress) {
223 m_rebuildProgress = newProgress;
228 void TreeViewHeader::updateRebuildProgressRange(
int min,
int max) {
229 m_rebuildProgressMin = min;
230 m_rebuildProgressMax = max;