2009-09-17 13:59:10 +02:00
|
|
|
#include "detailsbutton.h"
|
|
|
|
|
2009-12-01 17:44:16 +01:00
|
|
|
#include <QtGui/QPaintEvent>
|
|
|
|
#include <QtGui/QPainter>
|
|
|
|
|
2009-09-17 13:59:10 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
2009-12-01 17:44:16 +01:00
|
|
|
DetailsButton::DetailsButton(QWidget *parent) : QAbstractButton(parent)
|
2009-09-17 13:59:10 +02:00
|
|
|
{
|
|
|
|
setCheckable(true);
|
2009-12-01 17:44:16 +01:00
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2009-09-29 18:06:13 +02:00
|
|
|
}
|
|
|
|
|
2009-12-01 17:44:16 +01:00
|
|
|
QSize DetailsButton::sizeHint() const
|
2009-09-29 18:06:13 +02:00
|
|
|
{
|
2009-12-01 17:44:16 +01:00
|
|
|
// TODO: Adjust this when icons become available!
|
|
|
|
return QSize(40, 22);
|
2009-10-01 14:24:44 +02:00
|
|
|
}
|
|
|
|
|
2009-12-01 17:44:16 +01:00
|
|
|
|
|
|
|
void DetailsButton::paintEvent(QPaintEvent *e)
|
2009-10-01 14:24:44 +02:00
|
|
|
{
|
2009-12-01 17:44:16 +01:00
|
|
|
QWidget::paintEvent(e);
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
if (isChecked()) {
|
|
|
|
if (m_checkedPixmap.isNull() || m_checkedPixmap.size() != contentsRect().size())
|
|
|
|
m_checkedPixmap = cacheRendering(contentsRect().size(), true);
|
|
|
|
p.drawPixmap(contentsRect(), m_checkedPixmap);
|
|
|
|
} else {
|
|
|
|
if (m_uncheckedPixmap.isNull() || m_uncheckedPixmap.size() != contentsRect().size())
|
|
|
|
m_uncheckedPixmap = cacheRendering(contentsRect().size(), false);
|
|
|
|
p.drawPixmap(contentsRect(), m_uncheckedPixmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap DetailsButton::cacheRendering(const QSize &size, bool checked)
|
|
|
|
{
|
|
|
|
QLinearGradient lg;
|
|
|
|
lg.setCoordinateMode(QGradient::ObjectBoundingMode);
|
|
|
|
lg.setFinalStop(0, 1);
|
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
lg.setColorAt(0, palette().color(QPalette::Midlight));
|
|
|
|
lg.setColorAt(1, palette().color(QPalette::Button));
|
|
|
|
} else {
|
|
|
|
lg.setColorAt(0, palette().color(QPalette::Button));
|
|
|
|
lg.setColorAt(1, palette().color(QPalette::Midlight));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap pixmap(size);
|
|
|
|
QPainter p(&pixmap);
|
|
|
|
p.setBrush(lg);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
|
|
|
|
p.drawRect(0, 0, size.width() - 1, size.height() - 1);
|
|
|
|
|
|
|
|
p.setPen(QPen(palette().color(QPalette::Mid)));
|
|
|
|
p.drawLine(0, size.height() - 1, 0, 0);
|
|
|
|
p.drawLine(0, 0, size.width() - 1, 0);
|
|
|
|
p.drawLine(size.width() - 1, 0, size.width() - 1, size.height() - 1);
|
|
|
|
if (!checked)
|
|
|
|
p.drawLine(size.width() - 1, size.height() - 1, 0, size.height() - 1);
|
|
|
|
|
|
|
|
p.setPen(palette().color(QPalette::Text));
|
|
|
|
|
|
|
|
// TODO: This should actually use some icons instead...
|
|
|
|
if (checked) {
|
|
|
|
p.drawText(0, 0, size.width(), size.height(), Qt::AlignCenter, tr("Less"));
|
|
|
|
} else {
|
|
|
|
p.drawText(0, 0, size.width(), size.height(), Qt::AlignCenter, tr("More"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
2009-09-17 13:59:10 +02:00
|
|
|
}
|