FlowVis 1.0
|
00001 #include "LayerWidget.h" 00002 00003 00004 LayerWidget::LayerWidget(QWidget *parent) 00005 : QWidget(parent) 00006 { 00007 00008 box = new QGroupBox("Layer"); 00009 00010 comboBoxType = new QComboBox(); 00011 comboBoxType->addItem("Arrows"); 00012 comboBoxType->addItem("Texture"); 00013 comboBoxType->addItem("Streamlines"); 00014 comboBoxType->setCurrentIndex(-1); 00015 00016 labelType = new QLabel("Type:"); 00017 00018 comboBoxChannel = new QComboBox(); 00019 comboBoxChannel->addItem("Velocity"); 00020 comboBoxChannel->setCurrentIndex(-1); 00021 00022 labelChannel = new QLabel("Channel:"); 00023 00024 transfer = new TransferSettingsWidget(); 00025 00026 QHBoxLayout* buttons = new QHBoxLayout(); 00027 00028 up = new QPushButton(" up "); 00029 up->setFixedWidth(50); 00030 down = new QPushButton("down"); 00031 down->setFixedWidth(50); 00032 remove = new QPushButton("remove"); 00033 remove->setFixedWidth(50); 00034 00035 buttons->setMargin(0); 00036 buttons->addWidget(down,0,Qt::AlignLeft); 00037 buttons->addWidget(up,0,Qt::AlignCenter); 00038 buttons->addWidget(remove,0,Qt::AlignLeft); 00039 00040 grid = new QGridLayout(); 00041 grid->addWidget(labelType,0,0); 00042 grid->addWidget(comboBoxType,0,1); 00043 grid->addWidget(labelChannel,1,0); 00044 grid->addWidget(comboBoxChannel,1,1); 00045 00046 grid->addWidget(transfer,2,0,1,2,Qt::AlignCenter); 00047 grid->addLayout(buttons,3,0,1,2,Qt::AlignRight); 00048 box->setLayout(grid); 00049 00050 00051 00052 layout = new QHBoxLayout(); 00053 layout->addWidget(box); 00054 layout->setMargin(0); 00055 00056 this->setLayout(layout); 00057 this->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); 00058 00059 connectSignals(); 00060 } 00061 00062 void LayerWidget::connectSignals() 00063 { 00064 QObject::connect(up,SIGNAL(clicked()),this,SLOT(upButtonClicked())); 00065 QObject::connect(down,SIGNAL(clicked()),this,SLOT(downButtonClicked())); 00066 QObject::connect(remove,SIGNAL(clicked()),this,SLOT(removeButtonClicked())); 00067 QObject::connect(comboBoxType,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(typeComboBoxChanged(const QString &))); 00068 QObject::connect(comboBoxChannel,SIGNAL(currentIndexChanged(int)),this,SLOT(channelComboBoxChanged(int))); 00069 QObject::connect(transfer,SIGNAL(TransferImageUpdated(const QImage)),this,SLOT(transferImageUpdated(const QImage))); 00070 } 00071 00072 void LayerWidget::typeComboBoxChanged(const QString & text) 00073 { 00074 box->setTitle(text); 00075 00076 if(text == "Arrows") 00077 emit typeChanged(TYPE_ARROWS,this); 00078 00079 if(text == "Texture") 00080 emit typeChanged(TYPE_TEXTURE,this); 00081 00082 if(text == "Streamlines") 00083 emit typeChanged(TYPE_STREAMLINES,this); 00084 } 00085 LayerWidget::~LayerWidget() 00086 { 00087 delete layout; 00088 } 00089 00090 void LayerWidget::channelCountChanged(int channels) 00091 { 00092 int indx = comboBoxChannel->currentIndex(); 00093 00094 comboBoxChannel->clear(); 00095 00096 if(channels > 0) 00097 comboBoxChannel->addItem("Velocity"); 00098 00099 for(int i=1; i<channels; i++) 00100 { 00101 QString s("Channel "); 00102 s += QString::number(i-1); 00103 comboBoxChannel->addItem(s); 00104 } 00105 00106 indx = indx<channels?indx:-1; 00107 comboBoxChannel->setCurrentIndex(indx); 00108 emit channelComboBoxChanged(indx); 00109 } 00110 00111 QDataStream &operator<<(QDataStream &out, const LayerWidget *layer) 00112 { 00113 out << layer->transfer << layer->comboBoxType->currentIndex() << layer->comboBoxChannel->currentIndex(); 00114 return out; 00115 } 00116 QDataStream &operator>>(QDataStream &in, LayerWidget *layer) 00117 { 00118 int i,j; 00119 in >> layer->transfer >> i >> j; 00120 layer->comboBoxType->setCurrentIndex(i); 00121 00122 //if(j < layer->comboBoxChannel->count()) 00123 layer->comboBoxChannel->setCurrentIndex(j); 00124 00125 return in; 00126 }