Пример #1
0
QWidget* PredictiveKeyboard::widget(QWidget*)
{
    if(!mKeyboard) {
        mKeyboard = new KeyboardWidget(createKeyboardConfig(), 0);
        //TODO: load layouts from config
        mKeyboard->addBoard("russian", QStringList() << "ЙЦУКЕНГШЩЗХЪ" << "ФЫВАПРОЛДЖЭ" << "ЯЧСМИТЬБЮ,", KeyboardWidget::UpperCase);
        mKeyboard->addBoard("russian", QStringList() << "йцукенгшщзхъ" << "фывапролджэ" << (QString("ячсмитьбю.") + QChar(0x21b5)), KeyboardWidget::LowerCase);

        mKeyboard->addBoard("english", QStringList() << "QWERTYUIOP" << "ASDFGHJKL" << "ZXCVBNM", KeyboardWidget::UpperCase);
        mKeyboard->addBoard("english", QStringList() << "qwertyuiop" << "asdfghjkl" << "zxcvbnm", KeyboardWidget::LowerCase);

        mKeyboard->addBoard("numeric", QStringList() << "12345" << "67890", KeyboardWidget::Numeric);
        mKeyboard->addBoard("symbol",  QStringList() << "^#@!$()*&%" << "|,.;:'?\\`" << (QString("[]+=-/~\"_") + QChar(0x21b5)), KeyboardWidget::NonAlphabet);

        mKeyboard->setDefaultLayout("russian");

        QObject::connect(mKeyboard, SIGNAL(preedit(QString)), this, SLOT(preedit(QString)));
        QObject::connect(mKeyboard, SIGNAL(commit(QString)), this, SLOT(submitWord(QString)));
        QObject::connect(mKeyboard, SIGNAL(commit(QString)), this, SLOT(checkMicroFocus()));
        QObject::connect(mKeyboard, SIGNAL(backspace()), this, SLOT(erase()));
        KeyboardWidget::instantiatePopupScreen();
    }

    return mKeyboard;
};
Пример #2
0
WDialog::WDialog(QWidget *parent, CEntry *entry) : QWidget(parent) {
	// set window properties
	setWindowTitle(tr("Editing word"));
	setWindowIcon(QIcon(ICON));
	wMain->centerWidgetOnScreen(this);
	resize(400, 0);
	setAttribute(Qt::WA_DeleteOnClose);
	
	// initialize variables
	this->entry = entry;
	
	// create widgets
	wordLabel=new QLabel(tr("Word:"), this);
	translationLabel=new QLabel(tr("Translation:"), this);
	wordEdit=new QLineEdit(this);
	translationEdit=new QLineEdit(this);
	spLabel = new QLabel(tr("Speech part:"));
	spBox = new QComboBox;
		spBox->addItem(tr("-"));
		spBox->addItem(tr("noun"));
		spBox->addItem(tr("verb"));
		spBox->addItem(tr("adjective"));
		spBox->addItem(tr("adverb"));
		spBox->addItem(tr("other"));
	submitButton=new QPushButton(tr("OK"), this);
	cancelButton=new QPushButton(tr("Cancel"), this);

	// add layout
	QGridLayout *lay1=new QGridLayout;
		lay1->addWidget(wordLabel, 0, 0);
		lay1->addWidget(wordEdit, 0, 1);
		lay1->addWidget(translationLabel, 1, 0);
		lay1->addWidget(translationEdit, 1, 1);
		lay1->addWidget(spLabel, 2, 0);
		lay1->addWidget(spBox, 2, 1);
		QHBoxLayout *lay2=new QHBoxLayout;
			lay2->addWidget(submitButton);
			lay2->addWidget(cancelButton);
	QVBoxLayout *mainLayout=new QVBoxLayout;
		mainLayout->addLayout(lay1);
		mainLayout->addLayout(lay2);
	setLayout(mainLayout);
	
	// set tabbing order
	QWidget::setTabOrder(wordEdit, translationEdit);
	QWidget::setTabOrder(translationEdit, spBox);
	QWidget::setTabOrder(spBox, submitButton);
	QWidget::setTabOrder(submitButton, cancelButton);

	// connect signals and slots
	connect(submitButton, SIGNAL(clicked()), this, SLOT(submitWord()));
	connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));

	// create shortcuts
	QShortcut *submitShortcut=new QShortcut(Qt::Key_Return, this);
	connect(submitShortcut, SIGNAL(activated()), this, SLOT(submitWord()));
	
	QShortcut *quitShortcut=new QShortcut(Qt::Key_Escape, this);
	connect(quitShortcut, SIGNAL(activated()), this, SLOT(cancel()));
	
	// set values
	if(entry) {
		wordEdit->setText(entry->word);
		translationEdit->setText(entry->translation);
		spBox->setCurrentIndex((int)entry->sp);
	}
}