bool Buffer::find(const QString& findText, int flags, bool forward, bool wrap, bool *searchWrapped) { if (findText.isEmpty()) { return false; } if (searchWrapped) { *searchWrapped = false; } // Perform the search setSearchFlags(flags); setTargetStart(forward ? currentPos() : currentPos() - 1); setTargetEnd(forward ? length() : 0); QByteArray findArray = findText.toUtf8(); int findPos = searchInTarget(findArray.length(), findArray); // If the search should wrap, perform the search again. if (findPos == -1 && wrap) { setTargetStart(forward ? 0 : length()); setTargetEnd(forward ? currentPos() : currentPos() - 1); findPos = searchInTarget(findArray.length(), findArray); if (searchWrapped) { *searchWrapped = true; } } if (findPos != -1) { setSel(targetStart(), targetEnd()); scrollRange(targetStart(), targetEnd()); } return findPos != -1; }
void Listbox::SafeScrollPosition() { if (scrollPosition > 0) scrollPosition = 0; float scrollMax = scrollRange(); if (scrollPosition < -scrollMax) scrollPosition = -scrollMax; }
Rect Listbox::calcScrollBarRect() { Rect s = Rect(0,0,scrollButtonWidth,scrollButtonWidth*2); s.X = position.Width-scrollButtonWidth-3; //The scroll position is between 0 and scrollRange() so the //scroll bar must be between 0 and its range s.Y = 3+scrollButtonWidth+scrollBarRange()*-scrollPosition/scrollRange(); return s; }
void Listbox::drawScrollBar(GL2DProgram * shaders) { vec4 drawColor; Rect scrollBarLoc = calcScrollBarRect(); //Is the user dragging the bar? if ((lastScrollUpdate != 0) && (lastScrollPos.x >= 0)) { //The bar is being dragged now drawColor = highlightColor; //Determine the new scrollPosition scrollPosition = float scrollBarMovement = (lastScrollPos.y-lastMousePos.y)/scrollBarRange(); scrollPosition += scrollBarMovement*scrollRange(); lastScrollPos.y = lastMousePos.y; //Limit scroll position SafeScrollPosition(); //Since the scroll position moved, recalculate the bars position scrollBarLoc = calcScrollBarRect(); } else if (scrollBarLoc.InRect(lastMousePos)) { if (lastScrollUpdate != 0) { //Just started dragging drawColor = highlightColor; lastScrollPos = lastMousePos; } else drawColor = (highlightColor+barColor)/2.0; } else drawColor = barColor; //Finally draw the bar shaders->Model.PushMatrix(); shaders->Model.Translate(scrollBarLoc.X,scrollBarLoc.Y,0); scrollPosShape.color = drawColor; scrollPosShape.OverrideCalculatedSize(scrollBarLoc); scrollPosShape.Draw(shaders); shaders->Model.PopMatrix(); }