#include <kdialog.h>
#include <kglobalsettings.h>
#include <kfilemetainfo.h>
-#include <kvbox.h>
#include <kseparator.h>
#include <kiconloader.h>
#include "dolphinsettings.h"
#include "metadatawidget.h"
+#include "metatextlabel.h"
#include "pixmapviewer.h"
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();
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);
// 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));
connect(job, SIGNAL(failed(const KFileItem&)),
this, SLOT(showIcon(const KFileItem&)));
- QString text("<b>");
- text.append(file.fileName());
- text.append("</b>");
- m_nameLabel->setText(text);
+ m_nameLabel->setText(file.fileName());
}
showMetaInfo();
QModelIndex index = placesModel->index(i, 0);
if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) {
- QString text("<b>");
- text.append(placesModel->text(index));
- text.append("</b>");
- m_nameLabel->setText(text);
-
+ m_nameLabel->setText(placesModel->text(index));
m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128));
return true;
}
void InfoSidebarPage::showMetaInfo()
{
- QString text;
+ m_metaTextLabel->clear();
const KFileItemList& selectedItems = selection();
if (selectedItems.size() <= 1) {
}
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
KFileMetaInfo::ContentInfo |
KFileMetaInfo::Thumbnail;
const QString path = fileItem.url().url();
- const KFileMetaInfo metaInfo(path, QString(), flags);
- if (metaInfo.isValid()) {
- const QHash<QString, KFileMetaInfoItem>& items = metaInfo.items();
+ const KFileMetaInfo fileMetaInfo(path, QString(), flags);
+ if (fileMetaInfo.isValid()) {
+ const QHash<QString, KFileMetaInfoItem>& items = fileMetaInfo.items();
QHash<QString, KFileMetaInfoItem>::const_iterator it = items.constBegin();
const QHash<QString, KFileMetaInfoItem>::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;
}
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 += "<br/>";
+ m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize));
}
- text += QString("<b>%1</b> %2").arg(labelText).arg(infoText);
}
bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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 <kglobalsettings.h>
+#include <klocale.h>
+#include <kvbox.h>
+
+#include <QHBoxLayout>
+#include <QLabel>
+
+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"
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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 <QGroupBox>
+
+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