> This is a patch which ports the tooltip edition dialog to Qt4.
Here is the corrected version according to Michaƫl's comments.
Bruno
Index: tooltipeditdialog.cpp
===================================================================
--- tooltipeditdialog.cpp (revision 637996)
+++ tooltipeditdialog.cpp (working copy)
@@ -21,37 +21,15 @@
#include "kopeteglobal.h"
#include "kopeteappearancesettings.h"
-#include <qapplication.h>
-#include <qtoolbutton.h>
-#include <qstringlist.h>
-#include <q3header.h>
+#include <QStringList>
+#include <QApplication>
+#include <QToolButton>
+#include <QStandardItemModel>
+#include <QSortFilterProxyModel>
#include <kiconloader.h>
-#include <k3listview.h>
#include <klocale.h>
-class TooltipItem : public K3ListViewItem
-{
- public:
- TooltipItem(K3ListView *parent, const QString& label, const QString& propertyName)
- : K3ListViewItem(parent, label),
- mPropName(propertyName)
- {
- }
-
- TooltipItem(K3ListView *parent, Q3ListViewItem *item, const QString& label, const QString& propertyName)
- : K3ListViewItem(parent, item, label),
- mPropName(propertyName)
- {
- }
-
- QString propertyName() const { return mPropName; }
- private:
- QString mPropName;
-};
-
-
-
TooltipEditDialog::TooltipEditDialog(QWidget *parent)
: KDialog(parent)
{
@@ -65,24 +43,25 @@
setupUi(mMainWidget);
setMainWidget(mMainWidget);
- lstUsedItems->header()->hide();
- lstUnusedItems->header()->hide();
- lstUsedItems->setSorting( -1 );
- lstUnusedItems->setSorting( 0 );
+ /*
+ * Fill the model with the appropriates entries (pairs label/internal string)
+ */
+ mUnusedEntries = new QStandardItemModel(this);
+ mUsedEntries = new QStandardItemModel(this);
+
const Kopete::ContactPropertyTmpl::Map propmap(
Kopete::Global::Properties::self()->templateMap());
QStringList usedKeys = Kopete::AppearanceSettings::self()->toolTipContents();
- connect(lstUnusedItems, SIGNAL(doubleClicked ( Q3ListViewItem *, const QPoint &, int )), this, SLOT(slotAddButton()));
- connect(lstUsedItems, SIGNAL(doubleClicked ( Q3ListViewItem *, const QPoint &, int )), this, SLOT(slotRemoveButton()));
-
// first fill the "used" list
foreach(QString usedProp, usedKeys)
{
if(propmap.contains(usedProp) && !propmap[usedProp].isPrivate())
{
- new TooltipItem(lstUsedItems, propmap[usedProp].label(), usedProp);
+ QStandardItem *item = new QStandardItem( propmap[usedProp].label() );
+ item->setData( usedProp );
+ mUsedEntries->appendRow( item );
}
}
@@ -92,14 +71,30 @@
for(it = propmap.begin(); it != propmap.end(); ++it)
{
if((usedKeys.contains(it.key())==0) && (!it.value().isPrivate()))
- new TooltipItem(lstUnusedItems, it.value().label(), it.key());
+ {
+ QStandardItem *item = new QStandardItem( it.value().label() );
+ item->setData( it.key() );
+ mUnusedEntries->appendRow( item );
+ }
}
- connect(lstUnusedItems, SIGNAL(selectionChanged(Q3ListViewItem *)),
- this, SLOT(slotUnusedSelected(Q3ListViewItem *)));
- connect(lstUsedItems, SIGNAL(selectionChanged(Q3ListViewItem *)),
- this, SLOT(slotUsedSelected(Q3ListViewItem *)));
+ // We use a proxy for mUnusedEntries because it needs to be alphabetically sorted
+ QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel( this );
+ proxyModel->setSourceModel( mUnusedEntries );
+ proxyModel->sort( 0, Qt::AscendingOrder );
+ unusedItemsListView->setModel( proxyModel );
+ usedItemsListView->setModel( mUsedEntries );
+ /*
+ * Ui setup
+ */
+ connect(unusedItemsListView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this, SLOT(slotUnusedSelected(const QItemSelection&)));
+ connect(usedItemsListView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection&, const QItemSelection& )),
+ this, SLOT(slotUsedSelected(const QItemSelection&)));
+ connect(unusedItemsListView, SIGNAL(doubleClicked ( const QModelIndex& )), this, SLOT(slotAddButton()));
+ connect(usedItemsListView, SIGNAL(doubleClicked ( const QModelIndex& )), this, SLOT(slotRemoveButton()));
+
tbUp->setIcon(KIcon("up"));
tbUp->setEnabled(false);
tbUp->setAutoRepeat(true);
@@ -130,16 +125,17 @@
{
QStringList oldList = Kopete::AppearanceSettings::self()->toolTipContents();
QStringList newList;
- Q3ListViewItemIterator it(lstUsedItems);
+
QString keyname;
- while(it.current())
+ int max = mUsedEntries->rowCount( );
+ for ( int i=0; i < max; i++ )
{
- keyname = static_cast<TooltipItem *>(it.current())->propertyName();
+ QStandardItem *item = mUsedEntries->item( i, 0 );
+ keyname = item->data().value<QString>();
newList += keyname;
- kDebug(14000) << k_funcinfo <<
- "Adding key '" << keyname << "' to tooltip list" << endl;
- ++it;
+ // kDebug(14000) << k_funcinfo <<
+ // "Adding key '" << keyname << "' to tooltip list" << endl;
}
if(oldList != newList)
@@ -151,78 +147,127 @@
}
-void TooltipEditDialog::slotUnusedSelected(Q3ListViewItem *item)
+void TooltipEditDialog::slotUnusedSelected(const QItemSelection& selected)
{
- //tbRemove->setEnabled(false);
- tbAdd->setEnabled(item!=0);
+ tbAdd->setEnabled(selected.indexes().count());
}
-void TooltipEditDialog::slotUsedSelected(Q3ListViewItem *item)
+void TooltipEditDialog::slotUsedSelected(const QItemSelection& selected)
{
- tbRemove->setEnabled(item!=0);
- //tbAdd->setEnabled(false);
- if (item)
- {
- tbUp->setEnabled(item->itemAbove() != 0);
- tbDown->setEnabled(item->itemBelow() != 0);
- }
+ tbRemove->setEnabled( selected.indexes().count() );
+ tbUp->setEnabled( selected.indexes().count() );
+ tbDown->setEnabled( selected.indexes().count() );
+
+ if ( !selected.indexes().count() )
+ return;
+
+ // Disable Up button if we are at the top, disable Down one if we are at bottom
+ if ( selected.indexes().first().row() == 0 )
+ tbUp->setEnabled( false );
else
- {
- tbUp->setEnabled(false);
- tbDown->setEnabled(false);
- }
+ tbUp->setEnabled( true );
+
+ if ( selected.indexes().last().row() == mUsedEntries->rowCount() - 1 )
+ tbDown->setEnabled( false );
+ else
+ tbDown->setEnabled( true );
}
void TooltipEditDialog::slotUpButton()
{
- Q3ListViewItem *item = lstUsedItems->currentItem();
- Q3ListViewItem *prev = item->itemAbove();
- if(prev == 0) // we are first item already
- return;
+ QModelIndexList indexList = usedItemsListView->selectionModel()->selectedIndexes();
+ usedItemsListView->selectionModel()->clear();
- prev->moveItem(item);
- slotUsedSelected(item);
+ foreach( QModelIndex index, indexList )
+ {
+ int row = index.row();
+
+ if ( row - 1 < 0 )
+ return;
+
+ // Move it up
+ mUsedEntries->insertRow( row - 1, mUsedEntries->takeRow( row ) );
+
+ // Keep the element selected
+ usedItemsListView->selectionModel()->select( mUsedEntries->index( row - 1, 0 ) , QItemSelectionModel::Select );
+ usedItemsListView->scrollTo( mUsedEntries->index( row - 1, 0 ) );
+
+ // Check for the up and down buttons
+ if ( row - 1 == 0 )
+ tbUp->setEnabled( false );
+ tbDown->setEnabled( true );
+ }
}
void TooltipEditDialog::slotDownButton()
{
- Q3ListViewItem *item = lstUsedItems->currentItem();
- Q3ListViewItem *next = item->itemBelow();
- if(next == 0) // we are last item already
- return;
+ QModelIndexList indexList = usedItemsListView->selectionModel()->selectedIndexes();
+ usedItemsListView->selectionModel()->clear();
- item->moveItem(next);
- slotUsedSelected(item);
+ foreach( QModelIndex index, indexList ) {
+ int row = index.row();
+
+ if ( row + 1 > mUsedEntries->rowCount() )
+ return;
+
+ // Move it down
+ mUsedEntries->insertRow( row + 1, mUsedEntries->takeRow( row ) );
+
+ // Keep it selected
+ usedItemsListView->selectionModel()->select( mUsedEntries->index( row + 1, 0 ) , QItemSelectionModel::Select );
+ usedItemsListView->scrollTo( mUsedEntries->index( row + 1, 0 ) );
+
+
+ // Check for the up and down buttons
+ if ( row + 1 == mUsedEntries->rowCount() - 1 )
+ tbDown->setEnabled( false );
+ tbUp->setEnabled( true );
+ }
}
void TooltipEditDialog::slotAddButton()
{
- TooltipItem *item = static_cast<TooltipItem *>(lstUnusedItems->currentItem());
- if(!item)
- return;
- //kDebug(14000) << k_funcinfo << endl;
+ QModelIndexList indexList = unusedItemsListView->selectionModel()->selectedIndexes();
- // build a new one in the "used" list
- new TooltipItem(lstUsedItems, item->text(0), item->propertyName());
+ foreach( QModelIndex index_, indexList )
+ {
+ QModelIndex index = static_cast<QSortFilterProxyModel*>( unusedItemsListView->model() )->mapToSource( index_ );
- // remove the old one from "unused" list
- lstUnusedItems->takeItem(item);
- delete item;
+ // We insert it after the last selected one if there is a selection,
+ // at the end else.
+ QModelIndex insertAfter;
+ if ( !usedItemsListView->selectionModel()->selectedIndexes().isEmpty() )
+ insertAfter = usedItemsListView->selectionModel()->selectedIndexes().last();
+ else
+ insertAfter = mUsedEntries->index( mUsedEntries->rowCount() - 1, 0 );
+
+ // Move the row from the unused items list to the used items one.
+ mUsedEntries->insertRow( insertAfter.row() + 1, mUnusedEntries->takeRow( index.row() ) );
+
+ // Make the newly inserted item current
+ QModelIndex newIndex = mUsedEntries->index( insertAfter.row() + 1, 0 );
+ usedItemsListView->setCurrentIndex( newIndex );
+ }
}
void TooltipEditDialog::slotRemoveButton()
{
- TooltipItem *item = static_cast<TooltipItem *>(lstUsedItems->currentItem());
- if(!item)
- return;
- //kDebug(14000) << k_funcinfo << endl;
+ QModelIndexList indexList = usedItemsListView->selectionModel()->selectedIndexes();
- // build a new one in the "unused" list
- new TooltipItem(lstUnusedItems, item->text(0), item->propertyName());
+ foreach( QModelIndex index, indexList )
+ {
+ int row = index.row();
- // remove the old one from "used" list
- lstUsedItems->takeItem(item);
- delete item;
+
+ mUnusedEntries->insertRow( 0, mUsedEntries->takeRow( index.row() ) );
+
+ // Move selection
+ if ( row > 0 )
+ usedItemsListView->selectionModel()->select( mUsedEntries->index( row - 1, 0 ), QItemSelectionModel::Select );
+ else
+ usedItemsListView->selectionModel()->select( mUsedEntries->index( row, 0 ), QItemSelectionModel::Select );
+
+ }
}
#include "tooltipeditdialog.moc"
Index: tooltipeditdialog.h
===================================================================
--- tooltipeditdialog.h (revision 637996)
+++ tooltipeditdialog.h (working copy)
@@ -20,10 +20,11 @@
#include <kdebug.h>
#include <kdialog.h>
-#include <q3listview.h>
#include "ui_tooltipeditwidget.h"
+class QStandardItemModel;
+
class TooltipEditDialog : public KDialog, private Ui::TooltipEditWidget
{
Q_OBJECT
@@ -32,8 +33,8 @@
TooltipEditDialog(QWidget *parent=0);
private slots:
- void slotUnusedSelected(Q3ListViewItem *);
- void slotUsedSelected(Q3ListViewItem *);
+ void slotUnusedSelected(const QItemSelection&);
+ void slotUsedSelected(const QItemSelection&);
void slotUpButton();
void slotDownButton();
void slotAddButton();
@@ -45,6 +46,9 @@
private:
QWidget *mMainWidget;
+
+ QStandardItemModel *mUnusedEntries;
+ QStandardItemModel *mUsedEntries;
};
#endif
Index: tooltipeditwidget.ui
===================================================================
--- tooltipeditwidget.ui (revision 637996)
+++ tooltipeditwidget.ui (working copy)
@@ -1,108 +1,63 @@
<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
<class>TooltipEditWidget</class>
<widget class="QWidget" name="TooltipEditWidget" >
<property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>582</width>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>751</width>
<height>408</height>
- </rect>
- </property>
+ </rect>
+ </property>
<property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>7</hsizetype>
- <vsizetype>7</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<layout class="QGridLayout" >
<property name="margin" >
- <number>11</number>
- </property>
+ <number>9</number>
+ </property>
<property name="spacing" >
<number>6</number>
- </property>
- <item row="1" column="0" >
- <widget class="Line" name="line1" >
- <property name="frameShape" >
- <enum>QFrame::HLine</enum>
- </property>
- <property name="frameShadow" >
- <enum>QFrame::Sunken</enum>
- </property>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item row="2" column="0" >
- <widget class="QLabel" name="textLabel1" >
- <property name="text" >
- <string>Using the arrow buttons, put on the right the items you want to see in the contact tooltips. You can then sort them.</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="0" column="0" >
- <widget class="QLabel" name="textLabel2" >
- <property name="text" >
- <string><b>Here you can customize the contact tooltips</b></string>
- </property>
- </widget>
- </item>
+ </property>
<item row="3" column="0" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
- </property>
+ </property>
<property name="spacing" >
<number>6</number>
- </property>
+ </property>
<item>
- <widget class="K3ListView" name="lstUnusedItems" >
- <property name="whatsThis" >
- <string>This list contains elements which are currently <b>not present</b> in the contact tooltip.</string>
- </property>
- <property name="fullWidth" >
- <bool>true</bool>
- </property>
- <column>
- <property name="text" >
- <string/>
- </property>
- </column>
- </widget>
+ <widget class="QListView" name="unusedItemsListView" />
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
- </property>
+ </property>
<property name="spacing" >
<number>6</number>
- </property>
+ </property>
<item>
- <spacer>
+ <spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
- </property>
+ </property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
- </property>
+ </property>
<property name="sizeHint" >
- <size>
- <width>20</width>
- <height>60</height>
- </size>
- </property>
- </spacer>
+ <size>
+ <width>20</width>
+ <height>60</height>
+ </size>
+ </property>
+ </spacer>
</item>
<item>
<layout class="QGridLayout" >
@@ -116,86 +71,95 @@
<widget class="QToolButton" name="tbDown" >
<property name="whatsThis" >
<string>Use this arrow to reorder the items in the list.</string>
- </property>
+ </property>
<property name="text" >
- <string>v</string>
- </property>
- </widget>
+ <string>v</string>
+ </property>
+ </widget>
</item>
<item row="0" column="1" >
<widget class="QToolButton" name="tbUp" >
<property name="text" >
- <string>^</string>
- </property>
- </widget>
+ <string>^</string>
+ </property>
+ </widget>
</item>
<item row="1" column="0" >
<widget class="QToolButton" name="tbRemove" >
<property name="text" >
- <string><</string>
- </property>
- </widget>
+ <string><</string>
+ </property>
+ </widget>
</item>
<item row="1" column="2" >
<widget class="QToolButton" name="tbAdd" >
<property name="whatsThis" >
- <string>Use this arrows to add or remove items to your contact tooltips.</string>
- </property>
+ <string>Use this arrows to add or remove items to your contact tooltips.</string>
+ </property>
<property name="text" >
<string>></string>
</property>
- </widget>
+ </widget>
</item>
</layout>
</item>
<item>
- <spacer>
+ <spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
- </property>
+ </property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
- </property>
+ </property>
<property name="sizeHint" >
- <size>
- <width>20</width>
- <height>30</height>
- </size>
- </property>
- </spacer>
+ <size>
+ <width>20</width>
+ <height>30</height>
+ </size>
+ </property>
+ </spacer>
</item>
</layout>
</item>
<item>
- <widget class="K3ListView" name="lstUsedItems" >
- <property name="whatsThis" >
- <string>This list contains elements which are currently <b>present</b> in the contact tooltips.</string>
- </property>
- <property name="fullWidth" >
- <bool>true</bool>
- </property>
- <column>
- <property name="text" >
- <string/>
- </property>
- </column>
- </widget>
+ <widget class="QListView" name="usedItemsListView" />
</item>
</layout>
</item>
+ <item row="1" column="0" >
+ <widget class="Line" name="line1" >
+ <property name="frameShape" >
+ <enum>QFrame::HLine</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="textLabel1" >
+ <property name="text" >
+ <string>Using the arrow buttons, put on the right the items you want to see in the contact tooltips. You can then sort them.</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="textLabel2" >
+ <property name="text" >
+ <string><b>Here you can customize the contact tooltips</b></string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
- <customwidgets>
- <customwidget>
- <class>K3ListView</class>
- <extends></extends>
- <header>k3listview.h</header>
- <container>0</container>
- <pixmap></pixmap>
- </customwidget>
- </customwidgets>
<resources/>
<connections/>
</ui>
_______________________________________________
kopete-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kopete-devel