blob: 240017cfb3375bb5cec022dcb8710fb91efae083 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include <QLabel>
#include <QTimer>
#include <QHBoxLayout>
#include <QDesktopWidget>
#include <QApplication>
#include <kwindowsystem.h>
#include "toolwindow.h"
ToolWindow::ToolWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){
setWindowOpacity(0.8);
KWindowSystem::setOnAllDesktops(winId(), true);
KWindowSystem::setState(winId(), NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager);
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);
}
void ToolWindow::setText(const QString &text){
mLabel->setText(text);
}
void ToolWindow::toHTML(const QString &text){
QString html;
html.append(QString("<p style=\"margin:7px;\"><span style=\"font-weight: bold; font-size: large;\">%1</span></p>").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();
}
|