bool RecentBooksDlg::eventFilter(QObject *obj, QEvent *event) { if(event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); QString text; switch(keyEvent->key()) { case Qt::Key_Up: if(obj == m_ui->tableWidget) { QScrollBar * scrollBar = m_ui->tableWidget->verticalScrollBar(); int pageStrCount = scrollBar->pageStep(); int fullStrCount = scrollBar->maximum()-scrollBar->minimum()+pageStrCount; if(fullStrCount==pageStrCount) { pageCount = 1; //return; } if(pageStrCount==1) { scrollBar->setMaximum(fullStrCount*2); pageStrCount = scrollBar->pageStep(); } pageCount = ceil((double)fullStrCount/pageStrCount); if(((m_ui->tableWidget->currentRow()+1)/2 == 1) && (pageStrCount/2>1)){ } } break; return true; } } return false; }
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 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 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); }
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 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); }
/*! \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 message_view::page_down() { QScrollBar* bar = verticalScrollBar(); if (bar) { bar->setValue(bar->value()+bar->pageStep()); } }
void TocDlg::fillOpts() { QScrollBar * scrollBar = m_ui->treeWidget->verticalScrollBar(); pageStrCount = scrollBar->pageStep(); fullStrCount = scrollBar->maximum()-scrollBar->minimum()+pageStrCount; if(fullStrCount==pageStrCount) { pageCount = 1; return; } if(pageStrCount==1) { scrollBar->setMaximum(fullStrCount*2); pageStrCount = scrollBar->pageStep(); } pageCount = ceil((double)fullStrCount/pageStrCount); }
void ManuallyTaggerWindow::scrollBack() { QScrollBar * vert = ui->scrollArea->verticalScrollBar(); QScrollBar * horz = ui->scrollArea->horizontalScrollBar(); int last_horz = horz->value() - horz->pageStep() / 2; int last_vert = vert->value() - static_cast<int>(vert->pageStep() * 0.8); if(horz->value() == horz->minimum() && vert->value() == vert->minimum()) { back(); } else if(horz->value() == horz->minimum()) { horz->setValue(horz->maximum()); if(last_vert < vert->minimum()) { vert->setValue(vert->minimum()); } else { vert->setValue(last_vert); } } else if(last_horz < horz->minimum()) { horz->setValue(horz->minimum()); } else { horz->setValue(last_horz); } }
void ManuallyTaggerWindow::scroll() { QScrollBar * vert = ui->scrollArea->verticalScrollBar(); QScrollBar * horz = ui->scrollArea->horizontalScrollBar(); int next_horz = horz->value() + horz->pageStep() / 2; int next_vert = vert->value() + static_cast<int>(vert->pageStep() * 0.8); if(horz->value() == horz->maximum() && vert->value() == vert->maximum()) { next(); } else if(horz->value() == horz->maximum()) { horz->setValue(0); if(next_vert > vert->maximum()) { vert->setValue(vert->maximum()); } else { vert->setValue(next_vert); } } else if(next_horz > horz->maximum()) { horz->setValue(horz->maximum()); } else { horz->setValue(next_horz); } }
void ClockPhotoDialog::slotAdjustZoom(int percentage) { // Callback for when the zoom slider is adjusted. Scale the image to the new // value and adjust the scrollbars adjusted so that the center of the // display remains the same. // Remember what the old width was. float oldWidth = d->scrollArea->widget()->width(); // Convert the percentage to an absolute scale and scale the image. float absScale = (float)percentage / 100; d->imageLabel->resize(d->image->size() * absScale); // Calculate the size increase. float relScale = d->scrollArea->widget()->width() / oldWidth; // Adjust the scrollbars to the size increase. QScrollBar *barX = d->scrollArea->horizontalScrollBar(); QScrollBar *barY = d->scrollArea->verticalScrollBar(); barX->setValue(int(relScale * barX->value() + ((relScale - 1) * barX->pageStep()/2))); barY->setValue(int(relScale * barY->value() + ((relScale - 1) * barY->pageStep()/2))); }
TabsView::TabsView( QGraphicsWidget *parent ) : QGraphicsProxyWidget( parent ) { // tree view which holds the collection of fetched tabs m_treeView = new TabsTreeView( 0 ); connect( m_treeView, SIGNAL( clicked( const QModelIndex & ) ), this, SLOT( itemClicked( const QModelIndex & ) ) ); m_model = new QStandardItemModel(); m_model->setColumnCount( 1 ); m_treeView->setModel( m_model ); m_treeProxy = new QGraphicsProxyWidget( this ); m_treeProxy->setWidget( m_treeView ); // the textbrowser widget to display the tabs m_tabTextBrowser = new Plasma::TextBrowser( ); KTextBrowser *browserWidget = m_tabTextBrowser->nativeWidget(); browserWidget->setFrameShape( QFrame::StyledPanel ); browserWidget->setAttribute( Qt::WA_NoSystemBackground ); browserWidget->setOpenExternalLinks( true ); browserWidget->setUndoRedoEnabled( true ); browserWidget->setAutoFillBackground( false ); browserWidget->setWordWrapMode( QTextOption::NoWrap ); browserWidget->viewport()->setAutoFillBackground( true ); browserWidget->viewport()->setAttribute( Qt::WA_NoSystemBackground ); browserWidget->setTextInteractionFlags( Qt::TextBrowserInteraction | Qt::TextSelectableByKeyboard ); QScrollBar *treeScrollBar = m_treeView->verticalScrollBar(); m_scrollBar = new Plasma::ScrollBar( this ); m_scrollBar->setFocusPolicy( Qt::NoFocus ); // synchronize scrollbars connect( treeScrollBar, SIGNAL( rangeChanged( int, int ) ), SLOT( slotScrollBarRangeChanged( int, int ) ) ); connect( treeScrollBar, SIGNAL( valueChanged( int ) ), m_scrollBar, SLOT( setValue( int ) ) ); connect( m_scrollBar, SIGNAL( valueChanged( int ) ), treeScrollBar, SLOT( setValue( int ) ) ); m_scrollBar->setRange( treeScrollBar->minimum(), treeScrollBar->maximum() ); m_scrollBar->setPageStep( treeScrollBar->pageStep() ); m_scrollBar->setSingleStep( treeScrollBar->singleStep() ); // arrange textbrowser and treeview in a horizontal layout QGraphicsLinearLayout *layout = new QGraphicsLinearLayout( Qt::Horizontal ); layout->addItem( m_treeProxy ); layout->addItem( m_scrollBar ); layout->addItem( m_tabTextBrowser ); layout->setSpacing( 2 ); layout->setContentsMargins( 0, 0, 0, 0 ); setLayout( layout ); setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); updateScrollBarVisibility(); }
// code added 28.11.2011 int TocDlg::getCurrentItemPage() { if(isPageUpdated) { on_actionUpdatePage_triggered(); isPageUpdated = false; } QScrollBar * scrollBar = m_ui->treeWidget->verticalScrollBar(); pageStrCount = scrollBar->pageStep(); int page_num = 1; int iCurrentItemPos = getCurrentItemPosFromBegin(m_docview->getToc(),m_ui->treeWidget->currentItem(), 0); if(iCurrentItemPos>pageStrCount) page_num = ceil((double)iCurrentItemPos/pageStrCount); return page_num; }
void EditorWidgetBase::setDrawOffsetInternal(VSQ_NS::tick_t drawOffset) { static QMutex mutex; if (mutex.tryLock()) { int xScrollTo = -controllerAdapter->getXFromTick(drawOffset); QScrollBar *scrollBar = ui->mainContent->horizontalScrollBar(); int maxValue = scrollBar->maximum() + scrollBar->pageStep(); int minValue = scrollBar->minimum(); int contentWidth = static_cast<int>(ui->mainContent->getSceneWidth()); int value = static_cast<int>(minValue + (minValue - maxValue) * static_cast<double>(xScrollTo) / contentWidth); if (scrollBar->value() != value) scrollBar->setValue(value); mutex.unlock(); } }
void ClientTextEdit::scrollBarReleased() { // if(action == QAbstractSlider::SliderReleased) { QScrollBar* sb = verticalScrollBar(); int val = sb->value()+sb->pageStep(); int singleStep = sb->singleStep(); qDebug() << "* singleStep is:" << singleStep; //int docSize = sb->maximum() - sb->minimum() + sb->pageStep(); if(val%singleStep != 0) { qDebug() << "* val is:" << val; // here's what's left over int newVal = val/singleStep; int pixels = newVal*singleStep; qDebug() << "* newVal is:" << newVal; if(val-pixels < singleStep/2) { val = pixels; } else { val = pixels + singleStep; } } sb->setSliderPosition(val-sb->pageStep()); qDebug() << "* set slider position to" << val; // } }
void QConsolePrivate::updateScrollBar (void) { m_scrollBar->setMinimum (0); if (m_bufferSize.height () > m_consoleRect.height ()) m_scrollBar->setMaximum (m_bufferSize.height () - m_consoleRect.height ()); else m_scrollBar->setMaximum (0); m_scrollBar->setSingleStep (1); m_scrollBar->setPageStep (m_consoleRect.height ()); m_scrollBar->setValue (m_consoleRect.top ()); log ("Scrollbar parameters updated: %d/%d/%d/%d\n", m_scrollBar->minimum (), m_scrollBar->maximum (), m_scrollBar->singleStep (), m_scrollBar->pageStep ()); }
void Main::moveDefinicio(QEvent *event) { int type = event->type(); int step,pagestep; QScrollBar *bar; bar=ui.definicio->verticalScrollBar(); step=bar->singleStep(); pagestep=bar->pageStep(); if (type == QEvent::User+Auxiliar::KeyDown()) { bar->setSliderPosition(bar->sliderPosition()+step); } else if (type == QEvent::User+Auxiliar::KeyUp()) { bar->setSliderPosition(bar->sliderPosition()-step); } else if (type == QEvent::User+Auxiliar::KeyNextPage()) { bar->setSliderPosition(bar->sliderPosition()+pagestep); } else if (type == QEvent::User+Auxiliar::KeyPrevPage()) { bar->setSliderPosition(bar->sliderPosition()-pagestep); } }
void BCI2000Viewer::ChannelPageNext() { QScrollBar* s = ui->verticalScrollBar; s->setSliderPosition( min( s->maximum(), s->sliderPosition() + s->pageStep() ) ); }
void Viewer::updateGraphView(bool honorDisplayFlag) { try { // invalid QModelIndex signifies the root. GraphGenerator g(this->dataSource_->modelRoot(), gvOpt, honorDisplayFlag); // this creates dot file and png file g.draw(); std::stringstream msg; if (image != 0) { delete image; image = 0; } image = new QImage(gvOpt.getPng().c_str()); if (image != 0) { // setWidget calls delete on old graphview. no need to delete. graphView = new QLabel(); graphView->setBackgroundRole(QPalette::Base); graphView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); graphView->setScaledContents(true); QPixmap pixmap = QPixmap::fromImage(*image); // scale image by amount on slider double factor = (100.0 - this->ui.horizontalSlider->value()) / 100.0; graphView->setPixmap(pixmap); 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 << "Graph View Updated " << image->size().width() << "x" << image->size().height(); this->ui.statusbar->showMessage( tr(msg.str().c_str())); } else { msg << "Error loading image file"; this->ui.statusbar->showMessage( tr(msg.str().c_str())); } } catch (const char *&e) { this->ui.statusbar->showMessage(tr(e)); } }
void BCI2000Viewer::ChannelPagePrev() { QScrollBar* s = ui->verticalScrollBar; s->setSliderPosition( max( s->minimum(), s->sliderPosition() - s->pageStep() ) ); }