void Autocorrect::finishedWord(QTextDocument *document, int cursorPosition) { if (!m_enabled->isChecked()) return; m_cursor = QTextCursor(document); selectWord(m_cursor, cursorPosition); m_word = m_cursor.selectedText(); if (m_word.isEmpty()) return; emit startMacro(i18n("Autocorrection")); bool done = autoFormatURLs(); if (!done) done = singleSpaces(); if (!done) done = autoBoldUnderline(); if (!done) done = autoFractions(); if (!done) advancedAutocorrect(); if (!done) uppercaseFirstCharOfSentence(); if (!done) fixTwoUppercaseChars(); if (!done) autoNumbering(); if (!done) superscriptAppendix(); if (!done) capitalizeWeekDays(); if (!done) autoFormatBulletList(); if (!done) replaceTypographicQuotes(); if (m_cursor.selectedText() != m_word) m_cursor.insertText(m_word); emit stopMacro(); }
void OcrEngine::slotImagePosition(const QPoint &p) { if (!m_trackingActive) return; // not interested // ImageCanvas did the coordinate conversion. // OcrResEdit does all of the rest of the work. emit selectWord(p); }
bool ZLTextSelectionModel::selectPrevWord() { ZLTextElementMap::const_iterator it = myView.myTextElementMap.begin(); for (; it != myView.myTextElementMap.end(); ++it) { if ((it->Kind == ZLTextElement::WORD_ELEMENT) && ((it->YEnd == myArea.YEnd) && (it->XStart == myArea.XStart))) { break; } } // Reverse search. if (it == myView.myTextElementMap.end()) { return false; } if (it == myView.myTextElementMap.begin()) { return false; } --it; clear(); return selectWord(*it, it->XStart, it->YEnd); }
bool ZLTextSelectionModel::selectNextWord() { ZLTextElementMap::const_iterator it = myView.myTextElementMap.begin(); for (; it != myView.myTextElementMap.end(); ++it) { /* if ((it->Kind == ZLTextElement::WORD_ELEMENT) && ((it->YEnd == myArea.YEnd) && (it->XStart > myArea.XStart) || (it->YEnd > myArea.YEnd))) */ if ((it->Kind == ZLTextElement::WORD_ELEMENT) && ((it->YEnd == myArea.YEnd) && (it->XStart == myArea.XStart))) { break; } } if (it == myView.myTextElementMap.end()) { return false; } ++it; if (it == myView.myTextElementMap.end()) { return false; } clear(); return selectWord(*it, it->XStart, it->YEnd); }
bool KonqCombo::eventFilter( QObject *o, QEvent *ev ) { // Handle Ctrl+Del/Backspace etc better than the Qt widget, which always // jumps to the next whitespace. QLineEdit *edit = lineEdit(); if ( o == edit ) { const int type = ev->type(); if (type == QEvent::KeyPress) { QKeyEvent *e = static_cast<QKeyEvent *>( ev ); KShortcut key( e->key() | e->modifiers() ); if ( key == KStandardShortcut::deleteWordBack() || key == KStandardShortcut::deleteWordForward() || ((e->modifiers() & Qt::ControlModifier) && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) ) ) { selectWord(e); e->accept(); return true; } } else if ( type == QEvent::MouseButtonDblClick ) { edit->selectAll(); return true; } } return KComboBox::eventFilter( o, ev ); }
bool ZLTextSelectionModel::selectPrevLineWord() { int y_dist = INT_MAX; ZLTextElementMap::const_iterator it = myView.myTextElementMap.begin(); for (; it != myView.myTextElementMap.end(); ++it) { if ((it->Kind == ZLTextElement::WORD_ELEMENT)) { if (myArea.YEnd > it->YEnd) { if (y_dist > myArea.YEnd - it->YEnd) { y_dist = myArea.YEnd - it->YEnd; } } else { break; } } } if (it != myView.myTextElementMap.begin()) { --it; } if (it == myView.myTextElementMap.end() || it == myView.myTextElementMap.begin()) { return false; } // Search again. int x_dist = INT_MAX; ZLTextElementMap::const_iterator pos = myView.myTextElementMap.end(); for (; it != myView.myTextElementMap.begin(); --it) { if (it->Kind == ZLTextElement::WORD_ELEMENT) { if (y_dist < myArea.YEnd - it->YEnd) { break; } if (x_dist > abs(it->XStart - myArea.XStart)) { pos = it; x_dist = abs(it->XStart - myArea.XStart); } } } if (pos == myView.myTextElementMap.end()) { return false; } clear(); return selectWord(*pos, pos->XStart, pos->YEnd); }
void Display::_itemSelected(QListBoxItem* item) { for(unsigned int i = 0;i < d_meanings.size();++i) { d_meanings[i]->_unselectListsExcept(item); } const char* word = item->text(); emit selectWord(word); }
bool ZLTextSelectionModel::selectLastWord() { clear(); ZLTextElementMap::const_iterator it = myView.myTextElementMap.begin(); if (it == myView.myTextElementMap.end()) { return false; } const ZLTextElementArea & area = myView.myTextElementMap.back(); return selectWord(area, area.XStart, area.YEnd); }
bool ZLTextSelectionModel::selectFirstWord() { clear(); ZLTextElementMap::const_iterator it = myView.myTextElementMap.begin(); if (it == myView.myTextElementMap.end()) { return false; } return selectWord(*it, it->XStart, it->YEnd); }
void Autocorrect::uppercaseFirstCharOfSentence() { if (! m_uppercaseFirstCharOfSentence) return; int startPos = m_cursor.selectionStart(); QTextBlock block = m_cursor.block(); m_cursor.setPosition(block.position()); m_cursor.setPosition(startPos, QTextCursor::KeepAnchor); int position = m_cursor.selectionEnd(); QString text = m_cursor.selectedText(); if (text.isEmpty()) // start of a paragraph m_word.replace(0, 1, m_word.at(0).toUpper()); else { QString::ConstIterator constIter = text.constEnd(); constIter--; while (constIter != text.constBegin()) { while (constIter != text.begin() && constIter->isSpace()) { constIter--; position--; } if (constIter != text.constBegin() && (*constIter == QChar('.') || *constIter == QChar('!') || *constIter == QChar('?'))) { constIter--; while (constIter != text.constBegin() && !(constIter->isLetter())) { position--; constIter--; } bool replace = true; selectWord(m_cursor, --position); QString prevWord = m_cursor.selectedText(); // search for exception if (m_upperCaseExceptions.contains(prevWord.trimmed())) replace = false; if (replace) m_word.replace(0, 1, m_word.at(0).toUpper()); break; } else break; } } m_cursor.setPosition(startPos); m_cursor.setPosition(startPos + m_word.length(), QTextCursor::KeepAnchor); }
MainWindow::MainWindow() { QMenu *fileMenu = new QMenu(tr("&File")); fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), QKeySequence(tr("Ctrl+O", "File|Open"))); QAction *quitAction = fileMenu->addAction(tr("E&xit"), this, SLOT(close())); quitAction->setShortcut(tr("Ctrl+Q")); QMenu *editMenu = new QMenu(tr("&Edit")); cutAction = editMenu->addAction(tr("Cu&t"), this, SLOT(cutSelection())); cutAction->setShortcut(tr("Ctrl+X")); cutAction->setEnabled(false); copyAction = editMenu->addAction(tr("&Copy"), this, SLOT(copySelection())); copyAction->setShortcut(tr("Ctrl+C")); copyAction->setEnabled(false); pasteAction = editMenu->addAction(tr("&Paste"), this, SLOT(pasteSelection())); pasteAction->setShortcut(tr("Ctrl+V")); pasteAction->setEnabled(false); QMenu *selectMenu = new QMenu(tr("&Select")); selectMenu->addAction(tr("&Word"), this, SLOT(selectWord())); selectMenu->addAction(tr("&Line"), this, SLOT(selectLine())); selectMenu->addAction(tr("&Block"), this, SLOT(selectBlock())); selectMenu->addAction(tr("&Frame"), this, SLOT(selectFrame())); menuBar()->addMenu(fileMenu); menuBar()->addMenu(editMenu); menuBar()->addMenu(selectMenu); editor = new QTextEdit(this); document = new QTextDocument(this); editor->setDocument(document); connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); setCentralWidget(editor); setWindowTitle(tr("Text Document Writer")); }
MainWindow::MainWindow() { QMenu *fileMenu = new QMenu(tr("&File")); fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence(tr("Ctrl+Q", "File|Exit"))); QMenu *editMenu = new QMenu(tr("&Edit")); cutAction = editMenu->addAction(tr("Cu&t"), this, SLOT(cutSelection()), QKeySequence(tr("Ctrl+X", "Edit|Cut"))); copyAction = editMenu->addAction(tr("&Copy"), this, SLOT(copySelection()), QKeySequence(tr("Ctrl+C", "Edit|Copy"))); pasteAction = editMenu->addAction(tr("&Paste"), this, SLOT(pasteSelection()), QKeySequence(tr("Ctrl+V", "Edit|Paste"))); QMenu *selectMenu = new QMenu(tr("&Select")); selectMenu->addAction(tr("&Word"), this, SLOT(selectWord())); selectMenu->addAction(tr("&Line"), this, SLOT(selectLine())); selectMenu->addAction(tr("&Block"), this, SLOT(selectBlock())); selectMenu->addAction(tr("&Frame"), this, SLOT(selectFrame())); QMenu *insertMenu = new QMenu(tr("&Insert")); insertMenu->addAction(tr("&List"), this, SLOT(insertList()), QKeySequence(tr("Ctrl+L", "Insert|List"))); menuBar()->addMenu(fileMenu); menuBar()->addMenu(editMenu); menuBar()->addMenu(selectMenu); menuBar()->addMenu(insertMenu); editor = new QTextEdit(this); document = new QTextDocument(this); editor->setDocument(document); connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); updateMenus(); setCentralWidget(editor); setWindowTitle(tr("Text Document Writer")); }
bool ZLTextSelectionModel::selectWord(int x, int y) { clear(); ZLTextElementMap::const_iterator it = myView.myTextElementMap.begin(); for (; it != myView.myTextElementMap.end(); ++it) { //if ((it->YStart > y) || ((it->YEnd > y) && (it->XEnd > x))) { //fixed bug: for fb2 ,it is special case to have up notation hyperlink if (((it->YStart > y) && it->XStart > x) || ((it->YEnd > y) && (it->XEnd > x))) { break; } } if (it == myView.myTextElementMap.end()) { return false; } return selectWord(*it, it->XStart, it->YEnd); }
bool KLSHistoryCombo::eventFilter( QObject *o, QEvent *ev ) { // Handle Ctrl+Del/Backspace etc better than the Qt widget, which always // jumps to the next whitespace. QLineEdit *edit = lineEdit(); if ( o == edit ) { int type = ev->type(); if ( type == QEvent::KeyPress ) { QKeyEvent *e = static_cast<QKeyEvent *>( ev ); if ( e->key() == Key_Return || e->key() == Key_Enter ) { //m_modifier = e->state(); return false; } int delete_word_back = KStdAccel::deleteWordBack().keyCodeQt(); int delete_word_forward = KStdAccel::deleteWordForward().keyCodeQt(); if ( KKey( e ) == KKey(delete_word_back) || KKey( e ) == KKey(delete_word_forward) || ((e->state() & ControlButton) && (e->key() == Key_Left || e->key() == Key_Right) ) ) { selectWord(e); e->accept(); return true; } } else if ( type == QEvent::MouseButtonDblClick ) { edit->selectAll(); return true; } } return KComboBox::eventFilter( o, ev ); }
Window::Window() { m_board = new Board(this); connect(m_board, &Board::finished, this, &Window::gameFinished); connect(m_board, &Board::started, this, &Window::gameStarted); connect(m_board, &Board::pauseChanged, this, &Window::gamePauseChanged); QWidget* contents = new QWidget(this); setCentralWidget(contents); View* view = new View(m_board, contents); m_scores = new ScoreBoard(this); m_definitions = new Definitions(m_board->words(), this); connect(m_board, &Board::wordAdded, m_definitions, &Definitions::addWord); connect(m_board, &Board::wordSolved, m_definitions, &Definitions::solveWord); connect(m_board, &Board::wordSelected, m_definitions, &Definitions::selectWord); connect(m_board, &Board::loading, m_definitions, &Definitions::clear); // Create success message m_success = new QLabel(contents); m_success->setAttribute(Qt::WA_TransparentForMouseEvents); QFont f = font(); f.setPointSize(24); QFontMetrics metrics(f); int width = metrics.width(tr("Success")); int height = metrics.height(); int ratio = devicePixelRatio(); QPixmap pixmap(QSize(width + height, height * 2) * ratio); pixmap.setDevicePixelRatio(ratio); pixmap.fill(QColor(0, 0, 0, 0)); { QPainter painter(&pixmap); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 200)); painter.setRenderHint(QPainter::Antialiasing, true); painter.drawRoundedRect(0, 0, width + height, height * 2, 10, 10); painter.setFont(f); painter.setPen(Qt::white); painter.setRenderHint(QPainter::TextAntialiasing, true); painter.drawText(height / 2, height / 2 + metrics.ascent(), tr("Success")); } m_success->setPixmap(pixmap); m_success->hide(); connect(m_board, &Board::loading, m_success, &QLabel::hide); // Create overlay background QLabel* overlay = new QLabel(this); f = font(); f.setPixelSize(20); metrics = QFontMetrics(f); width = std::max(metrics.width(tr("Loading")), metrics.width(tr("Paused"))); for (int i = 0; i < 10; ++i) { QString test(6, QChar(i + 48)); test.insert(4, QLatin1Char(':')); test.insert(2, QLatin1Char(':')); width = std::max(width, metrics.width(test)); } pixmap = QPixmap(QSize(width + 82, 32) * ratio); pixmap.setDevicePixelRatio(ratio); pixmap.fill(Qt::transparent); { QPainter painter(&pixmap); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 200)); painter.setRenderHint(QPainter::Antialiasing, true); painter.drawRoundedRect(0, -32, width + 82, 64, 5, 5); } overlay->setPixmap(pixmap); // Create overlay buttons m_definitions_button = new QLabel(overlay); m_definitions_button->setPixmap(QIcon(":/definitions.png").pixmap(24,24)); m_definitions_button->setCursor(Qt::PointingHandCursor); m_definitions_button->setToolTip(tr("Definitions")); m_definitions_button->installEventFilter(this); m_hint_button = new QLabel(overlay); m_hint_button->setPixmap(QIcon(":/hint.png").pixmap(24,24)); m_hint_button->setCursor(Qt::PointingHandCursor); m_hint_button->setToolTip(tr("Hint")); m_hint_button->setDisabled(true); m_hint_button->installEventFilter(this); connect(m_board, &Board::hintAvailable, m_hint_button, &QLabel::setEnabled); // Create clock m_clock = new Clock(overlay); m_clock->setDisabled(true); connect(m_clock, &Clock::togglePaused, m_board, &Board::togglePaused); connect(m_board, &Board::loading, m_clock, &Clock::setLoading); QHBoxLayout* overlay_layout = new QHBoxLayout(overlay); overlay_layout->setMargin(0); overlay_layout->setSpacing(0); overlay_layout->addSpacing(10); overlay_layout->addWidget(m_definitions_button); overlay_layout->addStretch(); overlay_layout->addWidget(m_clock, 0, Qt::AlignCenter); overlay_layout->addStretch(); overlay_layout->addWidget(m_hint_button); overlay_layout->addSpacing(10); // Lay out board QGridLayout* layout = new QGridLayout(contents); layout->setMargin(0); layout->setSpacing(0); layout->addWidget(view, 0, 0); layout->addWidget(m_success, 0, 0, Qt::AlignCenter); layout->addWidget(overlay, 0, 0, Qt::AlignHCenter | Qt::AlignTop); // Create menus QMenu* menu = menuBar()->addMenu(tr("&Game")); menu->addAction(tr("&New"), this, SLOT(newGame()), QKeySequence::New); menu->addAction(tr("&Choose..."), this, SLOT(chooseGame())); menu->addSeparator(); m_pause_action = menu->addAction(tr("&Pause"), m_board, SLOT(togglePaused()), tr("P")); m_pause_action->setDisabled(true); QAction* action = menu->addAction(tr("&Hint"), m_board, SLOT(showHint()), tr("H")); action->setDisabled(true); connect(m_board, &Board::hintAvailable, action, &QAction::setEnabled); menu->addAction(tr("D&efinitions"), m_definitions, SLOT(selectWord()), tr("D")); menu->addSeparator(); menu->addAction(tr("&Details"), this, SLOT(showDetails())); menu->addAction(tr("&Scores"), m_scores, SLOT(exec())); menu->addSeparator(); action = menu->addAction(tr("&Quit"), qApp, SLOT(quit()), QKeySequence::Quit); action->setMenuRole(QAction::QuitRole); menu = menuBar()->addMenu(tr("&Settings")); menu->addAction(tr("Application &Language..."), this, SLOT(setLocale())); menu = menuBar()->addMenu(tr("&Help")); action = menu->addAction(tr("&About"), this, SLOT(about())); action->setMenuRole(QAction::AboutRole); action = menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); action->setMenuRole(QAction::AboutQtRole); // Restore window geometry QSettings settings; resize(800, 600); restoreGeometry(settings.value("Geometry").toByteArray()); // Continue previous or start new game show(); if (settings.contains("Current/Words") && (settings.value("Current/Version" ).toInt() == 4)) { m_board->openGame(); } else { settings.remove("Current"); newGame(); } }
int main(int argc, char * argv[]) { Game game = {FALSE, 0}; char guesses[80]; int wordLength; int dashes; int incorrectGuesses; int maxTries; while(game.gameOver == FALSE) { char * word; char * ptr; wordLength = 0; dashes = 0; incorrectGuesses = 0; maxTries = 15; wordLength = selectWord(game.randomWord); /* Selecting random word */ word = game.randomWord; /* Assigning word to the randomWord */ ptr = strchr(word,'\n'); /* Getting rid of the new line */ *ptr = '\0'; for (dashes = 0; dashes < wordLength; dashes ++) /* For loop to print out the dashes */ { guesses[dashes] = DASH; } printWelcomeMessages( wordLength ); char input; while(game.gameOver == FALSE) { printf("Number of guesses: %i\n",incorrectGuesses); printf("Number of tries left: %i\n",(maxTries - incorrectGuesses)); printLettersGuessed( &game, game.totalGuesses ); printf( "Guess a letter: "); scanf( " %c", &input ); if (input == '\n' || input == ' ') { input = getchar(); } game.lettersGuessed[game.totalGuesses] = input; game.totalGuesses++; if (compareChar(input,word,guesses)) { printf("\n\nYou guessed '%c' correctly\n\n",input); } else { printf("\n\nSorry, '%c' is not a letter in the word\n\n",input); incorrectGuesses++; } printChar(guesses,wordLength); if (!gameOver(game.numRight,wordLength,guesses)) { system("clear"); printf("Congratulations! You have correctly guessed '%s'!\n\n",guesses); break; } if (incorrectGuesses == maxTries) { system("clear"); printf("GAME OVER!\nYou have failed to guess '%s'\n\n",word); break; } } newGame(game,guesses); } return 0; }