int sql_prepOpen(const char *stmt, ...) { int n; struct OCURS *o; va_start(sqlargs, stmt); n = prepareCursor(stmt, false); if(n < 0) { SQLFreeHandle(SQL_HANDLE_STMT, hstmt); return n; } if(openfirst) goto done; o = findCursor(n); sql_open(n); if(rv_lastStatus) { o->flag = CURSOR_NONE; /* back to square 0 */ SQLFreeHandle(SQL_HANDLE_STMT, o->hstmt); o->hstmt = SQL_NULL_HSTMT; rv_numRets = 0; memset(rv_type, 0, sizeof (rv_type)); n = -1; } done: exclist = 0; return n; } /* sql_prepOpen */
/*! * Find a string within document. * * \param findString string to be found. * \param options find options. */ void TextEdit::findExpretion(const QString &findString, QTextDocument::FindFlags options) { /*! \todo fix the performance! */ //highlight(findString, options); QTextDocument *document = this->document(); QTextCursor findCursor(document); QTextCursor cursor(document); int pos = this->textCursor().position(); if (textCursor().hasSelection() && options == QTextDocument::FindBackward){ findCursor.setPosition(pos, QTextCursor::MoveAnchor); findCursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); } else { findCursor.setPosition(pos, QTextCursor::MoveAnchor); } if (textCursor().hasSelection() && options == QTextDocument::FindBackward){ cursor.setPosition(pos, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); } else { cursor.setPosition(pos, QTextCursor::MoveAnchor); } if ((m_lastFindString.contains(findString) || findString.contains(m_lastFindString)) && options != QTextDocument::FindBackward && textCursor().hasSelection() && findString != m_lastFindString){ findCursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); } //if (!(this->textCursor().hasSelection()) && (!findString.isEmpty() || !findString.isNull())) findCursor = document->find(findString, findCursor, options); if (findCursor.isNull()) { if (options == QTextDocument::FindBackward){ findCursor = cursor; findCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); } findCursor = document->find(findString, findCursor, options); } if (findCursor.isNull()) { this->setTextCursor(cursor); } else { this->setTextCursor(findCursor); //m_isFirstTime = false; } m_lastFindString = findString; }
void sql_close(int cid) { struct OCURS *o = findCursor(cid); if(o->flag < CURSOR_OPENED) errorPrint("2cannot close cursor %d, not yet opened", cid); stmt_text = "close"; debugStatement(); hstmt = o->hstmt; rc = SQLCloseCursor(hstmt); if(errorTrap(0)) return; o->flag = CURSOR_PREPARED; exclist = 0; } /* sql_close */
void sql_free(int cid) { struct OCURS *o = findCursor(cid); if(o->flag == CURSOR_OPENED) sql_close(cid); stmt_text = "free"; debugStatement(); hstmt = o->hstmt; rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt); o->flag = CURSOR_NONE; o->hstmt = SQL_NULL_HSTMT; rv_numRets = 0; memset(rv_type, 0, sizeof (rv_type)); /* free should never fail */ errorTrap(0); exclist = 0; } /* sql_free */
void sql_open(int cid) { short i; struct OCURS *o = findCursor(cid); if(o->flag == CURSOR_OPENED) return; /* already open */ if(!o->numrets) errorPrint("2cursor is being opened with no returns"); stmt_text = "open"; debugStatement(); hstmt = o->hstmt; rc = SQLExecute(hstmt); if(errorTrap(0)) return; o->flag = CURSOR_OPENED; o->rownum = 0; exclist = 0; } /* sql_open */
void ofEasyFingerCam::end() { findCursor(); // this has to happen after all drawing + findCursor() // but before camera.end() ofPushStyle(); ofSetColor(ofColor::black); ofSphere(cursor.x, cursor.y, cursor.z, 1); ofSphere(cursor.x-1, cursor.y, cursor.z, 1); ofSphere(cursor.x+1, cursor.y, cursor.z, 1); ofSphere(cursor.x, cursor.y-1, cursor.z, 1); ofSphere(cursor.x, cursor.y+1, cursor.z, 1); ofSphere(cursor.x, cursor.y, cursor.z-1, 1); ofSphere(cursor.x, cursor.y, cursor.z+1, 1); ofPopStyle(); //optimistically, we presume there's no stray push/pops ofPopMatrix(); ofCamera::end(); glDisable(GL_DEPTH_TEST); if(fingers.size()==3) { ofVec2f mouseP; mouseP.x = (fingers[0]->getX()*ofGetWidth()+ fingers[1]->getX()*ofGetWidth() +fingers[2]->getX()*ofGetWidth())/3; mouseP.y = (fingers[0]->getY()*ofGetHeight()+ fingers[1]->getY()*ofGetHeight()+ fingers[2]->getY()*ofGetHeight())/3; if (viewportRect.inside(mouseP)) { ofPushStyle(); ofFill(); ofSetColor(50, 10, 10); ofRect(mouseP.x + 20, mouseP.y + 20, 80, 40); stringstream ss; ss << "x: " << ofToString(cursor.x, 2) << endl; ss << "y: " << ofToString(cursor.y, 2) << endl; ss << "z: " << ofToString(cursor.z, 2) << endl; ofSetColor(255, 255, 255); ofDrawBitmapString(ss.str(), mouseP.x + 30, mouseP.y + 30); ofPopStyle(); } } }
//-------------------------- void ofxGrabCam::end() { //optimistically, we presume there's no stray push/pops ofPopMatrix(); if ((pickCursorFlag || !mouseDown || !mouseActions) && !mouseWForced) { findCursor(); pickCursorFlag = false; } // this has to happen after all drawing + findCursor() // but before camera.end() if (drawCursor) { ofPushStyle(); ofSetColor(0, 0, 0); ofSphere(mouseW.x, mouseW.y, mouseW.z, drawCursorSize); ofPopStyle(); } ofCamera::end(); glDisable(GL_DEPTH_TEST); if (drawCursor && viewportRect.inside(mouseP)) { ofPushStyle(); ofFill(); ofSetColor(50, 10, 10); ofRect(mouseP.x + 20, mouseP.y + 20, 80, 40); stringstream ss; ss << "x: " << ofToString(mouseW.x, 2) << endl; ss << "y: " << ofToString(mouseW.y, 2) << endl; ss << "z: " << ofToString(mouseW.z, 2) << endl; ofSetColor(255, 255, 255); ofDrawBitmapString(ss.str(), mouseP.x + 30, mouseP.y + 30); ofPopStyle(); } }
bool EditorBrowser::eventFilter( QObject *o, QEvent *e ) { if ( #if (QT_VERSION) < 0x030200 o->parent()->inherits("Editor") || o->inherits("Editor") #else ::qt_cast<Editor*>(o->parent()) || ::qt_cast<Editor*>(o) #endif ) { QMouseEvent *me; QKeyEvent *ke; switch ( e->type() ) { case QEvent::MouseMove: me = (QMouseEvent*)e; if ( ( me->state() & ControlButton ) == ControlButton ) { curEditor->viewport()->setCursor( pointingHandCursor ); QTextCursor c( curEditor->document() ); curEditor->placeCursor( curEditor->viewportToContents( me->pos() ), &c ); QTextCursor from, to; if ( oldHighlightedParag ) { oldHighlightedParag->setEndState( -1 ); oldHighlightedParag->format(); oldHighlightedParag = 0; } if ( findCursor( c, from, to ) && from.paragraph() == to.paragraph() ) { // avoid collision with other selections for ( int i = 0; i < curEditor->document()->numSelections(); ++i ) curEditor->document()->removeSelection( i ); from.paragraph()->setFormat( from.index(), to.index() - from.index() + 1, highlightedFormat, FALSE ); lastWord = from.paragraph()->string()->toString().mid( from.index(), to.index() - from.index() + 1 ); oldHighlightedParag = from.paragraph(); } else { lastWord = ""; } curEditor->repaintChanged(); return TRUE; } break; case QEvent::MouseButtonPress: { bool killEvent = !lastWord.isEmpty(); if ( !lastWord.isEmpty() ) showHelp( lastWord ); lastWord = ""; curEditor->viewport()->setCursor( ibeamCursor ); if ( oldHighlightedParag ) { oldHighlightedParag->setEndState( -1 ); oldHighlightedParag->format(); curEditor->repaintChanged(); oldHighlightedParag = 0; } if ( killEvent ) return TRUE; } break; case QEvent::KeyRelease: lastWord = ""; ke = (QKeyEvent*)e; if ( ke->key() == Key_Control ) { curEditor->viewport()->setCursor( ibeamCursor ); if ( oldHighlightedParag ) { oldHighlightedParag->setEndState( -1 ); oldHighlightedParag->format(); curEditor->repaintChanged(); oldHighlightedParag = 0; } } default: break; } } return FALSE; }
void TextRoom::spellCheck() { textEdit->document()->blockSignals(true); QString textVar = textEdit->document()->toPlainText(); textVar.replace(" ", "+"); textVar.replace("\n", "+"); textVar.replace("\t", "+"); textVar.replace("\r", "+"); textVar.replace(".", "+"); textVar.replace(",", "+"); textVar.replace(";", "+"); textVar.replace("!", "+"); textVar.replace("?", "+"); textVar.replace("(", "+"); textVar.replace(")", "+"); textVar.replace(":", "+"); textVar.replace("@", "+"); textVar.replace("&", "+"); textVar.replace("$", "+"); textVar.replace("%", "+"); textVar.replace("\"", "+"); QStringList wordList = textVar.split("+", QString::SkipEmptyParts); QString affFileName; QString dicFileName; #ifdef Q_OS_WIN32 affFileName = language+".aff"; dicFileName = language+".dic"; #elif defined(Q_OS_MACX) affFileName = resourcesDir+"/dict/"+language+".aff"; dicFileName = resourcesDir+"/dict/"+language+".dic"; #else affFileName = "/usr/share/hunspell/"+language+".aff"; dicFileName = "/usr/share/hunspell/"+language+".dic"; #endif pMS= new Hunspell(affFileName.toLocal8Bit(), dicFileName.toLocal8Bit()); QTextCharFormat highlightFormat; highlightFormat.setUnderlineColor(Qt::red); highlightFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline); QTextCharFormat defaultFormat; defaultFormat.setUnderlineStyle(QTextCharFormat::NoUnderline); if ( !isHighlighted ) isHighlighted = true; else { isHighlighted = false; } QTextCursor findCursor(textEdit->document()); findCursor.movePosition(QTextCursor::Start); foreach (QString word, wordList) { QTextCursor highlightCursor(textEdit->document()->find(word, findCursor)); findCursor.setPosition(highlightCursor.position()); findCursor.movePosition(QTextCursor::EndOfWord); QByteArray ba = word.toUtf8(); char * wordChar = ba.data(); int correct = pMS->spell(wordChar); if ( !correct && isHighlighted ) highlightCursor.mergeCharFormat(highlightFormat); else { QTextCursor notUnderlined(textEdit->document()->find(" ", findCursor)); notUnderlined.mergeCharFormat(defaultFormat); highlightCursor.mergeCharFormat(defaultFormat); } }
/* fetch row n from the open cursor. * Flag can be used to fetch first, last, next, or previous. */ static bool fetchInternal(int cid, long n, int flag) { long nextrow, lastrow; struct OCURS *o = findCursor(cid); everything_null = true; /* don't do the fetch if we're looking for row 0 absolute, * that just nulls out the return values */ if(flag == SQL_FD_FETCH_ABSOLUTE && !n) { o->rownum = 0; fetchZero: return false; } lastrow = nextrow = o->rownum; if(flag == SQL_FD_FETCH_ABSOLUTE) nextrow = n; if(flag == SQL_FD_FETCH_FIRST) nextrow = 1; if(isnotnull(lastrow)) { /* we haven't lost track yet */ if(flag == SQL_FD_FETCH_NEXT) ++nextrow; if(flag == SQL_FD_FETCH_PREV && nextrow) --nextrow; } if(flag == SQL_FD_FETCH_LAST) { nextrow = nullint; /* we just lost track */ } if(!nextrow) goto fetchZero; if(o->flag != CURSOR_OPENED) errorPrint("2cannot fetch from cursor %d, not yet opened", cid); /* The next line of code is very subtle. I use to declare all cursors as scroll cursors. It's a little inefficient, but who cares. Then I discovered you can't fetch blobs from scroll cursors. You can however fetch them from regular cursors, even with an order by clause. So cursors became non-scrolling by default. If the programmer chooses to fetch by absolute number, but he is really going in sequence, I turn them into fetch-next statements, so that the cursor need not be a scroll cursor. */ if(flag == SQL_FD_FETCH_ABSOLUTE) { if(isnull(nextrow)) errorPrint("2sql fetches absolute row using null index"); if(isnotnull(lastrow) && nextrow == lastrow + 1) flag = SQL_FD_FETCH_NEXT; } stmt_text = "fetch"; debugStatement(); hstmt = o->hstmt; rc = SQLFetchScroll(hstmt, (ushort) flag, nextrow); if(rc == SQL_NO_DATA) return false; if(errorTrap(0)) return false; o->rownum = nextrow; everything_null = false; return true; } /* fetchInternal */