/** Redefined. */
void PlaylistHeaderView::paintEvent(QPaintEvent *)
{
	QStylePainter p(this->viewport());

	QLinearGradient vLinearGradient(rect().topLeft(), QPoint(rect().left(), rect().top() + rect().height()));
	/// XXX
	QPalette palette = QApplication::palette();
	if (SettingsPrivate::instance()->isCustomColors()) {
		vLinearGradient.setColorAt(0, palette.base().color().lighter(110));
		vLinearGradient.setColorAt(1, palette.base().color());
	} else {
		vLinearGradient.setColorAt(0, palette.base().color());
		vLinearGradient.setColorAt(1, palette.window().color());
	}

	QStyleOptionHeader opt;
	opt.initFrom(this->viewport());
	p.fillRect(rect(), QBrush(vLinearGradient));
	p.setPen(opt.palette.windowText().color());
	QRect r;
	p.save();
	if (QGuiApplication::isLeftToRight()) {
		p.translate(-offset(), 0);
	} else {
		p.translate(offset(), 0);
	}
	for (int i = 0; i < count(); i++) {
		QRect r2(sectionPosition(i), viewport()->rect().y(), sectionSize(i), viewport()->rect().height());
		p.drawText(r2, Qt::AlignCenter, model()->headerData(i, Qt::Horizontal).toString());
		if (r2.contains(mapFromGlobal(QCursor::pos()))) {
			r = r2;
		}
	}
	p.restore();
	if (!r.isNull()) {
		p.save();
		p.setPen(palette.highlight().color());
		p.drawLine(r.x(), r.y() + r.height() / 4,
				   r.x(), r.y() + 3 * r.height() / 4);
		p.drawLine(r.x() + r.width() - 1, r.y() + r.height() / 4,
				   r.x() + r.width() - 1, r.y() + 3 * r.height() / 4);
		p.restore();
	}

	// Bottom frame
	p.setPen(QApplication::palette().mid().color());
	p.drawLine(rect().bottomLeft(),  QPoint(rect().left() + rect().width(), rect().top() + rect().height()));

	// Vertical frame
	if (QGuiApplication::isLeftToRight()) {
		p.drawLine(rect().topLeft(), QPoint(rect().left(), rect().top() + rect().height()));
	} else {
		p.drawLine(rect().topRight(), QPoint(rect().right(), rect().top() + rect().height()));
	}
}
void FilterTableHeader::adjustPositions()
{
    // Loop through all widgets
    for(int i=0;i < filterWidgets.size(); ++i)
    {
        // Get the current widget, move it and reisize it
        QWidget* w = filterWidgets.at(i);
        w->move(sectionPosition(i) - offset(), filterWidgets.at(i)->sizeHint().height() + 2);   // The two adds some extra space between the header label and the input widget
        w->resize(sectionSize(i), filterWidgets.at(i)->sizeHint().height());
    }
}
Example #3
0
void RDHeaderView::mouseReleaseEvent(QMouseEvent *event)
{
  if(m_movingSection >= 0)
  {
    int mousePos = event->x();
    int idx = logicalIndexAt(mousePos);

    if(idx >= 0)
    {
      int secSize = sectionSize(idx);
      int secPos = sectionPosition(idx);

      int srcSection = visualIndex(m_movingSection);
      int dstSection = visualIndex(idx);

      if(srcSection >= 0 && dstSection >= 0 && srcSection != dstSection)
      {
        // the half-way point of the section decides whether we're dropping to the left
        // or the right of it.
        if(mousePos < secPos + secSize / 2)
        {
          // if we're moving from the left, place it to the left of dstSection
          if(srcSection < dstSection)
            moveSection(srcSection, dstSection - 1);
          else
            moveSection(srcSection, dstSection);
        }
        else
        {
          // if we're moving it from the right, place it to the right of dstSection
          if(srcSection > dstSection)
            moveSection(srcSection, dstSection + 1);
          else
            moveSection(srcSection, dstSection);
        }
      }
    }

    m_sectionPreview->hide();
  }

  m_movingSection = -1;

  if(m_customSizing)
  {
    m_resizeState = qMakePair(NoResize, -1);

    return QAbstractItemView::mouseReleaseEvent(event);
  }

  QHeaderView::mouseReleaseEvent(event);
}