#include #include #include #include #include #include #include "toolwindow.h" ToolWindow::ToolWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){ setWindowOpacity(0.9); mLabel = new QLabel; mLabel->setFrameStyle(QFrame::Panel | QFrame::Plain); mLabel->setFont(QFont("courier", 16, QFont::Bold)); mLabel->setAlignment(Qt::AlignCenter); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(mLabel); mHideTimer = new QTimer(this); connect(mHideTimer, &QTimer::timeout, this, &QWidget::hide); setLayout(mainLayout); KWindowSystem::setOnAllDesktops(winId(), true); } void ToolWindow::setText(const QString &text){ mLabel->setText(text); } void ToolWindow::toHTML(const QString &text){ QString html; html.append(QString("

%1

").arg(text)); mLabel->setText(html); } void ToolWindow::showMe(){ QDesktopWidget *dw = QApplication::desktop(); QRect screenRect = dw->screenGeometry(QCursor::pos()); QPoint screenCenter = screenRect.center(); QPoint where(screenCenter.x() - width() / 2, 150); move(where); KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); mHideTimer->stop(); mHideTimer->start(5000); show(); raise(); }