From d75b1de7bfeba76c540f6772e997aed4aacada88 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Thu, 9 Feb 2017 19:36:11 +0100 Subject: Rename FileMetaDataToolTip to DolphinFileMetaDataWidget Since commit 230fe13d1f this class is not a "tooltip" anymore, but just a simple widget. Rename it to avoid future confusion. Reviewers: emmanuelp Differential Revision: https://phabricator.kde.org/D4451 --- src/CMakeLists.txt | 2 +- src/views/tooltips/dolphinfilemetadatawidget.cpp | 158 +++++++++++++++++++++++ src/views/tooltips/dolphinfilemetadatawidget.h | 82 ++++++++++++ src/views/tooltips/filemetadatatooltip.cpp | 158 ----------------------- src/views/tooltips/filemetadatatooltip.h | 82 ------------ src/views/tooltips/tooltipmanager.cpp | 28 ++-- src/views/tooltips/tooltipmanager.h | 4 +- 7 files changed, 257 insertions(+), 257 deletions(-) create mode 100644 src/views/tooltips/dolphinfilemetadatawidget.cpp create mode 100644 src/views/tooltips/dolphinfilemetadatawidget.h delete mode 100644 src/views/tooltips/filemetadatatooltip.cpp delete mode 100644 src/views/tooltips/filemetadatatooltip.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 87300d60c..ce4cec80c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -102,7 +102,7 @@ set(dolphinprivate_LIB_SRCS views/dolphinviewactionhandler.cpp views/draganddrophelper.cpp views/renamedialog.cpp - views/tooltips/filemetadatatooltip.cpp + views/tooltips/dolphinfilemetadatawidget.cpp views/tooltips/tooltipmanager.cpp views/versioncontrol/updateitemstatesthread.cpp views/versioncontrol/versioncontrolobserver.cpp diff --git a/src/views/tooltips/dolphinfilemetadatawidget.cpp b/src/views/tooltips/dolphinfilemetadatawidget.cpp new file mode 100644 index 000000000..755636c6c --- /dev/null +++ b/src/views/tooltips/dolphinfilemetadatawidget.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinfilemetadatawidget.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#ifndef HAVE_BALOO +#include +#else +#include +#endif + +DolphinFileMetaDataWidget::DolphinFileMetaDataWidget(QWidget* parent) : + QWidget(parent), + m_preview(0), + m_name(0), + m_fileMetaDataWidget(0) +{ + // Create widget for file preview + m_preview = new QLabel(this); + m_preview->setAlignment(Qt::AlignTop); + + // 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, &DolphinFileMetaDataWidget::metaDataRequestFinished); +#else + m_fileMetaDataWidget = new Baloo::FileMetaDataWidget(this); + connect(m_fileMetaDataWidget, &Baloo::FileMetaDataWidget::metaDataRequestFinished, + this, &DolphinFileMetaDataWidget::metaDataRequestFinished); +#endif + m_fileMetaDataWidget->setForegroundRole(QPalette::ToolTipText); + m_fileMetaDataWidget->setReadOnly(true); + + QVBoxLayout* textLayout = new QVBoxLayout(); + textLayout->addWidget(m_name); + textLayout->addWidget(new KSeparator()); + textLayout->addWidget(m_fileMetaDataWidget); + textLayout->setAlignment(m_name, Qt::AlignCenter); + textLayout->setAlignment(m_fileMetaDataWidget, Qt::AlignLeft); + // Assure that the text-layout gets top-aligned by adding a stretch. + // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does + // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget + // (see bug #241608) + textLayout->addStretch(); + + QHBoxLayout* layout = new QHBoxLayout(this); + layout->addWidget(m_preview); + layout->addSpacing(layout->margin()); + layout->addLayout(textLayout); +} + +DolphinFileMetaDataWidget::~DolphinFileMetaDataWidget() +{ +} + +void DolphinFileMetaDataWidget::setPreview(const QPixmap& pixmap) +{ + m_preview->setPixmap(pixmap); +} + +QPixmap DolphinFileMetaDataWidget::preview() const +{ + if (m_preview->pixmap()) { + return *m_preview->pixmap(); + } + return QPixmap(); +} + +void DolphinFileMetaDataWidget::setName(const QString& 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 DolphinFileMetaDataWidget::name() const +{ + return m_name->text(); +} + +void DolphinFileMetaDataWidget::setItems(const KFileItemList& items) +{ + m_fileMetaDataWidget->setItems(items); +} + +KFileItemList DolphinFileMetaDataWidget::items() const +{ + return m_fileMetaDataWidget->items(); +} + diff --git a/src/views/tooltips/dolphinfilemetadatawidget.h b/src/views/tooltips/dolphinfilemetadatawidget.h new file mode 100644 index 000000000..cf796250d --- /dev/null +++ b/src/views/tooltips/dolphinfilemetadatawidget.h @@ -0,0 +1,82 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINFILEMETADATAWIDGET_H +#define DOLPHINFILEMETADATAWIDGET_H + +#include +#include "config-baloo.h" + +class KFileItemList; +class QLabel; + +#ifndef HAVE_BALOO +class KFileMetaDataWidget; +#else +namespace Baloo { + class FileMetaDataWidget; +} +#endif + +/** + * @brief Widget that shows the meta information and a preview of one + * or more files inside a KToolTipWidget. + */ +class DolphinFileMetaDataWidget : public QWidget +{ + Q_OBJECT + +public: + DolphinFileMetaDataWidget(QWidget* parent = 0); + virtual ~DolphinFileMetaDataWidget(); + + void setPreview(const QPixmap& pixmap); + QPixmap preview() const; + + void setName(const QString& name); + QString name() const; + + /** + * Sets the items for which the meta data should be shown. + * The signal metaDataRequestFinished() will be emitted, + * as soon as the meta data for the items has been received. + */ + void setItems(const KFileItemList& items); + KFileItemList items() const; + +signals: + /** + * Is emitted after the meta data has been received for the items + * set by DolphinFileMetaDataWidget::setItems(). + */ + void metaDataRequestFinished(const KFileItemList& items); + +private: + QLabel* m_preview; + QLabel* m_name; +#ifndef HAVE_BALOO + KFileMetaDataWidget* m_fileMetaDataWidget; +#else + Baloo::FileMetaDataWidget* m_fileMetaDataWidget; +#endif +}; + +#endif diff --git a/src/views/tooltips/filemetadatatooltip.cpp b/src/views/tooltips/filemetadatatooltip.cpp deleted file mode 100644 index e466ff3ed..000000000 --- a/src/views/tooltips/filemetadatatooltip.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "filemetadatatooltip.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#ifndef HAVE_BALOO -#include -#else -#include -#endif - -FileMetaDataToolTip::FileMetaDataToolTip(QWidget* parent) : - QWidget(parent), - m_preview(0), - m_name(0), - m_fileMetaDataWidget(0) -{ - // Create widget for file preview - m_preview = new QLabel(this); - m_preview->setAlignment(Qt::AlignTop); - - // 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); - - QVBoxLayout* textLayout = new QVBoxLayout(); - textLayout->addWidget(m_name); - textLayout->addWidget(new KSeparator()); - textLayout->addWidget(m_fileMetaDataWidget); - textLayout->setAlignment(m_name, Qt::AlignCenter); - textLayout->setAlignment(m_fileMetaDataWidget, Qt::AlignLeft); - // Assure that the text-layout gets top-aligned by adding a stretch. - // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does - // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget - // (see bug #241608) - textLayout->addStretch(); - - QHBoxLayout* tipLayout = new QHBoxLayout(this); - tipLayout->addWidget(m_preview); - tipLayout->addSpacing(tipLayout->margin()); - tipLayout->addLayout(textLayout); -} - -FileMetaDataToolTip::~FileMetaDataToolTip() -{ -} - -void FileMetaDataToolTip::setPreview(const QPixmap& pixmap) -{ - m_preview->setPixmap(pixmap); -} - -QPixmap FileMetaDataToolTip::preview() const -{ - if (m_preview->pixmap()) { - return *m_preview->pixmap(); - } - return QPixmap(); -} - -void FileMetaDataToolTip::setName(const QString& 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 -{ - return m_name->text(); -} - -void FileMetaDataToolTip::setItems(const KFileItemList& items) -{ - m_fileMetaDataWidget->setItems(items); -} - -KFileItemList FileMetaDataToolTip::items() const -{ - return m_fileMetaDataWidget->items(); -} - diff --git a/src/views/tooltips/filemetadatatooltip.h b/src/views/tooltips/filemetadatatooltip.h deleted file mode 100644 index 1738e386c..000000000 --- a/src/views/tooltips/filemetadatatooltip.h +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef FILEMETADATATOOLTIP_H -#define FILEMETADATATOOLTIP_H - -#include -#include "config-baloo.h" - -class KFileItemList; -class QLabel; - -#ifndef HAVE_BALOO -class KFileMetaDataWidget; -#else -namespace Baloo { - class FileMetaDataWidget; -} -#endif - -/** - * @brief Widget that shows the meta information and a preview of one - * or more files inside a KToolTipWidget. - */ -class FileMetaDataToolTip : public QWidget -{ - Q_OBJECT - -public: - FileMetaDataToolTip(QWidget* parent = 0); - virtual ~FileMetaDataToolTip(); - - void setPreview(const QPixmap& pixmap); - QPixmap preview() const; - - void setName(const QString& name); - QString name() const; - - /** - * Sets the items for which the meta data should be shown. - * The signal metaDataRequestFinished() will be emitted, - * as soon as the meta data for the items has been received. - */ - void setItems(const KFileItemList& items); - KFileItemList items() const; - -signals: - /** - * Is emitted after the meta data has been received for the items - * set by FileMetaDataToolTip::setItems(). - */ - void metaDataRequestFinished(const KFileItemList& items); - -private: - QLabel* m_preview; - QLabel* m_name; -#ifndef HAVE_BALOO - KFileMetaDataWidget* m_fileMetaDataWidget; -#else - Baloo::FileMetaDataWidget* m_fileMetaDataWidget; -#endif -}; - -#endif diff --git a/src/views/tooltips/tooltipmanager.cpp b/src/views/tooltips/tooltipmanager.cpp index d19e98c81..4a9f91359 100644 --- a/src/views/tooltips/tooltipmanager.cpp +++ b/src/views/tooltips/tooltipmanager.cpp @@ -19,7 +19,7 @@ #include "tooltipmanager.h" -#include "filemetadatatooltip.h" +#include "dolphinfilemetadatawidget.h" #include #include #include @@ -38,7 +38,7 @@ ToolTipManager::ToolTipManager(QWidget* parent) : m_showToolTipTimer(0), m_contentRetrievalTimer(0), m_transientParent(0), - m_fileMetaDataToolTip(0), + m_fileMetaDataWidget(0), m_tooltipWidget(new KToolTipWidget()), m_toolTipRequested(false), m_metaDataRequested(false), @@ -82,9 +82,9 @@ void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect, // Only start the retrieving of the content, when the mouse has been over this // item for 200 milliseconds. This prevents a lot of useless preview jobs and // meta data retrieval, when passing rapidly over a lot of items. - delete m_fileMetaDataToolTip; - m_fileMetaDataToolTip = new FileMetaDataToolTip(); - connect(m_fileMetaDataToolTip, &FileMetaDataToolTip::metaDataRequestFinished, + delete m_fileMetaDataWidget; + m_fileMetaDataWidget = new DolphinFileMetaDataWidget(); + connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::metaDataRequestFinished, this, &ToolTipManager::slotMetaDataRequestFinished); m_contentRetrievalTimer->start(); @@ -113,17 +113,17 @@ void ToolTipManager::startContentRetrieval() return; } - m_fileMetaDataToolTip->setName(m_item.text()); + m_fileMetaDataWidget->setName(m_item.text()); // Request the retrieval of meta-data. The slot // slotMetaDataRequestFinished() is invoked after the // meta-data have been received. m_metaDataRequested = true; - m_fileMetaDataToolTip->setItems(KFileItemList() << m_item); - m_fileMetaDataToolTip->adjustSize(); + m_fileMetaDataWidget->setItems(KFileItemList() << m_item); + m_fileMetaDataWidget->adjustSize(); // Request a preview of the item - m_fileMetaDataToolTip->setPreview(QPixmap()); + m_fileMetaDataWidget->setPreview(QPixmap()); KIO::PreviewJob* job = new KIO::PreviewJob(KFileItemList() << m_item, QSize(256, 256)); job->setIgnoreMaximumSize(m_item.isLocalFile()); @@ -149,7 +149,7 @@ void ToolTipManager::setPreviewPix(const KFileItem& item, if (pixmap.isNull()) { previewFailed(); } else { - m_fileMetaDataToolTip->setPreview(pixmap); + m_fileMetaDataWidget->setPreview(pixmap); if (!m_showToolTipTimer->isActive()) { showToolTip(); } @@ -163,7 +163,7 @@ void ToolTipManager::previewFailed() } const QPixmap pixmap = QIcon::fromTheme(m_item.iconName()).pixmap(128, 128); - m_fileMetaDataToolTip->setPreview(pixmap); + m_fileMetaDataWidget->setPreview(pixmap); if (!m_showToolTipTimer->isActive()) { showToolTip(); } @@ -190,7 +190,7 @@ void ToolTipManager::showToolTip() m_appliedWaitCursor = false; } - if (m_fileMetaDataToolTip->preview().isNull() || m_metaDataRequested) { + if (m_fileMetaDataWidget->preview().isNull() || m_metaDataRequested) { Q_ASSERT(!m_appliedWaitCursor); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); m_appliedWaitCursor = true; @@ -198,8 +198,8 @@ void ToolTipManager::showToolTip() } // Adjust the size to get a proper sizeHint() - m_fileMetaDataToolTip->adjustSize(); - m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataToolTip, m_transientParent); + m_fileMetaDataWidget->adjustSize(); + m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataWidget, m_transientParent); m_toolTipRequested = false; } diff --git a/src/views/tooltips/tooltipmanager.h b/src/views/tooltips/tooltipmanager.h index 58fe68763..9c504c898 100644 --- a/src/views/tooltips/tooltipmanager.h +++ b/src/views/tooltips/tooltipmanager.h @@ -25,7 +25,7 @@ #include -class FileMetaDataToolTip; +class DolphinFileMetaDataWidget; class KToolTipWidget; class QTimer; class QWindow; @@ -77,7 +77,7 @@ private: /// Transient parent of the tooltip, mandatory on Wayland. QWindow* m_transientParent; - FileMetaDataToolTip* m_fileMetaDataToolTip; + DolphinFileMetaDataWidget* m_fileMetaDataWidget; QScopedPointer m_tooltipWidget; bool m_toolTipRequested; -- cgit v1.3