示例#1
0
void
SpinBox::focusOutEvent(QFocusEvent* e)
{
    //qDebug() << "focusout";
    QString str = text();

    if (str != _imp->valueWhenEnteringFocus) {
        if ( validateText() ) {
            //setValue_internal(text().toDouble(), true, true); // force a reformat
            bool ok;
            QString newValueStr = text();
            double newValue = newValueStr.toDouble(&ok);

            if (!ok) {
                newValueStr = _imp->valueWhenEnteringFocus;
                newValue = newValueStr.toDouble(&ok);
                assert(ok);
            }
            QLineEdit::setText(newValueStr);
            Q_EMIT valueChanged(newValue);
        }
    } else {
        bool ok;
        double v = str.toDouble(&ok);
        Q_UNUSED(v);
        if (!ok) {
            QLineEdit::setText(_imp->valueWhenEnteringFocus);
        }
    }
    LineEdit::focusOutEvent(e);
}
示例#2
0
void
SpinBox::interpretReturn()
{
    if ( validateText() ) {
        //setValue_internal(text().toDouble(), true, true); // force a reformat
        Q_EMIT valueChanged( value() );
    }
}
示例#3
0
void FindLineEdit::keyPressEvent(QKeyEvent *event)
{
    QLineEdit::keyPressEvent(event);

    if (use_regex_) {
        validateText();
    }
}
示例#4
0
LicenseTemplate::LicenseTemplate()
{
  QVBoxLayout *licenseTemplateVLayout = new QVBoxLayout;
  licensePlainTextEdit = new QPlainTextEdit;
  licensePlainTextEdit->setPlainText(settings.value("License/Template", "").toString());
  licenseTemplateVLayout->addWidget(licensePlainTextEdit);
  fileSelector = new FileSelector(FileSelectorContexts::LicenseFile);
  fileSelector->setFileName(settings.value("License/File", "").toString());
  connect(fileSelector, SIGNAL(changed()), this, SLOT(fileSelectorSlot())),
  licenseTemplateVLayout->addWidget(fileSelector);
  buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Help);
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(saveLicenseTemplateText()));
  licenseTemplateVLayout->addWidget(buttonBox);
  connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(helpLicenseTemplate()));
  connect(licensePlainTextEdit, SIGNAL(textChanged()), this, SLOT(validateText()));
  retranslateUi();
  setLayout(licenseTemplateVLayout);
  validateText();
}
示例#5
0
/**
 * \brief Validates the entered Unicode number and displays its Unicode character.
 */
void UnicodeDialog::slotTextChanged(QString text)
{
    unicodeNumber->blockSignals(true);

    QString newText = validateText(text);
    if (newText.length() == 0) {
        unicodeChar->setText("");
        unicodeNumber->setText("");
        clearOverviewChars();
        m_lastCursorPos = 0;
        m_lastUnicodeNumber = "";
        labelInfoText->setText(unicodeInfo(""));

    } else {

        int cursorPos = unicodeNumber->cursorPosition();

        unicodeNumber->setText(newText);
        unicodeNumber->setCursorPosition(cursorPos);

        // Get the decimal number as uint to create the QChar from
        bool ok;
        uint value = 0;
        switch (inputMethod) {
        case InputHex:
            value = newText.toUInt(&ok, 16);
            break;
        case InputDec:
            value = newText.toUInt(&ok, 10);
            break;
        }
        updateOverviewChars(value);

        if (!ok) {
            // Impossible! validateText never fails!
        }

        // If an invalid character has been entered:
        // Reset the cursor position because the entered char has been deleted.
        if (text != newText && newText == m_lastUnicodeNumber) {
            unicodeNumber->setCursorPosition(m_lastCursorPos);
        }

        m_lastCursorPos = unicodeNumber->cursorPosition();
        m_lastUnicodeNumber = newText;

        labelInfoText->setText(unicodeInfo(newText));
        unicodeChar->setText(QChar(value));
    }

    unicodeNumber->blockSignals(false);
}
示例#6
0
	void TextInput::appendText(const std::string &text)
	{
		if (!validateText(text.c_str()))
		{
			return;
		}
		std::string str = getText();
		str.insert(mInputPosition, text);
		if (mMaxCharacters > 0 && str.size() > mMaxCharacters)
		{
			str.resize(mMaxCharacters);
		}
		mText->setText(str);
		fireChangeEvent();
		updateInputCursor(text.size());
	}
示例#7
0
int main(int argc, char **argv) {

	char key[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	FILE *fin = stdin;

	/*
	 * Get command line arguments. Setup key and input location
	 */
	switch (argc) {
		case 2:
			fin = fopen(argv[1], "r");
			if (fin == NULL) {
				printf("Invalid file: %s. Unable to open for reading.\n", argv[3]);
				return -1;
			}
		case 1:
			if (!removeLetter(key, 'J')) {
				printf("Could not remove letter J from cipher key.\n");
				return -1;
			}
			break;
		case 4:
			fin = fopen(argv[3], "r");
			if (fin == NULL) {
				printf("Invalid file: %s. Unable to open for reading.\n", argv[3]);
				return -1;
			}
		case 3:
			if (strcmp(argv[1], "-r")) {
				printf("Optional parameter '-r' not found. '%s' found instead.\n", argv[1]);
				return -1;
			}
			if(!removeLetter(key, argv[2][0])) {
				printf("Could not remove letter %c from cipher key.\n", argv[2][0]);
				return -1;
			}
			break;
		default:
			printf("Invalid usage. See below for proper usage.\n");
			printf("\t./%s [ -r <character_to_remove> ] [ ciphertext_filepath ]\n", argv[0]);
			return -1;
	}

	/*	
	 * Input cipher and ensure it is valid
	 */
	char *ciphertext, *plaintext;
	int messageLen;
	ciphertext = readCipher(fin, INPUT_STEP_SIZE);
	messageLen = strlen(ciphertext);
	if (validateText(ciphertext, &messageLen) != 0) {
		free(ciphertext);
		return -1;
	}
	ciphertext = realloc(ciphertext, sizeof(*ciphertext) * (messageLen + 1));
	ciphertext[messageLen] = '\0';
	plaintext = calloc(messageLen + 1, sizeof(*plaintext));
	strcpy(plaintext, ciphertext);	
	
	// close the file as long as it is not stdin
	if (fin != stdin)
		fclose(fin);

	// Output relevant information for error checking
	printf("Attempting to crack the following ciphertext with key: %s\n", key);
	printf("%s\n", ciphertext);

	int iter = 0;
	double score = -DBL_MAX, maxScore = -DBL_MAX;
	srand(time(NULL)); // randomize seed
	// Run until max iteration met 
	while (iter < MAX_ITERATIONS) {
		iter++;
		score = simulatedAnnealing(key, ciphertext, plaintext, messageLen);
		if (score > maxScore) {
			maxScore = score;
			decipher(key, ciphertext, plaintext, messageLen);
			printf("\nPossible Plaintext found using key:\n");
			outputKey(key);
			printf("%s\n\n", plaintext);
		}
	}
	
	free(plaintext);
	free(ciphertext);
	return 0;
}
示例#8
0
void FindLineEdit::setUseRegex()
{
    use_regex_ = true;
    validateText();
    emit useRegexFind(use_regex_);
}
示例#9
0
void FindLineEdit::setUseTextual()
{
    use_regex_ = false;
    validateText();
    emit useRegexFind(use_regex_);
}
示例#10
0
void ProgramInit::connectCoreAndGui()
{
    qDebug() << "--> GetInfoInit::connectAll()";

    connect(mainWindow, &MainWindow::searchParameters, core, &Core::search);
    connect(mainWindow, &MainWindow::addNewPlugin, core, &Core::addNewPlugin);
    connect(mainWindow, SIGNAL(textValidation(QString)), core->inputValidator.data(), SLOT(validateText(QString)));
    connect(mainWindow, &MainWindow::getQueryResultTable, core, &Core::getQueryResultModel);
    connect(mainWindow, &MainWindow::deleteHistoryRow, core, &Core::deleteHistoryRow);

    connect(mainWindow, &MainWindow::countryFieldChanged, core, &Core::setCurrentCountry);
    connect(mainWindow, &MainWindow::cityFieldChanged, core, &Core::updateCityModel);
    connect(mainWindow, &MainWindow::knowledgeFieldChanged, core, &Core::updateKnowledgeModel);

    connect(core, &Core::setResultModel, mainWindow , &MainWindow::setSearchResultModel);
    connect(core, &Core::setPluginList, mainWindow, &MainWindow::setupSearchResourcesCheckBoxes);
    connect(core->inputValidator.data(), &InputValidator::showValidateError, mainWindow, &MainWindow::showStatusBarMessage);
    connect(core->inputValidator.data(), &InputValidator::showNoValidateError, mainWindow, &MainWindow::clearStatusBarMessage);
    connect(core, &Core::setResultModel, mainWindow, &MainWindow::setQueryResultModel);
    connect(core, &Core::setPluginErrorMessage,
            mainWindow, &MainWindow::showErrorMessageFromPlugin);
    connect(core->getPluginProcessor(), &PluginProcessor::pluginsResultFinished, mainWindow, &MainWindow::closeProgressBar);
}