-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpicturesscrollarea.cpp
64 lines (55 loc) · 1.82 KB
/
picturesscrollarea.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
/** @file picturesscrollarea.cpp
* Soubor s tridou PicturesScrollArea dedici ze tridy QScrollArea,
* implementuje skrolovaci plochu do ktere bude umisten ram s fotkami
*/
#include "picturesscrollarea.h"
PicturesScrollArea::PicturesScrollArea(QWidget* parent)
: QScrollArea(parent)
{
setWidgetResizable(true);
setFocusPolicy(Qt::StrongFocus);
this->setFrameShape(QFrame::Panel);
this->setFrameShadow(QFrame::Sunken);
this->setBackgroundRole(QPalette::Light);
setAutoFillBackground(true);
}
void PicturesScrollArea::resizeEvent(QResizeEvent* event)
{
event->accept();
emit showImages();
}
QSize PicturesScrollArea::sizeHint() const
{
return QSize(850, 16777215);
}
void PicturesScrollArea::keyPressEvent(QKeyEvent* event)
{
emit processEvent(event);
}
void PicturesScrollArea::wheelEvent(QWheelEvent* event)
{
if (event->modifiers() & Qt::ControlModifier) {
event->accept();
if (event->angleDelta().y() < 0) {
emit changeSize(-1);
} else {
emit changeSize(1);
}
} else {
QScrollArea::wheelEvent(event);
}
}
void PicturesScrollArea::setImageFocus(int dy, int widgetHeight)
{
if (dy + this->widget()->pos().y() < 0) { // widget je nad scrollAreou
QScrollBar* scrollBar = verticalScrollBar();
scrollBar->setValue(scrollBar->value() + (dy + this->widget()->pos().y()));
} else if (dy > verticalScrollBar()->value() + this->contentsRect().height() - widgetHeight) { // widget je pod scrollAreou
QScrollBar* scrollBar = verticalScrollBar();
scrollBar->setValue(scrollBar->value() + (dy + this->widget()->pos().y()) - (this->contentsRect().height() - widgetHeight));
}
}
void PicturesScrollArea::shiftScrollBar(int dy)
{
verticalScrollBar()->setValue(verticalScrollBar()->value() + dy * 3);
}