Beispiel #1
0
void KisSketchView::Private::resetDocumentPosition()
{
    view->zoomController()->setZoomMode(KoZoomMode::ZOOM_PAGE);

    QPoint pos;
    QScrollBar *sb = view->canvasControllerWidget()->horizontalScrollBar();

    pos.rx() = sb->minimum() + (sb->maximum() - sb->minimum()) / 2;

    sb = view->canvasControllerWidget()->verticalScrollBar();
    pos.ry() = sb->minimum() + (sb->maximum() - sb->minimum()) / 2;

    view->canvasControllerWidget()->setScrollBarValue(pos);
}
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;
}
/* since we cannot use translate() directly on the scene we hack on
 * the scroll bars (hidden) functionality */
void ProfileGraphicsView::scrollViewTo(const QPoint pos)
{
    if (!zoomLevel)
        return;
    QScrollBar *vs = verticalScrollBar();
    QScrollBar *hs = horizontalScrollBar();
    const qreal yRat = pos.y() / sceneRect().height();
    const qreal xRat = pos.x() / sceneRect().width();
    const int vMax = vs->maximum();
    const int hMax = hs->maximum();
    const int vMin = vs->minimum();
    const int hMin = hs->minimum();
    /* QScrollBar receives crazy negative values for minimum */
    vs->setValue(yRat * (vMax - vMin) + vMin * 0.9);
    hs->setValue(xRat * (hMax - hMin) + hMin * 0.9);
}
Beispiel #4
0
/*! \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);
}
Beispiel #5
0
void TabBar::scrollLeft()
{
    enter
    QScrollBar *bar = ui->scroll->horizontalScrollBar();
    int value = bar->value();
    bar->setValue(qMin(bar->minimum(), value - 10));
    updateScrollButtonsVisibility();
    leave
}
void AddMultipleDownloadsResultsPage::scrollBarValueChanged()
{
    if (m_finder && !m_finder->hasFinished() && !m_finder->isDownloading()) {
        QScrollBar *sb = m_view->verticalScrollBar();
        if (!sb || (sb->value() == sb->maximum()) || ((sb->maximum() + sb->minimum()) == 0)) {
            m_finder->start();
        }
    }
}
    void PianorollTrackView::ensureNoteVisible(
            VSQ_NS::tick_t tick, VSQ_NS::tick_t length, int noteNumber) {
        int left = controllerAdapter->getXFromTick(tick);
        int right = controllerAdapter->getXFromTick(tick + length);

        QRect visibleArea = ui->mainContent->getVisibleArea();
        QScrollBar *horizontalScrollBar = ui->mainContent->horizontalScrollBar();
        QScrollBar *verticalScrollBar = ui->mainContent->verticalScrollBar();
        int dx = 0;
        int newValue = verticalScrollBar->value();
        if (visibleArea.right() < right) {
            dx = ui->mainContent->width() - (right - left);
        } else if (left < visibleArea.left()) {
            dx = -ui->mainContent->width() + (right - left);
        }
        if (0 <= noteNumber) {
            int top = getYFromNoteNumber(noteNumber, trackHeight);
            int bottom = top + trackHeight;
            if (top < visibleArea.top() || visibleArea.bottom() < bottom) {
                newValue = (bottom + top) / 2 - visibleArea.height() / 2;
            }

            if (verticalScrollBar->value() != newValue) {
                if (newValue < verticalScrollBar->minimum()) {
                    verticalScrollBar->setValue(verticalScrollBar->minimum());
                } else if (verticalScrollBar->maximum() < newValue) {
                    verticalScrollBar->setValue(verticalScrollBar->maximum());
                } else {
                    verticalScrollBar->setValue(newValue);
                }
            }
        }
        if (dx) {
            int value = horizontalScrollBar->value() + dx;
            if (value < horizontalScrollBar->minimum()) {
                horizontalScrollBar->setValue(horizontalScrollBar->minimum());
            } else if (horizontalScrollBar->maximum() < value) {
                horizontalScrollBar->setValue(horizontalScrollBar->maximum());
            } else {
                horizontalScrollBar->setValue(value);
            }
        }
    }
Beispiel #8
0
void
TabsView::showTab( TabsItem *tab )
{
    if( tab )
    {
        QString tabText = tab->getTabData();
        if( tabText.length() > 0 )
        {
            tabText.replace( "\n", "<br></br>", Qt::CaseInsensitive );

            QFont tabFont( "monospace");
            tabFont.setStyleHint( QFont::Courier );
            tabFont.setStyleStrategy( QFont::PreferAntialias );
            tabFont.setWeight( QFont::Normal );
            tabFont.setPointSize( QFont().pointSize() );

            QFont headingFont( "sans-serif" );
            headingFont.setPointSize( tabFont.pointSize() + 2 );
            headingFont.setStyleHint( QFont::SansSerif );
            headingFont.setStyleStrategy( QFont::PreferAntialias );
            headingFont.setWeight( QFont::Black );
            QString linkColor = The::paletteHandler()->palette().link().color().name();
            QString textColor = The::paletteHandler()->palette().text().color().name();
            int headingWeight = 600;

            QString htmlData = "<html>";
                    htmlData += "<body style=\"font-family:'" + tabFont.family() + "';";
                    htmlData += "font-size:" + QString::number( tabFont.pointSize() ) + "pt;";
                    htmlData += "font-weight:" + QString::number( tabFont.weight() ) + ";";
                    htmlData += "color:" + textColor + ";\">";

                    // tab heading + tab source
                    htmlData += "<p><span style=\"font-family:'" + headingFont.family() + "';";
                    htmlData += "font-size:" + QString::number( headingFont.pointSize() ) + "pt;";
                    htmlData += "font-weight:" + QString::number( headingWeight ) + ";\">";
                    htmlData += tab->getTabTitle();
                    htmlData += " (" + i18n( "tab provided from: " ) + "<a href=\"" + tab->getTabUrl() + "\">";
                    htmlData += "<span style=\"text-decoration: underline; color:" + linkColor + ";\">";
                    htmlData += tab->getTabSource() + "</a>";
                    htmlData += ")</span></p>";

                    // tab data
                    htmlData += tabText + "</body></html>";

            // backup current scrollbar position
            QScrollBar *vbar = m_tabTextBrowser->nativeWidget()->verticalScrollBar();
            int scrollPosition = vbar->isVisible() ? vbar->value() : vbar->minimum();

            m_tabTextBrowser->nativeWidget()->setHtml( htmlData );

            // re-apply scrollbar position
            vbar->setSliderPosition( scrollPosition );
        }
    }
}
Beispiel #9
0
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 AddMultipleDownloadsResultsPage::finderHasResults(const QList<Download *> &newResults)
{
    if (m_finder && !newResults.isEmpty()) {
        updateSubTitle();
        if (!m_finder->hasFinished() && !m_finder->isDownloading()) {
            QScrollBar *sb = m_view->verticalScrollBar();
            if (!sb || ((sb->maximum() + sb->minimum()) == 0)) {
                m_finder->start();
            }
        }
    }
}
Beispiel #11
0
    void gestureEvent(QGestureEvent *event)
    {
        QPanGesture *pan = static_cast<QPanGesture *>(event->gesture(Qt::PanGesture));
        if (pan) {
            switch(pan->state()) {
            case Qt::GestureStarted: qDebug() << this << "Pan: started"; break;
            case Qt::GestureFinished: qDebug() << this << "Pan: finished"; break;
            case Qt::GestureCanceled: qDebug() << this << "Pan: canceled"; break;
            case Qt::GestureUpdated: break;
            default: qDebug() << this << "Pan: <unknown state>"; break;
            }

            if (pan->state() == Qt::GestureStarted)
                outside = false;
            event->ignore();
            event->ignore(pan);
            if (outside)
                return;

            const QPointF delta = pan->delta();
            const QPointF totalOffset = pan->offset();
            QScrollBar *vbar = verticalScrollBar();
            QScrollBar *hbar = horizontalScrollBar();

            if ((vbar->value() == vbar->minimum() && totalOffset.y() > 10) ||
                (vbar->value() == vbar->maximum() && totalOffset.y() < -10)) {
                outside = true;
                return;
            }
            if ((hbar->value() == hbar->minimum() && totalOffset.x() > 10) ||
                (hbar->value() == hbar->maximum() && totalOffset.x() < -10)) {
                outside = true;
                return;
            }
            vbar->setValue(vbar->value() - delta.y());
            hbar->setValue(hbar->value() - delta.x());
            event->accept(pan);
        }
    }
Beispiel #12
0
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();
}
 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 UnifyLabelMannual::patchNext()
{
    PatchPairView* v = pair_views_[current_patch_];
    v->setFrameShape(QFrame::NoFrame);
    if( current_patch_ < patches_.size() - 1 )++current_patch_;
    else current_patch_ = 0;
    v = pair_views_[current_patch_];
    v->setFrameShape(QFrame::Box);
    QScrollBar* bar = ui->scrollArea->horizontalScrollBar();
    int value;
    int min = bar->minimum();
    int max = bar->maximum();
    value = current_patch_ * ( max - min ) / ( patches_.size() - 1 );
    bar->setValue(value+min);
}
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 ());
}
Beispiel #16
0
void ReportViewWidget::ScrollArea::verticalScrollBarValueChanged(int value)
{
	//qfLogFuncFrame() << "value:" << value;
	//qfInfo() << value;
	static int old_val = -1;
	QScrollBar *sb = verticalScrollBar();
	if(value == old_val) {
		if(value == sb->maximum()) {
			emit showNextPage();
		}
		else if(value == sb->minimum()) {
			emit showPreviousPage();
		}
	}
	old_val = value;
}
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);
}
Beispiel #18
0
void TraitWidget::on_traitScroll_valueChanged(int value)
{
	QScrollBar *traitScroll = this->findChild<QScrollBar *>("traitScroll");
	QLineEdit *leftEdit = this->findChild<QLineEdit *>("leftEdit");
	QLineEdit *rightEdit = this->findChild<QLineEdit *>("rightEdit");
    int mid = (traitScroll->maximum() + traitScroll->minimum())/2;
	if (value == mid) {
		return;
	}
	std::string leftText = leftEdit->text().toStdString();
	long leftValue = 0;
	try {
		leftValue = boost::lexical_cast<long>(leftText);
	} catch (const boost::bad_lexical_cast& e) {
		
	}
	std::string rightText = rightEdit->text().toStdString();
	long rightValue = 0;
	try {
		rightValue = boost::lexical_cast<long>(rightText);
	} catch (const boost::bad_lexical_cast& e) {
		
	}
	if (value < mid) {
		++leftValue;
		if (rightValue > 0) {
			--rightValue;
		}
	} else {
		++rightValue;
		if (leftValue > 0) {
			--leftValue;
		}
	}
	std::ostringstream ssLeft;
	ssLeft<<leftValue;
	std::ostringstream ssRight;
	ssRight<<rightValue;
	leftEdit->setText(ssLeft.str().c_str());
	rightEdit->setText(ssRight.str().c_str());
	traitScroll->setValue(mid);
}
Beispiel #19
0
void TabBar::updateScrollButtonsVisibility()
{
    enter
    int contentWidth = ui->scrollContent->size().width();
    int viewportWidth = ui->scroll->viewport()->size().width();
    if (contentWidth>viewportWidth)
    {
        ui->cmdScrollLeft->show();
        ui->cmdScrollRight->show();

        QScrollBar *bar = ui->scroll->horizontalScrollBar();
        ui->cmdScrollLeft->setEnabled(bar->value() > bar->minimum());
        ui->cmdScrollRight->setEnabled(bar->value() < bar->maximum());
    }
    else
    {
        ui->cmdScrollLeft->hide();
        ui->cmdScrollRight->hide();
    }
    leave
}
Beispiel #20
0
bool ListView::event(QEvent *e)
{
	if (e->type() == QEvent::Wheel)
	{
		bool ret = QListView::event(e);

		QScrollBar *scrollBar = this->verticalScrollBar();
		if (scrollBar != NULL)
		{
			// eat the mouse wheel event if scrolling (return true)
			// otherwise it propogates, and scrolls the parent as well

			if (scrollBar->value() < scrollBar->maximum() && scrollBar->value() > scrollBar->minimum())
				return true;
		}

		return ret;
	}

	return QListView::event(e);
}
Beispiel #21
0
void tst_QAbstractScrollArea::task214488_layoutDirection()
{
    QScrollArea scrollArea;
    scrollArea.resize(200, 200);
    QWidget widget;
    widget.resize(600, 600);
    scrollArea.setWidget(&widget);
    scrollArea.show();
    QScrollBar *hbar = scrollArea.horizontalScrollBar();
    hbar->setValue((hbar->minimum() + hbar->maximum()) / 2);

    QFETCH(Qt::LayoutDirection, dir);
    QFETCH(Qt::Key, key);
    QFETCH(bool, lessThan);

    scrollArea.setLayoutDirection(dir);

    int refValue = hbar->value();
    qApp->sendEvent(&scrollArea, new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier));
    QVERIFY(lessThan ? (hbar->value() < refValue) : (hbar->value() > refValue));
}
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);
    }
}
Beispiel #23
0
void ReportViewWidget::ScrollArea::wheelEvent(QWheelEvent * ev)
{
	if(ev->orientation() == Qt::Vertical) {
		if(ev->modifiers() == Qt::ControlModifier) {
			int delta = ev->delta();
			emit zoomOnWheel(delta, ev->pos());
			ev->accept();
			return;
		}
		else {
			QScrollBar *sb = verticalScrollBar();
			if(sb) {
				if(sb->value() == sb->minimum() && ev->delta() > 0) {
					emit showPreviousPage();
					ev->accept();
					return;
				}
				if(sb->value() == sb->maximum() && ev->delta() < 0) {
					emit showNextPage();
					ev->accept();
					return;
				}
			}
			if(!sb || !sb->isVisible()) {
				/// pokud neni scroll bar, nemuzu se spolehnout na funkci verticalScrollBarValueChanged(), protoze value je pro oba smery == 0
				//qfInfo() << e->delta();
				if(ev->delta() < 0) {
					emit showNextPage();
				}
				else {
					emit showPreviousPage();
				}
				ev->accept();
				return;
			}
		}
	}
	QScrollArea::wheelEvent(ev);
}
Beispiel #24
0
void VMdEditor::makeBlockVisible(const QTextBlock &p_block)
{
    if (!p_block.isValid() || !p_block.isVisible()) {
        return;
    }

    QScrollBar *vbar = verticalScrollBar();
    if (!vbar || (vbar->minimum() == vbar->maximum())) {
        // No vertical scrollbar. No need to scroll.
        return;
    }

    int height = rect().height();
    QScrollBar *hbar = horizontalScrollBar();
    if (hbar && (hbar->minimum() != hbar->maximum())) {
        height -= hbar->height();
    }

    bool moved = false;

    QAbstractTextDocumentLayout *layout = document()->documentLayout();
    QRectF rect = layout->blockBoundingRect(p_block);
    int y = GETVISUALOFFSETY;
    int rectHeight = (int)rect.height();

    // Handle the case rectHeight >= height.
    if (rectHeight >= height) {
        if (y < 0) {
            // Need to scroll up.
            while (y + rectHeight < height && vbar->value() > vbar->minimum()) {
                moved = true;
                vbar->setValue(vbar->value() - vbar->singleStep());
                rect = layout->blockBoundingRect(p_block);
                rectHeight = (int)rect.height();
                y = GETVISUALOFFSETY;
            }
        } else if (y > 0) {
            // Need to scroll down.
            while (y > 0 && vbar->value() < vbar->maximum()) {
                moved = true;
                vbar->setValue(vbar->value() + vbar->singleStep());
                rect = layout->blockBoundingRect(p_block);
                rectHeight = (int)rect.height();
                y = GETVISUALOFFSETY;
            }

            if (y < 0) {
                // One step back.
                moved = true;
                vbar->setValue(vbar->value() - vbar->singleStep());
            }
        }

        if (moved) {
            qDebug() << "scroll to make huge block visible";
        }

        return;
    }

    while (y < 0 && vbar->value() > vbar->minimum()) {
        moved = true;
        vbar->setValue(vbar->value() - vbar->singleStep());
        rect = layout->blockBoundingRect(p_block);
        rectHeight = (int)rect.height();
        y = GETVISUALOFFSETY;
    }

    if (moved) {
        qDebug() << "scroll page down to make block visible";
        return;
    }

    while (y + rectHeight > height && vbar->value() < vbar->maximum()) {
        moved = true;
        vbar->setValue(vbar->value() + vbar->singleStep());
        rect = layout->blockBoundingRect(p_block);
        rectHeight = (int)rect.height();
        y = GETVISUALOFFSETY;
    }

    if (moved) {
        qDebug() << "scroll page up to make block visible";
    }
}
Beispiel #25
0
 /**
  * Resize the scroll bars and center the point clicked.
  *
  */
 void StatisticsTool::resizeScrollbars() {
   QScrollBar *hbar = p_visualScroll->horizontalScrollBar();
   QScrollBar *vbar = p_visualScroll->verticalScrollBar();
   hbar->setSliderPosition((hbar->maximum() + hbar->minimum()) / 2);
   vbar->setSliderPosition((vbar->maximum() + vbar->minimum()) / 2);
 }
void BCI2000Viewer::ChannelPagePrev()
{ QScrollBar* s = ui->verticalScrollBar;
  s->setSliderPosition( max( s->minimum(), s->sliderPosition() - s->pageStep() ) ); }
bool BCI2000Viewer::ChannelUp_Enabled()
{ QScrollBar* s = ui->verticalScrollBar;
  return s->isEnabled() && s->sliderPosition() > s->minimum(); }
Beispiel #28
0
void QUAboutDialog::resetText() {
	QScrollBar *bar = credits->verticalScrollBar();
	bar->setValue(bar->minimum());
	QTimer::singleShot(SCROLL_GAP, this, SLOT(scrollDown()));
}
Beispiel #29
0
// -------------------------------------------------------------------------
void ctkTreeComboBox::resizePopup()
{
  // copied from QComboBox.cpp
  Q_D(ctkTreeComboBox);

  QStyle * const style = this->style();
  QWidget* container = qobject_cast<QWidget*>(this->view()->parent());

  QStyleOptionComboBox opt;
  this->initStyleOption(&opt);
  QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
                                       QStyle::SC_ComboBoxListBoxPopup, this));
  QRect screen = QApplication::desktop()->availableGeometry(
    QApplication::desktop()->screenNumber(this));
  QPoint below = this->mapToGlobal(listRect.bottomLeft());
  int belowHeight = screen.bottom() - below.y();
  QPoint above = this->mapToGlobal(listRect.topLeft());
  int aboveHeight = above.y() - screen.y();
  bool boundToScreen = !this->window()->testAttribute(Qt::WA_DontShowOnScreen);

  const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
    {
    int listHeight = 0;
    int count = 0;
    QStack<QModelIndex> toCheck;
    toCheck.push(this->view()->rootIndex());
#ifndef QT_NO_TREEVIEW
    QTreeView *treeView = qobject_cast<QTreeView*>(this->view());
    if (treeView && treeView->header() && !treeView->header()->isHidden())
      listHeight += treeView->header()->height();
#endif
    while (!toCheck.isEmpty())
      {
      QModelIndex parent = toCheck.pop();
      for (int i = 0; i < this->model()->rowCount(parent); ++i)
        {
        QModelIndex idx = this->model()->index(i, this->modelColumn(), parent);
        if (!idx.isValid())
          {
          continue;
          }
        listHeight += this->view()->visualRect(idx).height(); /* + container->spacing() */;
#ifndef QT_NO_TREEVIEW
        if (this->model()->hasChildren(idx) && treeView && treeView->isExpanded(idx))
          {
          toCheck.push(idx);
          }
#endif
        ++count;
        if (!usePopup && count > this->maxVisibleItems())
          {
          toCheck.clear();
          break;
          }
        }
      }
    listRect.setHeight(listHeight);
    }
      {
      // add the spacing for the grid on the top and the bottom;
      int heightMargin = 0;//2*container->spacing();

      // add the frame of the container
      int marginTop, marginBottom;
      container->getContentsMargins(0, &marginTop, 0, &marginBottom);
      heightMargin += marginTop + marginBottom;

      //add the frame of the view
      this->view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
      //marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->top;
      //marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->bottom;
      heightMargin += marginTop + marginBottom;

      listRect.setHeight(listRect.height() + heightMargin);
      }

      // Add space for margin at top and bottom if the style wants it.
      if (usePopup)
        {
        listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
        }

      // Make sure the popup is wide enough to display its contents.
      if (usePopup)
        {
        const int diff = d->computeWidthHint() - this->width();
        if (diff > 0)
          {
          listRect.setWidth(listRect.width() + diff);
          }
        }

      //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
      container->layout()->activate();
      //takes account of the minimum/maximum size of the container
      listRect.setSize( listRect.size().expandedTo(container->minimumSize())
                        .boundedTo(container->maximumSize()));

      // make sure the widget fits on screen
      if (boundToScreen)
        {
        if (listRect.width() > screen.width() )
          {
          listRect.setWidth(screen.width());
          }
        if (this->mapToGlobal(listRect.bottomRight()).x() > screen.right())
          {
          below.setX(screen.x() + screen.width() - listRect.width());
          above.setX(screen.x() + screen.width() - listRect.width());
          }
        if (this->mapToGlobal(listRect.topLeft()).x() < screen.x() )
          {
          below.setX(screen.x());
          above.setX(screen.x());
          }
        }

      if (usePopup)
        {
        // Position horizontally.
        listRect.moveLeft(above.x());

#ifndef Q_WS_S60
        // Position vertically so the curently selected item lines up
        // with the combo box.
        const QRect currentItemRect = this->view()->visualRect(this->view()->currentIndex());
        const int offset = listRect.top() - currentItemRect.top();
        listRect.moveTop(above.y() + offset - listRect.top());
#endif

      // Clamp the listRect height and vertical position so we don't expand outside the
      // available screen geometry.This may override the vertical position, but it is more
      // important to show as much as possible of the popup.
        const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
#ifdef Q_WS_S60
        //popup needs to be stretched with screen minimum dimension
        listRect.setHeight(qMin(screen.height(), screen.width()));
#else
        listRect.setHeight(height);
#endif

        if (boundToScreen)
          {
          if (listRect.top() < screen.top())
            {
            listRect.moveTop(screen.top());
            }
          if (listRect.bottom() > screen.bottom())
            {
            listRect.moveBottom(screen.bottom());
            }
          }
#ifdef Q_WS_S60
        if (screen.width() < screen.height())
          {
          // in portait, menu should be positioned above softkeys
          listRect.moveBottom(screen.bottom());
          }
        else
          {
          TRect staConTopRect = TRect();
          AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
          listRect.setWidth(listRect.height());
          //by default popup is centered on screen in landscape
          listRect.moveCenter(screen.center());
          if (staConTopRect.IsEmpty())
            {
            // landscape without stacon, menu should be at the right
            (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
              listRect.setLeft(screen.left());
            }
          }
#endif
        }
      else if (!boundToScreen || listRect.height() <= belowHeight)
        {
        listRect.moveTopLeft(below);
        }
      else if (listRect.height() <= aboveHeight)
        {
        listRect.moveBottomLeft(above);
        }
      else if (belowHeight >= aboveHeight)
        {
        listRect.setHeight(belowHeight);
        listRect.moveTopLeft(below);
        }
      else
        {
        listRect.setHeight(aboveHeight);
        listRect.moveBottomLeft(above);
        }

#if QT_VERSION < QT_VERSION_CHECK(5,0,0) && !defined QT_NO_IM
      if (QInputContext *qic = this->inputContext())
        {
        qic->reset();
        }
#endif
      QScrollBar *sb = this->view()->horizontalScrollBar();
      Qt::ScrollBarPolicy policy = this->view()->horizontalScrollBarPolicy();
      bool needHorizontalScrollBar =
        (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn)
        && sb->minimum() < sb->maximum();
      if (needHorizontalScrollBar)
        {
        listRect.adjust(0, 0, 0, sb->height());
        }
      container->setGeometry(listRect);
}
Beispiel #30
0
void pTreeComboBox::calculPopupGeometry()
{
    if ( !mView ) {
        return;
    }
    
    QStyle * const style = this->style();

    // set current item and select it
    view()->selectionModel()->setCurrentIndex( mCurrentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
    QFrame* container = mFrame;
    QStyleOptionComboBox opt;
    initStyleOption( &opt );
    QRect listRect( style->subControlRect( QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this ) );
    QRect screen = popupGeometry( QApplication::desktop()->screenNumber( this ) );
    QPoint below = mapToGlobal( listRect.bottomLeft() );
    int belowHeight = screen.bottom() -below.y();
    QPoint above = mapToGlobal( listRect.topLeft() );
    int aboveHeight = above.y() -screen.y();
    bool boundToScreen = !window()->testAttribute( Qt::WA_DontShowOnScreen );
    
    listRect.moveTopLeft( mapToGlobal( rect().bottomLeft() ) );
    listRect.setSize( QSize( 
        qMax( qMax( view()->viewport()->width(), mFrame->width() ), width() )
        ,
        qMax( view()->viewport()->height(), mFrame->height() )
    ) );

    const bool usePopup = style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this );
    {
        int listHeight = 0;
        int count = 0;
        QStack<QModelIndex> toCheck;
        toCheck.push( view()->rootIndex() );
#ifndef QT_NO_TREEVIEW
        QTreeView* treeView = qobject_cast<QTreeView*>( view() );
        if ( treeView && treeView->header() && !treeView->header()->isHidden() )
            listHeight += treeView->header()->height();
#endif
        while ( !toCheck.isEmpty() ) {
            QModelIndex parent = toCheck.pop();
            for ( int i = 0; i < model()->rowCount( parent ); ++i ) {
                QModelIndex idx = model()->index( i, mModelColumn, parent );
                if ( !idx.isValid() )
                    continue;
                listHeight += view()->visualRect( idx ).height();
#ifndef QT_NO_TREEVIEW
                if ( model()->hasChildren( idx ) && treeView && treeView->isExpanded( idx ) )
                    toCheck.push( idx );
#endif
                ++count;
                if ( !usePopup && count > mMaxVisibleItems ) {
                    toCheck.clear();
                    break;
                }
            }
        }
        listRect.setHeight( listHeight );
    }

    {
        // add the spacing for the grid on the top and the bottom;
        int heightMargin = 0;

        // add the frame of the container
        int marginTop, marginBottom;
        container->getContentsMargins( 0, &marginTop, 0, &marginBottom );
        heightMargin += marginTop +marginBottom;

        //add the frame of the view
        view()->getContentsMargins( 0, &marginTop, 0, &marginBottom );
        marginTop += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top*/;
        marginBottom += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom*/;
        heightMargin += marginTop +marginBottom;

        listRect.setHeight( listRect.height() +heightMargin );
    }

    // Add space for margin at top and bottom if the style wants it.
    if ( usePopup )
        listRect.setHeight( listRect.height() +style->pixelMetric( QStyle::PM_MenuVMargin, &opt, this ) *2 );

    // Make sure the popup is wide enough to display its contents.
    if ( usePopup ) {
        const int diff = sizeHint().width() /*d->computeWidthHint()*/ -width();
        if ( diff > 0 )
            listRect.setWidth( listRect.width() +diff );
    }

    //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
    container->layout()->activate();
    //takes account of the minimum/maximum size of the container
    listRect.setSize( listRect.size().expandedTo(container->minimumSize())
                      .boundedTo(container->maximumSize()));

    // make sure the widget fits on screen
    if (boundToScreen) {
        if (listRect.width() > screen.width() )
            listRect.setWidth(screen.width());
        if (/*mapToGlobal(*/listRect/*.bottomRight())*/.x() > screen.right()) {
            below.setX(screen.x() + screen.width() - listRect.width());
            above.setX(screen.x() + screen.width() - listRect.width());
        }
        if (/*mapToGlobal(*/listRect/*.topLeft())*/.x() < screen.x() ) {
            below.setX(screen.x());
            above.setX(screen.x());
        }
    }

    if ( usePopup ) {
        // Position horizontally.
        listRect.moveLeft( above.x() );

        // Position vertically so the curently selected item lines up
        // with the combo box.
        /*const QRect currentItemRect = view()->visualRect( view()->currentIndex() );
        const int offset = listRect.top() -currentItemRect.top();
        listRect.moveTop( above.y() +offset -listRect.top() );*/

        // Clamp the listRect height and vertical position so we don't expand outside the
        // available screen geometry.This may override the vertical position, but it is more
        // important to show as much as possible of the popup.
        const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
        listRect.setHeight(height);
        if (boundToScreen) {
            if (listRect.top() < screen.top())
                listRect.moveTop(screen.top());
            if (listRect.bottom() > screen.bottom())
                listRect.moveBottom(screen.bottom());
        }
    } else if (!boundToScreen || listRect.height() <= belowHeight) {
        listRect.moveTopLeft(below);
    } else if (listRect.height() <= aboveHeight) {
        listRect.moveBottomLeft(above);
    } else if (belowHeight >= aboveHeight) {
        listRect.setHeight(belowHeight);
        listRect.moveTopLeft(below);
    } else {
        listRect.setHeight(aboveHeight);
        listRect.moveBottomLeft(above);
    }

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#ifndef QT_NO_IM
    if ( QInputContext *qic = inputContext() )
        qic->reset();
#endif
#endif
    QScrollBar* sb = view()->horizontalScrollBar();
    Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy();
    bool needHorizontalScrollBar = ( policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn ) && sb->minimum() < sb->maximum();
    if ( needHorizontalScrollBar ) {
        listRect.adjust( 0, 0, 0, sb->height() );
    }
    
    container->setGeometry( listRect );

#ifndef Q_WS_MAC
    const bool updatesEnabled = container->updatesEnabled();
#endif

#if defined( Q_WS_WIN ) && !defined( QT_NO_EFFECTS )
// FIXME Fix me ASAP
    /*bool scrollDown = ( listRect.topLeft() == below );
    if ( QApplication::isEffectEnabled( Qt::UI_AnimateCombo ) 
        && !style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ) && !window()->testAttribute( Qt::WA_DontShowOnScreen ) )
        qScrollEffect( container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150 );*/
#endif

// Don't disable updates on Mac OS X. Windows are displayed immediately on this platform,
// which means that the window will be visible before the call to container->show() returns.
// If updates are disabled at this point we'll miss our chance at painting the popup 
// menu before it's shown, causing flicker since the window then displays the standard gray 
// background.
#ifndef Q_WS_MAC
    container->setUpdatesEnabled( false );
#endif

    container->raise();
    container->show();
    //container->updateScrollers();
    view()->setFocus();

    view()->scrollTo( view()->currentIndex(), style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ) ? QAbstractItemView::PositionAtCenter : QAbstractItemView::EnsureVisible );

#ifndef Q_WS_MAC
    container->setUpdatesEnabled( updatesEnabled );
#endif

    container->update();
#ifdef QT_KEYPAD_NAVIGATION
    if ( QApplication::keypadNavigationEnabled() )
        view()->setEditFocus( true );
#endif
}