From: Soren Stoutner Date: Mon, 11 Jul 2022 17:45:23 +0000 (-0700) Subject: Display the MIME type icon in the download dialog. X-Git-Tag: v0.1~22 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=fbcbf16ba69e2049ab8b023ce3ecd5ae94392e09;p=PrivacyBrowserPC.git Display the MIME type icon in the download dialog. --- diff --git a/src/dialogs/SaveDialog.cpp b/src/dialogs/SaveDialog.cpp index fff857d..622bc36 100644 --- a/src/dialogs/SaveDialog.cpp +++ b/src/dialogs/SaveDialog.cpp @@ -25,6 +25,7 @@ #include // Qt toolkit headers. +#include #include #include #include @@ -45,6 +46,7 @@ SaveDialog::SaveDialog(QWebEngineDownloadItem *downloadItemPointer) saveDialogUi.setupUi(this); // Get handles for the widgets. + QGraphicsView *mimeGraphicsViewPointer = saveDialogUi.mimeGraphicsView; QLabel *urlLabelPointer = saveDialogUi.urlLabel; QLabel *filetypeLabelPointer = saveDialogUi.fileTypeLabel; QLabel *mimeTypeLabelPointer = saveDialogUi.mimeTypeLabel; @@ -55,15 +57,33 @@ SaveDialog::SaveDialog(QWebEngineDownloadItem *downloadItemPointer) // Get the URL and the suggested file name. downloadUrl = downloadItemPointer->url(); suggestedFileName = downloadItemPointer->suggestedFileName(); - QString mimeType = downloadItemPointer->mimeType(); + QString mimeTypeString = downloadItemPointer->mimeType(); // Get a MIME type database. QMimeDatabase mimeDatabase; + // Get the MIME type. + QMimeType mimeType = mimeDatabase.mimeTypeForName(mimeTypeString); + + // Get the MIME type icon. + QIcon mimeTypeIcon = QIcon::fromTheme(mimeType.iconName()); + + // Create a graphics scene. + QGraphicsScene *mimeGraphicsScenePointer = new QGraphicsScene(this); + + // Set the graphics scene. + mimeGraphicsViewPointer->setScene(mimeGraphicsScenePointer); + + // Set the background of the graphics view to be the same as the window + mimeGraphicsViewPointer->setBackgroundRole(QPalette::Window); + + // Add the MIME type icon to the scene. + mimeGraphicsScenePointer->addPixmap(mimeTypeIcon.pixmap(64, 64)); + // Populate the labels. urlLabelPointer->setText("" + downloadUrl.toString() + ""); - filetypeLabelPointer->setText("" + mimeDatabase.mimeTypeForName(mimeType).comment() + ""); - mimeTypeLabelPointer->setText("" + mimeType + ""); + filetypeLabelPointer->setText("" + mimeType.comment() + ""); + mimeTypeLabelPointer->setText("" + mimeTypeString + ""); // Populate the download size label. if (downloadItemPointer->totalBytes() == -1) // The file size is unknown. diff --git a/src/uis/SaveDialog.ui b/src/uis/SaveDialog.ui index 489b8c8..b8e3dfa 100644 --- a/src/uis/SaveDialog.ui +++ b/src/uis/SaveDialog.ui @@ -51,74 +51,91 @@ File details - - - - - - - URL: + + + + + + QFrame::NoFrame - - - - - - - Qt::RichText - - - - - - - - - File type: - - - - - - - - Qt::RichText - - - - - - - - - MIME type: - - - - - - - Qt::RichText + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - Size: - - - - - - - - Qt::RichText - - + + + + + + + + URL: + + + + + + + + Qt::RichText + + + + + + + + + File type: + + + + + + + + Qt::RichText + + + + + + + + + MIME type: + + + + + + + + Qt::RichText + + + + + + + + + Size: + + + + + + + + Qt::RichText + + + +