]> cloud.milkyroute.net Git - dolphin.git/commitdiff
provide a cleaner layout for the information panel; there are still some open issues...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 16 Mar 2008 02:17:16 +0000 (02:17 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 16 Mar 2008 02:17:16 +0000 (02:17 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=786080

src/CMakeLists.txt
src/infosidebarpage.cpp
src/infosidebarpage.h
src/metatextlabel.cpp [new file with mode: 0644]
src/metatextlabel.h [new file with mode: 0644]

index de8b6f2e01f3ce2c29a180605ad8256e4fb8c325..fcecacd440a99a8182b967a3dddd02ce87b86a24 100644 (file)
@@ -102,6 +102,7 @@ set(dolphin_SRCS
    infosidebarpage.cpp
    main.cpp
    metadatawidget.cpp
    infosidebarpage.cpp
    main.cpp
    metadatawidget.cpp
+   metatextlabel.cpp
    pixmapviewer.cpp
    settingspagebase.cpp
    sidebarpage.cpp
    pixmapviewer.cpp
    settingspagebase.cpp
    sidebarpage.cpp
index f9a0b4a7ea2cf15950dfb9ff5e2f0eec60c903bf..785d650d1d09d7adbecd02776104f70991958d67 100644 (file)
@@ -29,7 +29,6 @@
 #include <kdialog.h>
 #include <kglobalsettings.h>
 #include <kfilemetainfo.h>
 #include <kdialog.h>
 #include <kglobalsettings.h>
 #include <kfilemetainfo.h>
-#include <kvbox.h>
 #include <kseparator.h>
 #include <kiconloader.h>
 
 #include <kseparator.h>
 #include <kiconloader.h>
 
@@ -43,6 +42,7 @@
 
 #include "dolphinsettings.h"
 #include "metadatawidget.h"
 
 #include "dolphinsettings.h"
 #include "metadatawidget.h"
+#include "metatextlabel.h"
 #include "pixmapviewer.h"
 
 InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
 #include "pixmapviewer.h"
 
 InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
@@ -51,10 +51,10 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
     m_shownUrl(),
     m_urlCandidate(),
     m_fileItem(),
     m_shownUrl(),
     m_urlCandidate(),
     m_fileItem(),
-    m_preview(0),
     m_nameLabel(0),
     m_nameLabel(0),
-    m_infoLabel(0),
-    m_metaDataWidget(0)
+    m_preview(0),
+    m_metaDataWidget(0),
+    m_metaTextLabel(0)
 {
     const int spacing = KDialog::spacingHint();
 
 {
     const int spacing = KDialog::spacingHint();
 
@@ -66,37 +66,35 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
     QVBoxLayout* layout = new QVBoxLayout;
     layout->setSpacing(spacing);
 
     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);
     // 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);
 
     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()) {
 
     if (MetaDataWidget::metaDataAvailable()) {
+        // rating, comment and tags
         m_metaDataWidget = new MetaDataWidget(this);
     }
 
         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(m_nameLabel);
-    layout->addWidget(new KSeparator(this));
-    layout->addWidget(m_infoLabel);
+    layout->addWidget(m_preview);
     if (m_metaDataWidget != 0) {
     if (m_metaDataWidget != 0) {
-        layout->addWidget(new KSeparator(this));
         layout->addWidget(m_metaDataWidget);
     }
         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);
     // 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);
     // 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));
 
     // 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&)));
 
         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();
     }
 
     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)) {
         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;
         }
             m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128));
             return true;
         }
@@ -290,7 +280,7 @@ void InfoSidebarPage::cancelRequest()
 
 void InfoSidebarPage::showMetaInfo()
 {
 
 void InfoSidebarPage::showMetaInfo()
 {
-    QString text;
+    m_metaTextLabel->clear();
 
     const KFileItemList& selectedItems = selection();
     if (selectedItems.size() <= 1) {
 
     const KFileItemList& selectedItems = selection();
     if (selectedItems.size() <= 1) {
@@ -304,12 +294,12 @@ void InfoSidebarPage::showMetaInfo()
         }
 
         if (fileItem.isDir()) {
         }
 
         if (fileItem.isDir()) {
-            addInfoLine(text, i18nc("@label", "Type:"), i18nc("@label", "Folder"));
+            m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder"));
         } else {
         } 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
 
             // 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();
                                                    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) {
                 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;
                 }
                     }
                     ++it;
                 }
@@ -349,25 +339,14 @@ void InfoSidebarPage::showMetaInfo()
 
         unsigned long int totalSize = 0;
         foreach (const KFileItem& item, selectedItems) {
 
         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();
             }
         }
             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
 }
 
 bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const
index 08782d7799af9ddae682f4c83154b92ac0b9ed48..6cdc1e824859a4867a29ba0aac5e05928d2a2879 100644 (file)
@@ -39,6 +39,7 @@ class KFileItem;
 class QLabel;
 class PixmapViewer;
 class MetaDataWidget;
 class QLabel;
 class PixmapViewer;
 class MetaDataWidget;
+class MetaTextLabel;
 
 /**
  * @brief Sidebar for showing meta information of one ore more selected items.
 
 /**
  * @brief Sidebar for showing meta information of one ore more selected items.
@@ -121,14 +122,6 @@ private:
      */
     void showMetaInfo();
 
      */
     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
     /**
      * 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)
 
     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_nameLabel;
-
-    QLabel* m_infoLabel;
-
+    PixmapViewer* m_preview;
     MetaDataWidget* m_metaDataWidget;
     MetaDataWidget* m_metaDataWidget;
+    MetaTextLabel* m_metaTextLabel;
 };
 
 #endif // INFOSIDEBARPAGE_H
 };
 
 #endif // INFOSIDEBARPAGE_H
diff --git a/src/metatextlabel.cpp b/src/metatextlabel.cpp
new file mode 100644 (file)
index 0000000..eb8a287
--- /dev/null
@@ -0,0 +1,90 @@
+/***************************************************************************
+ *   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"
diff --git a/src/metatextlabel.h b/src/metatextlabel.h
new file mode 100644 (file)
index 0000000..856bc85
--- /dev/null
@@ -0,0 +1,49 @@
+/***************************************************************************
+ *   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