Example #1
0
bool MdiChild::loadBackup()
{
  QString fileName = QFileDialog::getOpenFileName(this, tr("Open backup Models and Settings file"), g.eepromDir(),tr(EEPROM_FILES_FILTER));
  if (fileName.isEmpty())
    return false;
  QFile file(fileName);

  if (!file.exists()) {
    QMessageBox::critical(this, tr("Error"), tr("Unable to find file %1!").arg(fileName));
    return false;
  }
  if(getCurrentRow() < 1) return false;
  int index = getCurrentRow() - 1;

  int eeprom_size = file.size();
  if (!file.open(QFile::ReadOnly)) {  //reading binary file   - TODO HEX support
    QMessageBox::critical(this, tr("Error"),
                          tr("Error opening file %1:\n%2.")
                          .arg(fileName)
                          .arg(file.errorString()));
    return false;
  }
  QByteArray eeprom(eeprom_size, 0);
  long result = file.read((char*)eeprom.data(), eeprom_size);
  file.close();

  if (result != eeprom_size) {
    QMessageBox::critical(this, tr("Error"),
                          tr("Error reading file %1:\n%2.")
                          .arg(fileName)
                          .arg(file.errorString()));

    return false;
  }

    std::bitset<NUM_ERRORS> errorsEeprom((unsigned long long)LoadBackup(radioData, (uint8_t *)eeprom.data(), eeprom_size, index));
    if (!errorsEeprom.test(NO_ERROR)) {
      ShowEepromErrors(this, tr("Error"), tr("Invalid binary backup File %1").arg(fileName), (errorsEeprom).to_ulong());
      return false;
    }
    if (errorsEeprom.test(HAS_WARNINGS)) {
      ShowEepromWarnings(this, tr("Warning"), errorsEeprom.to_ulong());
    }

  ui->modelsList->refreshList();

  return true;
}
Example #2
0
void Documents::setValue(QString n, QVariant value)
{

    for (int i = 0; i < columnsProperties.count(); i++)
    {
        if (n.toUpper() == columnsProperties.at(i).column)
        {
            Essence::setValue(n, value, getCurrentRow());
            return;
        }
    }
    for (int i = 0; i < attrFields.count(); i++)
    {
        if ((n.toUpper() == attrFields.at(i).column) || (n.toUpper() == prefix + attrFields.at(i).column))
        {
            Essence::setValue(prefix + n, value, getCurrentRow());
            return;
        }
    }
}
Example #3
0
void ItemViewWidget::notifySelectionChanged()
{
	if (m_model)
	{
		m_previousIndex = m_currentIndex;
		m_currentIndex = getIndex(getCurrentRow());

		emit canMoveUpChanged(canMoveUp());
		emit canMoveDownChanged(canMoveDown());
		emit needsActionsUpdate();
	}
}
Example #4
0
void MdiChild::wizardEdit()
{
  int row = getCurrentRow();
  if (row > 0) {
    checkAndInitModel(row);
    WizardDialog * wizard = new WizardDialog(radioData.generalSettings, row, this);
    wizard->exec();
    if (wizard->mix.complete /*TODO rather test the exec() result?*/) {
      radioData.models[row - 1] = wizard->mix;
      setModified();
    }
  }
}
Example #5
0
void MdiChild::print(int model, QString filename)
{
  PrintDialog * pd = NULL;

  if (model>=0 && !filename.isEmpty()) {
    pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, radioData.generalSettings, radioData.models[model], filename);
  }
  else if (getCurrentRow() > 0) {
    pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, radioData.generalSettings, radioData.models[getCurrentRow()-1]);
  }
    
  if (pd) {
    pd->setAttribute(Qt::WA_DeleteOnClose, true);
    pd->show();
  }
}
Example #6
0
void MdiChild::openEditWindow()
{
  int row = getCurrentRow();
  if (row == 0){
    generalEdit();
  }
  else{
    ModelData &model = radioData.models[row - 1];
    if (model.isEmpty() && g.useWizard()) {
      wizardEdit();
    }
    else {
      modelEdit();
    }
  }
}
Example #7
0
void MdiChild::modelEdit()
{
  int row = getCurrentRow();

  if (row == 0){
    generalEdit();
  } 
  else {
    QApplication::setOverrideCursor(Qt::WaitCursor);
    checkAndInitModel( row );
    ModelData &model = radioData.models[row - 1];
    ModelEdit *t = new ModelEdit(this, radioData, (row - 1), GetCurrentFirmware()/*firmware*/);
    t->setWindowTitle(tr("Editing model %1: ").arg(row) + model.name);
    connect(t, SIGNAL(modified()), this, SLOT(setModified()));
    t->show();
    QApplication::restoreOverrideCursor();
  }
}
Example #8
0
// Edit a timer of the list
void MainWindow::editTimerTriggerred()
{
    Timer* timer = getCurrentTimer();

    // Prevent the user to edit the timer if its media is broken
    if (timer->isBroken()) {
        QMessageBox::warning(this, tr("Error"), tr("This timer can't be modified because it's broken"), QMessageBox::Ok);
    }
    else {
        QString filename         = timer->getFilename();
        int period               = timer->getPeriod();
        QKeySequence keySequence = timer->getKeySequence();
        UINT virtualKey          = timer->getVirtualKey();
        UINT modifiers           = timer->getModifiers();

        QPointer<DlgEditTimer> dlg = new DlgEditTimer(filename, period, keySequence, modifiers, virtualKey, this);
        if (dlg->exec() == QDialog::Accepted) {
            try {
                timer->setNewData(dlg->getPeriod(), dlg->getKeySquence(), dlg->getNativeModifiers(), dlg->getNativeVirtualKey(), this->hotkeyID);
                this->hotkeyID++;
            }
            catch (const SMException& exception) {
                QString message = tr("Couldn't modify the timer: %1").arg(exception.getMessage());
                QMessageBox::critical(this, tr("Error"), message, QMessageBox::Ok);
                return;
            }

            int period              = timer->getPeriod();
            QString displayedPeriod = QString("%1:%2").arg(period / 60, 2, 10, QChar('0')).arg(period % 60, 2, 10, QChar('0'));
            TableItem* itemPeriod   = new TableItem(displayedPeriod);

            QKeySequence keySequence = timer->getKeySequence();
            QString displayedHotkey  = keySequence.toString();
            TableItem* itemHotkey    = new TableItem(displayedHotkey);

            int row = getCurrentRow();
            this->timerTable->setItem(row, COLUMN_PERIOD, itemPeriod);
            this->timerTable->setItem(row, COLUMN_HOTKEY, itemHotkey);

            this->modified.setModified(true);
        }
        delete dlg;
    }
}
Example #9
0
// Delete a timer of the list
void MainWindow::removeTimerTriggerred()
{
    delete getCurrentTimer();
    this->timerTable->removeRow(getCurrentRow());
    this->modified.setModified(true);
}
Example #10
0
void updatePlayer(PLAYER* player)
{
	int8_t dx = 0;
	int8_t dy = 0;

	uint8_t row_top = 0;
	uint8_t row_bottom = 0;
	uint8_t column_left = 0;
	uint8_t column_right = 0;

	uint16_t right = player->x_position + PLAYER_WIDTH - 1;
	uint16_t left = player->x_position;
	uint16_t top = player->y_position;
	uint16_t bottom = player->y_position + PLAYER_HEIGHT - 1;

	row_bottom = getCurrentRow (bottom);
	column_left = getCurrentColumn (left);
	column_right = getCurrentColumn (right);

	if (player->left)
	{
		dx -= player->speed;
		column_left = getCurrentColumn (left + dx);
		row_bottom = getCurrentRow (bottom);
		row_top = getCurrentRow (top + dy);

		if (map[row_top][column_left] == BLOCKED || map[row_bottom][column_left] == BLOCKED)
		{
			dx = -(dx + ((left - dx) % CELL_WIDTH));
		}
	}

	if (player->right)
	{
		dx += player->speed;
		column_right = getCurrentColumn (right + dx);
		row_bottom = getCurrentRow (bottom);
		row_top = getCurrentRow (top + dy);

		if (map[row_top][column_right] == BLOCKED || map[row_bottom][column_right] == BLOCKED)
		{
			dx = dx - ((left + dx) % CELL_WIDTH);
		}
	}

	row_bottom = getCurrentRow (bottom);
	column_left = getCurrentColumn (left + dx);
	column_right = getCurrentColumn (right + dx);

	if (player->jumping)
	{
		dy -= player->jump_speed;
		player->current_jump_height += player->jump_speed;
		if (player->current_jump_height > MAX_JUMP_HEIGHT)
		{
			player->jumping = 0;
			player->falling = 1;
			player->current_jump_height = 0;
		}
		row_top = getCurrentRow (top + dy);
		column_left = getCurrentColumn (left + dx);
		column_right = getCurrentColumn (right + dx);

		if (map[row_top][column_left] == BLOCKED || map[row_top][column_right] == BLOCKED)
		{
			dy = -(dy + ((player->y_position - dy) % CELL_HEIGHT));
			player->jumping = 0;
			player->falling = 1;
			player->current_jump_height = 0;
		}
	}
	else if (map[row_bottom][column_left] == AIR && map[row_bottom][column_right] == AIR)
	{
		player->falling = 1;
		dy += GRAVITY;

		row_bottom = getCurrentRow (bottom + dy);
		column_left = getCurrentColumn (left + dx);
		column_right = getCurrentColumn (right + dx);

		if (map[row_bottom][column_left] == BLOCKED || map[row_bottom][column_right] == BLOCKED)
		{
			dy = dy - ((player->y_position + dy) % CELL_HEIGHT);
			player->falling = 0;
		}

	}

	player->x_position += dx;
	player->y_position += dy;
}
Example #11
0
void MdiChild::simulate()
{
  if (getCurrentRow() > 0) {
    startSimulation(this, radioData, getCurrentRow()-1);
  }
}
void EditorBuffer::moveCursorRow(int direction, bool shift, bool cmd) {
  setCursorPosition(getCurrentCol(), getCurrentRow() + direction);
  updateSelect(shift);
}