LayoutGadget improvements and migration

portability/boost
zetaPRIME 2019-06-28 21:46:09 -04:00
parent 212e46b67d
commit 5dc9befec8
10 changed files with 154 additions and 169 deletions

View File

@ -15,6 +15,7 @@ using namespace Xybrid::Config;
using namespace Xybrid::Audio;
#include "ui/patchboard/nodeobject.h"
#include "ui/gadgets/layoutgadget.h"
#include "ui/gadgets/knobgadget.h"
using namespace Xybrid::UI;
@ -71,30 +72,22 @@ void GainBalance::loadData(const QCborMap& m) {
void GainBalance::onGadgetCreated() {
if (!obj) return;
//obj->showName = false;
//obj->canRename = false;
obj->showPluginName = false;
obj->setGadgetSize(8+8*2+32*2, 64);
auto l = new LayoutGadget(obj);
{
auto k = new KnobGadget(obj->contents);
k->setPos(8, 16);
k->min = -60;
k->max = 6;
k->step = .1;
k->bind(gain);
auto k = new KnobGadget(l);
k->min = -60;
k->max = 6;
k->step = .1;
k->bind(gain);
k->setLabel("Gain");
k->fText = [](double d) { return QString("%1dB").arg(d); };
}
k->setLabel("Gain");
k->fText = [](double d) { return QString("%1dB").arg(d); };
{
auto k = new KnobGadget(obj->contents);
k->setPos(32+8+8, 16);
k->min = -1;
k->max = 1;
k->bind(balance);
k = new KnobGadget(l);
k->min = -1;
k->max = 1;
k->bind(balance);
k->setLabel("Balance");
}
k->setLabel("Balance");
}

View File

@ -11,6 +11,7 @@ using namespace Xybrid::Config;
using namespace Xybrid::Audio;
#include "ui/patchboard/nodeobject.h"
#include "ui/gadgets/layoutgadget.h"
#include "ui/gadgets/knobgadget.h"
using namespace Xybrid::UI;
@ -78,20 +79,15 @@ void Transpose::loadData(const QCborMap& m) {
void Transpose::onGadgetCreated() {
if (!obj) return;
//obj->showName = false;
//obj->canRename = false;
obj->showPluginName = false;
obj->setGadgetSize(12*2+32, 64);
auto l = new LayoutGadget(obj);
l->margin = 12;
{
auto k = new KnobGadget(obj->contents);
k->setPos(12, 16);
k->min = -24;
k->max = 24;
k->step = 1;
k->bind(amount);
auto k = new KnobGadget(l);
k->min = -24;
k->max = 24;
k->step = 1;
k->bind(amount);
k->setLabel("Transpose");
//k->fText = [](double d) { return QString("%1dB").arg(d); };
}
k->setLabel("Transpose");
}

View File

@ -13,6 +13,7 @@ using namespace Xybrid::Config;
using namespace Xybrid::Audio;
#include "ui/patchboard/nodeobject.h"
#include "ui/gadgets/layoutgadget.h"
#include "ui/gadgets/knobgadget.h"
using namespace Xybrid::UI;
@ -207,133 +208,79 @@ void I2x03::onGadgetCreated() {
return QString("?");
};
constexpr double w = 248;
constexpr double r1 = 16;
constexpr double r2 = r1+64;
constexpr double spc = 38;
constexpr double l = spc-32;
auto off = QPointF(spc, 0);
auto ol = new LayoutGadget(obj, true);
auto l1 = new LayoutGadget(ol);
auto l2 = new LayoutGadget(ol);
obj->setGadgetSize(w, 128);
KnobGadget* k;
{
KnobGadget* k;
k = new KnobGadget(l1);
k->min = 0;
k->max = 6;
k->step = 1;
k->stepPx = KnobGadget::BigStep;
k->bind(wave);
k->fText = wavetxt;
k->setLabel("Wave");
k = new KnobGadget(obj->contents);
k->setPos(l, r1);
k->min = 0;
k->max = 6;
k->step = 1;
k->stepPx = KnobGadget::BigStep;
k->bind(wave);
k->fText = wavetxt;
k->setLabel("Wave");
}
l1->addSpacer();
KnobGadget::autoCreate(l1, adsr);
{
// adsr group
auto g = QPointF(w-(spc*4), r1);
KnobGadget* k;
// blip group
k = new KnobGadget(obj->contents);
k->setPos(g + off*0);
k->min = 0.0;
k->max = 5.0;
k->step = .01;
k->bind(adsr.a);
k->setLabel("Attack");
k = new KnobGadget(l2);
k->min = 0.0;
k->max = 0.1;
k->step = .001;
k->bind(blipTime);
k->setLabel("Blip");
k = new KnobGadget(obj->contents);
k->setPos(g + off*1);
k->min = 0.0;
k->max = 5.0;
k->step = .01;
k->bind(adsr.d);
k->setLabel("Decay");
k = new KnobGadget(l2);
k->min = -1;
k->max = 4;
k->defaultVal = -1;
k->step = 1;
k->stepPx = KnobGadget::BigStep;
k->bind(blipWave);
k->fText = wavetxt;
k->setLabel("Wave");
k = new KnobGadget(obj->contents);
k->setPos(g + off*2);
k->min = 0.0;
k->max = 1.0;
k->defaultVal = 1.0;
k->step = .01;
k->bind(adsr.s);
k->setLabel("Sustain");
k = new KnobGadget(l2);
k->min = -12;
k->max = 12;
k->step = 1;
k->bind(blipNote);
k->setLabel("Note");
k = new KnobGadget(obj->contents);
k->setPos(g + off*3);
k->min = 0.0;
k->max = 5.0;
k->step = .01;
k->bind(adsr.r);
k->setLabel("Release");
}
l2->addSpacer();
{
// blip group
auto g = QPointF(l, r2);
KnobGadget* k;
// pwm group
k = new KnobGadget(obj->contents);
k->setPos(g + off*0);
k->min = 0.0;
k->max = 0.1;
k->step = .001;
k->bind(blipTime);
k->setLabel("Blip");
k = new KnobGadget(l2);
k->min = 0.0;
k->max = 1.0;
k->defaultVal = 0.75;
k->step = .01;
k->bind(pwmDepth);
k->fText = [](double d) {
return QString("%1%").arg(d*100, 0);
};
k->setLabel("PWM");
k = new KnobGadget(obj->contents);
k->setPos(g + off*1);
k->min = -1;
k->max = 4;
k->defaultVal = -1;
k->step = 1;
k->stepPx = KnobGadget::BigStep;
k->bind(blipWave);
k->fText = wavetxt;
k->setLabel("Wave");
k = new KnobGadget(l2);
k->min = 0.01;
k->max = 5.0;
k->defaultVal = 3.0;
k->step = .01;
k->bind(pwmTime);
k->setLabel("Time");
k = new KnobGadget(obj->contents);
k->setPos(g + off*2);
k->min = -12;
k->max = 12;
k->step = 1;
k->bind(blipNote);
k->setLabel("Note");
}
k = new KnobGadget(l2);
k->min = 0.0;
k->max = 1.0;
k->step = .01;
k->bind(pwmPhase);
k->setLabel("Phase");
{
// pwm group
auto g = QPointF(w-(spc*3), r2);
KnobGadget* k;
k = new KnobGadget(obj->contents);
k->setPos(g + off*0);
k->min = 0.0;
k->max = 1.0;
k->defaultVal = 0.75;
k->step = .01;
k->bind(pwmDepth);
k->fText = [](double d) {
return QString("%1%").arg(d*100, 0);
};
k->setLabel("PWM");
k = new KnobGadget(obj->contents);
k->setPos(g + off*1);
k->min = 0.01;
k->max = 5.0;
k->defaultVal = 3.0;
k->step = .01;
k->bind(pwmTime);
k->setLabel("Time");
k = new KnobGadget(obj->contents);
k->setPos(g + off*2);
k->min = 0.0;
k->max = 1.0;
k->step = .01;
k->bind(pwmPhase);
k->setLabel("Phase");
}
//
}

View File

@ -126,13 +126,9 @@ void Xriek::loadData(const QCborMap& m) {
}
void Xriek::onGadgetCreated() {
qreal xfirst = 6;
qreal line = 38;
auto l = new LayoutGadget(obj->contents);
obj->setGadgetSize((xfirst*2)+(line*1)+32, 32+32);
auto l = new LayoutGadget(obj);
{
auto k = new KnobGadget(l);
//k->setPos(xfirst, 16);
k->min = 0.0;
k->max = 5.0;
k->step = .01;
@ -142,7 +138,6 @@ void Xriek::onGadgetCreated() {
{
auto k = new KnobGadget(l);
//k->setPos(xfirst+line*1, 16);
k->min = 0.0;
k->max = 5.0;
k->step = .01;
@ -150,7 +145,6 @@ void Xriek::onGadgetCreated() {
k->setLabel("Saturate");
}
l->addSpacer();
KnobGadget::autoCreate(l, adsr);
l->updateLayout();
obj->setGadgetSize(obj->contents->childrenBoundingRect().bottomRight());
}

View File

@ -10,6 +10,8 @@ void Gadget::centerOn(const QPointF& newPos) {
if (auto nc = pos() + c; nc != newPos) setPos(newPos - (nc - newPos));
}
void Gadget::updateGeometry() { }
QRectF Gadget::layoutBoundingRect() const { return boundingRect(); }
void Gadget::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) { }

View File

@ -12,6 +12,8 @@ namespace Xybrid::UI {
void centerOn(const QPointF&);
inline void centerOn(qreal x, qreal y) { centerOn(QPointF(x, y)); }
virtual void updateGeometry();
virtual QRectF layoutBoundingRect() const;
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;

View File

@ -1,6 +1,25 @@
#include "layoutgadget.h"
using Xybrid::UI::LayoutGadget;
#include "ui/patchboard/nodeobject.h"
namespace Xybrid::UI {
class LayoutSpacerGadget : public Gadget {
public:
LayoutSpacerGadget(QGraphicsItem* parent = nullptr) : Gadget(parent) { }
~LayoutSpacerGadget() override = default;
QRectF boundingRect() const override;
};
}
using Xybrid::UI::LayoutSpacerGadget;
QRectF LayoutSpacerGadget::boundingRect() const {
auto l = static_cast<LayoutGadget*>(parentItem());
auto w = l->spacing;
return QRectF(QPointF(), QSizeF(w, w));
}
QPointF LayoutGadget::orient(const QPointF& o) const {
if (!vertical) return o;
return QPointF(o.y(), o.x());
@ -16,24 +35,40 @@ QRectF LayoutGadget::orient(const QRectF& o) const {
return o.transposed();
}
LayoutGadget::LayoutGadget(QGraphicsItem* parent) : Gadget(parent) { }
LayoutGadget::LayoutGadget(QGraphicsItem* parent, bool vertical) : Gadget(parent), vertical(vertical) {
if (vertical) { // different defaults for vertical layouts
margin = 0;
spacing = 3;
}
}
void LayoutGadget::updateLayout() {
LayoutGadget::LayoutGadget(NodeObject* parent, bool vertical) : LayoutGadget(parent->contents, vertical) {
QObject::connect(parent, &NodeObject::finalized, this, [this, parent] {
updateGeometry();
parent->setGadgetSize();
});
}
void LayoutGadget::addSpacer() { new LayoutSpacerGadget(this); }
void LayoutGadget::updateGeometry() {
qreal cur = margin;
qreal h = 0;
auto ms = orient(minSize);
qreal h = ms.height();
for (auto c : childItems()) {
auto g = static_cast<Gadget*>(c);
g->updateGeometry();
auto r = orient(g->layoutBoundingRect());
h = std::max(h, r.height());
}
for (auto c : childItems()) {
auto g = static_cast<Gadget*>(c);
auto r = orient(g->layoutBoundingRect());
g->centerOn(orient(QPointF(cur + r.width()/2, h/2)));
g->centerOn(orient(QPointF(cur + r.width()/2, r.height()/2 + (h - r.height())*bias)));
cur += r.width() + spacing;
}
cur += margin - spacing;
size = orient(QSizeF(cur, h));
size = orient(QSizeF(std::max(cur, ms.width()), h));
}
QRectF LayoutGadget::boundingRect() const { return { QPointF(), size }; }

View File

@ -3,22 +3,30 @@
#include "ui/gadgets/gadget.h"
namespace Xybrid::UI {
class NodeObject;
class LayoutGadget : public Gadget {
QSizeF size;
qreal spacing = 6;
qreal margin = 6;
bool vertical = false;
QPointF orient(const QPointF&) const;
QSizeF orient(const QSizeF&) const;
QRectF orient(const QRectF&) const;
public:
LayoutGadget(QGraphicsItem* parent = nullptr);
QSizeF minSize = {0, 0};
qreal spacing = 6;
qreal margin = 6;
qreal bias = 0.5;
bool vertical = false;
LayoutGadget(QGraphicsItem* parent = nullptr, bool vertical = false);
LayoutGadget(NodeObject* parent, bool vertical = false);
~LayoutGadget() override = default;
void updateLayout();
void addSpacer();
void updateGeometry() override;
QRectF boundingRect() const override;
};

View File

@ -195,6 +195,8 @@ NodeObject::NodeObject(const std::shared_ptr<Data::Node>& n) {
createPorts();
node->onGadgetCreated();
emit finalized();
}
void NodeObject::setGadgetSize(QPointF p) {

View File

@ -78,6 +78,8 @@ namespace Xybrid::UI {
class NodeObject : public QGraphicsObject {
friend class PortObject;
Q_OBJECT
std::shared_ptr<Data::Node> node;
QPointF gadgetSize_{0, 0};
@ -114,6 +116,7 @@ namespace Xybrid::UI {
void setGadgetSize(QPointF);
inline void setGadgetSize(QSizeF s) { setGadgetSize(QPointF(s.width(), s.height())); }
inline void setGadgetSize(qreal w, qreal h) { setGadgetSize(QPointF(w, h)); }
inline void setGadgetSize() { setGadgetSize(contents->childrenBoundingRect().bottomRight()); }
void updatePorts() { createPorts(); }
@ -127,5 +130,8 @@ namespace Xybrid::UI {
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
QRectF boundingRect() const override;
signals:
void finalized();
};
}