2 Copyright (c) 2006 Gábor Lehel <illissius@gmail.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "columnlist.h"
22 #include "config-amarok.h"
23 #include "amarokconfig.h"
25 #include "metabundle.h"
29 #include <k3listview.h>
30 #include <kpushbutton.h>
36 #include <Q3ValueList>
39 class MyCheckListItem
: public Q3CheckListItem
41 typedef Q3CheckListItem super
;
45 MyCheckListItem( int c
, Q3ListView
*v
, const QString
&s
, Type t
, ColumnList
*list
):
46 super( v
, s
, t
), m_list( list
), column( c
) { }
47 virtual void paintCell( QPainter
* p
, const QColorGroup
&cg
, int c
, int w
, int a
)
51 f
.setBold( !f
.bold() );
53 super::paintCell( p
, cg
, c
, w
, a
);
55 virtual void stateChange( bool b
)
57 super::stateChange( b
);
60 MyCheckListItem
*itemAbove() { return static_cast<MyCheckListItem
*>( Q3CheckListItem::itemAbove() ); }
61 MyCheckListItem
*itemBelow() { return static_cast<MyCheckListItem
*>( Q3CheckListItem::itemBelow() ); }
64 ColumnList::ColumnList( QWidget
*parent
, const char *name
)
65 : KHBox( parent
), m_changed( true )
67 setObjectName( name
);
70 KVBox
*buttonbox
= new KVBox( this );
72 m_up
= new KPushButton( KGuiItem( QString(), "up" ), buttonbox
);
73 m_up
->setToolTip( i18n( "Move column up" ) );
74 connect( m_up
, SIGNAL( clicked() ), this, SLOT( moveUp() ) );
76 m_down
= new KPushButton( KGuiItem( QString(), "down" ), buttonbox
);
77 m_down
->setToolTip( i18n( "Move column down" ) );
78 connect( m_down
, SIGNAL( clicked() ), this, SLOT( moveDown() ) );
80 m_list
= new K3ListView( this );
81 m_list
->addColumn("");
82 m_list
->header()->hide();
83 m_list
->setSelectionMode( Q3ListView::Single
);
84 m_list
->setResizeMode( Q3ListView::LastColumn
);
85 m_list
->setSorting( -1 );
86 m_list
->setAcceptDrops( true );
87 m_list
->setDragEnabled( true );
88 m_list
->setDropVisualizer( true );
89 m_list
->setDropVisualizerWidth( 3 );
90 connect( m_list
, SIGNAL( moved() ), this, SLOT( updateUI() ) );
91 connect( m_list
, SIGNAL( moved() ), this, SLOT( setChanged() ) );
92 connect( m_list
, SIGNAL( currentChanged( Q3ListViewItem
* ) ), this, SLOT( updateUI() ) );
94 Q3Header
* const h
= Playlist::instance()->header();
95 for( int i
= h
->count() - 1; i
>= 0; --i
)
97 const int s
= h
->mapToSection( i
);
98 if( ( s
!= MetaBundle::Rating
|| AmarokConfig::useRatings() ) &&
99 ( s
!= MetaBundle::Mood
|| AmarokConfig::showMoodbar() ) &&
100 ( s
!= MetaBundle::Score
|| AmarokConfig::useScores() ) )
102 ( new MyCheckListItem( s
, m_list
, MetaBundle::prettyColumnName( s
), Q3CheckListItem::CheckBox
, this ) )
103 ->setOn( h
->sectionSize( s
) );
107 m_list
->setCurrentItem( m_list
->firstChild() );
112 Q3ValueList
<int> ColumnList::visibleColumns() const
115 for( MyCheckListItem
*item
= static_cast<MyCheckListItem
*>( m_list
->firstChild() ); item
; item
= item
->itemBelow() )
117 v
.append( item
->column
);
121 Q3ValueList
<int> ColumnList::columnOrder() const
124 for( MyCheckListItem
*item
= static_cast<MyCheckListItem
*>( m_list
->firstChild() ); item
; item
= item
->itemBelow() )
125 v
.append( item
->column
);
129 bool ColumnList::isChanged() const
134 void ColumnList::resetChanged()
139 void ColumnList::moveUp()
141 if( Q3ListViewItem
*item
= m_list
->currentItem() )
142 if( item
->itemAbove() )
144 m_list
->moveItem( item
, 0, item
->itemAbove()->itemAbove() );
145 m_list
->setCurrentItem( item
);
146 m_list
->ensureItemVisible( item
);
152 void ColumnList::moveDown()
154 if( Q3ListViewItem
*item
= m_list
->currentItem() )
156 m_list
->moveItem( item
, 0, item
->itemBelow() );
157 m_list
->setCurrentItem( item
);
158 m_list
->ensureItemVisible( item
);
164 void ColumnList::updateUI()
166 m_up
->setEnabled( m_list
->currentItem() && m_list
->currentItem()->itemAbove() );
167 m_down
->setEnabled( m_list
->currentItem() && m_list
->currentItem()->itemBelow() );
170 void ColumnList::setChanged() //slot
179 ColumnsDialog::ColumnsDialog()
180 : KDialog( MainWindow::self() ),
181 m_list( new ColumnList( this ) )
183 setCaption( i18n( "Playlist Columns" ) );
186 setMainWidget( m_list
);
187 enableButtonApply( false );
188 connect( m_list
, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
191 ColumnsDialog::~ColumnsDialog()
196 void ColumnsDialog::slotApply()
199 KDialog::slotButtonClicked( KDialog::Apply
);
202 void ColumnsDialog::slotOk()
205 KDialog::slotButtonClicked( KDialog::Ok
);
208 void ColumnsDialog::hide()
214 void ColumnsDialog::apply()
216 Playlist::instance()->setColumns( m_list
->columnOrder(), m_list
->visibleColumns() );
217 m_list
->resetChanged();
218 enableButtonApply( false );
221 void ColumnsDialog::display() //static
224 s_instance
= new ColumnsDialog
;
228 void ColumnsDialog::slotChanged() //slot
230 enableButtonApply( true );
233 ColumnsDialog
*ColumnsDialog::s_instance
= 0;
235 #include "columnlist.moc"