Files
qt-creator/src/libs/utils/faketooltip.cpp
Lucie Gérard a7956df3ca Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.

Task-number: QTBUG-67283
Change-Id: I708fd1f9f2b73d60f57cc3568646929117825813
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-08-26 12:27:18 +00:00

57 lines
1.7 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "faketooltip.h"
#include <QStyleOption>
#include <QStylePainter>
/*!
\class Utils::FakeToolTip
\brief The FakeToolTip class is a widget that pretends to be a tooltip.
By default it has Qt::WA_DeleteOnClose set.
*/
namespace Utils {
FakeToolTip::FakeToolTip(QWidget *parent) :
QWidget(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus)
{
setFocusPolicy(Qt::NoFocus);
setAttribute(Qt::WA_DeleteOnClose);
// Set the window and button text to the tooltip text color, since this
// widget draws the background as a tooltip.
QPalette p = palette();
const QColor toolTipTextColor = p.color(QPalette::Inactive, QPalette::ToolTipText);
p.setColor(QPalette::Inactive, QPalette::WindowText, toolTipTextColor);
p.setColor(QPalette::Inactive, QPalette::ButtonText, toolTipTextColor);
setPalette(p);
const int margin = 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, nullptr, this);
setContentsMargins(margin + 1, margin, margin, margin);
setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, nullptr, this) / 255.0);
}
void FakeToolTip::paintEvent(QPaintEvent *)
{
QStylePainter p(this);
QStyleOptionFrame opt;
opt.initFrom(this);
p.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
p.end();
}
void FakeToolTip::resizeEvent(QResizeEvent *)
{
QStyleHintReturnMask frameMask;
QStyleOption option;
option.initFrom(this);
if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option, this, &frameMask))
setMask(frameMask.region);
}
} // namespace Utils