mirror-chatterino2/src/widgets/tooltipwidget.cpp

70 lines
1.7 KiB
C++
Raw Normal View History

#include "tooltipwidget.hpp"
2017-12-31 00:50:07 +01:00
#include "singletons/fontmanager.hpp"
#include "singletons/thememanager.hpp"
2018-01-22 20:14:43 +01:00
#include <QDebug>
#include <QDesktopWidget>
#include <QStyle>
#include <QVBoxLayout>
namespace chatterino {
namespace widgets {
TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow(parent)
, displayText(new QLabel())
{
2018-01-22 20:14:43 +01:00
this->setStyleSheet("color: #fff; background: #000");
this->setWindowOpacity(0.8);
2018-01-22 20:14:43 +01:00
this->updateFont();
this->setStayInScreenRect(true);
this->setAttribute(Qt::WA_ShowWithoutActivating);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
2018-01-22 20:14:43 +01:00
Qt::X11BypassWindowManagerHint | Qt::BypassWindowManagerHint |
Qt::SubWindow);
displayText->setAlignment(Qt::AlignHCenter);
2018-01-22 20:14:43 +01:00
displayText->setText("tooltip text");
auto layout = new QVBoxLayout();
layout->setContentsMargins(10, 5, 10, 5);
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();
}
2018-01-25 20:49:49 +01:00
void TooltipWidget::scaleChangedEvent(float)
2018-01-22 20:14:43 +01:00
{
this->updateFont();
}
void TooltipWidget::updateFont()
{
this->setFont(singletons::FontManager::getInstance().getFont(
2018-01-25 20:49:49 +01:00
singletons::FontManager::Type::MediumSmall, this->getScale()));
}
void TooltipWidget::setText(QString text)
{
this->displayText->setText(text);
}
2018-01-22 20:14:43 +01:00
void TooltipWidget::changeEvent(QEvent *)
{
// clear parents event
}
void TooltipWidget::leaveEvent(QEvent *)
{
// clear parents event
}
} // namespace widgets
} // namespace chatterino