-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhistogramwidget.cpp
48 lines (41 loc) · 1.08 KB
/
histogramwidget.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
#include "histogramwidget.h"
#include "playlistitem.h"
#include <QtGui>
HistogramWidget::HistogramWidget(QWidget *parent)
: QOpenGLWidget(parent), progress(-1), image(nullptr)
{
setAttribute(Qt::WA_AlwaysStackOnTop);
}
void HistogramWidget::mouseReleaseEvent(QMouseEvent *e)
{
float p = (float) e->pos().x() / width();
emit clicked(p);
e->accept();
}
void HistogramWidget::paintGL()
{
QPainter painter(this);
if (image) {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.drawImage(QRect(0,0,width(),height()), *image);
}
glLogicOp(GL_XOR);
glEnable(GL_COLOR_LOGIC_OP);
float p = progress * width();
painter.drawLine(QLineF(p, 0, p, height()));
glDisable(GL_COLOR_LOGIC_OP);
}
void HistogramWidget::updateProgress(float p)
{
progress = p;
update();
}
void HistogramWidget::updateImage(QImage *i)
{
qDebug() << this << "updateImage(QImage *)" << image << "->" << i;
QImage *temp = image;
image = i;
if (temp) delete temp;
update();
}