/**
 * 桥梁限界输入界面类定义
 *
 * @author 熊雪
 * @author 范翔
 * @version 1.0.0
 * @date 20140615
 */
InputBridgeWidget::InputBridgeWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::InputBridgeWidget)
{
    ui->setupUi(this);

    //data.initMaps();
    bridgeCollectModel = NULL;

    tunnelid = -1;

    tasktunnelid = -1;

    connect(ui->finishButton, SIGNAL(clicked()), this, SLOT(finishEdit()));

    // 初始没有做任何编辑
    hasedit = false;

    // 加载桥梁限界表表头数据
    loadBridgeClearanceData();

    // 关于编辑限界值、保存限界值的信号槽
    connect(ui->tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(saveItemChanged(QTableWidgetItem*)));
    connect(ui->lineEdit_minHeight,SIGNAL(textEdited(QString)),this,SLOT(minheightChanged(QString)));
    connect(ui->modifyButton, SIGNAL(clicked()), this, SLOT(canBeModified()));
    connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveChanges()));
    //connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancelModify()));
}
Ejemplo n.º 2
0
void ExprShortTextEdit::focusOutEvent(QFocusEvent* e) {
    // setTextCursor(QTextCursor());
    finishEdit();
    QTextCursor newCursor = textCursor();
    newCursor.clearSelection();
    setTextCursor(newCursor);
    setColor(false);
    hideTip();
    QTextEdit::focusOutEvent(e);
}
Ejemplo n.º 3
0
bool PosEdit::event(QEvent* event)
{
    if (event->type() == QEvent::KeyPress)
    {
        QKeyEvent* ke = static_cast<QKeyEvent*> (event);
        if (ke->key() == Qt::Key_Return)
        {
            //printf("key press event Return\n");   // REMOVE Tim.
            //enterPressed();
            finishEdit();
            emit returnPressed();
            emit editingFinished();
            return true;
        }

        if (ke->key() == Qt::Key_Escape)
        {
            //printf("key press event Escape\n");   // REMOVE Tim.
            if (lineEdit())
                lineEdit()->undo();
            // "By default, isAccepted() is set to true, but don't rely on this as subclasses may
            //   choose to clear it in their constructor."
            // Just to be sure. Otherwise escape will close a midi editor for example, which is annoying.
            ke->setAccepted(true);
            return true;
        }

        int segment = curSegment();
        if (ke->key() == Qt::Key_Backtab)
        {
            if (segment == 2)
            {
                lineEdit()->setSelection(5, 2);
                return true;
            }
            if (segment == 1)
            {
                lineEdit()->setSelection(0, 4);
                return true;
            }
        }
        if (ke->key() == Qt::Key_Tab)
        {
            if (segment == 0)
            {
                lineEdit()->setSelection(5, 2);
                return true;
            }
            if (segment == 1)
            {
                lineEdit()->setSelection(8, 3);
                return true;
            }
        }
    }
    else if (event->type() == QEvent::FocusIn)
    {
        QFocusEvent* fe = static_cast<QFocusEvent*> (event);
        QAbstractSpinBox::focusInEvent(fe);
        int segment = curSegment();
        switch (segment)
        {
        case 0: lineEdit()->setSelection(0, 4);
            break;
        case 1: lineEdit()->setSelection(5, 2);
            break;
        case 2: lineEdit()->setSelection(8, 3);
            break;
        }
        return true;
    }
    else if (event->type() == QEvent::FocusOut)
    {
        QFocusEvent* fe = static_cast<QFocusEvent*> (event);
        QAbstractSpinBox::focusOutEvent(fe);
        finishEdit();
        emit lostFocus();
        emit editingFinished();
        return true;
    }

    return QAbstractSpinBox::event(event);
}
Ejemplo n.º 4
0
void ExprShortTextEdit::keyPressEvent(QKeyEvent* e) {

    // If the completer is active pass keys it needs down
    if (completer && completer->popup()->isVisible()) {
        switch (e->key()) {
            case Qt::Key_Enter:
            case Qt::Key_Return:
            case Qt::Key_Escape:
            case Qt::Key_Tab:
            case Qt::Key_Backtab:
                e->ignore();
                return;
            default:
                break;
        }
    }

    // Accept expression
    if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
        selectAll();
        finishEdit();
        return;
    } else if (e->key() == Qt::Key_Escape) {
        setText(savedText);
        selectAll();
        finishEdit();
        return;
    } else if (e->key() == Qt::Key_Tab) {
        QWidget::keyPressEvent(e);
        return;
    } else if (!editing) {
        editing = true;
        setColor(true);
        savedText = toPlainText();
    }

    // use the values here as long as we are not using the shortcut to bring up the editor
    bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E);  // CTRL+E
    if (!isShortcut)  // dont process the shortcut when we have a completer
        QTextEdit::keyPressEvent(e);

    const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
    if (!completer || (ctrlOrShift && e->text().isEmpty())) return;

    bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;

    // grab the line we're on
    QTextCursor tc = textCursor();
    tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
    QString line = tc.selectedText();

    // matches the last prefix of a completable variable or function and extract as completionPrefix
    static QRegExp completion("^(?:.*[^A-Za-z0-9_$])?((?:\\$[A-Za-z0-9_]*)|[A-Za-z]+[A-Za-z0-9_]*)$");
    int index = completion.indexIn(line);
    QString completionPrefix;
    if (index != -1 && !line.contains('#')) {
        completionPrefix = completion.cap(1);
        // std::cout<<"we have completer prefix '"<<completionPrefix.toStdString()<<"'"<<std::endl;
    }

    // hide the completer if we have too few characters, we are at end of word
    if (!isShortcut && (hasModifier || e->text().isEmpty() || completionPrefix.length() < 1 || index == -1)) {
        completer->popup()->hide();
    } else {

        // copy the completion prefix in if we don't already have it in the completer
        if (completionPrefix != completer->completionPrefix()) {
            completer->setCompletionPrefix(completionPrefix);
            completer->popup()->setCurrentIndex(completer->completionModel()->index(0, 0));
        }

        // display the completer
        QRect cr = cursorRect();
        cr.setWidth(2 * (completer->popup()->sizeHintForColumn(0) + completer->popup()->sizeHintForColumn(1) +
                         completer->popup()->verticalScrollBar()->sizeHint().width()));
        completer->complete(cr);
        hideTip();
        return;
    }

    // documentation completion
    static QRegExp inFunction("^(?:.*[^A-Za-z0-9_$])?([A-Za-z0-9_]+)\\([^()]*$");
    int index2 = inFunction.indexIn(line);
    if (index2 != -1) {
        QString functionName = inFunction.cap(1);
        QStringList tips = completionModel->getDocString(functionName).split("\n");
        QString tip = "<b>" + tips[0] + "</b>";
        for (int i = 1; i < tips.size(); i++) {
            tip += "<br>" + tips[i];
        }
        showTip(tip);
    } else {
        hideTip();
    }
}
Ejemplo n.º 5
0
EditorMenuWidget::EditorMenuWidget(QWidget *parent) :
	QWidget(parent)
{
	editorMenuLayout = new QVBoxLayout(this);

	placeBallButton = new QPushButton(this);
	placeBallButton->setText("Modify ball position (Alt + &B)");
	connect(placeBallButton, &QPushButton::clicked, [this](){
		placeBallButton->setStyleSheet("color: black; background-color: red");
		editLineButton->setStyleSheet("color: black; background-color: white");
		emit placeBallMode();});
	editorMenuLayout->addWidget(placeBallButton);

	editLineButton = new QPushButton(this);
	editLineButton->setText("Modify field lines (Alt + &G)");
	connect(editLineButton, &QPushButton::clicked, [this](){
		placeBallButton->setStyleSheet("color: black; background-color: white");
		editLineButton->setStyleSheet("color: black; background-color: yellow");
		emit editLineMode();});
	editorMenuLayout->addWidget(editLineButton);

	playerChangeButton = new QPushButton(this);
	connect(playerChangeButton, &QPushButton::clicked, [this](){
		gameState->changePlayer();
		updatePlayer();
	});
	editorMenuLayout->addWidget(playerChangeButton);

	checkboxWidget = new QWidget(this);
	checkboxesLayout = new QHBoxLayout(checkboxWidget);
	p1AICheckBox = new QCheckBox(this);
	p1AICheckBox->setText("Player 1 controlled by AI");
	p2AICheckBox = new QCheckBox(this);
	p2AICheckBox->setText("Player 2 controlled by AI");
	checkboxesLayout->addWidget(p1AICheckBox);
	checkboxesLayout->addWidget(p2AICheckBox);
	checkboxWidget->setLayout(checkboxesLayout);

	editorMenuLayout->addWidget(checkboxWidget);

	finishButton = new QPushButton(this);
	finishButton->setText("Finish Edit (Alt + &Q)");
	connect(finishButton, &QPushButton::clicked, [this](){
		gameState->setPlayer1AI(p1AICheckBox->isChecked());
		gameState->setPlayer2AI(p2AICheckBox->isChecked());
		emit finishEdit();
	});
	editorMenuLayout->addWidget(finishButton);

	infoButton = new QPushButton("Show instructions (Alt + &H)", this);
	connect(infoButton, &QPushButton::clicked, [this](){
		if(infoLabel->isHidden()){
			infoButton->setText("Hide instructions (Alt + &H)");
			infoLabel->show();
		}else{
			infoButton->setText("Show instructions (Alt + &H)");
			infoLabel->hide();
		}
	});

	infoLabel = new QLabel(this);
	infoLabel->setStyleSheet("color: black; background-color: white");
	infoLabel->setAlignment(Qt::AlignCenter);
	QString text = "";
	text += "When the PLACE BALL MODE is activated, click a point\n";
	text += "to place the ball there. When the EDIT LINE MODE is\n";
	text += "activated, click two adjacent points to add/remove the line\n";
	text += "between them. To change modes, use buttons.\n";
	text += "The goal cannot be modified.";
	infoLabel->setText(text);
	infoLabel->hide();

	editorMenuLayout->addWidget(infoButton);
	editorMenuLayout->addWidget(infoLabel);

	setLayout(editorMenuLayout);

}