diff --git a/src/plugins/help/openpagesmanager.cpp b/src/plugins/help/openpagesmanager.cpp index 5762ee7686a47583c9d92a29c68d67ad8d896854..484d658a00fc18fbcc6e342dd63ab219821f91de 100644 --- a/src/plugins/help/openpagesmanager.cpp +++ b/src/plugins/help/openpagesmanager.cpp @@ -38,7 +38,9 @@ #include "openpageswidget.h" #include <QtGui/QApplication> +#include <QtGui/QClipboard> #include <QtGui/QComboBox> +#include <QtGui/QMenu> #include <QtGui/QTreeView> #include <QtHelp/QHelpEngine> @@ -74,7 +76,10 @@ OpenPagesManager::OpenPagesManager(QObject *parent) m_comboBox = new QComboBox; m_comboBox->setModel(m_model); m_comboBox->setMinimumContentsLength(40); + m_comboBox->setContextMenuPolicy(Qt::CustomContextMenu); connect(m_comboBox, SIGNAL(activated(int)), this, SLOT(setCurrentPage(int))); + connect(m_comboBox, SIGNAL(customContextMenuRequested(QPoint)), this, + SLOT(openPagesContextMenu(QPoint))); m_openPagesSwitcher = new OpenPagesSwitcher(m_model); connect(m_openPagesSwitcher, SIGNAL(closePage(QModelIndex)), this, @@ -294,3 +299,18 @@ void OpenPagesManager::showTwicherOrSelectPage() const m_openPagesSwitcher->selectAndHide(); } } + +// -- private slots + +void OpenPagesManager::openPagesContextMenu(const QPoint &point) +{ + const QModelIndex &index = m_model->index(m_comboBox->currentIndex(), 0); + const QString &fileName = m_model->data(index, Qt::ToolTipRole).toString(); + if (fileName.isEmpty()) + return; + + QMenu menu; + menu.addAction(tr("Copy Full Path to Clipboard")); + if (menu.exec(m_comboBox->mapToGlobal(point))) + QApplication::clipboard()->setText(fileName); +} diff --git a/src/plugins/help/openpagesmanager.h b/src/plugins/help/openpagesmanager.h index 2b8c3d99d74211bddd5354be436165b0629efdbe..42b84ba7b3215202a9c31fd201b6e0f8eeed6181 100644 --- a/src/plugins/help/openpagesmanager.h +++ b/src/plugins/help/openpagesmanager.h @@ -35,6 +35,7 @@ QT_FORWARD_DECLARE_CLASS(QComboBox) QT_FORWARD_DECLARE_CLASS(QListView) QT_FORWARD_DECLARE_CLASS(QModelIndex) +QT_FORWARD_DECLARE_CLASS(QPoint) QT_FORWARD_DECLARE_CLASS(QTreeView) QT_FORWARD_DECLARE_CLASS(QUrl) QT_FORWARD_DECLARE_CLASS(QWidget) @@ -85,6 +86,9 @@ private: void removePage(int index); void showTwicherOrSelectPage() const; +private slots: + void openPagesContextMenu(const QPoint &point); + private: QComboBox *m_comboBox; OpenPagesModel *m_model; diff --git a/src/plugins/help/openpagesmodel.cpp b/src/plugins/help/openpagesmodel.cpp index 36f973051de048116df04014a728eb7c15e09a26..5d6c3070d3f0b8fe581c79bce785a18278ba7829 100644 --- a/src/plugins/help/openpagesmodel.cpp +++ b/src/plugins/help/openpagesmodel.cpp @@ -51,13 +51,22 @@ int OpenPagesModel::columnCount(const QModelIndex &/*parent*/) const QVariant OpenPagesModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || role != Qt::DisplayRole - || index.row() >= rowCount() || index.column() >= columnCount() - 1) + if (!index.isValid() || index.row() >= rowCount() + || index.column() >= columnCount() - 1) return QVariant(); - QString title = m_pages.at(index.row())->title(); - title.replace(QLatin1Char('&'), QLatin1String("&&")); - return title.isEmpty() ? tr("(Untitled)") : title; + switch (role) { + case Qt::ToolTipRole: + return m_pages.at(index.row())->source().toString(); + case Qt::DisplayRole: { + QString title = m_pages.at(index.row())->title(); + title.replace(QLatin1Char('&'), QLatin1String("&&")); + return title.isEmpty() ? tr("(Untitled)") : title; + } + default: + break; + } + return QVariant(); } void OpenPagesModel::addPage(const QUrl &url, qreal zoom)