3 changed files with 191 additions and 0 deletions
@ -0,0 +1,79 @@ |
|||||||
|
#include "ParamWidget.h" |
||||||
|
|
||||||
|
|
||||||
|
ParamWidget::ParamWidget(QWidget *parent) : QWidget(parent) |
||||||
|
{ |
||||||
|
ui.setupUi(this); |
||||||
|
} |
||||||
|
|
||||||
|
ParamWidget::~ParamWidget() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void ParamWidget::setupInt(QString title,QString description,int value,int min,int max) |
||||||
|
{ |
||||||
|
type = INT; |
||||||
|
ui.titleLabel->setText("<h3>" + title + "</h3>"); |
||||||
|
ui.descriptionLabel->setText(description); |
||||||
|
ui.valueComboBox->hide(); |
||||||
|
ui.valueSlider->show(); |
||||||
|
ui.intSpinBox->show(); |
||||||
|
ui.doubleSpinBox->hide(); |
||||||
|
m_min = min; |
||||||
|
m_max = max; |
||||||
|
} |
||||||
|
|
||||||
|
void ParamWidget::setupDouble(QString title,QString description,double value,double min,double max) |
||||||
|
{ |
||||||
|
type = DOUBLE; |
||||||
|
ui.titleLabel->setText("<h3>" + title + "</h3>"); |
||||||
|
ui.descriptionLabel->setText(description); |
||||||
|
ui.valueComboBox->hide(); |
||||||
|
ui.valueSlider->show(); |
||||||
|
ui.intSpinBox->hide(); |
||||||
|
ui.doubleSpinBox->show(); |
||||||
|
m_min = min; |
||||||
|
m_max = max; |
||||||
|
} |
||||||
|
|
||||||
|
void ParamWidget::setupCombo(QString title,QString description,QList<QPair<int,QString> > list) |
||||||
|
{ |
||||||
|
type = COMBO; |
||||||
|
ui.titleLabel->setText("<h3>" + title + "</h3>"); |
||||||
|
ui.descriptionLabel->setText(description); |
||||||
|
ui.valueComboBox->show(); |
||||||
|
ui.valueSlider->hide(); |
||||||
|
ui.intSpinBox->hide(); |
||||||
|
ui.doubleSpinBox->hide(); |
||||||
|
m_valueList = list; |
||||||
|
ui.valueComboBox->clear(); |
||||||
|
for (int i=0;i<m_valueList.size();i++) |
||||||
|
{ |
||||||
|
ui.valueComboBox->addItem(m_valueList[i].second); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ParamWidget::setValue(double value) |
||||||
|
{ |
||||||
|
if (type == INT) |
||||||
|
{ |
||||||
|
ui.intSpinBox->setValue(value); |
||||||
|
ui.valueSlider->setValue(((value + m_min) / (m_max + m_min)) * 100.0); |
||||||
|
} |
||||||
|
else if (type == DOUBLE) |
||||||
|
{ |
||||||
|
ui.doubleSpinBox->setValue(value); |
||||||
|
ui.valueSlider->setValue(((value + m_min) / (m_max + m_min)) * 100.0); |
||||||
|
} |
||||||
|
else if (type == COMBO) |
||||||
|
{ |
||||||
|
for (int i=0;i<m_valueList.size();i++) |
||||||
|
{ |
||||||
|
if ((int)value == m_valueList[i].first) |
||||||
|
{ |
||||||
|
ui.valueComboBox->setCurrentIndex(i); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
#ifndef PARAMWIDGET_H |
||||||
|
#define PARAMWIDGET_H |
||||||
|
|
||||||
|
#include <QWidget> |
||||||
|
#include "ui_ParamWidget.h" |
||||||
|
|
||||||
|
class ParamWidget : public QWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
explicit ParamWidget(QWidget *parent = 0); |
||||||
|
~ParamWidget(); |
||||||
|
void setupInt(QString title,QString description,int value,int min,int max); |
||||||
|
void setupDouble(QString title,QString description,double value,double min,double max); |
||||||
|
void setupCombo(QString title,QString description,QList<QPair<int,QString> > list); |
||||||
|
void setValue(double value); |
||||||
|
private: |
||||||
|
enum VIEWTYPE |
||||||
|
{ |
||||||
|
INT, |
||||||
|
DOUBLE, |
||||||
|
COMBO |
||||||
|
}; |
||||||
|
double m_min; |
||||||
|
double m_max; |
||||||
|
double m_dvalue; |
||||||
|
int m_ivalue; |
||||||
|
VIEWTYPE type; |
||||||
|
QList<QPair<int,QString> > m_valueList; |
||||||
|
Ui::ParamWidget ui; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // PARAMWIDGET_H
|
@ -0,0 +1,78 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<ui version="4.0"> |
||||||
|
<class>ParamWidget</class> |
||||||
|
<widget class="QWidget" name="ParamWidget"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>0</x> |
||||||
|
<y>0</y> |
||||||
|
<width>619</width> |
||||||
|
<height>207</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="windowTitle"> |
||||||
|
<string>Form</string> |
||||||
|
</property> |
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2"> |
||||||
|
<item> |
||||||
|
<layout class="QVBoxLayout" name="verticalLayout"> |
||||||
|
<item> |
||||||
|
<widget class="QLabel" name="titleLabel"> |
||||||
|
<property name="text"> |
||||||
|
<string>TextLabel</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QLabel" name="descriptionLabel"> |
||||||
|
<property name="text"> |
||||||
|
<string>TextLabel</string> |
||||||
|
</property> |
||||||
|
<property name="wordWrap"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||||
|
<item> |
||||||
|
<widget class="QSpinBox" name="intSpinBox"/> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox"/> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QSlider" name="valueSlider"> |
||||||
|
<property name="maximum"> |
||||||
|
<number>100</number> |
||||||
|
</property> |
||||||
|
<property name="orientation"> |
||||||
|
<enum>Qt::Horizontal</enum> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QComboBox" name="valueComboBox"/> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<spacer name="horizontalSpacer"> |
||||||
|
<property name="orientation"> |
||||||
|
<enum>Qt::Horizontal</enum> |
||||||
|
</property> |
||||||
|
<property name="sizeHint" stdset="0"> |
||||||
|
<size> |
||||||
|
<width>40</width> |
||||||
|
<height>20</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
</spacer> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</widget> |
||||||
|
<resources/> |
||||||
|
<connections/> |
||||||
|
</ui> |
Loading…
Reference in new issue