mirror-chatterino2/src/widgets/TooltipWidget.cpp

99 lines
2.2 KiB
C++
Raw Normal View History

2018-06-26 14:09:39 +02:00
#include "TooltipWidget.hpp"
2018-06-26 14:09:39 +02:00
#include "Application.hpp"
#include "singletons/FontManager.hpp"
#include "singletons/ThemeManager.hpp"
2018-01-22 20:14:43 +01:00
#include <QDebug>
#include <QDesktopWidget>
#include <QStyle>
#include <QVBoxLayout>
#ifdef USEWINSDK
#include <Windows.h>
#endif
namespace chatterino {
2018-05-26 17:11:09 +02:00
TooltipWidget *TooltipWidget::getInstance()
{
static TooltipWidget *tooltipWidget = nullptr;
if (tooltipWidget == nullptr) {
tooltipWidget = new TooltipWidget();
}
return tooltipWidget;
}
TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow(parent, BaseWindow::TopMost)
, displayText(new QLabel())
{
auto app = getApp();
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::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint |
Qt::BypassWindowManagerHint);
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);
this->fontChangedConnection = app->fonts->fontChanged.connect([this] { this->updateFont(); });
2018-01-22 20:14:43 +01:00
}
TooltipWidget::~TooltipWidget()
{
this->fontChangedConnection.disconnect();
}
#ifdef USEWINSDK
void TooltipWidget::raise()
{
2018-05-26 17:11:09 +02:00
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
#endif
2018-05-16 14:55:45 +02:00
void TooltipWidget::themeRefreshEvent()
{
this->setStyleSheet("color: #fff; background: #000");
}
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()
{
auto app = getApp();
this->setFont(
2018-06-26 17:06:17 +02:00
app->fonts->getFont(chatterino::FontManager::Type::ChatMediumSmall, 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 chatterino