-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowLessAction.cpp
More file actions
72 lines (54 loc) · 1.42 KB
/
WindowLessAction.cpp
File metadata and controls
72 lines (54 loc) · 1.42 KB
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
65
66
67
68
69
70
71
#include "painter.h"
#include "rectangle.h"
#include "shape.h"
#include "size.h"
#include "WindowLessAction.h"
class WindowWidget;
namespace {
const int SHAPE_PADING = 5;
}
WindowLessAction::WindowLessAction(WindowLessWidget* parent) : WindowLessWidget(parent)
{
}
WindowLessAction::~WindowLessAction()
{
if (m_shape)
delete m_shape;
}
void WindowLessAction::show()
{
WindowLessWidget::show();
if (m_pText)
{
getPainter()->drawText(m_pText, getRect());
return;
}
if (m_shape)
{
checkShapeSize();
checkShapeLoc();
m_shape->draw();
}
}
void WindowLessAction::checkShapeSize()
{
if (!m_shape)
return;
int width = getWidth();
int height = getHeight();
Size shapeSize = m_shape->getSize();
shapeSize.setWidth(shapeSize.getWidth() < width - SHAPE_PADING ? shapeSize.getWidth() : width - SHAPE_PADING);
shapeSize.setHeight(shapeSize.getHeight() < height - SHAPE_PADING ? shapeSize.getHeight() : height - SHAPE_PADING);
m_shape->resize(shapeSize.getWidth(), shapeSize.getHeight());
}
void WindowLessAction::checkShapeLoc()
{
Point& actionLoc = getLoc();
int actionWidth = getWidth();
int actionHeight = getHeight();
Size shapeSize = m_shape->getSize();
int diffWidth = (actionWidth - shapeSize.getWidth()) / 2;
int diffHeight = (actionHeight - shapeSize.getHeight()) / 2;
Point shapeNewLoc = {actionLoc.x() + diffWidth, actionLoc.y() + diffHeight};
m_shape->moveFunction(*m_shape->getBegin(), shapeNewLoc);
}