diff --git a/ChangeLog b/ChangeLog index 0e73dde4e..9f24d3ba1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,15 @@ - Commit initial version of QGraphicsScene-based Song Editor - Please save bugreports for another week or so, this is immature code + * src/gui/tracks/track_content_object_item.cpp: + * src/gui/tracks/track_item.cpp: + * src/gui/tracks/bb_tco_item.cpp: + * src/gui/tracks/pattern_item.cpp: + * include/gui/tracks/pattern_item.h: + * include/gui/tracks/bb_tco_item.h: + - Add BB and Pattern subclasses + - Play with some styling, about to move style code into lmmsStyle + 2009-02-09 Paul Giblock * include/basic_filters.h: diff --git a/include/gui/tracks/bb_tco_item.h b/include/gui/tracks/bb_tco_item.h new file mode 100644 index 000000000..037173ac2 --- /dev/null +++ b/include/gui/tracks/bb_tco_item.h @@ -0,0 +1,36 @@ +#ifndef _BB_TCO_ITEM_H_ +#define _BB_TCO_ITEM_H_ + +#include +#include +#include +#include +#include +#include +#include + +class trackContentObject; +class TrackItem; + +#include "gui/tracks/track_content_object_item.h" + +class BbTrackContentObjectItem : public TrackContentObjectItem +{ + Q_OBJECT + +public: + BbTrackContentObjectItem( TrackItem * _track, trackContentObject * _object ); + + void paint( QPainter * _painter, const QStyleOptionGraphicsItem * _option, + QWidget * _widget ); + + QVariant itemChange( GraphicsItemChange _change, const QVariant & _value ); + + +protected: + virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); + virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent * event ); + +}; + +#endif diff --git a/include/gui/tracks/pattern_item.h b/include/gui/tracks/pattern_item.h new file mode 100644 index 000000000..2f159aed0 --- /dev/null +++ b/include/gui/tracks/pattern_item.h @@ -0,0 +1,36 @@ +#ifndef _PATTERN_ITEM_H_ +#define _PATTERN_ITEM_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "gui/tracks/track_content_object_item.h" + +class trackContentObject; +class TrackItem; + +class PatternItem : public TrackContentObjectItem +{ + Q_OBJECT + +public: + PatternItem( TrackItem * _track, trackContentObject * _object ); + + void paint( QPainter * _painter, const QStyleOptionGraphicsItem * _option, + QWidget * _widget ); + + QVariant itemChange( GraphicsItemChange _change, const QVariant & _value ); + + +protected: + virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); + virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent * event ); + +}; + +#endif diff --git a/src/gui/tracks/bb_tco_item.cpp b/src/gui/tracks/bb_tco_item.cpp new file mode 100644 index 000000000..0ca10385f --- /dev/null +++ b/src/gui/tracks/bb_tco_item.cpp @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include + +#include "gui/tracks/bb_tco_item.h" +#include "gui/tracks/track_content_object_item.h" +#include "gui/tracks/track_container_scene.h" +#include "gui/tracks/track_item.h" +#include "track.h" + +namespace BBTcoStuff { +QLinearGradient getGradient( const QColor & _col, const QRectF & _rect ) +{ + QLinearGradient g( _rect.topLeft(), _rect.bottomLeft() ); + + qreal hue = _col.hueF(); + qreal value = _col.valueF(); + qreal saturation = _col.saturationF(); + + QColor c = _col; + c.setHsvF( hue, 0.42 * saturation, 0.98 * value ); + g.setColorAt( 0, c ); + c.setHsvF( hue, 0.58 * saturation, 0.95 * value ); + g.setColorAt( 0.25, c ); + c.setHsvF( hue, 0.70 * saturation, 0.93 * value ); + g.setColorAt( 0.5, c ); + + c.setHsvF( hue, 0.95 * saturation, 0.9 * value ); + g.setColorAt( 0.501, c ); + c.setHsvF( hue * 0.95, 0.95 * saturation, 0.95 * value ); + g.setColorAt( 0.75, c ); + c.setHsvF( hue * 0.90, 0.95 * saturation, 1 * value ); + g.setColorAt( 1.0, c ); + + return g; +} + +QLinearGradient darken( const QLinearGradient & _gradient ) +{ + QGradientStops stops = _gradient.stops(); + for (int i = 0; i < stops.size(); ++i) { + QColor color = stops.at(i).second; + stops[i].second = color.darker(160); + } + + QLinearGradient g = _gradient; + g.setStops(stops); + return g; +} + +void drawPath( QPainter *p, const QPainterPath &path, + const QColor &col, const QString &name, + bool dark = false ) +{ + const QRectF pathRect = path.boundingRect(); + + const QLinearGradient baseGradient = getGradient(col, pathRect); + const QLinearGradient darkGradient = darken(baseGradient); + + p->setOpacity(0.25); + + // glow + if (dark) + p->strokePath(path, QPen(darkGradient, 4)); + else + p->strokePath(path, QPen(baseGradient, 4)); + + p->setOpacity(1.0); + + // fill + if (dark) + p->fillPath(path, darkGradient); + else + p->fillPath(path, baseGradient); + + QLinearGradient g(pathRect.topLeft(), pathRect.topRight()); + g.setCoordinateMode(QGradient::ObjectBoundingMode); + + p->setOpacity(0.2); + p->fillPath(path, g); + + p->setOpacity(0.5); + + // highlight + if (dark) + p->strokePath(path, QPen(col.lighter(160).darker(160), 2)); + else + p->strokePath(path, QPen(col.lighter(160), 2)); + +} +} +using namespace BBTcoStuff; + +BbTrackContentObjectItem::BbTrackContentObjectItem( TrackItem * _track, trackContentObject * _object ) : + TrackContentObjectItem( _track, _object ) +{ +} + +void BbTrackContentObjectItem::paint( QPainter * _painter, + const QStyleOptionGraphicsItem * _option, QWidget * _widget ) +{ + + QColor col; + if( !isSelected() ) + { + col = QColor( 0x00, 0x33, 0x99 ); + } + else + { + col = QColor( 0x00, 0x99, 0x33 ); + } + + QRectF rc = boundingRect(); + + qreal xscale = _option->matrix.m11(); + _painter->save(); + _painter->scale( 1.0f/xscale, 1.0f ); + rc.setWidth( rc.width() * xscale ); + + QPainterPath path; + path.addRoundedRect(2, 2, rc.width()-4, rc.height()-4, 4, 4); + drawPath( _painter, path, col, "hah", false ); + + const float cellW = TrackContainerScene::DEFAULT_CELL_WIDTH; + _painter->setOpacity(0.2); + _painter->setRenderHint( QPainter::Antialiasing, false ); + _painter->setPen( QColor(0, 0, 0) ); + for( int i = 0; i < m_tco->length().getTact(); ++i ) + { + float x = cellW * i; + _painter->drawLine(x, 2, x, rc.height()-4); + } + + _painter->translate( 1, 0 ); + _painter->setPen( col.lighter(160) ); + for( int i = 0; i < m_tco->length().getTact(); ++i ) + { + float x = cellW * i; + _painter->drawLine(x, 2, x, rc.height()-4); + } + + _painter->setRenderHint( QPainter::Antialiasing, true ); + _painter->restore(); + + return; + + + QColor col0 = col.light( 130 ); + QColor col1 = col.light( 70 ); + QColor col2 = col.light( 40 ); + + QLinearGradient lingrad( 0, 0, 0, rc.height() ); + lingrad.setColorAt( 0, col0 ); + lingrad.setColorAt( 1, col1 ); + + QLinearGradient bordergrad( 0, 0, 0, rc.height() ); + bordergrad.setColorAt( 1, col2 ); + bordergrad.setColorAt( 0, col1 ); + + + rc.adjust( 0, 0, -1, -1 ); + + + _painter->setRenderHint( QPainter::Antialiasing, true ); + _painter->setBrush( lingrad ); + _painter->setPen( QPen( bordergrad, 1.5 ) ); // QColor( 6, 6, 6 ) ); + _painter->drawRoundedRect( rc, 4, 4 ); + _painter->setRenderHint( QPainter::Antialiasing, false ); + + _painter->restore(); +} + +QVariant BbTrackContentObjectItem::itemChange( GraphicsItemChange _change, const QVariant & _value ) +{ + return TrackContentObjectItem::itemChange( _change, _value ); +} + + +void BbTrackContentObjectItem::mousePressEvent( QGraphicsSceneMouseEvent * event ) +{ + TrackContentObjectItem::mousePressEvent( event ); +} + + + +void BbTrackContentObjectItem::mouseReleaseEvent( QGraphicsSceneMouseEvent * event ) +{ + TrackContentObjectItem::mouseReleaseEvent( event ); +} + + +#include "gui/tracks/moc_bb_tco_item.cxx" diff --git a/src/gui/tracks/pattern_item.cpp b/src/gui/tracks/pattern_item.cpp new file mode 100644 index 000000000..eacfbdf73 --- /dev/null +++ b/src/gui/tracks/pattern_item.cpp @@ -0,0 +1,179 @@ +#include +#include +#include +#include +#include + +#include "gui/tracks/pattern_item.h" +#include "gui/tracks/track_content_object_item.h" +#include "gui/tracks/track_container_scene.h" +#include "gui/tracks/track_item.h" +#include "track.h" + +namespace PatternItemStuff { +QLinearGradient getGradient( const QColor & _col, const QRectF & _rect ) +{ + QLinearGradient g( _rect.topLeft(), _rect.bottomLeft() ); + + qreal hue = _col.hueF(); + qreal value = _col.valueF(); + qreal saturation = _col.saturationF(); + + QColor c = _col; + c.setHsvF( hue, 0.42 * saturation, 1.08 * value ); + g.setColorAt( 0, c ); + c.setHsvF( hue, 0.58 * saturation, 1.05 * value ); + g.setColorAt( 0.25, c ); + c.setHsvF( hue, 0.70 * saturation, 1.03 * value ); + g.setColorAt( 0.5, c ); + + c.setHsvF( hue, 0.95 * saturation, 0.9 * value ); + g.setColorAt( 0.501, c ); + c.setHsvF( hue * 0.95, 0.95 * saturation, 0.95 * value ); + g.setColorAt( 0.75, c ); + c.setHsvF( hue * 0.90, 0.95 * saturation, 1 * value ); + g.setColorAt( 1.0, c ); + + return g; +} + +QLinearGradient darken( const QLinearGradient & _gradient ) +{ + QGradientStops stops = _gradient.stops(); + for (int i = 0; i < stops.size(); ++i) { + QColor color = stops.at(i).second; + stops[i].second = color.darker(160); + } + + QLinearGradient g = _gradient; + g.setStops(stops); + return g; +} + +void drawPath( QPainter *p, const QPainterPath &path, + const QColor &col, const QColor &borderCol, + bool dark = false ) +{ + const QRectF pathRect = path.boundingRect(); + + const QLinearGradient baseGradient = getGradient(col, pathRect); + const QLinearGradient darkGradient = darken(baseGradient); + + p->setOpacity(0.25); + + // glow + if (dark) + p->strokePath(path, QPen(darkGradient, 4)); + else + p->strokePath(path, QPen(baseGradient, 4)); + + p->setOpacity(1.0); + + // fill + if (dark) + p->fillPath(path, darkGradient); + else + p->fillPath(path, baseGradient); + + /* + QLinearGradient g(pathRect.topLeft(), pathRect.topRight()); + g.setCoordinateMode(QGradient::ObjectBoundingMode); + + p->setOpacity(0.2); + p->fillPath(path, g); +*/ + p->setOpacity(0.5); + + // highlight + if (dark) + p->strokePath(path, QPen(borderCol.darker(160), 2)); + else + p->strokePath(path, QPen(borderCol, 2)); + +} +}; + +using namespace PatternItemStuff; + + +PatternItem::PatternItem( TrackItem * _track, trackContentObject * _object ) : + TrackContentObjectItem( _track, _object ) +{ +} + +void PatternItem::paint( QPainter * _painter, + const QStyleOptionGraphicsItem * _option, QWidget * _widget ) +{ + + QColor col; + if( !isSelected() ) + { + col = QColor( 0x00, 0x33, 0x99 ); + } + else + { + col = QColor( 0x00, 0x99, 0x33 ); + } + QColor colBorder = col.lighter(160); + QColor col0 = col.darker(400); + + QRectF rc = boundingRect(); + + qreal xscale = _option->matrix.m11(); + _painter->save(); + _painter->scale( 1.0f/xscale, 1.0f ); + rc.setWidth( rc.width() * xscale ); + + QPainterPath path; + path.addRoundedRect(2, 2, rc.width()-4, rc.height()-4, 4, 4); + drawPath( _painter, path, col0, colBorder, false ); + + _painter->restore(); + + return; + + QColor col0a = col.darker( 300 ); + QColor col1 = col.light( 70 ); + QColor col2 = col.light( 40 ); + + QLinearGradient lingrad( 0, 0, 0, rc.height() ); + lingrad.setColorAt( 0, col0 ); + lingrad.setColorAt( 1, col0a ); + + QLinearGradient bordergrad( 0, 0, 0, rc.height() ); + bordergrad.setColorAt( 1, col2 ); + bordergrad.setColorAt( 0, col1 ); + + + rc.adjust( 0, 0, -1, -1 ); + + + _painter->setRenderHint( QPainter::Antialiasing, true ); + _painter->setBrush( lingrad ); + _painter->setPen( QPen( bordergrad, 1.5 ) ); // QColor( 6, 6, 6 ) ); + _painter->drawRoundedRect( rc, 4, 4 ); + _painter->setRenderHint( QPainter::Antialiasing, false ); + + _painter->restore(); +} + +QVariant PatternItem::itemChange( GraphicsItemChange _change, const QVariant & _value ) +{ + return TrackContentObjectItem::itemChange( _change, _value ); +} + + +void PatternItem::mousePressEvent( QGraphicsSceneMouseEvent * event ) +{ + TrackContentObjectItem::mousePressEvent( event ); +} + + + +void PatternItem::mouseReleaseEvent( QGraphicsSceneMouseEvent * event ) +{ + TrackContentObjectItem::mouseReleaseEvent( event ); +} + + +#include "gui/tracks/moc_pattern_item.cxx" diff --git a/src/gui/tracks/track_content_object_item.cpp b/src/gui/tracks/track_content_object_item.cpp index 60575ac3b..47b47533a 100644 --- a/src/gui/tracks/track_content_object_item.cpp +++ b/src/gui/tracks/track_content_object_item.cpp @@ -9,9 +9,6 @@ #include "gui/tracks/track_item.h" #include "track.h" -//QTimeLine TrackContentObjectItem::s_timeLine; -//QGraphicsItemAnimation TrackContentObjectItem::s_animation; -QTimeLine TrackContentObjectItem::s_snapBackTimeLine; TrackContentObjectItem::TrackContentObjectItem( TrackItem * _track, trackContentObject * _object ) : QObject(), diff --git a/src/gui/tracks/track_item.cpp b/src/gui/tracks/track_item.cpp index 54fe3ea15..601afecf9 100644 --- a/src/gui/tracks/track_item.cpp +++ b/src/gui/tracks/track_item.cpp @@ -4,6 +4,12 @@ #include "gui/tracks/track_content_object_item.h" #include "gui/tracks/track_container_scene.h" +#include "gui/tracks/bb_tco_item.h" +#include "gui/tracks/pattern_item.h" + +#include "bb_track.h" +#include "pattern.h" + TrackItem::TrackItem( TrackContainerScene * _scene, track * _track ) { m_scene = _scene; @@ -43,7 +49,22 @@ TrackItem::~TrackItem() void TrackItem::addTCO( trackContentObject * _tco ) { - TrackContentObjectItem * tcoItem = new TrackContentObjectItem( this, _tco ); + // TODO move into a factory? + TrackContentObjectItem * tcoItem; + + if( bbTCO * bbTco = dynamic_cast( _tco ) ) + { + tcoItem = new BbTrackContentObjectItem( this, (trackContentObject*)bbTco ); + } + else if( pattern * pat = dynamic_cast( _tco ) ) + { + tcoItem = new PatternItem( this, (trackContentObject*)pat ); + } + else + { + // Whoa. + return; + } // TODO refactor to private updateTCOGeometry tcoItem->setPos( tcoItem->x(), y() );