示例#1
0
void WidgetHighlighter::paintEvent(QPaintEvent* event) {
    Q_UNUSED(event);

    //Painting the WidgetHighlighter over its parent widget with a
    //semi-transparent color is the best I could get. However, it has some
    //flaws. For example, a QMenu does not highlight its menu button. And some
    //widgets may be hardly highlighted if their background color is almost the
    //same as the highlight color (although it should not happen very often).
    //
    //Changing the parent widget palette does not work because some widgets
    //(like tool buttons) don't paint a background, only paint the text and get
    //its parent widget background. Forcing the painting of the background with
    //some color role does not help, as it may look ugly in some styles that use
    //a gradient for the background. Changing the palette has one benefit,
    //though, as it also changes the palette from the children widgets, which
    //means that a QMenu would highlight its menu button.
    //
    //Ideally, the highlighter should lighten its parent widget but when it is
    //too bright (for example, the white background of a text edit). In that
    //case, the parent widget should be darkened. To do this, however, the
    //WidgetHighlighter must know how its parent widget is painted.
    //
    //Calling QPixmap::grabWidget from the WidgetHighlighter::paintEvent is not
    //good, as it triggers a recursive paint event in its parent (provided the
    //WidgetHighlighter paintEvent is guarded against a recursive call, else the
    //application would directly hang). Calling it from the updateProgress and
    //storing the QPixmap in memory would theoretically work, but it showed some
    //strange artifacts.
    //
    //Setting a custom QGraphicsEffect does not seem like a good idea, as Qt can
    //be compiled without them, and because, as far as I know, only one effect
    //can  be used on a widget at a time (as making a Composite design pattern
    //with something like QComposedGraphicsEffect class is pretty easy and there
    //is no such class, I presume that it is not a good idea to use several
    //effects on the same widget, at least for now).
    //
    //Anyway, I do not know how to check whether a picture is light or dark
    //quickly enough to be done in a realtime animation, so... a
    //semi-transparent colored child widget is good enough until someone makes
    //something better ;)
    //
    //However, filling the whole widget and animating it is too CPU intensive
    //when tinting a parent widget with lots of child widgets (for example, the
    //main widget in showfoto). So, instead of tinting the whole parent only
    //a frame is painted and animated. In this case, the frame gets its full
    //opacity at the peak of the animation, instead of half the opacity as used
    //when tinting the whole widget.

    //The inactive palette does not usually have a lot of contrast between
    //normal color and highlight color (for example, a QStatusBar in Oxygen
    //style). The highlight color from the active palette is used in every case
    //to ensure that the widget is clearly highlighted, even if the window is
    //not the active one.
    QColor color = mTargetWidget->palette().color(QPalette::Active,
                                                  QPalette::Highlight);

    QPainter painter(this);
    painter.setOpacity(mProgress);

    QPen pen;
    pen.setWidth(mFrameWidth);
    pen.setColor(color);
    painter.setPen(pen);

    //Third and fourth arguments are width and height, not end coordinates
    painter.drawRect(pen.width() / 2, pen.width() / 2,
                     width() - pen.width(), height() - pen.width());
    painter.end();
}
示例#2
0
/****************************************************************************
 * Small right-click menu for rate control
 ****************************************************************************/
void SpeedLabel::showSpeedMenu( QPoint pos )
{
    speedControlMenu->exec( QCursor::pos() - pos
                          + QPoint( 0, height() ) );
}
示例#3
0
render_scope::render_scope()
{
	EXT_CALL(glBindFramebuffer)(EXT_MACRO(GL_FRAMEBUFFER), framebuffer_id);
	glViewport(0, 0, width(), height());
}
示例#4
0
文件: BBTrack.cpp 项目: uro5h/lmms
void BBTCOView::paintEvent( QPaintEvent * )
{
	QPainter painter( this );

	if( !needsUpdate() )
	{
		painter.drawPixmap( 0, 0, m_paintPixmap );
		return;
	}

	setNeedsUpdate( false );

	m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() 
		? QPixmap( size() ) : m_paintPixmap;

	QPainter p( &m_paintPixmap );

	QLinearGradient lingrad( 0, 0, 0, height() );
	QColor c;
	bool muted = m_bbTCO->getTrack()->isMuted() || m_bbTCO->isMuted();
	
	// state: selected, muted, default, user selected
	c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor() 
		: ( m_bbTCO->m_useStyleColor ? painter.background().color() 
		: m_bbTCO->colorObj() ) );
	
	lingrad.setColorAt( 0, c.light( 130 ) );
	lingrad.setColorAt( 1, c.light( 70 ) );
	
	if( gradient() )
	{
		p.fillRect( rect(), lingrad );
	}
	else
	{
		p.fillRect( rect(), c );
	}
	
	// bar lines
	const int lineSize = 3;
	p.setPen( c.darker( 200 ) );

	tact_t t = Engine::getBBTrackContainer()->lengthOfBB( m_bbTCO->bbTrackIndex() );
	if( m_bbTCO->length() > MidiTime::ticksPerTact() && t > 0 )
	{
		for( int x = static_cast<int>( t * pixelsPerTact() );
								x < width() - 2;
			x += static_cast<int>( t * pixelsPerTact() ) )
		{
			p.drawLine( x, TCO_BORDER_WIDTH, x, TCO_BORDER_WIDTH + lineSize );
			p.drawLine( x, rect().bottom() - ( TCO_BORDER_WIDTH + lineSize ),
			 	x, rect().bottom() - TCO_BORDER_WIDTH );
		}
	}

	// pattern name
	p.setRenderHint( QPainter::TextAntialiasing );

	if(  m_staticTextName.text() != m_bbTCO->name() )
	{
		m_staticTextName.setText( m_bbTCO->name() );
	}

	QFont font;
	font.setHintingPreference( QFont::PreferFullHinting );
	font.setPointSize( 8 );
	p.setFont( font );

	const int textTop = TCO_BORDER_WIDTH + 1;
	const int textLeft = TCO_BORDER_WIDTH + 1;

	p.setPen( textShadowColor() );
	p.drawStaticText( textLeft + 1, textTop + 1, m_staticTextName );
	p.setPen( textColor() );
	p.drawStaticText( textLeft, textTop, m_staticTextName );

	// inner border
	p.setPen( c.lighter( 130 ) );
	p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH,
		rect().bottom() - TCO_BORDER_WIDTH );	

	// outer border
	p.setPen( c.darker( 300 ) );
	p.drawRect( 0, 0, rect().right(), rect().bottom() );
	
	// draw the 'muted' pixmap only if the pattern was manualy muted
	if( m_bbTCO->isMuted() )
	{
		const int spacing = TCO_BORDER_WIDTH;
		const int size = 14;
		p.drawPixmap( spacing, height() - ( size + spacing ),
			embed::getIconPixmap( "muted", size, size ) );
	}
	
	p.end();
	
	painter.drawPixmap( 0, 0, m_paintPixmap );
	
}
示例#5
0
void RenderView::layout()
{
    if (!document().paginated())
        setPageLogicalHeight(0);

    if (shouldUsePrintingLayout())
        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth();

    SubtreeLayoutScope layoutScope(this);

    // Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
    bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
    if (relayoutChildren) {
        layoutScope.setChildNeedsLayout(this);
        for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
            if (child->isSVGRoot())
                continue;

            if ((child->isBox() && toRenderBox(child)->hasRelativeLogicalHeight())
                    || child->style()->logicalHeight().isPercent()
                    || child->style()->logicalMinHeight().isPercent()
                    || child->style()->logicalMaxHeight().isPercent())
                layoutScope.setChildNeedsLayout(child);
        }

        if (document().svgExtensions())
            document().accessSVGExtensions()->invalidateSVGRootsWithRelativeLengthDescendents(&layoutScope);
    }

    ASSERT(!m_layoutState);
    if (!needsLayout())
        return;

    LayoutState state;
    initializeLayoutState(state);

    m_pageLogicalHeightChanged = false;
    m_layoutState = &state;

    layoutContent(state);

    if (m_frameView->partialLayout().isStopping()) {
        m_layoutState = 0;
        return;
    }

#ifndef NDEBUG
    checkLayoutState(state);
#endif
    m_layoutState = 0;
    clearNeedsLayout();
}
示例#6
0
文件: Pattern.cpp 项目: diizy/lmms
void PatternView::mousePressEvent( QMouseEvent * _me )
{
	if( _me->button() == Qt::LeftButton &&
				m_pat->m_patternType == Pattern::BeatPattern &&
				( fixedTCOs() || pixelsPerTact() >= 96 ||
				m_pat->m_steps != MidiTime::stepsPerTact() ) &&
				_me->y() > height() - s_stepBtnOff->height() )

	// when mouse button is pressed in beat/bassline -mode

	{
//	get the step number that was clicked on and
//	do calculations in floats to prevent rounding errors...
		float tmp = ( ( float(_me->x()) - TCO_BORDER_WIDTH ) *
				float( m_pat -> m_steps ) ) / float(width() - TCO_BORDER_WIDTH*2);

		int step = int( tmp );

//	debugging to ensure we get the correct step...
//		qDebug( "Step (%f) %d", tmp, step );

		if( step >= m_pat->m_steps )
		{
			qDebug( "Something went wrong in pattern.cpp: step %d doesn't exist in pattern!", step );
			return;
		}

		Note * n = m_pat->noteAtStep( step );

		// if note at step not found, ensureBeatNotes and try again
		if( n == NULL )
		{
			m_pat -> ensureBeatNotes();
			n = m_pat->noteAtStep( step );
			if( n == NULL ) // still can't find a note? bail!
			{
				qDebug( "Something went wrong in pattern.cpp: couldn't add note at step %d!", step );
				return;
			}
		}
		else // note at step found
		{
			if( n->length() < 0 )
			{
				n->setLength( 0 );	// set note as enabled beat note
			}
			else
			{
				n->setLength( -DefaultTicksPerTact );	// set note as disabled beat note
			}
		}

		Engine::getSong()->setModified();
		update();

		if( gui->pianoRoll()->currentPattern() == m_pat )
		{
			gui->pianoRoll()->update();
		}
	}
	else

	// if not in beat/bassline -mode, let parent class handle the event

	{
		TrackContentObjectView::mousePressEvent( _me );
	}
}
/*
    Set up the layout.
*/
void QTabWidget::setUpLayout( bool onlyCheck )
{
    if ( onlyCheck && !d->dirty )
	return; // nothing to do

    if ( !isVisible() ) {
	d->dirty = TRUE;
	return; // we'll do it later
    }

    QSize t( 0, d->stack->frameWidth() );
    if ( d->tabs->isVisibleTo(this) )
	t = d->tabs->sizeHint();
    int lcw = 0;
    if ( d->leftCornerWidget && d->leftCornerWidget->isVisible()  ) {
	QSize sz = d->leftCornerWidget->sizeHint();
	d->leftCornerWidget->resize(sz);
	lcw = sz.width();
	if ( t.height() > lcw )
	    lcw = t.height();
     }
    int rcw = 0;
    if ( d->rightCornerWidget && d->rightCornerWidget->isVisible() ) {
	QSize sz = d->rightCornerWidget->sizeHint();
	d->rightCornerWidget->resize(sz);
	rcw = sz.width();
	if ( t.height() > rcw )
	    rcw = t.height();
    }
    int tw = width() - lcw - rcw;
    if ( t.width() > tw )
	t.setWidth( tw );
    int lw = d->stack->lineWidth();
    bool reverse = QApplication::reverseLayout();
    int tabx, taby, stacky, exty, exth, overlap;

    exth = style().pixelMetric( QStyle::PM_TabBarBaseHeight, this );
    overlap = style().pixelMetric( QStyle::PM_TabBarBaseOverlap, this );

    if ( reverse )
	tabx = QMIN( width() - t.width(), width() - t.width() - lw + 2 ) - lcw;
    else
	tabx = QMAX( 0, lw - 2 ) + lcw;
    if ( d->pos == Bottom ) {
	taby = height() - t.height() - lw;
	stacky = 0;
	exty = taby - (exth - overlap);
    } else { // Top
	taby = 0;
	stacky = t.height()-lw + (exth - overlap);
	exty = taby + t.height() - overlap;
    }

    // do alignment
    int alignment = style().styleHint( QStyle::SH_TabBar_Alignment, this );
    if ( alignment != AlignLeft && t.width() < width() ) {
	if ( alignment == AlignHCenter )
	    tabx += (width()-lcw-rcw)/2 - t.width()/2;
	else if ( alignment == AlignRight )
	    tabx += width() - t.width() - rcw;
    }

    d->tabs->setGeometry( tabx, taby, t.width(), t.height() );
    d->tabBase->setGeometry( 0, exty, width(), exth );
    if ( exth == 0 )
	d->tabBase->hide();
    else
	d->tabBase->show();

    d->stack->setGeometry( 0, stacky, width(), height() - (exth-overlap) -
			   t.height()+QMAX(0, lw-2));

    d->dirty = FALSE;

    // move cornerwidgets
    if ( d->leftCornerWidget ) {
	int y = ( t.height() / 2 ) - ( d->leftCornerWidget->height() / 2 );
	int x = ( reverse ? width() - lcw + y : y );
	d->leftCornerWidget->move( x, y + taby );
    }
    if ( d->rightCornerWidget ) {
	int y = ( t.height() / 2 ) - ( d->rightCornerWidget->height() / 2 );

    if ( !onlyCheck )
	update();
    updateGeometry();
    if ( autoMask() )
	updateMask();
	int x = ( reverse ? y : width() - rcw + y );
	d->rightCornerWidget->move( x, y + taby );
    }
}
示例#8
0
bool MainWindowPlugin::canIncreaseWindowHeight() const
{
    QSize maxWindowsSize = getMaxWindowSize();
    return height() < maxWindowsSize.height();
}
示例#9
0
bool MainWindowPlugin::canDecreaseWindowHeight() const
{
    QSize minWindowsSize = PLUGIN_WINDOW_MIN_SIZE;
    return height() > minWindowsSize.height();
}
示例#10
0
文件: title.cpp 项目: jubalh/tdesktop
void TitleHider::paintEvent(QPaintEvent *e) {
	QPainter p(this);
	p.setOpacity(_level * st::layerAlpha);
	p.fillRect(App::main()->dlgsWidth() - st::dlgShadow, 0, width() + st::dlgShadow - App::main()->dlgsWidth(), height(), st::layerBG->b);
}
示例#11
0
void Graph::paintEvent(QPaintEvent * ) {
    QPainter paint(this);
    paint.save();

    int gx1 = hPadding();
    int gy1 = vPadding();
    int gx2 = width() - hPadding();
    int gy2 = height() - vPadding();

    //paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1);

    QFontMetrics fm(font());
    //QRect brect;

    // get the dimensions of the title label and then draw it
    if(title().length() > 0) {
        fm = QFontMetrics(titleFont());
        //brect = fm.boundingRect(title());
        paint.setFont(titleFont());
        paint.drawText(gx1, gy1, gx2 - gx1, fm.height(), titleAlignment(), title());
        gy1 += fm.height();
    }

    // we need to do some drawing that depends on some other elements having
    // already been placed... since those require that these have already been
    // placed we will just save the old value of gy2 and then calculate the
    // value that we should have after the other code runs without actually
    // drawing anything right now
    int gy2_old = gy2;
    if(dataLabel().length() > 0) {
        fm = QFontMetrics(dataLabelFont());
        gy2 -= fm.height();
    }
    fm = QFontMetrics(dataFont());
    QMapIterator<int, GReference> dlit = _data.begin();
    double tlh = 0.0;
    for(dlit = _data.begin(); dlit != _data.end(); ++dlit) {
        tlh = QMAX(sin45deg * fm.width(dlit.data().first), tlh);
    }
    // don't change this variable as we use it later
    int th = (tlh == 0.0 ? 0 : (int)(tlh + (fm.height() * sin45deg)) + 2);
    fm = QFontMetrics(valueFont());
    if(fm.height() > th) th = fm.height();
    gy2 -= th;


    // get the dimensions of the value label then draw it
    if(valueLabel().length() > 0) {
        fm = QFontMetrics(valueLabelFont());
        //brect = fm.boundingRect(valueLabel());
        paint.setFont(valueLabelFont());
        paint.save();
        paint.rotate(-90);
        paint.drawText(-gy2, gx1, gy2 - gy1, fm.height(), valueLabelAlignment(), valueLabel());
        paint.restore();
        gx1 += fm.height();
    }

    fm = QFontMetrics(valueFont());

    QString min_str = QString().sprintf("%-.0f",minValue());
    QString org_str = ( minValue() == 0.0 ? QString::null : "0" );
    QString max_str = QString().sprintf("%-.0f",maxValue());

    int width = QMAX(fm.width(min_str), fm.width(max_str));
    if(org_str.length() > 0) width = QMAX(width, fm.width(org_str));

    gx1 += (width + 5);

    int gy_max = gy1;
    int gy_min = gy2 - 1;
    int gy_org = gy_min;

    paint.setFont(valueFont());
    int tfa = AlignTop | AlignRight;
    paint.drawText(gx1 - 5 - fm.width(min_str), gy_min, fm.width(min_str), fm.height(), tfa, min_str);
    paint.drawLine(gx1 - 3, gy_min, gx1 + 2, gy_min);
    paint.drawText(gx1 - 5 - fm.width(max_str), gy_max, fm.width(max_str), fm.height(), tfa, max_str);
    paint.drawLine(gx1 - 3, gy_max, gx1 + 2, gy_max);
    int gheight = gy2 - gy1;
    double grng = maxValue() - minValue();
    if(org_str.length() > 0) {
        double perc = (0 - minValue()) / grng;
        gy_org = gy2 - (int)(perc * (double)gheight);
        paint.drawText(gx1 - 5 - fm.width(org_str), gy_org, fm.width(org_str), fm.height(), tfa, org_str);
        paint.drawLine(gx1 - 3, gy_org, gx1 + 2, gy_org);
    }

    gx1 += 3;

    // put the old value back so all the code to come draw correctly!
    gy2 = gy2_old;

    // get the dimensions of the data label then draw it
    if(dataLabel().length() > 0) {
        fm = QFontMetrics(dataLabelFont());
        //brect = fm.boundingRect(dataLabel());
        paint.setFont(dataLabelFont());
        gy2 -= fm.height();
        paint.drawText(gx1, gy2, gx2 - gx1, fm.height(), dataLabelAlignment(), dataLabel());
    }

    gy2 -= th;

    int ref_cnt = _data.count();
    int gwidth = gx2 - gx1;
    gheight = gy2 - gy1;

    if(ref_cnt > 0) {
        paint.save();
        fm = QFontMetrics(dataFont());
        paint.setFont(dataFont());
        int refwidth = QMAX(1, gwidth / ref_cnt);
        int buf = (int)(refwidth / 5);
        int buf2 = buf * 2;
        QMapIterator<int, GReference> rit;
        int pos = gx1 + (int)((gwidth - (refwidth * ref_cnt)) / 2);
        int bar_height;
        int fmheight = fm.height();
        int fmheight_div_2 = fmheight / 2;
        int refwidth_div_2 = refwidth / 2;
        int label_offset = (int)(fmheight_div_2 * cos45deg);
        int last_label_at = -1000;
        QMap<int, double> last_map;
        QMap<int, double> this_map;
        for(rit = _data.begin(); rit != _data.end(); ++rit ) {
            GReference ref = rit.data();
            QString label = ref.first;
            if(label.length() > 0 && ((pos + refwidth_div_2) - last_label_at) > ((label_offset * 2) + 1)) {
                last_label_at = pos + refwidth_div_2;
                int lx = (int)(((pos + refwidth_div_2) * cos45deg) - ((gy2 + label_offset) * sin45deg));
                int ly = (int)(((pos + refwidth_div_2) * sin45deg) + ((gy2 + label_offset) * cos45deg));
                int fmwidth = fm.width(label) + 5;
                paint.save();
                paint.rotate(-45);
                paint.drawText(lx - fmwidth, ly - fmheight_div_2, fmwidth, fmheight, AlignCenter | AlignTop, label);
                paint.restore();
            }

            QMapIterator<int, double> sit;
            paint.save();
            if(drawBars() == TRUE) {
                TSetValue tval;
                QMap<double, TSetValue> sort_map;
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit ) {
                    if(sit.data() != 0.0) {
                        tval.first = sit.key();
                        tval.second = sit.data();
                        sort_map[(tval.second < 0.0 ? minValue() : maxValue()) - (tval.second < 0.0 ? -tval.second : tval.second)] = tval;
                    }
                }
                QMapIterator<double, TSetValue> it;
                for(it = sort_map.begin(); it != sort_map.end(); ++it) {
                    tval = it.data();
                    if(tval.second != 0.0) {
                        if(tval.second < 0) {
                            bar_height = (int)((tval.second / minValue()) * (gy_org - gy_min));
                        } else {
                            bar_height = (int)((tval.second / maxValue()) * (gy_org - gy_max));
                        }
                        paint.fillRect(pos + buf, gy_org - bar_height, refwidth - buf2, bar_height, getSetColor(tval.first));
                    }
                }
            }
            if(drawLines() == TRUE) {
                this_map.clear();
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) {
                    this_map[sit.key()] = sit.data();
                    if(last_map.contains(sit.key())) {
                        paint.setPen(getSetColor(sit.key()));
                        double old_val = last_map[sit.key()];
                        double new_val = sit.data();
                        int ly1;
                        if(old_val < 0.0) ly1 = (int)((old_val / minValue()) * (gy_org - gy_min));
                        else              ly1 = (int)((old_val / maxValue()) * (gy_org - gy_max));
                        ly1 = gy_org - ly1;
                        int lx1 = pos - refwidth_div_2;
                        int ly2;
                        if(new_val < 0.0) ly2 = (int)((new_val / minValue()) * (gy_org - gy_min));
                        else              ly2 = (int)((new_val / maxValue()) * (gy_org - gy_max));
                        ly2 = gy_org - ly2;
                        int lx2 = pos + refwidth_div_2;
                        paint.drawLine(lx1, ly1, lx2, ly2);
                    }
                }
                last_map = this_map;
            }
            if(drawPoints() == TRUE) {
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) {
                    paint.setBrush(getSetColor(sit.key()));
                    paint.setPen(QColor(0,0,0));
                    int ly1;
                    if(sit.data() < 0.0) ly1 = (int)((sit.data() / minValue()) * (gy_org - gy_min));
                    else                 ly1 = (int)((sit.data() / maxValue()) * (gy_org - gy_max));
                    ly1 = gy_org - ly1;
                    int lx1 = pos + refwidth_div_2;
                    paint.drawEllipse(lx1 - 2, ly1 - 2, 5, 5);
                }
            }
            paint.restore();
            pos += refwidth;
        }
        paint.restore();
    }

    paint.drawLine(gx1, gy_org, gx2 - 1, gy_org);
    paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1);


    // Now that we are done return the paint device back to the state
    // it was when we started to mess with it
    paint.restore();
}
示例#12
0
void AmeGradientButton::paintEvent(QPaintEvent *)
{
        QPainter painter(this);

        QColor outlineColor1(0x7e, 0x7e, 0x7e);
        QColor outlineColor2(0x97, 0x97, 0x97);

        QColor topColor, bottomColor;
        if (isDown()) {
                topColor = QColor(0xa3, 0xa3, 0xa3);
                bottomColor = QColor(0x95, 0x95, 0x95);
        } else {
                topColor = QColor(0xfb, 0xfb, 0xfb);
                bottomColor = QColor(0xee, 0xee, 0xee);
        }

        QRect r = painter.window();

        int left, right, h, w, x1, x2;
        h = (height() - 2) / 2;
        x1 = 1; x2 = 0;

        switch (gPos) {
                case LeftButton : {
                        w = width() - 1;
                        left=r.left() + 1;
                        right=r.right();
                        x1 = 2;
                        break;
                }
                case MidButton: {
                        w = width();
                        left = r.left();
                        right = r.right();
                        break;
                }
                case RightButton : {
                        w = width() - 2;
                        left = r.left();
                        right = r.right();
                        x2 = -1;
                        break;
                }
        }

        painter.setPen(QPen(outlineColor1, 0));
        painter.drawLine(QPoint(left, r.top()), QPoint(right, r.top()));


        int y1 = r.top() + 1;
        painter.setPen(QPen(outlineColor2, 0));
        painter.drawLine(QPoint(left, y1), QPoint(left, r.bottom()));
        painter.drawLine(QPoint(left, r.bottom()), QPoint(right, r.bottom()));

        if (gPos == RightButton)
                painter.drawLine(QPoint(right, y1), QPoint(right, r.bottom()));

        left ++;
        painter.fillRect(left, 1, w, h, topColor);
        painter.fillRect(left, h + 1, w, h, bottomColor);

        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.rect.adjust(x1, 1, x2, -1);

        QPixmap pix = icon().pixmap(iconSize(),
                isEnabled() ? QIcon::Normal : QIcon::Disabled,
                isDown() ? QIcon::On : QIcon::Off);

        int pw = pix.width();
        int ph = pix.height();

        QPoint point(option.rect.x() + option.rect.width() / 2 - pw / 2,
                     option.rect.y() + option.rect.height() / 2 - ph / 2);

        painter.drawPixmap(style()->visualPos(layoutDirection(), option.rect, point), pix);

        if (hasFocus()) {
                option.backgroundColor = palette().color(QPalette::Background);
                style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
        }

}
示例#13
0
void ChoiceView::paintEvent(QPaintEvent *event) {
    QFontMetrics metrics(font());
    QPainter painter(this);

    int y = arrowHeight + 2;
    const int baseline = metrics.leading() + metrics.ascent() + 1;
    const int w = width(), h = height() - (y * 2);
    const int yInc = h / 10;
    const int labelWidth = w - yInc - 10;
    const int hotkeyCenter = w - (yInc / 2);

    // Top arrow
    const int center = w / 2;
    painter.eraseRect(0, 0, w, y);
    if (_offset > 0) {
        painter.drawLine(center, 0, center - arrowHeight, arrowHeight);
        painter.drawLine(center, 0, center + arrowHeight, arrowHeight);
        painter.drawLine(center - arrowHeight, arrowHeight, center + arrowHeight, arrowHeight);
    }

    // Bottom arrow
    painter.eraseRect(0, height() - y, w, y);
    if (_offset + 10 < _choices.size()) {
        painter.drawLine(center, height() - 1, center - arrowHeight, height() - arrowHeight - 1);
        painter.drawLine(center, height() - 1, center + arrowHeight, height() - arrowHeight - 1);
        painter.drawLine(center - arrowHeight, height() - arrowHeight - 1,
                         center + arrowHeight, height() - arrowHeight - 1);
    }

    QLinearGradient fade(QPointF(0,0), QPointF(labelWidth, 0));
    fade.setColorAt(0, Qt::black);
    fade.setColorAt(0.95, Qt::black);
    fade.setColorAt(1.0, QColor(0xAA, 0xAA, 0xAA));

    QTextOption noWrap;
    noWrap.setWrapMode(QTextOption::NoWrap);

    // Choice area
    for (int row = 0; row < NUM_CHOICES; row++) {
        const int item = row + _offset;
        painter.eraseRect(0, y, w, yInc);
        if (item < _choices.size()) {
            const Choice &c = _choices[item];
            if (metrics.width(c.title()) > labelWidth) {
                painter.setPen(QPen(QBrush(fade), 1));
            } else {
                painter.setPen(QPen(Qt::black));
            }

            painter.drawText(QRectF(0, y, labelWidth, yInc), c.title(), noWrap);

            painter.save();
            if (row > 0) {
                painter.setPen(QColor(0xAA, 0xAA, 0xAA));
                painter.drawLine(50, y - 10, w - 50, y - 10);
            }

            painter.setPen(QColor(0x55, 0x55, 0x55));
            painter.drawRoundedRect(labelWidth + 10, y + metrics.leading(), yInc - 1, metrics.height(), 4, 4);
            painter.drawText(hotkeyCenter - (metrics.width(_hotkeys[row]) / 2), y + baseline,
                             QString(1, _hotkeys[row]));

            painter.restore();
        }
        y += yInc;
    }
}
示例#14
0
int ViNeuralNetworkWidget::yBiasOffset()
{
	return height() - (mNeuronSize * 3);
}
FloatRect::operator BRect() const
{
    return BRect(BPoint(x(), y()), BSize(width() - 1, height() - 1));
}
void QCtkXipSGWidget::paintGL()
{

  static bool testHack = true;
  if(testHack)
  {
    QStringList test; 
    test.append("xipivcored.dll");
    test.append("xipivcoregld.dll");
    test.append("xipivdicomd.dll");
    test.append("xipivoverlayd.dll");
    test.append("xipivrendererd.dll");
    test.append("xipivextrad.dll");

    loadIVExtensions(test);
    loadIvFile("../vtkIvPropProject/simpleXIP/TestSceneGraph_Opaque_Transparent_Annotations.iv");
    //         loadIvFile("scenegraphs/cone.iv");

    testHack = false;

    SoMFUInt32 *swapBuffersInfo = (SoMFUInt32 *) SoDB::getGlobalField("SwapBuffersInfo");
    if(swapBuffersInfo)
      swapBuffersInfo = (SoMFUInt32 *) SoDB::createGlobalField(SbName("SwapBuffersInfo"), SoMFUInt32::getClassTypeId());
  }

  processDelayQueue();

#ifdef WIN32 // FIXME: Make it work on Unix
  quint64 countAfterSwap;
#endif /* WIN32 */
  SbXipPerformanceTimer timer;

  renderScene(mSceneManager);

  float timeOfRenderPass = timer.elapsed() / 1000.0f;

  SbXipPerformanceTimer swapTime;
  swapBuffers();
  gTimings[1] = swapTime.elapsed(); // swap time





#ifdef WIN32 // FIXME: Make it work on Unix
  // Measure perf counter right after swap
  QueryPerformanceCounter((LARGE_INTEGER*) &countAfterSwap);
#endif /* WIN32 */

  float timeSinceLastRenderPass = mTimeSinceLastRenderPass.elapsed() / 1000.0f;
  mTimeSinceLastRenderPass.reset();

  char tmp[100];
  if (timeSinceLastRenderPass < (timeOfRenderPass + 100))
  {
    // continues updates, print both current render time and time since last update
    int freq = 1000 / timeSinceLastRenderPass;
    sprintf(tmp, timeOfRenderPass >= 100 ? "%dx%d, %0.f ms, %d Hz" : "%dx%d, %0.1f ms, %d Hz", width(), height(), timeOfRenderPass, freq);
  }
  else
  {
    // only print current render time
    sprintf(tmp, timeOfRenderPass >= 100 ? "%dx%d, %0.f ms" : "%dx%d, %0.1f ms", width(), height(), timeOfRenderPass);
  }


  // store timings
  gTimings[0] = timer.elapsed(); // total time
#ifdef WIN32 // FIXME: Make it work on Unix
  *((quint64*)&gTimings[2]) = countAfterSwap; // counter after swap
  SoMFUInt32 *swapBuffersInfo = (SoMFUInt32 *) SoDB::getGlobalField("SwapBuffersInfo");
  //SoDebugError::postInfo("Radbuilder::renderCallback", "%d *** gTimings[2]: %d, field[2]: %d\n", (unsigned int) c4, gTimings[2], (*swapBuffersInfo)[2]);
  if ( swapBuffersInfo )
  {
    swapBuffersInfo->setNum(6);
    swapBuffersInfo->setValues(0, 6, gTimings);
  }
#endif /* WIN32 */

  update();

}
示例#17
0
void Mouse::setType(int type)
{
    delete _animation; _animation = 0;
    _type = type;
    switch(_type)
    {
        case BIG_ARROW:
            loadFromSurface(ResourceManager::surface("art/intrface/stdarrow.frm"));
            setXOffset(0);
            setYOffset(0);
            _lastType = _type;
            break;
        case SCROLL_W:
            loadFromSurface(ResourceManager::surface("art/intrface/scrwest.frm"));
            setYOffset( - ceil(height()/2));
            setXOffset(0);
            break;
        case SCROLL_W_X:
            loadFromSurface(ResourceManager::surface("art/intrface/scrwx.frm"));
            setYOffset( - ceil(height()/2));
            setXOffset(0);
            break;
        case SCROLL_N:
            loadFromSurface(ResourceManager::surface("art/intrface/scrnorth.frm"));
            setXOffset( - ceil(width()/2));
            setYOffset(0);
            break;
        case SCROLL_N_X:
            loadFromSurface(ResourceManager::surface("art/intrface/scrnx.frm"));
            setXOffset( - ceil(width()/2));
            setYOffset(0);
            break;
        case SCROLL_S:
            loadFromSurface(ResourceManager::surface("art/intrface/scrsouth.frm"));
            setXOffset( - ceil(width()/2));
            setYOffset( - height());
            break;
        case SCROLL_S_X:
            loadFromSurface(ResourceManager::surface("art/intrface/scrsx.frm"));
            setXOffset(- ceil(width()/2));
            setYOffset(- height());
            break;
        case SCROLL_E:
            loadFromSurface(ResourceManager::surface("art/intrface/screast.frm"));
            setXOffset( - width());
            setYOffset( - ceil(height()/2));
            break;
        case SCROLL_E_X:
            loadFromSurface(ResourceManager::surface("art/intrface/screx.frm"));
            setXOffset(- width());
            setYOffset(- ceil(height()/2));
            break;
        case SCROLL_NW:
            loadFromSurface(ResourceManager::surface("art/intrface/scrnwest.frm"));
            setXOffset(0);
            setYOffset(0);
            break;
        case SCROLL_NW_X:
            loadFromSurface(ResourceManager::surface("art/intrface/scrnwx.frm"));
            setXOffset(0);
            setYOffset(0);
            break;
        case SCROLL_SW:
            loadFromSurface(ResourceManager::surface("art/intrface/scrswest.frm"));
            setXOffset(0);
            setYOffset(- height());
            break;
        case SCROLL_SW_X:
            loadFromSurface(ResourceManager::surface("art/intrface/scrswx.frm"));
            setXOffset(0);
            setYOffset(- height());
            break;
        case SCROLL_NE:
            loadFromSurface(ResourceManager::surface("art/intrface/scrneast.frm"));
            setXOffset(- width());
            setYOffset(0);
            break;
        case SCROLL_NE_X:
            loadFromSurface(ResourceManager::surface("art/intrface/scrnex.frm"));
            setXOffset(- width());
            setYOffset(0);
            break;
        case SCROLL_SE:
            loadFromSurface(ResourceManager::surface("art/intrface/scrseast.frm"));
            setXOffset(- width());
            setYOffset(- height());
            break;
        case SCROLL_SE_X:
            loadFromSurface(ResourceManager::surface("art/intrface/scrsex.frm"));
            setXOffset(- width());
            setYOffset(- height());
            break;
        case HEXAGON_RED:
            loadFromSurface(ResourceManager::surface("art/intrface/msef000.frm"));
            setXOffset(- width()/2);
            setYOffset(- height()/2);
            _lastType = _type;
            break;
        case ACTION:
            loadFromSurface(ResourceManager::surface("art/intrface/actarrow.frm"));
            setXOffset(0);
            setYOffset(0);
            _lastType = _type;
            break;
        case WAIT:
            _animation = new Animation("art/intrface/wait.frm");
            _animation->setEnabled(true);
            setXOffset(- width()/2);
            setYOffset(- height()/2);
            _lastType = _type;
            break;
        case NONE:
            loadFromSurface(new Surface());
            break;
    }
}
void QCtkXipSGWidget::resizeEvent(QResizeEvent * event)
{
  QWidget::resizeEvent(event);
  resizeGL(width(), height());
}
示例#19
0
文件: Pattern.cpp 项目: diizy/lmms
void PatternView::paintEvent( QPaintEvent * )
{
	if( m_needsUpdate == false )
	{
		QPainter p( this );
		p.drawPixmap( 0, 0, m_paintPixmap );
		return;
	}

	QPainter _p( this );
	const QColor styleColor = _p.pen().brush().color();

	m_pat->changeLength( m_pat->length() );

	m_needsUpdate = false;

	if( m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() )
	{
		m_paintPixmap = QPixmap( size() );
	}

	QPainter p( &m_paintPixmap );

	QLinearGradient lingrad( 0, 0, 0, height() );

	QColor c;
	if(( m_pat->m_patternType != Pattern::BeatPattern ) &&
		!( m_pat->getTrack()->isMuted() || m_pat->isMuted() ))
	{
		c = styleColor;
	}
	else
	{
		c = QColor( 80, 80, 80 );
	}

	if( isSelected() == true )
	{
		c.setRgb( qMax( c.red() - 128, 0 ), qMax( c.green() - 128, 0 ), 255 );
	}

	if( m_pat->m_patternType != Pattern::BeatPattern )
	{
		lingrad.setColorAt( 1, c.darker( 300 ) );
		lingrad.setColorAt( 0, c );
	}
	else
	{
		lingrad.setColorAt( 0, c.darker( 300 ) );
		lingrad.setColorAt( 1, c );
	}

	p.setBrush( lingrad );
	if( gui->pianoRoll()->currentPattern() == m_pat && m_pat->m_patternType != Pattern::BeatPattern )
		p.setPen( c.lighter( 130 ) );
	else
		p.setPen( c.darker( 300 ) );
	p.drawRect( QRect( 0, 0, width() - 1, height() - 1 ) );

	p.setBrush( QBrush() );
	if( m_pat->m_patternType != Pattern::BeatPattern )
	{
		if( gui->pianoRoll()->currentPattern() == m_pat )
			p.setPen( c.lighter( 160 ) );
		else
			p.setPen( c.lighter( 130 ) );
		p.drawRect( QRect( 1, 1, width() - 3, height() - 3 ) );
	}

	const float ppt = fixedTCOs() ?
			( parentWidget()->width() - 2 * TCO_BORDER_WIDTH )
					/ (float) m_pat->length().getTact() :
				( width() - 2 * TCO_BORDER_WIDTH )
					/ (float) m_pat->length().getTact();


	const int x_base = TCO_BORDER_WIDTH;
	p.setPen( c.darker( 300 ) );

	for( tact_t t = 1; t < m_pat->length().getTact(); ++t )
	{
		p.drawLine( x_base + static_cast<int>( ppt * t ) - 1,
				TCO_BORDER_WIDTH, x_base + static_cast<int>(
						ppt * t ) - 1, 5 );
		p.drawLine( x_base + static_cast<int>( ppt * t ) - 1,
				height() - ( 4 + 2 * TCO_BORDER_WIDTH ),
				x_base + static_cast<int>( ppt * t ) - 1,
				height() - 2 * TCO_BORDER_WIDTH );
	}

// melody pattern paint event

	if( m_pat->m_patternType == Pattern::MelodyPattern )
	{
		if( m_pat->m_notes.size() > 0 )
		{
			// first determine the central tone so that we can
			// display the area where most of the m_notes are
			// also calculate min/max tones so the tonal range can be
			// properly stretched accross the pattern vertically

			int central_key = 0;
			int max_key = 0;
			int min_key = 9999999;
			int total_notes = 0;

			for( NoteVector::Iterator it = m_pat->m_notes.begin();
					it != m_pat->m_notes.end(); ++it )
			{
				if( ( *it )->length() > 0 )
				{
					max_key = qMax( max_key, ( *it )->key() );
					min_key = qMin( min_key, ( *it )->key() );
					central_key += ( *it )->key();
					++total_notes;
				}
			}

			if( total_notes > 0 )
			{
				central_key = central_key / total_notes;
				const int keyrange = qMax( qMax( max_key - central_key, central_key - min_key ), 1 );

				// debug code
				// qDebug( "keyrange: %d", keyrange );

				// determine height of the pattern view, sans borders
				const int ht = (height() - 1 - TCO_BORDER_WIDTH * 2) -1;

				// determine maximum height value for drawing bounds checking
				const int max_ht = height() - 1 - TCO_BORDER_WIDTH;

				// set colour based on mute status
				if( m_pat->getTrack()->isMuted() ||
							m_pat->isMuted() )
				{
					p.setPen( QColor( 160, 160, 160 ) );
				}
				else
				{
					p.setPen( fgColor() );	
				}

				// scan through all the notes and draw them on the pattern
				for( NoteVector::Iterator it =
							m_pat->m_notes.begin();
					it != m_pat->m_notes.end(); ++it )
				{
					// calculate relative y-position
					const float y_key =
						( float( central_key - ( *it )->key() ) / keyrange + 1.0f ) / 2;
					// multiply that by pattern height
					const int y_pos = static_cast<int>( TCO_BORDER_WIDTH + y_key * ht ) + 1;

					// debug code
					// if( ( *it )->length() > 0 ) qDebug( "key %d, central_key %d, y_key %f, y_pos %d", ( *it )->key(), central_key, y_key, y_pos );

					// check that note isn't out of bounds, and has a length
					if( ( *it )->length() > 0 &&
							y_pos >= TCO_BORDER_WIDTH &&
							y_pos <= max_ht )
					{
						// calculate start and end x-coords of the line to be drawn
						const int x1 = x_base +
							static_cast<int>
							( ( *it )->pos() * ( ppt  / MidiTime::ticksPerTact() ) );
						const int x2 = x_base +
							static_cast<int>
							( ( ( *it )->pos() + ( *it )->length() ) * ( ppt  / MidiTime::ticksPerTact() ) );

						// check bounds, draw line
						if( x1 < width() - TCO_BORDER_WIDTH )
							p.drawLine( x1, y_pos,
										qMin( x2, width() - TCO_BORDER_WIDTH ), y_pos );
					}
				}
			}
		}
	}

// beat pattern paint event

	else if( m_pat->m_patternType == Pattern::BeatPattern &&
		( fixedTCOs() || ppt >= 96
			|| m_pat->m_steps != MidiTime::stepsPerTact() ) )
	{
		QPixmap stepon;
		QPixmap stepoverlay;
		QPixmap stepoff;
		QPixmap stepoffl;
		const int steps = qMax( 1,
					m_pat->m_steps );
		const int w = width() - 2 * TCO_BORDER_WIDTH;

		// scale step graphics to fit the beat pattern length
		stepon = s_stepBtnOn->scaled( w / steps,
					      s_stepBtnOn->height(),
					      Qt::IgnoreAspectRatio,
					      Qt::SmoothTransformation );
		stepoverlay = s_stepBtnOverlay->scaled( w / steps,
					      s_stepBtnOn->height(),
					      Qt::IgnoreAspectRatio,
					      Qt::SmoothTransformation );
		stepoff = s_stepBtnOff->scaled( w / steps,
						s_stepBtnOff->height(),
						Qt::IgnoreAspectRatio,
						Qt::SmoothTransformation );
		stepoffl = s_stepBtnOffLight->scaled( w / steps,
						s_stepBtnOffLight->height(),
						Qt::IgnoreAspectRatio,
						Qt::SmoothTransformation );

		for( int it = 0; it < steps; it++ )	// go through all the steps in the beat pattern
		{
			Note * n = m_pat->noteAtStep( it );

			// figure out x and y coordinates for step graphic
			const int x = TCO_BORDER_WIDTH + static_cast<int>( it * w / steps );
			const int y = height() - s_stepBtnOff->height() - 1;

			// get volume and length of note, if noteAtStep returned null
			// (meaning, note at step doesn't exist for some reason)
			// then set both at zero, ie. treat as an off step
			const int vol = ( n != NULL ? n->getVolume() : 0 );
			const int len = ( n != NULL ? int( n->length() ) : 0 );

			if( len < 0 )
			{
				p.drawPixmap( x, y, stepoff );
				for( int i = 0; i < vol / 5 + 1; ++i )
				{
					p.drawPixmap( x, y, stepon );
				}
				for( int i = 0; i < ( 25 + ( vol - 75 ) ) / 5;
									++i )
				{
					p.drawPixmap( x, y, stepoverlay );
				}
			}
			else if( ( it / 4 ) % 2 )
			{
				p.drawPixmap( x, y, stepoffl );
			}
			else
			{
				p.drawPixmap( x, y, stepoff );
			}
		} // end for loop
	}

	p.setFont( pointSize<8>( p.font() ) );

	QColor text_color = ( m_pat->isMuted() || m_pat->getTrack()->isMuted() )
		? QColor( 30, 30, 30 )
		: textColor();

	if( m_pat->name() != m_pat->instrumentTrack()->name() )
	{
		p.setPen( QColor( 0, 0, 0 ) );
		p.drawText( 4, p.fontMetrics().height()+1, m_pat->name() );
		p.setPen( text_color );
		p.drawText( 3, p.fontMetrics().height(), m_pat->name() );
	}

	if( m_pat->isMuted() )
	{
		p.drawPixmap( 3, p.fontMetrics().height() + 1,
				embed::getIconPixmap( "muted", 16, 16 ) );
	}

	p.end();

	_p.drawPixmap( 0, 0, m_paintPixmap );

}
示例#20
0
void PerspectiveView::glPass(GLResourceContext &ctx)
{
    glEnable(GL_DEPTH_TEST);

    QMatrix4x4 cameraProjM = _camera->getProjMatrix(width(), height());
    QMatrix4x4 cameraViewM = _camera->getViewMatrix(width(), height());
    QMatrix4x4 cameraProjViewM = cameraProjM * cameraViewM;
    QMatrix4x4 objToWorld;

    Scene* scene = Scene::activeScene();

    // render each mesh
    QHashIterator<QString,Mesh*> meshes = scene->meshes();
    while (meshes.hasNext()) {
        meshes.next();
        Mesh* mesh = meshes.value();

        // make sure a texture exists for this mesh
        if (!hasMeshTexture(mesh)) {
            std::cout << "creating mesh texture" << std::endl;

            QOpenGLFramebufferObject* transferFbo = ctx.transferFbo();

            transferFbo->bind();

            GLuint textureId;
            glGenTextures(1, &textureId);

            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, textureId);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            glClearColor(.5,.5,.5,1);
            glClear(GL_COLOR_BUFFER_BIT);

            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0,1,0,1,-1,1);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            glViewport(0, 0, 256, 256);

            glColor3f(.8,.8,.8);
            glBegin(GL_QUADS);
            {
                glVertex2f(.25,.25);
                glVertex2f(.75,.25);
                glVertex2f(.75,.75);
                glVertex2f(.25,.75);
            }
            glEnd();

            glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 256, 256, 0);


            transferFbo->release();

            //glActiveTexture(GL_TEXTURE0);
            //QImage img("/tmp/lena.jpg");
            //QImage image = QGLWidget::convertToGLFormat(img);
            //glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0 , image.width(), image.height(),  GL_RGB, GL_UNSIGNED_BYTE, image.bits() );


            glViewport(0, 0, width(), height());

            setMeshTexture(mesh, textureId);
        }

        QOpenGLFramebufferObject* paintFbo = ctx.paintFbo();

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, meshTexture(mesh));
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, paintFbo->texture());
        glActiveTexture(GL_TEXTURE0);

        QGLShaderProgram* meshShader = ctx.meshShader();
        meshShader->bind();
        meshShader->setUniformValue("objToWorld", objToWorld);
        meshShader->setUniformValue("cameraPV", cameraProjViewM);
        meshShader->setUniformValue("paintFboWidth", PAINT_FBO_WIDTH);
        meshShader->setUniformValue("brushColor", _brushColor.redF(), _brushColor.greenF(), _brushColor.blueF(), 1);
        meshShader->setUniformValue("meshTexture", 0);
        meshShader->setUniformValue("paintTexture", 1);

        renderMesh(mesh);

        meshShader->release();


    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glLoadMatrixf(cameraProjM.data());
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glLoadMatrixf(cameraViewM.data());

    glBegin(GL_LINES);
    for (int i = -10; i <= 10; i++) {
        glVertex3f(-10, 0, i);
        glVertex3f(10, 0, i);
    }
    glEnd();

    glDisable(GL_DEPTH_TEST);

    drawPaintStrokes(ctx);

    if (_bakePaintLayer) {
        bakePaintLayer(ctx);
    }
}
示例#21
0
/**
 * Overrides the standard paint event.
 */
void ObjectNodeWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    int w = width();
    int h = height();

    const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
    const int fontHeight  = fm.lineSpacing();
    int textStartY = (h / 2) - (fontHeight / 2);

    setPenFromSettings(painter);

    if (UMLWidget::useFillColor()) {
        painter->setBrush(UMLWidget::fillColor());
    }

    painter->drawRect(0, 0, w, h);
    painter->setFont(UMLWidget::font());

    switch (m_objectNodeType)
    {
    case Normal : break;
    case Buffer :
        {
            painter->setPen(textColor());
            painter->drawText(OBJECTNODE_MARGIN, (textStartY/2), w - OBJECTNODE_MARGIN * 2, fontHeight, Qt::AlignHCenter, QLatin1String("<< centralBuffer >>"));
            painter->drawText(OBJECTNODE_MARGIN, (textStartY/2) + fontHeight + 5, w - OBJECTNODE_MARGIN * 2, fontHeight, Qt::AlignHCenter, name());
        }
        break;
    case Data :
        {
            painter->setPen(textColor());
            painter->drawText(OBJECTNODE_MARGIN, (textStartY/2), w - OBJECTNODE_MARGIN * 2, fontHeight, Qt::AlignHCenter, QLatin1String("<< datastore >>"));
            painter->drawText(OBJECTNODE_MARGIN, (textStartY/2) + fontHeight + 5, w - OBJECTNODE_MARGIN * 2, fontHeight, Qt::AlignHCenter, name());
        }
        break;
    case Flow :
        {
            QString objectflow_value;
            if (state() == QLatin1String("-") || state().isEmpty())
            {
                objectflow_value = QLatin1Char(' ');
            }
            else
            {
                objectflow_value = QLatin1Char('[') + state() + QLatin1Char(']');
            }

            painter->drawLine(10, h/2, w-10, h/2);
            painter->setPen(textColor());
            painter->setFont(UMLWidget::font());
            painter->drawText(OBJECTNODE_MARGIN, textStartY/2 - OBJECTNODE_MARGIN, w - OBJECTNODE_MARGIN * 2, fontHeight, Qt::AlignHCenter, name());
            painter->drawText(OBJECTNODE_MARGIN, textStartY/2 + textStartY + OBJECTNODE_MARGIN, w - OBJECTNODE_MARGIN * 2, fontHeight, Qt::AlignHCenter, objectflow_value);
        }
        break;
    }

    UMLWidget::paint(painter, option, widget);
}
示例#22
0
void Hruler::mouseReleaseEvent(QMouseEvent *m)
{
	if (currDoc->isLoading())
	{
		Mpressed = false;
		return;
	}
	if (textEditMode && currItem)
	{
		if ((m->y() < height()) && (m->y() > 0))
		{
			bool mustApplyStyle = false;
			ParagraphStyle paraStyle;
			double ColWidth = (textWidth() - ColGap * (Cols - 1)) / Cols;			
			switch (RulerCode)
			{
				case rc_leftFrameDist:
					currDoc->m_Selection->itemAt(0)->setTextToFrameDistLeft(Extra);
					emit DocChanged(false);
					break;
				case rc_rightFrameDist:
					currDoc->m_Selection->itemAt(0)->setTextToFrameDistRight(RExtra);
					emit DocChanged(false);
					break;
				case rc_indentFirst:
					paraStyle.setFirstIndent(First);
					mustApplyStyle = true;
					emit DocChanged(false);
					break;
				case rc_leftMargin:
					paraStyle.setLeftMargin(Indent);
					paraStyle.setFirstIndent(First);
					mustApplyStyle = true;
					emit DocChanged(false);
					break;
				case rc_rightMargin:
					paraStyle.setRightMargin(ColWidth - RMargin);
					mustApplyStyle = true;
					emit DocChanged(false);
					break;
				case rc_tab:
					if (m->button() == Qt::RightButton)
					{
						TabValues[ActTab].tabType += 1;
						if (TabValues[ActTab].tabType > 4)
							TabValues[ActTab].tabType = 0;
					}
					paraStyle.setTabValues(TabValues);
					mustApplyStyle = true;
					emit DocChanged(false);
					break;
				default:
					break;
			}
			if (mustApplyStyle)
			{
				Selection tempSelection(this, false);
				tempSelection.addItem(currItem);
				currDoc->itemSelection_ApplyParagraphStyle(paraStyle, &tempSelection);
			}
			else
			{
				currItem->update();
			}
		}
		else
		{
			if (RulerCode == rc_tab)
			{
				TabValues.removeAt(ActTab);
				ActTab = 0;
				ParagraphStyle paraStyle;
				paraStyle.setTabValues(TabValues);
				Selection tempSelection(this, false);
				tempSelection.addItem(currItem);
				currDoc->itemSelection_ApplyParagraphStyle(paraStyle, &tempSelection);
				emit DocChanged(false);
				qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
			}
		}
		RulerCode = rc_none;
		currView->DrawNew();
		currDoc->m_Selection->itemAt(0)->emitAllToGUI();
	}
	else
	{
		if (Mpressed)
		{
			rulerGesture->mouseReleaseEvent(m);
			Mpressed = false;
		}
	}
	Mpressed = false;
}
示例#23
0
int CButton::GetTextWidth()
{
    return m_bLeftIcon?(width()-height()*0.8):(width());
}
示例#24
0
void Hruler::mouseMoveEvent(QMouseEvent *m)
{
	if (currDoc->isLoading())
		return;
	if (textEditMode)
	{
		double ColWidth = (textWidth() - ColGap * (Cols - 1)) / Cols;
		int ColEnd, ColStart;
		double oldInd;
		if (RulerCode == rc_leftFrameDist || RulerCode == rc_rightFrameDist)
		{
			ColStart = 0; //textPosToLocal(0);
			ColEnd = width(); //textPosToLocal(textWidth());
		}
		else
		{
			ColStart = textPosToLocal((ColWidth+ColGap)*(ActCol-1));
			ColEnd = textPosToLocal((ColWidth+ColGap)*(ActCol-1) + ColWidth);
		}
		if ((Mpressed) && (m->y() < height()) && (m->y() > 0) && (m->x() > ColStart - currDoc->guidesSettings.grabRad) && (m->x() < ColEnd + currDoc->guidesSettings.grabRad))
		{
			qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
			double toplimit = textWidth() + RExtra - (ColGap * (Cols - 1))-1;
			double toplimit2 = textWidth() + Extra - (ColGap * (Cols - 1))-1;
			switch (RulerCode)
			{
				case rc_leftFrameDist:
					Extra -= (MouseX - m->x()) / Scaling;
					if (Extra < 0)
						Extra = 0;
					if (Extra > toplimit2)
						Extra = toplimit2;
					emit MarkerMoved(currItem->xPos(), textBase()-currItem->xPos());
					repaint();
					break;
				case rc_rightFrameDist:
					RExtra += (MouseX - m->x()) / Scaling;
					if (RExtra < 0)
						RExtra = 0;
					if (RExtra > toplimit)
						RExtra = toplimit;
					emit MarkerMoved(RExtra, 0);
					repaint();
					break;
				case rc_indentFirst:
					First -= (MouseX - m->x()) / Scaling;
					if (First+Indent < 0)
						First = -Indent;					
					if (First+Indent > ColWidth)
						First  = ColWidth-Indent;
					emit MarkerMoved(textBase(), First+Indent);
					repaint();
					break;
				case rc_leftMargin:
					oldInd = Indent+First;
					Indent -= (MouseX - m->x()) / Scaling;
					if (Indent < 0)
						Indent = 0;
					if (Indent > ColWidth-1)
						Indent  = ColWidth-1;
					First = oldInd - Indent;
					emit MarkerMoved(textBase(), Indent);
					repaint();
					break;
				case rc_rightMargin:
					RMargin -= (MouseX - m->x()) / Scaling;
					if (RMargin < 0)
						RMargin = 0;
					if (RMargin > ColWidth-1)
						RMargin  = ColWidth-1;
					emit MarkerMoved(textBase(), RMargin);
					repaint();
					break;
				case rc_tab:
					TabValues[ActTab].tabPosition -= (MouseX - m->x()) / Scaling;
					if (TabValues[ActTab].tabPosition < 0)
						TabValues[ActTab].tabPosition = 0;
					if (TabValues[ActTab].tabPosition > ColWidth-1)
						TabValues[ActTab].tabPosition  = ColWidth-1;
					emit MarkerMoved(textBase(), TabValues[ActTab].tabPosition);
					UpdateTabList();
					repaint();
					break;
				default:
					break;
			}
			MouseX = m->x();
/*			if (RulerCode != rc_none)
			{
				QPoint py = currView->viewport()->mapFromGlobal(m->globalPos());
				QPainter p;
				p.begin(currView->viewport());
				p.setCompositionMode(QPainter::CompositionMode_Xor);
				p.setPen(QPen(Qt::white, 1, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
				QPoint out = currView->contentsToViewport(QPoint(0, qRound(currDoc->currentPage()->yOffset() * Scaling)));
				p.drawLine(Markp, out.y(), Markp, out.y()+qRound(currDoc->currentPage()->height() * Scaling));
				p.drawLine(py.x(), out.y(), py.x(), out.y()+qRound(currDoc->currentPage()->height() * Scaling));
				p.end();
				Markp = py.x();
			}*/
			return;
		}
		if ((!Mpressed) && (m->y() < height()) && (m->y() > 0) && (m->x() > ColStart - 2*currDoc->guidesSettings.grabRad) && (m->x() < ColEnd + 2*currDoc->guidesSettings.grabRad))
		{
			qApp->changeOverrideCursor(QCursor(loadIcon("tab.png"), 3));
			switch(findRulerHandle(m->pos(), currDoc->guidesSettings.grabRad))
			{
				case rc_leftFrameDist:
					qApp->changeOverrideCursor(QCursor(Qt::SplitHCursor));
					break;
				case rc_rightFrameDist:
					qApp->changeOverrideCursor(QCursor(Qt::SplitHCursor));
					break;
				case rc_indentFirst:
					qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
					break;
				case rc_leftMargin:
					qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
					break;
				case rc_rightMargin:
					qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
					break;
				case rc_tab:
					qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
					break;
			}
			Draw(m->x());
			double marker = localToTextPos(m->x());
			emit MarkerMoved(textBase(), marker);
			return;
		}
		if ((Mpressed) && (RulerCode == rc_tab) && ((m->y() > height()) || (m->y() < 0)))
		{
			qApp->changeOverrideCursor(QCursor(loadIcon("DelPoint.png"), 1, 1));
			return;
		}
		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
	}
	else
	{
		if (Mpressed)
		{
			rulerGesture->mouseMoveEvent(m);
		}
		else
		{
			QCursor* cursor = qApp->overrideCursor();
			Qt::CursorShape shape = cursor ? cursor->shape() : Qt::ArrowCursor;
			if ((shape == Qt::SplitHCursor) || (shape == Qt::SplitVCursor))
			{
				qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
			}
		}
	}
}
示例#25
0
void FindTextContent::slotMenuFind()
{
  findMenu_->popup(mapToGlobal(QPoint(0, height()-1)));
}
示例#26
0
void WaveformView::paintEvent(QPaintEvent *event)
{
	PG_UNUSED(event);

	QPainter	dc(this);

	int32		clientWidth = width();
	int32		clientHeight = height();

	if (fDoc == NULL)
	{
		dc.drawText(QRect(0, 0, clientWidth, clientHeight), Qt::AlignHCenter | Qt::AlignVCenter, tr("Drop WAV audio file here"));
		return;
	}

	int32		topBorder = 16; // should be the height of frame label text
	int32		halfClientHeight;
	int32		sampleHeight, halfSampleHeight, textHeight;
	int32		fps = fDoc->Fps();
	int32		x = 0;
	int32		frameX;
	int32		sample = 0;
	int32		frame = 0;
	bool		drawPlayMarker = false;
	QRect		r;
	QColor		textCol(64, 64, 64);
	QColor		sampleFillCol(162, 205, 242);
	QColor		sampleOutlineCol(30, 121, 198);
	QColor		playBackCol(255, 127, 127);
	QColor		playForeCol(209, 102, 121, 128);
	QColor		playOutlineCol(128, 0, 0);
	QColor		frameCol(192, 192, 192);
	QColor		phraseFillCol(205, 242, 162);
	QColor		phraseOutlineCol(121, 198, 30);
	QColor		wordFillCol(242, 205, 162);
	QColor		wordOutlineCol(198, 121, 30);
	QColor		wordMissingFillCol(255, 127, 127);
	QColor		wordMissingOutlineCol(255, 0, 0);
	QColor		phonemeFillCol(231, 185, 210);
	QColor		phonemeOutlineCol(173, 114, 146);
	QMediaPlayer	*audioPlayer = fDoc->GetAudioPlayer();

	textHeight = dc.fontMetrics().height() + 4;
	topBorder = textHeight;
	halfClientHeight = (clientHeight - textHeight) / 2;

	if (audioPlayer && audioPlayer->state() == QMediaPlayer::PlayingState)
	{
		drawPlayMarker = true;
		x = fCurFrame * fFrameWidth;
		dc.fillRect(QRect(x, 0, fFrameWidth, clientHeight), playBackCol);
	}

	x = 0;
	for (int32 i = 0; i < fNumSamples; i++)
	{
		if (((sample + 1) % fSamplesPerFrame) == 0)
		{
			dc.setPen(frameCol);
			// draw frame marker
			frameX = (frame + 1) * fFrameWidth;
			if (fSampleWidth >= 2 && ((fFrameWidth > 2) || ((frame + 2) % fps == 0)))
			{
				dc.drawLine(frameX, topBorder, frameX, clientHeight);
			}
			// draw frame label
			if ((fFrameWidth > 30) || ((frame + 2) % fps == 0))
			{
				dc.drawLine(frameX, 0, frameX, topBorder);
				dc.drawText(frameX + 2, textHeight - 4, QString::number(frame + 2));
			}
		}

		sampleHeight = PG_ROUND(fAmp[i] * (real)(clientHeight - topBorder));
		halfSampleHeight = sampleHeight / 2;
		r.setRect(x, topBorder + halfClientHeight - halfSampleHeight, fSampleWidth + 1, sampleHeight);
		dc.fillRect(r, sampleFillCol);
		dc.setPen(sampleOutlineCol);
		dc.drawLine(r.topLeft(), r.topRight());
		dc.drawLine(r.bottomLeft(), r.bottomRight());
		dc.drawLine(r.topRight(), r.bottomRight());
		if (i == 0)
		{
			dc.drawLine(r.topLeft(), r.bottomLeft());
		}
		else if (fAmp[i] > fAmp[i - 1])
		{
			sampleHeight = PG_ROUND(fAmp[i - 1] * (real)(clientHeight - topBorder));
			halfSampleHeight = sampleHeight / 2;
			dc.drawLine(r.topLeft(), QPoint(r.left(), topBorder + halfClientHeight - halfSampleHeight));
			dc.drawLine(r.bottomLeft(), QPoint(r.left(), topBorder + halfClientHeight - halfSampleHeight + sampleHeight - 1));
		}

		x += fSampleWidth;
		sample++;
		if ((sample % fSamplesPerFrame) == 0)
			frame++;
	}

	if (fDoc->fCurrentVoice)
	{
		topBorder += 4;
		for (int32 p = 0; p < fDoc->fCurrentVoice->fPhrases.size(); p++)
		{
			LipsyncPhrase *phrase = fDoc->fCurrentVoice->fPhrases[p];
			r = QRect(phrase->fStartFrame * fFrameWidth, topBorder, (phrase->fEndFrame - phrase->fStartFrame + 1) * fFrameWidth, textHeight);
			phrase->fTop = r.top();
			phrase->fBottom = r.bottom();
			dc.fillRect(r, phraseFillCol);
			dc.setPen(phraseOutlineCol);
			dc.drawRect(r);
			dc.setClipRect(r);
			dc.setPen(textCol);
			r = r.marginsRemoved(QMargins(2, 2, 2, 2));
			dc.drawText(QPoint(r.left(), r.bottom() - 2), phrase->fText);
			dc.setClipping(false);

			for (int32 w = 0; w < phrase->fWords.size(); w++)
			{
				LipsyncWord *word = phrase->fWords[w];
				r = QRect(word->fStartFrame * fFrameWidth, topBorder + 4 + textHeight, (word->fEndFrame - word->fStartFrame + 1) * fFrameWidth, textHeight);
				if (w & 1)
					r.translate(0, textHeight - textHeight / 4);
				word->fTop = r.top();
				word->fBottom = r.bottom();
				if (word->fPhonemes.size() == 0)
				{
					dc.fillRect(r, wordMissingFillCol);
					dc.setPen(wordMissingOutlineCol);
				}
				else
				{
					dc.fillRect(r, wordFillCol);
					dc.setPen(wordOutlineCol);
				}
				dc.drawRect(r);
				dc.setClipRect(r);
				dc.setPen(textCol);
				r = r.marginsRemoved(QMargins(2, 2, 2, 2));
				dc.drawText(QPoint(r.left(), r.bottom() - 2), word->fText);
				dc.setClipping(false);

				for (int32 i = 0; i < word->fPhonemes.size(); i++)
				{
					LipsyncPhoneme *phoneme = word->fPhonemes[i];
					r = QRect(phoneme->fFrame * fFrameWidth, clientHeight - 4 - textHeight, fFrameWidth, textHeight);
					if (i & 1)
						r.translate(0, -(textHeight - textHeight / 4));
					phoneme->fTop = r.top();
					phoneme->fBottom = r.bottom();
					dc.fillRect(r, phonemeFillCol);
					dc.setPen(phonemeOutlineCol);
					dc.drawRect(r);
					dc.setPen(textCol);
					r = r.marginsRemoved(QMargins(2, 2, 2, 2));
					dc.drawText(QPoint(r.left(), r.bottom() - 2), phoneme->fText);
				} // for i
			} // for w
		} // for p
	}

	if (drawPlayMarker)
	{
		x = fCurFrame * fFrameWidth;
		dc.fillRect(QRect(x, 0, fFrameWidth, clientHeight), playForeCol);
		dc.setPen(playOutlineCol);
		dc.drawRect(QRect(x, 0, fFrameWidth, clientHeight));
	}
}
示例#27
0
 QVariant inputMethodQuery(Qt::InputMethodQuery query) const
 {
     if (query == Qt::ImMicroFocus)
         return QRect(width() / 2, height() / 2, 5, 5);
     return QWidget::inputMethodQuery(query);
 }
示例#28
0
int KisColorSelectorRing::innerRadius() const
{
    return (qMin(width(), height())/2)*m_innerRingRadiusFraction;
}
示例#29
0
void init(int buffer_width, int buffer_height)
{
	// Clear any old errors.
	glGetError();
	frame_buffer_texture_width = buffer_width;
	frame_buffer_texture_height = buffer_height;

#if defined(__ANDROID__)
	{
		supported = false;
		LOG("FRAME BUFFER OBJECT NOT SUPPORTED");
		return;
	}
#endif

#if defined(TARGET_OS_HARMATTAN) || defined(TARGET_PANDORA) || defined(TARGET_TEGRA) || defined(TARGET_BLACKBERRY) || defined(__ANDROID__)
	if (glGenFramebuffersOES        != NULL &&
		glBindFramebufferOES        != NULL &&
		glFramebufferTexture2DOES   != NULL &&
		glCheckFramebufferStatusOES != NULL)
	{
		supported = true;
	}
	else
	{
		fprintf(stderr, "FRAME BUFFER OBJECT NOT SUPPORTED\n");
		supported = false;
		return;
	}
#elif !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
	if(!GLEW_EXT_framebuffer_object)
    {
		fprintf(stderr, "FRAME BUFFER OBJECT NOT SUPPORTED\n");
		supported = false;
		return;
	}
#endif
	fprintf(stderr, "FRAME BUFFER OBJECT IS SUPPORTED\n");

#ifndef TARGET_TEGRA
	glGetIntegerv(EXT_MACRO(GL_FRAMEBUFFER_BINDING), &video_framebuffer_id);
#endif
	// Grab the error code first, because of the side effect in glGetError() of 
	// clearing the error code and the double call in the ASSERT_EQ() macro we lose
	// the actual error code.
	GLenum err = glGetError();
	ASSERT_EQ(err, GL_NO_ERROR);

	glGenTextures(1, &texture_id);
	glBindTexture(GL_TEXTURE_2D, texture_id);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width(), height(), 0,
             GL_RGBA, GL_UNSIGNED_BYTE, 0);
	glBindTexture(GL_TEXTURE_2D, 0);


	// create a framebuffer object
	EXT_CALL(glGenFramebuffers)(1, &framebuffer_id);
	EXT_CALL(glBindFramebuffer)(EXT_MACRO(GL_FRAMEBUFFER), framebuffer_id);

	// attach the texture to FBO color attachment point
	EXT_CALL(glFramebufferTexture2D)(EXT_MACRO(GL_FRAMEBUFFER), EXT_MACRO(GL_COLOR_ATTACHMENT0),
                          GL_TEXTURE_2D, texture_id, 0);

	// check FBO status
	GLenum status = EXT_CALL(glCheckFramebufferStatus)(EXT_MACRO(GL_FRAMEBUFFER));
	if(status == EXT_MACRO(GL_FRAMEBUFFER_UNSUPPORTED)) {
		std::cerr << "FRAME BUFFER OBJECT NOT SUPPORTED\n";
		supported = false;
		err = glGetError();
	} else {
		ASSERT_EQ(status, EXT_MACRO(GL_FRAMEBUFFER_COMPLETE));
	}

	// switch back to window-system-provided framebuffer
	EXT_CALL(glBindFramebuffer)(EXT_MACRO(GL_FRAMEBUFFER), video_framebuffer_id);

	err = glGetError();
	ASSERT_EQ(err, GL_NO_ERROR);
}
示例#30
0
void KPropColor::sizeUpdate()
{
  int h = fontMetrics().height() + 2;
	setFixedHeight( (h > 30 ? h : 30) );
	button->setFixedHeight( height() - 2 );
}