2013-05-08 01:36:34 +00:00
|
|
|
#include "toggleblock.hpp"
|
|
|
|
#include "groupblock.hpp"
|
|
|
|
#include "groupbox.hpp"
|
|
|
|
#include "itemblock.hpp"
|
|
|
|
|
2013-05-11 10:55:46 +00:00
|
|
|
CSVSettings::ToggleBlock::ToggleBlock(QWidget *parent) :
|
2013-05-08 01:36:34 +00:00
|
|
|
CustomBlock(parent)
|
|
|
|
{}
|
|
|
|
|
2013-06-15 11:40:18 +00:00
|
|
|
int CSVSettings::ToggleBlock::build(CustomBlockDef *def)
|
2013-05-08 01:36:34 +00:00
|
|
|
{
|
2013-06-15 11:40:18 +00:00
|
|
|
if (def->blockDefList.size()==0)
|
2013-05-08 01:36:34 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-06-15 11:40:18 +00:00
|
|
|
QList<GroupBlockDef *>::Iterator it = def->blockDefList.begin();
|
2013-05-08 01:36:34 +00:00
|
|
|
|
|
|
|
//first def in the list is the def for the toggle block
|
|
|
|
GroupBlockDef *toggleDef = *it++;
|
|
|
|
|
2013-06-15 11:40:18 +00:00
|
|
|
if (toggleDef->captions.size() != def->blockDefList.size()-1 )
|
2013-05-08 01:36:34 +00:00
|
|
|
return -2;
|
|
|
|
|
|
|
|
if (toggleDef->widgets.size() == 0)
|
|
|
|
return -3;
|
|
|
|
|
|
|
|
//create the toogle block UI structure
|
2013-06-15 11:40:18 +00:00
|
|
|
QLayout *blockLayout = createLayout (def->blockOrientation, true);
|
2013-05-08 01:36:34 +00:00
|
|
|
GroupBox *propertyBox = buildGroupBox (toggleDef->widgetOrientation);
|
|
|
|
|
|
|
|
mBox->setLayout(blockLayout);
|
|
|
|
mBox->setTitle (toggleDef->title);
|
|
|
|
|
|
|
|
//build the blocks contained in the def list
|
|
|
|
//this manages proxy block construction.
|
|
|
|
//Any settings managed by the proxy setting
|
|
|
|
//must be included in the blocks defined in the list.
|
2013-06-15 11:40:18 +00:00
|
|
|
CustomBlock::build (def->blockDefList, &it);
|
2013-05-08 01:36:34 +00:00
|
|
|
|
|
|
|
for (GroupBlockList::iterator it = mGroupList.begin(); it != mGroupList.end(); ++it)
|
|
|
|
propertyBox->layout()->addWidget ((*it)->getGroupBox());
|
|
|
|
|
|
|
|
//build togle widgets, linking them to the settings
|
2013-06-15 11:40:18 +00:00
|
|
|
GroupBox *toggleBox = buildToggleWidgets (toggleDef, def->defaultValue);
|
2013-05-08 01:36:34 +00:00
|
|
|
|
|
|
|
blockLayout->addWidget(toggleBox);
|
|
|
|
blockLayout->addWidget(propertyBox);
|
|
|
|
blockLayout->setAlignment (propertyBox, Qt::AlignRight);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-15 11:40:18 +00:00
|
|
|
CSVSettings::GroupBox *CSVSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef *def, QString &defaultToggle)
|
2013-05-08 01:36:34 +00:00
|
|
|
{
|
|
|
|
GroupBox *box = new GroupBox (false, getParent());
|
|
|
|
|
2013-06-15 11:40:18 +00:00
|
|
|
QLayout *layout = createLayout (def->widgetOrientation, true, static_cast<QWidget *>(box));
|
2013-05-08 01:36:34 +00:00
|
|
|
|
2013-06-15 11:40:18 +00:00
|
|
|
for (int i = 0; i < def->widgets.size(); ++i)
|
2013-05-08 01:36:34 +00:00
|
|
|
{
|
2013-06-15 11:40:18 +00:00
|
|
|
QString caption = def->captions.at(i);
|
|
|
|
WidgetDef *wDef = def->widgets.at(i);
|
2013-05-08 01:36:34 +00:00
|
|
|
|
|
|
|
wDef->caption = caption;
|
2013-05-12 19:28:36 +00:00
|
|
|
wDef->widgetAlignment = Align_Left;
|
2013-05-08 01:36:34 +00:00
|
|
|
|
|
|
|
AbstractWidget *widg = buildWidget (caption, *wDef, layout, false);
|
|
|
|
|
|
|
|
GroupBlock *block = mGroupList.at(i);
|
|
|
|
|
|
|
|
//connect widget's update to the property block's enabled status
|
|
|
|
connect (widg->widget(), SIGNAL (toggled (bool)), block, SLOT (slotSetEnabled(bool)));
|
|
|
|
|
|
|
|
//enable the default toggle option
|
|
|
|
block->getGroupBox()->setEnabled( caption == defaultToggle );
|
|
|
|
|
|
|
|
layout = widg->getLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|