-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWaterFallScrollArea.cpp
89 lines (75 loc) · 2.11 KB
/
WaterFallScrollArea.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "WaterFallScrollArea.h"
#include "WaterFallWidget.h"
#include "ImageSreachThread.h"
CWaterFallScrollArea::CWaterFallScrollArea(QWidget* parant /*= 0*/)
: QScrollArea(parant)
, m_content(0)
{
m_content = new CWaterFallWidget;
m_content->setFixedHeight(30);
setWidget(m_content);
connect(verticalScrollBar(), &QScrollBar::rangeChanged, this, &CWaterFallScrollArea::onVerticalBarRangeChanged);
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &CWaterFallScrollArea::onVerticalBarValueChanged);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAcceptDrops(true);
}
void CWaterFallScrollArea::resizeEvent(QResizeEvent *event)
{
Q_ASSERT(m_content);
m_content->setFixedWidth(width()-2);
m_content->setFixedHeight(height() + 100);
}
void CWaterFallScrollArea::onVerticalBarRangeChanged(int min, int max)
{
qDebug() << QString("range changed: %1 - %2").arg(min).arg(max);
}
void CWaterFallScrollArea::onVerticalBarValueChanged(int value)
{
qDebug() << QString("value moved: %1").arg(value);
Q_ASSERT(m_content);
if (value >= (verticalScrollBar()->maximum() - 5))
{
m_content->onScrollToBottom(height());
}
else if (value <= 5)
{
m_content->onScrollToTop(height());
}
}
void CWaterFallScrollArea::setImageList(const QStringList& listImagePath)
{
Q_ASSERT(m_content);
m_content->setImageList(listImagePath);
}
void CWaterFallScrollArea::dropEvent(QDropEvent *event)
{
setEnabled(false);
if (event->mimeData()->hasUrls())
{
QList<QUrl> urls = event->mimeData()->urls();
if (!urls.isEmpty())
{
QStringList paths;
for (int i = 0; i < urls.size(); i++ )
{
if (urls[i].isLocalFile())
{
QEventLoop loop;
CImageSreachThread sreachThread;
connect(&sreachThread, &CImageSreachThread::finished, &loop, &QEventLoop::quit);
sreachThread.setRootPath(urls[i].toLocalFile());
sreachThread.start();
loop.exec();
paths.append(sreachThread.fileList());
}
}
setImageList(paths);
}
}
setEnabled(true);
}
void CWaterFallScrollArea::dragEnterEvent(QDragEnterEvent *event)
{
event->accept();
}