X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e3063e001a016849276b65527ac56c26d56b5f30..d48b733:/src/views/tooltips/filemetadatatooltip.cpp diff --git a/src/views/tooltips/filemetadatatooltip.cpp b/src/views/tooltips/filemetadatatooltip.cpp index deda38ab6..8fbca290d 100644 --- a/src/views/tooltips/filemetadatatooltip.cpp +++ b/src/views/tooltips/filemetadatatooltip.cpp @@ -1,6 +1,7 @@ /*************************************************************************** * Copyright (C) 2010 by Peter Penz * * Copyright (C) 2008 by Fredrik Höglund * + * Copyright (C) 2012 by Mark Gaiser * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -21,14 +22,24 @@ #include "filemetadatatooltip.h" #include -#include #include -#include +// For the blurred tooltip background +#include +#include +#include #include #include #include #include +#include +#include + +#ifndef HAVE_BALOO +#include +#else +#include +#endif FileMetaDataToolTip::FileMetaDataToolTip(QWidget* parent) : QWidget(parent), @@ -45,16 +56,29 @@ FileMetaDataToolTip::FileMetaDataToolTip(QWidget* parent) : // Create widget for file name m_name = new QLabel(this); + m_name->setForegroundRole(QPalette::ToolTipText); + m_name->setTextFormat(Qt::PlainText); + m_name->setAlignment(Qt::AlignHCenter); + QFont font = m_name->font(); font.setBold(true); m_name->setFont(font); + QFontMetrics fontMetrics(font); + m_name->setMaximumWidth(fontMetrics.averageCharWidth() * 40); + // Create widget for the meta data +#ifndef HAVE_BALOO m_fileMetaDataWidget = new KFileMetaDataWidget(this); + connect(m_fileMetaDataWidget, &KFileMetaDataWidget::metaDataRequestFinished, + this, &FileMetaDataToolTip::metaDataRequestFinished); +#else + m_fileMetaDataWidget = new Baloo::FileMetaDataWidget(this); + connect(m_fileMetaDataWidget, &Baloo::FileMetaDataWidget::metaDataRequestFinished, + this, &FileMetaDataToolTip::metaDataRequestFinished); +#endif m_fileMetaDataWidget->setForegroundRole(QPalette::ToolTipText); m_fileMetaDataWidget->setReadOnly(true); - connect(m_fileMetaDataWidget, SIGNAL(metaDataRequestFinished(KFileItemList)), - this, SIGNAL(metaDataRequestFinished(KFileItemList))); QVBoxLayout* textLayout = new QVBoxLayout(); textLayout->addWidget(m_name); @@ -93,7 +117,33 @@ QPixmap FileMetaDataToolTip::preview() const void FileMetaDataToolTip::setName(const QString& name) { - m_name->setText(name); + QTextOption textOption; + textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + + const QString processedName = Qt::mightBeRichText(name) ? name : KStringHandler::preProcessWrap(name); + + QTextLayout textLayout(processedName); + textLayout.setFont(m_name->font()); + textLayout.setTextOption(textOption); + + QString wrappedText; + wrappedText.reserve(processedName.length()); + + // wrap the text to fit into the maximum width of m_name + textLayout.beginLayout(); + QTextLine line = textLayout.createLine(); + while (line.isValid()) { + line.setLineWidth(m_name->maximumWidth()); + wrappedText += processedName.midRef(line.textStart(), line.textLength()); + + line = textLayout.createLine(); + if (line.isValid()) { + wrappedText += QChar::LineSeparator; + } + } + textLayout.endLayout(); + + m_name->setText(wrappedText); } QString FileMetaDataToolTip::name() const @@ -122,4 +172,10 @@ void FileMetaDataToolTip::paintEvent(QPaintEvent* event) QWidget::paintEvent(event); } -#include "filemetadatatooltip.moc" +void FileMetaDataToolTip::showEvent(QShowEvent *) +{ +#pragma message("TODO: port Plasma::WindowEffects::overrideShadow") + //Plasma::WindowEffects::overrideShadow(winId(), true); + KWindowEffects::enableBlurBehind(winId(), true, mask()); +} +