diff --git a/kmymoney/views/kreportsview.h b/kmymoney/views/kreportsview.h --- a/kmymoney/views/kreportsview.h +++ b/kmymoney/views/kreportsview.h @@ -228,6 +228,7 @@ void slotDelete(); void slotListContextMenu(const QPoint &); void slotOpenFromList(); + void slotPrintFromList(); void slotConfigureFromList(); void slotNewFromList(); void slotDeleteFromList(); diff --git a/kmymoney/views/kreportsview.cpp b/kmymoney/views/kreportsview.cpp --- a/kmymoney/views/kreportsview.cpp +++ b/kmymoney/views/kreportsview.cpp @@ -323,7 +323,7 @@ m_tocTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); - m_tocTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); + m_tocTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); m_listTabLayout->addWidget(m_tocTreeWidget); m_reportTabWidget->addTab(m_listTab, i18n("Reports")); @@ -1073,47 +1073,79 @@ void KReportsView::slotListContextMenu(const QPoint & p) { - QTreeWidgetItem *item = m_tocTreeWidget->itemAt(p); + QList items = m_tocTreeWidget->selectedItems(); - if (!item) { + if (items.isEmpty()) return; - } - TocItem* tocItem = dynamic_cast(item); + QList tocItems; + foreach(QTreeWidgetItem *item, items) { + TocItem* tocItem = dynamic_cast(item); + if (!tocItem || !tocItem->isReport()) + continue; + tocItems.append(tocItem); + } - if (!tocItem->isReport()) { - // currently there is no context menu for reportgroup items + if (tocItems.isEmpty()) return; - } KMenu* contextmenu = new KMenu(this); - contextmenu->addAction(i18nc("To open a new report", "&Open"), + contextmenu->addAction(i18nc("To open a report", "&Open"), this, SLOT(slotOpenFromList())); - contextmenu->addAction(i18nc("Configure a report", "&Configure"), - this, SLOT(slotConfigureFromList())); + contextmenu->addAction(i18nc("To print a report", "&Print"), + this, SLOT(slotPrintFromList())); - contextmenu->addAction(i18n("&New report"), - this, SLOT(slotNewFromList())); + if (tocItems.size() == 1) { + TocItem* tocItem = dynamic_cast(tocItems.at(0)); - // Only add this option if it's a custom report. Default reports cannot be deleted - TocItemReport* reportTocItem = dynamic_cast(tocItem); - MyMoneyReport& report = reportTocItem->getReport(); - if (! report.id().isEmpty()) { - contextmenu->addAction(i18n("&Delete"), - this, SLOT(slotDeleteFromList())); + contextmenu->addAction(i18nc("Configure a report", "&Configure"), + this, SLOT(slotConfigureFromList())); + + contextmenu->addAction(i18n("&New report"), + this, SLOT(slotNewFromList())); + + // Only add this option if it's a custom report. Default reports cannot be deleted + TocItemReport* reportTocItem = dynamic_cast(tocItem); + MyMoneyReport& report = reportTocItem->getReport(); + if (! report.id().isEmpty()) { + contextmenu->addAction(i18n("&Delete"), + this, SLOT(slotDeleteFromList())); + } } contextmenu->popup(m_tocTreeWidget->mapToGlobal(p)); } void KReportsView::slotOpenFromList() { - TocItem* tocItem = dynamic_cast(m_tocTreeWidget->currentItem()); + QList items = m_tocTreeWidget->selectedItems(); - if (tocItem) - slotItemDoubleClicked(tocItem, 0); + if (items.isEmpty()) + return; + + foreach(QTreeWidgetItem *item, items) { + TocItem* tocItem = dynamic_cast(item); + if (tocItem && tocItem->isReport()) + slotItemDoubleClicked(tocItem, 0); + } +} + +void KReportsView::slotPrintFromList() +{ + QList items = m_tocTreeWidget->selectedItems(); + + if (items.isEmpty()) + return; + + foreach(QTreeWidgetItem *item, items) { + TocItem* tocItem = dynamic_cast(item); + if (tocItem && tocItem->isReport()) { + slotItemDoubleClicked(tocItem, 0); + slotPrintView(); + } + } } void KReportsView::slotConfigureFromList()