Skip to content

Commit

Permalink
Linked model groups (#4964)
Browse files Browse the repository at this point in the history
Add labeled controls for different types with a common base class

Implement a container for multiple equal groups of linked models and
suiting views. Such groups are suited for representing mono effects where each
Model occurs twice. A group provides Models for one mono processor and is
visually represented with a group box.

This concept is common for LADSPA and Lv2, and useful for any mono effect.
  • Loading branch information
JohannesLorenz authored Feb 21, 2020
1 parent 3410db4 commit eebdc0f
Show file tree
Hide file tree
Showing 11 changed files with 1,351 additions and 0 deletions.
133 changes: 133 additions & 0 deletions include/ControlLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* ControlLayout.h - layout for controls
*
* Copyright (c) 2019-2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
*
* This file is part of LMMS - https://lmms.io
*
* 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 (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef CONTROLLAYOUT_H
#define CONTROLLAYOUT_H

#include <QLayout>
#include <QMultiMap>
#include <QStyle>
class QLayoutItem;
class QRect;
class QString;

/**
Layout for controls (models)
Originally token from Qt's FlowLayout example. Modified.
Features a search bar, as well as looking up widgets with string keys
Keys have to be provided in the widgets' objectNames
*/
class ControlLayout : public QLayout
{
Q_OBJECT

public:
explicit ControlLayout(QWidget *parent,
int margin = -1, int hSpacing = -1, int vSpacing = -1);
~ControlLayout() override;

void addItem(QLayoutItem *item) override;
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const override;
bool hasHeightForWidth() const override;
int heightForWidth(int) const override;
int count() const override;
QLayoutItem *itemAt(int index) const override;
QLayoutItem *itemByString(const QString& key) const;
QSize minimumSize() const override;
void setGeometry(const QRect &rect) override;
QSize sizeHint() const override;
QLayoutItem *takeAt(int index) override;

private slots:
void onTextChanged(const QString&);

private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QMap<QString, QLayoutItem *>::const_iterator pairAt(int index) const;

QMultiMap<QString, QLayoutItem *> m_itemMap;
int m_hSpace;
int m_vSpace;
// relevant dimension is width, as later, heightForWidth() will be called
// 400 looks good and is ~4 knobs in a row
constexpr const static int m_minWidth = 400;
class QLineEdit* m_searchBar;
//! name of search bar, must be ASCII sorted before any alpha numerics
static constexpr const char* s_searchBarName = "!!searchBar!!";
};

#endif // CONTROLLAYOUT_H
134 changes: 134 additions & 0 deletions include/Controls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Controls.h - labeled control widgets
*
* Copyright (c) 2019-2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
*
* This file is part of LMMS - https://lmms.io
*
* 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 (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef CONTROLS_H
#define CONTROLS_H


#include "Model.h"

// headers only required for covariance
#include "AutomatableModel.h"
#include "ComboBoxModel.h"


class QString;
class QWidget;
class AutomatableModel;


/**
These classes provide
- a control with a text label
- a type safe way to set a model
(justification: setting the wrong typed model to a widget will cause
hard-to-find runtime errors)
*/
class Control
{
public:
virtual QWidget* topWidget() = 0;
virtual void setText(const QString& text) = 0;

virtual void setModel(AutomatableModel* model) = 0;
virtual AutomatableModel* model() = 0;
virtual class AutomatableModelView* modelView() = 0;

virtual ~Control();
};


class KnobControl : public Control
{
class Knob* m_knob;

public:
void setText(const QString& text) override;
QWidget* topWidget() override;

void setModel(AutomatableModel* model) override;
FloatModel* model() override;
class AutomatableModelView* modelView() override;

KnobControl(QWidget* parent = nullptr);
~KnobControl() override;
};


class ComboControl : public Control
{
QWidget* m_widget;
class ComboBox* m_combo;
class QLabel* m_label;

public:
void setText(const QString& text) override;
QWidget* topWidget() override { return m_widget; }

void setModel(AutomatableModel* model) override;
ComboBoxModel* model() override;
class AutomatableModelView* modelView() override;

ComboControl(QWidget* parent = nullptr);
~ComboControl() override;
};


class LcdControl : public Control
{
class LcdSpinBox* m_lcd;

public:
void setText(const QString& text) override;
QWidget* topWidget() override;

void setModel(AutomatableModel* model) override;
IntModel* model() override;
class AutomatableModelView* modelView() override;

LcdControl(int numDigits, QWidget* parent = nullptr);
~LcdControl() override;
};


class CheckControl : public Control
{
QWidget* m_widget;
class LedCheckBox* m_checkBox;
QLabel* m_label;

public:
void setText(const QString& text) override;
QWidget* topWidget() override;

void setModel(AutomatableModel* model) override;
BoolModel *model() override;
class AutomatableModelView* modelView() override;

CheckControl(QWidget* parent = nullptr);
~CheckControl() override;
};


#endif // CONTROLS_H
105 changes: 105 additions & 0 deletions include/LinkedModelGroupViews.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* LinkedModelGroupViews.h - view for groups of linkable models
*
* Copyright (c) 2019-2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
*
* This file is part of LMMS - https://lmms.io
*
* 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 (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LINKEDMODELGROUPVIEWS_H
#define LINKEDMODELGROUPVIEWS_H


#include <cstddef>
#include <memory>
#include <vector>
#include <QWidget>


/**
@file LinkedModelGroupViews.h
See Lv2ViewBase.h for example usage
*/


/**
View for a representative processor
Features:
* Remove button for removable models
* Simple handling of adding, removing and model changing
@note Neither this class, nor any inheriting classes, shall inherit
ModelView. The "view" in the name is just for consistency
with LinkedModelGroupsView.
*/
class LinkedModelGroupView : public QWidget
{
public:
/**
@param colNum numbers of columns for the controls
(link LEDs not counted)
*/
LinkedModelGroupView(QWidget *parent, class LinkedModelGroup* model,
std::size_t colNum);
~LinkedModelGroupView();

//! Reconnect models if model changed
void modelChanged(class LinkedModelGroup *linkedModelGroup);

protected:
//! Add a control to this widget
//! @warning This widget will own this control, do not free it
void addControl(class Control *ctrl, const std::string &id,
const std::string& display, bool removable);

void removeControl(const QString &key);

private:
class LinkedModelGroup* m_model;

//! column number in surrounding grid in LinkedModelGroupsView
std::size_t m_colNum;
class ControlLayout* m_layout;
std::map<std::string, std::unique_ptr<class Control>> m_widgets;
};


/**
Container class for one LinkedModelGroupView
@note It's intended this class does not inherit from ModelView.
Inheriting classes need to do that, see e.g. Lv2Instrument.h
*/
class LinkedModelGroupsView
{
protected:
~LinkedModelGroupsView() = default;

//! Reconnect models if model changed; to be called by child virtuals
void modelChanged(class LinkedModelGroups* ctrlBase);

private:
//! The base class must return the adressed group view,
//! which has the same value as "this"
virtual LinkedModelGroupView* getGroupView() = 0;
};


#endif // LINKEDMODELGROUPVIEWS_H
Loading

0 comments on commit eebdc0f

Please sign in to comment.