File indexing completed on 2024-04-28 04:37:54

0001 /*
0002     SPDX-FileCopyrightText: 2008 Cédric Pasteur <cedric.pasteur@free.fr>
0003     SPDX-FileCopyrightText: 2001 Matthias Hölzer-Klüpfel <mhk@caldera.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef ASTYLEPLUGIN_H
0009 #define ASTYLEPLUGIN_H
0010 
0011 #include "astyle_preferences.h"
0012 
0013 #include <interfaces/iplugin.h>
0014 #include <interfaces/isourceformatter.h>
0015 
0016 class AStyleFormatter;
0017 
0018 class AStylePlugin : public KDevelop::IPlugin, public KDevelop::ISourceFormatter
0019 {
0020     Q_OBJECT
0021     Q_INTERFACES(KDevelop::ISourceFormatter)
0022 
0023 public:
0024     explicit AStylePlugin(QObject *parent, const QVariantList & = QVariantList());
0025     ~AStylePlugin() override;
0026 
0027     QString name() const override;
0028     QString caption() const override;
0029     QString description() const override;
0030 
0031     /** \return A map of predefined styles (a key and a caption for each type)
0032     */
0033     QVector<KDevelop::SourceFormatterStyle> predefinedStyles() const override;
0034 
0035     bool hasEditStyleWidget() const override;
0036 
0037     /** \return The widget to edit a style.
0038     */
0039     KDevelop::SettingsWidgetPtr editStyleWidget(const QMimeType& mime) const override;
0040 
0041     QString formatSourceWithStyle(const KDevelop::SourceFormatterStyle& style,
0042                                   const QString& text,
0043                                   const QUrl &url,
0044                                   const QMimeType& mime,
0045                                   const QString& leftContext = QString(),
0046                                   const QString& rightContext = QString()) const override;
0047 
0048     /** \return The text used in the config dialog to preview the current style.
0049     */
0050     QString previewText(const KDevelop::SourceFormatterStyle& style, const QMimeType& mime) const override;
0051 
0052     Indentation indentation(const KDevelop::SourceFormatterStyle& style, const QUrl& url,
0053                             const QMimeType& mime) const override;
0054 
0055     static QString formattingSample(AStylePreferences::Language lang);
0056     static QString indentingSample(AStylePreferences::Language lang);
0057 
0058 private:
0059     QScopedPointer<AStyleFormatter> m_formatter;
0060 };
0061 
0062 #endif // ASTYLEPLUGIN_H