Commit 10007538 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 310808 - Add context menus for list entries

Added menu when make sense.

FIXED-IN: 4.10
BUG: 310808
parent 374f7966
......@@ -37,6 +37,7 @@
#include <kdebug.h>
#include <kpushbutton.h>
#include <kdialog.h>
#include <KMenu>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QListWidget>
......@@ -62,6 +63,12 @@ SimpleStringListEditor::SimpleStringListEditor( QWidget * parent,
hlay->setMargin( 0 );
mListBox = new QListWidget( this );
mListBox->setContextMenuPolicy( Qt::CustomContextMenu );
connect( mListBox, SIGNAL(customContextMenuRequested(QPoint)),
SLOT(slotContextMenu(QPoint)) );
mListBox->setSelectionMode(QAbstractItemView::ExtendedSelection);
hlay->addWidget( mListBox, 1 );
......@@ -347,6 +354,24 @@ void SimpleStringListEditor::slotSelectionChanged() {
}
}
void SimpleStringListEditor::slotContextMenu(const QPoint&pos)
{
QList<QListWidgetItem *> lstSelectedItems = mListBox->selectedItems();
const bool hasItemsSelected = !lstSelectedItems.isEmpty();
KMenu *menu = new KMenu( this );
if (mAddButton) {
menu->addAction( mAddButton->text(), this, SLOT(slotAdd()));
}
if (mModifyButton && (lstSelectedItems.count() == 1)) {
menu->addAction( mModifyButton->text(), this, SLOT(slotModify()));
}
if (mRemoveButton && hasItemsSelected) {
menu->addAction( mRemoveButton->text(), this, SLOT(slotRemove()));
}
menu->exec( mListBox->mapToGlobal( pos ) );
delete menu;
}
#include "simplestringlisteditor.moc"
......@@ -90,7 +90,8 @@ protected slots:
void slotDown();
void slotSelectionChanged();
private Q_SLOTS:
void slotContextMenu(const QPoint&);
protected:
bool containsString( const QString & str );
QList<QListWidgetItem*> selectedItems() const;
......
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