[kde-doc-english] [trojita] src/Gui: GUI: use proper icons and human-readable description on Qt5
Jan Kundrát
jkt at flaska.net
Tue Mar 12 12:37:54 UTC 2013
Git commit c7666ad17a11a27fd63d152b85343496bfc04245 by Jan Kundrát.
Committed on 12/03/2013 at 13:31.
Pushed by jkt into branch 'master'.
GUI: use proper icons and human-readable description on Qt5
M +24 -1 src/Gui/AttachmentView.cpp
http://commits.kde.org/trojita/c7666ad17a11a27fd63d152b85343496bfc04245
diff --git a/src/Gui/AttachmentView.cpp b/src/Gui/AttachmentView.cpp
index e8bfd0f..9a05199 100644
--- a/src/Gui/AttachmentView.cpp
+++ b/src/Gui/AttachmentView.cpp
@@ -40,6 +40,9 @@
#include <QLabel>
#include <QTemporaryFile>
#include <QToolButton>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#include <QMimeDatabase>
+#endif
namespace Gui
{
@@ -50,10 +53,26 @@ AttachmentView::AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessM
{
m_fileDownloadManager = new Imap::Network::FileDownloadManager(this, manager, partIndex);
QHBoxLayout *layout = new QHBoxLayout(this);
+
// Icon on the left
QLabel *lbl = new QLabel();
+
+ QString mimeDescription = partIndex.data(Imap::Mailbox::RolePartMimeType).toString();
+ QString rawMime = mimeDescription;
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+ QMimeType mimeType = QMimeDatabase().mimeTypeForName(mimeDescription);
+ if (mimeType.isValid() && !mimeType.isDefault()) {
+ mimeDescription = mimeType.comment();
+ QIcon icon = QIcon::fromTheme(mimeType.iconName(), loadIcon(QLatin1String("mail-attachment")));
+ lbl->setPixmap(icon.pixmap(22, 22));
+ } else {
+ lbl->setPixmap(loadIcon(QLatin1String("mail-attachment")).pixmap(22, 22));
+ }
+#else
lbl->setPixmap(loadIcon(QLatin1String("mail-attachment")).pixmap(22, 22));
+#endif
layout->addWidget(lbl);
+
QWidget *labelArea = new QWidget();
QVBoxLayout *subLayout = new QVBoxLayout(labelArea);
// The file name shall be mouse-selectable
@@ -63,9 +82,12 @@ AttachmentView::AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessM
lbl->setTextInteractionFlags(Qt::TextSelectableByMouse);
subLayout->addWidget(lbl);
// Some metainformation -- the MIME type and the file size
- lbl = new QLabel(tr("%2, %3").arg(partIndex.data(Imap::Mailbox::RolePartMimeType).toString(),
+ lbl = new QLabel(tr("%2, %3").arg(mimeDescription,
Imap::Mailbox::PrettySize::prettySize(partIndex.data(Imap::Mailbox::RolePartOctets).toUInt(),
Imap::Mailbox::PrettySize::WITH_BYTES_SUFFIX)));
+ if (rawMime != mimeDescription) {
+ lbl->setToolTip(rawMime);
+ }
QFont f = lbl->font();
f.setItalic(true);
f.setPointSizeF(f.pointSizeF() * 0.8);
@@ -73,6 +95,7 @@ AttachmentView::AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessM
subLayout->addWidget(lbl);
layout->addWidget(labelArea);
layout->addStretch();
+
// Download/Open buttons
m_downloadButton = new QToolButton();
m_downloadButton->setPopupMode(QToolButton::MenuButtonPopup);
More information about the kde-doc-english
mailing list