#include #include "demowidgets.h" #include "./ui_demowidgets.h" using namespace std; DemoWidgets::DemoWidgets(QWidget *parent) : QMainWindow(parent) , ui(new Ui::DemoWidgets) { ui->setupUi(this); initialize_foods_menu(); initialize_table(); } enum { AMERICAN_FOOD, CHINESE_FOOD, INDIAN_FOOD }; const QString FOODS[] = { "American", "Chinese", "Indian" }; enum { COLOR_ROW, DEPT_ROW, FOOD_ROW }; enum { LABEL_COL, DATA_COL }; DemoWidgets::~DemoWidgets() { delete ui; } void DemoWidgets::initialize_foods_menu() { ui->foods_menu->addItem(FOODS[AMERICAN_FOOD], AMERICAN_FOOD); ui->foods_menu->addItem(FOODS[CHINESE_FOOD], CHINESE_FOOD); ui->foods_menu->addItem(FOODS[INDIAN_FOOD], INDIAN_FOOD); } void DemoWidgets::initialize_table() { ui->selections_table->setItem(COLOR_ROW, LABEL_COL, new QTableWidgetItem(QString("Color"))); ui->selections_table->setItem(DEPT_ROW, LABEL_COL, new QTableWidgetItem(QString("Department"))); ui->selections_table->setItem(FOOD_ROW, LABEL_COL, new QTableWidgetItem(QString("Food"))); QStringList headers; headers << "Items" << "Values"; ui->selections_table->setHorizontalHeaderLabels(headers); } void DemoWidgets::on_name_submit_clicked() { QString name = ui->name_input->toPlainText(); ui->name_output->setText("Hi, " + name + "!"); ui->name_output->setStyleSheet("color: red"); QFont font = ui->name_output->font(); font.setPointSize(28); ui->name_output->setFont(font); } void DemoWidgets::on_red_cb_stateChanged(int arg1) { show_color_selections(); } void DemoWidgets::on_green_cb_stateChanged(int arg1) { show_color_selections(); } void DemoWidgets::on_blue_cb_stateChanged(int arg1) { show_color_selections(); } void DemoWidgets::show_color_selections() { char buffer[16]; string colors = ""; if (ui->red_cb->isChecked()) colors += "red "; if (ui->green_cb->isChecked()) colors += "green "; if (ui->blue_cb->isChecked()) colors += "blue"; strcpy(buffer, colors.c_str()); ui->selections_table->setItem(COLOR_ROW, DATA_COL, new QTableWidgetItem(QString(buffer))); } void DemoWidgets::on_foods_menu_currentIndexChanged(int index) { show_food_selection(index); } void DemoWidgets::show_food_selection(int index) { ui->selections_table->setItem(FOOD_ROW, DATA_COL, new QTableWidgetItem(FOODS[index])); } void DemoWidgets::on_cs_radio_clicked() { ui->selections_table->setItem(DEPT_ROW, DATA_COL, new QTableWidgetItem(QString( "Computer Science"))); } void DemoWidgets::on_ads_radio_clicked() { ui->selections_table->setItem(DEPT_ROW, DATA_COL, new QTableWidgetItem(QString( "Applied Data Science"))); } void DemoWidgets::on_ees_radio_clicked() { ui->selections_table->setItem(DEPT_ROW, DATA_COL, new QTableWidgetItem(QString( "Engineering Extended Studies"))); }