Пример #1
0
QPixmap DetailsWidget::createBackground(const QSize &size, int topHeight, QWidget *widget)
{
    QPixmap pixmap(size);
    pixmap.fill(Qt::transparent);
    QPainter p(&pixmap);

    QRect topRect(0, 0, size.width(), topHeight);
    QRect fullRect(0, 0, size.width(), size.height());
    if (HostOsInfo::isMacHost())
        p.fillRect(fullRect, qApp->palette().window().color());
    else
        p.fillRect(fullRect, creatorTheme()->color(Theme::DetailsWidgetBackgroundColor));

    if (creatorTheme()->widgetStyle () == Theme::StyleDefault) {
        QLinearGradient lg(topRect.topLeft(), topRect.bottomLeft());
        lg.setStops(creatorTheme()->gradient(Theme::DetailsWidgetHeaderGradient));
        p.fillRect(topRect, lg);
        p.setRenderHint(QPainter::Antialiasing, true);
        p.translate(0.5, 0.5);
        p.setPen(QColor(0, 0, 0, 40));
        p.setBrush(Qt::NoBrush);
        p.drawRoundedRect(fullRect.adjusted(0, 0, -1, -1), 2, 2);
        p.setBrush(Qt::NoBrush);
        p.setPen(QColor(255,255,255,140));
        p.drawRoundedRect(fullRect.adjusted(1, 1, -2, -2), 2, 2);
        p.setPen(QPen(widget->palette().color(QPalette::Mid)));
    }

    return pixmap;
}
Пример #2
0
    QPixmap DetailsWidget::cacheBackground(const QSize &size, bool expanded)
    {
        QPixmap pixmap(size);
        pixmap.fill(Qt::transparent);
        QPainter p(&pixmap);

        QRect topRect(0, 0, size.width(), d->m_useCheckBox ? d->m_summaryCheckBox->height() : d->m_summaryLabel->height());
        QRect fullRect(0, 0, size.width(), size.height());
        p.fillRect(fullRect, QColor(255, 255, 255, 40));

        QColor highlight = palette().highlight().color();
        highlight.setAlpha(0.5);
        if (expanded) {
            p.fillRect(topRect, highlight);
        }

        QLinearGradient lg(topRect.topLeft(), topRect.bottomLeft());
        lg.setColorAt(0, QColor(255, 255, 255, 130));
        lg.setColorAt(1, QColor(255, 255, 255, 0));
        p.fillRect(topRect, lg);
        p.setRenderHint(QPainter::Antialiasing, true);
        p.translate(0.5, 0.5);
        p.setPen(QColor(0, 0, 0, 40));
        p.setBrush(Qt::NoBrush);
        p.drawRoundedRect(fullRect.adjusted(0, 0, -1, -1), 2, 2);
        p.setBrush(Qt::NoBrush);
        p.setPen(QColor(255,255,255,140));
        p.drawRoundedRect(fullRect.adjusted(1, 1, -2, -2), 2, 2);
        p.setPen(QPen(palette().color(QPalette::Mid)));

        return pixmap;
    }
Пример #3
0
void UIComponentTabView::onRender(GraphicsDevice* renderer, Widget* view)
{
	RectangleShape topRect(FloatRect(view->getPosition().x, view->getPosition().y, view->getSize().x, 20.f), Color::White);
	renderer->draw(topRect);

	RectangleShape bottomRect(FloatRect(view->getPosition().x, view->getPosition().y + 20, view->getSize().x, view->getSize().y - 20.f), Color::Orange);
	renderer->draw(bottomRect);
}
Пример #4
0
TEST(TransparencyWin, DISABLED_TranslateScaleOpaqueCompositeLayer)
{
    OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1));

    // The background is white on top with red on bottom.
    Color white(0xFFFFFFFF);
    FloatRect topRect(0, 0, 16, 8);
    src->context()->fillRect(topRect, white);
    Color red(0xFFFF0000);
    FloatRect bottomRect(0, 8, 16, 8);
    src->context()->fillRect(bottomRect, red);

    src->context()->save();

    // Translate left by one pixel.
    AffineTransform left;
    left.translate(-1, 0);

    // Scale by 2x.
    AffineTransform scale;
    scale.scale(2.0);
    src->context()->concatCTM(scale);

    // Then translate up by one pixel (which will actually be 2 due to scaling).
    AffineTransform up;
    up.translate(0, -1);
    src->context()->concatCTM(up);

    // Now draw 50% red square.
    {
        // Create a transparency helper inset one pixel in the buffer. The
        // coordinates are before transforming into this space, and maps to
        // IntRect(1, 1, 14, 14).
        TransparencyWin helper;
        helper.init(src->context(),
                    TransparencyWin::OpaqueCompositeLayer,
                    TransparencyWin::KeepTransform,
                    IntRect(1, -15, 14, 14));

        // Fill with red.
        helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000));
        clearTopLayerAlphaChannel(helper.context());
        helper.composite();
    }
}
// ImageViewDialog message handlers
void ImageViewDialog::OnPaint() {
  BufferredPaintDC dc(this);
  
  CRect rectTitle;
  GetDlgItem(IDC_PLACE_CAPTION)->GetWindowRect(&rectTitle);
  ScreenToClient(&rectTitle);
  dc.FillSolidRect(rectTitle, RGB(54, 133, 214));

  CRect imageRect;
  GetDlgItem(IDC_PLACE_IMAGE)->GetWindowRect(&imageRect);
  ScreenToClient(&imageRect);
  dc.FillSolidRect(imageRect, RGB(0, 0, 0));

  CRect topRect(imageRect.left, imageRect.top, 
      imageRect.right, imageRect.top + imageRect.Height() / 2);
  CRect bottomRect(imageRect.left, topRect.bottom, imageRect.right, imageRect.bottom);
  dc.SetStretchBltMode(HALFTONE);
  DrawImage(&dc, &topImage_, topRect);
  DrawImage(&dc, &bottomImage_, bottomRect);
}
Пример #6
0
void WinBarDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
    if(index.isValid() && index.data(ChannelData).isValid()){
        painter->save();
        painter->setRenderHint(QPainter::Antialiasing);

        /**************配置*****************/
        QRectF rect(option.rect.marginsAdded(margins));
        if(option.state & QStyle::State_Sunken && option.state & QStyle::State_HasFocus){
            rect.moveTo(rect.x() + 1, rect.y() + 1);
        }
        QRectF topRect(rect);
        topRect.setHeight(rect.height()/6);
        QFont font = option.font;
        font.setFamily(font.defaultFamily());

        /*****************色卡*****************/
        QRectF colorRect(topRect);
        colorRect.setHeight(topRect.height()/5 * 3);
        painter->setPen(QColor(0,0,0,0));
        painter->setBrush(QColor(index.data(ChannelColor).value<QColor>()));
        painter->drawRoundedRect(colorRect,5,5);

        /****************头部背景色**************/
        QRectF headRect(topRect);
        headRect.setTop(colorRect.center().y());
        painter->setBrush(QBrush(QColor(240,240,240)));
        painter->drawRect(headRect);

        /******************底部背景色*******************/
        QRectF bottomRect(rect);
        bottomRect.setTop(topRect.bottom() + 2);
        painter->setPen(QColor(0,0,0,0));
        painter->setBrush(QBrush(QColor(240,240,240)));
        painter->drawRect(bottomRect);

        /******************色柱********************/
        QRectF barRect(bottomRect);
        quint8 base = index.data(ChannelBarBase).toUInt();
        qreal mesureVal = index.data(ChannelData).toDouble();
        qreal rangeUpper = index.data(ChannelDispUpper).toDouble();
        qreal rangeDowner = index.data(ChannelDispDowner).toDouble();
        if(mesureVal >= 0){
            barRect.setTop(barRect.top() + barRect.height()/2 * (1 - mesureVal/rangeUpper));
        }else if(mesureVal < 0){
            barRect.setTop(barRect.top() + barRect.height()/2 * (1 + mesureVal/rangeDowner));
        }
        if(base == 1){
            barRect.setBottom(bottomRect.center().y());
        }else if(base == 2){
            barRect.setBottom(bottomRect.top());
        }
        painter->setPen(QColor(0,0,0,0));
        painter->setBrush(QColor(index.data(ChannelColor).value<QColor>()));
        painter->drawRect(barRect);

        /****************光泽效果*****************/
        QLinearGradient skinColor(rect.topLeft(),rect.topRight());
        skinColor.setColorAt(0,QColor(255,255,255,0));
        skinColor.setColorAt(0.09,QColor(255,255,255,0));
        skinColor.setColorAt(0.1,QColor(255,255,255,200));
        skinColor.setColorAt(0.13,QColor(255,255,255,200));
        skinColor.setColorAt(0.14,QColor(255,255,255,80));
        skinColor.setColorAt(0.50,QColor(0,0,0,20));
        skinColor.setColorAt(0.75,QColor(0,0,0,10));
        skinColor.setColorAt(0.76,QColor(255,255,255,30));
        skinColor.setColorAt(0.95,QColor(255,255,255,150));
        skinColor.setColorAt(0.96,QColor(255,255,255,0));
        skinColor.setColorAt(1,QColor(255,255,255,0));
        painter->setPen(QPen(QColor(200,230,255,0)));
        painter->setBrush(skinColor);
        painter->drawRect(rect);

        /*****************刻度*********************/
        qreal baseX = bottomRect.right();
        qreal baseY = bottomRect.top();
        qreal len = bottomRect.width()/8;
        quint8 count = index.data(ChannelBarDiv).toUInt();
        qreal span = bottomRect.height()/count;
        painter->setPen(Qt::black);
        painter->setBrush(QBrush(QColor(0,0,0,0)));
        for(quint8 i=1; i<count; ++i){
            painter->drawLine(baseX - len, baseY + i*span, baseX, baseY + i*span);
        }

        /**************量程*****************/
        QRectF valRect(bottomRect);
        valRect.setHeight(span);
        font.setPixelSize(valRect.height()/2);
        painter->setFont(font);
        painter->setPen(QPen(Qt::black,1));
        painter->drawText(valRect,QString::number(rangeUpper,'f',4));
        valRect.moveBottom(bottomRect.bottom());
        painter->drawText(valRect,Qt::AlignBottom,QString::number(rangeDowner,'f',4));

        /**************测量值*********************/
        valRect.moveBottom(barRect.top());
        if(valRect.top() < baseY + span){
            valRect.moveTop(baseY + span);
        }else if(valRect.bottom() > bottomRect.bottom() - 2 * span){
            valRect.moveBottom(bottomRect.bottom() - 2 * span);
        }
        painter->drawText(valRect,Qt::AlignBottom|Qt::AlignHCenter,QString::number(mesureVal,'f',4));

        /*******************单位***********************/
        valRect.moveTop(valRect.bottom());
        valRect.setRight(baseX - len);
        //painter->setPen(QColor(100,100,100));
        painter->drawText(valRect,Qt::AlignRight|Qt::AlignTop,index.data(ChannelUnit).toString());

        /****************标记********************/
        font.setPixelSize(headRect.height()/2);
        painter->setFont(font);
        painter->setPen(QColor(100,100,100));
        painter->drawText(headRect,Qt::AlignCenter,index.data(ChannelTag).toString());

        /*****************擦除头尾连接**********************/
        painter->setBrush(QBrush(QColor(0,0,0,0)));
        painter->setPen(QPen(Qt::black,1));
        painter->drawRect(bottomRect);
        painter->eraseRect(QRectF(topRect.bottomLeft(), bottomRect.topRight()));

        /*********************按压效果*************************/
        if(option.state & QStyle::State_Sunken && option.state & QStyle::State_HasFocus){
            painter->setPen(QPen(QColor(0,0,255,100),3));
            painter->setBrush(QBrush(QColor(180,180,180,50)));
            painter->drawRoundedRect(rect,6,6);
        }

        painter->restore();
    }
}
Пример #7
0
bool RenderThemeGtk::paintInnerSpinButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
    // We expand the painted area by 2 pixels on the top and bottom and 2 pixels on the right. This
    // is because GTK+ themes want to draw over the text box borders, but WebCore renders the inner
    // spin button inside the text box.
    IntRect expandedRect(rect);
    expandedRect.inflateY(2);
    expandedRect.setWidth(rect.width() + 2);

    WidgetRenderingContext widgetContext(paintInfo.context, expandedRect);
    GtkWidget* widget = gtkSpinButton();
    gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style().direction()));

    IntRect fullSpinButtonRect(IntPoint(), expandedRect.size());
    widgetContext.gtkPaintBox(fullSpinButtonRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "spinbutton");

    bool upPressed = isSpinUpButtonPartPressed(renderObject);
    bool upHovered = isSpinUpButtonPartHovered(renderObject);
    bool controlActive = isEnabled(renderObject) && !isReadOnlyControl(renderObject);
    GtkShadowType shadowType = upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;

    GtkStateType stateType = GTK_STATE_INSENSITIVE;
    if (controlActive) {
        if (isPressed(renderObject) && upPressed)
            stateType = GTK_STATE_ACTIVE;
        else if (isHovered(renderObject) && upHovered)
            stateType = GTK_STATE_PRELIGHT;
        else
            stateType = GTK_STATE_NORMAL;
    }
    IntRect topRect(IntPoint(), expandedRect.size());
    topRect.setHeight(expandedRect.height() / 2);
    widgetContext.gtkPaintBox(topRect, widget, stateType, shadowType, "spinbutton_up");

    // The arrow size/position calculation here is based on the arbitrary gymnastics that happen
    // in gtkspinbutton.c. It isn't pretty there and it isn't pretty here. This manages to make
    // the button look native for many themes though.
    IntRect arrowRect;
    int arrowSize = (expandedRect.width() - 3) / 2;
    arrowSize -= (arrowSize % 2) - 1; // Force odd.
    arrowRect.setWidth(arrowSize);
    arrowRect.setHeight(arrowSize);
    arrowRect.move((expandedRect.width() - arrowRect.width()) / 2,
                   (topRect.height() - arrowRect.height()) / 2 + 1);
    widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_UP, "spinbutton");

    shadowType = isPressed(renderObject) && !upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
    if (controlActive) {
        if (isPressed(renderObject) && !upPressed)
            stateType = GTK_STATE_ACTIVE;
        else if (isHovered(renderObject) && !upHovered)
            stateType = GTK_STATE_PRELIGHT;
        else
            stateType = GTK_STATE_NORMAL;
    }
    IntRect bottomRect(IntPoint(0, expandedRect.height() / 2), expandedRect.size());
    bottomRect.setHeight(expandedRect.height() - bottomRect.y());
    widgetContext.gtkPaintBox(bottomRect, widget, stateType, shadowType, "spinbutton_down");

    arrowRect.setY(arrowRect.y() + bottomRect.y() - 1);
    widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_DOWN, "spinbutton");

    return false;
}
ActivityWindow::ActivityWindow()
	:
	BWindow(BRect(100, 100, 500, 350), B_TRANSLATE_SYSTEM_NAME("ActivityMonitor"),
	B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	}

#ifdef __HAIKU__
	BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 0);
	SetLayout(layout);

	// create GUI

	BMenuBar* menuBar = new BMenuBar("menu");
	layout->AddView(menuBar);

	fLayout = new BGroupLayout(B_VERTICAL);
	float inset = ceilf(be_plain_font->Size() * 0.7);
	fLayout->SetInsets(inset, inset, inset, inset);
	fLayout->SetSpacing(inset);

	BView* top = new BView("top", 0, fLayout);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	layout->AddView(top);

	BMessage viewState;
	int32 count = 0;
	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
			== B_OK; i++) {
		ActivityView* view = new ActivityView("ActivityMonitor", &viewState);
		fLayout->AddItem(view->CreateHistoryLayoutItem());
		fLayout->AddItem(view->CreateLegendLayoutItem());
		count++;
	}
	if (count == 0) {
		// Add default views (memory & CPU usage)
		_AddDefaultView();
		_AddDefaultView();
	}
#else	// !__HAIKU__
	BView *layout = new BView(Bounds(), "topmost", B_FOLLOW_NONE, 0);
	AddChild(layout);

	// create GUI
	BRect mbRect(Bounds());
	mbRect.bottom = 10;
	BMenuBar* menuBar = new BMenuBar(mbRect, "menu");
	layout->AddChild(menuBar);

	BRect topRect(Bounds());
	topRect.top = menuBar->Bounds().bottom + 1;

	BView* top = new BView(topRect, "top", B_FOLLOW_ALL, 0);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	layout->AddChild(top);

	BMessage viewState;
	int32 count = 0;
	ActivityView *aview;
	BRect rect;
	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
			== B_OK; i++) {
		aview = new ActivityView("ActivityMonitor", &viewState);
		if (!rect.IsValid())
			rect = aview->Bounds();
		else
			rect.OffsetBySelf(0.0, aview->Bounds().Height());
		top->AddChild(aview);
		count++;
	}
	if (count == 0)
		top->AddChild(new ActivityView("ActivityMonitor", NULL));

#endif
	// add menu

	// "File" menu
	BMenu* menu = new BMenu(B_TRANSLATE("File"));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Add graph"),
		new BMessage(kMsgAddView)));
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);

	// "Settings" menu
	menu = new BMenu(B_TRANSLATE("Settings"));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS),
		new BMessage(kMsgShowSettings)));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);
}
Пример #9
0
void MScene::drawForeground(QPainter *painter, const QRectF &rect)
{
    Q_D(MScene);

    /* Overlay information on the widgets in development mode */
    if (MApplication::showBoundingRect() || MApplication::showSize() || MApplication::showPosition() || MApplication::showMargins() || MApplication::showObjectNames() || MApplication::showStyleNames()) {
        QList<QGraphicsItem *> itemList = items(rect);
        QList<QGraphicsItem *>::iterator item;

        painter->setFont(TextFont);
        int fontHeight = d->metrics.height();
        QTransform rotationMatrix;
        painter->setTransform(rotationMatrix);

        QList<QGraphicsItem *>::iterator end = itemList.end();
        for (item = itemList.begin(); item != end; ++item) {
            QRectF br = (*item)->boundingRect();
            QPolygonF bp = (*item)->mapToScene(br);

            if (MApplication::showBoundingRect()) {
                if (!dynamic_cast<MApplicationPage *>(*item)) { // filter out page for clarity
                    painter->setOpacity(BoundingRectOpacity);
                    painter->setPen(d->boundingRectLinePen);
                    painter->setBrush(d->boundingRectFillBrush);
                    painter->drawPolygon(bp);
                }
            }

            if (MApplication::showMargins()) {
                // Draw content margins
                QGraphicsLayoutItem *layoutItem = dynamic_cast<QGraphicsLayoutItem *>(*item);
                if (layoutItem) {
                    qreal left, top, right, bottom;
                    layoutItem->getContentsMargins(&left, &top, &right, &bottom);

                    QRectF outerRect = (*item)->mapRectToScene(br);
                    QRectF innerRect = (*item)->mapRectToScene(br.adjusted(left, top, -right, -bottom));

                    QRectF leftRect(outerRect.x(), outerRect.y(), innerRect.x() - outerRect.x(), outerRect.height());
                    QRectF topRect(innerRect.x(), outerRect.y(), innerRect.width(), innerRect.y() - outerRect.y());
                    QRectF rightRect(innerRect.bottomRight().x(), outerRect.y(), outerRect.bottomRight().x() - innerRect.bottomRight().x(), outerRect.height());
                    QRectF bottomRect(innerRect.x(), innerRect.bottomRight().y(), innerRect.width(), outerRect.bottomRight().y() - innerRect.bottomRight().y());

                    painter->setOpacity(0.5);

                    d->fillMarginRectWithPattern(painter, leftRect, leftRect.width());
                    d->fillMarginRectWithPattern(painter, topRect, topRect.height());
                    d->fillMarginRectWithPattern(painter, rightRect, rightRect.width());
                    d->fillMarginRectWithPattern(painter, bottomRect, bottomRect.height());

                }

                painter->setOpacity(1.0);
            }

            if (MApplication::showPosition()) {
                QPointF topLeft = ((*item)->mapToScene(br.topLeft()));
                QString posStr = QString("(%1, %2)").arg(topLeft.x()).arg(topLeft.y());
                painter->setPen(Qt::black);
                painter->drawText(topLeft += QPointF(5, fontHeight), posStr);
                painter->setPen(Qt::white);
                painter->drawText(topLeft -= QPointF(1, 1),  posStr);
            }

            if (MApplication::showSize()) {
                QPointF bottomRight = ((*item)->mapToScene(br.bottomRight()));
                QPointF pos = (*item)->mapToScene(br.topLeft());
                QString sizeStr = QString("%1x%2 (%3,%4)").arg(br.width()).arg(br.height()).arg(pos.x()).arg(pos.y());
                painter->setPen(Qt::black);
                painter->drawText(bottomRight -= QPointF(d->metrics.width(sizeStr), 2), sizeStr);
                painter->setPen(Qt::white);
                painter->drawText(bottomRight -= QPointF(1, 1), sizeStr);
            }

            if (MApplication::showObjectNames()) {
                d->drawObjectNames(painter, item);
            }

            if (MApplication::showStyleNames()) {
                d->drawStyleNames(painter, item);
            }
        }
    }

    bool countingFps = MApplication::logFps() || MApplication::showFps();
    if (countingFps) {
        if (d->fps.frameCount < 0) {
            d->fps.time.restart();
            d->fps.frameCount = 0;
        }
        ++d->fps.frameCount;

        int ms = d->fps.time.elapsed();
        if (ms > FpsRefreshInterval) {
            float fps = d->fps.frameCount * 1000.0f / ms;
            d->fps.time.restart();
            d->fps.frameCount = 0;
            if (MApplication::logFps()) {
                QTime time = d->fps.time.currentTime();
                d->logFpsCounter(&time, fps);
            }
            d->fps.fps = fps;
        }

        if (MApplication::showFps()) {
            d->showFpsCounter(painter, d->fps.fps);
        }

        // this update call makes repainting work as fast
        // as possible, and by that prints useful fps numbers
        QTimer::singleShot(0, this, SLOT(update()));
    } else {
        d->fps.frameCount = -1;
    }

    if (MApplication::emulateTwoFingerGestures() &&
        d->pinchEmulationEnabled)
    {
        static const QPixmap *tapPixmap = MTheme::pixmap("meegotouch-tap");
        QPointF pixmapCenterDelta(tapPixmap->width() / 2, tapPixmap->height() / 2);

        painter->drawPixmap(d->emuPoint1.scenePos() - pixmapCenterDelta, *tapPixmap);
        painter->drawPixmap(d->emuPoint2.scenePos() - pixmapCenterDelta, *tapPixmap);
    }
}