Ejemplo n.º 1
0
static void ScrollbarDownArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned state)
{
    if (qApp == NULL) NULL_Q_APP;
    NULL_PROXY_ORIENTED_WIDGET(TileQt_QScrollBar_Widget);
    Tcl_MutexLock(&tileqtMutex);
    QPixmap      pixmap(b.width, b.height);
    QPainter     painter(&pixmap);
    TILEQT_PAINT_BACKGROUND(b.width, b.height);
#ifdef TILEQT_QT_VERSION_4
    wc->TileQt_QScrollBar_Widget->resize(b.width, b.height);
    wc->TileQt_QScrollBar_Widget->setValue(0);
    if (orient == TTK_ORIENT_HORIZONTAL) {
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Horizontal);
    } else {
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Vertical);
    }
    QStyleOptionSlider option;
    option.initFrom(wc->TileQt_QScrollBar_Widget); option.state |= 
      (QStyle::StateFlag) TileQt_StateTableLookup(scrollbar_statemap, state);
    option.subControls = QStyle::SC_ScrollBarAddLine;
    wc->TileQt_Style->drawComplexControl(QStyle::CC_ScrollBar, &option,
                                  &painter, wc->TileQt_QScrollBar_Widget);
#endif /* TILEQT_QT_VERSION_4 */
    TileQt_CopyQtPixmapOnToDrawable(pixmap, d, tkwin,
                                    0, 0, b.width, b.height, b.x, b.y);
    Tcl_MutexUnlock(&tileqtMutex);
#ifdef TILEQT_SCROLLBAR_SIZE_DEBUG
    printf("ScrollbarDownArrowElementDraw: width=%d, height=%d, orient=%d\n",
            b.width, b.height, orient); fflush(0);
#endif /* TILEQT_SCROLLBAR_SIZE_DEBUG */
}
Ejemplo n.º 2
0
void DoubleSlider::paintEvent(QPaintEvent *)
{
  QPainter painter(this);
  QStyleOptionSlider option;
  option.initFrom(this);
  option.maximum = maximum();
  option.minimum = minimum();
  option.sliderPosition = v1;
  style()->drawComplexControl(QStyle::CC_Slider, &option, &painter, this);
  QRect handle1 = style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this);

  option.sliderPosition = v2;
  option.subControls = QStyle::SC_SliderHandle;
  style()->drawComplexControl(QStyle::CC_Slider, &option, &painter, this);
  QRect handle2 = style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this);
  QPen p;
  p.setColor(QColor(0, 0, 200, 150));
  p.setWidth(handle1.height()-6);
  p.setCapStyle(Qt::FlatCap);
  painter.setPen(p);
  QRect groove = style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderGroove, this);
  int wi = handle1.width();
  painter.drawLine(handle1.x()+wi, handle1.height()/2,  handle2.x(), handle1.height()/2);

   painter.end();
}
Ejemplo n.º 3
0
static void ScrollbarThumbElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned state)
{
    if (qApp == NULL) NULL_Q_APP;
    if (state & TTK_STATE_DISABLED) return;
    NULL_PROXY_ORIENTED_WIDGET(TileQt_QScrollBar_Widget);
    Tcl_MutexLock(&tileqtMutex);
    //QPixmap      pixmap(b.width, b.height);
    QPixmap      pixmap = QPixmap::grabWindow(Tk_WindowId(tkwin));
    QPainter     painter(&pixmap);
#ifdef TILEQT_QT_VERSION_4
    wc->TileQt_QScrollBar_Widget->resize(b.width, b.height);
    wc->TileQt_QScrollBar_Widget->setValue(0);
    if (orient == TTK_ORIENT_HORIZONTAL) {
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Horizontal);
    } else {
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Vertical);
    }
    QStyleOptionSlider option;
    option.initFrom(wc->TileQt_QScrollBar_Widget); option.state |= 
      (QStyle::StateFlag) TileQt_StateTableLookup(scrollbar_statemap, state);
    option.subControls = QStyle::SC_ScrollBarGroove;
    wc->TileQt_Style->drawComplexControl(QStyle::CC_ScrollBar, &option,
                                  &painter, wc->TileQt_QScrollBar_Widget);
#endif /* TILEQT_QT_VERSION_4 */
    // printf("x=%d, y=%d, w=%d, h=%d\n", b.x, b.y, b.width, b.height);
    TileQt_CopyQtPixmapOnToDrawable(pixmap, d, tkwin,
                                    0, 0, b.width, b.height, b.x, b.y);
    Tcl_MutexUnlock(&tileqtMutex);
}
Ejemplo n.º 4
0
static void ScrollbarDownArrowElementGeometry(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    if (qApp == NULL) NULL_Q_APP;
    NULL_PROXY_ORIENTED_WIDGET(TileQt_QScrollBar_Widget);
    Tcl_MutexLock(&tileqtMutex);
    if (orient == TTK_ORIENT_HORIZONTAL) {
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Horizontal);
    } else {
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Vertical);
    }
#ifdef TILEQT_QT_VERSION_4
    QStyleOptionSlider option;
    option.initFrom(wc->TileQt_QScrollBar_Widget);
    QRect rc = wc->TileQt_Style->subControlRect(QStyle::CC_ScrollBar,
          &option, QStyle::SC_ScrollBarAddLine, wc->TileQt_QScrollBar_Widget);
#endif /* TILEQT_QT_VERSION_4 */
    if (rc.isValid()) {
      *widthPtr = rc.width();
      *heightPtr = rc.height();
      /* Qt Style Fixes: */
      // printf("%s\n", wc->TileQt_Style->name());
      if (TileQt_ThemeIs(wc, "keramik") || TileQt_ThemeIs(wc, "thinkeramik") ||
          TileQt_ThemeIs(wc, "shinekeramik")) {
        // Keramic & ThinKeramic are buggy: Their subcontrol metrics are for 2
        // buttons, not one. Find the smallest dimension, and return a
        // rectangle.
        if (orient == TTK_ORIENT_HORIZONTAL) {
          *heightPtr = 17;
          *widthPtr  = 34;
        } else {
          *heightPtr = 34;
          *widthPtr  = 17;
        }
      } else if (TileQt_ThemeIs(wc, "sgi") ||
                 TileQt_ThemeIs(wc, "compact") ||
                 TileQt_ThemeIs(wc, "platinum") ||
                 TileQt_ThemeIs(wc, "motifplus") ||
                 TileQt_ThemeIs(wc, "cde") ||
                 TileQt_ThemeIs(wc, "motif") ||
                 TileQt_ThemeIs(wc, "windows")) {
        // These styles are buggy?: Some times one dimension is returned as 10,
        // others as 21.
        if (*widthPtr < *heightPtr) *widthPtr  = *heightPtr;
        if (*heightPtr < *widthPtr) *heightPtr = *widthPtr;
      }
    }
    Tcl_MutexUnlock(&tileqtMutex);
    *paddingPtr = Ttk_UniformPadding(0);
#ifdef TILEQT_SCROLLBAR_SIZE_DEBUG
   printf("ScrollbarDownArrowElementGeometry: width=%d, height=%d, orient=%d\n",
            *widthPtr, *heightPtr, orient); fflush(0);
#endif /* TILEQT_SCROLLBAR_SIZE_DEBUG */
}
QStyleOptionSlider MyIntervalSliderOptions::copyOptions() const
{
	QStyleOptionSlider opt;
	opt.initFrom(slider);
	opt.maximum = slider->maximum();
	opt.minimum = slider->minimum();
	opt.orientation = slider->orientation();
	opt.pageStep = slider->pageStep();
	opt.singleStep = slider->singleStep();
	return opt;
}
Ejemplo n.º 6
0
QStyleOptionSlider GTScrollBar::initScrollbarOptions(GUITestOpStatus &os, QScrollBar *scrollbar) {
    GT_CHECK_RESULT(scrollbar != NULL, "scrollbar is NULL", QStyleOptionSlider());
    QStyleOptionSlider options;
    options.initFrom(scrollbar);
    options.sliderPosition = scrollbar->sliderPosition();
    options.maximum = scrollbar->maximum();
    options.minimum = scrollbar->minimum();
    options.singleStep = scrollbar->singleStep();
    options.pageStep = scrollbar->pageStep();
    options.orientation = scrollbar->orientation();
    options.sliderValue = options.sliderPosition;
    options.upsideDown = false;
    options.state = QStyle::State_Sunken | QStyle::State_Enabled;

    return options;
}
Ejemplo n.º 7
0
int ScrollBar::extent() const
{
    QStyleOptionSlider opt;
    opt.init(this);
    opt.subControls = QStyle::SC_None;
    opt.activeSubControls = QStyle::SC_None;
    opt.orientation = orientation();
    opt.minimum = minimum();
    opt.maximum = maximum();
    opt.sliderPosition = sliderPosition();
    opt.sliderValue = value();
    opt.singleStep = singleStep();
    opt.pageStep = pageStep();
    opt.upsideDown = invertedAppearance();
    if (orientation() == Qt::Horizontal)
        opt.state |= QStyle::State_Horizontal;
    return style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt, this);
}
Ejemplo n.º 8
0
static QStyleOptionSlider* styleOptionSlider(ScrollbarThemeClient* scrollbar, QWidget* widget = 0)
{
    static QStyleOptionSlider opt;
    if (widget)
        opt.initFrom(widget);
    else
        opt.state |= QStyle::State_Active;

    opt.state &= ~QStyle::State_HasFocus;

    opt.rect = scrollbar->frameRect();
    if (scrollbar->enabled())
        opt.state |= QStyle::State_Enabled;
    if (scrollbar->controlSize() != RegularScrollbar)
        opt.state |= QStyle::State_Mini;
    opt.orientation = (scrollbar->orientation() == VerticalScrollbar) ? Qt::Vertical : Qt::Horizontal;

    if (scrollbar->orientation() == HorizontalScrollbar)
        opt.state |= QStyle::State_Horizontal;
    else
        opt.state &= ~QStyle::State_Horizontal;

    opt.sliderValue = scrollbar->value();
    opt.sliderPosition = opt.sliderValue;
    opt.pageStep = scrollbar->pageStep();
    opt.singleStep = scrollbar->lineStep();
    opt.minimum = 0;
    opt.maximum = qMax(0, scrollbar->maximum());
    ScrollbarPart pressedPart = scrollbar->pressedPart();
    ScrollbarPart hoveredPart = scrollbar->hoveredPart();
    if (pressedPart != NoPart) {
        opt.activeSubControls = scPart(scrollbar->pressedPart());
        if (pressedPart == BackButtonStartPart || pressedPart == ForwardButtonStartPart
            || pressedPart == BackButtonEndPart || pressedPart == ForwardButtonEndPart
            || pressedPart == ThumbPart)
            opt.state |= QStyle::State_Sunken;
    } else
        opt.activeSubControls = scPart(hoveredPart);
    if (hoveredPart != NoPart)
        opt.state |= QStyle::State_MouseOver;
    return &opt;
}
Ejemplo n.º 9
0
// TODO: get rid of this in Qt 4.3
QStyleOptionSlider QxtStarsPrivate::getStyleOption() const
{
    const QxtStars* p = &qxt_p();
    QStyleOptionSlider opt;
    opt.initFrom(p);
    opt.subControls = QStyle::SC_None;
    opt.activeSubControls = QStyle::SC_None;
    opt.orientation = p->orientation();
    opt.maximum = p->maximum();
    opt.minimum = p->minimum();
    opt.upsideDown = (p->orientation() == Qt::Horizontal) ?
                     (p->invertedAppearance() != (opt.direction == Qt::RightToLeft)) : (!p->invertedAppearance());
    opt.direction = Qt::LeftToRight; // we use the upsideDown option instead
    opt.sliderPosition = p->sliderPosition();
    opt.sliderValue = p->value();
    opt.singleStep = p->singleStep();
    opt.pageStep = p->pageStep();
    if (p->orientation() == Qt::Horizontal)
        opt.state |= QStyle::State_Horizontal;
    return opt;
}
Ejemplo n.º 10
0
void CustomDial::paintEvent(QPaintEvent*) {
    QPainter p(this);

    QStyleOptionSlider tab;
    tab.init(this);

    bool hover = tab.state & QStyle::State_MouseOver;

    p.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
    QBrush brush("#333");
    if(hover) brush.setColor("#393939");

    p.setPen(Qt::NoPen);
    p.setBrush(brush);
    p.drawPie(20, 20, width()-20*2, height()-20*2, (220)*16, -(360-100)*16);

    if(hover) p.setPen(QPen(color.lighter(120), 15));
    else p.setPen(QPen(color, 15));

    p.drawArc(10, 10, width()-10*2, height()-10*2, 220*16, -(360-100)*16*value()/100);
}
Ejemplo n.º 11
0
static void ScrollbarTroughElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned state)
{
    if (qApp == NULL) NULL_Q_APP;
    NULL_PROXY_ORIENTED_WIDGET(TileQt_QScrollBar_Widget);
    Tcl_MutexLock(&tileqtMutex);
    /* We draw the whole scrollbar at once, but without the slider! */
    int width, height;
    //TileQt_QScrollBar_Widget->resize(b.width, b.height);
    if (orient == TTK_ORIENT_HORIZONTAL) {
      width = 2*b.width; height = b.height;
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Horizontal);
    } else {
      width = b.width; height = 2*b.height;
      wc->TileQt_QScrollBar_Widget->setOrientation(Qt::Vertical);
    }
#ifdef TILEQT_SCROLLBAR_SIZE_DEBUG
    printf("ScrollbarTroughElementDraw: width=%d, height=%d, orient=%d\n",
            width, height, orient); fflush(0);
#endif /* TILEQT_SCROLLBAR_SIZE_DEBUG */
    wc->TileQt_QScrollBar_Widget->resize(width, height);
    wc->TileQt_QScrollBar_Widget->setValue(0);
    QPixmap      pixmap(width, height);
    QPainter     painter(&pixmap);
    TILEQT_PAINT_BACKGROUND(width, height);

#ifdef TILEQT_QT_VERSION_4
    QStyleOptionSlider option;
    option.initFrom(wc->TileQt_QScrollBar_Widget); option.state |= 
      (QStyle::StateFlag) TileQt_StateTableLookup(scrollbar_statemap, state);
    wc->TileQt_Style->drawComplexControl(QStyle::CC_ScrollBar, &option,
                                  &painter, wc->TileQt_QScrollBar_Widget);
#endif /* TILEQT_QT_VERSION_4 */
    // printf("x=%d, y=%d, w=%d, h=%d\n", b.x, b.y, b.width, b.height);
    TileQt_CopyQtPixmapOnToDrawable(pixmap, d, tkwin,
                                    width-b.width, height-b.height,
                                    b.width, b.height, b.x, b.y);
    Tcl_MutexUnlock(&tileqtMutex);
}
Ejemplo n.º 12
0
void ShadowSlider::paintEvent(QPaintEvent * ev)
{
    QSlider::paintEvent(ev);
    QStyleOptionSlider option;

    option.initFrom(this);
    option.dialWrapping = false;
    option.maximum = this->maximum();
    option.minimum = this->minimum();
    option.notchTarget = 0;
    option.orientation = this->orientation();
    option.pageStep = 0;
    option.sliderPosition = m_shadow_position;
    option.sliderValue = m_shadow_position;
    option.tickInterval = 0;
    option.tickPosition = QSlider::NoTicks;
    option.upsideDown = this->orientation() == Qt::Vertical && ! this->invertedAppearance();
    option.subControls = QStyle::SC_DialHandle;

    QPainter painter(this);
    painter.setOpacity(0.5);
    this->style()->drawComplexControl(QStyle::CC_Slider, &option, &painter, this);
}
void GTUtilsMSAEditorSequenceArea::scrollToBottom(HI::GUITestOpStatus &os) {
    MSAEditorSequenceArea *msaSeqArea = qobject_cast<MSAEditorSequenceArea*>(GTWidget::findWidget(os, "msa_editor_sequence_area", GTUtilsMdi::activeWindow(os)));
    GT_CHECK(NULL != msaSeqArea, "MSA Editor sequence area is not found");

    // scroll down
    GScrollBar* vBar = msaSeqArea->getVBar();
#ifdef Q_OS_MAC
    vBar->setValue(vBar->maximum());
    return;
#endif
    GT_CHECK(NULL != vBar, "Vertical scroll bar is not found");

    QStyleOptionSlider vScrollBarOptions;
    vScrollBarOptions.initFrom(vBar);

    while (vBar->value() != vBar->maximum()) {
        const QRect sliderSpaceRect = vBar->style()->subControlRect(QStyle::CC_ScrollBar, &vScrollBarOptions, QStyle::SC_ScrollBarGroove, vBar);
        const QPoint bottomEdge(sliderSpaceRect.width() / 2 + 10, sliderSpaceRect.y() + sliderSpaceRect.height());

        GTMouseDriver::moveTo(vBar->mapToGlobal(bottomEdge) - QPoint(0, 1));
        GTMouseDriver::click();
    }
}
void GTUtilsMSAEditorSequenceArea::scrollToPosition(HI::GUITestOpStatus &os, const QPoint &position) {
    MSAEditorSequenceArea *msaSeqArea = qobject_cast<MSAEditorSequenceArea*>(GTWidget::findWidget(os, "msa_editor_sequence_area", GTUtilsMdi::activeWindow(os)));
    GT_CHECK(NULL != msaSeqArea, "MSA Editor sequence area is not found");
    GT_CHECK(msaSeqArea->isInRange(position), "Position is out of range");

    // scroll down
    GScrollBar* vBar = msaSeqArea->getVBar();
    GT_CHECK(NULL != vBar, "Vertical scroll bar is not found");

    QStyleOptionSlider vScrollBarOptions;
    vScrollBarOptions.initFrom(vBar);

    while (!msaSeqArea->isSeqVisible(position.y(), false)) {
        const QRect sliderSpaceRect = vBar->style()->subControlRect(QStyle::CC_ScrollBar, &vScrollBarOptions, QStyle::SC_ScrollBarGroove, vBar);
        const QPoint bottomEdge(sliderSpaceRect.width() / 2, sliderSpaceRect.y() + sliderSpaceRect.height());

        GTMouseDriver::moveTo(vBar->mapToGlobal(bottomEdge) - QPoint(0, 1));
        GTMouseDriver::click();
    }

    // scroll right
    GScrollBar* hBar = msaSeqArea->getHBar();
    GT_CHECK(NULL != hBar, "Horisontal scroll bar is not found");

    QStyleOptionSlider hScrollBarOptions;
    hScrollBarOptions.initFrom(hBar);

    while (!msaSeqArea->isPosVisible(position.x(), false)) {
        const QRect sliderSpaceRect = hBar->style()->subControlRect(QStyle::CC_ScrollBar, &hScrollBarOptions, QStyle::SC_ScrollBarGroove, hBar);
        const QPoint rightEdge(sliderSpaceRect.x() + sliderSpaceRect.width(), sliderSpaceRect.height() / 2);

        GTMouseDriver::moveTo(hBar->mapToGlobal(rightEdge) - QPoint(1, 0));
        GTMouseDriver::click();
    }

    SAFE_POINT(msaSeqArea->isVisible(position, false), "The position is still invisible after scrolling", );
}
Ejemplo n.º 15
0
void KoSliderCombo::KoSliderComboPrivate::showPopup()
{
    if(firstShowOfSlider) {
        container->show(); //show container a bit early so the slider can be layout'ed
        firstShowOfSlider = false;
    }

    QStyleOptionSlider opt;
    opt.init(slider);
    opt.maximum=256;
    opt.sliderPosition = opt.sliderValue = slider->value();
    int hdlPos = thePublic->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle).center().x();

    QStyleOptionComboBox optThis;
    optThis.init(thePublic);
    optThis.subControls = QStyle::SC_All;
    optThis.editable = true;
    int arrowPos = thePublic->style()->subControlRect(QStyle::CC_ComboBox, &optThis, QStyle::SC_ComboBoxArrow).center().x();

    QSize popSize = container->size();
    QRect popupRect(thePublic->mapToGlobal(QPoint(arrowPos - hdlPos - slider->x(), thePublic->size().height())), popSize);

    // Make sure the popup is not drawn outside the screen area
    QRect screenRect = QApplication::desktop()->availableGeometry(thePublic);
    if (popupRect.right() > screenRect.right())
        popupRect.translate(screenRect.right() - popupRect.right(), 0);
    if (popupRect.left() < screenRect.left())
        popupRect.translate(screenRect.left() - popupRect.left(), 0);
    if (popupRect.bottom() > screenRect.bottom())
        popupRect.translate(0, -(thePublic->height() + container->height()));

    container->setGeometry(popupRect);
    container->raise();
    container->show();
    slider->setFocus();
}
Ejemplo n.º 16
0
/// XXX
void MiamStyle::drawScrollBar(QPainter *p, const QWidget *widget) const
{
	QStyleOptionSlider scrollbar;
	scrollbar.palette = QApplication::palette();

	const QScrollBar *sc = qobject_cast<const QScrollBar *>(widget);
	scrollbar.initFrom(sc);


	QRect subLineRect = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &scrollbar, QStyle::SC_ScrollBarSubLine, sc);
	QRect addLineRect = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &scrollbar, QStyle::SC_ScrollBarAddLine, sc);
	QRect sliderRect = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &scrollbar, QStyle::SC_ScrollBarSlider, sc);

	//qDebug() << subLineRect << sliderRect << addLineRect;


	if (sc->orientation() == Qt::Vertical) {
		subLineRect.adjust(0, 0, -1, 0);
		addLineRect.adjust(0, 0, -1, 0);
		sliderRect.adjust(0, 0, -1, 0);
	} else {
		subLineRect.adjust(0, 0, 0, -1);
		addLineRect.adjust(0, 0, 0, -1);
		sliderRect.adjust(0, 0, 0, -1);
	}

	p->setPen(Qt::NoPen);
	p->setBrush(scrollbar.palette.window());
	p->drawRect(sc->rect());

	p->setBrush(scrollbar.palette.base().color().darker(125));
	p->drawRect(sliderRect);

	// Highlight
	p->save();
	QPoint pos = sc->mapFromGlobal(QCursor::pos());
	p->setPen(scrollbar.palette.highlight().color());

	if (!sc->isSliderDown()) {
		p->setBrush(scrollbar.palette.highlight().color().lighter());
		if (subLineRect.contains(pos)) {
			p->drawRect(subLineRect);
		} else if (sliderRect.contains(pos)) {
			p->drawRect(sliderRect);
		} else if (addLineRect.contains(pos)) {
			p->drawRect(addLineRect);
		}
	} else {
		p->setBrush(scrollbar.palette.highlight().color());
		//if (_isDown == 0) {
		//	p->drawRect(subLineRect);
		//} else if (_isDown == 1) {
		//	p->drawRect(sliderRect);
		//} else if (_isDown == 2) {
		//	p->drawRect(addLineRect);
		//}
	}
	p->restore();

	// Draw sort indicator
	static const QPointF upArrow[3] = {
		QPointF(0.0, 1.0),
		QPointF(1.0, 0.0),
		QPointF(2.0, 1.0)
	};
	static const QPointF downArrow[3] = {
		QPointF(0.0, 0.0),
		QPointF(2.0, 0.0),
		QPointF(1.0, 1.0)
	};
	static const QPointF leftArrow[3] = {
		QPointF(0.0, 1.0),
		QPointF(1.0, 0.0),
		QPointF(1.0, 2.0)
	};
	static const QPointF rightArrow[3] = {
		QPointF(0.0, 0.0),
		QPointF(1.0, 1.0),
		QPointF(0.0, 2.0)
	};

	// Arrows
	p->save();
	if (scrollbar.palette.windowText().color().value() < 128) {
		p->setPen(scrollbar.palette.dark().color());
		p->setBrush(scrollbar.palette.dark());
	} else {
		p->setPen(scrollbar.palette.mid().color());
		p->setBrush(scrollbar.palette.mid());
	}

	QTransform t;
	float ratio = (float) subLineRect.height() / 4.0;
	t.scale(ratio, ratio);

	if (sc->orientation() == Qt::Vertical) {
		QPolygonF up, down;
		up.append(t.map(upArrow[0]));
		up.append(t.map(upArrow[1]));
		up.append(t.map(upArrow[2]));
		down.append(t.map(downArrow[0]));
		down.append(t.map(downArrow[1]));
		down.append(t.map(downArrow[2]));
		p->translate(subLineRect.width() / 4.0, subLineRect.height() / 3.0);
		p->drawPolygon(up);
		p->translate(0, addLineRect.y());
		p->drawPolygon(down);
	} else {
		QPolygonF left, right;
		left.append(t.map(leftArrow[0]));
		left.append(t.map(leftArrow[1]));
		left.append(t.map(leftArrow[2]));
		right.append(t.map(rightArrow[0]));
		right.append(t.map(rightArrow[1]));
		right.append(t.map(rightArrow[2]));
		p->translate(subLineRect.height() / 3.0, subLineRect.width() / 4.0);
		p->drawPolygon(left);
		p->translate(addLineRect.x(), 0);
		p->drawPolygon(right);
	}
	p->restore();
}
Ejemplo n.º 17
0
void DiffZoomWidget::paintEvent(QPaintEvent *)
{
    const QScrollBar* scrollBar = diffview->scrollBar();
    if (!scrollBar)
        return;

    const QColor diffChangeColor(CervisiaSettings::diffChangeColor());
    const QColor diffInsertColor(CervisiaSettings::diffInsertColor());
    const QColor diffDeleteColor(CervisiaSettings::diffDeleteColor());

    // only y and height are important
    QStyleOptionSlider option;
    option.init(scrollBar);
    const QRect scrollBarGroove(scrollBar->isVisible()
                                ? style()->subControlRect(QStyle::CC_ScrollBar,
                                                          &option,
                                                          QStyle::SC_ScrollBarGroove,
                                                          scrollBar)
                                : rect());

    // draw rectangles at the positions of the differences

    const QByteArray& lineTypes(diffview->compressedContent());

    QPainter p(this);
    p.fillRect(0, scrollBarGroove.y(), width(), scrollBarGroove.height(),
               KColorScheme(QPalette::Active, KColorScheme::View).background().color());
    if (const unsigned int numberOfLines = lineTypes.size())
    {
        const double scale(((double) scrollBarGroove.height()) / numberOfLines);
        for (unsigned int index(0); index < numberOfLines;)
        {
            const char lineType(lineTypes[index]);

            // don't use qRound() to avoid painting outside of the pixmap
            // (yPos1 must be lesser than scrollBarGroove.height())
            const int yPos1(static_cast<int>(index * scale));

            // search next line with different lineType
            for (++index; index < numberOfLines && lineType == lineTypes[index]; ++index)
                ;

            QColor color;
            switch (lineType)
            {
            case 'C':
                color = diffChangeColor;
                break;
            case 'I':
                color = diffInsertColor;
                break;
            case 'D':
                color = diffDeleteColor;
                break;
            case ' ':
            case 'N':
                color = KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::AlternateBackground).color();
                break;
            }

            if (color.isValid())
            {
                const int yPos2(qRound(index * scale));
                const int areaHeight((yPos2 != yPos1) ? yPos2 - yPos1 : 1);

                p.fillRect(0, yPos1 + scrollBarGroove.y(), width(), areaHeight, QBrush(color));
            }
        }
    }
}