Exemplo n.º 1
0
void ObstacleGenerator::GenEasy(Obstacle *result) {
    int n = Random(4);
    int i, j;
    Obstacle *o = result; // shorthand
    switch (n) {
        case 0:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the row of the bonus
            FillRow(result, i + (Random(2) ? 1 : -1)); // horizontal bar next to i
            break;
        case 1:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the column of the bonus
            FillCol(result, i + (Random(2) ? 1 : -1)); // vertical bar next to i
            break;
        case 2:
            FillRow(result, 0);
            FillRow(result, OBS_GRID_SIZE - 1);
            FillCol(result, 0);
            FillCol(result, OBS_GRID_SIZE - 1);
            break;
        default:
            i = Random(0, OBS_GRID_SIZE - 2); // i is the row of the bonus
            j = Random(0, OBS_GRID_SIZE - 2); // i is the row of the bonus
            o->grid[i][j] = o->grid[i+1][j] = o->grid[i][j+1] = o->grid[i+1][j+1] = true;
            break;
    }
}
void OverviewThreadsWidget::UpdateView()
{
    ProcessStatistics::iterator tIt;
    int tRow = 0;
    int tSelectedRow = -1;

    // save old widget state
    int tOldVertSliderPosition = mTwThreads->verticalScrollBar()->sliderPosition();
    int tOldHorizSliderPosition = mTwThreads->horizontalScrollBar()->sliderPosition();
    bool tWasVertMaximized = (tOldVertSliderPosition == mTwThreads->verticalScrollBar()->maximum());
    if (mTwThreads->selectionModel()->currentIndex().isValid())
        tSelectedRow = mTwThreads->selectionModel()->currentIndex().row();

    // update widget content
    ProcessStatistics tStatList = SVC_PROCESS_STATISTIC.GetProcessStatistics();
    for (tIt = tStatList.begin(); tIt != tStatList.end(); tIt++)
        FillRow(tRow++, *tIt);

    for (int i = mTwThreads->rowCount(); i > tRow; i--)
        mTwThreads->removeRow(i);

    // restore old widget state
    mTwThreads->setRowCount(tRow);
    if (tSelectedRow != -1)
        mTwThreads->selectRow(tSelectedRow);
    if (tWasVertMaximized)
        mTwThreads->verticalScrollBar()->setSliderPosition(mTwThreads->verticalScrollBar()->maximum());
    else
        mTwThreads->verticalScrollBar()->setSliderPosition(tOldVertSliderPosition);
    mTwThreads->horizontalScrollBar()->setSliderPosition(tOldHorizSliderPosition);
}
Exemplo n.º 3
0
void CCMSDCommandCellView::InitBasicList()
{
	LOGFONT logFont = { 0 };
	logFont.lfCharSet = DEFAULT_CHARSET;
	logFont.lfHeight = 90;
	lstrcpy( logFont.lfFaceName, _T( "New Times Roman" ) );
	logFont.lfWeight = FW_BOLD;
	logFont.lfItalic = (BYTE)TRUE;

	m_fntCustomFont1.CreatePointFontIndirect( &logFont );

	logFont.lfHeight = 100;
	lstrcpy( logFont.lfFaceName, _T( "Arial" ) );
	logFont.lfUnderline = (BYTE)TRUE;
	m_fntCustomFont2.CreatePointFontIndirect( &logFont );

	m_wndListCtrl.SetImageList( m_ilItemImages );
	m_wndListCtrl.SetFocusSubItem( TRUE );

	//m_wndListCtrl.AddColumn( _T( "" ), 0, ITEM_IMAGE_CHECKBOX, TRUE, ITEM_FORMAT_CHECKBOX );
	m_wndListCtrl.AddColumn( _T( "" ), 0, ITEM_IMAGE_ADDBOX /*ITEM_IMAGE_CHECKBOX*/, TRUE, ITEM_FORMAT_CHECKBOX );

	m_wndListCtrl.AddColumn( _T( "Tag" ), 100,ITEM_IMAGE_NONE,FALSE,ITEM_FORMAT_EDIT| LVCF_WIDTH,ITEM_FLAGS_LEFT );
	m_wndListCtrl.AddColumn( _T( "Value" ), 100,ITEM_IMAGE_NONE,FALSE,ITEM_FORMAT_EDIT| LVCF_WIDTH,ITEM_FLAGS_CENTRE );

	//m_wndListCtrl.AddColumn( _T( "Progress" ), 170, ITEM_IMAGE_ATTACHMENT, FALSE, ITEM_FORMAT_PROGRESS );
	m_wndListCtrl.ShowHeaderSort( FALSE );
	//for(DataDictionary::iterator it  = Dict().begin(); it!= Dict().end(); it++)
	for(MTConnectDataModel::iterator it  = DataModel().begin(); it!= DataModel().end(); it++)
	{
		int nNewItem = m_wndListCtrl.AddItem("");
		FillRow( nNewItem,it);
	}
	AddLastRow();
#if 0
	for(int i=0; i<  Tablesize(); i++)
	{
		int nNewItem = m_wndListCtrl.AddItem("");
		FillRow( nNewItem);
	}
	AddLastRow();
#endif
}
Exemplo n.º 4
0
AbstractSurface::Status GameSurface::Update(
	const std::chrono::time_point<std::chrono::system_clock>& time)
{
	Status status = AbstractSurface::Status::CONTINUE;
	for (auto& gem : m_gems)
	{
		if (gem.Update(time) == AbstractSurface::Status::ANIMATION)
		{
			status = AbstractSurface::Status::ANIMATION;
		}
	}
	if (status == AbstractSurface::Status::CONTINUE)
	{
		if (m_animation == Animation::FALL_ANIMATION)
		{
			m_animation = Animation::NO_ANIMATION;
		}
		else if (m_animation == Animation::SWAPPING_ANIMATION)
		{
			SDL_assert(m_swapping.first != m_swapping.second);
			m_destroyingGems.swap(FindGroups());
			if (m_destroyingGems.empty())
			{
				Swap(m_swapping.first, m_swapping.second, true);
			}
			else StartDestruction();
		}
		else if (m_animation == Animation::DESTROY_ANIMATION)
		{
			while(!FillRow());
			m_destroyingGems.swap(FindGroups());
			if (!m_destroyingGems.empty())
				StartDestruction();
		}
		else if (m_animation == Animation::ROLLBACK_ANIMATION)
		{
			SDL_assert(m_swapping.first != m_swapping.second);
#ifdef _DEBUG
			auto&& groups = FindGroups();
			SDL_assert(groups.empty());
#endif
			m_animation = Animation::NO_ANIMATION;
			m_selectedGem = k_noGem;
		}
	}
	{
		m_candlewick.Update(time);
		if (m_scoreboard.Update(time) == AbstractSurface::Status::EXIT)
		{
			m_gameOver = true;
		}
	}
	return status;
}
Exemplo n.º 5
0
void ObstacleGenerator::GenHard(Obstacle *result) {
    int n = Random(4);
    int i;
    int j;
    switch (n) {
        case 0:
            i = Random(0, OBS_GRID_SIZE - 3);
            FillRow(result, i);
            FillRow(result, i + 1);
            FillRow(result, i + 2);
            FillRow(result, i + 3);
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
        case 1:
            i = Random(0, OBS_GRID_SIZE - 3);
            FillCol(result, i);
            FillCol(result, i + 1);
            FillCol(result, i + 2);
            FillCol(result, i + 3);
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
        case 2:
            i = Random(0, OBS_GRID_SIZE);
            for (j = 0; j < OBS_GRID_SIZE; j++) {
                if (i != j) {
                    FillCol(result, i);
                }
            }
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
        default:
            i = Random(0, OBS_GRID_SIZE);
            for (j = 0; j < OBS_GRID_SIZE; j++) {
                if (i != j) {
                    FillRow(result, i);
                }
            }
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
    }
}
Exemplo n.º 6
0
void ObstacleGenerator::GenMedium(Obstacle *result) {
    int n = Random(3);
    int i;
    switch (n) {
        case 0:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the row of the bonus
            FillRow(result, i + 1);
            FillRow(result, i - 1);
            break;
        case 1:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the column of the bonus
            FillCol(result, i - 1);
            FillCol(result, i + 1);
            break;
        default:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the column of the bonus
            FillRow(result, i);
            FillCol(result, i);
            break;

    }
}
Exemplo n.º 7
0
std::vector<std::vector<int>>& SetColAndRowTo0IfElemIs0(std::vector<std::vector<int>>& x)
{
	size_t N = x.size();
	if (N == 0) {
		return x;
	}
	size_t M = x[0].size();
	if (M == 0) {
		return x;
	}
	bool firstRowHas0 = RowHas0(x, 0);
	bool firstColHas0 = ColHas0(x, 0);

	for (size_t i = 1; i < N; i++) {
		bool r0 = x[i][0] == 0;
		for (size_t j = 1; j < M; j++) {
			bool c0 = x[0][j] == 0;
			if (x[i][j] == 0) {
				if (!r0) {
					r0 = true;
					FillRow(x, i, 0, j - 1);
				}
				if (!c0) {
					c0 = true;
					FillCol(x, j, 0, i - 1);
				}
			}
			else if (r0 || c0) {
				x[i][j] = 0;
			}
		}
	}
	if (firstRowHas0)
		FillRow(x, 0, 0, M - 1);
	if (firstColHas0)
		FillCol(x, 0, 0, N - 1);
	return x;
}
Exemplo n.º 8
0
void MainWindow::RefreshTable()
{
    ui->Table->setRowCount(variables.count());

    disconnect(ui->Table,SIGNAL(cellChanged(int,int)),this,SLOT(CellActivated(int,int)));

    for (int i = 0 ; i < variables.count(); i++)
    {
        FillRow(i,*variables.values().at(i));
        variables.values().at(i)->tableLine = i;
    }

    connect(ui->Table,SIGNAL(cellChanged(int,int)),this,SLOT(CellActivated(int,int)));
}
Exemplo n.º 9
0
void RegEditPanel::OnFormulaGenerate(bool checked)
{
    Q_UNUSED(checked);
    bool ok;
    int count = QInputDialog::getInt(this, "Instance generator", "Number of instances",
        0, 0, 100, 1, &ok);
    if(!ok)
        return;
    std::string name(m_ref.GetReg().name);
    size_t pos = name.find('n');
    if(pos == std::string::npos)
    {
        name.push_back('n');
        pos = name.size() - 1;
    }
    std::map< std::string, soc_word_t > map;
    std::vector< std::pair< std::string, soc_word_t > > list;
    std::string formula = m_ref.GetReg().formula.string;
    for(int n = 0; n < count; n++)
    {
        map["n"] = n;
        std::string err;
        soc_word_t res;
        if(!soc_desc_evaluate_formula(formula, map, res, err))
        {
            qDebug() << "Cannot evaluator " << QString::fromStdString(formula) 
                << "for n=" << n << ": " << QString::fromStdString(err);
            return;
        }
        std::string regname = name;
        std::string strn = QString("%1").arg(n).toStdString();
        regname.replace(pos, 1, strn);
        list.push_back(std::make_pair(regname, res));
    }
    // everything went good, commit result
    while(m_instances_table->rowCount() > 1)
        m_instances_table->removeRow(0);
    m_ref.GetReg().addr.resize(list.size());
    for(size_t i = 0; i < list.size(); i++)
    {
        m_instances_table->insertRow(i);
        m_ref.GetReg().addr[i].name = list[i].first;
        m_ref.GetReg().addr[i].addr = list[i].second;
        FillRow(i, m_ref.GetReg().addr[i]);
    }
}
Exemplo n.º 10
0
void FieldEditPanel::OnValueActivated(int row, int column)
{
    if(column != 0)
        return;
    int type = m_value_table->item(row, column)->type();
    if(type == FieldValueDeleteType)
    {
        m_ref.GetField().value.erase(m_ref.GetField().value.begin() + row);
        m_value_table->removeRow(row);
        emit OnModified(true);
    }
    else if(type == FieldValueNewType)
    {
        m_value_table->insertRow(row);
        soc_reg_field_value_t val;
        val.name = QString("UNNAMED_%1").arg(row).toStdString();
        val.value = 0;
        m_ref.GetField().value.push_back(val);
        FillRow(row, val);
    }
}
Exemplo n.º 11
0
void RegEditPanel::OnInstActivated(int row, int column)
{
    if(column != 0)
        return;
    int type = m_instances_table->item(row, column)->type();
    if(type == RegInstDeleteType)
    {
        m_ref.GetReg().addr.erase(m_ref.GetReg().addr.begin() + row);
        m_instances_table->removeRow(row);
        emit OnModified(true);
    }
    else if(type == RegInstNewType)
    {
        m_instances_table->insertRow(row);
        soc_reg_addr_t addr;
        addr.name = QString("UNNAMED_%1").arg(row).toStdString();
        addr.addr = 0;
        m_ref.GetReg().addr.push_back(addr);
        FillRow(row, addr);
    }
}
Exemplo n.º 12
0
/**
 * DevEditPanel
 */
DevEditPanel::DevEditPanel(SocDevRef ref, QWidget *parent)
    :QWidget(parent), m_ref(ref)
{
    m_name_group = new QGroupBox("Name", this);
    m_name_edit = new QLineEdit(this);
    m_name_edit->setText(QString::fromStdString(ref.GetDev().name));
    QVBoxLayout *name_group_layout = new QVBoxLayout;
    name_group_layout->addWidget(m_name_edit);
    m_name_group->setLayout(name_group_layout);

    m_long_name_group = new QGroupBox("Long Name", this);
    m_long_name_edit = new QLineEdit(this);
    m_long_name_edit->setText(QString::fromStdString(ref.GetDev().long_name));
    QVBoxLayout *long_name_group_layout = new QVBoxLayout;
    long_name_group_layout->addWidget(m_long_name_edit);
    m_long_name_group->setLayout(long_name_group_layout);

    m_version_group = new QGroupBox("Version", this);
    m_version_edit = new QLineEdit(this);
    m_version_edit->setText(QString::fromStdString(ref.GetDev().version));
    QVBoxLayout *version_group_layout = new QVBoxLayout;
    version_group_layout->addWidget(m_version_edit);
    m_version_group->setLayout(version_group_layout);

    QVBoxLayout *name_ver_layout = new QVBoxLayout;
    name_ver_layout->addWidget(m_name_group);
    name_ver_layout->addWidget(m_long_name_group);
    name_ver_layout->addWidget(m_version_group);
    name_ver_layout->addStretch();

    m_instances_table = new QTableWidget(this);
    m_instances_table->setRowCount(ref.GetDev().addr.size() + 1);
    m_instances_table->setColumnCount(3);
    for(size_t row = 0; row < ref.GetDev().addr.size(); row++)
        FillRow(row, ref.GetDev().addr[row]);
    CreateNewRow(ref.GetDev().addr.size());
    m_instances_table->setHorizontalHeaderItem(0, new QTableWidgetItem(""));
    m_instances_table->setHorizontalHeaderItem(1, new QTableWidgetItem("Name"));
    m_instances_table->setHorizontalHeaderItem(2, new QTableWidgetItem("Address"));
    m_instances_table->verticalHeader()->setVisible(false);
    m_instances_table->resizeColumnsToContents();
    m_instances_table->horizontalHeader()->setStretchLastSection(true);
    m_instances_table->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    m_instances_group = new QGroupBox("Instances", this);
    QHBoxLayout *instances_group_layout = new QHBoxLayout;
    instances_group_layout->addWidget(m_instances_table);
    m_instances_group->setLayout(instances_group_layout);

    QHBoxLayout *top_layout = new QHBoxLayout;
    top_layout->addWidget(m_instances_group);
    top_layout->addLayout(name_ver_layout);
    top_layout->addStretch();

    m_desc_group = new QGroupBox("Description", this);
    QHBoxLayout *group_layout = new QHBoxLayout;
    m_desc_edit = new MyTextEditor(this);
    m_desc_edit->SetTextHtml(QString::fromStdString(ref.GetDev().desc));
    group_layout->addWidget(m_desc_edit);
    m_desc_group->setLayout(group_layout);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addLayout(top_layout, 0);
    layout->addWidget(m_desc_group, 1);

    setLayout(layout);

    SocFieldItemDelegate *m_table_delegate = new SocFieldItemDelegate(this);
    QItemEditorFactory *m_table_edit_factory = new QItemEditorFactory();
    SocFieldEditorCreator *m_table_edit_creator = new SocFieldEditorCreator();
    m_table_edit_factory->registerEditor(QVariant::UInt, m_table_edit_creator);
    m_table_delegate->setItemEditorFactory(m_table_edit_factory);
    m_instances_table->setItemDelegate(m_table_delegate);

    connect(m_instances_table, SIGNAL(cellActivated(int,int)), this, SLOT(OnInstActivated(int,int)));
    connect(m_instances_table, SIGNAL(cellChanged(int,int)), this, SLOT(OnInstChanged(int,int)));
    connect(m_name_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnNameEdited(const QString&)));
    connect(m_long_name_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnLongNameEdited(const QString&)));
    connect(m_version_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnVersionEdited(const QString&)));
    connect(m_desc_edit, SIGNAL(OnTextChanged()), this, SLOT(OnDescEdited()));
}
Exemplo n.º 13
0
/**
 * FieldEditPanel
 */
FieldEditPanel::FieldEditPanel(SocFieldRef ref, QWidget *parent)
    :QWidget(parent), m_ref(ref)
{
    m_name_group = new QGroupBox("Name", this);
    m_name_edit = new QLineEdit(this);
    m_name_edit->setText(QString::fromStdString(ref.GetField().name));
    QVBoxLayout *name_group_layout = new QVBoxLayout;
    name_group_layout->addWidget(m_name_edit);
    m_name_group->setLayout(name_group_layout);

    m_bitrange_group = new QGroupBox("Bit Range", this);
    m_bitrange_edit = new QLineEdit(this);
    const soc_reg_field_t& field = ref.GetField();
    QString bits_str;
    if(field.first_bit == field.last_bit)
        bits_str.sprintf("%d", field.first_bit);
    else
        bits_str.sprintf("%d:%d", field.last_bit, field.first_bit);
    m_bitrange_edit->setText(bits_str);
    m_bitrange_edit->setValidator(new SocBitRangeValidator(m_bitrange_edit));
    QVBoxLayout *bitrange_group_layout = new QVBoxLayout;
    bitrange_group_layout->addWidget(m_bitrange_edit);
    m_bitrange_group->setLayout(bitrange_group_layout);

    m_desc_group = new QGroupBox("Description", this);
    QHBoxLayout *group_layout = new QHBoxLayout;
    m_desc_edit = new MyTextEditor(this);
    m_desc_edit->SetTextHtml(QString::fromStdString(ref.GetField().desc));
    group_layout->addWidget(m_desc_edit);
    m_desc_group->setLayout(group_layout);

    m_value_group = new QGroupBox("Values", this);
    QHBoxLayout *value_layout = new QHBoxLayout;
    m_value_table = new QTableWidget(this);
    m_value_table->setRowCount(ref.GetField().value.size() + 1);
    m_value_table->setColumnCount(FieldValueNrColumns);
    for(size_t row = 0; row < ref.GetField().value.size(); row++)
        FillRow(row, ref.GetField().value[row]);
    CreateNewRow(ref.GetField().value.size());
    m_value_table->setHorizontalHeaderItem(FieldValueIconColumn, new QTableWidgetItem(""));
    m_value_table->setHorizontalHeaderItem(FieldValueNameColumn, new QTableWidgetItem("Name"));
    m_value_table->setHorizontalHeaderItem(FieldValueValueColumn, new QTableWidgetItem("Value"));
    m_value_table->setHorizontalHeaderItem(FieldValueDescColumn, new QTableWidgetItem("Description"));
    m_value_table->verticalHeader()->setVisible(false);
    m_value_table->horizontalHeader()->setStretchLastSection(true);
    value_layout->addWidget(m_value_table);
    m_value_group->setLayout(value_layout);

    QHBoxLayout *line_layout = new QHBoxLayout;
    line_layout->addWidget(m_name_group);
    line_layout->addWidget(m_bitrange_group);
    line_layout->addStretch();

    QVBoxLayout *left_layout = new QVBoxLayout;
    left_layout->addLayout(line_layout);
    left_layout->addWidget(m_desc_group);
    left_layout->addWidget(m_value_group, 1);

    UpdateDelegates();

    connect(m_name_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnNameEdited(const QString&)));
    connect(m_desc_edit, SIGNAL(OnTextChanged()), this, SLOT(OnDescEdited()));
    connect(m_value_table, SIGNAL(cellActivated(int,int)), this, SLOT(OnValueActivated(int,int)));
    connect(m_value_table, SIGNAL(cellChanged(int,int)), this, SLOT(OnValueChanged(int,int)));
    connect(m_bitrange_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnBitRangeEdited(const QString&)));

    setLayout(left_layout);
}
Exemplo n.º 14
0
RegEditPanel::RegEditPanel(SocRegRef ref, QWidget *parent)
    :QWidget(parent), m_ref(ref), m_reg_font(font())
{
    m_reg_font.setWeight(100);
    m_reg_font.setKerning(false);

    m_name_group = new QGroupBox("Name", this);
    m_name_edit = new QLineEdit(this);
    m_name_edit->setText(QString::fromStdString(ref.GetReg().name));
    QVBoxLayout *name_group_layout = new QVBoxLayout;
    name_group_layout->addWidget(m_name_edit);
    m_name_group->setLayout(name_group_layout);

    m_instances_table = new QTableWidget(this);
    m_instances_table->setRowCount(ref.GetReg().addr.size() + 1);
    m_instances_table->setColumnCount(RegInstNrColumns);
    for(size_t row = 0; row < ref.GetReg().addr.size(); row++)
        FillRow(row, ref.GetReg().addr[row]);
    CreateNewAddrRow(ref.GetReg().addr.size());
    m_instances_table->setHorizontalHeaderItem(RegInstIconColumn, new QTableWidgetItem(""));
    m_instances_table->setHorizontalHeaderItem(RegInstNameColumn, new QTableWidgetItem("Name"));
    m_instances_table->setHorizontalHeaderItem(RegInstAddrColumn, new QTableWidgetItem("Address"));
    m_instances_table->verticalHeader()->setVisible(false);
    m_instances_table->resizeColumnsToContents();
    m_instances_table->horizontalHeader()->setStretchLastSection(true);
    m_instances_table->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    m_instances_group = new QGroupBox("Instances", this);
    QHBoxLayout *instances_group_layout = new QHBoxLayout;
    instances_group_layout->addWidget(m_instances_table);
    m_instances_group->setLayout(instances_group_layout);

    m_desc_group = new QGroupBox("Description", this);
    QHBoxLayout *group_layout = new QHBoxLayout;
    m_desc_edit = new MyTextEditor(this);
    m_desc_edit->SetTextHtml(QString::fromStdString(ref.GetReg().desc));
    group_layout->addWidget(m_desc_edit);
    m_desc_group->setLayout(group_layout);

    bool has_sct = m_ref.GetReg().flags & REG_HAS_SCT;
    m_sct_check = new QCheckBox("Set/Clear/Toggle", this);
    m_sct_check->setCheckState(has_sct ? Qt::Checked : Qt::Unchecked);
    QHBoxLayout *flags_layout = new QHBoxLayout;
    flags_layout->addWidget(m_sct_check);
    flags_layout->addStretch();
    m_flags_group = new QGroupBox("Flags", this);
    m_flags_group->setLayout(flags_layout);

    m_formula_combo = new QComboBox(this);
    m_formula_combo->addItem("None", QVariant(REG_FORMULA_NONE));
    m_formula_combo->addItem("String", QVariant(REG_FORMULA_STRING));
    m_formula_combo->setCurrentIndex(m_formula_combo->findData(QVariant(m_ref.GetReg().formula.type)));
    m_formula_type_label = new QLabel("Type:", this);
    QHBoxLayout *formula_top_layout = new QHBoxLayout;
    formula_top_layout->addWidget(m_formula_type_label);
    formula_top_layout->addWidget(m_formula_combo);
    m_formula_string_edit = new QLineEdit(QString::fromStdString(ref.GetReg().formula.string), this);
    QVBoxLayout *formula_layout = new QVBoxLayout;
    formula_layout->addLayout(formula_top_layout);
    formula_layout->addWidget(m_formula_string_edit);
    m_formula_string_gen = new QPushButton("Generate", this);
    formula_layout->addWidget(m_formula_string_gen);
    m_formula_group = new QGroupBox("Formula", this);
    m_formula_group->setLayout(formula_layout);

    QVBoxLayout *name_layout = new QVBoxLayout;
    name_layout->addWidget(m_name_group);
    name_layout->addWidget(m_flags_group);
    name_layout->addWidget(m_formula_group);
    name_layout->addStretch();

    QHBoxLayout *top_layout = new QHBoxLayout;
    top_layout->addWidget(m_instances_group);
    top_layout->addLayout(name_layout);
    top_layout->addWidget(m_desc_group, 1);

    m_sexy_display = new RegSexyDisplay(m_ref, this);
    m_sexy_display->setFont(m_reg_font);

    m_field_table = new QTableWidget;
    m_field_table->setRowCount(m_ref.GetReg().field.size());
    m_field_table->setColumnCount(4);
    for(size_t row = 0; row < m_ref.GetReg().field.size(); row++)
    {
        const soc_reg_field_t& field = m_ref.GetReg().field[row];
        QString bits_str;
        if(field.first_bit == field.last_bit)
            bits_str.sprintf("%d", field.first_bit);
        else
            bits_str.sprintf("%d:%d", field.last_bit, field.first_bit);
        QTableWidgetItem *item = new QTableWidgetItem(bits_str);
        item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        m_field_table->setItem(row, 1, item);
        item = new QTableWidgetItem(QString(field.name.c_str()));
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        m_field_table->setItem(row, 2, item);
        item = new QTableWidgetItem(QString(field.desc.c_str()));
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        m_field_table->setItem(row, 3, item);
        UpdateWarning(row);
    }
    m_field_table->setHorizontalHeaderItem(0, new QTableWidgetItem(""));
    m_field_table->setHorizontalHeaderItem(1, new QTableWidgetItem("Bits"));
    m_field_table->setHorizontalHeaderItem(2, new QTableWidgetItem("Name"));
    m_field_table->setHorizontalHeaderItem(3, new QTableWidgetItem("Description"));
    m_field_table->verticalHeader()->setVisible(false);
    m_field_table->resizeColumnsToContents();
    m_field_table->horizontalHeader()->setStretchLastSection(true);
    QHBoxLayout *field_layout = new QHBoxLayout;
    field_layout->addWidget(m_field_table);
    m_field_group = new QGroupBox("Flags", this);
    m_field_group->setLayout(field_layout);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addLayout(top_layout, 0);
    layout->addWidget(m_sexy_display, 0);
    layout->addWidget(m_field_group);

    UpdateFormula();

    setLayout(layout);

    SocFieldItemDelegate *m_table_delegate = new SocFieldItemDelegate(this);
    QItemEditorFactory *m_table_edit_factory = new QItemEditorFactory();
    SocFieldEditorCreator *m_table_edit_creator = new SocFieldEditorCreator();
    m_table_edit_factory->registerEditor(QVariant::UInt, m_table_edit_creator);
    m_table_delegate->setItemEditorFactory(m_table_edit_factory);
    m_instances_table->setItemDelegate(m_table_delegate);

    connect(m_instances_table, SIGNAL(cellActivated(int,int)), this, SLOT(OnInstActivated(int,int)));
    connect(m_instances_table, SIGNAL(cellChanged(int,int)), this, SLOT(OnInstChanged(int,int)));
    connect(m_name_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnNameEdited(const QString&)));
    connect(m_desc_edit, SIGNAL(OnTextChanged()), this, SLOT(OnDescEdited()));
    connect(m_sct_check, SIGNAL(stateChanged(int)), this, SLOT(OnSctEdited(int)));
    connect(m_formula_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormulaChanged(int)));
    connect(m_formula_string_edit, SIGNAL(textChanged(const QString&)), this, 
        SLOT(OnFormulaStringChanged(const QString&)));
    connect(m_formula_string_gen, SIGNAL(clicked(bool)), this, SLOT(OnFormulaGenerate(bool)));
}
void OverviewDataStreamsWidget::UpdateView()
{
	PacketStatistics::iterator tIt;
    int tRowAudio = 0, tRowVideo = 0;
    int tASelectedRow = -1, tVSelectedRow = -1;

    // save old widget state
    int tAudioOldVertSliderPosition = mTwAudio->verticalScrollBar()->sliderPosition();
    int tAudioOldHorizSliderPosition = mTwAudio->horizontalScrollBar()->sliderPosition();
    bool tAudioWasVertMaximized = (tAudioOldVertSliderPosition == mTwAudio->verticalScrollBar()->maximum());
    if (mTwAudio->selectionModel()->currentIndex().isValid())
        tASelectedRow = mTwAudio->selectionModel()->currentIndex().row();
    int tVideoOldVertSliderPosition = mTwVideo->verticalScrollBar()->sliderPosition();
    int tVideoOldHorizSliderPosition = mTwVideo->horizontalScrollBar()->sliderPosition();
    bool tVideoWasVertMaximized = (tVideoOldVertSliderPosition == mTwVideo->verticalScrollBar()->maximum());
    if (mTwVideo->selectionModel()->currentIndex().isValid())
        tVSelectedRow = mTwVideo->selectionModel()->currentIndex().row();

    // update widget content
    PacketStatistics tStatList = SVC_PACKET_STATISTIC.GetPacketStatisticsAccess();
    if (tStatList.size() > 0)
    {
        tIt = tStatList.begin();

        while (tIt != tStatList.end())
        {
        	switch((*tIt)->GetDataType())
        	{
				case DATA_TYPE_VIDEO:
                    FillRow(mTwVideo, tRowVideo++, *tIt);
					break;
				case DATA_TYPE_AUDIO:
                    FillRow(mTwAudio, tRowAudio++, *tIt);
					break;
        	}
            tIt++;
        }
    }
    SVC_PACKET_STATISTIC.ReleasePacketStatisticsAccess();

    for (int i = mTwAudio->rowCount(); i > tRowAudio; i--)
        mTwAudio->removeRow(i);
    for (int i = mTwVideo->rowCount(); i > tRowVideo; i--)
        mTwVideo->removeRow(i);

    // restore old widget state
    mTwAudio->setRowCount(tRowAudio);
    if (tASelectedRow != -1)
        mTwAudio->selectRow(tASelectedRow);
    if (tAudioWasVertMaximized)
        mTwAudio->verticalScrollBar()->setSliderPosition(mTwAudio->verticalScrollBar()->maximum());
    else
        mTwAudio->verticalScrollBar()->setSliderPosition(tAudioOldVertSliderPosition);
    mTwAudio->horizontalScrollBar()->setSliderPosition(tAudioOldHorizSliderPosition);
    mTwVideo->setRowCount(tRowVideo);
    if (tVSelectedRow != -1)
        mTwVideo->selectRow(tVSelectedRow);
    if (tVideoWasVertMaximized)
        mTwVideo->verticalScrollBar()->setSliderPosition(mTwVideo->verticalScrollBar()->maximum());
    else
        mTwVideo->verticalScrollBar()->setSliderPosition(tVideoOldVertSliderPosition);
    mTwVideo->horizontalScrollBar()->setSliderPosition(tVideoOldHorizSliderPosition);
}
Exemplo n.º 16
0
RegEditPanel::RegEditPanel(SocRegRef ref, QWidget *parent)
    :QWidget(parent), m_ref(ref), m_reg_font(font())
{
    m_reg_font.setWeight(100);
    m_reg_font.setKerning(false);

    m_name_group = new QGroupBox("Name", this);
    m_name_edit = new QLineEdit(this);
    m_name_edit->setText(QString::fromStdString(ref.GetReg().name));
    QVBoxLayout *name_group_layout = new QVBoxLayout;
    name_group_layout->addWidget(m_name_edit);
    m_name_group->setLayout(name_group_layout);

    m_instances_table = new QTableWidget(this);
    m_instances_table->setRowCount(ref.GetReg().addr.size() + 1);
    m_instances_table->setColumnCount(RegInstNrColumns);
    for(size_t row = 0; row < ref.GetReg().addr.size(); row++)
        FillRow(row, ref.GetReg().addr[row]);
    CreateNewAddrRow(ref.GetReg().addr.size());
    m_instances_table->setHorizontalHeaderItem(RegInstIconColumn, new QTableWidgetItem(""));
    m_instances_table->setHorizontalHeaderItem(RegInstNameColumn, new QTableWidgetItem("Name"));
    m_instances_table->setHorizontalHeaderItem(RegInstAddrColumn, new QTableWidgetItem("Address"));
    m_instances_table->verticalHeader()->setVisible(false);
    m_instances_table->resizeColumnsToContents();
    m_instances_table->horizontalHeader()->setStretchLastSection(true);
    m_instances_table->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    m_instances_group = new QGroupBox("Instances", this);
    QHBoxLayout *instances_group_layout = new QHBoxLayout;
    instances_group_layout->addWidget(m_instances_table);
    m_instances_group->setLayout(instances_group_layout);

    m_desc_group = new QGroupBox("Description", this);
    QHBoxLayout *group_layout = new QHBoxLayout;
    m_desc_edit = new MyTextEditor(this);
    m_desc_edit->SetTextHtml(QString::fromStdString(ref.GetReg().desc));
    group_layout->addWidget(m_desc_edit);
    m_desc_group->setLayout(group_layout);

    bool has_sct = m_ref.GetReg().flags & REG_HAS_SCT;
    m_sct_check = new QCheckBox("Set/Clear/Toggle", this);
    m_sct_check->setCheckState(has_sct ? Qt::Checked : Qt::Unchecked);
    QHBoxLayout *flags_layout = new QHBoxLayout;
    flags_layout->addWidget(m_sct_check);
    flags_layout->addStretch();
    m_flags_group = new QGroupBox("Flags", this);
    m_flags_group->setLayout(flags_layout);

    m_formula_combo = new QComboBox(this);
    m_formula_combo->addItem("None", QVariant(REG_FORMULA_NONE));
    m_formula_combo->addItem("String", QVariant(REG_FORMULA_STRING));
    m_formula_combo->setCurrentIndex(m_formula_combo->findData(QVariant(m_ref.GetReg().formula.type)));
    m_formula_type_label = new QLabel("Type:", this);
    QHBoxLayout *formula_top_layout = new QHBoxLayout;
    formula_top_layout->addWidget(m_formula_type_label);
    formula_top_layout->addWidget(m_formula_combo);
    m_formula_string_edit = new QLineEdit(QString::fromStdString(ref.GetReg().formula.string), this);
    QVBoxLayout *formula_layout = new QVBoxLayout;
    formula_layout->addLayout(formula_top_layout);
    formula_layout->addWidget(m_formula_string_edit);
    m_formula_string_gen = new QPushButton("Generate", this);
    formula_layout->addWidget(m_formula_string_gen);
    m_formula_group = new QGroupBox("Formula", this);
    m_formula_group->setLayout(formula_layout);

    QVBoxLayout *name_layout = new QVBoxLayout;
    name_layout->addWidget(m_name_group);
    name_layout->addWidget(m_flags_group);
    name_layout->addWidget(m_formula_group);
    name_layout->addStretch();

    QHBoxLayout *top_layout = new QHBoxLayout;
    top_layout->addWidget(m_instances_group);
    top_layout->addLayout(name_layout);
    top_layout->addWidget(m_desc_group, 1);

    m_value_table = new QTableView(this);
    m_value_model = new RegFieldTableModel(m_value_table); // view takes ownership
    m_value_model->SetRegister(m_ref.GetReg());
    m_value_model->SetReadOnly(true);
    m_value_table->setModel(m_value_model);
    m_value_table->verticalHeader()->setVisible(false);
    m_value_table->horizontalHeader()->setStretchLastSection(true);
    m_value_table->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    // FIXME we cannot use setAlternatingRowColors() because we override the
    // background color, should it be part of the model ?
    m_table_delegate = new SocFieldCachedItemDelegate(this);
    m_value_table->setItemDelegate(m_table_delegate);
    m_value_table->resizeColumnsToContents();

    m_sexy_display2 = new Unscroll<RegSexyDisplay2>(this);
    m_sexy_display2->setFont(m_reg_font);
    m_sexy_display2->setModel(m_value_model);
    m_sexy_display2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QHBoxLayout *field_layout = new QHBoxLayout;
    field_layout->addWidget(m_value_table);
    m_field_group = new QGroupBox("Flags", this);
    m_field_group->setLayout(field_layout);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addLayout(top_layout, 0);
    layout->addWidget(m_sexy_display2, 0);
    layout->addWidget(m_field_group);

    UpdateFormula();

    setLayout(layout);

    SocFieldItemDelegate *m_table_delegate = new SocFieldItemDelegate(this);
    QItemEditorFactory *m_table_edit_factory = new QItemEditorFactory();
    SocFieldEditorCreator *m_table_edit_creator = new SocFieldEditorCreator();
    m_table_edit_factory->registerEditor(QVariant::UInt, m_table_edit_creator);
    m_table_delegate->setItemEditorFactory(m_table_edit_factory);
    m_instances_table->setItemDelegate(m_table_delegate);

    connect(m_instances_table, SIGNAL(cellActivated(int,int)), this, SLOT(OnInstActivated(int,int)));
    connect(m_instances_table, SIGNAL(cellChanged(int,int)), this, SLOT(OnInstChanged(int,int)));
    connect(m_name_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnNameEdited(const QString&)));
    connect(m_desc_edit, SIGNAL(OnTextChanged()), this, SLOT(OnDescEdited()));
    connect(m_sct_check, SIGNAL(stateChanged(int)), this, SLOT(OnSctEdited(int)));
    connect(m_formula_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormulaChanged(int)));
    connect(m_formula_string_edit, SIGNAL(textChanged(const QString&)), this, 
        SLOT(OnFormulaStringChanged(const QString&)));
    connect(m_formula_string_gen, SIGNAL(clicked(bool)), this, SLOT(OnFormulaGenerate(bool)));
}