File indexing completed on 2024-03-24 16:04:11

0001 /*
0002     SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "phpdocumentationwidget.h"
0008 
0009 #include <QProgressBar>
0010 #include <QLabel>
0011 #include <QVBoxLayout>
0012 #include <QUrl>
0013 
0014 #include <KLocalizedString>
0015 
0016 #include "phpdocsplugin.h"
0017 #include <documentation/standarddocumentationview.h>
0018 
0019 PhpDocumentationWidget::PhpDocumentationWidget(KDevelop::DocumentationFindWidget* find, const QUrl &url,
0020                                                PhpDocsPlugin* provider, QWidget* parent)
0021 : QStackedWidget(parent)
0022 , m_loading(new QWidget(this))
0023 , m_provider(provider)
0024 {
0025     m_part = new KDevelop::StandardDocumentationView(find, this);
0026     m_part->setDelegateLinks(true);
0027     addWidget(m_part);
0028     addWidget(m_loading);
0029 
0030     auto* progressbar = new QProgressBar;
0031     progressbar->setValue(0);
0032     progressbar->setMinimum(0);
0033     progressbar->setMaximum(100);
0034     progressbar->setAlignment(Qt::AlignCenter);
0035 
0036 // temporary disabled for initial porting to QWidget-only StandardDocumentationView
0037 #if 0
0038     connect( m_part, &KDevelop::StandardDocumentationView::loadProgress,
0039              progressbar, &QProgressBar::setValue );
0040 #endif
0041 
0042     auto* layout = new QVBoxLayout;
0043     layout->addStretch();
0044     QLabel* label = new QLabel(i18n("...loading documentation..."));
0045     label->setAlignment(Qt::AlignCenter);
0046     layout->addWidget(label);
0047     layout->addWidget(progressbar);
0048     layout->addStretch();
0049     m_loading->setLayout(layout);
0050 // temporary disabled for initial porting to QWidget-only StandardDocumentationView
0051 #if 0
0052     setCurrentWidget(m_loading);
0053 #endif
0054 // instead directly show part
0055     setCurrentWidget(m_part);
0056 
0057 
0058     connect(m_part, &KDevelop::StandardDocumentationView::linkClicked, this, &PhpDocumentationWidget::linkClicked);
0059 // temporary disabled for initial porting to QWidget-only StandardDocumentationView
0060 #if 0
0061     connect(m_part, &KDevelop::StandardDocumentationView::loadFinished, this, &PhpDocumentationWidget::documentLoaded);
0062 #endif
0063     m_part->load( url );
0064 }
0065 
0066 PhpDocumentationWidget::~PhpDocumentationWidget()
0067 {
0068     // make sure we don't get called by any of the m_part signals on shutdown, see also:
0069     // https://codereview.qt-project.org/#/c/83800/
0070     disconnect(m_part, nullptr, this, nullptr);
0071 }
0072 
0073 void PhpDocumentationWidget::linkClicked(const QUrl& url)
0074 {
0075     m_provider->showDocumentation(url);
0076 }
0077 
0078 void PhpDocumentationWidget::documentLoaded()
0079 {
0080     setCurrentWidget(m_part);
0081     removeWidget(m_loading);
0082     delete m_loading;
0083     m_loading = nullptr;
0084 }
0085 
0086 #include "moc_phpdocumentationwidget.cpp"