Skip to content
Snippets Groups Projects
Commit fea475ea authored by kh1's avatar kh1
Browse files

Show tooltip for open pages and add a copy to clipboard option.

parent 6c580fd7
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,9 @@ ...@@ -38,7 +38,9 @@
#include "openpageswidget.h" #include "openpageswidget.h"
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <QtGui/QClipboard>
#include <QtGui/QComboBox> #include <QtGui/QComboBox>
#include <QtGui/QMenu>
#include <QtGui/QTreeView> #include <QtGui/QTreeView>
#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpEngine>
...@@ -74,7 +76,10 @@ OpenPagesManager::OpenPagesManager(QObject *parent) ...@@ -74,7 +76,10 @@ OpenPagesManager::OpenPagesManager(QObject *parent)
m_comboBox = new QComboBox; m_comboBox = new QComboBox;
m_comboBox->setModel(m_model); m_comboBox->setModel(m_model);
m_comboBox->setMinimumContentsLength(40); m_comboBox->setMinimumContentsLength(40);
m_comboBox->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_comboBox, SIGNAL(activated(int)), this, SLOT(setCurrentPage(int))); 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); m_openPagesSwitcher = new OpenPagesSwitcher(m_model);
connect(m_openPagesSwitcher, SIGNAL(closePage(QModelIndex)), this, connect(m_openPagesSwitcher, SIGNAL(closePage(QModelIndex)), this,
...@@ -294,3 +299,18 @@ void OpenPagesManager::showTwicherOrSelectPage() const ...@@ -294,3 +299,18 @@ void OpenPagesManager::showTwicherOrSelectPage() const
m_openPagesSwitcher->selectAndHide(); 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);
}
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
QT_FORWARD_DECLARE_CLASS(QComboBox) QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_FORWARD_DECLARE_CLASS(QListView) QT_FORWARD_DECLARE_CLASS(QListView)
QT_FORWARD_DECLARE_CLASS(QModelIndex) QT_FORWARD_DECLARE_CLASS(QModelIndex)
QT_FORWARD_DECLARE_CLASS(QPoint)
QT_FORWARD_DECLARE_CLASS(QTreeView) QT_FORWARD_DECLARE_CLASS(QTreeView)
QT_FORWARD_DECLARE_CLASS(QUrl) QT_FORWARD_DECLARE_CLASS(QUrl)
QT_FORWARD_DECLARE_CLASS(QWidget) QT_FORWARD_DECLARE_CLASS(QWidget)
...@@ -85,6 +86,9 @@ private: ...@@ -85,6 +86,9 @@ private:
void removePage(int index); void removePage(int index);
void showTwicherOrSelectPage() const; void showTwicherOrSelectPage() const;
private slots:
void openPagesContextMenu(const QPoint &point);
private: private:
QComboBox *m_comboBox; QComboBox *m_comboBox;
OpenPagesModel *m_model; OpenPagesModel *m_model;
......
...@@ -51,13 +51,22 @@ int OpenPagesModel::columnCount(const QModelIndex &/*parent*/) const ...@@ -51,13 +51,22 @@ int OpenPagesModel::columnCount(const QModelIndex &/*parent*/) const
QVariant OpenPagesModel::data(const QModelIndex &index, int role) const QVariant OpenPagesModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || role != Qt::DisplayRole if (!index.isValid() || index.row() >= rowCount()
|| index.row() >= rowCount() || index.column() >= columnCount() - 1) || index.column() >= columnCount() - 1)
return QVariant(); return QVariant();
QString title = m_pages.at(index.row())->title(); switch (role) {
title.replace(QLatin1Char('&'), QLatin1String("&&")); case Qt::ToolTipRole:
return title.isEmpty() ? tr("(Untitled)") : title; 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) void OpenPagesModel::addPage(const QUrl &url, qreal zoom)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment