Work on codestyle and readability

This commit is contained in:
Jonas Trappenberg
2015-01-18 15:50:17 -08:00
parent c13d111bc2
commit 71bab17233
6 changed files with 89 additions and 96 deletions

View File

@@ -134,7 +134,7 @@ public:
const Plugin::PluginTypes m_type;
} ;
SubPluginFeatures * subPluginFeatures;
SubPluginFeatures *subPluginFeatures;
} ;
@@ -148,7 +148,9 @@ public:
// returns display-name out of descriptor
virtual QString displayName() const
{
return Model::displayName().isEmpty() ? m_descriptor->displayName : Model::displayName();
return Model::displayName().isEmpty()
? m_descriptor->displayName
: Model::displayName();
}
// return plugin-type
@@ -173,13 +175,13 @@ public:
// returns an instance of a plugin whose name matches to given one
// if specified plugin couldn't be loaded, it creates a dummy-plugin
static Plugin * instantiate( const QString& pluginName, Model * parent, void * data );
static Plugin * instantiate( const QString& pluginName, Model *parent, void * data );
// fills given list with descriptors of all available plugins
static void getDescriptorsOfAvailPlugins( DescriptorList& pluginDescriptors );
// create a view for the model
PluginView * createView( QWidget* parent );
PluginView* createView( QWidget* parent );
protected:

View File

@@ -97,13 +97,13 @@ inline float typeInfo<float>::minEps()
}
template<>
inline bool typeInfo<float>::isEqual( float _x, float _y )
inline bool typeInfo<float>::isEqual( float x, float y )
{
if( likely( _x == _y ) )
if( unlikely( x == y ) )
{
return true;
}
return absVal( _x - _y ) < minEps();
return absVal( x - y ) < minEps();
}

View File

@@ -94,24 +94,25 @@ MainWindow::MainWindow() :
QSplitter * splitter = new QSplitter( Qt::Horizontal, w );
splitter->setChildrenCollapsible( false );
QString wdir = ConfigManager::inst()->workingDir();
ConfigManager* confMgr = ConfigManager::inst();
QString wdir = confMgr->workingDir();
sideBar->appendTab( new PluginBrowser( splitter ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userProjectsDir() + "*" +
ConfigManager::inst()->factoryProjectsDir(),
confMgr->userProjectsDir() + "*" +
confMgr->factoryProjectsDir(),
"*.mmp *.mmpz *.xml *.mid *.flp",
tr( "My Projects" ),
embed::getIconPixmap( "project_file" ).transformed( QTransform().rotate( 90 ) ),
splitter, false, true ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userSamplesDir() + "*" +
ConfigManager::inst()->factorySamplesDir(),
confMgr->userSamplesDir() + "*" +
confMgr->factorySamplesDir(),
"*", tr( "My Samples" ),
embed::getIconPixmap( "sample_file" ).transformed( QTransform().rotate( 90 ) ),
splitter, false, true ) );
sideBar->appendTab( new FileBrowser(
ConfigManager::inst()->userPresetsDir() + "*" +
ConfigManager::inst()->factoryPresetsDir(),
confMgr->userPresetsDir() + "*" +
confMgr->factoryPresetsDir(),
"*.xpf *.cs.xml *.xiz",
tr( "My Presets" ),
embed::getIconPixmap( "preset_file" ).transformed( QTransform().rotate( 90 ) ),
@@ -121,33 +122,30 @@ MainWindow::MainWindow() :
embed::getIconPixmap( "home" ).transformed( QTransform().rotate( 90 ) ),
splitter, false, true ) );
QStringList root_paths;
QString title = tr( "Root directory" );
bool dirs_as_items = false;
#ifdef LMMS_BUILD_APPLE
title = tr( "Volumes" );
root_paths += "/Volumes";
#else
#elif defined(LMMS_BUILD_WIN32)
title = tr( "My Computer" );
dirs_as_items = true;
#endif
#if ! defined(LMMS_BUILD_APPLE)
QFileInfoList drives = QDir::drives();
foreach( const QFileInfo & drive, drives )
{
root_paths += drive.absolutePath();
}
#endif
sideBar->appendTab( new FileBrowser( root_paths.join( "*" ), "*",
#ifdef LMMS_BUILD_WIN32
tr( "My Computer" ),
#elif defined(LMMS_BUILD_APPLE)
tr( "Volumes" ),
#else
tr( "Root Directory" ),
#endif
sideBar->appendTab( new FileBrowser( root_paths.join( "*" ), "*", title,
embed::getIconPixmap( "computer" ).transformed( QTransform().rotate( 90 ) ),
splitter,
#ifdef LMMS_BUILD_WIN32
true
#else
false
#endif
) );
splitter, dirs_as_items) );
m_workspace = new QMdiArea( splitter );
@@ -190,13 +188,13 @@ MainWindow::MainWindow() :
vbox->addWidget( w );
setCentralWidget( main_widget );
m_updateTimer.start( 1000 / 20, this ); // 20 fps
m_updateTimer.start( 1000 / 20, this ); // 20 fps
if( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() )
{
// connect auto save
connect(&m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
m_autoSaveTimer.start(1000 * 60); // 1 minute
m_autoSaveTimer.start(1000 * 60); // 1 minute
}
connect( Engine::getSong(), SIGNAL( playbackStateChanged() ),
@@ -208,12 +206,10 @@ MainWindow::MainWindow() :
MainWindow::~MainWindow()
{
for( QList<PluginView *>::iterator it = m_tools.begin();
it != m_tools.end(); ++it )
for( PluginView *view : m_tools )
{
Model * m = ( *it )->model();
delete *it;
delete m;
delete view;
delete view->model();
}
// TODO: Close tools
// destroy engine which will do further cleanups etc.

View File

@@ -88,8 +88,6 @@ PluginBrowser::~PluginBrowser()
PluginDescList::PluginDescList(QWidget *parent) :
QWidget(parent)
{
@@ -98,7 +96,6 @@ PluginDescList::PluginDescList(QWidget *parent) :
Plugin::getDescriptorsOfAvailPlugins( m_pluginDescriptors );
std::sort(m_pluginDescriptors.begin(), m_pluginDescriptors.end(), pluginBefore);
for( Plugin::DescriptorList::const_iterator it = m_pluginDescriptors.constBegin();
it != m_pluginDescriptors.constEnd(); ++it )
{
@@ -117,8 +114,6 @@ PluginDescList::PluginDescList(QWidget *parent) :
PluginDescWidget::PluginDescWidget( const Plugin::Descriptor & _pd,
QWidget * _parent ) :
QWidget( _parent ),
@@ -181,7 +176,6 @@ void PluginDescWidget::paintEvent( QPaintEvent * )
m_targetHeight = qMax( 60, 25 + br.height() );
}
}
}
@@ -237,6 +231,7 @@ void PluginDescWidget::updateHeight()
m_updateTimer.stop();
return;
}
if( !m_updateTimer.isActive() )
{
m_updateTimer.start( 15 );

View File

@@ -45,73 +45,70 @@ namespace
#include "embedded_resources.h"
QPixmap getIconPixmap( const char * _name, int _w, int _h )
QPixmap getIconPixmap( const char * pixmapName, int width, int height )
{
if( _w == -1 || _h == -1 )
if( width == -1 || height == -1 )
{
// Return cached pixmap
QPixmap cached = s_pixmapCache.value( _name );
// Return cached pixmap
QPixmap cached = s_pixmapCache.value( pixmapName );
if( !cached.isNull() )
{
return cached;
}
// Or try to load it
QList<QByteArray> formats =
QImageReader::supportedImageFormats();
QList<QByteArray> formats = QImageReader::supportedImageFormats();
QList<QString> candidates;
QPixmap p;
QPixmap pixmap;
QString name;
int i;
for ( i = 0; i < formats.size() && p.isNull(); ++i )
for ( i = 0; i < formats.size() && pixmap.isNull(); ++i )
{
candidates << QString( _name ) + "." + formats.at( i ).data();
candidates << QString( pixmapName ) + "." + formats.at( i ).data();
}
#ifdef PLUGIN_NAME
for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
p = QPixmap( ConfigManager::inst()->artworkDir() + "plugins/" +
pixmap = QPixmap( ConfigManager::inst()->artworkDir() + "plugins/" +
STRINGIFY( PLUGIN_NAME ) + "_" + name );
}
#endif
for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
p = QPixmap( ConfigManager::inst()->artworkDir() + name );
pixmap = QPixmap( ConfigManager::inst()->artworkDir() + name );
}
// nothing found, so look in default-artwork-dir
for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
p = QPixmap( ConfigManager::inst()->defaultArtworkDir()
+ name );
pixmap = QPixmap( ConfigManager::inst()->defaultArtworkDir() + name );
}
for ( i = 0; i < candidates.size() && p.isNull(); ++i ) {
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
name = candidates.at( i );
const embed::descriptor & e =
findEmbeddedData( name.toUtf8().constData() );
// found?
if( QString( e.name ) == name )
if( name == e.name )
{
p.loadFromData( e.data, e.size );
pixmap.loadFromData( e.data, e.size );
}
}
// Fallback
if(p.isNull())
if( pixmap.isNull() )
{
p = QPixmap( 1, 1 );
pixmap = QPixmap( 1, 1 );
}
// Save to cache and return
s_pixmapCache.insert( _name, p );
return p;
s_pixmapCache.insert( pixmapName, pixmap );
return pixmap;
}
return getIconPixmap( _name ).
scaled( _w, _h, Qt::IgnoreAspectRatio,
return getIconPixmap( pixmapName ).
scaled( width, height, Qt::IgnoreAspectRatio,
Qt::SmoothTransformation );
}

View File

@@ -107,53 +107,56 @@ SideBar::~SideBar()
void SideBar::appendTab( SideBarWidget * _sbw )
void SideBar::appendTab( SideBarWidget *widget )
{
SideBarButton * btn = new SideBarButton( orientation(), this );
btn->setText( _sbw->title() );
btn->setIcon( _sbw->icon() );
btn->setCheckable( true );
m_widgets[btn] = _sbw;
m_btnGroup.addButton( btn );
addWidget( btn );
SideBarButton *button = new SideBarButton( orientation(), this );
button->setText( widget->title() );
button->setIcon( widget->icon() );
button->setCheckable( true );
m_widgets[button] = widget;
m_btnGroup.addButton( button );
addWidget( button );
_sbw->hide();
_sbw->setMinimumWidth( 200 );
widget->hide();
widget->setMinimumWidth( 200 );
ToolTip::add( btn, _sbw->title() );
ToolTip::add( button, widget->title() );
}
void SideBar::toggleButton( QAbstractButton * _btn )
void SideBar::toggleButton( QAbstractButton * button )
{
QToolButton * toolButton = NULL;
QWidget * activeWidget = NULL;
for( ButtonMap::Iterator it = m_widgets.begin();
it != m_widgets.end(); ++it )
QToolButton *toolButton = NULL;
QWidget *activeWidget = NULL;
for( auto it = m_widgets.begin(); it != m_widgets.end(); ++it )
{
QToolButton * curBtn = it.key();
if( curBtn != _btn )
QToolButton *curBtn = it.key();
QWidget *curWidget = it.value();
if( curBtn == button )
{
toolButton = curBtn;
activeWidget = curWidget;
}
else
{
curBtn->setChecked( false );
curBtn->setToolButtonStyle( Qt::ToolButtonIconOnly );
}
else
if( curWidget )
{
toolButton = it.key();
activeWidget = it.value();
}
if( it.value() )
{
it.value()->hide();
curWidget->hide();
}
}
if( toolButton && activeWidget )
{
activeWidget->setVisible( _btn->isChecked() );
toolButton->setToolButtonStyle( _btn->isChecked() ?
activeWidget->setVisible( button->isChecked() );
toolButton->setToolButtonStyle( button->isChecked() ?
Qt::ToolButtonTextBesideIcon : Qt::ToolButtonIconOnly );
}
}