From: Peter Penz Date: Sun, 16 Mar 2008 02:17:16 +0000 (+0000) Subject: provide a cleaner layout for the information panel; there are still some open issues... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/2b8772807fb862895c00762fb5b246ed78b663fc?ds=sidebyside provide a cleaner layout for the information panel; there are still some open issues, but it looks already less cluttered... svn path=/trunk/KDE/kdebase/apps/; revision=786080 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de8b6f2e0..fcecacd44 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -102,6 +102,7 @@ set(dolphin_SRCS infosidebarpage.cpp main.cpp metadatawidget.cpp + metatextlabel.cpp pixmapviewer.cpp settingspagebase.cpp sidebarpage.cpp diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index f9a0b4a7e..785d650d1 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -43,6 +42,7 @@ #include "dolphinsettings.h" #include "metadatawidget.h" +#include "metatextlabel.h" #include "pixmapviewer.h" InfoSidebarPage::InfoSidebarPage(QWidget* parent) : @@ -51,10 +51,10 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : m_shownUrl(), m_urlCandidate(), m_fileItem(), - m_preview(0), m_nameLabel(0), - m_infoLabel(0), - m_metaDataWidget(0) + m_preview(0), + m_metaDataWidget(0), + m_metaTextLabel(0) { const int spacing = KDialog::spacingHint(); @@ -66,37 +66,35 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : QVBoxLayout* layout = new QVBoxLayout; layout->setSpacing(spacing); - // preview - m_preview = new PixmapViewer(this); - m_preview->setMinimumWidth(KIconLoader::SizeEnormous); - m_preview->setMinimumHeight(KIconLoader::SizeEnormous); - // name m_nameLabel = new QLabel(this); - m_nameLabel->setTextFormat(Qt::RichText); - m_nameLabel->setAlignment(m_nameLabel->alignment() | Qt::AlignHCenter); + QFont font = m_nameLabel->font(); + font.setBold(true); + m_nameLabel->setFont(font); + m_nameLabel->setAlignment(Qt::AlignHCenter); m_nameLabel->setWordWrap(true); - // general information - m_infoLabel = new QLabel(this); - m_infoLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - m_infoLabel->setTextFormat(Qt::RichText); - m_infoLabel->setWordWrap(true); - m_infoLabel->setFont(KGlobalSettings::smallestReadableFont()); + // preview + m_preview = new PixmapViewer(this); + m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium); + m_preview->setMinimumHeight(KIconLoader::SizeEnormous); if (MetaDataWidget::metaDataAvailable()) { + // rating, comment and tags m_metaDataWidget = new MetaDataWidget(this); } - layout->addItem(new QSpacerItem(spacing, spacing, QSizePolicy::Preferred, QSizePolicy::Fixed)); - layout->addWidget(m_preview); + // general meta text information + m_metaTextLabel = new MetaTextLabel(this); + m_metaTextLabel->setMinimumWidth(spacing); + layout->addWidget(m_nameLabel); - layout->addWidget(new KSeparator(this)); - layout->addWidget(m_infoLabel); + layout->addWidget(m_preview); if (m_metaDataWidget != 0) { - layout->addWidget(new KSeparator(this)); layout->addWidget(m_metaDataWidget); } + layout->addWidget(m_metaTextLabel); + // ensure that widgets in the information side bar are aligned towards the top layout->addStretch(1); setLayout(layout); @@ -168,7 +166,6 @@ void InfoSidebarPage::resizeEvent(QResizeEvent* event) // the current width of the sidebar. const int maxWidth = event->size().width() - KDialog::spacingHint() * 4; m_nameLabel->setMaximumWidth(maxWidth); - m_infoLabel->setMaximumWidth(maxWidth); // try to increase the preview as large as possible m_preview->setSizeHint(QSize(maxWidth, maxWidth)); @@ -227,10 +224,7 @@ void InfoSidebarPage::showItemInfo() connect(job, SIGNAL(failed(const KFileItem&)), this, SLOT(showIcon(const KFileItem&))); - QString text(""); - text.append(file.fileName()); - text.append(""); - m_nameLabel->setText(text); + m_nameLabel->setText(file.fileName()); } showMetaInfo(); @@ -269,11 +263,7 @@ bool InfoSidebarPage::applyPlace(const KUrl& url) QModelIndex index = placesModel->index(i, 0); if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) { - QString text(""); - text.append(placesModel->text(index)); - text.append(""); - m_nameLabel->setText(text); - + m_nameLabel->setText(placesModel->text(index)); m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128)); return true; } @@ -290,7 +280,7 @@ void InfoSidebarPage::cancelRequest() void InfoSidebarPage::showMetaInfo() { - QString text; + m_metaTextLabel->clear(); const KFileItemList& selectedItems = selection(); if (selectedItems.size() <= 1) { @@ -304,12 +294,12 @@ void InfoSidebarPage::showMetaInfo() } if (fileItem.isDir()) { - addInfoLine(text, i18nc("@label", "Type:"), i18nc("@label", "Folder")); + m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder")); } else { - addInfoLine(text, i18nc("@label", "Type:"), fileItem.mimeComment()); + m_metaTextLabel->add(i18nc("@label", "Type:"), fileItem.mimeComment()); - addInfoLine(text, i18nc("@label", "Size:"), KIO::convertSize(fileItem.size())); - addInfoLine(text, i18nc("@label", "Modified:"), fileItem.timeString()); + m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(fileItem.size())); + m_metaTextLabel->add(i18nc("@label", "Modified:"), fileItem.timeString()); // TODO: See convertMetaInfo below, find a way to display only interesting information // in a readable way @@ -318,17 +308,17 @@ void InfoSidebarPage::showMetaInfo() KFileMetaInfo::ContentInfo | KFileMetaInfo::Thumbnail; const QString path = fileItem.url().url(); - const KFileMetaInfo metaInfo(path, QString(), flags); - if (metaInfo.isValid()) { - const QHash& items = metaInfo.items(); + const KFileMetaInfo fileMetaInfo(path, QString(), flags); + if (fileMetaInfo.isValid()) { + const QHash& items = fileMetaInfo.items(); QHash::const_iterator it = items.constBegin(); const QHash::const_iterator end = items.constEnd(); QString labelText; while (it != end) { - const KFileMetaInfoItem& metaInfo = it.value(); - const QVariant& value = metaInfo.value(); - if (value.isValid() && convertMetaInfo(metaInfo.name(), labelText)) { - addInfoLine(text, labelText, value.toString()); + const KFileMetaInfoItem& metaInfoItem = it.value(); + const QVariant& value = metaInfoItem.value(); + if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) { + m_metaTextLabel->add(labelText, value.toString()); } ++it; } @@ -349,25 +339,14 @@ void InfoSidebarPage::showMetaInfo() unsigned long int totalSize = 0; foreach (const KFileItem& item, selectedItems) { - // Only count the size of files, not dirs; to match what - // DolphinViewContainer::selectionStatusBarText does. + // Only count the size of files, not dirs to match what + // DolphinViewContainer::selectionStatusBarText() does. if (!item.isDir() && !item.isLink()) { totalSize += item.size(); } } - addInfoLine(text, i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); - } - m_infoLabel->setText(text); -} - -void InfoSidebarPage::addInfoLine(QString& text, - const QString& labelText, - const QString& infoText) -{ - if (!text.isEmpty()) { - text += "
"; + m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); } - text += QString("%1 %2").arg(labelText).arg(infoText); } bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const diff --git a/src/infosidebarpage.h b/src/infosidebarpage.h index 08782d779..6cdc1e824 100644 --- a/src/infosidebarpage.h +++ b/src/infosidebarpage.h @@ -39,6 +39,7 @@ class KFileItem; class QLabel; class PixmapViewer; class MetaDataWidget; +class MetaTextLabel; /** * @brief Sidebar for showing meta information of one ore more selected items. @@ -121,14 +122,6 @@ private: */ void showMetaInfo(); - /** - * Adds the texts \a labelText and \a infoText as one formated line - * to text. - */ - void addInfoLine(QString& text, - const QString& labelText, - const QString& infoText); - /** * Converts the meta key \a key to a readable format into \a text. * Returns true, if the string \a key represents a meta information @@ -143,12 +136,10 @@ private: KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null) - PixmapViewer* m_preview; QLabel* m_nameLabel; - - QLabel* m_infoLabel; - + PixmapViewer* m_preview; MetaDataWidget* m_metaDataWidget; + MetaTextLabel* m_metaTextLabel; }; #endif // INFOSIDEBARPAGE_H diff --git a/src/metatextlabel.cpp b/src/metatextlabel.cpp new file mode 100644 index 000000000..eb8a2873c --- /dev/null +++ b/src/metatextlabel.cpp @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 "metatextlabel.h" + +#include +#include +#include + +#include +#include + +MetaTextLabel::MetaTextLabel(QWidget* parent) : + QGroupBox(i18nc("@title:group", "General"), parent), + m_lines(0), + m_layout(0) +{ +} + +MetaTextLabel::~MetaTextLabel() +{ +} + +void MetaTextLabel::clear() +{ + if (m_layout != 0) { + m_layout->removeWidget(m_lines); + } + + delete m_lines; + m_lines = 0; + + delete m_layout; + m_layout = 0; +} + +void MetaTextLabel::add(const QString& labelText, const QString& infoText) +{ + if (m_lines == 0) { + Q_ASSERT(m_layout == 0); + + m_lines = new KVBox(this); + m_layout = new QHBoxLayout(); + m_layout->addWidget(m_lines); + setLayout(m_layout); + + m_lines->show(); + } + + QWidget* line = new QWidget(m_lines); + + QLabel* label = new QLabel(labelText, line); + label->setFont(KGlobalSettings::smallestReadableFont()); + label->setAlignment(Qt::AlignRight | Qt::AlignTop); + + QPalette palette = label->palette(); + QColor foreground = palette.color(QPalette::Foreground); + foreground.setAlpha(128); + palette.setColor(QPalette::Foreground, foreground); + label->setPalette(palette); + + QLabel* info = new QLabel(infoText, line); + info->setFont(KGlobalSettings::smallestReadableFont()); + info->setAlignment(Qt::AlignLeft | Qt::AlignTop); + info->setWordWrap(true); + + QHBoxLayout* layout = new QHBoxLayout(line); + layout->addWidget(label, 50); + layout->addWidget(info, 50); + + line->show(); +} + +#include "metatextlabel.moc" diff --git a/src/metatextlabel.h b/src/metatextlabel.h new file mode 100644 index 000000000..856bc85c2 --- /dev/null +++ b/src/metatextlabel.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Penz * + * * + * 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 METATEXTLABEL_H +#define METATEXTLABEL_H + +#include + +class KVBox; +class QHBoxLayout; + +/** + * @brief Displays general meta in several lines. + * + * Each line contains a label and the the meta information. + */ +class MetaTextLabel : public QGroupBox +{ + Q_OBJECT + +public: + MetaTextLabel(QWidget* parent = 0); + virtual ~MetaTextLabel(); + + void clear(); + void add(const QString& labelText, const QString& infoText); + +private: + KVBox* m_lines; + QHBoxLayout* m_layout; +}; + +#endif