Exemplo n.º 1
0
void ExpandingTextEdit::reallyEnsureCursorVisible()
{
    QObject *ancestor = parent();
    while (ancestor) {
        QScrollArea *scrollArea = qobject_cast<QScrollArea*>(ancestor);
        if (scrollArea &&
                (scrollArea->verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOff &&
                 scrollArea->horizontalScrollBarPolicy() != Qt::ScrollBarAlwaysOff)) {
            const QRect &r = cursorRect();
            const QPoint &c = mapTo(scrollArea->widget(), r.center());
            scrollArea->ensureVisible(c.x(), c.y());
            break;
        }
        ancestor = ancestor->parent();
    }
}
Exemplo n.º 2
0
void
WPiano::look_at_cursor(LookMode mode)
{
	QWidget *viewport_widget = qobject_cast<QWidget *>(parent());
	if (viewport_widget == NULL)
		return;
	QScrollArea *scroll = qobject_cast<QScrollArea *>(viewport_widget->parent());
	if (scroll == NULL)
		return;
	QScrollBar *hs = scroll->horizontalScrollBar();
	QScrollBar *vs = scroll->verticalScrollBar();

	bool pl = playing();
	QRect v = viewport();
	int x1, x2, y1, y2;
	x1 = time2x(cursorTime());
	x2 = pl ? x1 + 1 : time2x(cursorEndTime());
	y1 = level2y(cursor_level_ + 1);
	y2 = level2y(cursor_level_ - 1);

	switch (mode) {
	case PAGE:
		if (x1 < v.left())
			hs->setValue(scroll_snap(this, x2 - v.width(), true));
		if (x2 > v.right())
			hs->setValue(scroll_snap(this, x1 - 1));
		if (pl && y1 < v.top())
			vs->setValue(y2 - v.height() + level_height);
		if (pl && y2 > v.bottom())
			vs->setValue(y1 - level_height);
		break;
	case MINSCROLL:
		scroll->ensureVisible(x1, y1, level_height, level_height);
		scroll->ensureVisible(x2, y2, level_height, level_height);
		break;
	case CENTER:
		hs->setValue((x1 + x2 - v.width()) / 2);
		vs->setValue((y1 + y2 - v.height()) / 2);
		break;
	}
}
Exemplo n.º 3
0
QFrame* MainWindow::initFilesListFrame(QWidget *parent)
{
    QScrollArea *scrollFrame = new QScrollArea(parent);
    QFrame *frame = new QFrame(scrollFrame);

    QVBoxLayout *layout = new QVBoxLayout(frame);

    layout->setContentsMargins(0, 0, 0, 0);
    layout->setAlignment(Qt::AlignTop);
    layout->addWidget(filesListWidget);
    layout->addSpacing(25);
    layout->addWidget(initDragFrame(frame), 0, Qt::AlignHCenter);
    layout->addSpacing(25);

    scrollFrame->setWidget(frame);
    scrollFrame->setAcceptDrops(true);
    scrollFrame->installEventFilter(this);
    scrollFrame->setWidgetResizable(true);
    scrollFrame->setStyleSheet("QFrame {"
                               "border: none;"
                               "}"
                               "QScrollBar:vertical {"
                               "background: white;"
                               "width: 8px;"
                               "}"
                               "QScrollBar::handle:vertical {"
                               "background: grey;"
                               "min-height: 20px;"
                               "}"
                               "QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {"
                               "width: 0px;"
                               "height: 0px;"
                               "}");

    QFrame *mainFrame = new QFrame(parent);
    QVBoxLayout *mainLayout = new QVBoxLayout(mainFrame);
    FixedHeaderView *headerView = new FixedHeaderView(Qt::Horizontal, mainFrame);
    headerView->setModel(new FilesListModel(filesList, this));
    headerView->setStyleSheet("QHeaderView::section {"
                              "background: transparent;"
                              "border-style: none;"
                              "border-bottom: 1px solid rgb(207, 207, 207);"
                              "border-right: 1px solid rgb(207, 207, 207);"
                              "}"
                              "QWidget {"
                              "font: bold 11px \"Arial\";"
                              "color: rgb(58, 58, 58);"
                              "}");
    headerView->setFixedHeight(30);
    headerView->setMinimumSectionSize(150);
    headerView->resizeSection(0, 250);
    headerView->resizeSection(1, 400);
    headerView->setFixedHeight(30);

    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);
    mainLayout->addWidget(headerView);
    mainLayout->addWidget(scrollFrame);

    connect(headerView, SIGNAL(sectionResized(int,int,int)), filesListWidget, SLOT(resizeSection(int, int, int)));
    connect(headerView, SIGNAL(settingsButtonClicked()), SIGNAL(incrementSettingsClicked()));
    //connect(headerView, &FixedHeaderView::settingsButtonClicked, this, [=](){ initSettingsFrame(); });

    connect(filesListWidget, &FilesListWidget::fileSelected, this, [=](int index)
    {
        if (index >= 0)
        {
            QRect rect = filesListWidget->visualRect(filesListWidget->currentIndex());

            scrollFrame->ensureVisible(rect.x(), rect.y() + rect.height(), 0, rect.height());
        }
    });

    return mainFrame;
}