2018-06-26 14:09:39 +02:00
|
|
|
#include "TooltipWidget.hpp"
|
2018-04-28 15:20:18 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Fonts.hpp"
|
|
|
|
#include "singletons/Themes.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>
|
|
|
|
|
2018-05-24 10:03:07 +02:00
|
|
|
#ifdef USEWINSDK
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2017-12-23 22:17:38 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-23 22:17:38 +01:00
|
|
|
TooltipWidget::TooltipWidget(BaseWidget *parent)
|
2018-05-24 10:03:07 +02:00
|
|
|
: BaseWindow(parent, BaseWindow::TopMost)
|
2017-12-23 22:17:38 +01:00
|
|
|
, displayText(new QLabel())
|
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
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();
|
2018-01-22 20:52:32 +01:00
|
|
|
this->setStayInScreenRect(true);
|
2017-12-23 22:17:38 +01:00
|
|
|
|
|
|
|
this->setAttribute(Qt::WA_ShowWithoutActivating);
|
2018-06-05 19:08:49 +02:00
|
|
|
this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint |
|
2018-05-24 10:03:07 +02:00
|
|
|
Qt::BypassWindowManagerHint);
|
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-04-28 15:20:18 +02:00
|
|
|
this->fontChangedConnection = app->fonts->fontChanged.connect([this] { this->updateFont(); });
|
2018-01-22 20:14:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TooltipWidget::~TooltipWidget()
|
|
|
|
{
|
|
|
|
this->fontChangedConnection.disconnect();
|
|
|
|
}
|
|
|
|
|
2018-05-24 10:03:07 +02:00
|
|
|
#ifdef USEWINSDK
|
|
|
|
void TooltipWidget::raise()
|
|
|
|
{
|
2018-05-26 17:11:09 +02:00
|
|
|
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0,
|
2018-05-24 10:03:07 +02:00
|
|
|
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()
|
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
this->setFont(
|
2018-06-28 19:51:07 +02:00
|
|
|
app->fonts->getFont(Fonts::Type::ChatMediumSmall, this->getScale()));
|
2017-12-23 22:17:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-01-22 15:06:36 +01:00
|
|
|
}
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2017-12-23 22:17:38 +01:00
|
|
|
} // namespace chatterino
|