예제 #1
0
void MainWindow::on_insertTitle_clicked()
{
    QTextEdit *pEdit = textEditor.editor;
    QTextCursor cursor = pEdit->textCursor();

    //set alignment center
    pEdit->setAlignment(Qt::AlignHCenter);
    groupCheck(0);

    //insert title
    cursor.insertText("“    ”学院 2011—2012学年第一学期\n");

    //insert paper info
    cursor.insertText("《           》期末考试试卷(  卷) 考核形式(  卷)\n");

    //set alignment left
    pEdit->setAlignment(Qt::AlignLeft);
    groupCheck(2);

    QFont font = pEdit->font();
    font.setBold(true);
    font.setPointSize(16);
    pEdit->setFont(font);
    pEdit->setTextCursor(cursor);
    pEdit->setFocus();
}
예제 #2
0
Dashboard::Dashboard(QWidget *parent)
    : QMainWindow(parent)
    , d_ptr(new DashboardPrivate(this))
{
    setWindowTitle("Maliit Keyboard Viewer");
    resize(854, 480);

    QGraphicsView *v = new QGraphicsView;
    v->setScene(new QGraphicsScene(v));
    v->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    v->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setCentralWidget(v);
    v->show();
    QWidget *w = 0;
    d_ptr->proxy_widget = v->scene()->addWidget(w = new QWidget);
    d_ptr->proxy_widget->setTransformOriginPoint(d_ptr->proxy_widget->geometry().center());
    w->resize(size());

    QVBoxLayout *vbox = d_ptr->vbox;
    w->setLayout(vbox);

    QSpacerItem *top_spacer = d_ptr->top;
    vbox->addItem(top_spacer);

    QWidget *buttons = d_ptr->buttons;
    buttons->show();
    vbox->addWidget(buttons);
    QHBoxLayout *hbox = new QHBoxLayout;
    buttons->setLayout(hbox);

    QPushButton *show = new QPushButton("Show virtual keyboard");
    connect(show, SIGNAL(clicked()),
            this, SLOT(onShow()));
    hbox->addWidget(show);
    show->show();

    QPushButton *orientation_changed = new QPushButton("Change orientation");
    connect(orientation_changed, SIGNAL(clicked()),
            this, SLOT(onOrientationChangeClicked()));
    hbox->addWidget(orientation_changed);
    orientation_changed->show();

    QPushButton *close = new QPushButton("Close application");
    connect(close, SIGNAL(clicked()),
            qApp,  SLOT(quit()));
    hbox->addWidget(close);
    close->show();

    QTextEdit *te = d_ptr->text_entry;
    vbox->addWidget(te);
    te->show();
    te->setFocus();

    QSpacerItem *bottom_spacer = d_ptr->bottom;
    vbox->addItem(bottom_spacer);

    onShow();
}
예제 #3
0
void SourceViewer::setSourceText(const QString &key, const QString &name, const QString &searchText, const QByteArray &sourceTextBuffer)
{
	QTextEdit *logTextEdit = NULL;
	QTextEditorContextMap::const_iterator i = logTextWidgetMap_.find(key);
	if(i == logTextWidgetMap_.end())
	{
		// New tab created..
		logTextEdit = new QTextEdit();
		QObject::connect(logTextEdit, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
		logTextEdit->setReadOnly(true);

		SourceViewContext* ctx = new SourceViewContext();
		ctx->logTextEdit = logTextEdit;
		logTextWidgetMap_.insert(key, ctx);
		ui.tabWidget->insertTab(0, logTextEdit, name);
		ui.tabWidget->setCurrentIndex(0);
	}
	else
	{
		// Already the tab exists.
		logTextEdit = i.value()->logTextEdit;
		int index = ui.tabWidget->indexOf(logTextEdit);
		if(index >= 0)
		{
			ui.tabWidget->setCurrentIndex(index);
		}
	}

	workingHighlightText_ = true;

	ui.searchText->setText(searchText);

	logTextEdit->setText(sourceTextBuffer);

	logTextEdit->setFocus();

	if(searchText.isEmpty() == false) 
	{
		doHighlightText(searchText, ui.caseSensitiveCheck->isChecked());
	
		QTextDocument::FindFlags flags = 0x0;
		if(ui.caseSensitiveCheck->isChecked())
			flags |=  QTextDocument::FindCaseSensitively;

		logTextEdit->moveCursor(QTextCursor::Start);

		while(logTextEdit->find(searchText, flags))
		{
			break;
		}
	}

	workingHighlightText_ = false;
}
예제 #4
0
/**
 * Inserts an image tag corresponding to the clicked smiley
 * into the message-textbox.
 * @brief MainWindow::on_lstSmileys_doubleClicked
 */
void MainWindow::on_lstSmileys_doubleClicked(const QModelIndex &index)
{
    QString img = "<img src=\"images/smileys/small/" + QString::number(index.row()) + ".png\" />";
    QTextEdit* txtMsg = ui->txtMessage;

    if(ui->tabgrpConversations->currentIndex() != 0)
    {
        txtMsg = ui->tabgrpConversations->currentWidget()->findChild<QTextEdit*>(CONVO_TAB_MSG_ID);
    }
    txtMsg->insertPlainText(img);
    txtMsg->setFocus();
}
예제 #5
0
void MainWindow::on_insertTable_clicked()
{
    InsertTableDialog dlg;
    if(dlg.exec() != QDialog::Accepted)
        return;

    QTextEdit *pEdit = textEditor.editor;
    QTextCursor cursor = pEdit->textCursor();
    QTextTableFormat format;
    format.setCellSpacing(0);
    format.setCellPadding(5);
    cursor.insertTable(dlg.row(), dlg.column(), format);
    pEdit->setFocus();
}
예제 #6
0
void MainWindow::on_insetList_clicked()
{
    QInputDialog dlg;
    QStringList items;
    items << tr("○..., ○..., ○...")
          << tr("●..., ●..., ●...")
          << tr("■..., ■..., ■...")
          << tr("1..., 2..., 3...")
          << tr("a..., b..., c...")
          << tr("A..., B..., C...")
          << tr("i..., ii..., iii...")
          << tr("I..., II..., III...");

    bool ok;
    QString item = QInputDialog::getItem(this, tr("请选择列表样式"),
                                         tr("列表前缀:"), items, 0, false, &ok);
    if (!ok || item.isEmpty())
        return;

    QTextEdit *pEdit = textEditor.editor;
    QTextCursor cursor = pEdit->textCursor();

    QTextListFormat listFormat;
    if(item == tr("○..., ○..., ○..."))
        listFormat.setStyle(QTextListFormat::ListCircle);
    else if(item == tr("●..., ●..., ●..."))
        listFormat.setStyle(QTextListFormat::ListDisc);
    else if(item == tr("■..., ■..., ■..."))
        listFormat.setStyle(QTextListFormat::ListSquare);
    else if(item == tr("1..., 2..., 3..."))
        listFormat.setStyle(QTextListFormat::ListDecimal);
    else if(item == tr("a..., b..., c..."))
        listFormat.setStyle(QTextListFormat::ListLowerAlpha);
    else if(item == tr("A..., B..., C..."))
        listFormat.setStyle(QTextListFormat::ListUpperAlpha);
    else if(item == tr("i..., ii..., iii..."))
        listFormat.setStyle(QTextListFormat::ListLowerRoman);
    else
        listFormat.setStyle(QTextListFormat::ListUpperRoman);

    cursor.insertList(listFormat);
    pEdit->setFocus();
}
예제 #7
0
QString QtopiaInputDialog::getMultiLineText(QWidget *parent, const QString &title, const QString &label,
                                            QtopiaApplication::InputMethodHint hint, const QString &hintParam,
                                            const QString &text, bool *ok)
{
    QTextEdit *te = new QTextEdit;
    QtopiaApplication::setInputMethodHint(te, hint, hintParam);
    te->setPlainText(text);
    te->setFocus();
    te->selectAll();
    te->setMinimumHeight(100);

    QtopiaInputDialog dlg(parent, title, label, te);

    QString result;
    bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
    if (ok)
        *ok = accepted;
    if (accepted)
        result = te->toPlainText();

    return result;
}
예제 #8
0
void osk_dialog_frame::Create(const std::string& title, const std::u16string& message, char16_t* init_text, u32 charlimit, u32 options)
{
	state = OskDialogState::Open;

	static const auto& lineEditWidth = []() {return QLabel("This is the very length of the lineedit due to hidpi reasons.").sizeHint().width(); };

	if (m_dialog)
	{
		m_dialog->close();
		delete m_dialog;
	}

	m_dialog = new custom_dialog(false);
	m_dialog->setModal(true);

	// Title
	m_dialog->setWindowTitle(qstr(title));

	// Message
	QLabel* message_label = new QLabel(QString::fromStdU16String(message));

	// Text Input Counter
	const QString text = QString::fromStdU16String(std::u16string(init_text));
	QLabel* inputCount = new QLabel(QString("%1/%2").arg(text.length()).arg(charlimit));

	// Ok Button
	QPushButton* button_ok = new QPushButton("Ok", m_dialog);

	// Button Layout
	QHBoxLayout* buttonsLayout = new QHBoxLayout;
	buttonsLayout->setAlignment(Qt::AlignCenter);
	buttonsLayout->addStretch();
	buttonsLayout->addWidget(button_ok);
	buttonsLayout->addStretch();

	// Input Layout
	QHBoxLayout* inputLayout = new QHBoxLayout;
	inputLayout->setAlignment(Qt::AlignHCenter);

	// Text Input
	if (options & CELL_OSKDIALOG_NO_RETURN)
	{
		QLineEdit* input = new QLineEdit(m_dialog);
		input->setFixedWidth(lineEditWidth());
		input->setMaxLength(charlimit);
		input->setText(text);
		input->setFocus();

		if (options & CELL_OSKDIALOG_NO_SPACE)
		{
			input->setValidator(new QRegExpValidator(QRegExp("^\\S*$"), this));
		}

		connect(input, &QLineEdit::textChanged, [=](const QString& text)
		{
			inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
			SetOskText(text);
			on_osk_input_entered();
		});
		connect(input, &QLineEdit::returnPressed, m_dialog, &QDialog::accept);

		inputLayout->addWidget(input);
	}
	else
	{
		QTextEdit* input = new QTextEdit(m_dialog);
		input->setFixedWidth(lineEditWidth());
		input->setText(text);
		input->setFocus();
		input->moveCursor(QTextCursor::End);
		m_text_old = text;

		connect(input, &QTextEdit::textChanged, [=]()
		{
			QString text = input->toPlainText();

			if (text == m_text_old)
			{
				return;
			}

			QTextCursor cursor = input->textCursor();
			const int cursor_pos_new = cursor.position();
			const int cursor_pos_old = cursor_pos_new + m_text_old.length() - text.length();

			// Reset to old state if character limit was reached
			if ((u32)m_text_old.length() >= charlimit && (u32)text.length() > charlimit)
			{
				input->blockSignals(true);
				input->setPlainText(m_text_old);
				cursor.setPosition(cursor_pos_old);
				input->setTextCursor(cursor);
				input->blockSignals(false);
				return;
			}

			int cursor_pos = cursor.position();

			// Clear text of spaces if necessary
			if (options & CELL_OSKDIALOG_NO_SPACE)
			{
				int trim_len = text.length();
				text.remove(QRegExp("\\s+"));
				trim_len -= text.length();
				cursor_pos -= trim_len;
			}

			// Crop if more than one character was pasted and the character limit was exceeded
			text.chop(text.length() - charlimit);

			// Set new text and block signals to prevent infinite loop
			input->blockSignals(true);
			input->setPlainText(text);
			cursor.setPosition(cursor_pos);
			input->setTextCursor(cursor);
			input->blockSignals(false);

			m_text_old = text;

			inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
			SetOskText(text);
			on_osk_input_entered();
		});

		inputLayout->addWidget(input);
	}

	inputLayout->addWidget(inputCount);

	QFormLayout* layout = new QFormLayout(m_dialog);
	layout->setFormAlignment(Qt::AlignHCenter);
	layout->addRow(message_label);
	layout->addRow(inputLayout);
	layout->addRow(buttonsLayout);
	m_dialog->setLayout(layout);

	// Events
	connect(button_ok, &QAbstractButton::clicked, m_dialog, &QDialog::accept);

	connect(m_dialog, &QDialog::accepted, [=]
	{
		on_osk_close(CELL_MSGDIALOG_BUTTON_OK);
	});

	connect(m_dialog, &QDialog::rejected, [=]
	{
		on_osk_close(CELL_MSGDIALOG_BUTTON_ESCAPE);
	});

	// Fix size
	m_dialog->layout()->setSizeConstraint(QLayout::SetFixedSize);
	m_dialog->show();
}