File indexing completed on 2024-05-12 04:38:18

0001 /*
0002     SPDX-FileCopyrightText: 2008 Cédric Pasteur <cedric.pasteur@free.fr>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_EDITSTYLEDIALOG_H
0008 #define KDEVPLATFORM_EDITSTYLEDIALOG_H
0009 
0010 #include <QMimeType>
0011 #include <QDialog>
0012 #include <interfaces/isourceformatter.h>
0013 #include "ui_editstyledialog.h"
0014 
0015 namespace KTextEditor {
0016 class Document;
0017 class View;
0018 }
0019 namespace KDevelop {
0020 class ISourceFormatter;
0021 class SettingsWidget;
0022 class SourceFormatterStyle;
0023 }
0024 
0025 /** \short A simple dialog to add preview around a \ref SettingsWidget
0026  */
0027 class EditStyleDialog
0028     : public QDialog
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     /**
0034      * @pre @p formatter.hasEditStyleWidget() == @c true
0035      */
0036     EditStyleDialog(const KDevelop::ISourceFormatter& formatter, const QMimeType& mime,
0037                     const KDevelop::SourceFormatterStyle&, QWidget* parent = nullptr);
0038     ~EditStyleDialog() override;
0039 
0040     /** \return The string representing the style given by the \ref SettingsWidget.
0041      */
0042     QString content() const;
0043 
0044     /**
0045      * @return whether the style uses preview
0046      */
0047     bool usePreview() const;
0048 
0049 private Q_SLOTS:
0050     void updatePreviewText(const QString &text);
0051 
0052 private:
0053     void init();
0054     void initPreview();
0055     void showPreview(const QString& text);
0056     void previewVisibilityChanged(bool visible);
0057 
0058     const KDevelop::ISourceFormatter& m_sourceFormatter;
0059     KTextEditor::View* m_view = nullptr;
0060     KTextEditor::Document* m_document = nullptr;
0061     /// the settings widget becomes valid in constructor, never changes afterwards
0062     KDevelop::SettingsWidget* m_settingsWidget;
0063     const QMimeType m_mimeType;
0064     QString m_pendingPreviewText; ///< if empty, m_document->text() is up to date
0065     Ui::EditStyle m_ui;
0066     KDevelop::SourceFormatterStyle m_style;
0067 };
0068 
0069 #endif // KDEVPLATFORM_EDITSTYLEDIALOG_H