Paint the headers nicer.
This commit is contained in:
parent
c84c51860d
commit
573d4c8050
@ -58,37 +58,53 @@ Group::HitResults Group::hitScan(const QPoint &pos) const
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Group::drawHeader(QPainter *painter, const int y)
|
void Group::drawHeader(QPainter *painter, const QStyleOptionViewItem &option, const int y)
|
||||||
{
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
int height = headerHeight() - 4;
|
|
||||||
int collapseSize = height;
|
|
||||||
|
|
||||||
// the icon
|
|
||||||
QRect iconRect = QRect(view->m_leftMargin + 2, 2 + y, collapseSize, collapseSize);
|
|
||||||
painter->setPen(QPen(Qt::black, 1));
|
|
||||||
painter->drawRect(iconRect);
|
|
||||||
static const int margin = 2;
|
static const int margin = 2;
|
||||||
|
static const int spacing = 10;
|
||||||
|
int height = headerHeight();
|
||||||
|
int text_height = height - 2 * margin;
|
||||||
|
|
||||||
|
// set the text colors
|
||||||
|
QPalette::ColorGroup cg = QPalette::Normal;
|
||||||
|
painter->setPen(opt.palette.color(cg, QPalette::Text));
|
||||||
|
|
||||||
|
// set up geometry
|
||||||
|
QRect iconRect = QRect(view->m_leftMargin + margin, y + margin, text_height - 1, text_height - 1);
|
||||||
QRect iconSubrect = iconRect.adjusted(margin, margin, -margin, -margin);
|
QRect iconSubrect = iconRect.adjusted(margin, margin, -margin, -margin);
|
||||||
|
QRect smallRect = iconSubrect.adjusted(margin, margin, -margin, -margin);
|
||||||
int midX = iconSubrect.center().x();
|
int midX = iconSubrect.center().x();
|
||||||
int midY = iconSubrect.center().y();
|
int midY = iconSubrect.center().y();
|
||||||
|
|
||||||
|
// checkboxy thingy
|
||||||
|
{
|
||||||
|
painter->drawRect(iconSubrect);
|
||||||
|
|
||||||
|
painter->setBrush(opt.palette.text());
|
||||||
|
painter->drawRect(smallRect.x(), midY, smallRect.width(), 2);
|
||||||
if(collapsed)
|
if(collapsed)
|
||||||
{
|
{
|
||||||
painter->drawLine(midX, iconSubrect.top(), midX, iconSubrect.bottom());
|
painter->drawRect(midX, smallRect.y(), 2, smallRect.height());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
painter->drawLine(iconSubrect.left(), midY, iconSubrect.right(), midY);
|
|
||||||
|
|
||||||
|
int x_left = iconRect.right();
|
||||||
|
|
||||||
|
if(text.length())
|
||||||
|
{
|
||||||
// the text
|
// the text
|
||||||
int textWidth = painter->fontMetrics().width(text);
|
int text_width = painter->fontMetrics().width(text);
|
||||||
QRect textRect = QRect(iconRect.right() + 4, y, textWidth, headerHeight());
|
QRect textRect = QRect(x_left + spacing, y + margin, text_width, text_height);
|
||||||
painter->setBrush(view->viewOptions().palette.text());
|
x_left = textRect.right();
|
||||||
view->style()->drawItemText(painter, textRect, Qt::AlignHCenter | Qt::AlignVCenter,
|
view->style()->drawItemText(painter, textRect, Qt::AlignHCenter | Qt::AlignVCenter,
|
||||||
view->viewport()->palette(), true, text);
|
opt.palette, true, text);
|
||||||
|
}
|
||||||
// the line
|
// the line
|
||||||
painter->drawLine(textRect.right() + 4, y + headerHeight() / 2,
|
painter->drawLine(x_left + spacing, midY + 1, view->contentWidth() - view->m_rightMargin,
|
||||||
view->contentWidth() - view->m_rightMargin, y + headerHeight() / 2);
|
midY + 1);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
@ -100,7 +116,11 @@ int Group::totalHeight() const
|
|||||||
|
|
||||||
int Group::headerHeight() const
|
int Group::headerHeight() const
|
||||||
{
|
{
|
||||||
return view->viewport()->fontMetrics().height() + 4;
|
int raw = view->viewport()->fontMetrics().height() + 4;
|
||||||
|
// add english. maybe. depends on font height.
|
||||||
|
if(raw % 2 == 0)
|
||||||
|
raw++;
|
||||||
|
return std::min( raw , 25 );
|
||||||
}
|
}
|
||||||
|
|
||||||
int Group::contentHeight() const
|
int Group::contentHeight() const
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
class GroupView;
|
class GroupView;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@ -26,7 +27,7 @@ struct Group
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
/// draw the header at y-position.
|
/// draw the header at y-position.
|
||||||
void drawHeader(QPainter *painter, const int y);
|
void drawHeader(QPainter *painter, const QStyleOptionViewItem &option, const int y);
|
||||||
|
|
||||||
/// height of the group, in total. includes a small bit of padding.
|
/// height of the group, in total. includes a small bit of padding.
|
||||||
int totalHeight() const;
|
int totalHeight() const;
|
||||||
|
@ -206,7 +206,7 @@ int GroupView::categoryRowHeight(const QModelIndex &index) const
|
|||||||
largestHeight =
|
largestHeight =
|
||||||
qMax(largestHeight, itemDelegate()->sizeHint(viewOptions(), i).height());
|
qMax(largestHeight, itemDelegate()->sizeHint(viewOptions(), i).height());
|
||||||
}
|
}
|
||||||
return largestHeight;
|
return largestHeight + m_spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<int, int> GroupView::categoryInternalPosition(const QModelIndex &index) const
|
QPair<int, int> GroupView::categoryInternalPosition(const QModelIndex &index) const
|
||||||
@ -423,11 +423,14 @@ void GroupView::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
QPainter painter(this->viewport());
|
QPainter painter(this->viewport());
|
||||||
|
|
||||||
|
QStyleOptionViewItemV4 option(viewOptions());
|
||||||
|
option.widget = this;
|
||||||
|
|
||||||
int y = -verticalOffset();
|
int y = -verticalOffset();
|
||||||
for (int i = 0; i < m_groups.size(); ++i)
|
for (int i = 0; i < m_groups.size(); ++i)
|
||||||
{
|
{
|
||||||
Group *category = m_groups.at(i);
|
Group *category = m_groups.at(i);
|
||||||
category->drawHeader(&painter, y);
|
category->drawHeader(&painter, option, y);
|
||||||
y += category->totalHeight() + m_categoryMargin;
|
y += category->totalHeight() + m_categoryMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,9 +442,7 @@ void GroupView::paintEvent(QPaintEvent *event)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Qt::ItemFlags flags = index.flags();
|
Qt::ItemFlags flags = index.flags();
|
||||||
QStyleOptionViewItemV4 option(viewOptions());
|
|
||||||
option.rect = visualRect(index);
|
option.rect = visualRect(index);
|
||||||
option.widget = this;
|
|
||||||
option.features |=
|
option.features |=
|
||||||
QStyleOptionViewItemV2::WrapText; // FIXME: what is the meaning of this anyway?
|
QStyleOptionViewItemV2::WrapText; // FIXME: what is the meaning of this anyway?
|
||||||
if (flags & Qt::ItemIsSelectable && selectionModel()->isSelected(index))
|
if (flags & Qt::ItemIsSelectable && selectionModel()->isSelected(index))
|
||||||
|
Loading…
Reference in New Issue
Block a user