3 #include "TreeViewHeader.h" 7 #include <QAbstractItemModel> 8 #include <QFontMetrics> 10 #include <QLinearGradient> 16 #include <QVBoxLayout> 19 #include "TreeViewContent.h" 20 #include "AbstractTreeModel.h" 24 TreeViewHeader::TreeViewHeader(TreeViewContent *someContent,
30 m_headerText =
new QString(
"Header text");
32 m_filterProgressMin = 0;
33 m_filterProgressMax = 0;
34 m_rebuildProgress = 0;
35 m_rebuildProgressMin = 0;
36 m_rebuildProgressMax = 0;
43 TreeViewHeader::TreeViewHeader(
const TreeViewHeader &other) {
46 m_headerText =
new QString(*other.m_headerText);
50 TreeViewHeader::~TreeViewHeader() {
58 QSize TreeViewHeader::minimumSizeHint()
const {
59 return QSize(QFontMetrics(font()).width(*m_headerText) + 15,
60 QFontMetrics(font()).height() + 6);
63 QString TreeViewHeader::getText() {
69 void TreeViewHeader::setText(QString text) {
77 TreeViewHeader &TreeViewHeader::operator=(
78 const TreeViewHeader &other) {
84 m_headerText =
new QString;
85 *m_headerText = *other.m_headerText;
92 void TreeViewHeader::setActive(
bool newActiveState) {
93 m_active = newActiveState;
97 void TreeViewHeader::handleFilterCountsChanged(
98 int visibleTopLevelItemCount,
int topLevelItemCount) {
99 m_visibleCount = visibleTopLevelItemCount;
100 m_totalCount = topLevelItemCount;
106 void TreeViewHeader::mouseReleaseEvent(QMouseEvent *event) {
113 void TreeViewHeader::paintEvent(QPaintEvent *event) {
114 QPainter painter(
this);
115 painter.setRenderHints(QPainter::Antialiasing |
116 QPainter::TextAntialiasing);
117 paintHeader(&painter, height());
118 painter.drawRect(0, 0, width(), height());
123 void TreeViewHeader::nullify() {
128 void TreeViewHeader::paintHeader(QPainter *painter,
int rowHeight) {
129 QRect rect(0, 0, width(), rowHeight);
131 int x = rect.center().x();
132 QLinearGradient gradient(x, rect.top(), x, rect.bottom());
135 bool selected =
false;
136 QColor color = selected ? palette().highlight().color() :
137 palette().button().color();
140 int adjustment = 100;
141 m_active ? adjustment += 7 : adjustment -= 3;
142 gradient.setColorAt(0, color.darker(adjustment));
143 gradient.setColorAt(0.5, color.lighter(adjustment));
144 gradient.setColorAt(1, color.darker(adjustment));
145 painter->fillRect(rect, gradient);
149 QBrush brush = painter->brush();
150 QPainter::CompositionMode compMode = painter->compositionMode();
151 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
154 painter->setBrush(QBrush(QColor(0, 70, 100, 30)));
155 paintProgress(painter, rect, m_filterProgressMin, m_filterProgressMax,
159 painter->setBrush(QBrush(QColor(100, 70, 0, 30)));
160 paintProgress(painter, rect, m_rebuildProgressMin, m_rebuildProgressMax,
164 painter->setBrush(brush);
165 painter->setCompositionMode(compMode);
166 painter->setPen(selected ? palette().highlightedText().color() :
167 palette().buttonText().color());
169 QString title(*m_headerText);
171 if (m_visibleCount >= 0) {
174 title += QLocale().toString(m_visibleCount);
177 title += QLocale().toString(m_totalCount);
181 painter->drawText(rect, title, QTextOption(Qt::AlignCenter));
185 void TreeViewHeader::paintProgress(QPainter *painter,
const QRect &rect,
186 int min,
int max,
int value) {
188 double progressPercent = 1.0;
189 int progressRange = max - min;
190 if (progressRange > 0)
191 progressPercent = ((double)(value - min)) / progressRange;
193 if (progressPercent < 1.0) {
194 QRect progressRect(rect);
195 progressRect.setWidth((
int)(progressRect.width() * progressPercent));
196 painter->fillRect(progressRect, painter->brush());
201 void TreeViewHeader::updateFilterProgress(
int newProgress) {
202 m_filterProgress = newProgress;
207 void TreeViewHeader::updateFilterProgressRange(
int min,
int max) {
208 m_filterProgressMin = min;
209 m_filterProgressMax = max;
214 void TreeViewHeader::updateRebuildProgress(
int newProgress) {
215 m_rebuildProgress = newProgress;
220 void TreeViewHeader::updateRebuildProgressRange(
int min,
int max) {
221 m_rebuildProgressMin = min;
222 m_rebuildProgressMax = max;
Namespace for ISIS/Bullet specific routines.