forked from qt-creator/qt-creator
Utils: Unify and simplify Details(Button|Widget) and ExpandButton
This replaces lots of custom painting/animating code with a simplified implementation and cross-platform visual unification. Task-number: QTCREATORBUG-27801 Change-Id: I18b12e8c7f0bba4ba5d8a05271ab1e757769dc5f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "detailsbutton.h"
|
||||
#include "hostosinfo.h"
|
||||
#include "stylehelper.h"
|
||||
#include "theme/theme.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
@@ -15,6 +16,8 @@
|
||||
#include <QApplication>
|
||||
#include <QStyle>
|
||||
|
||||
#include <qdrawutil.h>
|
||||
|
||||
/*!
|
||||
\class Utils::DetailsWidget
|
||||
|
||||
@@ -57,9 +60,6 @@ public:
|
||||
FadingPanel *m_toolWidget;
|
||||
QWidget *m_widget;
|
||||
|
||||
QPixmap m_collapsedPixmap;
|
||||
QPixmap m_expandedPixmap;
|
||||
|
||||
DetailsWidget::State m_state;
|
||||
bool m_hovered;
|
||||
bool m_useCheckBox;
|
||||
@@ -112,37 +112,6 @@ DetailsWidgetPrivate::DetailsWidgetPrivate(QWidget *parent) :
|
||||
m_grid->addWidget(m_additionalSummaryLabel, 1, 0, 1, 3);
|
||||
}
|
||||
|
||||
QPixmap DetailsWidget::createBackground(const QSize &size, int topHeight, QWidget *widget)
|
||||
{
|
||||
QPixmap pixmap(size);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter p(&pixmap);
|
||||
|
||||
QRect topRect(0, 0, size.width(), topHeight);
|
||||
QRect fullRect(0, 0, size.width(), size.height());
|
||||
if (HostOsInfo::isMacHost())
|
||||
p.fillRect(fullRect, QApplication::palette().window().color());
|
||||
else
|
||||
p.fillRect(fullRect, creatorTheme()->color(Theme::DetailsWidgetBackgroundColor));
|
||||
|
||||
if (!creatorTheme()->flag(Theme::FlatProjectsMode)) {
|
||||
QLinearGradient lg(topRect.topLeft(), topRect.bottomLeft());
|
||||
lg.setStops(creatorTheme()->gradient(Theme::DetailsWidgetHeaderGradient));
|
||||
p.fillRect(topRect, lg);
|
||||
p.setRenderHint(QPainter::Antialiasing, true);
|
||||
p.translate(0.5, 0.5);
|
||||
p.setPen(QColor(0, 0, 0, 40));
|
||||
p.setBrush(Qt::NoBrush);
|
||||
p.drawRoundedRect(fullRect.adjusted(0, 0, -1, -1), 2, 2);
|
||||
p.setBrush(Qt::NoBrush);
|
||||
p.setPen(QColor(255,255,255,140));
|
||||
p.drawRoundedRect(fullRect.adjusted(1, 1, -2, -2), 2, 2);
|
||||
p.setPen(QPen(widget->palette().color(QPalette::Mid)));
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
void DetailsWidgetPrivate::updateControls()
|
||||
{
|
||||
if (m_widget)
|
||||
@@ -248,27 +217,14 @@ void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
|
||||
{
|
||||
QWidget::paintEvent(paintEvent);
|
||||
|
||||
const QColor bgColor = creatorTheme()->flag(Theme::FlatProjectsMode) ?
|
||||
creatorTheme()->color(Theme::DetailsWidgetBackgroundColor)
|
||||
: palette().color(QPalette::Window);
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
QWidget *topLeftWidget = d->m_useCheckBox ? static_cast<QWidget *>(d->m_summaryCheckBox) : static_cast<QWidget *>(d->m_summaryLabelIcon);
|
||||
QPoint topLeft(topLeftWidget->geometry().left() - MARGIN, contentsRect().top());
|
||||
const QRect paintArea(topLeft, contentsRect().bottomRight());
|
||||
|
||||
int topHeight = d->m_useCheckBox ? d->m_summaryCheckBox->height() : d->m_summaryLabel->height();
|
||||
if (d->m_state == DetailsWidget::Expanded || d->m_state == DetailsWidget::Collapsed) // Details Button is shown
|
||||
topHeight = qMax(d->m_detailsButton->height(), topHeight);
|
||||
|
||||
if (d->m_state == Collapsed) {
|
||||
if (d->m_collapsedPixmap.isNull() ||
|
||||
d->m_collapsedPixmap.size() != size())
|
||||
d->m_collapsedPixmap = createBackground(paintArea.size(), topHeight, this);
|
||||
p.drawPixmap(paintArea, d->m_collapsedPixmap);
|
||||
} else {
|
||||
if (d->m_expandedPixmap.isNull() ||
|
||||
d->m_expandedPixmap.size() != size())
|
||||
d->m_expandedPixmap = createBackground(paintArea.size(), topHeight, this);
|
||||
p.drawPixmap(paintArea, d->m_expandedPixmap);
|
||||
}
|
||||
p.fillRect(rect(), bgColor);
|
||||
if (!creatorTheme()->flag(Theme::FlatProjectsMode))
|
||||
qDrawPlainRect(&p, rect(), palette().color(QPalette::Mid));
|
||||
}
|
||||
|
||||
void DetailsWidget::enterEvent(QEnterEvent *event)
|
||||
|
||||
Reference in New Issue
Block a user