diff --git a/src/filemetadataconfigwidget.cpp b/src/filemetadataconfigwidget.cpp index 97dd2b4..cb43f15 100644 --- a/src/filemetadataconfigwidget.cpp +++ b/src/filemetadataconfigwidget.cpp @@ -1,202 +1,202 @@ /***************************************************************************** * Copyright (C) 2013 by Vishesh Handa * * Copyright (C) 2009 by Peter Penz * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #include "filemetadataconfigwidget.h" #include "filemetadataprovider.h" #include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace Baloo; class FileMetaDataConfigWidget::Private { public: Private(FileMetaDataConfigWidget* parent); ~Private(); void init(); void loadMetaData(); void addItem(const QString& property); /** * Is invoked after the meta data model has finished the loading of * meta data. The meta data labels will be added to the configuration * list. */ void slotLoadingFinished(); int m_visibleDataTypes; KFileItemList m_fileItems; FileMetaDataProvider* m_provider; QListWidget* m_metaDataList; private: FileMetaDataConfigWidget* const q; }; FileMetaDataConfigWidget::Private::Private(FileMetaDataConfigWidget* parent) : m_visibleDataTypes(0), m_fileItems(), m_provider(nullptr), m_metaDataList(nullptr), q(parent) { m_metaDataList = new QListWidget(q); m_metaDataList->setSelectionMode(QAbstractItemView::NoSelection); m_metaDataList->setSortingEnabled(true); QVBoxLayout* layout = new QVBoxLayout(q); layout->addWidget(m_metaDataList); m_provider = new FileMetaDataProvider(q); m_provider->setReadOnly(true); connect(m_provider, SIGNAL(loadingFinished()), q, SLOT(slotLoadingFinished())); } FileMetaDataConfigWidget::Private::~Private() { } void FileMetaDataConfigWidget::Private::loadMetaData() { m_metaDataList->clear(); m_provider->setItems(m_fileItems); } void FileMetaDataConfigWidget::Private::addItem(const QString& key) { // Meta information provided by Baloo that is already // available from KFileItem as "fixed item" (see above) // should not be shown as second entry. static const char* const hiddenProperties[] = { "comment", // = fixed item kfileitem#comment "contentSize", // = fixed item kfileitem#size nullptr // mandatory last entry }; int i = 0; while (hiddenProperties[i] != nullptr) { if (key == QLatin1String(hiddenProperties[i])) { // the item is hidden return; } ++i; } // the item is not hidden, add it to the list KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup settings = config.group("Show"); const QString label = m_provider->label(key); QListWidgetItem* item = new QListWidgetItem(label, m_metaDataList); item->setData(Qt::UserRole, key); const bool show = settings.readEntry(key, true); item->setCheckState(show ? Qt::Checked : Qt::Unchecked); } void FileMetaDataConfigWidget::Private::slotLoadingFinished() { // Get all meta information labels that are available for // the currently shown file item and add them to the list. Q_ASSERT(m_provider != nullptr); m_metaDataList->clear(); QVariantMap data = m_provider->data(); // Always show these 3 data.remove("rating"); data.remove("tags"); data.remove("userComment"); QVariantMap::const_iterator it = data.constBegin(); while (it != data.constEnd()) { addItem(it.key()); ++it; } addItem("rating"); addItem("tags"); addItem("userComment"); } FileMetaDataConfigWidget::FileMetaDataConfigWidget(QWidget* parent) : QWidget(parent), d(new Private(this)) { } FileMetaDataConfigWidget::~FileMetaDataConfigWidget() { delete d; } void FileMetaDataConfigWidget::setItems(const KFileItemList& items) { d->m_fileItems = items; d->loadMetaData(); } KFileItemList FileMetaDataConfigWidget::items() const { return d->m_fileItems; } void FileMetaDataConfigWidget::save() { KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup showGroup = config.group("Show"); const int count = d->m_metaDataList->count(); for (int i = 0; i < count; ++i) { QListWidgetItem* item = d->m_metaDataList->item(i); const bool show = (item->checkState() == Qt::Checked); const QString key = item->data(Qt::UserRole).toString(); showGroup.writeEntry(key, show); } showGroup.sync(); } bool FileMetaDataConfigWidget::event(QEvent* event) { if (event->type() == QEvent::Polish) { qDebug() << "GOT POLISH EVENT!!!"; // loadMetaData() must be invoked asynchronously, as the list // must finish it's initialization first QMetaObject::invokeMethod(this, "loadMetaData", Qt::QueuedConnection); } return QWidget::event(event);; } QSize FileMetaDataConfigWidget::sizeHint() const { return d->m_metaDataList->sizeHint(); } #include "moc_filemetadataconfigwidget.cpp" diff --git a/src/filemetadataconfigwidget.h b/src/filemetadataconfigwidget.h index 66985a7..f2cff9a 100644 --- a/src/filemetadataconfigwidget.h +++ b/src/filemetadataconfigwidget.h @@ -1,76 +1,76 @@ /***************************************************************************** * Copyright (C) 2013 by Vishesh Handa * * Copyright (C) 2009 by Peter Penz * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #ifndef BALOO_FILEMETADATACONFIGWIDGET_H #define BALOO_FILEMETADATACONFIGWIDGET_H #include "widgets_export.h" #include -#include +#include namespace Baloo { /** * @brief Widget which allows to configure which meta data should be shown * in the FileMetadataWidget */ class BALOO_WIDGETS_EXPORT FileMetaDataConfigWidget : public QWidget { Q_OBJECT public: explicit FileMetaDataConfigWidget(QWidget* parent = nullptr); ~FileMetaDataConfigWidget() override; /** * Sets the items, for which the visibility of the meta data should * be configured. Note that the visibility of the meta data is not * bound to the items itself, the items are only used to determine * which meta data should be configurable. For example when a JPEG image * is set as item, it will be configurable which EXIF data should be * shown. If an audio file is set as item, it will be configurable * whether the artist, album name, ... should be shown. */ void setItems(const KFileItemList& items); KFileItemList items() const; /** * Saves the modified configuration. */ void save(); /** @see QWidget::sizeHint() */ QSize sizeHint() const override; protected: bool event(QEvent* event) override; private: class Private; Private* const d; Q_PRIVATE_SLOT(d, void loadMetaData()) Q_PRIVATE_SLOT(d, void slotLoadingFinished()) }; } #endif diff --git a/src/filemetadatawidget.h b/src/filemetadatawidget.h index 6b073be..e7e180e 100644 --- a/src/filemetadatawidget.h +++ b/src/filemetadatawidget.h @@ -1,108 +1,108 @@ /* Copyright (C) 2012-2013 Vishesh Handa Adapated from KFileMetadataWidget Copyright (C) 2008 by Sebastian Trueg Copyright (C) 2009-2010 by Peter Penz This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _BALOO_FILE_METADATAWIDGET_H #define _BALOO_FILE_METADATAWIDGET_H -#include -#include +#include +#include #include #include #include "widgets_export.h" namespace Baloo { /** * Modify format of date display */ enum class DateFormats { LongFormat = QLocale::LongFormat, ///< @see QLocale::LongFormat ShortFormat = QLocale::ShortFormat ///< @see QLocale::ShortFormat }; class BALOO_WIDGETS_EXPORT FileMetaDataWidget : public QWidget { Q_OBJECT Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) Q_PROPERTY(DateFormats dateFormat READ dateFormat WRITE setDateFormat) public: explicit FileMetaDataWidget(QWidget* parent = nullptr); ~FileMetaDataWidget() override; /** * 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; /** * If set to true, data such as the comment, tag or rating cannot be * changed by the user. Per default read-only is disabled. */ void setReadOnly(bool readOnly); bool isReadOnly() const; /** * Set date display format. * Per Default format is Long = @see QLocale::LongFormat */ void setDateFormat(const DateFormats format); DateFormats dateFormat() const; /** @see QWidget::sizeHint() */ QSize sizeHint() const override; Q_SIGNALS: /** * Is emitted, if a meta data represents an URL that has * been clicked by the user. */ void urlActivated(const QUrl& url); /** * Is emitted after the meta data has been received for the items * set by KFileMetaDataWidget::setItems(). * @since 4.6 */ void metaDataRequestFinished(const KFileItemList& items); private: class Private; Private* d; Q_PRIVATE_SLOT(d, void slotLoadingFinished()) Q_PRIVATE_SLOT(d, void slotLinkActivated(QString)) Q_PRIVATE_SLOT(d, void slotDataChangeStarted()) Q_PRIVATE_SLOT(d, void slotDataChangeFinished()) }; } Q_DECLARE_METATYPE(Baloo::DateFormats) #endif // _BALOO_FILE_METADATAWIDGET_H diff --git a/src/indexeddataretriever.h b/src/indexeddataretriever.h index 286ac1e..5181a52 100644 --- a/src/indexeddataretriever.h +++ b/src/indexeddataretriever.h @@ -1,52 +1,52 @@ /* * * Copyright (C) 2012 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef INDEXEDDATARETRIEVER_H #define INDEXEDDATARETRIEVER_H #include -#include -#include +#include +#include namespace Baloo { class IndexedDataRetriever : public KJob { Q_OBJECT public: explicit IndexedDataRetriever(const QString& fileUrl, QObject* parent = nullptr); ~IndexedDataRetriever() override; void start() override; QVariantMap data() const; private Q_SLOTS: void slotIndexedFile(int error); private: QString m_url; QProcess* m_process; QVariantMap m_data; }; } #endif // INDEXEDDATARETRIEVER_H diff --git a/src/kblocklayout.cpp b/src/kblocklayout.cpp index 59f6818..3fb6708 100644 --- a/src/kblocklayout.cpp +++ b/src/kblocklayout.cpp @@ -1,272 +1,272 @@ /* * This file is part of the Baloo KDE project. * Copyright (C) 2006-2007 Sebastian Trueg * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ /* KBlockLayout is based on the FlowLayout example from QT4. Copyright (C) 2004-2006 Trolltech ASA. All rights reserved. Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Contact: Nokia Corporation (qt-info@nokia.com) */ #include "kblocklayout.h" -#include -#include -#include +#include +#include +#include class KBlockLayout::Private { public: Private() : alignment(Qt::AlignLeft|Qt::AlignTop) { } int smartSpacing(QStyle::PixelMetric pm) const { QObject *parent = q->parent(); if (!parent) { return -1; } else if (parent->isWidgetType()) { QWidget *pw = static_cast(parent); return pw->style()->pixelMetric(pm, nullptr, pw); } else { return static_cast(parent)->spacing(); } } QList itemList; int m_hSpace; int m_vSpace; Qt::Alignment alignment; KBlockLayout* q; }; KBlockLayout::KBlockLayout( QWidget* parent, int margin, int hSpacing, int vSpacing ) : QLayout(parent), d( new Private() ) { d->q = this; setMargin(margin); setSpacing(hSpacing, vSpacing); } KBlockLayout::KBlockLayout( int margin, int hSpacing, int vSpacing ) : d( new Private() ) { d->q = this; setMargin(margin); setSpacing(hSpacing, vSpacing); } KBlockLayout::~KBlockLayout() { QLayoutItem* item; while ((item = takeAt(0))) delete item; delete d; } void KBlockLayout::setAlignment( Qt::Alignment a ) { d->alignment = a; } Qt::Alignment KBlockLayout::alignment() const { return d->alignment; } int KBlockLayout::horizontalSpacing() const { if (d->m_hSpace >= 0) { return d->m_hSpace; } else { return d->smartSpacing(QStyle::PM_LayoutHorizontalSpacing); } } int KBlockLayout::verticalSpacing() const { if (d->m_vSpace >= 0) { return d->m_vSpace; } else { return d->smartSpacing(QStyle::PM_LayoutVerticalSpacing); } } void KBlockLayout::setSpacing( int h, int v ) { d->m_hSpace = h; d->m_vSpace = v; QLayout::setSpacing( h ); } void KBlockLayout::addItem( QLayoutItem* item ) { d->itemList.append(item); } int KBlockLayout::count() const { return d->itemList.size(); } QLayoutItem *KBlockLayout::itemAt( int index ) const { return d->itemList.value(index); } QLayoutItem *KBlockLayout::takeAt( int index ) { if (index >= 0 && index < d->itemList.size()) return d->itemList.takeAt(index); else return nullptr; } Qt::Orientations KBlockLayout::expandingDirections() const { return nullptr; } bool KBlockLayout::hasHeightForWidth() const { return true; } int KBlockLayout::heightForWidth( int width ) const { int height = doLayout(QRect(0, 0, width, 0), true); return height; } void KBlockLayout::setGeometry( const QRect& rect ) { QLayout::setGeometry(rect); doLayout(rect, false); } QSize KBlockLayout::sizeHint() const { // TODO: try to get the items into a square QSize size; QLayoutItem *item; foreach (item, d->itemList) { const QSize itemSize = item->minimumSize(); size.rwidth() += itemSize.width(); if (itemSize.height() > size.height()) { size.setHeight(itemSize.height()); } } size.rwidth() += horizontalSpacing() * d->itemList.count(); size += QSize(2*margin(), 2*margin()); return size; } QSize KBlockLayout::minimumSize() const { QSize size; QLayoutItem *item; foreach (item, d->itemList) { size = size.expandedTo(item->minimumSize()); } size += QSize(2*margin(), 2*margin()); return size; } struct Row { Row( const QList& i, int h, int w ) : items(i), height(h), width(w) { } QList items; int height; int width; }; int KBlockLayout::doLayout( const QRect& rect, bool testOnly ) const { int x = rect.x(); int y = rect.y(); int lineHeight = 0; // 1. calculate lines QList rows; QList rowItems; for( int i = 0; i < d->itemList.count(); ++i ) { QLayoutItem* item = d->itemList[i]; int nextX = x + item->sizeHint().width() + horizontalSpacing(); if (nextX - horizontalSpacing() > rect.right() && lineHeight > 0) { rows.append( Row( rowItems, lineHeight, x - horizontalSpacing() ) ); rowItems.clear(); x = rect.x(); y = y + lineHeight + verticalSpacing(); nextX = x + item->sizeHint().width() + horizontalSpacing(); lineHeight = 0; } rowItems.append( item ); x = nextX; lineHeight = qMax(lineHeight, item->sizeHint().height()); } // append the last row rows.append( Row( rowItems, lineHeight, x-horizontalSpacing() ) ); int finalHeight = y + lineHeight - rect.y(); if( testOnly ) return finalHeight; // 2. place the items y = rect.y(); foreach( const Row &row, rows ) { x = rect.x(); if( alignment() & Qt::AlignRight ) x += (rect.width() - row.width); else if( alignment() & Qt::AlignHCenter ) x += (rect.width() - row.width)/2; foreach( QLayoutItem* item, row.items ) { int yy = y; if( alignment() & Qt::AlignBottom ) yy += (row.height - item->sizeHint().height()); else if( alignment() & Qt::AlignVCenter ) yy += (row.height - item->sizeHint().height())/2; item->setGeometry(QRect(QPoint(x, yy), item->sizeHint())); x += item->sizeHint().width() + horizontalSpacing(); if( alignment() & Qt::AlignJustify ) x += (rect.width() - row.width)/qMax(row.items.count()-1,1); } y = y + row.height + verticalSpacing(); } return finalHeight; } diff --git a/src/kblocklayout.h b/src/kblocklayout.h index cf9b262..5592efb 100644 --- a/src/kblocklayout.h +++ b/src/kblocklayout.h @@ -1,76 +1,76 @@ /* * This file is part of the Baloo KDE project. * Copyright (C) 2006-2007 Sebastian Trueg * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ /* KBlockLayout is based on the FlowLayout example from QT4. Copyright (C) 2004-2006 Trolltech ASA. All rights reserved. */ #ifndef KBLOCKLAYOUT_H #define KBLOCKLAYOUT_H -#include -#include +#include +#include /** * The KBlockLayout arranges widget in rows and columns like a text * editor does. */ class KBlockLayout : public QLayout { public: explicit KBlockLayout( QWidget *parent, int margin = 0, int hSpacing = -1, int vSpacing = -1 ); explicit KBlockLayout( int margin = 0, int hSpacing = -1, int vSpacing = -1 ); ~KBlockLayout() override; /** * Set the alignment to use. It can be a combination of a horizontal and * a vertical alignment flag. The vertical flag is used to arrange widgets * that do not fill the complete height of a row. * * The default alignment is Qt::AlignLeft|Qt::AlignTop */ void setAlignment( Qt::Alignment ); Qt::Alignment alignment() const; int horizontalSpacing() const; int verticalSpacing() const; void setSpacing( int h, int v ); void addItem( QLayoutItem* item ) override; Qt::Orientations expandingDirections() const override; bool hasHeightForWidth() const override; int heightForWidth(int) const override; int count() const override; QLayoutItem* itemAt( int index ) const override; QSize minimumSize() const override; void setGeometry( const QRect& rect ) override; QSize sizeHint() const override; QLayoutItem* takeAt( int index ) override; private: int doLayout( const QRect& rect, bool testOnly ) const; class Private; Private* const d; }; #endif diff --git a/src/kcommentwidget.cpp b/src/kcommentwidget.cpp index ff8d58a..6d03f8b 100644 --- a/src/kcommentwidget.cpp +++ b/src/kcommentwidget.cpp @@ -1,142 +1,142 @@ /***************************************************************************** * Copyright (C) 2008 by Sebastian Trueg * * Copyright (C) 2009 by Peter Penz * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #include "kcommentwidget_p.h" #include "keditcommentdialog.h" #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include KCommentWidget::KCommentWidget(QWidget* parent) : QWidget(parent), m_readOnly(false), m_label(nullptr), m_sizeHintHelper(nullptr), m_comment() { m_label = new QLabel(this); m_label->setWordWrap(true); m_label->setAlignment(Qt::AlignTop); connect(m_label, &QLabel::linkActivated, this, &KCommentWidget::slotLinkActivated); m_sizeHintHelper = new QLabel(this); m_sizeHintHelper->hide(); QVBoxLayout* layout = new QVBoxLayout(this); layout->setMargin(0); layout->addWidget(m_label); setText(m_comment); } KCommentWidget::~KCommentWidget() { } void KCommentWidget::setText(const QString& comment) { QString text; if (comment.isEmpty()) { if (m_readOnly) { text = "-"; } else { text = "" + i18nc("@label", "Add...") + ""; } } else { if (m_readOnly) { text = QString(comment).toHtmlEscaped(); } else { text = "

" + QString(comment).toHtmlEscaped() + " " + i18nc("@label", "Change...") + "

"; } } m_label->setText(text); m_sizeHintHelper->setText(text); m_comment = comment; } QString KCommentWidget::text() const { return m_comment; } void KCommentWidget::setReadOnly(bool readOnly) { m_readOnly = readOnly; setText(m_comment); } bool KCommentWidget::isReadOnly() const { return m_readOnly; } QSize KCommentWidget::sizeHint() const { // Per default QLabel tries to provide a square size hint. This // does not work well for complex layouts that rely on a heightForWidth() // functionality with unclipped content. Use an unwrapped text label // as layout helper instead, that returns the preferred size of // the rich-text line. return m_sizeHintHelper->sizeHint(); } bool KCommentWidget::event(QEvent* event) { if (event->type() == QEvent::Polish) { m_label->setForegroundRole(foregroundRole()); } return QWidget::event(event); } void KCommentWidget::slotLinkActivated(const QString& link) { const QString caption = (link == "changeComment") ? i18nc("@title:window", "Change Comment") : i18nc("@title:window", "Add Comment"); QPointer dialog = new KEditCommentDialog(this, m_comment, caption); KConfigGroup dialogConfig(KSharedConfig::openConfig(), "Baloo KEditCommentDialog"); KWindowConfig::restoreWindowSize(dialog->windowHandle(), dialogConfig); if (dialog->exec() == QDialog::Accepted) { const QString oldText = m_comment; if (dialog != nullptr) { setText(dialog->getCommentText()); } if (oldText != m_comment) { emit commentChanged(m_comment); } } if (dialog != nullptr) { KWindowConfig::saveWindowSize(dialog->windowHandle(), dialogConfig); delete dialog; dialog = nullptr; } } diff --git a/src/kcommentwidget_p.h b/src/kcommentwidget_p.h index 7986215..2b85649 100644 --- a/src/kcommentwidget_p.h +++ b/src/kcommentwidget_p.h @@ -1,69 +1,69 @@ /***************************************************************************** * Copyright (C) 2008 by Sebastian Trueg * * Copyright (C) 2009 by Peter Penz * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #ifndef KCOMMENT_WIDGET #define KCOMMENT_WIDGET -#include -#include +#include +#include class QLabel; /** * @brief Allows to edit and show a comment as part of KMetaDataWidget. */ class KCommentWidget : public QWidget { Q_OBJECT public: explicit KCommentWidget(QWidget* parent = nullptr); ~KCommentWidget() override; void setText(const QString& comment); QString text() const; /** * If set to true, the comment cannot be changed by the user. * Per default read-only is disabled. */ // TODO: provide common interface class for metadatawidgets void setReadOnly(bool readOnly); bool isReadOnly() const; QSize sizeHint() const override; Q_SIGNALS: void commentChanged(const QString& comment); protected: bool event(QEvent* event) override; private Q_SLOTS: void slotLinkActivated(const QString& link); private: bool m_readOnly; QLabel* m_label; QLabel* m_sizeHintHelper; // see comment in KCommentWidget::sizeHint() QString m_comment; }; #endif diff --git a/src/keditcommentdialog.cpp b/src/keditcommentdialog.cpp index dfef626..8adbb7e 100644 --- a/src/keditcommentdialog.cpp +++ b/src/keditcommentdialog.cpp @@ -1,61 +1,61 @@ /* This file is part of the KDE libraries Copyright (C) 2014 Felix Eisele This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "keditcommentdialog.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include KEditCommentDialog::KEditCommentDialog(QWidget* parent, const QString& commentText, const QString& captionText) : QDialog(parent) { setWindowTitle(captionText); QVBoxLayout* layout = new QVBoxLayout; setLayout(layout); m_editor = new QTextEdit(this); m_editor->setText(commentText); layout->addWidget(m_editor); QDialogButtonBox* buttonBox = new QDialogButtonBox(this); layout->addWidget(buttonBox); buttonBox->addButton(i18n("Save"), QDialogButtonBox::AcceptRole); buttonBox->addButton(QDialogButtonBox::Cancel); connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); resize(sizeHint()); } KEditCommentDialog::~KEditCommentDialog() { } QString KEditCommentDialog::getCommentText() const { return m_editor->toPlainText(); } diff --git a/src/keditcommentdialog.h b/src/keditcommentdialog.h index 8ff959a..2874b8f 100644 --- a/src/keditcommentdialog.h +++ b/src/keditcommentdialog.h @@ -1,43 +1,43 @@ /* This file is part of the KDE libraries Copyright (C) 2014 Felix Eisele This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KEDITCOMMENTDIALOG_H #define KEDITCOMMENTDIALOG_H -#include +#include class QWidget; class QTextEdit; class KEditCommentDialog : public QDialog { Q_OBJECT public: KEditCommentDialog(QWidget *parent, const QString &commentText, const QString &captionText); ~KEditCommentDialog() override; QString getCommentText() const; private: QTextEdit *m_editor; }; #endif diff --git a/src/kedittagsdialog.cpp b/src/kedittagsdialog.cpp index d252526..8a5c05f 100644 --- a/src/kedittagsdialog.cpp +++ b/src/kedittagsdialog.cpp @@ -1,228 +1,228 @@ /***************************************************************************** * Copyright (C) 2009 by Peter Penz * * Copyright (C) 2014 by Vishesh Handa * * Copyright (C) 2017 by James D. Smith -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include KEditTagsDialog::KEditTagsDialog(const QStringList& tags, QWidget *parent) : QDialog(parent), m_tags(tags), m_tagTree(nullptr), m_newTagEdit(nullptr) { const QString captionText = (tags.count() > 0) ? i18nc("@title:window", "Change Tags") : i18nc("@title:window", "Add Tags"); setWindowTitle(captionText); QDialogButtonBox* buttonBox = new QDialogButtonBox(this); buttonBox->addButton(i18n("Save"), QDialogButtonBox::AcceptRole); buttonBox->addButton(QDialogButtonBox::Cancel); connect(buttonBox, &QDialogButtonBox::accepted, this, &KEditTagsDialog::slotAcceptedButtonClicked); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QVBoxLayout* topLayout = new QVBoxLayout; setLayout(topLayout); QLabel* label = new QLabel(i18nc("@label:textbox", "Configure which tags should " "be applied."), this); m_tagTree = new QTreeWidget(); m_tagTree->setSortingEnabled(true); m_tagTree->setSelectionMode(QAbstractItemView::NoSelection); m_tagTree->setHeaderHidden(true); QLabel* newTagLabel = new QLabel(i18nc("@label", "Create new tag:")); m_newTagEdit = new QLineEdit(this); m_newTagEdit->setClearButtonEnabled(true); m_newTagEdit->setFocus(); connect(m_newTagEdit, &QLineEdit::textEdited, this, &KEditTagsDialog::slotTextEdited); connect(m_tagTree, &QTreeWidget::itemActivated, this, &KEditTagsDialog::slotItemActivated); QHBoxLayout* newTagLayout = new QHBoxLayout(); newTagLayout->addWidget(newTagLabel); newTagLayout->addWidget(m_newTagEdit, 1); topLayout->addWidget(label); topLayout->addWidget(m_tagTree); topLayout->addLayout(newTagLayout); topLayout->addWidget(buttonBox); resize(sizeHint()); Baloo::TagListJob* job = new Baloo::TagListJob(); connect(job, &Baloo::TagListJob::finished, [this] (KJob* job) { Baloo::TagListJob* tjob = static_cast(job); m_allTags = tjob->tags(); loadTagWidget(); }); job->start(); } KEditTagsDialog::~KEditTagsDialog() { } QStringList KEditTagsDialog::tags() const { return m_tags; } void KEditTagsDialog::slotAcceptedButtonClicked() { m_tags.clear(); for (const QTreeWidgetItem* item : m_allTagTreeItems.values()) { if (item->checkState(0) == Qt::Checked) { m_tags << qvariant_cast(item->data(0, Qt::UserRole)); } } accept(); } void KEditTagsDialog::slotItemActivated(const QTreeWidgetItem* item, int column) { Q_UNUSED(column) const QString tag = qvariant_cast(item->data(0, Qt::UserRole)); m_newTagEdit->setText(tag + QLatin1Char('/')); m_newTagEdit->setFocus(); } void KEditTagsDialog::slotTextEdited(const QString& text) { // Remove unnecessary spaces from a new tag is // mandatory, as the user cannot see the difference // between a tag "Test" and "Test ". QString tagText = text.simplified(); while (tagText.endsWith("//")) { tagText.chop(1); m_newTagEdit->setText(tagText); return; } // Remove all tree items related to the previous new tag const QStringList splitTag = m_newTag.split(QLatin1Char('/'), QString::SkipEmptyParts); for (int i = splitTag.size() - 1; i >= 0 && i < splitTag.size(); --i) { QString itemTag = m_newTag.section(QLatin1Char('/'), 0, i, QString::SectionSkipEmpty); QTreeWidgetItem* item = m_allTagTreeItems.value(itemTag); if (!m_allTags.contains(m_newTag) && (item->childCount() == 0)) { if (i != 0) { QTreeWidgetItem* parentItem = item->parent(); parentItem->removeChild(item); } else { const int row = m_tagTree->indexOfTopLevelItem(item); m_tagTree->takeTopLevelItem(row); } m_allTagTreeItems.remove(itemTag); } if (!m_tags.contains(itemTag)) { item->setCheckState(0, Qt::Unchecked); } item->setExpanded(false); } if (!tagText.isEmpty()) { m_newTag = tagText; modifyTagWidget(tagText); m_tagTree->sortItems(0, Qt::SortOrder::AscendingOrder); } else { m_newTag.clear(); m_allTagTreeItems.clear(); m_tagTree->clear(); loadTagWidget(); } } void KEditTagsDialog::loadTagWidget() { for (const QString &tag : m_tags) { modifyTagWidget(tag); } for (const QString &tag : m_allTags) { modifyTagWidget(tag); } m_tagTree->sortItems(0, Qt::SortOrder::AscendingOrder); } void KEditTagsDialog::modifyTagWidget(const QString &tag) { const QStringList splitTag = tag.split(QLatin1Char('/'), QString::SkipEmptyParts); for (int i = 0; i < splitTag.size(); ++i) { QTreeWidgetItem* item = new QTreeWidgetItem(); QString itemTag = tag.section(QLatin1Char('/'), 0, i, QString::SectionSkipEmpty); if (!m_allTagTreeItems.contains(itemTag)) { item->setText(0, splitTag.at(i)); item->setIcon(0, QIcon::fromTheme(QLatin1String("tag"))); item->setData(0, Qt::UserRole, itemTag); m_allTagTreeItems.insert(itemTag, item); QString parentTag = tag.section(QLatin1Char('/'), 0, (i - 1), QString::SectionSkipEmpty); QTreeWidgetItem* parentItem = m_allTagTreeItems.value(parentTag); if (i != 0) { parentItem->addChild(item); } else { m_tagTree->addTopLevelItem(item); } } else { item = m_allTagTreeItems.value(itemTag); } if (!m_allTags.contains(tag)) { m_tagTree->scrollToItem(item, QAbstractItemView::PositionAtCenter); } if (((item->childCount() != 0) && m_tags.contains(tag)) || (m_newTag == tag)) { item->setExpanded(true); } else if (item->parent() && m_tags.contains(tag)) { item->parent()->setExpanded(true); } const bool check = (m_tags.contains(itemTag) || (m_newTag == itemTag)); item->setCheckState(0, check ? Qt::Checked : Qt::Unchecked); } } diff --git a/src/kedittagsdialog_p.h b/src/kedittagsdialog_p.h index b2f6a61..30c0bf1 100644 --- a/src/kedittagsdialog_p.h +++ b/src/kedittagsdialog_p.h @@ -1,71 +1,71 @@ /* * Copyright (C) 2009 by Peter Penz * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KEDIT_TAGS_DIALOG_H #define KEDIT_TAGS_DIALOG_H -#include +#include class QLineEdit; class KJob; class QTreeWidget; class QTreeWidgetItem; class QPushButton; class QTimer; /** * @brief Dialog to edit a list of Baloo tags. * * It is possible for the user to add existing tags, * create new tags or to remove tags. * * @see KMetaDataConfigurationDialog */ class KEditTagsDialog : public QDialog { Q_OBJECT public: explicit KEditTagsDialog(const QStringList& tags, QWidget* parent = nullptr); ~KEditTagsDialog() override; QStringList tags() const; private Q_SLOTS: void slotTextEdited(const QString& text); void slotAcceptedButtonClicked(); void slotItemActivated(const QTreeWidgetItem* item, int column); private: void loadTagWidget(); void modifyTagWidget(const QString& tag); private: QHash m_allTagTreeItems; QStringList m_tags; QStringList m_allTags; QString m_newTag; QTreeWidget* m_tagTree; QLineEdit* m_newTagEdit; }; #endif diff --git a/src/metadatafilter.h b/src/metadatafilter.h index c495cb8..dd6e694 100644 --- a/src/metadatafilter.h +++ b/src/metadatafilter.h @@ -1,52 +1,52 @@ /* Copyright (C) 2012 Vishesh Handa This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _BALOO_METADATAFILTER_H #define _BALOO_METADATAFILTER_H -#include +#include namespace Baloo { class Variant; class MetadataFilter : public QObject { public: explicit MetadataFilter(QObject* parent = nullptr); ~MetadataFilter() override; /** * Takes all the data by the provider and filters the data * according to 'baloofileinformationrc' config * This acts as a filter and a data aggregator */ QVariantMap filter(const QVariantMap& data); private: /** * Initializes the configuration file "kmetainformationrc" * with proper default settings for the first start in * an uninitialized environment. */ void initMetaInformationSettings(); }; } #endif // _BALOO_METADATAFILTER_H diff --git a/src/tagcheckbox.cpp b/src/tagcheckbox.cpp index b1d9b84..670577b 100644 --- a/src/tagcheckbox.cpp +++ b/src/tagcheckbox.cpp @@ -1,111 +1,111 @@ /* This file is part of the Baloo KDE project. Copyright (C) 2013 Vishesh Handa Copyright (C) 2010 Sebastian Trueg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "tagcheckbox.h" #include "tagwidget.h" #include "tagwidget_p.h" -#include -#include -#include +#include +#include +#include using namespace Baloo; TagCheckBox::TagCheckBox(const QString& tag, QWidget* parent) : QWidget( parent ), m_label(nullptr), m_tag(tag), m_urlHover(false) { QHBoxLayout* layout = new QHBoxLayout(this); layout->setMargin(0); m_label = new QLabel(tag.split("/", QString::SkipEmptyParts).last(), this); m_label->setToolTip(tag); m_label->setMouseTracking(true); m_label->setTextFormat(Qt::PlainText); m_label->setForegroundRole(parent->foregroundRole()); m_child = m_label; m_child->installEventFilter( this ); m_child->setMouseTracking(true); layout->addWidget( m_child ); } TagCheckBox::~TagCheckBox() { } void TagCheckBox::leaveEvent( QEvent* event ) { QWidget::leaveEvent( event ); enableUrlHover( false ); } bool TagCheckBox::eventFilter( QObject* watched, QEvent* event ) { if( watched == m_child ) { switch( event->type() ) { case QEvent::MouseMove: { QMouseEvent* me = static_cast(event); enableUrlHover( tagRect().contains(me->pos()) ); break; } case QEvent::MouseButtonRelease: { QMouseEvent* me = static_cast(event); if (me->button() == Qt::LeftButton && tagRect().contains(me->pos())) { emit tagClicked( m_tag ); return true; } break; } default: // do nothing break; } } return QWidget::eventFilter( watched, event ); } QRect TagCheckBox::tagRect() const { return QRect(QPoint(0, 0), m_label->size()); } void TagCheckBox::enableUrlHover( bool enable ) { if( m_urlHover != enable ) { m_urlHover = enable; QFont f = font(); if(enable) f.setUnderline(true); m_child->setFont(f); m_child->setCursor( enable ? Qt::PointingHandCursor : Qt::ArrowCursor ); } } diff --git a/src/tagcheckbox.h b/src/tagcheckbox.h index 825bae1..b13c11a 100644 --- a/src/tagcheckbox.h +++ b/src/tagcheckbox.h @@ -1,64 +1,64 @@ /* This file is part of the Baloo KDE project. Copyright (C) 2010 Sebastian Trueg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef _BALOO_TAG_CHECKBOX_H_ #define _BALOO_TAG_CHECKBOX_H_ -#include +#include #include "tagwidget_p.h" class QMouseEvent; class QLabel; namespace Baloo { class TagCheckBox : public QWidget { Q_OBJECT public: explicit TagCheckBox(const QString& tag, QWidget* parent = nullptr); ~TagCheckBox() override; QString tag() const { return m_tag; } Q_SIGNALS: void tagClicked(const QString& tag); protected: void leaveEvent(QEvent* event ) override; bool eventFilter(QObject* watched, QEvent* event) override; private: QRect tagRect() const; void enableUrlHover( bool enabled ); // two modes: checkbox and simple label QLabel* m_label; QWidget* m_child; QString m_tag; bool m_urlHover; }; } #endif diff --git a/src/tagwidget.cpp b/src/tagwidget.cpp index 53a8bad..ba49905 100644 --- a/src/tagwidget.cpp +++ b/src/tagwidget.cpp @@ -1,190 +1,190 @@ /* * This file is part of the Baloo KDE project. * Copyright (C) 2006-2010 Sebastian Trueg * Copyright (C) 2011-2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "tagwidget.h" #include "tagwidget_p.h" #include "kblocklayout.h" #include "kedittagsdialog_p.h" #include "tagcheckbox.h" #include #include -#include -#include -#include +#include +#include +#include using namespace Baloo; void TagWidgetPrivate::init( TagWidget* parent ) { q = parent; m_readOnly = false; m_showAllLinkLabel = nullptr; m_editTagsDialog = nullptr; QGridLayout* mainLayout = new QGridLayout( q ); mainLayout->setMargin(0); //TODO spacingHint should be declared. Old code m_flowLayout = new KBlockLayout( 0, KDialog::spacingHint()*3 ); m_flowLayout = new KBlockLayout( 0 ); mainLayout->addLayout( m_flowLayout, 0, 0, 1, 2 ); mainLayout->setColumnStretch( 0, 1 ); } void TagWidgetPrivate::rebuild() { buildTagHash( q->selectedTags() ); } void TagWidgetPrivate::buildTagHash(const QStringList& tags) { qDeleteAll(m_checkBoxHash); m_checkBoxHash.clear(); foreach (const QString& tag, tags) { getTagCheckBox(tag); } delete m_showAllLinkLabel; m_showAllLinkLabel = nullptr; if (m_readOnly && !tags.isEmpty()) { return; } m_showAllLinkLabel = new QLabel( q ); m_flowLayout->addWidget( m_showAllLinkLabel ); if (m_readOnly) { m_showAllLinkLabel->setText("-"); } else { QFont f(q->font()); f.setUnderline(true); m_showAllLinkLabel->setFont(f); m_showAllLinkLabel->setText( QLatin1String("") + ( m_checkBoxHash.isEmpty() ? i18nc("@label", "Add...") : i18nc("@label", "Change...") ) + QLatin1String("") ); q->connect( m_showAllLinkLabel, SIGNAL(linkActivated(QString)), SLOT(slotShowAll()) ); } } TagCheckBox* TagWidgetPrivate::getTagCheckBox(const QString& tag) { QMap::iterator it = m_checkBoxHash.find(tag); if( it == m_checkBoxHash.end() ) { //kDebug() << "Creating checkbox for" << tag.genericLabel(); TagCheckBox* checkBox = new TagCheckBox(tag, q); q->connect( checkBox, SIGNAL(tagClicked(QString)), SIGNAL(tagClicked(QString)) ); m_checkBoxHash.insert( tag, checkBox ); m_flowLayout->addWidget( checkBox ); return checkBox; } else { return it.value(); } } void TagWidgetPrivate::selectTags(const QStringList& tags) { buildTagHash( tags ); } TagWidget::TagWidget( QWidget* parent ) : QWidget( parent ), d( new TagWidgetPrivate() ) { setForegroundRole(parent->foregroundRole()); d->init(this); } TagWidget::~TagWidget() { delete d; } QStringList TagWidget::selectedTags() const { QStringList tags; QMapIterator it(d->m_checkBoxHash); while( it.hasNext() ) { tags << it.next().key(); } return tags; } Qt::Alignment TagWidget::alignment() const { return d->m_flowLayout->alignment(); } bool TagWidget::readOnly() const { return d->m_readOnly; } void TagWidget::setSelectedTags(const QStringList& tags) { d->selectTags(tags); } void TagWidget::setAlignment( Qt::Alignment alignment ) { d->m_flowLayout->setAlignment( alignment ); } void TagWidget::setReadyOnly(bool readOnly) { d->m_readOnly = readOnly; d->rebuild(); } void TagWidget::slotTagUpdateDone() { setEnabled( true ); } void TagWidget::slotShowAll() { d->m_editTagsDialog = new KEditTagsDialog( selectedTags(), this ); d->m_editTagsDialog->setWindowModality( Qt::ApplicationModal ); connect( d->m_editTagsDialog, SIGNAL(finished(int)), this, SLOT(slotKEditTagDialogFinished(int)) ); d->m_editTagsDialog->open(); } void TagWidget::slotKEditTagDialogFinished(int result) { if( result == QDialog::Accepted ) { setSelectedTags( d->m_editTagsDialog->tags() ); emit selectionChanged( selectedTags() ); } d->m_editTagsDialog->deleteLater(); d->m_editTagsDialog = nullptr; } diff --git a/src/tagwidget.h b/src/tagwidget.h index 8ac7d70..d066f5a 100644 --- a/src/tagwidget.h +++ b/src/tagwidget.h @@ -1,125 +1,125 @@ /* * This file is part of the Baloo KDE project. * Copyright (C) 2006-2010 Sebastian Trueg * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef _BALOO_TAG_WIDGET_H_ #define _BALOO_TAG_WIDGET_H_ #include "widgets_export.h" -#include +#include namespace Baloo { class TagWidgetPrivate; /** * \class TagWidget tagwidget.h * * \brief Allows to change a selection of tags. * * TagWidget provides a simple GUI interface to assign tags. * * \author Sebastian Trueg */ class BALOO_WIDGETS_EXPORT TagWidget : public QWidget { Q_OBJECT public: /** * Constructor */ explicit TagWidget(QWidget* parent = nullptr); /** * Destructor */ ~TagWidget() override; /** * The list of selected tags. * * \return The list of all tags that are currently selected. In case * resources to be tagged have been selected this list matches the * tags assigned to the resources. * * \since 4.5 */ QStringList selectedTags() const; /** * The alignment of the tags in the widget. * * \since 4.5 */ Qt::Alignment alignment() const; /** * If the widget is read only */ bool readOnly() const; Q_SIGNALS: /** * This signal is emitted whenever a tag is clicked. */ void tagClicked(const QString&); /** * Emitted whenever the selection of tags changes. * * \since 4.5 */ void selectionChanged(const QStringList& tags); public Q_SLOTS: /** * Set the list of selected tags. In case resources have been * set via setTaggedResource() or setTaggedResources() their * list of tags is changed automatically. * * \since 4.5 */ void setSelectedTags(const QStringList& tags); /** * Set the alignment to use. Only horizontal alignment flags make a * difference. * * \since 4.5 */ void setAlignment( Qt::Alignment alignment ); /** * Set the TagWidget as read only */ void setReadyOnly(bool readOnly = true); private Q_SLOTS: void slotShowAll(); void slotTagUpdateDone(); void slotKEditTagDialogFinished( int result ); private: TagWidgetPrivate* const d; }; } #endif diff --git a/src/tagwidget_p.h b/src/tagwidget_p.h index ea28163..2eb5daf 100644 --- a/src/tagwidget_p.h +++ b/src/tagwidget_p.h @@ -1,62 +1,62 @@ /* * This file is part of the Baloo KDE project. * Copyright (C) 2006-2010 Sebastian Trueg * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef _BALOO_TAG_WIDGET_P_H_ #define _BALOO_TAG_WIDGET_P_H_ #include "tagwidget.h" -#include -#include +#include +#include class QLabel; class KBlockLayout; class KEditTagsDialog; namespace Baloo { class TagCheckBox; class TagWidgetPrivate { public: void init( TagWidget* parent ); void rebuild(); void buildTagHash(const QStringList& tags); /// lookup (and if necessary create) checkbox for tag TagCheckBox* getTagCheckBox(const QString& tag); /// check the corresponding checkboxes and even /// add missing checkboxes void selectTags(const QStringList& tags); bool m_readOnly; QMap m_checkBoxHash; QLabel* m_showAllLinkLabel; KBlockLayout* m_flowLayout; TagWidget* q; KEditTagsDialog* m_editTagsDialog; }; } #endif diff --git a/src/widgetfactory.cpp b/src/widgetfactory.cpp index c8330ca..63938f0 100644 --- a/src/widgetfactory.cpp +++ b/src/widgetfactory.cpp @@ -1,341 +1,341 @@ /* Copyright (C) 2012-2014 Vishesh Handa Code largely copied/adapted from KFileMetadataProvider Copyright (C) 2010 by Peter Penz This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "widgetfactory.h" #include "tagwidget.h" #include "kcommentwidget_p.h" #include "KRatingWidget" #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include namespace { static QString plainText(const QString& richText) { QString plainText; plainText.reserve(richText.length()); bool skip = false; for (int i = 0; i < richText.length(); ++i) { const QChar c = richText.at(i); if (c == QLatin1Char('<')) { skip = true; } else if (c == QLatin1Char('>')) { skip = false; } else if (!skip) { plainText.append(c); } } return plainText; } } using namespace Baloo; WidgetFactory::WidgetFactory(QObject* parent) : QObject(parent) , m_readOnly( false ) , m_noLinks( false ) , m_dateFormat(QLocale::LongFormat) { } WidgetFactory::~WidgetFactory() { } // // Widget Creation // static QString toString(const QVariant& value) { switch (value.type()) { case QVariant::Int: return QLocale().toString(value.toInt()); case QVariant::Double: return QLocale().toString(value.toDouble()); case QVariant::List: { QStringList list; for (const QVariant& var : value.toList()) { list << toString(var); } return list.join(", "); } default: return value.toString(); } } QWidget* WidgetFactory::createWidget(const QString& prop, const QVariant& value, QWidget* parent) { QWidget* widget = nullptr; if (prop == QLatin1String("rating")) { widget = createRatingWidget( value.toInt(), parent ); } else if (prop == QLatin1String("userComment")) { widget = createCommentWidget( value.toString(), parent ); } else if (prop == QLatin1String("tags")) { QStringList tags = value.toStringList(); QCollator coll; coll.setNumericMode(true); std::sort(tags.begin(), tags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); widget = createTagWidget( tags, parent ); } else { KFormat form; // vHanda: FIXME: Add links! Take m_noLinks into consideration QString valueString; if (prop == QLatin1String("duration")) { valueString = form.formatDuration(value.toInt() * 1000); } else if (prop == QLatin1String("bitRate")) { valueString = i18nc("@label bitrate (per second)", "%1/s", form.formatByteSize(value.toInt(), 0, KFormat::MetricBinaryDialect)); } else if (prop == QLatin1String("sampleRate")) { valueString = i18nc("@label samplerate in kilohertz", "%1 kHz", QLocale().toString(value.toDouble() / 1000)); } else if (prop == QLatin1String("releaseYear")) { valueString = value.toString(); } else if (prop == QLatin1String("originUrl")) { if (m_noLinks) { valueString = value.toString(); } else { valueString = QStringLiteral("%1").arg(value.toString()); } } else { // Check if Date/DateTime QDateTime dt = QDateTime::fromString(value.toString(), Qt::ISODate); if (dt.isValid()) { QTime time = dt.time(); if (!time.hour() && !time.minute() && !time.second()){ valueString = form.formatRelativeDate(dt.date(), m_dateFormat); } else { valueString = form.formatRelativeDateTime(dt, m_dateFormat); } } else { valueString = toString(value); } } widget = createValueWidget(valueString, parent); } widget->setForegroundRole(parent->foregroundRole()); widget->setFont(parent->font()); widget->setObjectName(prop); return widget; } QWidget* WidgetFactory::createTagWidget(const QStringList& tags, QWidget* parent) { TagWidget* tagWidget = new TagWidget(parent); tagWidget->setReadyOnly(m_readOnly); tagWidget->setSelectedTags(tags); connect(tagWidget, &TagWidget::selectionChanged, this, &WidgetFactory::slotTagsChanged); connect(tagWidget, &TagWidget::tagClicked, this, &WidgetFactory::slotTagClicked); m_tagWidget = tagWidget; m_prevTags = tags; return tagWidget; } QWidget* WidgetFactory::createCommentWidget(const QString& comment, QWidget* parent) { KCommentWidget* commentWidget = new KCommentWidget(parent); commentWidget->setText(comment); commentWidget->setReadOnly(m_readOnly); connect(commentWidget, &KCommentWidget::commentChanged, this, &WidgetFactory::slotCommentChanged); m_commentWidget = commentWidget; return commentWidget; } QWidget* WidgetFactory::createRatingWidget(int rating, QWidget* parent) { KRatingWidget* ratingWidget = new KRatingWidget(parent); const Qt::Alignment align = (ratingWidget->layoutDirection() == Qt::LeftToRight) ? Qt::AlignLeft : Qt::AlignRight; ratingWidget->setAlignment(align); ratingWidget->setRating(rating); const QFontMetrics metrics(parent->font()); ratingWidget->setPixmapSize(metrics.height()); connect(ratingWidget, static_cast(&KRatingWidget::ratingChanged), this, &WidgetFactory::slotRatingChanged); m_ratingWidget = ratingWidget; return ratingWidget; } // The default size hint of QLabel tries to return a square size. // This does not work well in combination with layouts that use // heightForWidth(): In this case it is possible that the content // of a label might get clipped. By specifying a size hint // with a maximum width that is necessary to contain the whole text, // using heightForWidth() assures having a non-clipped text. class ValueWidget : public QLabel { public: explicit ValueWidget(QWidget* parent = nullptr); QSize sizeHint() const override; }; ValueWidget::ValueWidget(QWidget* parent) : QLabel(parent) { } QSize ValueWidget::sizeHint() const { QFontMetrics metrics(font()); // TODO: QLabel internally provides already a method sizeForWidth(), // that would be sufficient. However this method is not accessible, so // as workaround the tags from a richtext are removed manually here to // have a proper size hint. return metrics.size(Qt::TextSingleLine, plainText(text())); } QWidget* WidgetFactory::createValueWidget(const QString& value, QWidget* parent) { ValueWidget* valueWidget = new ValueWidget(parent); valueWidget->setWordWrap(true); valueWidget->setAlignment(Qt::AlignTop | Qt::AlignLeft); valueWidget->setText(m_readOnly ? plainText(value) : value); connect(valueWidget, &ValueWidget::linkActivated, this, &WidgetFactory::slotLinkActivated); return valueWidget; } // // Data Synchronization // void WidgetFactory::slotCommentChanged(const QString& comment) { for (const QString& filePath : m_items) { KFileMetaData::UserMetaData md(filePath); md.setUserComment(comment); } emit dataChangeStarted(); emit dataChangeFinished(); } void WidgetFactory::slotRatingChanged(uint rating) { for (const QString& filePath : m_items) { KFileMetaData::UserMetaData md(filePath); md.setRating(rating); } emit dataChangeStarted(); emit dataChangeFinished(); } void WidgetFactory::slotTagsChanged(const QStringList& tags) { if (m_tagWidget) { for (const QString& filePath : m_items) { KFileMetaData::UserMetaData md(filePath); // When multiple tags are selected one doesn't want to loose the old tags // of any of the resources. Unless specifically removed. QStringList newTags = md.tags() + tags; newTags.removeDuplicates(); for (const QString& tag : m_prevTags) { if (!tags.contains(tag)) { newTags.removeAll(tag); } } md.setTags(newTags); } m_prevTags = tags; emit dataChangeStarted(); emit dataChangeFinished(); } } // // Notifications // void WidgetFactory::slotLinkActivated(const QString& url) { emit urlActivated(QUrl::fromUserInput(url)); } void WidgetFactory::slotTagClicked(const QString& tag) { QUrl url; url.setScheme("tags"); url.setPath(tag); emit urlActivated(url); } // // Accessor Methods // void WidgetFactory::setReadOnly(bool value) { m_readOnly = value; } void WidgetFactory::setNoLinks(bool value) { m_noLinks = value; } void WidgetFactory::setItems(const QStringList& items) { m_items = items; } Baloo::DateFormats WidgetFactory::dateFormat() const { return static_cast(m_dateFormat); } void Baloo::WidgetFactory::setDateFormat(const Baloo::DateFormats format) { m_dateFormat = static_cast(format); } diff --git a/src/widgetfactory.h b/src/widgetfactory.h index 5a545eb..ac95a2e 100644 --- a/src/widgetfactory.h +++ b/src/widgetfactory.h @@ -1,87 +1,87 @@ /* Copyright (C) 2012 Vishesh Handa This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef WIDGETFACTORY_H #define WIDGETFACTORY_H #include "filemetadatawidget.h" -#include -#include +#include +#include class KJob; class QUrl; class KCommentWidget; class KRatingWidget; namespace Baloo { class Tag; class TagWidget; class WidgetFactory : public QObject { Q_OBJECT public: explicit WidgetFactory(QObject* parent = nullptr); ~WidgetFactory() override; void setItems(const QStringList& items); void setReadOnly(bool value); void setNoLinks(bool value); void setDateFormat(const DateFormats format); DateFormats dateFormat() const; QWidget* createWidget(const QString& prop, const QVariant& value, QWidget* parent); Q_SIGNALS: void urlActivated(const QUrl& url); void dataChangeStarted(); void dataChangeFinished(); private Q_SLOTS: void slotTagsChanged(const QStringList& tags); void slotCommentChanged(const QString& comment); void slotRatingChanged(uint rating); void slotTagClicked(const QString& tag); void slotLinkActivated(const QString& url); private: QWidget* createRatingWidget(int rating, QWidget* parent); QWidget* createTagWidget(const QStringList& tags, QWidget* parent); QWidget* createCommentWidget(const QString& comment, QWidget* parent); QWidget* createValueWidget(const QString& value, QWidget* parent); TagWidget* m_tagWidget; KRatingWidget* m_ratingWidget; KCommentWidget* m_commentWidget; QStringList m_items; QStringList m_prevTags; bool m_readOnly; bool m_noLinks; QLocale::FormatType m_dateFormat; }; } #endif // WIDGETFACTORY_H diff --git a/test/metadataconfigwidgetapp.cpp b/test/metadataconfigwidgetapp.cpp index e8bfa74..cf815a0 100644 --- a/test/metadataconfigwidgetapp.cpp +++ b/test/metadataconfigwidgetapp.cpp @@ -1,74 +1,74 @@ /* Copyright (C) 2012 Vishesh Handa This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "filemetadataconfigwidget.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include class FileMetadataWidgetTest : public QWidget { Q_OBJECT public: explicit FileMetadataWidgetTest(QWidget* parent = nullptr, Qt::WindowFlags f = {}); private Q_SLOTS: void slotChooseFiles(); private: Baloo::FileMetaDataConfigWidget* m_metadataWidget; QPushButton* m_button; }; FileMetadataWidgetTest::FileMetadataWidgetTest(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { m_metadataWidget = new Baloo::FileMetaDataConfigWidget( this ); m_button = new QPushButton( QLatin1String("Select files"), this ); connect( m_button, SIGNAL(clicked(bool)), this, SLOT(slotChooseFiles()) ); QVBoxLayout* layout = new QVBoxLayout( this ); layout->addWidget( m_button ); layout->addWidget( m_metadataWidget ); } void FileMetadataWidgetTest::slotChooseFiles() { QList urlList = QFileDialog::getOpenFileUrls(); KFileItemList list; foreach(const QUrl& url, urlList) list << KFileItem( url, QString(), mode_t() ); m_metadataWidget->setItems( list ); } int main( int argc, char** argv ) { QApplication app( argc, argv ); app.setApplicationName( "FileMetaDataConfigWidgetApp" ); FileMetadataWidgetTest test; test.show(); return app.exec(); } #include "metadataconfigwidgetapp.moc" diff --git a/test/tagwidgetapp.cpp b/test/tagwidgetapp.cpp index 7ecca8d..e62f56d 100644 --- a/test/tagwidgetapp.cpp +++ b/test/tagwidgetapp.cpp @@ -1,33 +1,33 @@ /* This file is part of the Baloo KDE project. Copyright (C) 2010 Sebastian Trueg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "tagwidgettest.h" -#include -#include +#include +#include int main( int argc, char** argv ) { QApplication app( argc, argv ); QCoreApplication::setApplicationName("TagWidgetApp"); TagWidgetTest tw; tw.show(); return app.exec(); } diff --git a/test/tagwidgettest.cpp b/test/tagwidgettest.cpp index f9373bf..c5af84e 100644 --- a/test/tagwidgettest.cpp +++ b/test/tagwidgettest.cpp @@ -1,78 +1,78 @@ /* This file is part of the Baloo KDE project. Copyright (C) 2010 Sebastian Trueg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "tagwidgettest.h" #include "tagwidget.h" -#include -#include -#include +#include +#include +#include TagWidgetTest::TagWidgetTest() : QWidget() { m_tagWidget = new Baloo::TagWidget(this); QVBoxLayout* lay = new QVBoxLayout(this); lay->addWidget(m_tagWidget); connect(m_tagWidget, SIGNAL(tagClicked(QString)), this, SLOT(slotTagClicked(QString))); connect(m_tagWidget, SIGNAL(selectionChanged(QStringList)), this, SLOT(slotSelectionChanged(QStringList))); QCheckBox* box = new QCheckBox( "Align Right", this ); connect(box, SIGNAL(toggled(bool)), this, SLOT(alignRight(bool))); lay->addWidget(box); box = new QCheckBox( "Read only", this ); connect(box, SIGNAL(toggled(bool)), this, SLOT(setReadOnly(bool))); lay->addWidget(box); } TagWidgetTest::~TagWidgetTest() { } void TagWidgetTest::slotTagClicked(const QString& tag) { qDebug() << "Tag clicked:" << tag; } void TagWidgetTest::slotSelectionChanged( const QStringList& tags ) { qDebug() << "Selection changed:" << tags; } void TagWidgetTest::alignRight( bool enable ) { if( enable ) m_tagWidget->setAlignment( Qt::AlignRight ); else m_tagWidget->setAlignment( Qt::AlignLeft ); } void TagWidgetTest::setReadOnly( bool enable ) { m_tagWidget->setReadyOnly(enable); } diff --git a/test/tagwidgettest.h b/test/tagwidgettest.h index 3ef3bef..c659485 100644 --- a/test/tagwidgettest.h +++ b/test/tagwidgettest.h @@ -1,47 +1,47 @@ /* This file is part of the Baloo KDE project. Copyright (C) 2010 Sebastian Trueg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef TAGWIDGETTEST_H #define TAGWIDGETTEST_H -#include +#include #include "tagwidget.h" class TagWidgetTest : public QWidget { Q_OBJECT public: TagWidgetTest(); ~TagWidgetTest() override; public Q_SLOTS: void slotTagClicked(const QString&); void slotSelectionChanged( const QStringList& tags ); private Q_SLOTS: void alignRight( bool enable ); void setReadOnly( bool enable ); private: Baloo::TagWidget* m_tagWidget; }; #endif