flaviotordini / minitube

YouTube app
https://flavio.tordini.org/minitube
GNU General Public License v3.0
365 stars 73 forks source link

Feature Request: Tooltips time for timeline #165

Open Kwaskoff opened 4 years ago

Kwaskoff commented 4 years ago

I need open an video at the goal time and when move mouse need touch every time for understand how much time Imgur

flaviotordini commented 4 years ago

Useful but will have to check what Qt widgets offer to implement this feature...

thewolfwillcome commented 3 years ago

Qt itself doesn't provide an public API to convert a mouse position on an QSlider to a value (to which it would jump when left mouse button is clicked) But SMPlayer has such tooltip support on its time slider

https://app.assembla.com/spaces/smplayer/subversion/source/HEAD/smplayer/trunk/src/timeslider.cpp

relevant code part:

bool TimeSlider::event(QEvent *event) {
    if (event->type() == QEvent::ToolTip) {
        QHelpEvent * help_event = static_cast<QHelpEvent *>(event);
        //qDebug() << "TimeSlider::event: x:" << help_event->x() << "maximum:" << maximum() << "width:" << width() << "total_time:" << total_time;
        QStyleOptionSlider opt;
        initStyleOption(&opt);
        const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
        const QPoint center = sliderRect.center() - sliderRect.topLeft();
        int value = pixelPosToRangeValue(help_event->x() - center.x());
        int range = maximum() - minimum();
        qreal time = value * total_time / range;
        //qDebug() << "TimeSlider::event: value:" << value << "range:" << range << "time:" << time;
        if (time >= 0 && time <= total_time) {
            QToolTip::showText(help_event->globalPos(), Helper::formatTime(time), this);
        } else {
            QToolTip::hideText();
            event->ignore();
        }
        return true;
    }
    return QWidget::event(event);
}