From f9ae7c2bc668cb94df975dfea0ec3ce08993b733 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 27 Jul 2022 12:57:49 +0200 Subject: [PATCH] TextEditor: inline highlightersettingspage.ui Change-Id: Icc4b2fe7013f2ebb2eb57cc5f581798c87866ff5 Reviewed-by: Alessandro Portale Reviewed-by: --- src/plugins/texteditor/CMakeLists.txt | 2 +- .../texteditor/highlightersettingspage.cpp | 164 +++++++++----- .../texteditor/highlightersettingspage.h | 10 +- .../texteditor/highlightersettingspage.ui | 202 ------------------ src/plugins/texteditor/texteditor.qbs | 1 - 5 files changed, 119 insertions(+), 260 deletions(-) delete mode 100644 src/plugins/texteditor/highlightersettingspage.ui diff --git a/src/plugins/texteditor/CMakeLists.txt b/src/plugins/texteditor/CMakeLists.txt index b04c56dafe1..14a20e0d847 100644 --- a/src/plugins/texteditor/CMakeLists.txt +++ b/src/plugins/texteditor/CMakeLists.txt @@ -62,7 +62,7 @@ add_qtc_plugin(TextEditor formattexteditor.cpp formattexteditor.h highlighter.cpp highlighter.h highlightersettings.cpp highlightersettings.h - highlightersettingspage.cpp highlightersettingspage.h highlightersettingspage.ui + highlightersettingspage.cpp highlightersettingspage.h icodestylepreferences.cpp icodestylepreferences.h icodestylepreferencesfactory.cpp icodestylepreferencesfactory.h indenter.h diff --git a/src/plugins/texteditor/highlightersettingspage.cpp b/src/plugins/texteditor/highlightersettingspage.cpp index c571308c83f..5724304a068 100644 --- a/src/plugins/texteditor/highlightersettingspage.cpp +++ b/src/plugins/texteditor/highlightersettingspage.cpp @@ -24,23 +24,110 @@ ****************************************************************************/ #include "highlightersettingspage.h" + #include "highlightersettings.h" #include "highlighter.h" -#include "ui_highlightersettingspage.h" #include -#include +#include +#include +#include + +#include #include +#include +#include #include #include +#include using namespace TextEditor::Internal; using namespace Utils; namespace TextEditor { +namespace Internal { -class HighlighterSettingsPage::HighlighterSettingsPagePrivate +class HighlighterSettingsPageWidget : public QWidget +{ +public: + QLabel *definitionsInfolabel; + QPushButton *downloadDefinitions; + QLabel *updateStatus; + PathChooser *definitionFilesPath; + QPushButton *reloadDefinitions; + QPushButton *resetCache; + QLineEdit *ignoreEdit; + + HighlighterSettingsPageWidget() + { + resize(521, 332); + + definitionsInfolabel = new QLabel(this); + definitionsInfolabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + definitionsInfolabel->setTextFormat(Qt::RichText); + definitionsInfolabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + definitionsInfolabel->setWordWrap(true); + definitionsInfolabel->setOpenExternalLinks(true); + definitionsInfolabel->setText(tr("

Highlight definitions are provided by the " + "" + "KSyntaxHighlighting engine.

")); + + downloadDefinitions = new QPushButton(tr("Download Definitions")); + downloadDefinitions->setToolTip(tr("Download missing and update existing syntax definition files.")); + + updateStatus = new QLabel; + + definitionFilesPath = new PathChooser; + definitionFilesPath->setExpectedKind(PathChooser::ExistingDirectory); + definitionFilesPath->setHistoryCompleter("TextEditor.Highlighter.History"); + + reloadDefinitions = new QPushButton(tr("Reload Definitions")); + reloadDefinitions->setToolTip(tr("Reload externally modified definition files.")); + + resetCache = new QPushButton(tr("Reset Remembered Definitions")); + resetCache->setToolTip(tr("Reset definitions remembered for files that can be " + "associated with more than one highlighter definition.")); + + ignoreEdit = new QLineEdit; + + using namespace Layouting; + Column { + definitionsInfolabel, + Space(3), + Group { + title(tr("Syntax Highlight Definition Files")), + Column { + Row { downloadDefinitions, updateStatus, st }, + Row { tr("User Highlight Definition Files"), + definitionFilesPath, reloadDefinitions }, + Row { st, resetCache } + } + }, + Row { tr("Ignored file patterns:"), ignoreEdit }, + st + }.attachTo(this); + + connect(downloadDefinitions, &QPushButton::pressed, + [label = QPointer(updateStatus)]() { + Highlighter::downloadDefinitions([label] { + if (label) + label->setText(tr("Download finished")); + }); + }); + + connect(reloadDefinitions, &QPushButton::pressed, this, [] { + Highlighter::reload(); + }); + connect(resetCache, &QPushButton::clicked, this, [] { + Highlighter::clearDefinitionForDocumentCache(); + }); + } +}; + +} // Internal + +class HighlighterSettingsPagePrivate { Q_DECLARE_TR_FUNCTIONS(TextEditor::Internal::HighlighterSettingsPage) @@ -50,17 +137,20 @@ public: void ensureInitialized(); void migrateGenericHighlighterFiles(); + void settingsFromUI(); + void settingsToUI(); + bool settingsChanged(); + bool m_initialized = false; const QString m_settingsPrefix{"Text"}; HighlighterSettings m_settings; - QPointer m_widget; - Ui::HighlighterSettingsPage *m_page = nullptr; + QPointer m_widget; }; -void HighlighterSettingsPage::HighlighterSettingsPagePrivate::migrateGenericHighlighterFiles() +void HighlighterSettingsPagePrivate::migrateGenericHighlighterFiles() { QDir userDefinitionPath(m_settings.definitionFilesPath().toString()); if (userDefinitionPath.mkdir("syntax")) { @@ -73,7 +163,7 @@ void HighlighterSettingsPage::HighlighterSettingsPagePrivate::migrateGenericHigh } } -void HighlighterSettingsPage::HighlighterSettingsPagePrivate::ensureInitialized() +void HighlighterSettingsPagePrivate::ensureInitialized() { if (m_initialized) return; @@ -100,46 +190,24 @@ HighlighterSettingsPage::~HighlighterSettingsPage() QWidget *HighlighterSettingsPage::widget() { if (!d->m_widget) { - d->m_widget = new QWidget; - d->m_page = new Ui::HighlighterSettingsPage; - d->m_page->setupUi(d->m_widget); - d->m_page->definitionFilesPath->setExpectedKind(Utils::PathChooser::ExistingDirectory); - d->m_page->definitionFilesPath->setHistoryCompleter(QLatin1String("TextEditor.Highlighter.History")); - connect(d->m_page->downloadDefinitions, - &QPushButton::pressed, - [label = QPointer(d->m_page->updateStatus)]() { - Highlighter::downloadDefinitions([label](){ - if (label) - label->setText(HighlighterSettingsPagePrivate::tr("Download finished")); - }); - }); - connect(d->m_page->reloadDefinitions, &QPushButton::pressed, []() { - Highlighter::reload(); - }); - connect(d->m_page->resetCache, &QPushButton::clicked, []() { - Highlighter::clearDefinitionForDocumentCache(); - }); - - settingsToUI(); + d->m_widget = new HighlighterSettingsPageWidget; + d->settingsToUI(); } return d->m_widget; } void HighlighterSettingsPage::apply() { - if (!d->m_page) // page was not shown + if (!d->m_widget) // page was not shown return; - if (settingsChanged()) - settingsFromUI(); + if (d->settingsChanged()) + d->settingsFromUI(); } void HighlighterSettingsPage::finish() { delete d->m_widget; - if (!d->m_page) // page was not shown - return; - delete d->m_page; - d->m_page = nullptr; + d->m_widget = nullptr; } const HighlighterSettings &HighlighterSettingsPage::highlighterSettings() const @@ -148,26 +216,26 @@ const HighlighterSettings &HighlighterSettingsPage::highlighterSettings() const return d->m_settings; } -void HighlighterSettingsPage::settingsFromUI() +void HighlighterSettingsPagePrivate::settingsFromUI() { - d->ensureInitialized(); - d->m_settings.setDefinitionFilesPath(d->m_page->definitionFilesPath->filePath()); - d->m_settings.setIgnoredFilesPatterns(d->m_page->ignoreEdit->text()); - d->m_settings.toSettings(d->m_settingsPrefix, Core::ICore::settings()); + ensureInitialized(); + m_settings.setDefinitionFilesPath(m_widget->definitionFilesPath->filePath()); + m_settings.setIgnoredFilesPatterns(m_widget->ignoreEdit->text()); + m_settings.toSettings(m_settingsPrefix, Core::ICore::settings()); } -void HighlighterSettingsPage::settingsToUI() +void HighlighterSettingsPagePrivate::settingsToUI() { - d->ensureInitialized(); - d->m_page->definitionFilesPath->setFilePath(d->m_settings.definitionFilesPath()); - d->m_page->ignoreEdit->setText(d->m_settings.ignoredFilesPatterns()); + ensureInitialized(); + m_widget->definitionFilesPath->setFilePath(m_settings.definitionFilesPath()); + m_widget->ignoreEdit->setText(m_settings.ignoredFilesPatterns()); } -bool HighlighterSettingsPage::settingsChanged() const +bool HighlighterSettingsPagePrivate::settingsChanged() { - d->ensureInitialized(); - return d->m_settings.definitionFilesPath() != d->m_page->definitionFilesPath->filePath() - || d->m_settings.ignoredFilesPatterns() != d->m_page->ignoreEdit->text(); + ensureInitialized(); + return m_settings.definitionFilesPath() != m_widget->definitionFilesPath->filePath() + || m_settings.ignoredFilesPatterns() != m_widget->ignoreEdit->text(); } } // TextEditor diff --git a/src/plugins/texteditor/highlightersettingspage.h b/src/plugins/texteditor/highlightersettingspage.h index d9a491db1c5..deb0aa83948 100644 --- a/src/plugins/texteditor/highlightersettingspage.h +++ b/src/plugins/texteditor/highlightersettingspage.h @@ -44,13 +44,7 @@ public: const HighlighterSettings &highlighterSettings() const; private: - void settingsFromUI(); - void settingsToUI(); - - bool settingsChanged() const; - - class HighlighterSettingsPagePrivate; - HighlighterSettingsPagePrivate *d; + class HighlighterSettingsPagePrivate *d; }; -} // namespace TextEditor +} // TextEditor diff --git a/src/plugins/texteditor/highlightersettingspage.ui b/src/plugins/texteditor/highlightersettingspage.ui deleted file mode 100644 index 5bd32a8a87b..00000000000 --- a/src/plugins/texteditor/highlightersettingspage.ui +++ /dev/null @@ -1,202 +0,0 @@ - - - TextEditor::Internal::HighlighterSettingsPage - - - - 0 - 0 - 521 - 332 - - - - - - - - - - - 0 - 0 - - - - <html><head/><body><p>Highlight definitions are provided by the <a href="https://api.kde.org/frameworks/syntax-highlighting/html/index.html">KSyntaxHighlighting</a> engine.</p></body></html> - - - Qt::RichText - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - true - - - true - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 3 - - - - - - - - Syntax Highlight Definition Files - - - - - - - - Download missing and update existing syntax definition files. - - - Download Definitions - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - User Highlight Definition Files - - - - - - - - - - - - Reload externally modified definition files. - - - Reload Definitions - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Reset definitions remembered for files that can be associated with more than one highlighter definition. - - - Reset Remembered Definitions - - - - - - - - - - - - - - Ignored file patterns: - - - - - - - - - - - - Qt::Vertical - - - - 20 - 117 - - - - - - - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 - - editingFinished() - browsingFinished() - -
-
- - ignoreEdit - - - -
diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs index aa07aeaf98d..7fd4fc925be 100644 --- a/src/plugins/texteditor/texteditor.qbs +++ b/src/plugins/texteditor/texteditor.qbs @@ -82,7 +82,6 @@ Project { "highlightersettings.h", "highlightersettingspage.cpp", "highlightersettingspage.h", - "highlightersettingspage.ui", "icodestylepreferences.cpp", "icodestylepreferences.h", "icodestylepreferencesfactory.cpp",