From 165e088a35b9f2626ee81b34449f4a603be68920 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 30 Mar 2007 17:29:00 +0000 Subject: [PATCH] Give KMessageBoxes a parent widget. BUGS: 143612 svn path=/branches/KDE/3.5/kdegraphics/kpdf/; revision=648173 --- core/document.cpp | 19 ++++++++++++------- core/document.h | 5 ++++- core/generator_pdf/generator_pdf.cpp | 2 +- part.cpp | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 796d5e54d..0f123ad3c 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -106,8 +106,8 @@ struct RunningSearch /** KPDFDocument **/ -KPDFDocument::KPDFDocument() - : generator( 0 ), d( new KPDFDocumentPrivate ) +KPDFDocument::KPDFDocument(QWidget *widget) + : QObject(widget), generator( 0 ), d( new KPDFDocumentPrivate ) { d->allocatedPixmapsTotalMemory = 0; d->memCheckTimer = 0; @@ -355,6 +355,11 @@ void KPDFDocument::reparseConfig() } +QWidget *KPDFDocument::widget() const +{ + return static_cast(parent()); +} + bool KPDFDocument::isOpened() const { return generator; @@ -742,7 +747,7 @@ bool KPDFDocument::searchText( int searchID, const QString & text, bool fromStar { if ( currentPage >= pageCount ) { - if ( noDialogs || KMessageBox::questionYesNo(0, i18n("End of document reached.\nContinue from the beginning?"), QString::null, KStdGuiItem::cont(), KStdGuiItem::cancel()) == KMessageBox::Yes ) + if ( noDialogs || KMessageBox::questionYesNo(widget(), i18n("End of document reached.\nContinue from the beginning?"), QString::null, KStdGuiItem::cont(), KStdGuiItem::cancel()) == KMessageBox::Yes ) currentPage = 0; else break; @@ -788,7 +793,7 @@ bool KPDFDocument::searchText( int searchID, const QString & text, bool fromStar } } else if ( !noDialogs ) - KMessageBox::information( 0, i18n("No matches found for '%1'.").arg( text ) ); + KMessageBox::information( widget(), i18n("No matches found for '%1'.").arg( text ) ); } // 3. PREVMATCH //TODO else if ( type == PrevMatch ) @@ -990,7 +995,7 @@ void KPDFDocument::processLink( const KPDFLink * link ) { // this case is a link pointing to an executable with a parameter // that also is an executable, possibly a hand-crafted pdf - KMessageBox::information( 0, i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") ); + KMessageBox::information( widget(), i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") ); return; } } @@ -998,7 +1003,7 @@ void KPDFDocument::processLink( const KPDFLink * link ) { // this case is a link pointing to an executable with no parameters // core developers find unacceptable executing it even after asking the user - KMessageBox::information( 0, i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") ); + KMessageBox::information( widget(), i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") ); return; } } @@ -1011,7 +1016,7 @@ void KPDFDocument::processLink( const KPDFLink * link ) KRun::run( *ptr, lst ); } else - KMessageBox::information( 0, i18n( "No application found for opening file of mimetype %1." ).arg( mime->name() ) ); + KMessageBox::information( widget(), i18n( "No application found for opening file of mimetype %1." ).arg( mime->name() ) ); } break; case KPDFLink::Action: { diff --git a/core/document.h b/core/document.h index 0adb03109..8e4c1d8ec 100644 --- a/core/document.h +++ b/core/document.h @@ -51,7 +51,7 @@ class KPDFDocument : public QObject { Q_OBJECT public: - KPDFDocument(); + KPDFDocument( QWidget *widget ); ~KPDFDocument(); // document handling @@ -66,6 +66,9 @@ class KPDFDocument : public QObject // enum definitions enum Permission { AllowModify = 1, AllowCopy = 2, AllowPrint = 4, AllowNotes = 8 }; + // returns the widget where the document is shown + QWidget *widget() const; + // query methods (const ones) bool isOpened() const; const DocumentInfo * documentInfo() const; diff --git a/core/generator_pdf/generator_pdf.cpp b/core/generator_pdf/generator_pdf.cpp index 0067d8c17..d46cc121d 100644 --- a/core/generator_pdf/generator_pdf.cpp +++ b/core/generator_pdf/generator_pdf.cpp @@ -466,7 +466,7 @@ bool PDFGenerator::print( KPrinter& printer ) double yScale = ((double)paperHeight - (double)marginBottom - (double)marginTop) / (double)paperHeight; if ( abs((int)(xScale * 100) - (int)(yScale * 100)) > 5 ) { - int result = KMessageBox::questionYesNo(0, + int result = KMessageBox::questionYesNo(m_document->widget(), i18n("The margins you specified change the page aspect ratio. Do you want to print with the aspect ratio changed or do you want the margins to be adapted so that the aspect ratio is preserved?"), i18n("Aspect ratio change"), i18n("Print with specified margins"), diff --git a/part.cpp b/part.cpp index 4e3e755cd..a99122e92 100644 --- a/part.cpp +++ b/part.cpp @@ -110,7 +110,7 @@ Part::Part(QWidget *parentWidget, const char *widgetName, setInstance(KPDFPartFactory::instance()); // build the document - m_document = new KPDFDocument(); + m_document = new KPDFDocument(widget()); connect( m_document, SIGNAL( linkFind() ), this, SLOT( slotFind() ) ); connect( m_document, SIGNAL( linkGoToPage() ), this, SLOT( slotGoToPage() ) ); connect( m_document, SIGNAL( linkPresentation() ), this, SLOT( slotShowPresentation() ) );