Commit c1c104a6 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Fix preview windows covering the main window

by unsetting Part::widget() as their parent.

Differential Revision: D1408
parent 18000e9a
......@@ -45,6 +45,7 @@
#include <KConfigSkeleton>
#include <KXMLGUIFactory>
#include <QApplication>
#include <QDebug>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
......@@ -256,6 +257,18 @@ void MainWindow::setShowExtractDialog(bool option)
}
}
void MainWindow::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event)
// Preview windows don't have a parent, so we need to manually close them.
foreach (QWidget *widget, qApp->topLevelWidgets()) {
if (widget->isVisible()) {
widget->close();
}
}
}
void MainWindow::quit()
{
close();
......
......@@ -44,6 +44,9 @@ public slots:
void openUrl(const QUrl &url);
void setShowExtractDialog(bool);
protected:
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void updateActions();
void newArchive();
......
......@@ -40,11 +40,13 @@
#include <QPushButton>
#include <QMimeDatabase>
ArkViewer::ArkViewer(QWidget *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
ArkViewer::ArkViewer()
: QDialog()
{
qCDebug(ARK) << "ArkViewer opened";
setAttribute(Qt::WA_DeleteOnClose);
// Set a QVBoxLayout as main layout of dialog
m_mainLayout = new QVBoxLayout(this);
setLayout(m_mainLayout);
......@@ -93,7 +95,7 @@ void ArkViewer::dialogClosed()
}
}
void ArkViewer::view(const QString& fileName, QWidget *parent)
void ArkViewer::view(const QString& fileName)
{
QMimeDatabase db;
QMimeType mimeType = db.mimeTypeForFile(fileName);
......@@ -112,7 +114,7 @@ void ArkViewer::view(const QString& fileName, QWidget *parent)
const QList<QUrl> fileUrlList = {QUrl::fromLocalFile(fileName)};
// The last argument (tempFiles) set to true means that the temporary
// file will be removed when the viewer application exits.
KRun::runService(*viewer, fileUrlList, parent, true);
KRun::runService(*viewer, fileUrlList, Q_NULLPTR, true);
return;
}
......@@ -129,7 +131,7 @@ void ArkViewer::view(const QString& fileName, QWidget *parent)
// File has a defined MIME type, and not the default
// application/octet-stream. So it could be viewable as
// plain text, ask the user.
response = KMessageBox::warningContinueCancel(parent,
response = KMessageBox::warningContinueCancel(Q_NULLPTR,
xi18n("The internal viewer cannot preview this type of file<nl/>(%1).<nl/><nl/>Do you want to try to view it as plain text?", mimeType.name()),
i18nc("@title:window", "Cannot Preview File"),
KGuiItem(i18nc("@action:button", "Preview as Text"), QIcon::fromTheme(QStringLiteral("text-plain"))),
......@@ -141,7 +143,7 @@ void ArkViewer::view(const QString& fileName, QWidget *parent)
// There is still a possibility that it could be viewable as plain
// text, so ask the user. Not the same as the message/question
// above, because the wording and default are different.
response = KMessageBox::warningContinueCancel(parent,
response = KMessageBox::warningContinueCancel(Q_NULLPTR,
xi18n("The internal viewer cannot preview this unknown type of file.<nl/><nl/>Do you want to try to view it as plain text?"),
i18nc("@title:window", "Cannot Preview File"),
KGuiItem(i18nc("@action:button", "Preview as Text"), QIcon::fromTheme(QStringLiteral("text-plain"))),
......@@ -160,7 +162,7 @@ void ArkViewer::view(const QString& fileName, QWidget *parent)
if (viewInInternalViewer) {
qCDebug(ARK) << "Opening internal viewer";
ArkViewer *internalViewer = new ArkViewer(parent, Qt::Window);
ArkViewer *internalViewer = new ArkViewer();
internalViewer->show();
if (internalViewer->viewInInternalViewer(fileName, mimeType)) {
// The internal viewer is showing the file, and will
......@@ -169,7 +171,7 @@ void ArkViewer::view(const QString& fileName, QWidget *parent)
return;
}
else {
KMessageBox::sorry(parent, i18n("The internal viewer cannot preview this file."));
KMessageBox::sorry(Q_NULLPTR, i18n("The internal viewer cannot preview this file."));
delete internalViewer;
}
}
......
......@@ -39,13 +39,13 @@ public:
virtual ~ArkViewer();
QSize sizeHint() const Q_DECL_OVERRIDE;
static void view(const QString& fileName, QWidget* parent = 0);
static void view(const QString& fileName);
private slots:
void dialogClosed();
private:
explicit ArkViewer(QWidget* parent = 0, Qt::WindowFlags flags = 0);
explicit ArkViewer();
static KService::Ptr getViewer(const QString& mimeType);
bool viewInInternalViewer(const QString& fileName, const QMimeType& mimeType);
......
......@@ -803,7 +803,7 @@ void Part::slotOpenExtractedEntry(KJob *job)
switch (m_openFileMode) {
case Preview:
ArkViewer::view(fullName, widget());
ArkViewer::view(fullName);
break;
case OpenFile:
KRun::runUrl(QUrl::fromUserInput(fullName,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment