Commit fea475ea authored by kh1's avatar kh1
Browse files

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

parent 6c580fd7
......@@ -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);
}
......@@ -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;
......
......@@ -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)
......
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