Exemplo n.º 1
0
CountrySelect::CountrySelect() : QWidget(App::wnd()),
	_result("none"),
    _filter(this, st::inpCountry, lang(lng_country_ph)), _scroll(this, st::scrollCountries), _list(&_scroll),
    _doneButton(this, lang(lng_country_done), st::btnSelectDone),
    _cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
    _innerLeft(0), _innerTop(0), _innerWidth(0), _innerHeight(0),
	a_alpha(0), a_bgAlpha(0), a_coord(st::countriesSlideShift), _shadow(st::boxShadow) {
	setGeometry(App::wnd()->rect());
	
	App::wnd()->topWidget(this);

	connect(App::wnd(), SIGNAL(resized(const QSize &)), this, SLOT(onParentResize(const QSize &)));
	connect(&_doneButton, SIGNAL(clicked()), this, SLOT(onCountryChoose()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onCountryCancel()));
	connect(&_scroll, SIGNAL(scrollFinished()), this, SLOT(onScrollFinished()));
	connect(&_scroll, SIGNAL(geometryChanged()), &_list, SLOT(onParentGeometryChanged()));
	connect(&_scroll, SIGNAL(scrolled()), &_list, SLOT(onUpdateSelected()));
	connect(&_list, SIGNAL(countrySelected()), this, SLOT(onCountryChoose()));
	connect(&_filter, SIGNAL(changed()), this, SLOT(onFilterUpdate()));
	connect(&_list, SIGNAL(mustScrollTo(int, int)), &_scroll, SLOT(scrollToY(int, int)));

	show();
	setFocus();
	_scroll.setWidget(&_list);
	_scroll.setFocusPolicy(Qt::NoFocus);

	prepareAnimation(0);
}
Exemplo n.º 2
0
void HorizontalSlider::scrollToIndex(int index) {
    if (index == curIndex) return;
    if (index > numberOfChildren() - 1) return;

    this->curIndex = index;

    QPropertyAnimation *anim = new QPropertyAnimation(container, "geometry");
    anim->setDuration(300);
    anim->setStartValue(container->geometry());
    int accuwidth = 0;
    for (int i = 0; i < index; ++ i) accuwidth += widths[i];
    accuwidth += widths[index] / 2 - this->width() / 2;
    QRect endval(-accuwidth,
                            container->geometry().y(),
                            container->geometry().width(),
                            container->geometry().height()
                          );
    anim->setEndValue(endval);
    anim->setEasingCurve(QEasingCurve::OutCubic);
    connect(anim, &QPropertyAnimation::finished, [=] () {
        emit scrollFinished();
    });
    anim->start(QAbstractAnimation::DeleteWhenStopped);
}