Commit 060b5790 authored by R. Harish Navnit's avatar R. Harish Navnit Committed by Pali Rohár

Remove Q3ListViews in autoreplace

REVIEW: 124227
parent 0fffe07b
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
#include <qlayout.h> #include <qlayout.h>
#include <qpushbutton.h> #include <qpushbutton.h>
#include <q3header.h> #include <QTreeWidget>
#include <q3listview.h>
#include <klocale.h> #include <klocale.h>
#include <klineedit.h> #include <klineedit.h>
...@@ -40,6 +39,7 @@ K_EXPORT_PLUGIN(AutoReplacePreferencesFactory( "kcm_kopete_autoreplace" )) ...@@ -40,6 +39,7 @@ K_EXPORT_PLUGIN(AutoReplacePreferencesFactory( "kcm_kopete_autoreplace" ))
AutoReplacePreferences::AutoReplacePreferences( QWidget *parent, const QVariantList &args ) AutoReplacePreferences::AutoReplacePreferences( QWidget *parent, const QVariantList &args )
: KCModule( AutoReplacePreferencesFactory::componentData(), parent, args ) : KCModule( AutoReplacePreferencesFactory::componentData(), parent, args )
{ {
QStringList headerList = (QStringList() << i18n("Text") << i18n("Replacement"));
QVBoxLayout* l = new QVBoxLayout( this ); QVBoxLayout* l = new QVBoxLayout( this );
QWidget* w = new QWidget; QWidget* w = new QWidget;
preferencesDialog = new Ui::AutoReplacePrefsUI; preferencesDialog = new Ui::AutoReplacePrefsUI;
...@@ -47,9 +47,11 @@ AutoReplacePreferences::AutoReplacePreferences( QWidget *parent, const QVariantL ...@@ -47,9 +47,11 @@ AutoReplacePreferences::AutoReplacePreferences( QWidget *parent, const QVariantL
l->addWidget( w ); l->addWidget( w );
// creates table columns (avoids new columns every time) // creates table columns (avoids new columns every time)
preferencesDialog->m_list->addColumn( i18n("Text" ) ); preferencesDialog->m_list->setColumnCount(2);
preferencesDialog->m_list->addColumn( i18n("Replacement" ) ); preferencesDialog->m_list->setHeaderLabels(headerList);
preferencesDialog->m_list->header()->setStretchEnabled( true , 1 ); preferencesDialog->m_list->header()->setResizeMode(QHeaderView::Stretch);
preferencesDialog->m_list->setSelectionMode(QAbstractItemView::SingleSelection);
preferencesDialog->m_list->header()->setSortIndicatorShown(true);
// connect SIGNALS/SLOTS // connect SIGNALS/SLOTS
connect( preferencesDialog->m_add, SIGNAL(pressed()), connect( preferencesDialog->m_add, SIGNAL(pressed()),
...@@ -96,8 +98,9 @@ void AutoReplacePreferences::load() ...@@ -96,8 +98,9 @@ void AutoReplacePreferences::load()
AutoReplaceConfig::WordsToReplace map = m_config->map(); AutoReplaceConfig::WordsToReplace map = m_config->map();
for ( it = map.begin(); it != map.end(); ++it ) for ( it = map.begin(); it != map.end(); ++it )
{ {
QStringList args = (QStringList() << it.key() << it.value());
// notice: insertItem is called automatically by the constructor // notice: insertItem is called automatically by the constructor
new Q3ListViewItem( preferencesDialog->m_list, it.key(), it.value() ); new QTreeWidgetItem( preferencesDialog->m_list, args );
} }
preferencesDialog->AutoReplaceIncoming->setChecked(m_config->autoReplaceIncoming()); preferencesDialog->AutoReplaceIncoming->setChecked(m_config->autoReplaceIncoming());
...@@ -111,9 +114,10 @@ void AutoReplacePreferences::save() ...@@ -111,9 +114,10 @@ void AutoReplacePreferences::save()
{ {
// make a list reading all values from gui // make a list reading all values from gui
AutoReplaceConfig::WordsToReplace newWords; AutoReplaceConfig::WordsToReplace newWords;
for ( Q3ListViewItem * i = preferencesDialog->m_list->firstChild(); i != 0; i = i->nextSibling() ) for (int i = 0; i < preferencesDialog->m_list->topLevelItemCount(); ++i) {
newWords[ i->text( 0 ) ] = i->text( 1 ); QTreeWidgetItem *item = preferencesDialog->m_list->topLevelItem(i);
newWords[item->text(0)] = item->text(1);
}
// save the words list // save the words list
m_config->setMap( newWords ); m_config->setMap( newWords );
...@@ -130,19 +134,21 @@ void AutoReplacePreferences::slotAddCouple() ...@@ -130,19 +134,21 @@ void AutoReplacePreferences::slotAddCouple()
{ {
QString k = preferencesDialog->m_key->text(); QString k = preferencesDialog->m_key->text();
QString v = preferencesDialog->m_value->text(); QString v = preferencesDialog->m_value->text();
QStringList args = (QStringList() << k << v);
if ( !k.isEmpty() && !k.isNull() && !v.isEmpty() && !v.isNull() ) if ( !k.isEmpty() && !k.isNull() && !v.isEmpty() && !v.isNull() )
{ {
Q3ListViewItem * lvi; QTreeWidgetItem * lvi;
Q3ListViewItem * oldLvi = 0; QTreeWidgetItem * oldLvi = 0;
// see if we are replacing an existing entry // see if we are replacing an existing entry
oldLvi = preferencesDialog->m_list->findItem( k, 0 ); QList<QTreeWidgetItem *> oldLvi_List = preferencesDialog->m_list->findItems( k, Qt::MatchExactly, 0 );
oldLvi = oldLvi_List.first(); //SelectionMode::SingleSelection
delete oldLvi; delete oldLvi;
lvi = new Q3ListViewItem( preferencesDialog->m_list, k, v ); lvi = new QTreeWidgetItem( preferencesDialog->m_list, args );
// Triggers a size, geometry and content update // Triggers a size, geometry and content update
// during the next iteration of the event loop // during the next iteration of the event loop
preferencesDialog->m_list->triggerUpdate(); preferencesDialog->m_list->update();
// select last added // select last added
preferencesDialog->m_list->setSelected( lvi, true ); lvi->setSelected(true);
} }
slotWidgetModified(); slotWidgetModified();
...@@ -153,12 +159,12 @@ void AutoReplacePreferences::slotEditCouple() ...@@ -153,12 +159,12 @@ void AutoReplacePreferences::slotEditCouple()
{ {
const QString k = preferencesDialog->m_key->text(); const QString k = preferencesDialog->m_key->text();
const QString v = preferencesDialog->m_value->text(); const QString v = preferencesDialog->m_value->text();
Q3ListViewItem * lvi; QTreeWidgetItem * lvi;
if ( ( lvi = preferencesDialog->m_list->selectedItem() ) && !k.isEmpty() && !k.isNull() && !v.isEmpty() && !v.isNull() ) if ( ( lvi = preferencesDialog->m_list->currentItem() ) && !k.isEmpty() && !k.isNull() && !v.isEmpty() && !v.isNull() )
{ {
lvi->setText( 0, k ); lvi->setText( 0, k );
lvi->setText( 1, v ); lvi->setText( 1, v );
preferencesDialog->m_list->triggerUpdate(); preferencesDialog->m_list->update();
slotWidgetModified(); slotWidgetModified();
} }
} }
...@@ -167,7 +173,7 @@ void AutoReplacePreferences::slotEditCouple() ...@@ -167,7 +173,7 @@ void AutoReplacePreferences::slotEditCouple()
// Single selection mode and an item is selected // Single selection mode and an item is selected
void AutoReplacePreferences::slotRemoveCouple() void AutoReplacePreferences::slotRemoveCouple()
{ {
delete preferencesDialog->m_list->selectedItem(); delete preferencesDialog->m_list->currentItem();
slotWidgetModified(); slotWidgetModified();
} }
...@@ -175,13 +181,13 @@ void AutoReplacePreferences::slotRemoveCouple() ...@@ -175,13 +181,13 @@ void AutoReplacePreferences::slotRemoveCouple()
void AutoReplacePreferences::slotEnableAddEdit( const QString & keyText ) void AutoReplacePreferences::slotEnableAddEdit( const QString & keyText )
{ {
preferencesDialog->m_add->setEnabled( !keyText.isEmpty() ); preferencesDialog->m_add->setEnabled( !keyText.isEmpty() );
preferencesDialog->m_edit->setEnabled( !keyText.isEmpty() && preferencesDialog->m_list->selectedItem() ); preferencesDialog->m_edit->setEnabled( !keyText.isEmpty() && preferencesDialog->m_list->currentItem() );
} }
void AutoReplacePreferences::slotSelectionChanged() void AutoReplacePreferences::slotSelectionChanged()
{ {
Q3ListViewItem *selection = 0; QTreeWidgetItem *selection = 0;
if ( ( selection = preferencesDialog->m_list->selectedItem() ) ) if ( ( selection = preferencesDialog->m_list->currentItem() ) )
{ {
// enable the remove button // enable the remove button
preferencesDialog->m_remove->setEnabled( true ); preferencesDialog->m_remove->setEnabled( true );
...@@ -210,8 +216,9 @@ void AutoReplacePreferences::defaults() ...@@ -210,8 +216,9 @@ void AutoReplacePreferences::defaults()
AutoReplaceConfig::WordsToReplace map = m_config->map(); AutoReplaceConfig::WordsToReplace map = m_config->map();
for ( it = map.begin(); it != map.end(); ++it ) for ( it = map.begin(); it != map.end(); ++it )
{ {
QStringList args = (QStringList() << it.key() << it.value());
// notice: insertItem is called automatically by the constructor // notice: insertItem is called automatically by the constructor
new Q3ListViewItem( preferencesDialog->m_list, it.key(), it.value() ); new QTreeWidgetItem( preferencesDialog->m_list, args );
} }
preferencesDialog->AutoReplaceIncoming->setChecked(false); preferencesDialog->AutoReplaceIncoming->setChecked(false);
......
...@@ -89,16 +89,10 @@ ...@@ -89,16 +89,10 @@
<number>6</number> <number>6</number>
</property> </property>
<item row="1" column="0" > <item row="1" column="0" >
<widget class="Q3ListView" name="m_list" > <widget class="QTreeWidget" name="m_list" >
<property name="selectionMode" >
<enum>Q3ListView::Single</enum>
</property>
<property name="allColumnsShowFocus" > <property name="allColumnsShowFocus" >
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="showSortIndicator" >
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="1" > <item row="1" column="1" >
...@@ -257,13 +251,6 @@ ...@@ -257,13 +251,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>Q3ListView</class>
<extends>Q3Frame</extends>
<header>q3listview.h</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>DotEndSentence</tabstop> <tabstop>DotEndSentence</tabstop>
<tabstop>CapitalizeBeginningSentence</tabstop> <tabstop>CapitalizeBeginningSentence</tabstop>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment