2017-01-03 21:19:33 +01:00
|
|
|
#include "scrollbar.h"
|
2017-01-11 18:52:09 +01:00
|
|
|
#include "QPainter"
|
2017-01-03 21:19:33 +01:00
|
|
|
#include "colorscheme.h"
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
ScrollBar::ScrollBar(QWidget *widget)
|
|
|
|
: QWidget(widget)
|
|
|
|
, mutex()
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
resize(16, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollBar::~ScrollBar()
|
|
|
|
{
|
|
|
|
auto highlight = highlights;
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
while (highlight != NULL) {
|
2017-01-03 21:19:33 +01:00
|
|
|
auto tmp = highlight->next;
|
|
|
|
delete highlight;
|
|
|
|
highlight = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
ScrollBar::removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
mutex.lock();
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
ScrollBarHighlight *last = NULL;
|
|
|
|
ScrollBarHighlight *current = highlights;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
while (current != NULL) {
|
|
|
|
if (func(*current)) {
|
|
|
|
if (last == NULL) {
|
2017-01-03 21:19:33 +01:00
|
|
|
highlights = current->next;
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-03 21:19:33 +01:00
|
|
|
last->next = current->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto oldCurrent = current;
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
last = current;
|
|
|
|
|
|
|
|
delete oldCurrent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
ScrollBar::addHighlight(ScrollBarHighlight *highlight)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
mutex.lock();
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (highlights == NULL) {
|
2017-01-03 21:19:33 +01:00
|
|
|
highlights = highlight;
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-03 21:19:33 +01:00
|
|
|
highlight->next = highlights->next;
|
|
|
|
highlights->next = highlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
ScrollBar::paintEvent(QPaintEvent *)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
2017-01-06 23:28:48 +01:00
|
|
|
painter.fillRect(rect(), ColorScheme::instance().ScrollbarBG);
|
2017-01-03 21:19:33 +01:00
|
|
|
|
|
|
|
mutex.lock();
|
|
|
|
|
|
|
|
mutex.unlock();
|
|
|
|
}
|