Merge branch 'master' into fx-mixer-rework

This commit is contained in:
Tobias Doerffel
2009-11-26 01:47:38 +01:00
304 changed files with 28806 additions and 15914 deletions

View File

@@ -22,7 +22,7 @@
*
*/
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include "LocalResourceProvider.h"
@@ -45,6 +45,8 @@ LocalResourceProvider::LocalResourceProvider(
connect( database(), SIGNAL( directoryItemRemoved( const QString & ) ),
this, SLOT( removeDirectory( const QString & ) ) );
m_watcher.addPath( ResourceItem::getBaseDirectory( m_baseDir ) + m_dir );
database()->init();
}
@@ -120,23 +122,30 @@ void LocalResourceProvider::reloadDirectory( const QString & _path )
p += QDir::separator();
}
foreach( ResourceItem * it, database()->items() )
if( p == ResourceItem::getBaseDirectory( m_baseDir ) + m_dir )
{
if( it->type() == ResourceItem::TypeDirectory &&
it->fullName() == p )
{
dirRelation = it->relation();
}
updateDatabase();
}
if( dirRelation )
else
{
ResourceItem * dirItem = dirRelation->item();
if( dirItem )
foreach( ResourceItem * it, database()->items() )
{
m_scannedFolders.clear();
readDir( dirItem->fullRelativeName(),
dirRelation->parent() );
if( it->type() == ResourceItem::TypeDirectory &&
it->fullName() == p )
{
dirRelation = it->relation();
}
}
if( dirRelation )
{
ResourceItem * dirItem = dirRelation->item();
if( dirItem )
{
m_scannedFolders.clear();
readDir( dirItem->fullRelativeName(),
dirRelation->parent() );
}
}
}
@@ -165,7 +174,7 @@ void LocalResourceProvider::readDir( const QString & _dir,
ResourceItem::Relation * curParent = _parent->findChild( d.dirName() +
QDir::separator(),
m_baseDir );
printf("read dir: %s\n", d.canonicalPath().toUtf8().constData() );
qDebug() << "read dir" << d.canonicalPath();
if( curParent )
{
parentItem = curParent->item();
@@ -202,6 +211,7 @@ printf("read dir: %s\n", d.canonicalPath().toUtf8().constData() );
{
if( f.isSymLink() )
{
qDebug() << "following symlink" << f.canonicalFilePath() << "to" << f.symLinkTarget();
f = QFileInfo( f.symLinkTarget() );
}
@@ -268,7 +278,7 @@ printf("read dir: %s\n", d.canonicalPath().toUtf8().constData() );
{
ResourceItem::Relation * item = *it;
it = curParent->children().erase( it );
database()->recursiveRemoveItems( item );
database()->removeItemsRecursively( item );
}
else
{

View File

@@ -98,6 +98,21 @@ bool ResourceAction::importProject( trackContainer * _target )
bool ResourceAction::defaultTrigger()
{
switch( m_action )
{
case LoadProject:
return loadProject();
case ImportFile:
return importProject( engine::getSong() );
default:
break;
}
return false;
}
#include "moc_ResourceAction.cxx"

View File

@@ -98,7 +98,7 @@ void ResourceDB::init()
void ResourceDB::load( const QString & _file )
{
recursiveRemoveItems( topLevelNode(), false );
removeItemsRecursively( topLevelNode(), false );
multimediaProject m( _file );
@@ -283,7 +283,7 @@ void ResourceDB::addItem( ResourceItem * newItem )
ResourceItem::Relation * oldRelation = oldItem->relation();
if( oldRelation )
{
recursiveRemoveItems( oldRelation, false );
removeItemsRecursively( oldRelation, false );
delete oldRelation;
}
if( oldItem->type() == ResourceItem::TypeDirectory )
@@ -299,8 +299,8 @@ void ResourceDB::addItem( ResourceItem * newItem )
void ResourceDB::recursiveRemoveItems( ResourceItem::Relation * parent,
bool removeTopLevelParent )
void ResourceDB::removeItemsRecursively( ResourceItem::Relation * parent,
bool removeParent )
{
if( !parent )
{
@@ -309,10 +309,10 @@ void ResourceDB::recursiveRemoveItems( ResourceItem::Relation * parent,
while( !parent->children().isEmpty() )
{
recursiveRemoveItems( parent->children().front() );
removeItemsRecursively( parent->children().front() );
}
if( removeTopLevelParent && parent->item() )
if( removeParent && parent->item() )
{
if( parent->item()->type() == ResourceItem::TypeDirectory )
{

View File

@@ -35,6 +35,7 @@
#include "gui_templates.h"
#include "templates.h"
#include "Cpu.h"
#include "engine.h"
static void stream_write_callback(pa_stream *s, size_t length, void *userdata)
@@ -51,6 +52,7 @@ AudioPulseAudio::AudioPulseAudio( bool & _success_ful, mixer * _mixer ) :
DEFAULT_CHANNELS, SURROUND_CHANNELS ),
_mixer ),
m_s( NULL ),
m_quit( false ),
m_convertEndian( false )
{
_success_ful = false;
@@ -68,11 +70,6 @@ AudioPulseAudio::AudioPulseAudio( bool & _success_ful, mixer * _mixer ) :
AudioPulseAudio::~AudioPulseAudio()
{
stopProcessing();
if( m_s != NULL )
{
pa_stream_unref( m_s );
}
}
@@ -173,11 +170,29 @@ static void context_state_callback(pa_context *c, void *userdata)
_this->m_s = pa_stream_new( c, "lmms", &_this->m_sampleSpec, NULL);
pa_stream_set_state_callback( _this->m_s, stream_state_callback, _this );
pa_stream_set_write_callback( _this->m_s, stream_write_callback, _this );
pa_stream_connect_playback( _this->m_s, NULL, NULL,
(pa_stream_flags) 0,
pa_cvolume_set( &cv, _this->m_sampleSpec.channels,
PA_VOLUME_NORM ),
NULL );
pa_buffer_attr buffer_attr;
buffer_attr.maxlength = (uint32_t)(-1);
// play silence in case of buffer underun instead of using default rewind
buffer_attr.prebuf = 0;
buffer_attr.minreq = (uint32_t)(-1);
buffer_attr.fragsize = (uint32_t)(-1);
double latency = (double)( engine::getMixer()->framesPerPeriod() ) /
(double)_this->sampleRate();
// ask PulseAudio for the desired latency (which might not be approved)
buffer_attr.tlength = pa_usec_to_bytes( latency * PA_USEC_PER_MSEC,
&_this->m_sampleSpec );
pa_stream_connect_playback( _this->m_s, NULL, &buffer_attr,
PA_STREAM_ADJUST_LATENCY,
pa_cvolume_set( &cv, _this->m_sampleSpec.channels,
PA_VOLUME_NORM ),
NULL );
break;
}
@@ -195,51 +210,59 @@ static void context_state_callback(pa_context *c, void *userdata)
void AudioPulseAudio::run()
{
pa_mainloop * m = NULL;
if (!(m = pa_mainloop_new())) {
pa_mainloop * mainLoop = pa_mainloop_new();
if( !mainLoop )
{
qCritical( "pa_mainloop_new() failed.\n" );
return;
}
pa_mainloop_api * mainloop_api = pa_mainloop_get_api(m);
pa_mainloop_api * mainloop_api = pa_mainloop_get_api( mainLoop );
pa_context *context = pa_context_new(mainloop_api, "lmms");
pa_context *context = pa_context_new( mainloop_api, "lmms" );
if ( context == NULL )
{
qCritical( "pa_context_new() failed." );
qCritical( "pa_context_new() failed." );
return;
}
pa_context_set_state_callback(context, context_state_callback, this );
/* Connect the context */
pa_context_connect(context, NULL, (pa_context_flags) 0, NULL);
pa_context_set_state_callback( context, context_state_callback, this );
// connect the context
pa_context_connect( context, NULL, (pa_context_flags) 0, NULL );
int ret;
/* Run the main loop */
if (pa_mainloop_run(m, &ret) < 0)
// run the main loop
int ret = 0;
m_quit = false;
while( m_quit == false && pa_mainloop_iterate( mainLoop, 1, &ret ) >= 0 )
{
qCritical( "pa_mainloop_run() failed.\n" );
}
pa_stream_disconnect( m_s );
pa_stream_unref( m_s );
pa_context_disconnect( context );
pa_context_unref( context );
pa_mainloop_free( mainLoop );
}
void AudioPulseAudio::streamWriteCallback(pa_stream *s, size_t length)
void AudioPulseAudio::streamWriteCallback( pa_stream *s, size_t length )
{
const fpp_t fpp = getMixer()->framesPerPeriod();
sampleFrameA * temp = CPU::allocFrames( fpp );
Sint16 * pcmbuf = (Sint16*)pa_xmalloc( fpp * channels() *
Sint16 * pcmbuf = (Sint16*)CPU::memAlloc( fpp * channels() *
sizeof(Sint16) );
size_t fd = 0;
while( fd < length/4 )
while( fd < length/4 && m_quit == false )
{
const fpp_t frames = getNextBuffer( temp );
if( !frames )
{
return;
m_quit = true;
break;
}
int bytes = CPU::convertToS16( temp,
(intSampleFrameA *) pcmbuf,
@@ -254,7 +277,7 @@ void AudioPulseAudio::streamWriteCallback(pa_stream *s, size_t length)
fd += frames;
}
pa_xfree( pcmbuf );
CPU::memFree( pcmbuf );
CPU::freeFrames( temp );
}

View File

@@ -458,6 +458,9 @@ int main( int argc, char * * argv )
engine::mainWindow()->showMaximized();
}
engine::getSong()->loadProject( file_to_load );
// don't show welcome screen
engine::mainWindow()->showWelcomeScreen( false );
}
else if( !file_to_import.isEmpty() )
{
@@ -472,6 +475,9 @@ int main( int argc, char * * argv )
{
engine::mainWindow()->showMaximized();
}
// don't show welcome screen
engine::mainWindow()->showWelcomeScreen( false );
}
else
{
@@ -484,6 +490,9 @@ int main( int argc, char * * argv )
{
engine::mainWindow()->showMaximized();
}
// show welcome screen
engine::mainWindow()->showWelcomeScreen();
}
}
else
@@ -519,9 +528,7 @@ int main( int argc, char * * argv )
}
}
const int ret = app->exec();
delete app;
return( ret );
return app->exec();
}

View File

@@ -0,0 +1,50 @@
/*
* DirectorySelectDialog.cpp - implementation of DirectorySelectDialog
*
* Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "DirectorySelectDialog.h"
#include "ui_DirectorySelectDialog.h"
DirectorySelectDialog::DirectorySelectDialog( QWidget * _parent,
DatabaseScope _databaseScope ) :
ResourceSelectDialog( _parent, ResourceSelectDialog::TreeModel,
_databaseScope ),
ui( new Ui::DirectorySelectDialog )
{
// setup form
ui->setupUi( this );
// setup ResourceSelectDialog
setupUi();
}
DirectorySelectDialog::~DirectorySelectDialog()
{
}

View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DirectorySelectDialog</class>
<widget class="QDialog" name="DirectorySelectDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>465</width>
<height>546</height>
</rect>
</property>
<property name="windowTitle">
<string>Select directory</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="filterEdit"/>
</item>
<item>
<widget class="ResourceTreeView" name="resourceTreeView">
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ResourceTreeView</class>
<extends>QTreeView</extends>
<header>ResourceTreeView.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>filterEdit</tabstop>
<tabstop>resourceTreeView</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DirectorySelectDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DirectorySelectDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,776 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PreferencesDialog</class>
<widget class="QDialog" name="PreferencesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>577</width>
<height>478</height>
</rect>
</property>
<property name="windowTitle">
<string>Preferences</string>
</property>
<property name="styleSheet">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="3">
<widget class="QListWidget" name="configPageSelector">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>101</width>
<height>470</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>101</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">::item { width:87; }
</string>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="spacing">
<number>4</number>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="currentRow">
<number>-1</number>
</property>
<item>
<property name="text">
<string>General</string>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled</set>
</property>
</item>
<item>
<property name="text">
<string>Directories</string>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled</set>
</property>
</item>
<item>
<property name="text">
<string>Audio</string>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled</set>
</property>
</item>
<item>
<property name="text">
<string>MIDI</string>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled</set>
</property>
</item>
<item>
<property name="text">
<string>Plugins</string>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled</set>
</property>
</item>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QStackedWidget" name="configPages">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="generalSettingsPage">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>16</number>
</property>
<item>
<widget class="QLabel" name="generalTitleLabel">
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>General settings</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>User interface</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="enableToolTips">
<property name="text">
<string>Enable tooltips</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="showVolumeAsDBV">
<property name="text">
<string>Show volume as dbV</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="showWelcomeScreen">
<property name="text">
<string>Show welcome screen</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Online resources</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<property name="horizontalSpacing">
<number>10</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="enableOnlineResourcesCheckBox">
<property name="text">
<string>Enable online resources</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="enableUploadsCheckBox">
<property name="text">
<string>Enable uploads</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="usernameEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="passwordEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="directorySettingsPage"/>
<widget class="QWidget" name="audioSettingsPage">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>16</number>
</property>
<item>
<widget class="QLabel" name="generalTitleLabel_2">
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Audio settings</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>General</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>10</number>
</property>
<property name="horizontalSpacing">
<number>10</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Buffer size</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Sample rate</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="sampleRate">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>44100 Hz</string>
</property>
</item>
<item>
<property name="text">
<string>48000 Hz</string>
</property>
</item>
<item>
<property name="text">
<string>88200 Hz</string>
</property>
</item>
<item>
<property name="text">
<string>96000 Hz</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="bufferSize">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>3</number>
</property>
<item>
<property name="text">
<string>32</string>
</property>
</item>
<item>
<property name="text">
<string>64</string>
</property>
</item>
<item>
<property name="text">
<string>128</string>
</property>
</item>
<item>
<property name="text">
<string>256 (default)</string>
</property>
</item>
<item>
<property name="text">
<string>512</string>
</property>
</item>
<item>
<property name="text">
<string>1024</string>
</property>
</item>
<item>
<property name="text">
<string>2048</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Audio engine</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>10</number>
</property>
<property name="horizontalSpacing">
<number>10</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Audio engine</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="audioEngine">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Device</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="audioDevice">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="midiSettingsPage">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>16</number>
</property>
<item>
<widget class="QLabel" name="generalTitleLabel_3">
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>MIDI settings</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>MIDI engine</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>10</number>
</property>
<property name="horizontalSpacing">
<number>10</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>MIDI engine</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="midiEngine">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Device</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="midiDevice">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="midiRemoteControl">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="title">
<string>MIDI remote control</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="pluginsSettingsPage">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>16</number>
</property>
<item>
<widget class="QLabel" name="generalTitleLabel_4">
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Plugins settings</string>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string/>
</attribute>
<layout class="QGridLayout" name="gridLayout_7"/>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="2" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PreferencesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PreferencesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>enableUploadsCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>usernameEdit</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>299</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>336</x>
<y>283</y>
</hint>
</hints>
</connection>
<connection>
<sender>enableUploadsCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>passwordEdit</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>299</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>336</x>
<y>317</y>
</hint>
</hints>
</connection>
<connection>
<sender>enableOnlineResourcesCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>enableUploadsCheckBox</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>299</x>
<y>226</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
<y>253</y>
</hint>
</hints>
</connection>
<connection>
<sender>configPageSelector</sender>
<signal>currentRowChanged(int)</signal>
<receiver>configPages</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>54</x>
<y>238</y>
</hint>
<hint type="destinationlabel">
<x>340</x>
<y>224</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -356,6 +356,9 @@ p, li { white-space: pre-wrap; }
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="iconSize">
<size>
<width>16</width>
@@ -375,6 +378,9 @@ p, li { white-space: pre-wrap; }
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="iconSize">
<size>
<width>16</width>

View File

@@ -51,9 +51,10 @@
#include "engine.h"
#include "FxMixerView.h"
#include "AboutDialog.h"
#include "PreferencesDialog.h"
#include "ControllerRackView.h"
#include "plugin_browser.h"
#include "side_bar.h"
#include "SideBar.h"
#include "config_mgr.h"
#include "mixer.h"
#include "project_notes.h"
@@ -92,26 +93,22 @@ MainWindow::MainWindow() :
vbox->setSpacing( 0 );
vbox->setMargin( 0 );
QWidget * w = new QWidget( m_mainWidget );
QHBoxLayout * hbox = new QHBoxLayout( w );
hbox->setSpacing( 0 );
hbox->setMargin( 0 );
sideBar * side_bar = new sideBar( sideBar::Vertical, w );
side_bar->setStyle( sideBar::VSNET/*KDEV3ICON*/ );
side_bar->setPosition( sideBar::Left );
SideBar * sideBar = new SideBar( Qt::Vertical, w );
QSplitter * splitter = new QSplitter( Qt::Horizontal, w );
splitter->setChildrenCollapsible( false );
int id = 0;
QString wdir = configManager::inst()->workingDir();
side_bar->appendTab( new pluginBrowser( splitter ), ++id );
sideBar->appendTab( new pluginBrowser( splitter ) );
// add a resource browser to sidebar
m_resourceBrowser = new ResourceBrowser( splitter );
side_bar->appendTab( m_resourceBrowser, ++id );
sideBar->appendTab( m_resourceBrowser );
m_workspace = new QMdiArea( splitter );
@@ -136,7 +133,7 @@ MainWindow::MainWindow() :
m_workspace->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
m_workspace->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
hbox->addWidget( side_bar );
hbox->addWidget( sideBar );
hbox->addWidget( splitter );
@@ -155,17 +152,14 @@ MainWindow::MainWindow() :
vbox->addWidget( m_toolBar );
vbox->addWidget( w );
m_updateTimer.start( 1000 / 20, this ); // 20 fps
m_welcomeScreen = new WelcomeScreen( this );
setCentralWidget( m_welcomeScreen );
m_updateTimer.start( 1000 / 20, this ); // 20 fps
m_welcomeScreen->setVisible( false );
}
MainWindow::~MainWindow()
{
for( QList<PluginView *>::Iterator it = m_tools.begin();
@@ -185,15 +179,14 @@ MainWindow::~MainWindow()
void MainWindow::setMainWidgetVisible( bool _visible )
void MainWindow::showWelcomeScreen(bool _visible)
{
setCentralWidget( _visible ? m_mainWidget : m_welcomeScreen );
m_welcomeScreen->setVisible( _visible );
setCentralWidget( _visible ? m_welcomeScreen : m_mainWidget );
}
void MainWindow::finalize()
{
resetWindowTitle();
@@ -265,6 +258,10 @@ void MainWindow::finalize()
edit_menu->addAction( embed::getIconPixmap( "setup_general" ),
tr( "Settings" ),
this, SLOT( showSettingsDialog() ) );
edit_menu->addSeparator();
edit_menu->addAction( embed::getIconPixmap( "setup_general" ),
tr( "Preferences (premature dialog)" ),
this, SLOT( showPreferencesDialog() ) );
m_toolsMenu = new QMenu( this );
@@ -315,8 +312,7 @@ void MainWindow::finalize()
// create the grid layout for the first buttons area
QWidget * gridButtons_w = new QWidget( m_toolBar );
QGridLayout * gridButtons_layout = new QGridLayout( gridButtons_w/*, 2, 1*/ );
QGridLayout * gridButtons_layout = new QGridLayout( gridButtons_w );
// create tool-buttons
toolButton * project_new = new toolButton(
@@ -1059,6 +1055,14 @@ void MainWindow::showSettingsDialog()
void MainWindow::showPreferencesDialog()
{
PreferencesDialog().exec();
}
void MainWindow::aboutLMMS()
{
AboutDialog().exec();
@@ -1200,6 +1204,12 @@ void MainWindow::closeEvent( QCloseEvent * _ce )
}
void MainWindow::showEvent( QShowEvent * _se )
{
//showWelcomeScreen( false ); // must explicitly ask for welcome screen
_se->accept();
}
void MainWindow::focusOutEvent( QFocusEvent * _fe )

View File

@@ -0,0 +1,55 @@
/*
* PreferencesDialog.cpp - implementation of PreferencesDialog
*
* Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "PreferencesDialog.h"
#include "embed.h"
#include "engine.h"
#include "MainWindow.h"
#include "ui_PreferencesDialog.h"
PreferencesDialog::PreferencesDialog() :
QDialog( engine::mainWindow() ),
ui( new Ui::PreferencesDialog )
{
ui->setupUi( this );
// set up icons in page selector view on the left side
static const char * icons[] = {
"preferences-system",
"folder-64",
"preferences-desktop-sound",
"setup-midi",
"setup-plugins"
} ;
for( int i = 0; i < qMin<int>( sizeof( icons ),
ui->configPageSelector->count() ); ++i )
{
ui->configPageSelector->item( i )->setIcon(
embed::getIconPixmap( icons[i] ) );
}
}

View File

@@ -23,21 +23,23 @@
*/
#include "QuickLoadDialog.h"
#include "ResourceListModel.h"
#include "engine.h"
#include "ui_QuickLoadDialog.h"
QuickLoadDialog::QuickLoadDialog( QWidget * _parent,
ResourceItem::Type _typeFilter ) :
QDialog( _parent ),
ui( new Ui::QuickLoadDialog ),
m_listModel( new ResourceListModel( engine::mergedResourceDB(), this ) )
ResourceItem::Type _typeFilter,
DatabaseScope _databaseScope ) :
ResourceSelectDialog( _parent, ResourceSelectDialog::ListModel,
_databaseScope ),
ui( new Ui::QuickLoadDialog )
{
// setup form
ui->setupUi( this );
// setup ResourceSelectDialog
setupUi();
// setup type combobox + type filtering
for( int i = ResourceItem::TypeUnknown+1; i < ResourceItem::NumTypes; ++i )
{
@@ -53,16 +55,6 @@ QuickLoadDialog::QuickLoadDialog( QWidget * _parent,
{
ui->resourceTypeComboBox->setCurrentIndex( _typeFilter );
}
// setup list view to display our model
ui->resourceListView->setModel( m_listModel );
ui->resourceListView->selectionModel()->select(
m_listModel->index( 0, 0 ),
QItemSelectionModel::SelectCurrent );
// connect filter edit with model
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
m_listModel, SLOT( setKeywordFilter( const QString & ) ) );
}
@@ -70,18 +62,6 @@ QuickLoadDialog::QuickLoadDialog( QWidget * _parent,
QuickLoadDialog::~QuickLoadDialog()
{
delete m_listModel;
}
void QuickLoadDialog::setTypeFilter( int _type )
{
m_listModel->setTypeFilter( static_cast<ResourceItem::Type>( _type ) );
}
#include "moc_QuickLoadDialog.cxx"

View File

@@ -43,30 +43,30 @@
struct ActionDesc
{
ResourceBrowser::Actions action;
ResourceAction::Action action;
const char * pixmap;
const char * text;
} ;
static ActionDesc resourceBrowserActions[] =
{
{ ResourceBrowser::EditProperties, "edit_draw",
{ ResourceAction::EditProperties, "edit_draw",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Show/edit properties" ) },
{ ResourceBrowser::LoadProject, "project_open",
{ ResourceAction::LoadProject, "project_open",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load project" ) },
{ ResourceBrowser::LoadInNewTrackSongEditor, "songeditor",
{ ResourceAction::LoadInNewTrackSongEditor, "songeditor",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load in new track in Song Editor" ) },
{ ResourceBrowser::LoadInNewTrackBBEditor, "bb_track",
{ ResourceAction::LoadInNewTrackBBEditor, "bb_track",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load in new track in B+B Editor" ) },
{ ResourceBrowser::LoadInActiveInstrumentTrack, "instrument_track",
{ ResourceAction::LoadInActiveInstrumentTrack, "instrument_track",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load into active instrument track" ) },
{ ResourceBrowser::DownloadIntoCollection, "mimetypes/folder-downloads",
{ ResourceAction::DownloadIntoCollection, "mimetypes/folder-downloads",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Download into collection" ) },
{ ResourceBrowser::UploadToWWW, "mimetypes/network-workgroup",
{ ResourceAction::UploadToWWW, "mimetypes/network-workgroup",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Upload to WWW" ) },
{ ResourceBrowser::DeleteLocalResource, "edit-delete",
{ ResourceAction::DeleteLocalResource, "edit-delete",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Delete resource" ) },
{ ResourceBrowser::ImportFile, "project_import",
{ ResourceAction::ImportFile, "project_import",
QT_TRANSLATE_NOOP( "ResourceBrowser", "Import file" ) }
} ;
@@ -74,7 +74,7 @@ static ActionDesc resourceBrowserActions[] =
ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
sideBarWidget( tr( "Resource Browser" ),
SideBarWidget( tr( "Resource Browser" ),
embed::getIconPixmap( "resource_browser" ),
_parent ),
m_previewer(),
@@ -98,7 +98,7 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
filterLayout->addWidget( m_filterStatusLabel );
// create an according tree-view for our tree-model
m_treeView = new ResourceTreeView( &m_treeModel, contentParent() );
m_treeView = new ResourceTreeView( contentParent(), &m_treeModel );
// set up context menu handling
m_treeView->setContextMenuPolicy( Qt::CustomContextMenu );
@@ -167,7 +167,7 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
for( int i = 0; i < (int) ( sizeof( resourceBrowserActions ) /
sizeof( ActionDesc ) ); ++i )
{
Actions a = resourceBrowserActions[i].action;
ResourceAction::Action a = resourceBrowserActions[i].action;
m_actions[a] = new QAction(
embed::getIconPixmap(
resourceBrowserActions[i].pixmap ),
@@ -211,16 +211,16 @@ void ResourceBrowser::showContextMenu( const QPoint & _pos )
case ResourceItem::TypePreset:
case ResourceItem::TypePluginSpecificResource:
case ResourceItem::TypePlugin:
m.addAction( m_actions[LoadInNewTrackSongEditor] );
m.addAction( m_actions[LoadInNewTrackBBEditor] );
m.addAction( m_actions[LoadInActiveInstrumentTrack] );
m.addAction( m_actions[ResourceAction::LoadInNewTrackSongEditor] );
m.addAction( m_actions[ResourceAction::LoadInNewTrackBBEditor] );
m.addAction( m_actions[ResourceAction::LoadInActiveInstrumentTrack] );
break;
case ResourceItem::TypeProject:
m.addAction( m_actions[LoadProject] );
m.addAction( m_actions[ResourceAction::LoadProject] );
break;
case ResourceItem::TypeForeignProject:
case ResourceItem::TypeMidiFile:
m.addAction( m_actions[ImportFile] );
m.addAction( m_actions[ResourceAction::ImportFile] );
break;
case ResourceItem::TypeImage:
case ResourceItem::TypeDirectory:
@@ -234,25 +234,25 @@ void ResourceBrowser::showContextMenu( const QPoint & _pos )
m.addSeparator();
if( item->isLocalResource() )
{
m.addAction( m_actions[DeleteLocalResource] );
m.addAction( m_actions[UploadToWWW] );
m.addAction( m_actions[ResourceAction::DeleteLocalResource] );
m.addAction( m_actions[ResourceAction::UploadToWWW] );
}
else
{
m.addAction( m_actions[DownloadIntoCollection] );
m.addAction( m_actions[ResourceAction::DownloadIntoCollection] );
}
}
m.addSeparator();
m.addAction( m_actions[EditProperties] );
m.addAction( m_actions[ResourceAction::EditProperties] );
// show and exec menu
QAction * a = m.exec( m_treeView->mapToGlobal( _pos ) );
if( a )
{
// trigger action if one has been selected
triggerAction( static_cast<Actions>( a->data().toInt() ),
item );
triggerAction( static_cast<ResourceAction::Action>( a->data().toInt() ),
item );
}
}
@@ -269,12 +269,14 @@ void ResourceBrowser::startItemPreview( const QModelIndex & _idx )
}
void ResourceBrowser::setFocusAndPreview( const QModelIndex & _idx )
{
// transfor focus to the treeview. for some reason you have to
// setFocus to the line edit above it first.
m_filterEdit->setFocus(Qt::MouseFocusReason);
m_treeView->setFocus(Qt::MouseFocusReason);
m_filterEdit->setFocus( Qt::MouseFocusReason );
m_treeView->setFocus( Qt::MouseFocusReason );
startItemPreview( _idx );
}
@@ -291,7 +293,7 @@ void ResourceBrowser::stopItemPreview( const QModelIndex & )
void ResourceBrowser::currentChanged( const QModelIndex & current,
const QModelIndex & previous )
const QModelIndex & previous )
{
// stop previous previews
@@ -299,12 +301,11 @@ void ResourceBrowser::currentChanged( const QModelIndex & current,
// start previewing the sound we just changed to
startItemPreview( current );
}
void ResourceBrowser::stopPreview()
{
m_previewer.stopPreview();
@@ -316,28 +317,28 @@ void ResourceBrowser::stopPreview()
void ResourceBrowser::triggerDefaultAction( const QModelIndex & _idx )
{
ResourceItem * item = m_treeModel.item( _idx );
Actions action = NumActions;
ResourceAction::Action action = ResourceAction::NumActions;
switch( item->type() )
{
case ResourceItem::TypeSample:
action = LoadInNewTrackBBEditor;
action = ResourceAction::LoadInNewTrackBBEditor;
break;
case ResourceItem::TypePreset:
case ResourceItem::TypePluginSpecificResource:
case ResourceItem::TypePlugin:
action = LoadInNewTrackSongEditor;
action = ResourceAction::LoadInNewTrackSongEditor;
break;
case ResourceItem::TypeProject:
action = LoadProject;
action = ResourceAction::LoadProject;
break;
case ResourceItem::TypeForeignProject:
case ResourceItem::TypeMidiFile:
action = ImportFile;
action = ResourceAction::ImportFile;
break;
default:
break;
}
if( action != NumActions )
if( action != ResourceAction::NumActions )
{
triggerAction( action, item );
}
@@ -363,26 +364,14 @@ void ResourceBrowser::manageDirectories()
void ResourceBrowser::triggerAction( Actions _action, ResourceItem * _item )
void ResourceBrowser::triggerAction( ResourceAction::Action _action,
ResourceItem * _item )
{
ResourceAction action( _item, _action );
switch( _action )
{
case LoadProject:
if( engine::mainWindow()->mayChangeProject() )
{
ResourceFileMapper mapper( _item );
if( _item->isLocalResource() )
{
engine::getSong()->loadProject(
mapper.fileName() );
}
else
{
engine::getSong()->
createNewProjectFromTemplate(
mapper.fileName() );
}
}
default:
action.defaultTrigger();
break;
}
}

View File

@@ -0,0 +1,128 @@
/*
* ResourceSelectDialog.cpp - implementation of ResourceSelectDialog
*
* Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <QtGui/QAbstractItemView>
#include <QtGui/QLineEdit>
#include "ResourceSelectDialog.h"
#include "ResourceListModel.h"
#include "ResourceTreeModel.h"
#include "engine.h"
ResourceSelectDialog::ResourceSelectDialog( QWidget * _parent,
ModelTypes _modelType,
DatabaseScope _databaseScope ) :
QDialog( _parent ),
m_model( NULL )
{
ResourceDB * db = NULL;
switch( _databaseScope )
{
case WorkingDirResources:
db = engine::workingDirResourceDB();
break;
case WebResources:
db = engine::webResourceDB();
break;
case AllResources:
default:
db = engine::mergedResourceDB();
break;
}
switch( _modelType )
{
case ListModel:
m_model = new ResourceListModel( db, this );
break;
case TreeModel:
m_model = new ResourceTreeModel( db, this );
break;
}
}
ResourceSelectDialog::~ResourceSelectDialog()
{
delete m_model;
}
ResourceItem * ResourceSelectDialog::selectedItem()
{
if( result() != QDialog::Accepted )
{
return NULL;
}
QAbstractItemView * resourceView = findChild<QAbstractItemView *>();
if( !resourceView )
{
return NULL;
}
return m_model->item( resourceView->currentIndex() );
}
void ResourceSelectDialog::setupUi( )
{
QAbstractItemView * resourceView = findChild<QAbstractItemView *>();
if( resourceView )
{
// setup view to display our model
resourceView->setModel( m_model );
resourceView->selectionModel()->select( m_model->index( 0, 0 ),
QItemSelectionModel::SelectCurrent );
}
QLineEdit * filterEdit = findChild<QLineEdit *>();
if( filterEdit )
{
// connect filter edit with model
connect( filterEdit, SIGNAL( textChanged( const QString & ) ),
m_model, SLOT( setKeywordFilter( const QString & ) ) );
}
}
void ResourceSelectDialog::setTypeFilter( int _type )
{
m_model->setTypeFilter( static_cast<ResourceItem::Type>( _type ) );
}
#include "moc_ResourceSelectDialog.cxx"

View File

@@ -26,17 +26,39 @@
#include "ResourceTreeModel.h"
ResourceTreeView::ResourceTreeView( ResourceTreeModel * _tm,
QWidget * _parent ) :
ResourceTreeView::ResourceTreeView( QWidget * _parent,
ResourceTreeModel * _tm ) :
QTreeView( _parent ),
m_tm( _tm )
m_treeModel( NULL )
{
setHeaderHidden( true );
setDragEnabled( true );
setModel( m_tm );
connect( m_tm, SIGNAL( itemsChanged() ),
this, SLOT( updateFilter() ) );
setModel( _tm );
}
ResourceTreeView::~ResourceTreeView()
{
}
void ResourceTreeView::setModel( QAbstractItemModel * _model )
{
if( _model )
{
m_treeModel = dynamic_cast<ResourceTreeModel *>( _model );
if( m_treeModel )
{
QTreeView::setModel( m_treeModel );
connect( m_treeModel, SIGNAL( itemsChanged() ),
this, SLOT( updateFilter() ) );
}
}
}
@@ -48,11 +70,11 @@ void ResourceTreeView::setFilter( const QString & _s )
if( _s.isEmpty() )
{
collapseAll();
m_tm->setKeywordFilter( _s );
m_treeModel->setKeywordFilter( _s );
}
else
{
m_tm->setKeywordFilter( _s );
m_treeModel->setKeywordFilter( _s );
expandToDepth( _s.size() );
}
setUpdatesEnabled( true );

View File

@@ -112,7 +112,7 @@ WelcomeScreen::~WelcomeScreen()
void WelcomeScreen::createNewProject()
{
switchView();
hideWelcomeScreen();
}
@@ -141,7 +141,7 @@ void WelcomeScreen::instantMidiAction()
void WelcomeScreen::openRecentProject( const QModelIndex & _idx )
{
switchView();
hideWelcomeScreen();
ResourceAction( m_recentProjectsModel->item( _idx ) ).loadProject();
}
@@ -156,7 +156,7 @@ void WelcomeScreen::openCommunityResource( const QModelIndex & _idx )
switch( item->type() )
{
case ResourceItem::TypeProject:
switchView();
hideWelcomeScreen();
action.loadProject();
break;
default:
@@ -177,9 +177,9 @@ void WelcomeScreen::openOnlineResource( QListWidgetItem * _item )
void WelcomeScreen::switchView()
void WelcomeScreen::hideWelcomeScreen()
{
engine::mainWindow()->setMainWidgetVisible( true );
engine::mainWindow()->showWelcomeScreen( false );
}

View File

@@ -93,18 +93,18 @@ QPixmap getIconPixmap( const char * _name, int _w, int _h )
// Save to cache and return
s_pixmapCache.insert( _name, p );
return( p );
return p;
}
return( getIconPixmap( _name ).scaled( _w, _h, Qt::IgnoreAspectRatio,
Qt::SmoothTransformation ) );
return getIconPixmap( _name ).
scaled( _w, _h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
}
QString getText( const char * _name )
{
const embed::descriptor & e = findEmbeddedData( _name );
return( QString::fromLatin1( (const char *) e.data, e.size ) );
return QString::fromUtf8( (const char *) e.data, e.size );
}

View File

@@ -37,7 +37,7 @@
pluginBrowser::pluginBrowser( QWidget * _parent ) :
sideBarWidget( tr( "Instrument plugins" ),
SideBarWidget( tr( "Instrument plugins" ),
embed::getIconPixmap( "plugins" ), _parent )
{
setWindowTitle( tr( "Instrument browser" ) );

160
src/gui/widgets/SideBar.cpp Normal file
View File

@@ -0,0 +1,160 @@
/*
* SideBar.cpp - side-bar in LMMS' MainWindow
*
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <QtGui/QStyleOptionToolButton>
#include <QtGui/QStylePainter>
#include <QtGui/QToolButton>
#include "SideBar.h"
#include "SideBarWidget.h"
// internal helper class allowing to create QToolButtons with
// vertical orientation
class SideBarButton : public QToolButton
{
public:
SideBarButton( Qt::Orientation _orientation, QWidget * _parent ) :
QToolButton( _parent ),
m_orientation( _orientation )
{
}
virtual ~SideBarButton()
{
}
Qt::Orientation orientation() const
{
return m_orientation;
}
virtual QSize sizeHint() const
{
QSize s = QToolButton::sizeHint();
s.setWidth( s.width() + 8 );
if( orientation() == Qt::Horizontal )
{
return s;
}
return QSize( s.height(), s.width() );
}
protected:
virtual void paintEvent( QPaintEvent * )
{
QStylePainter p( this );
QStyleOptionToolButton opt;
initStyleOption( &opt );
if( orientation() == Qt::Vertical )
{
const QSize s = sizeHint();
p.rotate( 270 );
p.translate( -s.height(), 0 );
opt.rect = QRect( 0, 0, s.height(), s.width() );
}
p.drawComplexControl( QStyle::CC_ToolButton, opt );
}
private:
Qt::Orientation m_orientation;
} ;
SideBar::SideBar( Qt::Orientation _orientation, QWidget * _parent ) :
QToolBar( _parent ),
m_btnGroup( this )
{
setOrientation( _orientation );
setIconSize( QSize( 16, 16 ) );
m_btnGroup.setExclusive( false );
connect( &m_btnGroup, SIGNAL( buttonClicked( QAbstractButton * ) ),
this, SLOT( toggleButton( QAbstractButton * ) ) );
}
SideBar::~SideBar()
{
}
void SideBar::appendTab( SideBarWidget * _sbw )
{
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 );
_sbw->hide();
_sbw->setMinimumWidth( 200 );
}
void SideBar::toggleButton( QAbstractButton * _btn )
{
QToolButton * toolButton = NULL;
QWidget * activeWidget = NULL;
for( ButtonMap::Iterator it = m_widgets.begin();
it != m_widgets.end(); ++it )
{
QToolButton * curBtn = it.key();
if( curBtn != _btn )
{
curBtn->setChecked( false );
curBtn->setToolButtonStyle( Qt::ToolButtonIconOnly );
}
else
{
toolButton = it.key();
activeWidget = it.value();
}
if( it.value() )
{
it.value()->hide();
}
}
if( toolButton && activeWidget )
{
activeWidget->setVisible( _btn->isChecked() );
toolButton->setToolButtonStyle( _btn->isChecked() ?
Qt::ToolButtonTextBesideIcon : Qt::ToolButtonIconOnly );
}
}
#include "moc_SideBar.cxx"

View File

@@ -1,8 +1,8 @@
/*
* side_bar_widget.cpp - implementation of base-widget for side-bar
* SideBarWidget.cpp - implementation of base-widget for side-bar
*
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
@@ -22,17 +22,16 @@
*
*/
#include <QtGui/QApplication>
#include <QtGui/QFontMetrics>
#include <QtGui/QPainter>
#include "side_bar_widget.h"
#include "SideBarWidget.h"
#include "gui_templates.h"
sideBarWidget::sideBarWidget( const QString & _title, const QPixmap & _icon,
SideBarWidget::SideBarWidget( const QString & _title, const QPixmap & _icon,
QWidget * _parent ) :
QWidget( _parent ),
m_title( _title ),
@@ -47,14 +46,14 @@ sideBarWidget::sideBarWidget( const QString & _title, const QPixmap & _icon,
sideBarWidget::~sideBarWidget()
SideBarWidget::~SideBarWidget()
{
}
void sideBarWidget::paintEvent( QPaintEvent * )
void SideBarWidget::paintEvent( QPaintEvent * )
{
const int TITLE_FONT_HEIGHT = 13;
@@ -77,7 +76,7 @@ void sideBarWidget::paintEvent( QPaintEvent * )
void sideBarWidget::resizeEvent( QResizeEvent * )
void SideBarWidget::resizeEvent( QResizeEvent * )
{
const int MARGIN = 6;
m_contents->setGeometry( MARGIN, 40 + MARGIN, width() - MARGIN * 2,
@@ -86,6 +85,5 @@ void sideBarWidget::resizeEvent( QResizeEvent * )
#include "moc_side_bar.cxx"
#include "moc_side_bar_widget.cxx"
#include "moc_SideBarWidget.cxx"

View File

@@ -1,917 +0,0 @@
/*
* kmultitabbar.cpp - widget for horizontal and vertical tabs
*
* Copyright (c) 2001-2003 Joseph Wenninger <jowenn@kde.org>
* Copyright (c) 2004-2007 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "kmultitabbar.h"
#include <QtCore/QEvent>
#include <QtGui/QApplication>
#include <QtGui/QFontMetrics>
#include <QtGui/QFrame>
#include <QtGui/QLayout>
#include <QtGui/QPainter>
#include <QtGui/QStyle>
#include <QtGui/QStyleOptionButton>
#include <math.h>
#include "templates.h"
#include "tooltip.h"
#define NEARBYINT(i) ((int(float(i) + 0.5)))
class KMultiTabBarTabPrivate {
public:
QPixmap pix;
};
KMultiTabBarInternal::KMultiTabBarInternal(QWidget *parent, KMultiTabBar::KMultiTabBarMode bm):QWidget(parent)
{
m_expandedTabSize=-1;
m_showActiveTabTexts=false;
m_barMode=bm;
if (bm==KMultiTabBar::Vertical)
{
box=new QWidget(this);
mainLayout=new QVBoxLayout(box);
box->setFixedWidth(24);
setFixedWidth(24);
}
else
{
box=new QWidget(this);
mainLayout=new QHBoxLayout(box);
box->setFixedHeight(24);
setFixedHeight(24);
}
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
}
void KMultiTabBarInternal::setStyle(enum KMultiTabBar::KMultiTabBarStyle style)
{
m_style=style;
for (int i=0;i<m_tabs.count();i++)
m_tabs.at(i)->setStyle(m_style);
if ( (m_style==KMultiTabBar::KDEV3) ||
(m_style==KMultiTabBar::KDEV3ICON ) ) {
delete mainLayout;
mainLayout=0;
resizeEvent(0);
} else if (mainLayout==0) {
if (m_barMode==KMultiTabBar::Vertical)
{
box=new QWidget(this);
mainLayout=new QVBoxLayout(box);
box->setFixedWidth(24);
setFixedWidth(24);
}
else
{
box=new QWidget(this);
mainLayout=new QHBoxLayout(box);
box->setFixedHeight(24);
setFixedHeight(24);
}
for (int i=0;i<m_tabs.count();i++)
mainLayout->addWidget(m_tabs.at(i));
}
update();
}
#define CALCDIFF(m_tabs,diff,i) if (m_lines>(int)lines) {\
int ulen=0;\
diff=0; \
for (int i2=i;i2<tabCount;i2++) {\
int l1=m_tabs.at(i2)->neededSize();\
if ((ulen+l1)>(int)space){\
if (ulen==0) diff=0;\
else diff=((float)(space-ulen))/(i2-i);\
break;\
}\
ulen+=l1;\
}\
} else {diff=0; }
void KMultiTabBarInternal::resizeEvent(QResizeEvent *ev) {
if (ev) QWidget::resizeEvent(ev);
if ( (m_style==KMultiTabBar::KDEV3) ||
(m_style==KMultiTabBar::KDEV3ICON) ){
box->setGeometry(0,0,width(),height());
int lines=1;
uint space;
float tmp=0;
if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
space=width();
else
space=height();
int cnt=0;
//CALCULATE LINES
const int tabCount=m_tabs.count();
for (int i=0;i<tabCount;i++) {
cnt++;
tmp+=m_tabs.at(i)->neededSize();
if (tmp>space) {
if (cnt>1)i--;
else if (i==(tabCount-1)) break;
cnt=0;
tmp=0;
lines++;
}
}
//SET SIZE & PLACE
float diff=0;
cnt=0;
if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top)) {
setFixedHeight(lines*24);
box->setFixedHeight(lines*24);
m_lines=height()/24-1;
lines=0;
CALCDIFF(m_tabs,diff,0)
tmp=-diff;
for (int i=0;i<tabCount;i++) {
KMultiTabBarTab *tab=m_tabs.at(i);
cnt++;
tmp+=tab->neededSize()+diff;
if (tmp>space) {
if (cnt>1) {
CALCDIFF(m_tabs,diff,i)
i--;
}
else {
tab->removeEventFilter(this);
tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
tab->installEventFilter(this);
CALCDIFF(m_tabs,diff,(i+1))
}
tmp=-diff;
cnt=0;
lines++;
} else {
tab->removeEventFilter(this);
tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
tab->installEventFilter(this);
}
}
}
else {
setFixedWidth(lines*24);
box->setFixedWidth(lines*24);
m_lines=lines=width()/24;
lines=0;
CALCDIFF(m_tabs,diff,0)
tmp=-diff;
for (int i=0;i<tabCount;i++) {
KMultiTabBarTab *tab=m_tabs.at(i);
cnt++;
tmp+=tab->neededSize()+diff;
if (tmp>space) {
if (cnt>1) {
CALCDIFF(m_tabs,diff,i);
tmp=-diff;
i--;
}
else {
tab->removeEventFilter(this);
tab->move(lines*24,NEARBYINT(tmp-tab->neededSize()));
tab->setFixedHeight(NEARBYINT(tmp+diff)-tab->y());;
tab->installEventFilter(this);
}
cnt=0;
tmp=-diff;
lines++;
} else {
tab->removeEventFilter(this);
tab->move(lines*24,NEARBYINT(tmp-tab->neededSize()));
tab->setFixedHeight(NEARBYINT(tmp+diff)-tab->y());;
tab->installEventFilter(this);
}
}
}
} else {
int size=0; /*move the calculation into another function and call it only on add tab and tab click events*/
for (int i=0;i<(int)m_tabs.count();i++)
size+=(m_barMode==KMultiTabBar::Vertical?m_tabs.at(i)->height():m_tabs.at(i)->width());
if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
box->setGeometry(0,0,size,height());
else box->setGeometry(0,0,width(),size);
}
}
void KMultiTabBarInternal::showActiveTabTexts(bool show)
{
m_showActiveTabTexts=show;
}
KMultiTabBarTab* KMultiTabBarInternal::tab(int id) const
{
for (QListIterator<KMultiTabBarTab *> it(m_tabs);it.hasNext();it.next()){
if (it.peekNext()->id()==id) return it.peekNext();
}
return 0;
}
bool KMultiTabBarInternal::eventFilter(QObject *, QEvent *e) {
if (e->type()==QEvent::Resize) resizeEvent(0);
return false;
}
int KMultiTabBarInternal::appendTab(const QPixmap &pic ,int id,const QString& text)
{
KMultiTabBarTab *tab;
m_tabs.append(tab= new KMultiTabBarTab(pic,text,id,box,m_position,m_style));
mainLayout->addWidget( tab );
tab->installEventFilter(this);
tab->showActiveTabText(m_showActiveTabTexts);
if (m_style==KMultiTabBar::KONQSBC)
{
if (m_expandedTabSize<tab->neededSize()) {
m_expandedTabSize=tab->neededSize();
for (int i=0;i<m_tabs.count();i++)
m_tabs.at(i)->setSize(m_expandedTabSize);
} else tab->setSize(m_expandedTabSize);
} else tab->updateState();
tab->show();
resizeEvent(0);
return 0;
}
void KMultiTabBarInternal::removeTab(int id)
{
for (int pos=0;pos<m_tabs.count();pos++)
{
if (m_tabs.at(pos)->id()==id)
{
delete m_tabs.at(pos);
m_tabs.removeAt(pos);
resizeEvent(0);
break;
}
}
}
void KMultiTabBarInternal::setPosition(enum KMultiTabBar::KMultiTabBarPosition pos)
{
m_position=pos;
for (int i=0;i<m_tabs.count();i++)
m_tabs.at(i)->setTabsPosition(m_position);
update();
}
KMultiTabBarButton::KMultiTabBarButton(const QPixmap& pic,const QString& text, QMenu *popup,
int id,QWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,KMultiTabBar::KMultiTabBarStyle style)
:QPushButton(QIcon(),text,parent),m_style(style)
{
setIcon(pic);
setText(text);
m_position=pos;
if (popup) setMenu(popup);
setFlat(true);
setFixedHeight(24);
setFixedWidth(24);
m_id=id;
setToolTip(text);
connect(this,SIGNAL(clicked()),this,SLOT(slotClicked()));
}
KMultiTabBarButton::KMultiTabBarButton(const QString& text, QMenu *popup,
int id,QWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,KMultiTabBar::KMultiTabBarStyle style)
:QPushButton(QIcon(),text,parent),m_style(style)
{
setText(text);
m_position=pos;
if (popup) setMenu(popup);
setFlat(true);
setFixedHeight(24);
setFixedWidth(24);
m_id=id;
setToolTip(text);
connect(this,SIGNAL(clicked()),this,SLOT(slotClicked()));
}
KMultiTabBarButton::~KMultiTabBarButton() {
}
int KMultiTabBarButton::id() const{
return m_id;
}
void KMultiTabBarButton::setText(const QString& text)
{
QPushButton::setText(text);
m_text=text;
setToolTip(text);
}
void KMultiTabBarButton::slotClicked()
{
emit clicked(m_id);
}
void KMultiTabBarButton::setPosition(KMultiTabBar::KMultiTabBarPosition pos)
{
m_position=pos;
update();
}
void KMultiTabBarButton::setStyle(KMultiTabBar::KMultiTabBarStyle style)
{
m_style=style;
update();
}
void KMultiTabBarButton::hideEvent( QHideEvent* he) {
QPushButton::hideEvent(he);
KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
if (tb) tb->updateSeparator();
}
void KMultiTabBarButton::showEvent( QShowEvent* he) {
QPushButton::showEvent(he);
KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
if (tb) tb->updateSeparator();
}
QSize KMultiTabBarButton::sizeHint() const
{
//constPolish();
int w = 0, h = 0;
// calculate contents size...
int iw = 0, ih = 0;
if ( !icon().isNull() ) {
iw = 20;
ih = 16;
w += iw;
h = qMax( h, ih );
}
QStyleOptionButton sob;
if ( menu() != 0 )
w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &sob, this);
QString s( text() );
bool empty = s.isEmpty();
if ( empty )
s = QLatin1String("XXXX");
QFontMetrics fm = fontMetrics();
QSize sz = fm.size( Qt::TextShowMnemonic, s );
if(!empty || !w)
w += sz.width();
if(!empty || !h)
h = qMax(h, sz.height());
QStyleOptionToolButton opt;
opt.init(this);
opt.rect = QRect(0, 0, w, h);
opt.subControls = QStyle::SC_All;
opt.activeSubControls = 0;
opt.text = text();
opt.font = font();
opt.icon = icon();
opt.iconSize = QSize(iw, ih);
return (style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this).
expandedTo(QApplication::globalStrut()));
}
KMultiTabBarTab::KMultiTabBarTab(const QPixmap& pic, const QString& text,
int id,QWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,
KMultiTabBar::KMultiTabBarStyle style)
:KMultiTabBarButton(text,0,id,parent,pos,style),
m_showActiveTabText(false)
{
d=new KMultiTabBarTabPrivate();
setIcon(pic);
m_expandedSize=24;
setCheckable(true);
setAttribute( Qt::WA_OpaquePaintEvent, true );
}
KMultiTabBarTab::~KMultiTabBarTab() {
delete d;
}
void KMultiTabBarTab::setTabsPosition(KMultiTabBar::KMultiTabBarPosition pos)
{
if ((pos!=m_position) && ((pos==KMultiTabBar::Left) || (pos==KMultiTabBar::Right))) {
if (!d->pix.isNull()) {
QMatrix temp;// (1.0F, 0.0F, 0.0F, -1.0F, 0.0F, 0.0F);
temp.rotate(180);
d->pix=d->pix.transformed(temp);
setIcon(d->pix);
}
}
setPosition(pos);
}
void KMultiTabBarTab::setIcon(const QString& icon)
{
QPixmap pic(icon);
setIcon(pic);
}
void KMultiTabBarTab::setIcon(const QPixmap& icon)
{
if (m_style!=KMultiTabBar::KDEV3) {
if ((m_position==KMultiTabBar::Left) || (m_position==KMultiTabBar::Right)) {
QMatrix rotateMatrix;
/* if (m_position==KMultiTabBar::Left)
rotateMatrix.rotate(-270);
else*/
rotateMatrix.rotate(90);
d->pix=icon.transformed(rotateMatrix); //TODO FIX THIS, THIS SHOWS WINDOW
KMultiTabBarButton::setIcon(d->pix);
} else KMultiTabBarButton::setIcon(icon);
}
}
void KMultiTabBarTab::slotClicked()
{
updateState();
KMultiTabBarButton::slotClicked();
}
void KMultiTabBarTab::setState(bool b)
{
setChecked(b);
updateState();
}
void KMultiTabBarTab::updateState()
{
if (m_style!=KMultiTabBar::KONQSBC) {
if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isChecked())) {
QPushButton::setText(m_text);
} else {
QPushButton::setText(QString());
}
if ((m_position==KMultiTabBar::Right || m_position==KMultiTabBar::Left)) {
setFixedWidth(24);
if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isChecked())) {
setFixedHeight(KMultiTabBarButton::sizeHint().width());
} else setFixedHeight(36);
} else {
setFixedHeight(24);
if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isChecked())) {
setFixedWidth(KMultiTabBarButton::sizeHint().width());
} else setFixedWidth(36);
}
} else {
if ((!isChecked()) || (!m_showActiveTabText))
{
setFixedWidth(24);
setFixedHeight(24);
return;
}
if ((m_position==KMultiTabBar::Right || m_position==KMultiTabBar::Left))
setFixedHeight(m_expandedSize);
else
setFixedWidth(m_expandedSize);
}
}
int KMultiTabBarTab::neededSize()
{
return (((m_style!=KMultiTabBar::KDEV3)?24:0)+QFontMetrics(QFont()).width(m_text)+6);
}
void KMultiTabBarTab::setSize(int size)
{
m_expandedSize=size;
updateState();
}
void KMultiTabBarTab::showActiveTabText(bool show)
{
m_showActiveTabText=show;
}
void KMultiTabBarTab::paintEvent(QPaintEvent *) {
QPainter painter(this);
drawButton(&painter);
}
void KMultiTabBarTab::drawButtonLabel(QPainter *p) {
drawButton(p);
}
void KMultiTabBarTab::drawButton(QPainter *paint)
{
if (m_style!=KMultiTabBar::KONQSBC) drawButtonStyled(paint);
else drawButtonClassic(paint);
}
void KMultiTabBarTab::drawButtonStyled(QPainter *paint) {
QSize sh;
const int width = 36; // rotated
const int height = 24;
if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isChecked())) {
if ((m_position==KMultiTabBar::Left) || (m_position==KMultiTabBar::Right))
sh=QSize(this->height(),this->width());//KMultiTabBarButton::sizeHint();
else sh=QSize(this->width(),this->height());
}
else
sh=QSize(width,height);
QPixmap pixmap( sh.width(),height); ///,sh.height());
pixmap.fill(backgroundRole());
QPainter painter(&pixmap);
QStyle::State st=QStyle::State_None;
st|=QStyle::State_Enabled;
if (isChecked()) st|=QStyle::State_On;
QStyleOptionButton options;
options.init(this);
options.state = st;
options.rect = QRect(0,0,pixmap.width(),pixmap.height());
options.palette = palette();
options.text = text();
options.icon = icon();
options.iconSize = iconSize();
style()->drawControl(QStyle::CE_PushButton, &options, &painter, this);
switch (m_position) {
case KMultiTabBar::Left:
paint->rotate(-90);
paint->drawPixmap(1-pixmap.width(),0,pixmap);
break;
case KMultiTabBar::Right:
paint->rotate(90);
paint->drawPixmap(0,1-pixmap.height(),pixmap);
break;
default:
paint->drawPixmap(0,0,pixmap);
break;
}
}
void KMultiTabBarTab::drawButtonClassic(QPainter *paint)
{
QPixmap pixmap;
if( !icon().isNull() )
pixmap = icon().pixmap( 16, 16 );
paint->fillRect(0, 0, 24, 24, palette().background().color());
if (!isChecked())
{
if (m_position==KMultiTabBar::Right)
{
paint->fillRect(0,0,21,21,QBrush(palette().background().color()));
paint->setPen(palette().background().color().dark(150));
paint->drawLine(0,22,23,22);
paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
paint->setPen(palette().shadow().color());
paint->drawLine(0,0,0,23);
paint->setPen(palette().background().color().dark(120));
paint->drawLine(1,0,1,23);
}
else
if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
{
paint->fillRect(0,1,23,22,QBrush(palette().background().color()));
paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
paint->setPen(palette().background().color().dark(120));
paint->drawLine(23,0,23,23);
paint->setPen(palette().light().color());
paint->drawLine(0,22,23,22);
paint->drawLine(0,23,23,23);
paint->setPen(palette().shadow().color());
paint->drawLine(0,0,23,0);
paint->setPen(palette().background().color().dark(120));
paint->drawLine(0,1,23,1);
}
else
{
paint->setPen(palette().background().color().dark(120));
paint->drawLine(0,23,23,23);
paint->fillRect(0,0,23,21,QBrush(palette().background()));
paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
paint->setPen(palette().light().color());
paint->drawLine(23,0,23,23);
paint->drawLine(22,0,22,23);
paint->setPen(palette().shadow().color());
paint->drawLine(0,0,0,23);
}
}
else
{
if (m_position==KMultiTabBar::Right)
{
paint->setPen(palette().shadow().color());
paint->drawLine(0,height()-1,23,height()-1);
paint->drawLine(0,height()-2,23,height()-2);
paint->drawLine(23,0,23,height()-1);
paint->drawLine(22,0,22,height()-1);
paint->fillRect(0,0,21,height()-3,QBrush(palette().light().color()));
paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
if (m_showActiveTabText)
{
if (height()<25+4) return;
QPixmap tpixmap(height()-25-3, width()-2);
QPainter painter(&tpixmap);
painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),QBrush(palette().light().color()));
painter.setPen(palette().text().color());
painter.drawText(0,+width()/2+QFontMetrics(QFont()).height()/2,m_text);
paint->rotate(90);
paint->drawPixmap(25,-tpixmap.height()+1,tpixmap);
}
}
else
if (m_position==KMultiTabBar::Top)
{
paint->fillRect(0,0,width()-1,23,QBrush(palette().light().color()));
paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
if (m_showActiveTabText)
{
paint->setPen(palette().text().color());
paint->drawText(25,height()/2+QFontMetrics(QFont()).height()/2,m_text);
}
}
else
if (m_position==KMultiTabBar::Bottom)
{
paint->setPen(palette().shadow().color());
paint->drawLine(0,23,width()-1,23);
paint->drawLine(0,22,width()-1,22);
paint->fillRect(0,0,width()-1,21,QBrush(palette().light().color()));
paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
if (m_showActiveTabText)
{
paint->setPen(palette().text().color());
paint->drawText(25,height()/2+QFontMetrics(QFont()).height()/2,m_text);
}
}
else
{
paint->setPen(palette().shadow().color());
paint->drawLine(0,height()-1,23,height()-1);
paint->drawLine(0,height()-2,23,height()-2);
paint->fillRect(0,0,23,height()-3,QBrush(palette().light().color()));
paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
if (m_showActiveTabText)
{
if (height()<25+4) return;
QPixmap tpixmap(height()-25-3, width()-2);
QPainter painter(&tpixmap);
painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),QBrush(palette().light().color()));
painter.setPen(palette().text().color());
painter.drawText(tpixmap.width()-QFontMetrics(QFont()).width(m_text),+width()/2+QFontMetrics(QFont()).height()/2,m_text);
paint->rotate(-90);
paint->drawPixmap(-24-tpixmap.width(),2,tpixmap);
}
}
}
}
KMultiTabBar::KMultiTabBar(KMultiTabBarMode bm, QWidget *parent)
: QWidget(parent)
{
if (bm==Vertical)
{
m_l=new QVBoxLayout(this);
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
}
else
{
m_l=new QHBoxLayout(this);
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
}
m_l->setMargin(0);
m_internal=new KMultiTabBarInternal(this,bm);
setPosition((bm==KMultiTabBar::Vertical)?KMultiTabBar::Right:KMultiTabBar::Bottom);
setStyle(VSNET);
m_l->insertWidget(0,m_internal);
m_l->insertWidget(0,m_btnTabSep=new QFrame(this));
m_btnTabSep->setFixedHeight(4);
m_btnTabSep->setFrameStyle(QFrame::Panel | QFrame::Sunken);
m_btnTabSep->setLineWidth(2);
m_btnTabSep->hide();
updateGeometry();
}
KMultiTabBar::~KMultiTabBar() {
}
int KMultiTabBar::appendButton(const QPixmap &pic ,int id,QMenu *popup,const QString&)
{
KMultiTabBarButton *btn;
m_buttons.append(btn= new KMultiTabBarButton(pic,QString(),
popup,id,this,m_position,m_internal->m_style));
m_l->insertWidget(0,btn);
btn->show();
m_btnTabSep->show();
return 0;
}
void KMultiTabBar::updateSeparator() {
bool hideSep=true;
for (QListIterator<KMultiTabBarButton *> it(m_buttons);it.hasNext();){
if (it.next()->isVisibleTo(this)) {
hideSep=false;
break;
}
}
if (hideSep) m_btnTabSep->hide();
else m_btnTabSep->show();
}
int KMultiTabBar::appendTab(const QPixmap &pic ,int id ,const QString& text)
{
m_internal->appendTab(pic,id,text);
return 0;
}
KMultiTabBarButton* KMultiTabBar::button(int id) const
{
for (QListIterator<KMultiTabBarButton *> it(m_buttons);it.hasNext();it.next()){
if (it.peekNext()->id()==id) return it.peekNext();
}
return 0;
}
KMultiTabBarTab* KMultiTabBar::tab(int id) const
{
return m_internal->tab(id);
}
void KMultiTabBar::removeButton(int id)
{
for (int pos=0;pos<m_buttons.count();pos++)
{
if (m_buttons.at(pos)->id()==id)
{
m_buttons.at(pos)->deleteLater();
m_buttons.removeAt(pos);
break;
}
}
if (m_buttons.count()==0) m_btnTabSep->hide();
}
void KMultiTabBar::removeTab(int id)
{
m_internal->removeTab(id);
}
void KMultiTabBar::setTab(int id,bool state)
{
KMultiTabBarTab *ttab=tab(id);
if (ttab)
{
ttab->setState(state);
}
}
bool KMultiTabBar::isTabRaised(int id) const
{
KMultiTabBarTab *ttab=tab(id);
if (ttab)
{
return ttab->isChecked();
}
return false;
}
void KMultiTabBar::showActiveTabTexts(bool show)
{
m_internal->showActiveTabTexts(show);
}
void KMultiTabBar::setStyle(KMultiTabBarStyle style)
{
m_internal->setStyle(style);
}
KMultiTabBar::KMultiTabBarStyle KMultiTabBar::tabStyle() const
{
return m_internal->m_style;
}
void KMultiTabBar::setPosition(KMultiTabBarPosition pos)
{
m_position=pos;
m_internal->setPosition(pos);
for (int i=0;i<m_buttons.count();i++)
m_buttons.at(i)->setPosition(pos);
}
KMultiTabBar::KMultiTabBarPosition KMultiTabBar::position() const
{
return m_position;
}
void KMultiTabBar::fontChange(const QFont& /* oldFont */)
{
for (int i=0;i<tabs()->count();i++)
tabs()->at(i)->resize();
update();
}
QList<KMultiTabBarTab *>* KMultiTabBar::tabs() {return m_internal->tabs();}
QList<KMultiTabBarButton *>* KMultiTabBar::buttons() {return &m_buttons;}
#include "moc_kmultitabbar.cxx"