Exemplo n.º 1
0
int
MppTabBar :: computeHeight(int w) const
{
	int x_off = 0;
	int r;
	int n;

	for (r = n = 0; n != ntabs; n++) {
		int dw = computeWidth(n);
		if (x_off != 0 && x_off + dw >= w) {
			x_off = 0;
			r++;
		}
		x_off += dw;
	}
	if (x_off != 0) {
		x_off = 0;
		r++;
	}
	for (n = 0; n != nwidgets; n++) {
		int dw = (widgets[n].pWidget ? 4 : 3) * basic_size;
		if (x_off != 0 && x_off + dw >= w) {
			x_off = 0;
			r++;
		}
		x_off += dw;
	}
	return ((r + 1) * basic_size * 2);
}
Exemplo n.º 2
0
void Widget::updateFinalWidth()
{
    if (m_messageQueue.empty()) {
        return;
    }

    QString position = m_messageQueue.front().data["pos"]->toString();
    int width = computeWidth();

    qobject_cast<QPropertyAnimation*>(m_animation.animationAt(0))->setEndValue(width);
    if (position == "top_left" || position == "tl")
        updateTopLeftAnimation(width);
    else if (position == "top_right" || position == "tr")
        updateTopRightAnimation(width);
    else if (position == "bottom_right" || position == "br")
        updateBottomRightAnimation(width);
    else if (position == "bottom_left" || position == "bl")
        updateBottomLeftAnimation(width);
    else if (position == "top_center" || position == "tc")
        updateTopCenterAnimation(width);
    else if (position == "bottom_center" || position == "bc")
        updateBottomCenterAnimation(width);
    else if (position == "center" || position == "c")
        updateCenterAnimation(width);
}
Exemplo n.º 3
0
int TextRenderer::computeWidth(const char* str)
{
    int width = 0;
    for (const char* ch = str; *ch != 0; ch++) {
        width += computeWidth(*ch);
    }
    return width;
}
Exemplo n.º 4
0
void Widget::updateTopLeftAnimation(QVariant value)
{
    const int finalHeight = getHeight();
    QPoint p(0, 0);
    if (m_settings.has("gui/screen") && !m_settings.get("gui/screen").toString().isEmpty()) {
        p = QDesktopWidget().screenGeometry(m_settings.get("gui/screen").toInt()).topLeft();
    } else if (m_settings.has("gui/absolute_position") && !m_settings.get("gui/absolute_position").toString().isEmpty()) {
        QPoint tmp = stringToPos(m_settings.get("gui/absolute_position").toString());
        if (!tmp.isNull())
            p = tmp;
    }
    //setGeometry(p.x(), p.y(), value.toInt(), finalHeight);
    int width = computeWidth();
    if (width != -1)
        m_computedWidth = width;
    setGeometry(value.toInt()-m_computedWidth, p.y(), m_computedWidth, finalHeight);
    layout()->setSpacing(0);
    show();
}
Exemplo n.º 5
0
void Widget::processMessageQueue()
{
    if (m_messageQueue.empty()) {
        return;
    }

    if (m_animation.state() == QAbstractAnimation::Running ||
            m_visible.isActive()) {
       //(m_animation.totalDuration() - m_animation.currentTime()) < 50) {
        return;
    }

    QFont boldFont = font();
    boldFont.setBold(true);
    Message& m = m_messageQueue.front();
    loadDefaults();
    if (m.data["aot"]->toBool()) {
        setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
        raise();
    }
    setupFont();
    setupColors();
    setupIcon();
    setupTitle();
    setupContent();
    connectForPosition(m.data["pos"]->toString());
    m_animation.setDirection(QAnimationGroup::Forward);
    int width = computeWidth();
    qobject_cast<QPropertyAnimation*>(m_animation.animationAt(0))->setEasingCurve(QEasingCurve::Type(m_settings.get("gui/in_animation").toInt()));
    qobject_cast<QPropertyAnimation*>(m_animation.animationAt(0))->setStartValue(0);
    qobject_cast<QPropertyAnimation*>(m_animation.animationAt(0))->setEndValue(width);
    m_animation.start();
    QString soundCommand = m.data["sc"]->toString();
    if (!soundCommand.isEmpty())
        QProcess::startDetached(soundCommand);
   // m_shortcutGrabber.enableShortcuts();
}
Exemplo n.º 6
0
void
MppTabBar :: paintEvent(QPaintEvent *event)
{
	int ht = computeHeight(width());

	if (ht != height())
		doRepaintEnqueue();

	QPainter paint(this);

	int w = width();
	int h = height();
	int x_off = 0;
	int y_off;
	int n;
	int r;

	paint.setRenderHints(QPainter::Antialiasing, 1);
	paint.setFont(font());

	QColor grey(192,192,192);
	QColor light(128,128,128);
	QColor white(255,255,255);
	QColor black(0,0,0);

	paint.setPen(QPen(grey, 0));
	paint.setBrush(grey);
	paint.drawRoundedRect(QRect(0,0,w,h), 4, 4);

	for (r = n = 0; n != ntabs; n++) {
		int dw = computeWidth(n);
		if (x_off != 0 && x_off + dw >= w) {
			x_off = 0;
			r++;
		}
		y_off = r * basic_size * 2;

		if (isVisible(tabs[n].w)) {
			paint.setPen(QPen(black, 0));
			paint.setBrush(black);
		} else {
			paint.setPen(QPen(light, 0));
			paint.setBrush(light);
		}
		if (tabs[n].flags & FLAG_LEFT) {
			QPoint temp[3] = {
				QPoint(x_off, y_off + basic_size),
				QPoint(x_off + basic_size, y_off + (basic_size / 4)),
				QPoint(x_off + basic_size, y_off + (basic_size * 2) - (basic_size / 4) - 1)
			};
			paint.drawPolygon(temp, 3);

		} else if (tabs[n].flags & FLAG_RIGHT) {
			QPoint temp[3] = {
				QPoint(x_off + dw - basic_size, y_off + (basic_size / 4)),
				QPoint(x_off + dw, y_off + basic_size),
				QPoint(x_off + dw - basic_size, y_off + (basic_size * 2) - (basic_size / 4) - 1)
			};
			paint.drawPolygon(temp, 3);
		}

		tabs[n].area = QRect(x_off + (basic_size / 2), y_off + (basic_size / 4),
		    dw - basic_size, (basic_size * 2) - (basic_size / 2));

		if (isVisible(tabs[n].w)) {
			QRect area(x_off + basic_size, y_off + (basic_size / 4),
			    dw - (2*basic_size), (basic_size * 2) - (basic_size / 2));

			paint.setPen(QPen(white, 0));
			paint.setBrush(white);
			paint.drawRect(area);
		}

		paint.setPen(QPen(black, 0));
		paint.setBrush(black);
		paint.drawText(QRect(x_off + basic_size + (basic_size / 4),
		    y_off + (basic_size / 2),
		    dw - (2 * basic_size) - (basic_size / 2), basic_size),
		    Qt::TextSingleLine | Qt::AlignCenter, tabs[n].name);

		x_off += dw;
	}
	if (x_off != 0) {
		x_off = 0;
		r++;
	}
	for (n = 0; n != nwidgets; n++) {
		int dw = (widgets[n].pWidget ? 4 : 3) * basic_size;
		if (x_off != 0 && x_off + dw >= w) {
			x_off = 0;
			r++;
		}
		y_off = r * basic_size * 2;
		x_off += dw;
		if (widgets[n].pWidget == 0)
			continue;
		widgets[n].area = QRect(x_off - dw, y_off,
		    4 * basic_size, 2 * basic_size);
		widgets[n].pWidget->setGeometry(widgets[n].area);
		QWidget::eventFilter(widgets[n].pWidget, event);
	}
	y_off = (r + 1) * basic_size * 2;
}
Exemplo n.º 7
0
void PatternNoteDisplay::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    int w = width();
    if(w != computeWidth(_padding + _length))
    {
        setWidth(computeWidth(_padding + _length));
    }
    if(ptr == 0)//Most probably a dummy note
        return;

    painter->save();
    QPen pen;
    pen.setColor(Qt::black);
    QBrush brush;
    brush.setColor(Qt::red);
    brush.setStyle(Qt::SolidPattern);

    painter->setPen(pen);
    painter->setBrush(brush);

    w = computeWidth(_length);
    int h = height();

    painter->drawRect(0,0,w,h);

    int progress = _length / w;
    //TODO split channels
    float l=0,r=0;
    int curX = 0;
    int h_2 = h/2;
    int h_2_5 = h_2 - 5;

    int currentSample = _offset;
    int patternLen = ptr->length();
    for(int i=0;i<_length;++i)
    {
        float fl = ptr->Get(0,currentSample);
        float fr = ptr->Get(1,currentSample);
        currentSample = (currentSample + 1) % patternLen;

        fl *= fl;fr *= fr;
        l += fl;
        r += fr;

        if(i%progress == 0)
        {
            l = sqrt((l/progress));
            r = sqrt((r/progress));
            float avg = 20 * log((l+r)/2) / log(10);
            if(avg < -100)
                avg = -100;
            if(avg >= 0)
                avg = -0.000001;
            int velocity = ((100+avg)/100.0 *(h_2_5)) ;

            painter->drawLine(curX,h_2 - velocity, curX, h_2+velocity);
            ++curX;

            l = 0;
            r = 0;
        }
    }
    painter->restore();
}
Exemplo n.º 8
0
QPainterPath ConnectionItem::drawPath(const QPointF& start, const QPointF& end)
{
    const qreal RADIUS = 1.5 * ConnectorItem::SIZE;
    const qreal ARC_RECT_SIZE = 2*RADIUS;
    QRectF arcRect(0, 0, ARC_RECT_SIZE, ARC_RECT_SIZE);
    qreal xDiff = end.x() - start.x();
    qreal yDiff = end.y() - start.y();
    qreal yOffset = 0;
    
    if(yDiff <= 0)
        yOffset = yDiff;
    else
        yOffset = 0;
    
    QPainterPath path;
    
    path.moveTo(start);
    if(xDiff > 0)
    {
        // the connections points forward
        if(xDiff > 2*RADIUS)
        {
            // start and end are so far from each other that the can
            // be directly connected (without loop)
            if(yDiff > 0)
            {
                // the connection points downwards
                if(fabs(yDiff) < 2*RADIUS)
                {
                    // start and end point are so close too each other that
                    // the arcs must be less than 90 degrees
                    qreal angle = computeAngle(RADIUS, yDiff/2);
                    qreal width = computeWidth(yDiff/2, angle);
                    
                    arcRect.moveTo(start.x() + xDiff/2 - width - RADIUS, start.y());
                    path.arcTo(arcRect, 90, -angle);
                    arcRect.moveTo(start.x() + xDiff/2 + width - RADIUS, end.y() - ARC_RECT_SIZE);
                    path.arcTo(arcRect, -90 - angle, angle);
                }
                else
                {
                    // two 90 degree arcs are possible
                    arcRect.moveTo(start.x() + xDiff/2 - ARC_RECT_SIZE, start.y());
                    path.arcTo(arcRect, 90, -90);
                    arcRect.moveTo(start.x() + xDiff/2, end.y() - ARC_RECT_SIZE);
                    path.arcTo(arcRect, 180, 90);
                }
            }
            else
            {
                // the connection points upwards
                if(fabs(yDiff) < 2*RADIUS)
                {
                    // start and end point are so close too each other that
                    // the arcs must be less than 90 degrees
                    qreal angle = computeAngle(RADIUS, yDiff/2);
                    qreal width = computeWidth(yDiff/2, angle);
                    
                    arcRect.moveTo(start.x() + xDiff/2 - width - RADIUS, start.y() - ARC_RECT_SIZE);
                    path.arcTo(arcRect, 270, angle);
                    arcRect.moveTo(start.x() + xDiff/2 + width - RADIUS, end.y());
                    path.arcTo(arcRect, 90 + angle, -angle);
                }
                else
                {
                    // two 90 degree arcs are possible
                    arcRect.moveTo(start.x() + xDiff/2 - ARC_RECT_SIZE, start.y() - ARC_RECT_SIZE);
                    path.arcTo(arcRect, 270, 90);
                    arcRect.moveTo(start.x() + xDiff/2, end.y());
                    path.arcTo(arcRect, 180, -90);
                }
            }
        }
        else
        {
            // start and end are so close to each other to each other
            // that the connections must have loop
            arcRect.moveTo(start.x() + xDiff/2 - RADIUS, start.y() - ARC_RECT_SIZE);
            path.arcTo(arcRect, -90, 90);
            arcRect.moveTo(start.x() + xDiff/2 - RADIUS, start.y() + yOffset - 2*RADIUS);
            path.arcTo(arcRect, 0, 90);
            arcRect.moveTo(start.x() + xDiff/2 - RADIUS, start.y() + yOffset - 2*RADIUS);
            path.arcTo(arcRect, 90, 90);
            arcRect.moveTo(start.x() + xDiff/2 - RADIUS, end.y() - ARC_RECT_SIZE);
            path.arcTo(arcRect, 180, 90);
        }
    }
    else
    {
        // the connections points backward
        if(fabs(yDiff) > 4 * RADIUS)
        {            
            // start and end are so far from each other that the can
            // be directly with a line between the to operators
            if(yDiff > 0)
            {
                // the connection points downwards
                arcRect.moveTo(start.x() - RADIUS, start.y());
                path.arcTo(arcRect, 90, -90);
                arcRect.moveTo(start.x() - RADIUS, start.y() + yDiff/2 - ARC_RECT_SIZE);
                path.arcTo(arcRect, 0, -90);
                arcRect.moveTo(end.x() - RADIUS, start.y() + yDiff/2);
                path.arcTo(arcRect, 90, 90);
                arcRect.moveTo(end.x() - RADIUS, end.y() - ARC_RECT_SIZE);
                path.arcTo(arcRect, 180, 90);
            }
            else
            {
                // the connection points upwards
                arcRect.moveTo(start.x() - RADIUS, start.y() - ARC_RECT_SIZE);
                path.arcTo(arcRect, 270, 90);
                arcRect.moveTo(start.x() - RADIUS, start.y() + yDiff/2);
                path.arcTo(arcRect, 0, 90);
                arcRect.moveTo(end.x() - RADIUS, start.y() + yDiff/2 - ARC_RECT_SIZE);
                path.arcTo(arcRect, 270, -90);
                arcRect.moveTo(end.x() - RADIUS, end.y());
                path.arcTo(arcRect, 180, -90);
            }
        }
        else
        {
            // start and end are so close to each other to each other
            // that the connection must run around one of the operators
            arcRect.moveTo(start.x() - RADIUS, start.y() - ARC_RECT_SIZE);
            path.arcTo(arcRect, -90, 90);
            arcRect.moveTo(start.x() - RADIUS, start.y() - ARC_RECT_SIZE + yOffset - EXTRA_HEIGHT);
            path.arcTo(arcRect, 0, 90);
            arcRect.moveTo(end.x() - RADIUS, start.y() - ARC_RECT_SIZE + yOffset - EXTRA_HEIGHT);
            path.arcTo(arcRect, 90, 90);
            arcRect.moveTo(end.x() - RADIUS, end.y() - ARC_RECT_SIZE);
            path.arcTo(arcRect, 180, 90);
        }
    }
    path.lineTo(end);
    
    return path;
}