-
Notifications
You must be signed in to change notification settings - Fork 0
/
hintwindow.cpp
64 lines (56 loc) · 1.7 KB
/
hintwindow.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "hintwindow.h"
#include "ui_hintwindow.h"
#include <QDesktopWidget>
static const int hintWindowDeltaX = 4;
static const int hintWindowDeltaY = 16;
//******************************************************************************************************
/*!
*\class HintWindow
*\brief Окно для отображения всплывающей подсказки
*/
//******************************************************************************************************
HintWindow::HintWindow(QWidget *parent)
:QWidget(parent, Qt::Window | Qt::FramelessWindowHint | Qt::ToolTip)
,ui(new Ui::HintWindow)
{
ui->setupUi(this);
}
HintWindow::~HintWindow()
{
delete ui;
}
void HintWindow::setText(const QString &value)
{
ui->label->setText(value);
adjustSize();
}
QString HintWindow::text() const
{
return ui->label->text();
}
void HintWindow::showAt(const QPoint &cursorPosition)
{
ui->label->adjustSize();
QSize ls = ui->label->size();
QSize ss = screenSize(this);
QPoint windowPosition(cursorPosition.x() + hintWindowDeltaX, cursorPosition.y() + hintWindowDeltaY);
if (windowPosition.x() + ls.width() > ss.width())
{
windowPosition.setX(windowPosition.x() - ls.width() - hintWindowDeltaX*2);
}
if (windowPosition.y() + ls.height() > ss.height())
{
windowPosition.setY(windowPosition.y() - ls.height() - hintWindowDeltaY*2);
}
move(windowPosition);
show();
}
QSize HintWindow::screenSize(const QWidget *widget)
{
QSize result;
QDesktopWidget *desktop = qApp->desktop();
int screen = desktop->screenNumber(widget);
QRect screenRect = desktop->screenGeometry(screen);
result = screenRect.size();
return result;
}