Commit 4b224516 authored by Leo Treloar's avatar Leo Treloar
Browse files

Add name-only tooltip and make logicalHeightHints a pair of qreal and bool

parent e46e982d
Pipeline #114923 passed with stage
in 5 minutes and 5 seconds
......@@ -109,7 +109,6 @@ QFont KFileItemListWidgetInformant::customizedFontForLinks(const QFont& baseFont
return font;
}
KFileItemListWidget::KFileItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
KStandardItemListWidget(informant, parent)
{
......
......@@ -458,7 +458,7 @@ int KItemListView::lastVisibleIndex() const
return m_layouter->lastVisibleIndex();
}
void KItemListView::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint) const
void KItemListView::calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint) const
{
widgetCreator()->calculateItemSizeHints(logicalHeightHints, logicalWidthHint, this);
}
......@@ -495,6 +495,11 @@ QRectF KItemListView::itemContextRect(int index) const
return contextRect;
}
bool KItemListView::isElided(int index) const
{
return m_sizeHintResolver->isElided(index);
}
void KItemListView::scrollToItem(int index)
{
QRectF viewGeometry = geometry();
......
......@@ -189,7 +189,7 @@ public:
* @note the logical height (width) is actually the
* width (height) if the scroll orientation is Qt::Vertical!
*/
void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint) const;
void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint) const;
/**
* If set to true, items having child-items can be expanded to show the child-items as
......@@ -221,6 +221,12 @@ public:
*/
QRectF itemContextRect(int index) const;
/**
* @return Whether or not the name of the file has been elided. At present this will
* only ever be true when in icons view.
*/
bool isElided(int index) const;
/**
* Scrolls to the item with the index \a index so that the item
* will be fully visible.
......@@ -384,6 +390,8 @@ protected:
virtual void updateFont();
virtual void updatePalette();
KItemListSizeHintResolver* m_sizeHintResolver;
protected Q_SLOTS:
virtual void slotItemsInserted(const KItemRangeList& itemRanges);
virtual void slotItemsRemoved(const KItemRangeList& itemRanges);
......@@ -723,7 +731,6 @@ private:
QHash<int, Cell> m_visibleCells;
int m_scrollBarExtent;
KItemListSizeHintResolver* m_sizeHintResolver;
KItemListViewLayouter* m_layouter;
KItemListViewAnimation* m_animation;
......@@ -803,7 +810,7 @@ public:
virtual void recycle(KItemListWidget* widget);
virtual void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0;
virtual void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0;
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
int index,
......@@ -822,7 +829,7 @@ public:
KItemListWidget* create(KItemListView* view) override;
void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override;
void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override;
qreal preferredRoleColumnWidth(const QByteArray& role,
int index,
......@@ -856,7 +863,7 @@ KItemListWidget* KItemListWidgetCreator<T>::create(KItemListView* view)
}
template<class T>
void KItemListWidgetCreator<T>::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
void KItemListWidgetCreator<T>::calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
{
return m_informant->calculateItemSizeHints(logicalHeightHints, logicalWidthHint, view);
}
......
......@@ -35,7 +35,7 @@ public:
KItemListWidgetInformant();
virtual ~KItemListWidgetInformant();
virtual void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0;
virtual void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0;
virtual qreal preferredRoleColumnWidth(const QByteArray& role,
int index,
......
......@@ -36,7 +36,7 @@ KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant()
{
}
void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
{
switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) {
case KStandardItemListView::IconsLayout:
......@@ -121,7 +121,7 @@ QFont KStandardItemListWidgetInformant::customizedFontForLinks(const QFont& base
return baseFont;
}
void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
{
const KItemListStyleOption& option = view->styleOption();
const QFont& normalFont = option.font;
......@@ -138,7 +138,7 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
for (int index = 0; index < logicalHeightHints.count(); ++index) {
if (logicalHeightHints.at(index) > 0.0) {
if (logicalHeightHints.at(index).first > 0.0) {
continue;
}
......@@ -146,7 +146,7 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
const QFont& font = itemIsLink(index, view) ? linkFont : normalFont;
const QString& text = KStringHandler::preProcessWrap(itemText(index, view));
// Calculate the number of lines required for wrapping the name
qreal textHeight = 0;
QTextLayout layout(text, font);
......@@ -154,6 +154,7 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
layout.beginLayout();
QTextLine line;
int lineCount = 0;
bool isElided = false;
while ((line = layout.createLine()).isValid()) {
line.setLineWidth(maxWidth);
line.naturalTextWidth();
......@@ -161,6 +162,7 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
++lineCount;
if (lineCount == option.maxTextLines) {
isElided = layout.createLine().isValid();
break;
}
}
......@@ -169,13 +171,14 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
// Add one line for each additional information
textHeight += additionalRolesSpacing;
logicalHeightHints[index] = textHeight + spacingAndIconHeight;
logicalHeightHints[index].first = textHeight + spacingAndIconHeight;
logicalHeightHints[index].second = isElided;
}
logicalWidthHint = itemWidth;
}
void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
{
const KItemListStyleOption& option = view->styleOption();
const QFontMetrics& normalFontMetrics = option.fontMetrics;
......@@ -190,7 +193,7 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect
const QFontMetrics linkFontMetrics(customizedFontForLinks(option.font));
for (int index = 0; index < logicalHeightHints.count(); ++index) {
if (logicalHeightHints.at(index) > 0.0) {
if (logicalHeightHints.at(index).first > 0.0) {
continue;
}
......@@ -217,13 +220,13 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect
width = maxWidth;
}
logicalHeightHints[index] = width;
logicalHeightHints[index].first = width;
}
logicalWidthHint = height;
}
void KStandardItemListWidgetInformant::calculateDetailsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
void KStandardItemListWidgetInformant::calculateDetailsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const
{
const KItemListStyleOption& option = view->styleOption();
......@@ -241,7 +244,7 @@ void KStandardItemListWidgetInformant::calculateDetailsLayoutItemSizeHints(QVect
}
const qreal contentHeight = qMax<qreal>(option.iconSize, zoomLevel * option.fontMetrics.height());
logicalHeightHints.fill(contentHeight + 2 * option.padding);
logicalHeightHints.fill(std::make_pair(contentHeight + 2 * option.padding, false));
logicalWidthHint = -1.0;
}
......
......@@ -23,12 +23,13 @@ class DOLPHIN_EXPORT KStandardItemListWidgetInformant : public KItemListWidgetIn
public:
KStandardItemListWidgetInformant();
~KStandardItemListWidgetInformant() override;
void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override;
void calculateItemSizeHints(QVector<std::pair<qreal /* height */, bool /* isElided */>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override;
qreal preferredRoleColumnWidth(const QByteArray& role,
int index,
const KItemListView* view) const override;
protected:
/**
* @return The value of the "text" role. The default implementation returns
......@@ -59,9 +60,9 @@ protected:
*/
virtual QFont customizedFontForLinks(const QFont& baseFont) const;
void calculateIconsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
void calculateCompactLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
void calculateDetailsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
void calculateIconsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
void calculateCompactLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
void calculateDetailsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
friend class KStandardItemListWidget; // Accesses roleText()
};
......
......@@ -29,7 +29,12 @@ QSizeF KItemListSizeHintResolver::minSizeHint()
QSizeF KItemListSizeHintResolver::sizeHint(int index)
{
updateCache();
return QSizeF(m_logicalWidthHint, m_logicalHeightHintCache.at(index));
return QSizeF(m_logicalWidthHint, m_logicalHeightHintCache.at(index).first);
}
bool KItemListSizeHintResolver::isElided(int index)
{
return m_logicalHeightHintCache.at(index).second;
}
void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
......@@ -44,7 +49,7 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
// We build the new list from the end to the beginning to mimize the
// number of moves.
m_logicalHeightHintCache.insert(m_logicalHeightHintCache.end(), insertedCount, 0.0);
m_logicalHeightHintCache.insert(m_logicalHeightHintCache.end(), insertedCount, std::make_pair(0.0, false));
int sourceIndex = currentCount - 1;
int targetIndex = m_logicalHeightHintCache.count() - 1;
......@@ -63,7 +68,7 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
// Then: insert QSizeF() for the items which are inserted into 'range'.
while (targetIndex >= itemsToInsertBeforeCurrentRange + range.index) {
m_logicalHeightHintCache[targetIndex] = 0.0;
m_logicalHeightHintCache[targetIndex] = std::make_pair(0.0, false);
--targetIndex;
}
}
......@@ -75,14 +80,14 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList& itemRanges)
{
const QVector<qreal>::iterator begin = m_logicalHeightHintCache.begin();
const QVector<qreal>::iterator end = m_logicalHeightHintCache.end();
const QVector<std::pair<qreal, bool>>::iterator begin = m_logicalHeightHintCache.begin();
const QVector<std::pair<qreal, bool>>::iterator end = m_logicalHeightHintCache.end();
KItemRangeList::const_iterator rangeIt = itemRanges.constBegin();
const KItemRangeList::const_iterator rangeEnd = itemRanges.constEnd();
QVector<qreal>::iterator destIt = begin + rangeIt->index;
QVector<qreal>::iterator srcIt = destIt + rangeIt->count;
QVector<std::pair<qreal, bool>>::iterator destIt = begin + rangeIt->index;
QVector<std::pair<qreal, bool>>::iterator srcIt = destIt + rangeIt->count;
++rangeIt;
......@@ -109,7 +114,7 @@ void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList& itemRanges)
void KItemListSizeHintResolver::itemsMoved(const KItemRange& range, const QList<int>& movedToIndexes)
{
QVector<qreal> newLogicalHeightHintCache(m_logicalHeightHintCache);
QVector<std::pair<qreal, bool>> newLogicalHeightHintCache(m_logicalHeightHintCache);
const int movedRangeEnd = range.index + range.count;
for (int i = range.index; i < movedRangeEnd; ++i) {
......@@ -124,7 +129,7 @@ void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QB
{
Q_UNUSED(roles)
while (count) {
m_logicalHeightHintCache[index] = 0.0;
m_logicalHeightHintCache[index] = std::make_pair(0.0, false);
++index;
--count;
}
......@@ -134,7 +139,7 @@ void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QB
void KItemListSizeHintResolver::clearCache()
{
m_logicalHeightHintCache.fill(0.0);
m_logicalHeightHintCache.fill(std::make_pair(0.0, false));
m_needsResolving = true;
}
......
......@@ -25,6 +25,7 @@ public:
virtual ~KItemListSizeHintResolver();
QSizeF minSizeHint();
QSizeF sizeHint(int index);
bool isElided(int index);
void itemsInserted(const KItemRangeList& itemRanges);
void itemsRemoved(const KItemRangeList& itemRanges);
......@@ -36,7 +37,7 @@ public:
private:
const KItemListView* m_itemListView;
mutable QVector<qreal> m_logicalHeightHintCache;
mutable QVector<std::pair<qreal /* height */, bool /* isElided */>> m_logicalHeightHintCache;
mutable qreal m_logicalWidthHint;
mutable qreal m_minHeightHint;
bool m_needsResolving;
......
......@@ -59,6 +59,7 @@
#include <QScrollBar>
#include <QSize>
#include <QTimer>
#include <QToolTip>
#include <QVBoxLayout>
DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
......@@ -918,6 +919,11 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
if (watched == m_view) {
m_dragging = false;
}
break;
case QEvent::ToolTip:
tryShowNameToolTip(event);
default:
break;
}
......@@ -1637,13 +1643,15 @@ void DolphinView::updateViewState()
void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
{
#ifdef HAVE_BALOO
if (GeneralSettings::showToolTips()) {
#ifdef HAVE_BALOO
m_toolTipManager->hideToolTip(behavior);
}
#else
Q_UNUSED(behavior)
#endif
} else if (m_mode == DolphinView::IconsView) {
QToolTip::hideText();
}
}
void DolphinView::slotTwoClicksRenamingTimerTimeout()
......@@ -2158,3 +2166,25 @@ void DolphinView::updatePlaceholderLabel()
m_placeholderLabel->setVisible(true);
}
void DolphinView::tryShowNameToolTip(QEvent* event)
{
if (!GeneralSettings::showToolTips() && m_mode == DolphinView::IconsView) {
QHelpEvent *hoverEvent = reinterpret_cast<QHelpEvent *>(event);
const int index = m_view->itemAt(hoverEvent->pos());
if (index == -1) {
return;
}
// Check whether the filename has been elided
const bool isElided = m_view->isElided(index);
if(isElided) {
const KFileItem item = m_model->fileItem(index);
const QString text = item.text();
const QPoint pos = mapToGlobal(hoverEvent->pos());
QToolTip::showText(pos, text);
}
}
}
......@@ -862,6 +862,8 @@ private:
void updatePlaceholderLabel();
void tryShowNameToolTip(QEvent* event);
private:
void updatePalette();
void showLoadingPlaceholder();
......
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