void QScrollDownTextBrowser::insertPlainText(const QString &text) { QScrollBar * b = verticalScrollBar(); if (linecount >= 2000 && autoClear) { keepLines(1000); moveCursor(QTextCursor::End); linecount = 1000; QTextBrowser::insertPlainText(text); b->setValue(b->maximum()); return; } int f = b->value(); int e = b->maximum(); moveCursor(QTextCursor::End); QTextBrowser::insertPlainText(text); if(b->value() != e) { b->setValue(f); } else { b->setValue(b->maximum()); moveCursor(QTextCursor::End); } linecount++; }
void Robot25DWindow::mouseMoveEvent(QMouseEvent *event) { QScrollBar * vert = verticalScrollBar(); QScrollBar * horiz = horizontalScrollBar(); bool scrollable = vert->maximum() + horiz->maximum() > 0; if (scrollable) { if (mousePressPosition_ != QPoint(-1, -1)) { setCursor(Qt::ClosedHandCursor); const QPoint diff = event->pos() - mousePressPosition_; const int dx = diff.x(); const int dy = diff.y(); if (dx != 0) { horiz->setValue(horiz->value() - dx); } if (dy != 0) { vert->setValue(vert->value() - dy); } mousePressPosition_ = event->pos(); } event->accept(); } else { setCursor(Qt::ArrowCursor); event->ignore(); } }
void Viewer::scaleImage() { std::stringstream msg; if (!graphView) { msg << "No image to scale"; } else { // scale image by amount on slider double factor = (100.0 - this->ui.horizontalSlider->value()) / 100.0; graphView->resize(factor * graphView->pixmap()->size()); QScrollBar* scrollBar = this->ui.scrollArea->horizontalScrollBar(); scrollBar->setValue(int(factor * scrollBar->value() + ((factor - 1) * scrollBar->pageStep()/2))); scrollBar = this->ui.scrollArea->verticalScrollBar(); scrollBar->setValue(int(factor * scrollBar->value() + ((factor - 1) * scrollBar->pageStep()/2))); this->ui.scrollArea->setBackgroundRole(QPalette::Dark); this->ui.scrollArea->setWidget(graphView); this->ui.scrollArea->show(); msg << "Image scaled to " << factor; } this->ui.statusbar->showMessage( tr(msg.str().c_str())); }
void Chat::insertMessage(const QString& alias, const QString& msg, const QColor& color) { Q_ASSERT(this->_options); int scrollBarValue = -1; QScrollBar* scrollBar = this->outputTextBrowser->verticalScrollBar(); if (scrollBar && scrollBar->value() != scrollBar->maximum()) scrollBarValue = scrollBar->value(); QString html("<p>"); html += QString("<span style='color:%1;'>%2 %3</span>").arg(color.name()).arg(getFormatedDateTime()).arg(alias); html.append(": </p>"); this->outputTextBrowser->moveCursor(QTextCursor::End); this->outputTextBrowser->insertHtml(html); replaceUrls(msg); this->outputTextBrowser->insertHtml("<br />"); if (this->_options->chatWidget->smileys()) insertSmileys(); if (scrollBar) { if (scrollBarValue != -1) scrollBar->setValue(scrollBarValue); else scrollBar->setValue(scrollBar->maximum()); } }
void ZTileManagerView::paintEvent(QPaintEvent *event) { QGraphicsView::paintEvent(event); if (swcVisible) { ZPainter viewPainter(this->viewport()); QTransform transform; float scale = getParentWindow()->getScaleFactor(); QScrollBar* vSc; vSc = this->verticalScrollBar(); QScrollBar* hSc; hSc = this->horizontalScrollBar(); transform.translate(-hSc->value(),-vSc->value()); transform.scale(scale, scale); viewPainter.setTransform(transform); QList<ZSwcTree*> swcList = getParentWindow()->getDocument()->getSwcList(); foreach (ZSwcTree *swc, swcList ) { if (swc != NULL) { swc->display(viewPainter,-1, ZStackObject::SOLID); } } } }
void PageViewBase::scrollByDelta(int dx, int dy) { QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); vbar->setValue(vbar->value() + dy); hbar->setValue(hbar->value() + dx); }
void ConsoleWindow::write(QString data, MessageLevel::Enum mode) { QScrollBar *bar = ui->text->verticalScrollBar(); int max_bar = bar->maximum(); int val_bar = bar->value(); if(isVisible()) { if (m_scroll_active) { m_scroll_active = (max_bar - val_bar) <= 1; } else { m_scroll_active = val_bar == max_bar; } } if (data.endsWith('\n')) data = data.left(data.length() - 1); QStringList paragraphs = data.split('\n'); for (QString ¶graph : paragraphs) { paragraph = paragraph.trimmed(); } QListIterator<QString> iter(paragraphs); if (mode == MessageLevel::MultiMC) while (iter.hasNext()) writeColor(iter.next(), "blue", 0); else if (mode == MessageLevel::Error) while (iter.hasNext()) writeColor(iter.next(), "red", 0); else if (mode == MessageLevel::Warning) while (iter.hasNext()) writeColor(iter.next(), "orange", 0); else if (mode == MessageLevel::Fatal) while (iter.hasNext()) writeColor(iter.next(), "red", "black"); else if (mode == MessageLevel::Debug) while (iter.hasNext()) writeColor(iter.next(), "green", 0); else if (mode == MessageLevel::PrePost) while (iter.hasNext()) writeColor(iter.next(), "grey", 0); // TODO: implement other MessageLevels else while (iter.hasNext()) writeColor(iter.next(), 0, 0); if(isVisible()) { if (m_scroll_active) { bar->setValue(bar->maximum()); } m_last_scroll_value = bar->value(); } }
void QUAboutDialog::scrollDown() { QScrollBar *bar = credits->verticalScrollBar(); if(bar->value() >= bar->maximum()) QTimer::singleShot(RESET_GAP, this, SLOT(resetText())); else { bar->setValue(bar->value() + SCROLL_STEP); QTimer::singleShot(SCROLL_GAP, this, SLOT(scrollDown())); } }
void FocusedTextEdit::wheelEvent(QWheelEvent *event) { // If we're already scrolled all the way to the top or bottom, we pass the // wheel event onto the basket. QScrollBar *sb = verticalScrollBar(); if ((event->delta() > 0 && sb->value() > sb->minimum()) || (event->delta() < 0 && sb->value() < sb->maximum())) KTextEdit::wheelEvent(event); //else // Global::bnpView->currentBasket()->graphicsView()->wheelEvent(event); }
void ImageViewerWidget::zoomInOut(const double f) { m_Scale *= f; m_Image->resize(m_Scale * m_Image->pixmap()->size()); QScrollBar *hbar = horizontalScrollBar(); QScrollBar *vbar = verticalScrollBar(); int hs = int(f * hbar->value() + ((f - 1) * hbar->pageStep() / 2)); int vs = int(f * vbar->value() + ((f - 1) * vbar->pageStep() / 2)); hbar->setValue(hs); vbar->setValue(vs); }
void Viewer::zoomInOut(const double f) { _scale *= f; _image->resize(_scale * _image->pixmap()->size()); QScrollBar *hbar = horizontalScrollBar(); QScrollBar *vbar = verticalScrollBar(); int hs = int(f * hbar->value() + ((f - 1) * hbar->pageStep() / 2)); int vs = int(f * vbar->value() + ((f - 1) * vbar->pageStep() / 2)); hbar->setValue(hs); vbar->setValue(vs); }
void QCustomTableWidget::scrollTo(int row, int column) { repaint(); int row_count = rowCount(), column_count = columnCount(); if (row > -1 && row < row_count) { int y = rowViewportPosition(row); QScrollBar *bar = verticalScrollBar(); if (y < 0) { bar->setValue(bar->value()+y); } else { int dy = y + rowHeight(row) - viewport()->height(); if (columnViewportPosition(column_count-1) + columnWidth(column_count-1) > viewport()->width()) { dy += horizontalScrollBar()->height() + 3; } if (dy > 0) { int value = bar->value() + dy; if (value > bar->maximum()) { bar->setMaximum(value); } bar->setValue(value); } } } if (column > -1 && column < column_count) { int x = columnViewportPosition(column); QScrollBar *bar = horizontalScrollBar(); if (x < 0) { bar->setValue(bar->value()+x); } else { int dx = x + columnWidth(column) - viewport()->width(); if (dx > 0) { int value = bar->value() + dx; if (value > bar->maximum()) { bar->setMaximum(value); } bar->setValue(value); } } } }
bool ChatWindow::eventFilter(QObject* watched, QEvent* e) { if(e->type() == QEvent::KeyPress) { QKeyEvent* ke = static_cast<QKeyEvent*>(e); bool scrollMod = (Preferences::self()->useMultiRowInputBox() ? false : (ke->modifiers() == Qt::ShiftModifier)); if(ke->key() == Qt::Key_Up && scrollMod) { if(textView) { QScrollBar* sbar = textView->verticalScrollBar(); sbar->setValue(sbar->value() - sbar->singleStep()); } return true; } else if(ke->key() == Qt::Key_Down && scrollMod) { if(textView) { QScrollBar* sbar = textView->verticalScrollBar(); sbar->setValue(sbar->value() + sbar->singleStep()); } return true; } else if(ke->modifiers() == Qt::NoModifier && ke->key() == Qt::Key_PageUp) { if(textView) { QScrollBar* sbar = textView->verticalScrollBar(); sbar->setValue(sbar->value() - sbar->pageStep()); } return true; } else if(ke->modifiers() == Qt::NoModifier && ke->key() == Qt::Key_PageDown) { if(textView) { QScrollBar* sbar = textView->verticalScrollBar(); sbar->setValue(sbar->value() + sbar->pageStep()); } return true; } } return QWidget::eventFilter(watched, e); }
void dmz::QtCanvasView::pan_direction (const int Dx, const int Dy) { QScrollBar *hBar = horizontalScrollBar (); QScrollBar *vBar = verticalScrollBar (); if (hBar && vBar) { hBar->setValue (hBar->value() - Dx); vBar->setValue (vBar->value() - Dy); } }
void PlayLabel::mouseReleaseEvent(QMouseEvent *event) { QScrollBar* pHBar = m_pSclView->horizontalScrollBar(); QScrollBar* pVBar = m_pSclView->verticalScrollBar(); //算法:先获取之前的滚动条值,再加上横向和竖向移动的距离(鼠标按下时的位置减去移动到的位置),就是滚动条应该到的位置 pHBar->setValue(pHBar->value() + (m_preX - event->pos().x())); pVBar->setValue(pVBar->value() + (m_preY - event->pos().y())); //清掉之前的鼠标按下时候的值 m_preX = 0; m_preY = 0; }
void SCgView::mouseMoveEvent (QMouseEvent * event) { if(event->buttons() & Qt::MidButton) { viewport()->setCursor(Qt::ClosedHandCursor); QScrollBar *hBar = horizontalScrollBar(); QScrollBar *vBar = verticalScrollBar(); QPoint delta = event->pos() - mPrevMousePos; hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x())); vBar->setValue(vBar->value() - delta.y()); mPrevMousePos = event->pos(); } QGraphicsView::mouseMoveEvent(event); }
void AnimationForm::slot_scrollWindow(QPoint move) { QScrollBar *p ; setCursor(QCursor(Qt::ClosedHandCursor)) ; p = ui->scrollArea_anime->horizontalScrollBar() ; if ( p->isEnabled() && !p->isHidden() ) { p->setValue(p->value()-move.x()); } p = ui->scrollArea_anime->verticalScrollBar() ; if ( p->isEnabled() && !p->isHidden() ) { p->setValue(p->value()-move.y()); } }
void EmacsKeysPlugin::genericVScroll(int direction) { if (!m_currentEditorWidget) return; m_currentState->beginOwnAction(); QScrollBar *verticalScrollBar = m_currentEditorWidget->verticalScrollBar(); const int value = verticalScrollBar->value(); const int halfPageStep = verticalScrollBar->pageStep() / 2; const int newValue = value + (direction > 0 ? halfPageStep : -halfPageStep); verticalScrollBar->setValue(newValue); // adjust cursor if it's out of screen const QRect viewportRect = m_currentEditorWidget->viewport()->rect(); const QTextCursor::MoveMode mode = m_currentState->mark() != -1 ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor ; const QTextCursor::MoveOperation op = m_currentEditorWidget->cursorRect().y() < 0 ? QTextCursor::Down : QTextCursor::Up ; QTextCursor cursor = m_currentEditorWidget->textCursor(); while (!m_currentEditorWidget->cursorRect(cursor).intersects(viewportRect)) { const int previousPosition = cursor.position(); cursor.movePosition(op, mode); if (previousPosition == cursor.position()) break; } m_currentEditorWidget->setTextCursor(cursor); m_currentState->endOwnAction(KeysActionOther); }
void PageViewBase::mouseMoveEvent(QMouseEvent *e) { if (lx >= 0) { const int dx = lx - e->x(); const int dy = ly - e->y(); QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); vbar->setValue(vbar->value() + dy); hbar->setValue(hbar->value() + dx); } lx = e->x(); ly = e->y(); }
void ConsoleWindow::toggleConsole() { QScrollBar *bar = ui->text->verticalScrollBar(); if (isVisible()) { if(!isActiveWindow()) { activateWindow(); return; } int max_bar = bar->maximum(); int val_bar = m_last_scroll_value = bar->value(); m_scroll_active = (max_bar - val_bar) <= 1; hide(); } else { show(); isTopLevel(); if (m_scroll_active) { bar->setValue(bar->maximum()); } else { bar->setValue(m_last_scroll_value); } } }
void OverviewView::mousePressEvent(QMouseEvent* e) { if (scene_->itemAt(mapToScene(e->pos()).x(), mapToScene(e->pos()).y()) && scene_->itemAt(mapToScene(e->pos()).x(), mapToScene(e->pos()).y())->boundingRect() == highlightBar_->boundingRect()) { barMovement_ = true; relativeBarPosition_ = e->pos().x(); } else if (e->button() == Qt::LeftButton) { QScrollBar* scroll = horizontalScrollBar(); if (e->x()+ scroll->value() >= 0 && e->x()+ scroll->value() <= AnimationEditor::getDuration()) { currentFrameGraphicsItem_->setPos(e->x() + scroll->value(), 20); slide_ = true; emit currentFrameChanged(e->x() + scroll->value()); } } QGraphicsView::mousePressEvent(e); }
void ThumbnailView::rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ) { QModelIndex index = currentIndex(); QScrollBar *vScroll = verticalScrollBar(); int startY = visualRect( index.sibling( start, index.column() ) ).top(); int endY = visualRect( index.sibling( end + 1, index.column() ) ).top(); int scrollValue = vScroll->value() - endY + startY; QListView::rowsAboutToBeRemoved( parent, start, end ); if( index.row() >= start ) { if( index.row() <= end && end + 1 < model()->rowCount( parent ) ) { selectionModel()->setCurrentIndex( model()->index( end + 1, index.column(), parent ), QItemSelectionModel::ClearAndSelect); } } if( startY <= 0 ) vScroll->setValue( scrollValue ); }
void RKProgressControlDialog::addOutput (const ROutput *output) { RK_TRACE (MISC); // scrolled all the way to the bottom? bool at_end = true; QScrollBar *bar = output_text->verticalScrollBar (); if (bar && (bar->value () < bar->maximum ())) at_end = false; if (output->type != last_output_type) { last_output_type = output->type; output_text->insertPlainText ("\n"); if (output->type == ROutput::Output) { output_text->setTextColor (Qt::black); } else { output_text->setTextColor (Qt::red); if (!isDetailsWidgetVisible ()) setDetailsWidgetVisible (true); error_indicator->show (); } } output_text->insertPlainText (output->output); // if previously at end, auto-scroll if (at_end && output_text->isVisible ()) scrollDown (); }
void TocDlg::moveUp(){ if(isPageUpdated) { on_actionUpdatePage_triggered(); isPageUpdated = false; } int cur_num = getCurrentItemPosFromBegin(m_docview->getToc(),m_ui->treeWidget->currentItem(), 0); QScrollBar * scrollBar = m_ui->treeWidget->verticalScrollBar(); // для отладки if((cur_num<=((curPage-1)*pageStrCount)+1) || (cur_num==1)){ // last page if((curPage-1)==0){ curPage=pageCount; scrollBar->setMaximum((pageCount-1) * pageStrCount); scrollBar->setValue(curPage*pageStrCount-pageStrCount); updateTitle(); ////break; return; } // previous page if(curPage-1>=1) { curPage-=1; scrollBar->setValue(scrollBar->value()-pageStrCount); updateTitle(); } } }
/*! \internal */ void QAbstractScrollAreaPrivate::replaceScrollBar(QScrollBar *scrollBar, Qt::Orientation orientation) { Q_Q(QAbstractScrollArea); QAbstractScrollAreaScrollBarContainer *container = scrollBarContainers[orientation]; bool horizontal = (orientation == Qt::Horizontal); QScrollBar *oldBar = horizontal ? hbar : vbar; if (horizontal) hbar = scrollBar; else vbar = scrollBar; scrollBar->setParent(container); container->scrollBar = scrollBar; container->layout->removeWidget(oldBar); container->layout->insertWidget(0, scrollBar); scrollBar->setVisible(oldBar->isVisibleTo(container)); scrollBar->setInvertedAppearance(oldBar->invertedAppearance()); scrollBar->setInvertedControls(oldBar->invertedControls()); scrollBar->setRange(oldBar->minimum(), oldBar->maximum()); scrollBar->setOrientation(oldBar->orientation()); scrollBar->setPageStep(oldBar->pageStep()); scrollBar->setSingleStep(oldBar->singleStep()); scrollBar->setSliderDown(oldBar->isSliderDown()); scrollBar->setSliderPosition(oldBar->sliderPosition()); scrollBar->setTracking(oldBar->hasTracking()); scrollBar->setValue(oldBar->value()); delete oldBar; QObject::connect(scrollBar, SIGNAL(valueChanged(int)), q, horizontal ? SLOT(_q_hslide(int)) : SLOT(_q_vslide(int))); QObject::connect(scrollBar, SIGNAL(rangeChanged(int,int)), q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection); }
void ImageView::scale(double scaleW, double scaleH) { if(_selectMode == SELECTMODE_NONE) { QPoint mousePos = mapToWidget(mapFromGlobal(QCursor::pos())); QPoint pixelPos = _imgWidget->mapToPixmap(mousePos); _imgWidget->setFixedSize(pixmap().width()*scaleW, pixmap().height()*scaleH); QPoint offset = _imgWidget->mapFromPixmap(pixelPos) - mousePos; QScrollBar* hsb = this->horizontalScrollBar(); QScrollBar* vsb = this->verticalScrollBar(); hsb->setValue(hsb->value() + offset.x()); vsb->setValue(vsb->value() + offset.y()); redrawSelect(); } }
void message_view::page_down() { QScrollBar* bar = verticalScrollBar(); if (bar) { bar->setValue(bar->value()+bar->pageStep()); } }
void FilmstripFrames::scroll(int dy) { QScrollBar *sb = m_scrollArea->verticalScrollBar(); int sbValue = sb->value(); int y = visibleRegion().boundingRect().bottom() + dy + 1; if (y < 0) y = 0; updateContentHeight(y); sb->setValue(sbValue + dy); }
/** * Moves the view with the mouse while hand scrolling. */ void MapView::mouseMoveEvent(QMouseEvent *event) { if (mHandScrolling) { QScrollBar *hBar = horizontalScrollBar(); QScrollBar *vBar = verticalScrollBar(); const QPoint d = event->globalPos() - mLastMousePos; hBar->setValue(hBar->value() + (isRightToLeft() ? d.x() : -d.x())); vBar->setValue(vBar->value() - d.y()); mLastMousePos = event->globalPos(); return; } QGraphicsView::mouseMoveEvent(event); mLastMousePos = event->globalPos(); mLastMouseScenePos = mapToScene(viewport()->mapFromGlobal(mLastMousePos)); }
void RosegardenScrollView::slotScrollHoriz(int hpos) { QScrollBar* hbar = getMainHorizontalScrollBar(); int currentContentYPos = contentsY(); /* Lots of performance hitting debug RG_DEBUG << "RosegardenScrollView::slotScrollHoriz: hpos is " << hpos << ", contentsX is " << contentsX() << ", visibleWidth is " << visibleWidth() << endl; */ if (hpos == 0) { // returning to zero // hbar->setValue(0); setContentsPos(0, currentContentYPos); //@@@ // possible replacement: ?? //this->widget()->move( 0, currentContentYPos ) } else if (hpos > (contentsX() + visibleWidth() * 1.6) || hpos < (contentsX() - visibleWidth() * 0.7)) { // miles off one side or the other // hbar->setValue(hpos - int(visibleWidth() * 0.4)); setContentsPos(hpos - int(visibleWidth() * 0.4), currentContentYPos); } else if (hpos > (contentsX() + visibleWidth() * 0.9)) { // moving off the right hand side of the view // hbar->setValue(hbar->value() + int(visibleWidth() * 0.6)); setContentsPos(hbar->value() + int(visibleWidth() * 0.6), currentContentYPos); } else if (hpos < (contentsX() + visibleWidth() * 0.1)) { // moving off the left // hbar->setValue(hbar->value() - int(visibleWidth() * 0.6)); setContentsPos(hbar->value() - int(visibleWidth() * 0.6), currentContentYPos); } }