Merging from old trunk:

r632958 | knight | 2007-02-12 20:39:15 +0100 (Mon, 12 Feb 2007) | 4 lines

* Port KListBox to KListWidget
* Port all usage of Q3ListBox / Q3ListBoxItem to QListWidget / QListWidgetItem


svn path=/trunk/KDE/kdebase/workspace/; revision=659542
This commit is contained in:
Luboš Luňák 2007-04-30 11:55:02 +00:00
parent 3d50459834
commit 8f6f8bf076
5 changed files with 67 additions and 64 deletions

View file

@ -18,6 +18,7 @@
#include "ruleslist.h"
#include <klistwidget.h>
#include <kpushbutton.h>
#include <assert.h>
#include <kdebug.h>
@ -32,10 +33,10 @@ KCMRulesList::KCMRulesList( QWidget* parent)
: KCMRulesListBase( parent)
{
// connect both current/selected, so that current==selected (stupid QListBox :( )
connect( rules_listbox, SIGNAL( currentChanged( Q3ListBoxItem* )),
SLOT( activeChanged( Q3ListBoxItem*)));
connect( rules_listbox, SIGNAL( selectionChanged( Q3ListBoxItem* )),
SLOT( activeChanged( Q3ListBoxItem*)));
connect( rules_listbox, SIGNAL( currentChanged( QListWidgetItem* )),
SLOT( activeChanged( QListWidgetItem*)));
connect( rules_listbox, SIGNAL( selectionChanged( QListWidgetItem* )),
SLOT( activeChanged( QListWidgetItem*)));
connect( new_button, SIGNAL( clicked()),
SLOT( newClicked()));
connect( modify_button, SIGNAL( clicked()),
@ -46,7 +47,7 @@ KCMRulesList::KCMRulesList( QWidget* parent)
SLOT( moveupClicked()));
connect( movedown_button, SIGNAL( clicked()),
SLOT( movedownClicked()));
connect( rules_listbox, SIGNAL( doubleClicked ( Q3ListBoxItem * ) ),
connect( rules_listbox, SIGNAL( doubleClicked ( QListWidgetItem * ) ),
SLOT( modifyClicked()));
load();
}
@ -60,14 +61,16 @@ KCMRulesList::~KCMRulesList()
rules.clear();
}
void KCMRulesList::activeChanged( Q3ListBoxItem* item )
void KCMRulesList::activeChanged( QListWidgetItem* item )
{
int itemRow = rules_listbox->row(item);
if( item != NULL )
rules_listbox->setSelected( item, true ); // make current==selected
item->setSelected( true ); // make current==selected
modify_button->setEnabled( item != NULL );
delete_button->setEnabled( item != NULL );
moveup_button->setEnabled( item != NULL && item->prev() != NULL );
movedown_button->setEnabled( item != NULL && item->next() != NULL );
moveup_button->setEnabled( item != NULL && itemRow > 0 );
movedown_button->setEnabled( item != NULL && itemRow < (rules_listbox->count()-1) );
}
void KCMRulesList::newClicked()
@ -76,16 +79,16 @@ void KCMRulesList::newClicked()
Rules* rule = dlg.edit( NULL, 0, false );
if( rule == NULL )
return;
int pos = rules_listbox->currentItem() + 1;
rules_listbox->insertItem( rule->description, pos );
rules_listbox->setSelected( pos, true );
int pos = rules_listbox->currentRow() + 1;
rules_listbox->insertItem( pos , rule->description );
rules_listbox->item(pos)->setSelected( true );
rules.insert( rules.begin() + pos, rule );
emit changed( true );
}
void KCMRulesList::modifyClicked()
{
int pos = rules_listbox->currentItem();
int pos = rules_listbox->currentRow();
if ( pos == -1 )
return;
RulesDialog dlg;
@ -94,29 +97,29 @@ void KCMRulesList::modifyClicked()
return;
delete rules[ pos ];
rules[ pos ] = rule;
rules_listbox->changeItem( rule->description, pos );
rules_listbox->item(pos)->setText( rule->description );
emit changed( true );
}
void KCMRulesList::deleteClicked()
{
int pos = rules_listbox->currentItem();
int pos = rules_listbox->currentRow();
assert( pos != -1 );
rules_listbox->removeItem( pos );
delete rules_listbox->takeItem( pos );
rules.erase( rules.begin() + pos );
emit changed( true );
}
void KCMRulesList::moveupClicked()
{
int pos = rules_listbox->currentItem();
int pos = rules_listbox->currentRow();
assert( pos != -1 );
if( pos > 0 )
{
QString txt = rules_listbox->text( pos );
rules_listbox->removeItem( pos );
rules_listbox->insertItem( txt, pos - 1 );
rules_listbox->setSelected( pos - 1, true );
QString txt = rules_listbox->item(pos)->text();
delete rules_listbox->takeItem( pos );
rules_listbox->insertItem( pos - 1 , txt );
rules_listbox->item(pos-1)->setSelected( true );
Rules* rule = rules[ pos ];
rules[ pos ] = rules[ pos - 1 ];
rules[ pos - 1 ] = rule;
@ -126,14 +129,14 @@ void KCMRulesList::moveupClicked()
void KCMRulesList::movedownClicked()
{
int pos = rules_listbox->currentItem();
int pos = rules_listbox->currentRow();
assert( pos != -1 );
if( pos < int( rules_listbox->count()) - 1 )
{
QString txt = rules_listbox->text( pos );
rules_listbox->removeItem( pos );
rules_listbox->insertItem( txt, pos + 1 );
rules_listbox->setSelected( pos + 1, true );
QString txt = rules_listbox->item(pos)->text();
delete rules_listbox->takeItem( pos );
rules_listbox->insertItem( pos + 1 , txt);
rules_listbox->item(pos+1)->setSelected( true );
Rules* rule = rules[ pos ];
rules[ pos ] = rules[ pos + 1 ];
rules[ pos + 1 ] = rule;
@ -160,10 +163,10 @@ void KCMRulesList::load()
cfg.changeGroup( QString::number( i ));
Rules* rule = new Rules( cfg );
rules.append( rule );
rules_listbox->insertItem( rule->description );
rules_listbox->addItem( rule->description );
}
if( rules.count() > 0 )
rules_listbox->setSelected( 0, true );
rules_listbox->item(0)->setSelected( true );
else
activeChanged( NULL );
}

View file

@ -26,7 +26,7 @@
#include "../../rules.h"
class Q3ListBoxItem;
class QListWidgetItem;
namespace KWin
{
@ -58,7 +58,7 @@ class KCMRulesList
void deleteClicked();
void moveupClicked();
void movedownClicked();
void activeChanged( Q3ListBoxItem* );
void activeChanged( QListWidgetItem* );
private:
QVector< Rules* > rules;
};

View file

@ -17,7 +17,7 @@
<number>0</number>
</property>
<item rowspan="6" row="0" column="0" colspan="1" >
<widget class="K3ListBox" name="rules_listbox" />
<widget class="KListWidget" name="rules_listbox" />
</item>
<item row="0" column="1" >
<widget class="KPushButton" name="new_button" >
@ -80,9 +80,9 @@
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<customwidgets>
<customwidget>
<class>K3ListBox</class>
<extends>Q3ListBox</extends>
<header>k3listbox.h</header>
<class>KListWidget</class>
<extends>QListWidget</extends>
<header>klistwidget.h</header>
</customwidget>
</customwidgets>
<includes>

View file

@ -383,16 +383,16 @@ void RulesWidget::setRules( Rules* rules )
role->setText( rules->windowrole );
role_match->setCurrentIndex( rules->windowrolematch );
roleMatchChanged();
types->setSelected( 0, rules->types & NET::NormalMask );
types->setSelected( 1, rules->types & NET::DialogMask );
types->setSelected( 2, rules->types & NET::UtilityMask );
types->setSelected( 3, rules->types & NET::DockMask );
types->setSelected( 4, rules->types & NET::ToolbarMask );
types->setSelected( 5, rules->types & NET::MenuMask );
types->setSelected( 6, rules->types & NET::SplashMask );
types->setSelected( 7, rules->types & NET::DesktopMask );
types->setSelected( 8, rules->types & NET::OverrideMask );
types->setSelected( 9, rules->types & NET::TopMenuMask );
types->item(0)->setSelected( rules->types & NET::NormalMask );
types->item(1)->setSelected( rules->types & NET::DialogMask );
types->item(2)->setSelected( rules->types & NET::UtilityMask );
types->item(3)->setSelected( rules->types & NET::DockMask );
types->item(4)->setSelected( rules->types & NET::ToolbarMask );
types->item(5)->setSelected( rules->types & NET::MenuMask );
types->item(6)->setSelected( rules->types & NET::SplashMask );
types->item(7)->setSelected( rules->types & NET::DesktopMask );
types->item(8)->setSelected( rules->types & NET::OverrideMask );
types->item(9)->setSelected( rules->types & NET::TopMenuMask );
title->setText( rules->title );
title_match->setCurrentIndex( rules->titlematch );
titleMatchChanged();
@ -466,25 +466,25 @@ Rules* RulesWidget::rules() const
rules->windowrolematch = static_cast< Rules::StringMatch >( role_match->currentIndex());
rules->types = 0;
bool all_types = true;
for( unsigned int i = 0;
for( int i = 0;
i < types->count();
++i )
if( !types->isSelected( i ))
if( !types->item(i)->isSelected())
all_types = false;
if( all_types ) // if all types are selected, use AllTypesMask (for future expansion)
rules->types = NET::AllTypesMask;
else
{
rules->types |= types->isSelected( 0 ) ? NET::NormalMask : 0;
rules->types |= types->isSelected( 1 ) ? NET::DialogMask : 0;
rules->types |= types->isSelected( 2 ) ? NET::UtilityMask : 0;
rules->types |= types->isSelected( 3 ) ? NET::DockMask : 0;
rules->types |= types->isSelected( 4 ) ? NET::ToolbarMask : 0;
rules->types |= types->isSelected( 5 ) ? NET::MenuMask : 0;
rules->types |= types->isSelected( 6 ) ? NET::SplashMask : 0;
rules->types |= types->isSelected( 7 ) ? NET::DesktopMask : 0;
rules->types |= types->isSelected( 8 ) ? NET::OverrideMask : 0;
rules->types |= types->isSelected( 9 ) ? NET::TopMenuMask : 0;
rules->types |= types->item(0)->isSelected() ? NET::NormalMask : 0;
rules->types |= types->item(1)->isSelected() ? NET::DialogMask : 0;
rules->types |= types->item(2)->isSelected() ? NET::UtilityMask : 0;
rules->types |= types->item(3)->isSelected() ? NET::DockMask : 0;
rules->types |= types->item(4)->isSelected() ? NET::ToolbarMask : 0;
rules->types |= types->item(5)->isSelected() ? NET::MenuMask : 0;
rules->types |= types->item(6)->isSelected() ? NET::SplashMask : 0;
rules->types |= types->item(7)->isSelected() ? NET::DesktopMask : 0;
rules->types |= types->item(8)->isSelected() ? NET::OverrideMask : 0;
rules->types |= types->item(9)->isSelected() ? NET::TopMenuMask : 0;
}
rules->title = title->text();
rules->titlematch = static_cast< Rules::StringMatch >( title_match->currentIndex());
@ -567,19 +567,19 @@ void RulesWidget::detected( bool ok )
roleMatchChanged();
if( detect_dlg->selectedWholeApp())
{
for( unsigned int i = 0;
for( int i = 0;
i < types->count();
++i )
types->setSelected( i, true );
types->item(i)->setSelected( true );
}
else
{
NET::WindowType type = detect_dlg->selectedType();
for( unsigned int i = 0;
for( int i = 0;
i < types->count();
++i )
types->setSelected( i, false );
types->setSelected( typeToCombo( type ), true );
types->item(i)->setSelected( false );
types->item( typeToCombo(type) )->setSelected( true );
}
title->setText( detect_dlg->selectedTitle());
title_match->setCurrentIndex( detect_dlg->titleMatch());
@ -653,10 +653,10 @@ bool RulesWidget::finalCheck()
description->setText( i18n( "Unnamed entry" ));
}
bool all_types = true;
for( unsigned int i = 0;
for( int i = 0;
i < types->count();
++i )
if( !types->isSelected( i ))
if( !types->item(i)->isSelected())
all_types = false;
if( wmclass_match->currentIndex() == Rules::UnimportantMatch && all_types )
{

View file

@ -329,7 +329,7 @@
<cstring>types</cstring>
</property>
</widget>
<widget class="K3ListBox" row="1" column="0" rowspan="1" colspan="4">
<widget class="KListWidget" row="1" column="0" rowspan="1" colspan="4">
<item>
<property name="text">
<string>Normal Window</string>