// ============================================================================= // Cria um widget pelo nome da classe // ============================================================================= QWidget *WidgetFactory::createWidget(QString name, QWidget *parent) { QWidget *widget = NULL; if (name == QString("QPushButton")) { widget = new QPushButton(QObject::tr("Botão"), parent); } else if (name == QString("QLabel")) { widget = new QLabel(QObject::tr("Label"), parent); } else if (name == QString("QLineEdit")) { widget = new QLineEdit(QObject::tr("Caixa de Texto"), parent); } else if (name == QString("QCheckBox")) { widget = new QCheckBox(QObject::tr("Caixa de Checagem"), parent); } else if (name == QString("QRadioButton")) { widget = new QRadioButton(QObject::tr("Botão Radio"), parent); } else if (name == QString("QComboBox")) { widget = new QComboBox(parent); } else if (name == QString("QGroupBox")) { QGroupBox *box = new QGroupBox(QObject::tr("Caixa de Grupo"), parent); // Ajusta o tamanho da caixa :P box->resize(QSize(150, 50)); widget = box; } else { cout << "Falha ao encontrar tipo de widget" << name.toStdString() << endl; widget = new QWidget(parent); } return widget; }
egx_wnd_t egx_groupbox_create_(int res_id,char *name,egx_uint32_t style,int x,int y,int width,int height,egx_wnd_t parent) { QGroupBox *button = new QGroupBox(QString::fromLocal8Bit(name),(QWidget*)(parent)); if(x == 0 || y == 0){ button->resize(width,height); }else{ button->setGeometry(x,y,width,height); } return HWND_TO_GUIWND(button); }
/// 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; }
// ============================================================================= // Cria widgets pelo Id // ============================================================================= QWidget *WidgetFactory::createWidget(int id, QWidget *parent) { QWidget *widget = NULL; QString name; switch (id) { case GEH_CTRL_BUTTON: { widget = new QPushButton(QObject::tr("Botão"), parent); name = QString("botao%1").arg(sm_pushButtonCounter++); break; } case GEH_CTRL_LABEL: { widget = new QLabel(QObject::tr("Label"), parent); name = QString("label%1").arg(sm_labelCounter++); break; } case GEH_CTRL_EDITBOX: { widget = new QLineEdit(QObject::tr(""), parent); name = QString("campo%1").arg(sm_lineEditCounter++); break; } case GEH_CTRL_CHECKBOX: { widget = new QCheckBox(QObject::tr("Caixa de Checagem"), parent); name = QString("checagem%1").arg(sm_checkBoxCounter++); break; } case GEH_CTRL_RADIOBUTTON: { widget = new QRadioButton(QObject::tr("Botão Radio"), parent); name = QString("radio%1").arg(sm_radioButtonCounter++); break; } case GEH_CTRL_GROUPBOX: { QGroupBox *box = new QGroupBox(QObject::tr("Caixa de Grupo"), parent); // Ajusta o tamanho da caixa :P box->resize(QSize(150, 50)); widget = box; name = QString("grupo%1").arg(sm_groupBoxCounter++); break; } case GEH_CTRL_COMBOBOX: { widget = new QComboBox(parent); name = QString("combo%1").arg(sm_comboBoxCounter++); break; } default: { widget = new QWidget(parent); name = QString("widget%1").arg(sm_unknownCounter++); break; } } widget->setObjectName(name); return widget; }