Added: Analysis panel which shows the calculated frequency response of the filters for the selected device and channel.
Improved: GUIs of GraphicEQ and Copy command can now be resized Improved: GraphicEQ GUI can now be zoomed separately in X and Y direction using mouse wheel on rulers. Also now shows values at mouse position. Fixed: Original APO was not released when E-APO was shutting down, leading to a memory leak.
This commit is contained in:
1 parent
04d22adb07
commit
0895d84055
49 files changed
+2228
-267
No files matched your search
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of EqualizerAPO, a system-wide equalizer.
|
||||
Copyright (C) 2015 Jonas Thedering
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include "ExponentialSpinBox.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
ExponentialSpinBox::ExponentialSpinBox(QWidget* parent)
|
||||
: QSpinBox(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ExponentialSpinBox::stepBy(int steps)
|
||||
{
|
||||
qint64 v = value();
|
||||
if(steps > 0)
|
||||
{
|
||||
v <<= steps;
|
||||
if(v > maximum())
|
||||
v = maximum();
|
||||
}
|
||||
else
|
||||
{
|
||||
v >>= -steps;
|
||||
if(v < minimum())
|
||||
v = minimum();
|
||||
}
|
||||
|
||||
setValue((int)v);
|
||||
}
|
||||
|
||||
int ExponentialSpinBox::valueFromText(const QString& text) const
|
||||
{
|
||||
int value = QSpinBox::valueFromText(text);
|
||||
value = exp2(round(log2(value)));
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
This file is part of EqualizerAPO, a system-wide equalizer.
|
||||
Copyright (C) 2015 Jonas Thedering
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <QSpinBox>
|
||||
|
||||
class ExponentialSpinBox : public QSpinBox
|
||||
{
|
||||
public:
|
||||
ExponentialSpinBox(QWidget* parent = 0);
|
||||
|
||||
public:
|
||||
void stepBy(int steps) override;
|
||||
|
||||
protected:
|
||||
int valueFromText(const QString& text) const override;
|
||||
};
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "FrequencyPlotView.h"
|
||||
#include "FrequencyPlotHRuler.h"
|
||||
@@ -33,6 +34,7 @@ FrequencyPlotHRuler::FrequencyPlotHRuler(QWidget* parent) :
|
||||
void FrequencyPlotHRuler::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
FrequencyPlotView* view = qobject_cast<FrequencyPlotView*>(parentWidget());
|
||||
FrequencyPlotScene* s = view->scene();
|
||||
QFontMetrics metrics = painter.fontMetrics();
|
||||
@@ -40,6 +42,7 @@ void FrequencyPlotHRuler::paintEvent(QPaintEvent*)
|
||||
|
||||
QPointF topLeft = view->mapToScene(0, 0);
|
||||
QPointF bottomRight = view->mapToScene(view->viewport()->width(), view->viewport()->height());
|
||||
int offsetLeft = view->viewportMargins().left();
|
||||
double fromHz = s->xToHz(topLeft.x());
|
||||
double toHz = s->xToHz(bottomRight.x());
|
||||
const vector<double>& bands = s->getBands();
|
||||
@@ -61,7 +64,7 @@ void FrequencyPlotHRuler::paintEvent(QPaintEvent*)
|
||||
else
|
||||
text = QString("%0k").arg(hz / 1000);
|
||||
if(metrics.width(text) + 2 < s->hzToX(hz + hzBase) - x)
|
||||
painter.drawText(x - topLeft.x() + height() + 1, 0, 0, height(), Qt::TextDontClip | Qt::AlignCenter, text);
|
||||
painter.drawText(x - topLeft.x() + offsetLeft + 1, 0, 0, height(), Qt::TextDontClip | Qt::AlignCenter, text);
|
||||
}
|
||||
|
||||
hz += hzBase;
|
||||
@@ -83,8 +86,50 @@ void FrequencyPlotHRuler::paintEvent(QPaintEvent*)
|
||||
text = QString("%0").arg(hz);
|
||||
else
|
||||
text = QString("%0k").arg(hz / 1000);
|
||||
painter.drawText(x - topLeft.x() + height() + 1, 0, 0, height(), Qt::TextDontClip | Qt::AlignCenter, text);
|
||||
painter.drawText(x - topLeft.x() + offsetLeft + 1, 0, 0, height(), Qt::TextDontClip | Qt::AlignCenter, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPoint mousePos = view->getLastMousePos();
|
||||
if(!mousePos.isNull())
|
||||
{
|
||||
QPointF mouseScenePos = view->mapToScene(mousePos);
|
||||
|
||||
double hz = s->xToHz(mouseScenePos.x());
|
||||
double x = s->hzToX(hz);
|
||||
if(x != -1)
|
||||
{
|
||||
QString text = QString("%0").arg(hz, 0, 'f', 1);
|
||||
QFontMetrics metrics = painter.fontMetrics();
|
||||
QRectF rect = metrics.boundingRect(text);
|
||||
float center = x - topLeft.x() + offsetLeft + 1;
|
||||
rect = QRectF(center - ceil(rect.width() / 2) - 2 + 0.5, ceil(height() / 2) - ceil(rect.height() / 2) + 1.5, rect.width() + 3, rect.height());
|
||||
QPainterPath path;
|
||||
path.addRect(rect);
|
||||
QPainterPath topTriangle;
|
||||
topTriangle.moveTo(QPoint(center - 3, rect.top() + 1));
|
||||
topTriangle.lineTo(QPoint(center + 3, rect.top() + 1));
|
||||
topTriangle.lineTo(QPoint(center, rect.top() - 3));
|
||||
path = path.united(topTriangle);
|
||||
|
||||
painter.setPen(Qt::black);
|
||||
painter.setBrush(Qt::white);
|
||||
painter.drawPath(path);
|
||||
painter.setPen(Qt::blue);
|
||||
painter.drawText(center, 0, 0, height(), Qt::TextDontClip | Qt::AlignCenter, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FrequencyPlotHRuler::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
FrequencyPlotView* view = qobject_cast<FrequencyPlotView*>(parentWidget());
|
||||
view->zoom(event->angleDelta().y(), 0, event->x() - view->viewportMargins().left(), 0);
|
||||
}
|
||||
|
||||
void FrequencyPlotHRuler::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
FrequencyPlotView* view = qobject_cast<FrequencyPlotView*>(parentWidget());
|
||||
view->setLastMousePos(QPoint(event->x() - view->viewportMargins().left(), view->viewport()->height() - 1));
|
||||
}
|
||||
@@ -29,4 +29,6 @@ public:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
void wheelEvent(QWheelEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
};
|
||||
@@ -48,7 +48,7 @@ void FrequencyPlotScene::addItem(FrequencyPlotItem* item)
|
||||
|
||||
double FrequencyPlotScene::xToHz(double x)
|
||||
{
|
||||
return pow(maxHz / minHz, x / zoom / maxX) * minHz;
|
||||
return pow(maxHz / minHz, x / zoomX / maxX) * minHz;
|
||||
}
|
||||
|
||||
double FrequencyPlotScene::hzToX(double hz)
|
||||
@@ -56,12 +56,12 @@ double FrequencyPlotScene::hzToX(double hz)
|
||||
if(hz < minHz || hz > maxHz)
|
||||
return -1;
|
||||
|
||||
return log(hz / minHz) / log(maxHz / minHz) * maxX * zoom;
|
||||
return log(hz / minHz) / log(maxHz / minHz) * maxX * zoomX;
|
||||
}
|
||||
|
||||
double FrequencyPlotScene::yToDb(double y)
|
||||
{
|
||||
return (minDb + (1 - y / zoom / maxY) * (maxDb - minDb));
|
||||
return (minDb + (1 - y / zoomY / maxY) * (maxDb - minDb));
|
||||
}
|
||||
|
||||
double FrequencyPlotScene::dbToY(double db)
|
||||
@@ -69,17 +69,23 @@ double FrequencyPlotScene::dbToY(double db)
|
||||
if(db < minDb || db > maxDb)
|
||||
return -1;
|
||||
|
||||
return (1 - (db - minDb) / (maxDb - minDb)) * maxY * zoom;
|
||||
return (1 - (db - minDb) / (maxDb - minDb)) * maxY * zoomY;
|
||||
}
|
||||
|
||||
double FrequencyPlotScene::getZoom() const
|
||||
double FrequencyPlotScene::getZoomX() const
|
||||
{
|
||||
return zoom;
|
||||
return zoomX;
|
||||
}
|
||||
|
||||
void FrequencyPlotScene::setZoom(double value)
|
||||
double FrequencyPlotScene::getZoomY() const
|
||||
{
|
||||
zoom = value;
|
||||
return zoomY;
|
||||
}
|
||||
|
||||
void FrequencyPlotScene::setZoom(double zoomX, double zoomY)
|
||||
{
|
||||
this->zoomX = zoomX;
|
||||
this->zoomY = zoomY;
|
||||
updateSceneRect();
|
||||
|
||||
for(QGraphicsItem* item : items())
|
||||
@@ -91,7 +97,7 @@ void FrequencyPlotScene::setZoom(double value)
|
||||
|
||||
void FrequencyPlotScene::updateSceneRect()
|
||||
{
|
||||
setSceneRect(0, 0, maxX * zoom, maxY * zoom);
|
||||
setSceneRect(0, 0, maxX * zoomX, maxY * zoomY);
|
||||
}
|
||||
|
||||
int FrequencyPlotScene::getBandCount() const
|
||||
|
||||
@@ -37,8 +37,9 @@ public:
|
||||
double yToDb(double y);
|
||||
double dbToY(double db);
|
||||
|
||||
double getZoom() const;
|
||||
void setZoom(double value);
|
||||
double getZoomX() const;
|
||||
double getZoomY() const;
|
||||
void setZoom(double zoomX, double zoomY);
|
||||
|
||||
int getBandCount() const;
|
||||
virtual void setBandCount(int value);
|
||||
@@ -54,6 +55,7 @@ protected:
|
||||
private:
|
||||
void updateSceneRect();
|
||||
|
||||
double zoom = 1.0;
|
||||
double zoomX = 1.0;
|
||||
double zoomY = 1.0;
|
||||
int bandCount = -1;
|
||||
};
|
||||
@@ -17,6 +17,8 @@
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include "FrequencyPlotView.h"
|
||||
#include "FrequencyPlotScene.h"
|
||||
#include "FrequencyPlotVRuler.h"
|
||||
@@ -29,13 +31,13 @@ FrequencyPlotVRuler::FrequencyPlotVRuler(QWidget *parent) :
|
||||
void FrequencyPlotVRuler::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
FrequencyPlotView* view = qobject_cast<FrequencyPlotView*>(parentWidget());
|
||||
FrequencyPlotScene* scene = view->scene();
|
||||
FrequencyPlotScene* s = view->scene();
|
||||
|
||||
QPointF topLeft = view->mapToScene(0, 0);
|
||||
QPointF bottomRight = view->mapToScene(view->viewport()->width(), view->viewport()->height());
|
||||
double dbHeight = abs(scene->yToDb(topLeft.y()) - scene->yToDb(bottomRight.y()));
|
||||
double dbStep = dbHeight / 4;
|
||||
double dbStep = abs(s->yToDb(0) - s->yToDb(30));
|
||||
|
||||
double dbBase = pow(10, floor(log10(dbStep)));
|
||||
if(dbStep >= 5 * dbBase)
|
||||
@@ -45,16 +47,58 @@ void FrequencyPlotVRuler::paintEvent(QPaintEvent*)
|
||||
else
|
||||
dbStep = dbBase;
|
||||
|
||||
double fromDb = floor(scene->yToDb(topLeft.y()) / dbStep) * dbStep;
|
||||
double toDb = ceil(scene->yToDb(bottomRight.y()) / dbStep) * dbStep;
|
||||
double fromDb = floor(s->yToDb(topLeft.y()) / dbStep) * dbStep;
|
||||
double toDb = ceil(s->yToDb(bottomRight.y()) / dbStep) * dbStep;
|
||||
|
||||
painter.setPen(QColor(50, 50, 50));
|
||||
for(double db = toDb; db <= fromDb; db += dbStep)
|
||||
{
|
||||
if(abs(db) < 1e-6)
|
||||
db = 0;
|
||||
double y = scene->dbToY(db);
|
||||
double y = s->dbToY(db);
|
||||
if(y != -1)
|
||||
painter.drawText(0, y - topLeft.y() - 1, width(), 0, Qt::TextDontClip | Qt::AlignCenter, QString("%0").arg(db));
|
||||
}
|
||||
|
||||
QPoint mousePos = view->getLastMousePos();
|
||||
if(!mousePos.isNull())
|
||||
{
|
||||
QPointF mouseScenePos = view->mapToScene(mousePos);
|
||||
|
||||
double db = s->yToDb(mouseScenePos.y());
|
||||
double y = s->dbToY(db);
|
||||
if(y != -1)
|
||||
{
|
||||
QString text = QString("%0").arg(db, 0, 'f', 1);
|
||||
QFontMetrics metrics = painter.fontMetrics();
|
||||
QRectF rect = metrics.boundingRect(text);
|
||||
float center = y - topLeft.y() - 1;
|
||||
rect = QRectF(ceil(width() / 2) - ceil(rect.width() / 2) - 2.5, center - rect.height() / 2 + 1, rect.width() + 3, rect.height());
|
||||
QPainterPath path;
|
||||
path.addRect(rect);
|
||||
QPainterPath rightTriangle;
|
||||
rightTriangle.moveTo(QPoint(rect.right(), center - 2));
|
||||
rightTriangle.lineTo(QPoint(rect.right(), center + 4));
|
||||
rightTriangle.lineTo(QPoint(rect.right() + 4, center + 1));
|
||||
path = path.united(rightTriangle);
|
||||
|
||||
painter.setPen(Qt::black);
|
||||
painter.setBrush(Qt::white);
|
||||
painter.drawPath(path);
|
||||
painter.setPen(Qt::blue);
|
||||
painter.drawText(0, center, width() - 2, 0, Qt::TextDontClip | Qt::AlignCenter, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FrequencyPlotVRuler::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
FrequencyPlotView* view = qobject_cast<FrequencyPlotView*>(parentWidget());
|
||||
view->zoom(0, event->angleDelta().y(), 0, event->y());
|
||||
}
|
||||
|
||||
void FrequencyPlotVRuler::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
FrequencyPlotView* view = qobject_cast<FrequencyPlotView*>(parentWidget());
|
||||
view->setLastMousePos(QPoint(0, min(event->y(), view->viewport()->height() - 1)));
|
||||
}
|
||||
@@ -29,4 +29,6 @@ public:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
void wheelEvent(QWheelEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
};
|
||||
@@ -29,9 +29,11 @@ using namespace std;
|
||||
FrequencyPlotView::FrequencyPlotView(QWidget *parent) :
|
||||
QGraphicsView(parent)
|
||||
{
|
||||
setViewportMargins(20, 0, 0, 20);
|
||||
setViewportMargins(32, 0, 0, 20);
|
||||
hRuler = new FrequencyPlotHRuler(this);
|
||||
vRuler = new FrequencyPlotVRuler(this);
|
||||
hRuler->setMouseTracking(true);
|
||||
vRuler->setMouseTracking(true);
|
||||
}
|
||||
|
||||
FrequencyPlotScene* FrequencyPlotView::scene() const
|
||||
@@ -58,8 +60,7 @@ void FrequencyPlotView::drawBackground(QPainter* painter, const QRectF& drawRect
|
||||
FrequencyPlotScene* s = scene();
|
||||
QPointF topLeft = mapToScene(0, 0);
|
||||
QPointF bottomRight = mapToScene(viewport()->width(), viewport()->height());
|
||||
double dbHeight = abs(s->yToDb(topLeft.y()) - s->yToDb(bottomRight.y()));
|
||||
double dbStep = dbHeight / 4;
|
||||
double dbStep = abs(s->yToDb(0) - s->yToDb(30));
|
||||
|
||||
double dbBase = pow(10, floor(log10(dbStep)));
|
||||
if(dbStep >= 5 * dbBase)
|
||||
@@ -120,27 +121,57 @@ void FrequencyPlotView::updateHRuler()
|
||||
hRuler->update();
|
||||
}
|
||||
|
||||
void FrequencyPlotView::wheelEvent(QWheelEvent* event)
|
||||
QPoint FrequencyPlotView::getLastMousePos() const
|
||||
{
|
||||
return lastMousePos;
|
||||
}
|
||||
|
||||
void FrequencyPlotView::setLastMousePos(QPoint pos)
|
||||
{
|
||||
lastMousePos = pos;
|
||||
hRuler->update();
|
||||
vRuler->update();
|
||||
}
|
||||
|
||||
void FrequencyPlotView::zoom(int deltaX, int deltaY, int mouseX, int mouseY)
|
||||
{
|
||||
FrequencyPlotScene* s = scene();
|
||||
QPointF scenePos = mapToScene(event->pos());
|
||||
QPointF scenePos = mapToScene(mouseX, mouseY);
|
||||
double hz = s->xToHz(scenePos.x());
|
||||
double db = s->yToDb(scenePos.y());
|
||||
|
||||
qreal zoomFactor = pow(1.001, event->angleDelta().y());
|
||||
s->setZoom(max(0.5, min(30, s->getZoom() * zoomFactor)));
|
||||
qreal zoomFactorX = pow(1.001, deltaX);
|
||||
qreal zoomFactorY = pow(1.001, deltaY);
|
||||
double zoomX = max(0.5, min(30.0, s->getZoomX() * zoomFactorX));
|
||||
double zoomY = max(0.5, min(30.0, s->getZoomY() * zoomFactorY));
|
||||
s->setZoom(zoomX, zoomY);
|
||||
|
||||
double x = s->hzToX(hz);
|
||||
if(x != -1)
|
||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + round(x - scenePos.x()));
|
||||
double y = s->dbToY(db);
|
||||
if(y != -1)
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->value() + round(y - scenePos.y()));
|
||||
if(deltaX != 0)
|
||||
{
|
||||
double x = s->hzToX(hz);
|
||||
if(x != -1)
|
||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + round(x - scenePos.x()));
|
||||
}
|
||||
|
||||
if(deltaY != 0)
|
||||
{
|
||||
double y = s->dbToY(db);
|
||||
if(y != -1)
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->value() + round(y - scenePos.y()));
|
||||
}
|
||||
|
||||
resetCachedContent();
|
||||
viewport()->update();
|
||||
hRuler->update();
|
||||
vRuler->update();
|
||||
if(deltaX != 0)
|
||||
hRuler->update();
|
||||
if(deltaY != 0)
|
||||
vRuler->update();
|
||||
}
|
||||
|
||||
void FrequencyPlotView::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
int delta = event->angleDelta().y();
|
||||
zoom(delta, delta, event->x(), event->y());
|
||||
}
|
||||
|
||||
void FrequencyPlotView::scrollContentsBy(int dx, int dy)
|
||||
@@ -158,15 +189,16 @@ void FrequencyPlotView::resizeEvent(QResizeEvent* event)
|
||||
QGraphicsView::resizeEvent(event);
|
||||
|
||||
const QRect rect = viewport()->geometry();
|
||||
hRuler->setGeometry(rect.x() - 20, rect.y() + rect.height(), rect.width() + 20, 20);
|
||||
vRuler->setGeometry(rect.x() - 20, rect.y(), 20, rect.height() + 20);
|
||||
QMargins margins = viewportMargins();
|
||||
hRuler->setGeometry(rect.x() - margins.left(), rect.y() + rect.height(), rect.width() + margins.left(), margins.bottom());
|
||||
vRuler->setGeometry(rect.x() - margins.left(), rect.y(), margins.left(), rect.height() + margins.bottom());
|
||||
}
|
||||
|
||||
void FrequencyPlotView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
|
||||
lastMousePos = event->pos();
|
||||
setLastMousePos(event->pos());
|
||||
}
|
||||
|
||||
void FrequencyPlotView::mouseMoveEvent(QMouseEvent* event)
|
||||
@@ -180,7 +212,12 @@ void FrequencyPlotView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
}
|
||||
lastMousePos = event->pos();
|
||||
setLastMousePos(event->pos());
|
||||
}
|
||||
|
||||
void FrequencyPlotView::leaveEvent(QEvent*)
|
||||
{
|
||||
setLastMousePos(QPoint());
|
||||
}
|
||||
|
||||
void FrequencyPlotView::showEvent(QShowEvent* event)
|
||||
|
||||
@@ -38,12 +38,19 @@ public:
|
||||
|
||||
void updateHRuler();
|
||||
|
||||
QPoint getLastMousePos() const;
|
||||
void setLastMousePos(QPoint pos);
|
||||
using QGraphicsView::viewportMargins;
|
||||
|
||||
void zoom(int deltaX, int deltaY, int mouseX, int mouseY);
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent* event) override;
|
||||
void scrollContentsBy(int dx, int dy) override;
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void leaveEvent(QEvent*) override;
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
This file is part of EqualizerAPO, a system-wide equalizer.
|
||||
Copyright (C) 2015 Jonas Thedering
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "ResizeCorner.h"
|
||||
|
||||
ResizeCorner::ResizeCorner(FilterTable* filterTable, QSize minimumSize, QSize maximumSize, std::function<QSize()> getFunc, std::function<void(QSize)> setFunc, QWidget *parent)
|
||||
: QLabel(parent), minimumSize(minimumSize), maximumSize(maximumSize), getFunc(getFunc), setFunc(setFunc), filterTable(filterTable)
|
||||
{
|
||||
setPixmap(QPixmap(":/icons/resize_corner.png"));
|
||||
setCursor(Qt::SizeFDiagCursor);
|
||||
}
|
||||
|
||||
void ResizeCorner::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
filterTable->setMinimumHeightHint(filterTable->height());
|
||||
QSize size = getFunc();
|
||||
offsetX = size.width() - event->globalX();
|
||||
offsetY = size.height() - event->globalY();
|
||||
}
|
||||
|
||||
void ResizeCorner::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
QSize size;
|
||||
size.setWidth(offsetX + event->globalPos().x());
|
||||
size.setHeight(offsetY + event->globalPos().y());
|
||||
size = size.expandedTo(minimumSize);
|
||||
size = size.boundedTo(maximumSize);
|
||||
setFunc(size);
|
||||
}
|
||||
|
||||
void ResizeCorner::mouseReleaseEvent(QMouseEvent*)
|
||||
{
|
||||
filterTable->setMinimumHeightHint(0);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
This file is part of EqualizerAPO, a system-wide equalizer.
|
||||
Copyright (C) 2015 Jonas Thedering
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <QLabel>
|
||||
|
||||
#include "Editor/FilterTable.h"
|
||||
|
||||
class ResizeCorner : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ResizeCorner(FilterTable* filterTable, QSize minimumSize, QSize maximumSize,
|
||||
std::function<QSize()> getFunc, std::function<void(QSize)> setFunc, QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
|
||||
private:
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
QSize minimumSize;
|
||||
QSize maximumSize;
|
||||
FilterTable* filterTable;
|
||||
std::function<QSize()> getFunc;
|
||||
std::function<void(QSize)> setFunc;
|
||||
};
|
||||
Reference in new issue
Block a user