void TextInstance::startExecution()
	{
		bool ok = true;
	
		mText = evaluateString(ok, "text");
		int pause  = evaluateInteger(ok, "pause");

		if(pause < 0)
			pause = 0;

		mTimer->setInterval(pause);
		mCurrentCharacter = 0;
	
		if(!ok)
			return;
		
		if(pause == 0)
		{
			if(!mKeyboardDevice.writeText(mText))
			{
				emit executionException(FailedToSendInputException, tr("Unable to write the text"));
				return;
			}

			QTimer::singleShot(1, this, SIGNAL(executionEnded()));
		}
		else
		{
			pressNextKey();

			mTimer->start();
		}
	}
	void PlaySoundInstance::startExecution()
	{
		bool ok = true;

		QString file = evaluateString(ok, "file");
		int volume = evaluateInteger(ok, "volume");
		mBlocking = evaluateBoolean(ok, "blocking");
		bool looping = evaluateBoolean(ok, "looping");
		bool isUrl = evaluateBoolean(ok, "url");
		int playbackRate = evaluateInteger(ok, "playbackRate");

		if(!ok)
			return;

		mMediaPlaylist->clear();

		QUrl url;

		if(isUrl)
			url = QUrl(file);
		else
			url = QUrl::fromLocalFile(file);

		if(!mMediaPlaylist->addMedia(url))
		{
			emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to load file %1: %2").arg(file).arg(mMediaPlayer->errorString()));
			return;
		}

		mMediaPlaylist->setPlaybackMode(looping ? QMediaPlaylist::Loop : QMediaPlaylist::CurrentItemOnce);

		mMediaPlayer->setPlaybackRate(playbackRate / 100.0f);
		mMediaPlayer->setVolume(volume);
		mMediaPlayer->play();

		if(mMediaPlayer->error() != QMediaPlayer::NoError)
		{
			emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to play file %1: %2").arg(file).arg(mMediaPlayer->errorString()));
			return;
		}

		if(!mBlocking)
			emit executionEnded();
	}
Exemple #3
0
	void FindImageInstance::startExecution()
	{
		bool ok = true;

		mSource = evaluateListElement<Source>(ok, sources, QStringLiteral("source"));
		mImageToFind = evaluateImage(ok, QStringLiteral("imageToFind"));
		mIfFound = evaluateIfAction(ok, QStringLiteral("ifFound"));
		mIfNotFound = evaluateIfAction(ok, QStringLiteral("ifNotFound"));
		mPositionVariableName = evaluateVariable(ok, QStringLiteral("position"));
		mMethod = evaluateListElement<Method>(ok, methods, QStringLiteral("method"));
		mWindowRelativePosition = evaluateBoolean(ok, QStringLiteral("windowRelativePosition"));
		mConfidenceMinimum = evaluateInteger(ok, QStringLiteral("confidenceMinimum"));
		mMaximumMatches = evaluateInteger(ok, QStringLiteral("maximumMatches"));
		mDownPyramidCount = evaluateInteger(ok, QStringLiteral("downPyramidCount"));
		mSearchExpansion = evaluateInteger(ok, QStringLiteral("searchExpansion"));
		mConfidenceVariableName = evaluateVariable(ok, QStringLiteral("confidence"));
		mSearchDelay = evaluateInteger(ok, QStringLiteral("searchDelay"));

		if(!ok)
			return;

		validateParameterRange(ok, mConfidenceMinimum, QStringLiteral("confidenceMinimum"), tr("minimum confidence"), 0, 100);
		validateParameterRange(ok, mMaximumMatches, QStringLiteral("maximumMatches"), tr("maximum matches"), 1);
		validateParameterRange(ok, mDownPyramidCount, QStringLiteral("downPyramidCount"), tr("downsampling"), 1);
		validateParameterRange(ok, mSearchExpansion, QStringLiteral("searchExpansion"), tr("search expansion"), 1);

		if(!ok)
			return;

        if(mImageToFind.isNull())
		{
            emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Invalid image to find"));

			return;
		}

        startSearching();
    }
Exemple #4
0
	void MultiDataInputInstance::startExecution()
	{
		bool ok = true;

		QString question = evaluateString(ok, QStringLiteral("question"));
		mMode = evaluateListElement<Mode>(ok, modes, QStringLiteral("mode"));
		mItems = evaluateItemList(ok, QStringLiteral("items"));
		QString defaultValue = evaluateString(ok, QStringLiteral("defaultValue"));
		mVariable = evaluateVariable(ok, QStringLiteral("variable"));
		QString windowTitle = evaluateString(ok, QStringLiteral("windowTitle"));
		QImage windowIcon = evaluateImage(ok, QStringLiteral("windowIcon"));
		mMaximumChoiceCount = evaluateInteger(ok, QStringLiteral("maximumChoiceCount"));

		if(!ok)
			return;

		if(mDialog)
			delete mDialog;

		mDialog = new QDialog;

        mDialog->setWindowFlags(mDialog->windowFlags() | Qt::WindowContextHelpButtonHint);

		auto layout = new QVBoxLayout(mDialog);

		mDialog->setLayout(layout);
		mDialog->setWindowTitle(windowTitle);

        if(!windowIcon.isNull())
            mDialog->setWindowIcon(QIcon(QPixmap::fromImage(windowIcon)));

		QLabel *questionLabel = new QLabel(mDialog);
		questionLabel->setText(question);
		layout->addWidget(questionLabel);

		switch(mMode)
		{
		case ComboBoxMode:
		case EditableComboBoxMode:
			{
				mComboBox = new QComboBox(mDialog);
				mComboBox->addItems(mItems);

				int currentItem = mComboBox->findText(defaultValue);
				if(currentItem == -1)
					currentItem = 0;
				mComboBox->setCurrentIndex(currentItem);

				mComboBox->setEditable(mMode == EditableComboBoxMode);

				layout->addWidget(mComboBox);
			}
			break;
		case ListMode:
			{
				mListWidget = new QListWidget(mDialog);

				if(mMaximumChoiceCount <= 1)
					mListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
				else
					mListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);

				mListWidget->addItems(mItems);

				QList<QListWidgetItem *> defaultItem = mListWidget->findItems(defaultValue, Qt::MatchExactly);
				if(!defaultItem.isEmpty())
					mListWidget->setCurrentItem(defaultItem.first());

				layout->addWidget(mListWidget);

				if(mMaximumChoiceCount > 1)
                    connect(mListWidget, &QListWidget::itemSelectionChanged, this, &MultiDataInputInstance::listItemSelectionChanged);
			}
			break;
		case CheckboxMode:
			layout->addLayout(createRadioButtonsOrCheckboxes<QCheckBox>(defaultValue, mMaximumChoiceCount <= 1));
			break;
		case RadioButtonMode:
			layout->addLayout(createRadioButtonsOrCheckboxes<QRadioButton>(defaultValue, true));
			break;
		}

        if(mMode != ListMode)
            layout->addStretch(1);

		QDialogButtonBox *dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, mDialog);
		layout->addWidget(dialogButtonBox);

        connect(dialogButtonBox, &QDialogButtonBox::accepted, mDialog, &QDialog::accept);
        connect(dialogButtonBox, &QDialogButtonBox::rejected, mDialog, &QDialog::reject);
        connect(mDialog, &QDialog::accepted, this, &MultiDataInputInstance::accepted);
        connect(mDialog, &QDialog::rejected, this, &MultiDataInputInstance::rejected);

        for(QLabel *label: mDialog->findChildren<QLabel*>())
            label->setOpenExternalLinks(true);

		mDialog->show();
	}