2017-12-23 22:17:38 +01:00
|
|
|
#include "tooltipwidget.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/fontmanager.hpp"
|
2018-01-22 15:06:36 +01:00
|
|
|
#include "singletons/thememanager.hpp"
|
2017-12-23 22:17:38 +01:00
|
|
|
|
2018-01-22 20:14:43 +01:00
|
|
|
#include <QDebug>
|
2018-01-22 15:06:36 +01:00
|
|
|
#include <QDesktopWidget>
|
2017-12-23 22:17:38 +01:00
|
|
|
#include <QStyle>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
|
|
|
TooltipWidget::TooltipWidget(BaseWidget *parent)
|
2018-01-22 15:06:36 +01:00
|
|
|
: BaseWindow(parent)
|
2017-12-23 22:17:38 +01:00
|
|
|
, displayText(new QLabel())
|
|
|
|
{
|
2018-01-22 20:14:43 +01:00
|
|
|
this->setStyleSheet("color: #fff; background: #000");
|
2017-12-23 22:17:38 +01:00
|
|
|
this->setWindowOpacity(0.8);
|
2018-01-22 20:14:43 +01:00
|
|
|
this->updateFont();
|
2017-12-23 22:17:38 +01:00
|
|
|
|
|
|
|
this->setAttribute(Qt::WA_ShowWithoutActivating);
|
2018-01-22 15:06:36 +01:00
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
|
2018-01-22 20:14:43 +01:00
|
|
|
Qt::X11BypassWindowManagerHint | Qt::BypassWindowManagerHint |
|
|
|
|
Qt::SubWindow);
|
2017-12-23 22:17:38 +01:00
|
|
|
|
|
|
|
displayText->setAlignment(Qt::AlignHCenter);
|
2018-01-22 20:14:43 +01:00
|
|
|
displayText->setText("tooltip text");
|
2017-12-23 22:17:38 +01:00
|
|
|
auto layout = new QVBoxLayout();
|
2017-12-23 23:24:35 +01:00
|
|
|
layout->setContentsMargins(10, 5, 10, 5);
|
2017-12-23 22:17:38 +01:00
|
|
|
layout->addWidget(displayText);
|
|
|
|
this->setLayout(layout);
|
|
|
|
|
2018-01-22 20:14:43 +01:00
|
|
|
this->fontChangedConnection =
|
|
|
|
singletons::FontManager::getInstance().fontChanged.connect([this] { this->updateFont(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
TooltipWidget::~TooltipWidget()
|
|
|
|
{
|
|
|
|
this->fontChangedConnection.disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TooltipWidget::dpiMultiplierChanged(float, float)
|
|
|
|
{
|
|
|
|
this->updateFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TooltipWidget::updateFont()
|
|
|
|
{
|
|
|
|
this->setFont(singletons::FontManager::getInstance().getFont(
|
|
|
|
singletons::FontManager::Type::MediumSmall, this->getDpiMultiplier()));
|
2017-12-23 22:17:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TooltipWidget::setText(QString text)
|
|
|
|
{
|
|
|
|
this->displayText->setText(text);
|
|
|
|
}
|
|
|
|
|
2018-01-22 15:06:36 +01:00
|
|
|
void TooltipWidget::moveTo(QWidget *parent, QPoint point)
|
2017-12-23 22:17:38 +01:00
|
|
|
{
|
|
|
|
point.rx() += 16;
|
|
|
|
point.ry() += 16;
|
2018-01-22 20:14:43 +01:00
|
|
|
|
2017-12-23 22:17:38 +01:00
|
|
|
this->move(point);
|
2018-01-22 20:14:43 +01:00
|
|
|
this->moveIntoDesktopRect(parent);
|
2017-12-23 22:17:38 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 15:06:36 +01:00
|
|
|
void TooltipWidget::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
|
|
|
this->moveIntoDesktopRect(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TooltipWidget::moveIntoDesktopRect(QWidget *parent)
|
|
|
|
{
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
|
|
|
|
QRect s = desktop->screenGeometry(parent);
|
2018-01-22 20:14:43 +01:00
|
|
|
QPoint p = this->pos();
|
2018-01-22 15:06:36 +01:00
|
|
|
|
2018-01-22 20:14:43 +01:00
|
|
|
if (p.x() < s.left()) {
|
|
|
|
p.setX(s.left());
|
2018-01-22 15:06:36 +01:00
|
|
|
}
|
2018-01-22 20:14:43 +01:00
|
|
|
if (p.y() < s.top()) {
|
|
|
|
p.setY(s.top());
|
2018-01-22 15:06:36 +01:00
|
|
|
}
|
2018-01-22 20:14:43 +01:00
|
|
|
if (p.x() + this->width() > s.right()) {
|
|
|
|
p.setX(s.right() - this->width());
|
2018-01-22 15:06:36 +01:00
|
|
|
}
|
2018-01-22 20:14:43 +01:00
|
|
|
if (p.y() + this->height() > s.bottom()) {
|
|
|
|
p.setY(s.bottom() - this->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p != this->pos()) {
|
|
|
|
this->move(p);
|
2018-01-22 15:06:36 +01:00
|
|
|
}
|
2018-01-22 20:14:43 +01:00
|
|
|
}
|
2018-01-22 15:06:36 +01:00
|
|
|
|
2018-01-22 20:14:43 +01:00
|
|
|
void TooltipWidget::changeEvent(QEvent *)
|
|
|
|
{
|
|
|
|
// clear parents event
|
|
|
|
}
|
|
|
|
|
|
|
|
void TooltipWidget::leaveEvent(QEvent *)
|
|
|
|
{
|
|
|
|
// clear parents event
|
2018-01-22 15:06:36 +01:00
|
|
|
}
|
2017-12-23 22:17:38 +01:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|