/// continue the creation of the widgets once the pieces XML was loaded.
/// this is where all the work of creating the family tabs and their content is performed.
void PicsSelectWidget::continueCreate()
{
	const PicBucket& bucket = PicBucket::instance();

	m_tabs = new QTabWidget(this);
	connect(m_tabs, SIGNAL(currentChanged(int)), this, SLOT(updateSetsSpinBox(int)));
	m_layout->addWidget(m_tabs);
	m_groups.resize(bucket.grps.size());

	for (int f = 0; f < bucket.families.size(); ++f)
	{
		const PicFamily &fam = bucket.families[f];

		SizedWidget *tab = new SizedWidget(QSize(6 * BOT_TOTAL_X + BOT_OFFS_X + FRAME_OFFS_SPACE_RIGHT - 5, NUM_DEFS * BOT_TOTAL_Y + FRAME_OFFS_Y), nullptr);
		//QWidget *tab = new QWidget();
		//tab->resize(QSize(6 * BOT_TOTAL_X + BOT_OFFS_X + FRAME_OFFS_SPACE_RIGHT, NUM_DEFS * BOT_TOTAL_Y + FRAME_OFFS_Y));

		QScrollArea *scroll = new QScrollArea();
		scroll->setWidget(tab);
		// the following is the voodoo needed to make the scroll area the same color as the tab
		// if this wasn't here, the scroll area would have gotten the default window color
		// this is significant in Windows XP with new apperance style where the tab color is 
		// different from the default window color
		scroll->viewport()->setAutoFillBackground(false);
		tab->setAutoFillBackground(false);
		// scroll area has a frame by default. get rid of it.
		scroll->setFrameShape(QFrame::NoFrame);

		m_tabs->addTab(scroll, fam.name.c_str());


		for (int g = fam.startIndex; g < fam.startIndex + fam.numGroups; ++g)
		{
			const PicGroupDef *grp = &(bucket.grps[g]);
			GroupCtrl &grpctrl = m_groups[g];
			int normg = (g - fam.startIndex); // normalized g with start of family

			QGroupBox *groupbox = new QGroupBox(grp->name.c_str(), tab);
			groupbox->move(BOT_OFFS_X-FRAME_OFFS_SPACE_LEFT, FRAME_OFFS_Y + normg*BOT_TOTAL_Y - 30);
			groupbox->resize(FRAME_OFFS_SPACE_RIGHT + grp->numPics() * BOT_TOTAL_X, BOT_Y + 55);

			grpctrl.num = new DataSpinBox(g, tab);
			grpctrl.num->move(grp->numPics() * BOT_TOTAL_X + BOT_OFFS_X + FRAME_OFFS_SPACE_RIGHT - 65, BOT_OFFS_Y + normg*BOT_TOTAL_Y + 40);
			grpctrl.num->resize(45, 23);
			grpctrl.num->setButtonSymbols(QAbstractSpinBox::PlusMinus);
			grpctrl.num->setRange(-1, MAX_IDENTICAL_PIECES); 
			grpctrl.num->setSpecialValueText("X");

			connect(grpctrl.num, SIGNAL(dvalueChanged(int, int)), this, SLOT(changedGrpBox(int, int)));


			for (int p = 0; p < bucket.grps[g].numPics(); ++p)
			{
				const PicDef* pic = &(grp->getPic(p));
				PicCtrl picctrl;
				int data = (g << 16) | p;

				DataPushButton *button = new DataPushButton(data, QIcon(pic->pixmap), QString(), tab);
				picctrl.bot = button;
				button->setCheckable(true);
				button->move(BOT_OFFS_X + p*BOT_TOTAL_X, BOT_OFFS_Y + normg * BOT_TOTAL_Y); // g normalized to start of family
				button->resize(BOT_X, BOT_Y);
				button->setIconSize(pic->pixmap.size()); // +1 because it's the texture + line, from Pieces.h
				connect(button, SIGNAL(pclicked(int, bool)), this, SLOT(pressedPicButton(int, bool)));

				DataSpinBox *spinbox = new DataSpinBox(data, tab);
				picctrl.num = spinbox;
				spinbox->setRange(0, MAX_IDENTICAL_PIECES);
				spinbox->move(BOT_OFFS_X + p*BOT_TOTAL_X + (BOT_X/5*2 + 2), BOT_OFFS_Y + normg*BOT_TOTAL_Y + BOT_Y + 5);
				spinbox->resize(BOT_X/5*3 - 4, EDIT_THICK + 1);
				spinbox->setButtonSymbols(QAbstractSpinBox::PlusMinus);
				
				connect(spinbox, SIGNAL(dvalueChanged(int, int)), this, SLOT(changedNumBox(int, int)));

				QLabel *solnum = new QLabel("0", tab);
				picctrl.snum = solnum;
				solnum->move(BOT_OFFS_X + p*BOT_TOTAL_X + 2, BOT_OFFS_Y + normg*BOT_TOTAL_Y + BOT_Y + 6);
				solnum->resize(BOT_X/5*2 - 4, EDIT_THICK); 
				solnum->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
				solnum->setFrameShadow(QFrame::Sunken);
				solnum->setFrameShape(QFrame::Panel);
				
				solnum->setPalette(*m_slvPalette);
				solnum->setVisible(false);


				grpctrl.pics.push_back(picctrl);
			}

		}

	}

	setBuildTilesCount(m_doc->getBuild().tilesCount());
	// prevent the build Help sidebar to get notifications. it might not be there yet.
	// eventually the sidebar will take care of itself.
	blockSignals(true); 
	changeToResetValues();
	blockSignals(false);

	m_bFinishedCreate = true;
}