Example #1
0
    QImage *createArrowBackground(const QMatrix &matrix) const
    {
        QRect scaledRect;
        scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height()));

        QImage *image = new QImage(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied);
        image->fill(QColor(0, 0, 0, 0).rgba());
        QPainter painter(image);
        painter.setRenderHint(QPainter::SmoothPixmapTransform);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setPen(Qt::NoPen);

        if (Colors::useEightBitPalette){
            painter.setPen(QColor(120, 120, 120));
            if (this->pressed)
                painter.setBrush(QColor(60, 60, 60));
            else if (this->highlighted)
                painter.setBrush(QColor(100, 100, 100));
            else
                painter.setBrush(QColor(80, 80, 80));
        }
        else {
            QLinearGradient outlinebrush(0, 0, 0, scaledRect.height());
            QLinearGradient brush(0, 0, 0, scaledRect.height());

            brush.setSpread(QLinearGradient::PadSpread);
            QColor highlight(255, 255, 255, 70);
            QColor shadow(0, 0, 0, 70);
            QColor sunken(220, 220, 220, 30);
            QColor normal1 = QColor(200, 170, 160, 50);
            QColor normal2 = QColor(50, 10, 0, 50);

           if (pressed) {
               outlinebrush.setColorAt(0.0f, shadow);
               outlinebrush.setColorAt(1.0f, highlight);
               brush.setColorAt(0.0f, sunken);
               painter.setPen(Qt::NoPen);
           } else {
               outlinebrush.setColorAt(1.0f, shadow);
               outlinebrush.setColorAt(0.0f, highlight);
               brush.setColorAt(0.0f, normal1);
               if (!this->highlighted)
                   brush.setColorAt(1.0f, normal2);
               painter.setPen(QPen(outlinebrush, 1));
           }
           painter.setBrush(brush);
        }

        painter.drawRect(0, 0, scaledRect.width(), scaledRect.height());

        float xOff = scaledRect.width() / 2;
        float yOff = scaledRect.height() / 2;
        float sizex = 3.0f * matrix.m11();
        float sizey = 1.5f * matrix.m22();
        if (this->type == TextButton::UP)
            sizey *= -1;
        QPainterPath path;
        path.moveTo(xOff, yOff + (5 * sizey));
        path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey));
        path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey));
        path.lineTo(xOff, yOff + (5 * sizey));
        painter.drawPath(path);

        return image;
    }
Example #2
0
void HistogramItem::drawBar(QPainter *painter,
   Qt::Orientation, const QRect& rect) const
{
   painter->save();

   const QColor color(painter->pen().color());
#if QT_VERSION >= 0x040000
   const QRect r = rect.normalized();
#else
   const QRect r = rect.normalize();
#endif

   const int factor = 125;
   const QColor light(color.light(factor));
   const QColor dark(color.dark(factor));

   painter->setBrush(color);
   painter->setPen(Qt::NoPen);
   QwtPainter::drawRect(painter, r.x() + 1, r.y() + 1,
      r.width() - 2, r.height() - 2);
   painter->setBrush(Qt::NoBrush);

   painter->setPen(QPen(light, 2));
#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter,
      r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2);
#else
   QwtPainter::drawLine(painter,
      r.left(), r.top() + 2, r.right() + 1, r.top() + 2);
#endif

   painter->setPen(QPen(dark, 2));
#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter, 
      r.left() + 1, r.bottom(), r.right() + 1, r.bottom());
#else
   QwtPainter::drawLine(painter, 
      r.left(), r.bottom(), r.right() + 1, r.bottom());
#endif

   painter->setPen(QPen(light, 1));

#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter, 
      r.left(), r.top() + 1, r.left(), r.bottom());
   QwtPainter::drawLine(painter,
      r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1);
#else
   QwtPainter::drawLine(painter, 
      r.left(), r.top() + 1, r.left(), r.bottom() + 1);
   QwtPainter::drawLine(painter,
      r.left() + 1, r.top() + 2, r.left() + 1, r.bottom());
#endif

   painter->setPen(QPen(dark, 1));

#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter, 
      r.right() + 1, r.top() + 1, r.right() + 1, r.bottom());
   QwtPainter::drawLine(painter, 
      r.right(), r.top() + 2, r.right(), r.bottom() - 1);
#else
   QwtPainter::drawLine(painter, 
      r.right() + 1, r.top() + 1, r.right() + 1, r.bottom() + 1);
   QwtPainter::drawLine(painter, 
      r.right(), r.top() + 2, r.right(), r.bottom());
#endif

   painter->restore();
}
QRegion QDecorationWindows::region(const QWidget *widget, const QRect &rect, int type)
{
    Qt::WindowFlags flags = widget->windowFlags();
    bool hasTitle = flags & Qt::WindowTitleHint;
    bool hasSysMenu = flags & Qt::WindowSystemMenuHint;
    bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint;
    bool hasMinimize = flags & Qt::WindowMinimizeButtonHint;
    bool hasMaximize = flags & Qt::WindowMaximizeButtonHint;
    const QFontMetrics fontMetrics = QApplication::fontMetrics();
    int titleHeight = hasTitle ? qMax(20, fontMetrics.height()) : 0;
    int state = widget->windowState();
    bool isMinimized = state & Qt::WindowMinimized;
    bool isMaximized = state & Qt::WindowMaximized;

    QRegion region;
    switch (type) {
    case Menu: {
        if (hasSysMenu) {
            region = QRect(rect.left() + 2, rect.top() - titleHeight,
                           menu_width, titleHeight);
        }
    }
    break;

    case Title: {
        QRect r(rect.left()
                + (hasSysMenu ? menu_width + 4: 0),
                rect.top() - titleHeight,
                rect.width()
                - (hasSysMenu ? menu_width : 0)
                - close_width
                - (hasMaximize ? maximize_width : 0)
                - (hasMinimize ? minimize_width : 0)
                - (hasContextHelp ? help_width : 0)
                - 3,
                titleHeight);
        if (r.width() > 0)
            region = r;
    }
    break;
    case Help: {
        if (hasContextHelp) {
            QRect r(rect.right()
                    - close_width
                    - (hasMaximize ? maximize_width : 0)
                    - (hasMinimize ? minimize_width : 0)
                    - help_width - 3, rect.top() - titleHeight,
                    help_width, titleHeight);
            if (r.left() > rect.left() + titleHeight)
                region = r;
        }
    }
    break;

    case Minimize: {
        if (hasMinimize && !isMinimized) {
            QRect r(rect.right() - close_width
                    - (hasMaximize ? maximize_width : 0)
                    - minimize_width - 3, rect.top() - titleHeight,
                    minimize_width, titleHeight);
            if (r.left() > rect.left() + titleHeight)
                region = r;
        }
    }
    break;

    case Maximize: {
        if (hasMaximize && !isMaximized) {
            QRect r(rect.right() - close_width - maximize_width - 3,
                    rect.top() - titleHeight, maximize_width, titleHeight);
            if (r.left() > rect.left() + titleHeight)
                region = r;
        }
    }
    break;

    case Normalize: {
        if (hasMinimize && isMinimized) {
            QRect r(rect.right() - close_width
                    - (hasMaximize ? maximize_width : 0)
                    - minimize_width - 3, rect.top() - titleHeight,
                    minimize_width, titleHeight);
            if (r.left() > rect.left() + titleHeight)
                region = r;
        } else if (hasMaximize && isMaximized) {
            QRect r(rect.right() - close_width - maximize_width - 3,
                    rect.top() - titleHeight, maximize_width, titleHeight);
            if (r.left() > rect.left() + titleHeight)
                region = r;
        }
    }
    break;

    case Close: {
        QRect r(rect.right() - close_width - 1, rect.top() - titleHeight,
                close_width, titleHeight);
        if (r.left() > rect.left() + titleHeight)
            region = r;
    }
    break;

    default:
        region = QDecorationDefault::region(widget, rect, type);
        break;
    }

    return region;
}
Example #4
0
void ccHistogramWindow::mouseMoveEvent(QMouseEvent *event)
{
	if (event->buttons() & Qt::LeftButton)
	{
		if (m_sfInteractionMode)
		{
			QPoint mousePos = event->pos();
			if (m_histogram)
			{
				QRect rect = m_histogram->rect();
				mousePos.setX(std::min(rect.x()+rect.width(),std::max(rect.x(),mousePos.x())));
			}

			switch(m_selectedItem)
			{
			case NONE:
				//nothing to do
				break;
			case LEFT_AREA:
				if (m_areaLeft)
				{
					double newValue = m_areaLeft->pixelToKey(mousePos.x());
					if (m_areaRight)
						newValue = std::min(newValue,m_areaRight->currentVal());
					setMinDispValue(newValue);
				}
				break;
			case RIGHT_AREA:
				if (m_areaRight)
				{
					double newValue = m_areaRight->pixelToKey(mousePos.x());
					if (m_areaLeft)
						newValue = std::max(newValue,m_areaLeft->currentVal());
					setMaxDispValue(newValue);
				}
				break;
			case BOTH_AREAS:
				{
					int dx = m_lastMouseClick.x() - mousePos.x();
					if (dx < -2)
					{
						//going to the right
						m_selectedItem = RIGHT_AREA;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					else if (dx > 2)
					{
						//going to the left
						m_selectedItem = LEFT_AREA;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					//else: nothing we can do right now!
				}
				break;
			case LEFT_ARROW:
				if (m_arrowLeft)
				{
					double newValue = m_arrowLeft->pixelToKey(mousePos.x());
					if (m_arrowRight)
						newValue = std::min(newValue,m_arrowRight->currentVal());
					setMinSatValue(newValue);
				}
				break;
			case RIGHT_ARROW:
				if (m_arrowRight)
				{
					double newValue = m_arrowRight->pixelToKey(mousePos.x());
					if (m_arrowLeft)
						newValue = std::max(newValue,m_arrowLeft->currentVal());
					setMaxSatValue(newValue);
				}
				break;
			case BOTH_ARROWS:
				{
					int dx = m_lastMouseClick.x() - mousePos.x();
					if (dx < -2)
					{
						//going to the right
						m_selectedItem = RIGHT_ARROW;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					else if (dx > 2)
					{
						//going to the left
						m_selectedItem = LEFT_ARROW;
						//call the same method again
						mouseMoveEvent(event);
						return;
					}
					//else: nothing we can do right now!
				}
				break;
			default:
				assert(false);
				break;
			}
		}
		else
		{
			if (m_histogram && !m_histoValues.empty())
			{
				QRect roi = m_histogram->rect();
				if (roi.contains(event->pos(),false))
				{
					m_drawVerticalIndicator = true;

					int verticalIndicatorPosition = (static_cast<int>(m_histoValues.size()) * (event->x() - roi.x())) / roi.width();
					m_verticalIndicatorPositionPercent = static_cast<double>(verticalIndicatorPosition) / m_histoValues.size();

					refresh();
				}
			}
		}
	}
	else
	{
		event->ignore();
	}
}
Example #5
0
void TracePainter::drawPage(int i, int j)
{
    // Calculate the number of components by vertical
    int from_component = (j == 0) ? 0 : j * components_per_page;
    int to_component = from_component + components_per_page - 1;

    if (to_component >= model->getVisibleComponents().size())
    {
        to_component = model->getVisibleComponents().size() - 1;
    }

    timePerPage = (i > 0) ? timePerFullPage : timePerFirstPage;

    Time min_time = model->getMinTime();
    if (i > 0) min_time = min_time + timePerFirstPage + timePerFullPage * (i - 1);

    Time max_time = min_time + timePerPage;
    if (max_time > model->getMaxTime())
    {
        max_time = model->getMaxTime();
    }

    // FIXME: this temporary change of model is ugly.
    TraceModelPtr saved_model = model;
    model = model->setRange(min_time, max_time);

    if (i == 0)
    {
        left_margin = left_margin1;
    }
    else
    {
        left_margin = left_margin2;
    }

    drawComponentsList(from_component, to_component, i == 0);
    QApplication::processEvents();
    if (state_ == Canceled) return;

    painter->setClipRect(left_margin, y_unparented - lifeline_stepping / 2,
        width - right_margin-left_margin, components_per_page * lifeline_stepping);

    drawEvents(from_component, to_component);
    if (state_ == Canceled) return;

    drawStates(from_component, to_component);
    if (state_ == Canceled) return;

    drawGroups(from_component, to_component);
    if (state_ == Canceled) return;

    if (printer_flag)
    {
        // Draw timeline
        painter->setClipRect(0, 0, width, height);
        drawTimeline(painter, 0, height - (timeline_text_top+text_height));

        // Draw labels with page numbers
        int x, y; QRect r;

        x = 0; y = 0;
        r = drawPageMarker(0, i+1, pages_horizontally, x, y, true);
        x = width - r.width(); y = r.height()/2;
        drawPageMarker(painter, i+1, pages_horizontally, x, y, true);

        x = 0; y = 0;
        r = drawPageMarker(0, j+1, pages_vertically, x, y, false);
        x = r.width()/2; y = height - r.height();
        drawPageMarker(painter, j+1, pages_vertically, x, y, false);

    }

    model = saved_model;
}