diff --git a/data/themes/default/controller_bg.png b/data/themes/default/controller_bg.png deleted file mode 100644 index 6d7830fff..000000000 Binary files a/data/themes/default/controller_bg.png and /dev/null differ diff --git a/data/themes/default/timeline.png b/data/themes/default/timeline.png deleted file mode 100644 index b942d72d1..000000000 Binary files a/data/themes/default/timeline.png and /dev/null differ diff --git a/include/ControllerRackView.h b/include/ControllerRackView.h index eb99ded4d..f96dc7987 100644 --- a/include/ControllerRackView.h +++ b/include/ControllerRackView.h @@ -34,8 +34,10 @@ class QPushButton; class QScrollArea; +class QVBoxLayout; class ControllerView; +class Controller; class ControllerRackView : public QWidget, public SerializingObject @@ -56,12 +58,13 @@ public: public slots: void deleteController( ControllerView * _view ); + void onControllerAdded( Controller * ); + void onControllerRemoved( Controller * ); protected: virtual void closeEvent( QCloseEvent * _ce ); private slots: - virtual void update(); void addController(); @@ -69,8 +72,12 @@ private: QVector m_controllerViews; QScrollArea * m_scrollArea; + QVBoxLayout * m_scrollAreaLayout; QPushButton * m_addButton; + // Stores the index of where to insert the next ControllerView. + // Needed so that the StretchItem always stays at the last position. + int m_nextIndex; } ; #endif diff --git a/include/ControllerView.h b/include/ControllerView.h index f1d73c400..8903c0e3c 100644 --- a/include/ControllerView.h +++ b/include/ControllerView.h @@ -25,7 +25,7 @@ #ifndef CONTROLLER_VIEW_H #define CONTROLLER_VIEW_H -#include +#include #include "AutomatableModel.h" #include "Controller.h" @@ -39,7 +39,7 @@ class QMdiSubWindow; class LedCheckBox; -class ControllerView : public QWidget, public ModelView +class ControllerView : public QFrame, public ModelView { Q_OBJECT public: @@ -70,15 +70,14 @@ signals: protected: virtual void contextMenuEvent( QContextMenuEvent * _me ); - virtual void paintEvent( QPaintEvent * _pe ); virtual void modelChanged(); virtual void mouseDoubleClickEvent( QMouseEvent * event ); private: - QPixmap m_bg; QMdiSubWindow * m_subWindow; ControllerDialog * m_controllerDlg; + QLabel * m_nameLabel; bool m_show; } ; diff --git a/include/Song.h b/include/Song.h index 8f33a208b..8c7d6d899 100644 --- a/include/Song.h +++ b/include/Song.h @@ -323,6 +323,8 @@ private: void saveControllerStates( QDomDocument & doc, QDomElement & element ); void restoreControllerStates( const QDomElement & element ); + void removeAllControllers(); + AutomationTrack * m_globalAutomationTrack; @@ -376,6 +378,8 @@ signals: void lengthChanged( int tacts ); void tempoChanged( bpm_t newBPM ); void timeSignatureChanged( int oldTicksPerTact, int ticksPerTact ); + void controllerAdded( Controller * ); + void controllerRemoved( Controller * ); } ; diff --git a/include/TimeLineWidget.h b/include/TimeLineWidget.h index f962657e6..6487c840a 100644 --- a/include/TimeLineWidget.h +++ b/include/TimeLineWidget.h @@ -154,7 +154,6 @@ protected: private: - static QPixmap * s_timeLinePixmap; static QPixmap * s_posMarkerPixmap; static QPixmap * s_loopPointBeginPixmap; static QPixmap * s_loopPointEndPixmap; diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 325399e0b..bb9ecef4f 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -95,11 +95,6 @@ Controller::~Controller() s_controllers.remove( idx ); } - if( Engine::getSong() ) - { - Engine::getSong()->removeController( this ); - } - m_valueBuffer.clear(); // Remove connections by destroyed signal } diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 21ab0ed49..fe9a124b3 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -828,11 +828,7 @@ void Song::clearProject() gui->getProjectNotes()->clear(); } - // Move to function - while( !m_controllers.empty() ) - { - delete m_controllers.last(); - } + removeAllControllers(); emit dataChanged(); @@ -1215,6 +1211,19 @@ void Song::restoreControllerStates( const QDomElement & element ) } + +void Song::removeAllControllers() +{ + for (int i = 0; i < m_controllers.size(); ++i) + { + delete m_controllers.at(i); + } + + m_controllers.clear(); +} + + + void Song::exportProjectTracks() { exportProject( true ); @@ -1383,12 +1392,14 @@ void Song::setModified() -void Song::addController( Controller * c ) +void Song::addController( Controller * controller ) { - if( c != NULL && m_controllers.contains( c ) == false ) + if( controller && !m_controllers.contains( controller ) ) { - m_controllers.append( c ); - emit dataChanged(); + m_controllers.append( controller ); + emit controllerAdded( controller ); + + this->setModified(); } } @@ -1402,11 +1413,10 @@ void Song::removeController( Controller * controller ) { m_controllers.remove( index ); - if( Engine::getSong() ) - { - Engine::getSong()->setModified(); - } - emit dataChanged(); + emit controllerRemoved( controller ); + delete controller; + + this->setModified(); } } diff --git a/src/gui/FileBrowser.cpp b/src/gui/FileBrowser.cpp index ecb640277..ef05c6465 100644 --- a/src/gui/FileBrowser.cpp +++ b/src/gui/FileBrowser.cpp @@ -372,8 +372,6 @@ FileBrowserTreeWidget::FileBrowserTreeWidget(QWidget * parent ) : headerItem()->setHidden( true ); setSortingEnabled( false ); - setFont( pointSizeF( font(), 7.5f ) ); - connect( this, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), SLOT( activateListItem( QTreeWidgetItem *, int ) ) ); connect( this, SIGNAL( itemCollapsed( QTreeWidgetItem * ) ), diff --git a/src/gui/PluginBrowser.cpp b/src/gui/PluginBrowser.cpp index 6e7174168..6e7b9a619 100644 --- a/src/gui/PluginBrowser.cpp +++ b/src/gui/PluginBrowser.cpp @@ -68,7 +68,6 @@ PluginBrowser::PluginBrowser( QWidget * _parent ) : "Beat+Bassline Editor or into an " "existing instrument track." ), m_view ); - hint->setFont( pointSize<8>( hint->font() ) ); hint->setWordWrap( true ); QScrollArea* scrollarea = new QScrollArea( m_view ); @@ -153,8 +152,12 @@ void PluginDescWidget::paintEvent( QPaintEvent * ) p.drawRect( 0, 0, rect().right(), rect().bottom() ); p.drawPixmap( 4, 4, logo ); - QFont f = pointSize<8>( p.font() ); - f.setBold( true ); + QFont f = p.font(); + if ( m_mouseOver ) + { + f.setBold( true ); + } + p.setFont( f ); p.drawText( 10 + logo_size.width(), 15, m_pluginDescriptor.displayName ); @@ -162,7 +165,7 @@ void PluginDescWidget::paintEvent( QPaintEvent * ) if( height() > 24 || m_mouseOver ) { f.setBold( false ); - p.setFont( pointSize<8>( f ) ); + p.setFont( f ); QRect br; p.drawText( 10 + logo_size.width(), 20, width() - 58 - 5, 999, Qt::TextWordWrap, @@ -231,7 +234,7 @@ void PluginDescWidget::updateHeight() if( !m_updateTimer.isActive() ) { - m_updateTimer.start( 15 ); + m_updateTimer.start( 10 ); } } diff --git a/src/gui/TimeLineWidget.cpp b/src/gui/TimeLineWidget.cpp index 870d7288d..821683187 100644 --- a/src/gui/TimeLineWidget.cpp +++ b/src/gui/TimeLineWidget.cpp @@ -47,7 +47,6 @@ #endif -QPixmap * TimeLineWidget::s_timeLinePixmap = NULL; QPixmap * TimeLineWidget::s_posMarkerPixmap = NULL; QPixmap * TimeLineWidget::s_loopPointBeginPixmap = NULL; QPixmap * TimeLineWidget::s_loopPointEndPixmap = NULL; @@ -73,11 +72,6 @@ TimeLineWidget::TimeLineWidget( const int xoff, const int yoff, const float ppt, m_loopPos[0] = 0; m_loopPos[1] = DefaultTicksPerTact; - if( s_timeLinePixmap == NULL ) - { - s_timeLinePixmap = new QPixmap( embed::getIconPixmap( - "timeline" ) ); - } if( s_posMarkerPixmap == NULL ) { s_posMarkerPixmap = new QPixmap( embed::getIconPixmap( @@ -96,7 +90,7 @@ TimeLineWidget::TimeLineWidget( const int xoff, const int yoff, const float ppt, setAttribute( Qt::WA_OpaquePaintEvent, true ); move( 0, yoff ); - setFixedHeight( s_timeLinePixmap->height() ); + setFixedHeight( 18 ); m_xOffset -= s_posMarkerPixmap->width() / 2; @@ -250,10 +244,18 @@ void TimeLineWidget::paintEvent( QPaintEvent * ) int x = m_xOffset + s_posMarkerPixmap->width() / 2 - ( ( static_cast( m_begin * m_ppt ) / MidiTime::ticksPerTact() ) % static_cast( m_ppt ) ); - p.setPen( QColor( 192, 192, 192 ) ); + QColor lineColor( 192, 192, 192 ); + QColor tactColor( lineColor.darker( 120 ) ); + + // Set font to half of the widgets size (in pixels) + QFont font = p.font(); + font.setPixelSize( this->height() * 0.5 ); + p.setFont( font ); + for( int i = 0; x + i * m_ppt < width(); ++i ) { const int cx = x + qRound( i * m_ppt ); + p.setPen( lineColor ); p.drawLine( cx, 5, cx, height() - 6 ); ++tact_num; if( ( tact_num - 1 ) % @@ -261,9 +263,10 @@ void TimeLineWidget::paintEvent( QPaintEvent * ) MidiTime::ticksPerTact() / m_ppt ) ) == 0 ) { const QString s = QString::number( tact_num ); + p.setPen( tactColor ); p.drawText( cx + qRound( ( m_ppt - p.fontMetrics(). width( s ) ) / 2 ), - height() - p.fontMetrics().height() / 2, s ); + height() - p.fontMetrics().ascent() / 2, s ); } } diff --git a/src/gui/widgets/ControllerRackView.cpp b/src/gui/widgets/ControllerRackView.cpp index 182571093..2bf7054a8 100644 --- a/src/gui/widgets/ControllerRackView.cpp +++ b/src/gui/widgets/ControllerRackView.cpp @@ -28,9 +28,11 @@ #include #include #include +#include #include #include #include +#include #include "Song.h" #include "embed.h" @@ -43,32 +45,33 @@ ControllerRackView::ControllerRackView( ) : - QWidget() + QWidget(), + m_nextIndex(0) { - setMinimumWidth( 250 ); - setMaximumWidth( 250 ); - resize( 250, 160 ); - setWindowIcon( embed::getIconPixmap( "controller" ) ); setWindowTitle( tr( "Controller Rack" ) ); m_scrollArea = new QScrollArea( this ); - m_scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); - m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_scrollArea->setPalette( QApplication::palette( m_scrollArea ) ); - m_scrollArea->setMinimumHeight( 64 ); + m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + + QWidget * scrollAreaWidget = new QWidget( m_scrollArea ); + m_scrollAreaLayout = new QVBoxLayout( scrollAreaWidget ); + m_scrollAreaLayout->addStretch(); + scrollAreaWidget->setLayout( m_scrollAreaLayout ); + + m_scrollArea->setWidget( scrollAreaWidget ); + m_scrollArea->setWidgetResizable( true ); m_addButton = new QPushButton( this ); m_addButton->setText( tr( "Add" ) ); - QWidget * w = new QWidget(); - m_scrollArea->setWidget( w ); - connect( m_addButton, SIGNAL( clicked() ), this, SLOT( addController() ) ); - connect( Engine::getSong(), SIGNAL( dataChanged() ), - this, SLOT( update() ) ); + Song * song = Engine::getSong(); + connect( song, SIGNAL( controllerAdded( Controller* ) ), SLOT( onControllerAdded( Controller* ) ) ); + connect( song, SIGNAL( controllerRemoved( Controller* ) ), SLOT( onControllerRemoved( Controller* ) ) ); QVBoxLayout * layout = new QVBoxLayout(); layout->addWidget( m_scrollArea ); @@ -82,8 +85,9 @@ ControllerRackView::ControllerRackView( ) : flags &= ~Qt::WindowMaximizeButtonHint; subWin->setWindowFlags( flags ); - parentWidget()->setAttribute( Qt::WA_DeleteOnClose, false ); - parentWidget()->move( 880, 310 ); + subWin->setAttribute( Qt::WA_DeleteOnClose, false ); + subWin->move( 680, 310 ); + subWin->resize(400, 200); } @@ -91,8 +95,6 @@ ControllerRackView::ControllerRackView( ) : ControllerRackView::~ControllerRackView() { - // delete scroll-area with all children - delete m_scrollArea; } @@ -119,8 +121,7 @@ void ControllerRackView::deleteController( ControllerView * _view ) { Controller * c = _view->getController(); - int connectionCount = c->connectionCount(); - if( connectionCount > 0 ) + if( c->connectionCount() > 0 ) { QMessageBox msgBox; msgBox.setIcon( QMessageBox::Question ); @@ -134,58 +135,64 @@ void ControllerRackView::deleteController( ControllerView * _view ) } } - - m_controllerViews.erase( qFind( m_controllerViews.begin(), - m_controllerViews.end(), _view ) ); - delete _view; - delete c; - update(); + Song * song = Engine::getSong(); + song->removeController( c ); } -void ControllerRackView::update() +void ControllerRackView::onControllerAdded( Controller * controller ) { - QWidget * w = m_scrollArea->widget(); - Song * s = Engine::getSong(); + QWidget * scrollAreaWidget = m_scrollArea->widget(); - setUpdatesEnabled( false ); + ControllerView * controllerView = new ControllerView( controller, scrollAreaWidget ); - int i = 0; - for( i = 0; i < m_controllerViews.size(); ++i ) - { - delete m_controllerViews[i]; - } + connect( controllerView, SIGNAL( deleteController( ControllerView * ) ), + this, SLOT( deleteController( ControllerView * ) ), Qt::QueuedConnection ); - m_controllerViews.clear(); + m_controllerViews.append( controllerView ); + m_scrollAreaLayout->insertWidget( m_nextIndex, controllerView ); - for( i = 0; i < s->m_controllers.size(); ++i ) - { - ControllerView * v = new ControllerView( s->m_controllers[i], w ); - - connect( v, SIGNAL( deleteController( ControllerView * ) ), - this, SLOT( deleteController( ControllerView * ) ), - Qt::QueuedConnection ); - - m_controllerViews.append( v ); - v->move( 0, i*32 ); - v->show(); - } - - w->setFixedSize( 210, i*32 ); - - setUpdatesEnabled( true ); - QWidget::update(); + ++m_nextIndex; } + + +void ControllerRackView::onControllerRemoved( Controller * removedController ) +{ + ControllerView * viewOfRemovedController = 0; + + QVector::const_iterator end = m_controllerViews.end(); + for ( QVector::const_iterator it = m_controllerViews.begin(); it != end; ++it) + { + ControllerView *currentControllerView = *it; + if ( currentControllerView->getController() == removedController ) + { + viewOfRemovedController = currentControllerView; + break; + } + } + + if (viewOfRemovedController ) + { + m_controllerViews.erase( qFind( m_controllerViews.begin(), + m_controllerViews.end(), viewOfRemovedController ) ); + + delete viewOfRemovedController; + --m_nextIndex; + } +} + + + + void ControllerRackView::addController() { // TODO: Eventually let the user pick from available controller types Engine::getSong()->addController( new LfoController( Engine::getSong() ) ); - update(); // fix bug which always made ControllerRackView loose focus when adding // new controller diff --git a/src/gui/widgets/ControllerView.cpp b/src/gui/widgets/ControllerView.cpp index b6ed84333..641f27e78 100644 --- a/src/gui/widgets/ControllerView.cpp +++ b/src/gui/widgets/ControllerView.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "ControllerView.h" @@ -46,22 +47,35 @@ ControllerView::ControllerView( Controller * _model, QWidget * _parent ) : - QWidget( _parent ), + QFrame( _parent ), ModelView( _model, this ), - m_bg( embed::getIconPixmap( "controller_bg" ) ), m_subWindow( NULL ), m_controllerDlg( NULL ), m_show( true ) { - setFixedSize( 210, 32 ); + this->setFrameStyle( QFrame::StyledPanel ); + this->setFrameShadow( QFrame::Raised ); + + QVBoxLayout *vBoxLayout = new QVBoxLayout(this); + + QHBoxLayout *hBox = new QHBoxLayout(); + vBoxLayout->addLayout(hBox); + + QLabel *label = new QLabel( "" + _model->displayName() + "", this); + QSizePolicy sizePolicy = label->sizePolicy(); + sizePolicy.setHorizontalStretch(1); + label->setSizePolicy(sizePolicy); + + hBox->addWidget(label); + + QPushButton * controlsButton = new QPushButton( tr( "Controls" ), this ); + connect( controlsButton, SIGNAL( clicked() ), SLOT( editControls() ) ); + + hBox->addWidget(controlsButton); + + m_nameLabel = new QLabel(_model->name(), this); + vBoxLayout->addWidget(m_nameLabel); - QPushButton * ctls_btn = new QPushButton( tr( "Controls" ), this ); - - QFont f = ctls_btn->font(); - ctls_btn->setFont( pointSize<8>( f ) ); - ctls_btn->setGeometry( 140, 2, 50, 14 ); - connect( ctls_btn, SIGNAL( clicked() ), - this, SLOT( editControls() ) ); m_controllerDlg = getController()->createDialog( gui->mainWindow()->workspace() ); @@ -90,7 +104,6 @@ ControllerView::ControllerView( Controller * _model, QWidget * _parent ) : ControllerView::~ControllerView() { - delete m_subWindow; } @@ -128,28 +141,6 @@ void ControllerView::deleteController() -void ControllerView::paintEvent( QPaintEvent * ) -{ - QPainter p( this ); - p.drawPixmap( 0, 0, m_bg ); - - QFont f = pointSizeF( font(), 7.5f ); - f.setBold( true ); - p.setFont( f ); - - Controller * c = castModel(); - - p.setPen( QColor( 64, 64, 64 ) ); - p.drawText( 7, 13, c->displayName() ); - p.setPen( Qt::white ); - p.drawText( 6, 12, c->displayName() ); - - f.setBold( false ); - p.setFont( f ); - p.drawText( 8, 26, c->name() ); -} - - void ControllerView::mouseDoubleClickEvent( QMouseEvent * event ) { @@ -162,7 +153,7 @@ void ControllerView::mouseDoubleClickEvent( QMouseEvent * event ) if( ok && !new_name.isEmpty() ) { c->setName( new_name ); - update(); + m_nameLabel->setText( new_name ); } } diff --git a/src/gui/widgets/SideBarWidget.cpp b/src/gui/widgets/SideBarWidget.cpp index 2da0c9a45..c1559f909 100644 --- a/src/gui/widgets/SideBarWidget.cpp +++ b/src/gui/widgets/SideBarWidget.cpp @@ -55,21 +55,22 @@ SideBarWidget::~SideBarWidget() void SideBarWidget::paintEvent( QPaintEvent * ) { - const int TITLE_FONT_HEIGHT = 13; - QPainter p( this ); p.fillRect( 0, 0, width(), 27, palette().highlight().color() ); QFont f = p.font(); f.setBold( true ); - p.setFont( pointSize( f ) ); + f.setUnderline( true ); + f.setPointSize( f.pointSize() + 2 ); + p.setFont( f ); p.setPen( palette().highlightedText().color() ); const int tx = m_icon.width()+4; - const int ty = 2+TITLE_FONT_HEIGHT; + + QFontMetrics metrics( f ); + const int ty = metrics.ascent(); p.drawText( tx, ty, m_title ); - p.drawLine( tx, ty+4, width()-4, ty+4 ); p.drawPixmap( 2, 2, m_icon.transformed( QTransform().rotate( -90 ) ) ); }