Make BarModelEditor inherit from FloatModelEditorBase

Make `BarModelEditor` inherit from `FloatModelEditorBase` so that it
inherits all shared functionality. Currently the class mostly implements
size related methods and overrides the paint method.
This commit is contained in:
Michael Gregorius
2023-07-08 15:53:58 +02:00
parent c63d86f6d8
commit e3dc60d7c3
3 changed files with 5 additions and 64 deletions

View File

@@ -67,14 +67,7 @@ QWidget * LadspaWidgetFactory::createWidget(LadspaControl * ladspaControl, QWidg
knob->setModel(ladspaControl->knobModel());
knob->setLabel(name);
break;*/
{
FloatModelEditorBase * fme = new FloatModelEditorBase(parent, name);
fme->setModel(ladspaControl->knobModel());
fme->setHintText(QObject::tr("Value:"), "");
return fme;
}
// FloatModelEditorBase
//return new BarModelEditor(name, ladspaControl->knobModel(), parent);
return new BarModelEditor(name, ladspaControl->knobModel(), parent);
case TIME:
knob = new TempoSyncKnob(knobBright_26, parent, name);

View File

@@ -1,20 +1,16 @@
#include <BarModelEditor.h>
#include "CaptionMenu.h"
#include <QPainter>
#include <QInputDialog>
namespace lmms::gui
{
BarModelEditor::BarModelEditor(QString text, FloatModel * floatModel, QWidget * parent) :
QWidget(parent),
FloatModelView( floatModel, this ),
FloatModelEditorBase(parent),
m_text(text)
{
connectToModelSignals();
setModel(floatModel);
}
QSizePolicy BarModelEditor::sizePolicy() const
@@ -71,45 +67,4 @@ void BarModelEditor::paintEvent(QPaintEvent *event)
painter.drawText(textRect, m_text);
}
void BarModelEditor::contextMenuEvent(QContextMenuEvent * me)
{
CaptionMenu contextMenu(model()->displayName(), this);
addDefaultActions(&contextMenu);
contextMenu.addSeparator();
contextMenu.exec(QCursor::pos());
}
void BarModelEditor::mouseDoubleClickEvent(QMouseEvent * me)
{
bool ok;
float new_val = QInputDialog::getDouble(
this, tr("Set value"),
tr("Please enter a new value between "
"%1 and %2:").
arg(model()->minValue()).
arg(model()->maxValue()),
model()->getRoundedValue(),
model()->minValue(),
model()->maxValue(), model()->getDigitCount(), &ok);
if (ok)
{
model()->setValue(new_val);
}
}
void BarModelEditor::connectToModelSignals()
{
auto * m = model();
if(m)
{
// TODO The first connection does a "friendly" update in Knob. Do we also have to do this?
QObject::connect(m, SIGNAL(dataChanged()), this, SLOT(update()));
QObject::connect(m ,SIGNAL(propertiesChanged()), this, SLOT(update()));
}
}
}