#include <QtGui/QApplication>
#include "TabWidget.h"
int main(int argc, char *argv[])
{
TabWidget w;
w.show();
return a.exec();
}
#include <QList>
#include <QWidget>
class SubMaster;
{
Q_OBJECT
public:
virtual ~TabWidget();
signals:
void buttonOneClicked(int submaster);
void buttonTwoClicked(int submaster);
void buttonThreeClicked(int submaster);
void sliderValueChanged(int submaster, int value);
void spinboxValueChanged(int submaster, int value);
public slots:
void handleSliderValueChange(int submaster);
void handleSpinboxValueChange(int submaster);
private:
QList<SubMaster *> m_submasters;
};
#endif // TABWIDGET_H
#include <QVBoxLayout>
#include <QSignalMapper>
#include "TabWidget.h"
#include "ParentSignals.h"
{
for(int i = 0; i < 18; ++i)
{
SubMaster * sub_master = new SubMaster();
connect(sub_master, SIGNAL(buttonOneClicked()), buttonOneMapper, SLOT(map()));
buttonOneMapper->setMapping(sub_master, i);
connect(buttonOneMapper, SIGNAL(mapped(int)), this, SIGNAL(buttonOneClicked(int)));
connect(sub_master, SIGNAL(buttonTwoClicked()), buttonTwoMapper, SLOT(map()));
buttonTwoMapper->setMapping(sub_master, i);
connect(buttonTwoMapper, SIGNAL(mapped(int)), this, SIGNAL(buttonTwoClicked(int)));
connect(sub_master, SIGNAL(buttonThreeClicked()), buttonThreeMapper, SLOT(map()));
buttonThreeMapper->setMapping(sub_master, i);
connect(buttonThreeMapper, SIGNAL(mapped(int)), this, SIGNAL(buttonThreeClicked(int)));
connect(sub_master, SIGNAL(sliderValueChanged()), sliderMapper, SLOT(map()));
sliderMapper->setMapping(sub_master, i);
connect(sliderMapper, SIGNAL(mapped(int)), this, SLOT(handleSliderValueChange(int)));
connect(sub_master, SIGNAL(spinboxValueChanged()), spinboxMapper, SLOT(map()));
spinboxMapper->setMapping(sub_master, i);
connect(spinboxMapper, SIGNAL(mapped(int)), this, SLOT(handleSpinboxValueChange(int)));
layout->addWidget(sub_master);
m_submasters.push_back(sub_master);
}
this->setLayout(layout);
}
TabWidget::~TabWidget()
{
}
void TabWidget::handleSliderValueChange(int submaster)
{
int slider_value = m_submasters.at(submaster)->currentSliderValue();
emit sliderValueChanged(submaster, slider_value);
}
void TabWidget::handleSpinboxValueChange(int submaster)
{
int spinbox_value = m_submasters.at(submaster)->currentSpinBoxValue();
emit spinboxValueChanged(submaster, spinbox_value);
}
#ifndef SUBMASTER_H
#define SUBMASTER_H
#include <QtGui>
#include <QtCore>
{
Q_OBJECT
public:
virtual ~SubMaster();
int currentSliderValue() { return slider->value(); }
int currentSpinBoxValue() { return spin_box->value(); }
signals:
void buttonOneClicked();
void buttonTwoClicked();
void buttonThreeClicked();
void sliderValueChanged();
void spinboxValueChanged();
private:
};
#endif // SUBMASTER_H
#include "SubMaster.h"
{
connect(button_one, SIGNAL(clicked()), this, SIGNAL(buttonOneClicked()));
connect(button_two, SIGNAL(clicked()), this, SIGNAL(buttonTwoClicked()));
connect(button_three, SIGNAL(clicked()), this, SIGNAL(buttonThreeClicked()));
connect(slider, SIGNAL(valueChanged(int)), this, SIGNAL(sliderValueChanged()));
connect(spin_box, SIGNAL(valueChanged(int)), this, SIGNAL(spinboxValueChanged()));
connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
layout->addWidget(button_one);
layout->addWidget(button_two);
layout->addWidget(button_three);
layout->addWidget(slider);
layout->addWidget(spin_box);
this->setLayout(layout);
}
SubMaster::~SubMaster()
{
}
#include <QtGui/QApplication>
#include "TabWidget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TabWidget w;
w.show();
return a.exec();
}
#include <QList>
#include <QWidget>
class SubMaster;
class TabWidget : public QWidget
{
Q_OBJECT
public:
TabWidget(QWidget * parent = 0);
virtual ~TabWidget();
signals:
void buttonOneClicked(int submaster);
void buttonTwoClicked(int submaster);
void buttonThreeClicked(int submaster);
void sliderValueChanged(int submaster, int value);
void spinboxValueChanged(int submaster, int value);
public slots:
void handleSliderValueChange(int submaster);
void handleSpinboxValueChange(int submaster);
private:
QList<SubMaster *> m_submasters;
};
#endif // TABWIDGET_H
#include <QVBoxLayout>
#include <QSignalMapper>
#include "TabWidget.h"
#include "ParentSignals.h"
TabWidget::TabWidget(QWidget *parent) : QWidget(parent)
{
QVBoxLayout * layout = new QVBoxLayout();
QSignalMapper * buttonOneMapper = new QSignalMapper(this);
QSignalMapper * buttonTwoMapper = new QSignalMapper(this);
QSignalMapper * buttonThreeMapper = new QSignalMapper(this);
QSignalMapper * sliderMapper = new QSignalMapper(this);
QSignalMapper * spinboxMapper = new QSignalMapper(this);
for(int i = 0; i < 18; ++i)
{
SubMaster * sub_master = new SubMaster();
connect(sub_master, SIGNAL(buttonOneClicked()), buttonOneMapper, SLOT(map()));
buttonOneMapper->setMapping(sub_master, i);
connect(buttonOneMapper, SIGNAL(mapped(int)), this, SIGNAL(buttonOneClicked(int)));
connect(sub_master, SIGNAL(buttonTwoClicked()), buttonTwoMapper, SLOT(map()));
buttonTwoMapper->setMapping(sub_master, i);
connect(buttonTwoMapper, SIGNAL(mapped(int)), this, SIGNAL(buttonTwoClicked(int)));
connect(sub_master, SIGNAL(buttonThreeClicked()), buttonThreeMapper, SLOT(map()));
buttonThreeMapper->setMapping(sub_master, i);
connect(buttonThreeMapper, SIGNAL(mapped(int)), this, SIGNAL(buttonThreeClicked(int)));
connect(sub_master, SIGNAL(sliderValueChanged()), sliderMapper, SLOT(map()));
sliderMapper->setMapping(sub_master, i);
connect(sliderMapper, SIGNAL(mapped(int)), this, SLOT(handleSliderValueChange(int)));
connect(sub_master, SIGNAL(spinboxValueChanged()), spinboxMapper, SLOT(map()));
spinboxMapper->setMapping(sub_master, i);
connect(spinboxMapper, SIGNAL(mapped(int)), this, SLOT(handleSpinboxValueChange(int)));
layout->addWidget(sub_master);
m_submasters.push_back(sub_master);
}
this->setLayout(layout);
}
TabWidget::~TabWidget()
{
}
void TabWidget::handleSliderValueChange(int submaster)
{
int slider_value = m_submasters.at(submaster)->currentSliderValue();
emit sliderValueChanged(submaster, slider_value);
}
void TabWidget::handleSpinboxValueChange(int submaster)
{
int spinbox_value = m_submasters.at(submaster)->currentSpinBoxValue();
emit spinboxValueChanged(submaster, spinbox_value);
}
#ifndef SUBMASTER_H
#define SUBMASTER_H
#include <QtGui>
#include <QtCore>
class SubMaster : public QWidget
{
Q_OBJECT
public:
SubMaster(QWidget * parent = 0);
virtual ~SubMaster();
int currentSliderValue() { return slider->value(); }
int currentSpinBoxValue() { return spin_box->value(); }
signals:
void buttonOneClicked();
void buttonTwoClicked();
void buttonThreeClicked();
void sliderValueChanged();
void spinboxValueChanged();
private:
QPushButton * button_one;
QPushButton * button_two;
QPushButton * button_three;
QSlider * slider;
QSpinBox * spin_box;
};
#endif // SUBMASTER_H
#include "SubMaster.h"
SubMaster::SubMaster(QWidget * parent) : QWidget(parent)
{
button_one = new QPushButton("One");
connect(button_one, SIGNAL(clicked()), this, SIGNAL(buttonOneClicked()));
button_two = new QPushButton("Two");
connect(button_two, SIGNAL(clicked()), this, SIGNAL(buttonTwoClicked()));
button_three = new QPushButton("Three");
connect(button_three, SIGNAL(clicked()), this, SIGNAL(buttonThreeClicked()));
slider = new QSlider();
connect(slider, SIGNAL(valueChanged(int)), this, SIGNAL(sliderValueChanged()));
spin_box = new QSpinBox();
connect(spin_box, SIGNAL(valueChanged(int)), this, SIGNAL(spinboxValueChanged()));
connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
QHBoxLayout * layout = new QHBoxLayout();
layout->addWidget(button_one);
layout->addWidget(button_two);
layout->addWidget(button_three);
layout->addWidget(slider);
layout->addWidget(spin_box);
this->setLayout(layout);
}
SubMaster::~SubMaster()
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks