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 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())
|
|
|
|
{
|
2017-12-23 23:24:35 +01:00
|
|
|
QColor black(0, 0, 0);
|
|
|
|
QColor white(255, 255, 255);
|
2017-12-23 22:17:38 +01:00
|
|
|
|
|
|
|
QPalette palette;
|
2017-12-23 23:24:35 +01:00
|
|
|
palette.setColor(QPalette::WindowText, white);
|
|
|
|
palette.setColor(QPalette::Background, black);
|
2017-12-23 22:17:38 +01:00
|
|
|
this->setPalette(palette);
|
2018-01-07 23:47:08 +01:00
|
|
|
this->displayText->setStyleSheet("color: #ffffff");
|
2017-12-23 22:17:38 +01:00
|
|
|
this->setWindowOpacity(0.8);
|
2018-01-22 15:06:36 +01:00
|
|
|
this->setFont(singletons::FontManager::getInstance().getFont(
|
|
|
|
singletons::FontManager::Type::MediumSmall, this->getDpiMultiplier()));
|
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 |
|
|
|
|
Qt::X11BypassWindowManagerHint);
|
2017-12-23 22:17:38 +01:00
|
|
|
|
|
|
|
displayText->setAlignment(Qt::AlignHCenter);
|
2018-01-07 23:47:08 +01:00
|
|
|
displayText->setText("lmao xD");
|
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);
|
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::FontManager::getInstance().fontChanged.connect([this] {
|
2018-01-22 15:06:36 +01:00
|
|
|
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;
|
|
|
|
this->move(point);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
QRect w = this->geometry();
|
|
|
|
|
|
|
|
if (w.left() < s.left()) {
|
|
|
|
w.moveLeft(s.left());
|
|
|
|
}
|
|
|
|
if (w.right() < s.right()) {
|
|
|
|
w.moveRight(s.right());
|
|
|
|
}
|
|
|
|
if (w.top() < s.top()) {
|
|
|
|
w.moveTop(s.top());
|
|
|
|
}
|
|
|
|
if (w.bottom() < s.bottom()) {
|
|
|
|
w.moveBottom(s.bottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setGeometry(w);
|
|
|
|
}
|
2017-12-23 22:17:38 +01:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|