Exemple #1
0
int DAbstractSliderSpinBox::valueForX(int x, Qt::KeyboardModifiers modifiers) const
{
    const Q_D(DAbstractSliderSpinBox);

    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    QRect correctedProgRect;

    if (d->style == DAbstractSliderSpinBoxPrivate::STYLE_FUSION)
    {
        correctedProgRect = progressRect(spinOpts).adjusted(2, 0, -2, 0);
    }
    else if (d->style == DAbstractSliderSpinBoxPrivate::STYLE_BREEZE)
    {
        correctedProgRect = progressRect(spinOpts);
    }
    else
    {
        // Adjust for magic number in style code (margins)
        correctedProgRect = progressRect(spinOpts).adjusted(2, 2, -2, -2);
    }

    // Compute the distance of the progress bar, in pixel
    double leftDbl  = correctedProgRect.left();
    double xDbl     = x - leftDbl;

    // Compute the ration of the progress bar used, linearly (ignoring the exponent)
    double rightDbl = correctedProgRect.right();
    double minDbl   = d->minimum;
    double maxDbl   = d->maximum;

    double dValues  = (maxDbl - minDbl);
    double percent  = (xDbl / (rightDbl - leftDbl));

    // If SHIFT is pressed, movement should be slowed.
    if (modifiers & Qt::ShiftModifier)
    {
        percent = d->shiftPercent + (percent - d->shiftPercent) * d->slowFactor;
    }

    // Final value
    double realvalue = ((dValues * pow(percent, d->exponentRatio)) + minDbl);
    // If key CTRL is pressed, round to the closest step.
    if (modifiers & Qt::ControlModifier)
    {
        double fstep = d->fastSliderStep;

        if (modifiers & Qt::ShiftModifier)
        {
            fstep *= d->slowFactor;
        }

        realvalue = floor((realvalue+fstep / 2) / fstep) * fstep;
    }

    return int(realvalue);
}
QStyleOptionProgressBar KisAbstractSliderSpinBox::progressBarOptions() const
{
    const Q_D(KisAbstractSliderSpinBox);
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    //Create opts for drawing the progress portion
    QStyleOptionProgressBar progressOpts;
    progressOpts.initFrom(this);
    progressOpts.maximum = d->maximum;
    progressOpts.minimum = d->minimum;

    qreal minDbl = d->minimum;

    qreal dValues = (d->maximum - minDbl);

    progressOpts.progress = dValues * pow((d->value - minDbl) / dValues, 1 / d->exponentRatio) + minDbl;
    progressOpts.text = valueString() + d->suffix;
    progressOpts.textAlignment = Qt::AlignCenter;
    progressOpts.textVisible = !(d->edit->isVisible());

    //Change opts rect to be only the ComboBox's text area
    progressOpts.rect = progressRect(spinOpts);

    return progressOpts;
}
IntRect RenderThemeGtk::calculateProgressRect(const RenderObject& renderObject, const IntRect& fullBarRect)
{
    IntRect progressRect(fullBarRect);
    const RenderProgress* renderProgress = toRenderProgress(&renderObject);
    if (renderProgress->isDeterminate()) {
        int progressWidth = progressRect.width() * renderProgress->position();
        if (renderObject.style().direction() == RTL)
            progressRect.setX(progressRect.x() + progressRect.width() - progressWidth);
        progressRect.setWidth(progressWidth);
        return progressRect;
    }

    double animationProgress = renderProgress->animationProgress();

    // Never let the progress rect shrink smaller than 2 pixels.
    int newWidth = std::max(2, progressRect.width() / progressActivityBlocks);
    int movableWidth = progressRect.width() - newWidth;
    progressRect.setWidth(newWidth);

    // We want the first 0.5 units of the animation progress to represent the
    // forward motion and the second 0.5 units to represent the backward motion,
    // thus we multiply by two here to get the full sweep of the progress bar with
    // each direction.
    if (animationProgress < 0.5)
        progressRect.setX(progressRect.x() + (animationProgress * 2 * movableWidth));
    else
        progressRect.setX(progressRect.x() + ((1.0 - animationProgress) * 2 * movableWidth));
    return progressRect;
}
Exemple #4
0
void UrlLineEdit::paintEvent(QPaintEvent *event)
{
    QPalette p = palette();
    if (m_webView && m_webView->url().scheme() == QLatin1String("https")) {
        QColor lightYellow(248, 248, 210);
        p.setBrush(QPalette::Base, generateGradient(lightYellow));
    } else {
        p.setBrush(QPalette::Base, m_defaultBaseColor);
    }
    setPalette(p);
    ExLineEdit::paintEvent(event);

    QPainter painter(this);
    QStyleOptionFrame panel;
    initStyleOption(&panel);
    QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
    if (m_webView && !hasFocus()) {
        int progress = m_webView->progress();
        QColor loadingColor = QColor(116, 192, 250);
        painter.setBrush(generateGradient(loadingColor));
        painter.setPen(Qt::transparent);
        int mid = backgroundRect.width() / 100.0f * progress;
        QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height());
        painter.drawRect(progressRect);
    }
}
Exemple #5
0
void DAbstractSliderSpinBox::mouseReleaseEvent(QMouseEvent* e)
{
    Q_D(DAbstractSliderSpinBox);

    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    d->isDragging = false;

    // Step up/down for buttons
    // Emulating mouse grab too
    if (upButtonRect(spinOpts).contains(e->pos()) && d->upButtonDown)
    {
        setInternalValue(d->value + d->singleStep);
    }
    else if (downButtonRect(spinOpts).contains(e->pos()) && d->downButtonDown)
    {
        setInternalValue(d->value - d->singleStep);
    }
    else if (progressRect(spinOpts).contains(e->pos()) &&
             !(d->edit->isVisible())                      &&
             !(d->upButtonDown || d->downButtonDown))
    {
        // Snap to percentage for progress area
        setInternalValue(valueForX(e->pos().x(),e->modifiers()));
    }
    else
    {
        // Confirm the last known value, since we might be ignoring move events
        setInternalValue(d->value);
    }

    d->upButtonDown   = false;
    d->downButtonDown = false;
    update();
}
void AddressBar::paintEvent(QPaintEvent * event)
{
    QPainter p(this);
    QStyleOptionFrameV2 panel;
    initStyleOption(&panel);
    style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);

    if(hasFocus() || progress == 100) QLineEdit::paintEvent(event);

    QPainter painter(this);
    QStyleOptionFrameV2 lenap;
    initStyleOption(&lenap);
    QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &lenap, this);

    if(!hasFocus() && progress < 100)
    {
        QColor loadingColor = QColor(116, 192, 250);
        painter.setBrush(generateGradient(loadingColor));
        painter.setPen(Qt::transparent);
        int mid = backgroundRect.width() / 100 * progress;
        QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height());
        painter.drawRect(progressRect);

        painter.setPen(Qt::SolidLine);
        painter.drawText(backgroundRect,Qt::AlignLeft|Qt::AlignVCenter, " " + this->text());
    }
}
void StylePainterMobile::drawProgress(const QRect& rect, double progress, bool leftToRight, bool animated, bool vertical) const
{
    const int horizontalBorder = (vertical ? rect.width() / 4 : 0);
    const int verticalBorder = (vertical ? 0 : rect.height() / 4);
    const QRect targetRect = rect.adjusted(horizontalBorder, verticalBorder, -horizontalBorder, -verticalBorder);

    QPixmap result;
    QSize imageSize = sizeForPainterScale(targetRect);
    if (vertical)
        qSwap(imageSize.rheight(), imageSize.rwidth());
    KeyIdentifier id;
    id.type = KeyIdentifier::Progress;
    id.width = imageSize.width();
    id.height = imageSize.height();
    id.trait1 = animated;
    id.trait2 = (!animated && !leftToRight);
    id.trait3 = progress * 100;
    if (!findCachedControl(id, &result)) {
        if (imageSize.isNull())
            return;
        result = QPixmap(imageSize);
        result.fill(Qt::transparent);
        QPainter painter(&result);
        painter.setRenderHint(QPainter::Antialiasing);
        QRect progressRect(QPoint(0, 0), imageSize);
        qreal radius = radiusFactor * progressRect.height();
        painter.setBrush(Qt::NoBrush);
        painter.setPen(borderPen());
        progressRect.adjust(1, 1, -1, -1);
        painter.drawRoundedRect(progressRect, radius, radius);
        progressRect.adjust(1, 1, -1, -1);
        if (animated) {
            const int right = progressRect.right();
            const int startPos = right * (1 - progressBarChunkPercentage) * 2 * fabs(progress - 0.5);
            progressRect.setWidth(progressBarChunkPercentage * right);
            progressRect.moveLeft(startPos);
        } else {
            progressRect.setWidth(progress * progressRect.width());
            if (!leftToRight)
                progressRect.moveRight(imageSize.width() - 2);
        }
        if (progressRect.width() > 0) {
            QLinearGradient gradient;
            gradient.setStart(progressRect.bottomLeft());
            gradient.setFinalStop(progressRect.topLeft());
            gradient.setColorAt(0.0, highlightColor);
            gradient.setColorAt(1.0, highlightColor.lighter());
            painter.setBrush(gradient);
            painter.setPen(Qt::NoPen);
            radius = radiusFactor * progressRect.height();
            painter.drawRoundedRect(progressRect, radius, radius);
        }
        insertIntoCache(id, result);
    }
    QTransform transform;
    transform.rotate(-90);
    painter->drawPixmap(targetRect, vertical ? result.transformed(transform) : result);
}
    void FalagardProgressBarEx::render()
    {
        const StateImagery* imagery;

        // get WidgetLookFeel for the assigned look.
        const WidgetLookFeel& wlf = getLookNFeel();
        // try and get imagery for our current state
        imagery = &wlf.getStateImagery(d_window->isDisabled() ? "Disabled" : "Enabled");
        // peform the rendering operation.
        imagery->render(*d_window);

        // get imagery for actual progress rendering
        imagery = &wlf.getStateImagery(d_window->isDisabled() ? "DisabledProgress" : "EnabledProgress");

        // get target rect for this imagery
        Rect progressRect(wlf.getNamedArea("ProgressArea").getArea().getPixelRect(*d_window));

        // calculate a clipper according to the current progress.
        Rect progressClipper(progressRect);

        ProgressBar* w = (ProgressBar*)d_window;
        if (d_vertical)
        {
            float height = PixelAligned(progressClipper.getHeight() * w->getProgress());

            if (d_reversed)
            {
                progressClipper.setHeight(height);
            }
            else
            {
                progressClipper.d_top = progressClipper.d_bottom - height;
            }
        }
        else
        {
            float width = PixelAligned(progressClipper.getWidth() * w->getProgress());

            if (d_reversed)
            {
                progressClipper.d_left = progressClipper.d_right - width;
            }
            else
            {
                progressClipper.setWidth(width);
            }
        }

        // peform the rendering operation.
        imagery->render(*d_window, progressRect, 0, &progressClipper);

        // perform the text rendering operation
        imagery = &wlf.getStateImagery("Label");
        imagery->render(*d_window);
    }
void KisAbstractSliderSpinBox::showEdit()
{
    Q_D(KisAbstractSliderSpinBox);
    if (d->edit->isVisible()) return;
    d->edit->setGeometry(progressRect(spinBoxOptions()));
    d->edit->setText(valueString());
    d->edit->selectAll();
    d->edit->show();
    d->edit->setFocus(Qt::OtherFocusReason);
    update();
}
Exemple #10
0
void DAbstractSliderSpinBox::showEdit()
{
    Q_D(DAbstractSliderSpinBox);

    if (d->edit->isVisible())
        return;

    if (d->style == DAbstractSliderSpinBoxPrivate::STYLE_PLASTIQUE)
    {
        d->edit->setGeometry(progressRect(spinBoxOptions()).adjusted(0, 0, -2, 0));
    }
    else
    {
        d->edit->setGeometry(progressRect(spinBoxOptions()));
    }

    d->edit->setText(valueString());
    d->edit->selectAll();
    d->edit->show();
    d->edit->setFocus(Qt::OtherFocusReason);
    update();
}
int KisAbstractSliderSpinBox::valueForX(int x) const
{
    const Q_D(KisAbstractSliderSpinBox);
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    //Adjust for magic number in style code (margins)
    QRect correctedProgRect = progressRect(spinOpts).adjusted(2, 2, -2, -2);

    qreal leftDbl = correctedProgRect.left();
    qreal xDbl = x - leftDbl;
    qreal rightDbl = correctedProgRect.right();
    qreal minDbl = d->minimum;
    qreal maxDbl = d->maximum;

    qreal dValues = (maxDbl - minDbl);
    qreal percent = (xDbl / (rightDbl - leftDbl));

    return ((dValues * pow(percent, d->exponentRatio)) + minDbl);
}
Exemple #12
0
double SliderDoubleSpinBoxPrivate::valueForX(int x) const
{
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    // adjust for border used in the QStyles (FIXME: probably not exact)
    QRect correctedProgRect = progressRect(spinOpts).adjusted(2, 2, -2, -2);

    const double left = correctedProgRect.left();
    const double right = correctedProgRect.right();
    const double val = qMax(0.0 , x - left);

    const double range = q->maximum() - q->minimum();
    double percent = val / (right - left);

    if (q->layoutDirection() == Qt::RightToLeft) {
        percent = 1 - percent;
    }

    return q->minimum() + percent * (range);
}
bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
    GtkWidget* widget = gtkProgressBar();
    gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style().direction()));

    WidgetRenderingContext widgetContext(paintInfo.context, rect);
    IntRect fullProgressBarRect(IntPoint(), rect.size());
    widgetContext.gtkPaintBox(fullProgressBarRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "trough");

    GtkStyle* style = gtk_widget_get_style(widget);
    IntRect progressRect(fullProgressBarRect);
    progressRect.inflateX(-style->xthickness);
    progressRect.inflateY(-style->ythickness);
    progressRect = RenderThemeGtk::calculateProgressRect(renderObject, progressRect);

    if (!progressRect.isEmpty())
        widgetContext.gtkPaintBox(progressRect, widget, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, "bar");

    return false;
}
void KisAbstractSliderSpinBox::paintEvent(QPaintEvent* e)
{
    Q_D(KisAbstractSliderSpinBox);
    Q_UNUSED(e)

    QPainter painter(this);

    //Create options to draw spin box parts
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    //Draw "SpinBox".Clip off the area of the lineEdit to avoid double
    //borders being drawn
    painter.save();
    painter.setClipping(true);
    QRect eraseRect(QPoint(rect().x(), rect().y()),
                    QPoint(progressRect(spinOpts).right(), rect().bottom()));
    painter.setClipRegion(QRegion(rect()).subtracted(eraseRect));
    style()->drawComplexControl(QStyle::CC_SpinBox, &spinOpts, &painter, d->dummySpinBox);
    painter.setClipping(false);
    painter.restore();


    //Create options to draw progress bar parts
    QStyleOptionProgressBar progressOpts = progressBarOptions();

    //Draw "ProgressBar" in SpinBox
    style()->drawControl(QStyle::CE_ProgressBar, &progressOpts, &painter, 0);

    //Draw focus if necessary
    if (hasFocus() &&
            d->edit->hasFocus()) {
        QStyleOptionFocusRect focusOpts;
        focusOpts.initFrom(this);
        focusOpts.rect = progressOpts.rect;
        focusOpts.backgroundColor = palette().color(QPalette::Window);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpts, &painter, this);
    }

}
Exemple #15
0
QStyleOptionProgressBarV2 SliderDoubleSpinBoxPrivate::progressBarOptions() const
{
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    // scale up to model requrested precision with int
    const double factor = std::pow(10.0, q->decimals());

    //Create opts for drawing the progress portion
    QStyleOptionProgressBarV2 progressOpts;
    progressOpts.initFrom(q);
    progressOpts.maximum = q->maximum() * factor;
    progressOpts.minimum = q->minimum() * factor;
    progressOpts.progress = q->value() * factor;
    progressOpts.text = QString::number(q->value(), 'f', q->decimals()) + q->suffix();
    progressOpts.textAlignment = Qt::AlignCenter;
    progressOpts.textVisible = ! q->lineEdit()->isVisible();

    //Change opts rect to be only the ComboBox's text area
    progressOpts.rect = progressRect(spinOpts);

    return progressOpts;
}
void KisAbstractSliderSpinBox::mouseReleaseEvent(QMouseEvent* e)
{
    Q_D(KisAbstractSliderSpinBox);
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    //Step up/down for buttons
    //Emualting mouse grab too
    if (upButtonRect(spinOpts).contains(e->pos()) && d->upButtonDown) {
        setInternalValue(d->value + d->singleStep);
    } else if (downButtonRect(spinOpts).contains(e->pos()) && d->downButtonDown) {
        setInternalValue(d->value - d->singleStep);
    } else if (progressRect(spinOpts).contains(e->pos()) &&
               !(d->edit->isVisible()) &&
               !(d->upButtonDown || d->downButtonDown)) {
        //Snap to percentage for progress area
        setInternalValue(valueForX(e->pos().x()));
    }

    d->upButtonDown = false;
    d->downButtonDown = false;
    update();
}
/* -----------------------------------------------------------------\
|  Method: paint
|  Begin:  22.03.2011 / 12:20
|  Author: Jo2003
|  Description: paint custom view item
|
|  Parameters: painter, view item, model index
|
|  Returns: --
\----------------------------------------------------------------- */
void QChanListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
   // paint any selection / hover effect ...
   QStyledItemDelegate::paint(painter, option, index);
   painter->save();

   /////////////////////////////////////////////////////////////////////////////
   int     iPos     = qvariant_cast<int>(index.data(channellist::posRole));
   int     iCid     = qvariant_cast<int>(index.data(channellist::cidRole));
   uint    uiStart  = qvariant_cast<uint>(index.data(channellist::startRole));
   uint    uiEnd    = qvariant_cast<uint>(index.data(channellist::endRole));
   QIcon   icon     = qvariant_cast<QIcon>(index.data(channellist::iconRole));
#ifdef _TASTE_CHITRAM_TV
   // maybe we should think about to use these values for all brandings ...
   QSize   iconsize = icon.actualSize(QSize(42, 42));
#else
   QSize   iconsize = icon.actualSize(option.decorationSize);
#endif // _TASTE_CHITRAM_TV
   QString sChan    = qvariant_cast<QString>(index.data(channellist::nameRole));
   QString sProg    = qvariant_cast<QString>(index.data(channellist::progRole));
   QString sColor   = qvariant_cast<QString>(index.data(channellist::bgcolorRole));
   QString fromTo   = QString("%1 - %2")
                      .arg(QDateTime::fromTime_t(uiStart).toString("h:mm"))
                      .arg(QDateTime::fromTime_t(uiEnd).toString("h:mm"));
   /////////////////////////////////////////////////////////////////////////////

   // colorize background if this is a channel group ...
   if ((iCid == -1) && (sColor != "")
      && !(option.state & (QStyle::State_Selected | QStyle::State_MouseOver)))
   {
      // channel group ...
      painter->fillRect(option.rect, QColor(sColor));
   }

   // draw icon ...
   int   x = option.rect.x() + 2;
   int   y = option.rect.y() + ((option.rect.height() - iconsize.height()) / 2);
   QRect iconRect(x, y, iconsize.width(), iconsize.height());
   painter->drawPixmap(iconRect, icon.pixmap(iconsize));

   x = iconRect.right() + 4;
   int rightWidth = option.rect.right() - x - 2;

   // font stuff for channel line ...
   QFont chanFont = option.font;
   chanFont.setPointSize(chanFont.pointSize() + 1);
   chanFont.setBold(true);
   QFontMetrics fmChan(chanFont);

   // check if additional info is available ...
   if ((sProg == "") || !uiStart || !uiEnd)
   {
      // draw simple item only ...

      // channel line ...
      y = option.rect.y() + ((option.rect.height() - fmChan.height()) / 2);
      QRect chanRect(x, y, rightWidth, fmChan.height());

      painter->setFont(chanFont);
      painter->drawText(chanRect, Qt::TextSingleLine, sChan);
   }
   else
   {
      // draw advanced item ...
      QRect bounting;
      QFont progFont = option.font;
      progFont.setPointSize(progFont.pointSize() - 1);
      progFont.setWeight(progFont.weight() - 2);
      QFontMetrics fmProg(progFont);

      // channel line ...
      y = option.rect.y() + 2;
      QRect chanRect(x, y, rightWidth, fmChan.height());

      CSmallHelpers::cutProgString(sChan, fmChan, rightWidth);
      painter->setFont(chanFont);
      painter->drawText(chanRect, Qt::TextSingleLine, sChan, &bounting);

      // program line ...
      y = bounting.bottom();
      QRect progRect(x, y, rightWidth, fmProg.height());

      CSmallHelpers::cutProgString(sProg, fmProg, rightWidth);
      painter->setFont(progFont);
      painter->drawText(progRect, Qt::TextSingleLine, sProg.section('\n', 0, 0), &bounting);

      // from ... to line ...
      y = bounting.bottom();
      QRect timesRect(x, y, rightWidth, fmProg.height());
      painter->drawText(timesRect, Qt::TextSingleLine, fromTo, &bounting);

      // progress bar ...
      y = bounting.bottom() + 2;
      QRect progressRect(x, y, rightWidth, 5);
      iPos = (iPos > (int)(uiEnd - uiStart)) ? (int)(uiEnd - uiStart) : iPos;

#ifndef Q_OS_MAC
      QStyleOptionProgressBar progressBar;
      progressBar.rect        = progressRect;
      progressBar.minimum     = 0;
      progressBar.maximum     = (int)(uiEnd - uiStart);
      progressBar.progress    = iPos;
      progressBar.textVisible = false;

      QApplication::style()->drawControl(QStyle::CE_ProgressBar,
                                         &progressBar, painter);
#else
      // Drawing the progress bar on mac doesn't look nice
      // because the height can't be shrinked as needed.
      // So we try to draw our own progress bar here ...

      // make sure background is white ...
      painter->fillRect(progressRect, QColor("white"));

      // prepare pen for border line ...
      QPen pen(Qt::SolidLine);
      pen.setColor(QColor("silver"));
      pen.setWidth(1);
      painter->setPen(pen);

      // draw outline ...
      painter->drawRect(progressRect);

      // compute size of inner rect (take care of border) ...
      x = progressRect.width()  - pen.width();
      y = progressRect.height() - pen.width();
      x = (uiEnd - uiStart) ? ((x * iPos) / (int)(uiEnd - uiStart)) : 0; ///< avoid division with 0 !!!

      // inner rectangle (progess) ...
      QRect macRect(progressRect.x() + pen.width(), progressRect.y() + pen.width(), x, y);

      // paint progress ...
      painter->fillRect(macRect, QColor("#036"));
#endif // Q_OS_MAC

   }

   painter->restore();
}