forked from qt-creator/qt-creator
Beautifier: Inline configurationdialog.ui
This slightly changes the setup by removing the horizontal splitter which does not really serve a good purpose on a freely resizable top-level dialog. Change-Id: I1ba418dc9173af54aadab5e98144673b55544e8f Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -15,7 +15,7 @@ add_qtc_plugin(Beautifier
|
||||
clangformat/clangformatconstants.h
|
||||
clangformat/clangformatoptionspage.cpp clangformat/clangformatoptionspage.h
|
||||
clangformat/clangformatsettings.cpp clangformat/clangformatsettings.h
|
||||
configurationdialog.cpp configurationdialog.h configurationdialog.ui
|
||||
configurationdialog.cpp configurationdialog.h
|
||||
configurationeditor.cpp configurationeditor.h
|
||||
configurationpanel.cpp configurationpanel.h
|
||||
generaloptionspage.cpp generaloptionspage.h
|
||||
|
@@ -20,7 +20,6 @@ QtcPlugin {
|
||||
"beautifierplugin.h",
|
||||
"configurationdialog.cpp",
|
||||
"configurationdialog.h",
|
||||
"configurationdialog.ui",
|
||||
"configurationeditor.cpp",
|
||||
"configurationeditor.h",
|
||||
"configurationpanel.cpp",
|
||||
|
@@ -24,34 +24,73 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "configurationdialog.h"
|
||||
#include "ui_configurationdialog.h"
|
||||
|
||||
#include "abstractsettings.h"
|
||||
#include "configurationeditor.h"
|
||||
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QSplitter>
|
||||
#include <QTextEdit>
|
||||
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
namespace Beautifier::Internal {
|
||||
|
||||
ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ConfigurationDialog)
|
||||
ConfigurationDialog::ConfigurationDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
resize(640, 512);
|
||||
|
||||
m_name = new QLineEdit;
|
||||
|
||||
m_editor = new ConfigurationEditor;
|
||||
|
||||
m_documentationHeader = new QLabel;
|
||||
|
||||
m_documentation = new QTextEdit;
|
||||
m_documentation->setReadOnly(true);
|
||||
|
||||
m_buttonBox = new QDialogButtonBox(this);
|
||||
m_buttonBox->setOrientation(Qt::Horizontal);
|
||||
m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||
|
||||
using namespace Utils::Layouting;
|
||||
|
||||
Column {
|
||||
Group {
|
||||
Title(tr("Name")),
|
||||
Column { m_name }
|
||||
},
|
||||
Group {
|
||||
Title(tr("Value")),
|
||||
Column {
|
||||
m_editor,
|
||||
m_documentationHeader,
|
||||
m_documentation
|
||||
}
|
||||
},
|
||||
m_buttonBox
|
||||
}.attachTo(this);
|
||||
|
||||
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
// Filter out characters which are not allowed in a file name
|
||||
QRegularExpressionValidator *fileNameValidator = new QRegularExpressionValidator(
|
||||
QRegularExpression("^[^\\/\\\\\\?\\>\\<\\*\\%\\:\\\"\\']*$"), ui->name);
|
||||
ui->name->setValidator(fileNameValidator);
|
||||
QRegularExpression("^[^\\/\\\\\\?\\>\\<\\*\\%\\:\\\"\\']*$"), m_name);
|
||||
m_name->setValidator(fileNameValidator);
|
||||
|
||||
updateDocumentation();
|
||||
connect(ui->name, &QLineEdit::textChanged, this, &ConfigurationDialog::updateOkButton);
|
||||
connect(m_name, &QLineEdit::textChanged, this, &ConfigurationDialog::updateOkButton);
|
||||
updateOkButton(); // force initial test.
|
||||
connect(ui->editor, &ConfigurationEditor::documentationChanged,
|
||||
connect(m_editor, &ConfigurationEditor::documentationChanged,
|
||||
this, &ConfigurationDialog::updateDocumentation);
|
||||
|
||||
// Set palette and font according to settings
|
||||
@@ -66,11 +105,11 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
|
||||
if (selectionFormat.background().style() != Qt::NoBrush)
|
||||
pal.setColor(QPalette::Highlight, selectionFormat.background().color());
|
||||
pal.setBrush(QPalette::HighlightedText, selectionFormat.foreground());
|
||||
ui->documentation->setPalette(pal);
|
||||
ui->editor->setPalette(pal);
|
||||
m_documentation->setPalette(pal);
|
||||
m_editor->setPalette(pal);
|
||||
|
||||
ui->documentation->setFont(tf.font());
|
||||
ui->editor->setFont(tf.font());
|
||||
m_documentation->setFont(tf.font());
|
||||
m_editor->setFont(tf.font());
|
||||
|
||||
// Set style sheet for documentation browser
|
||||
const QTextCharFormat tfOption = fs.toTextCharFormat(TextEditor::C_FIELD);
|
||||
@@ -85,63 +124,59 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
|
||||
.arg(tfOption.foreground().color().name())
|
||||
.arg(tfOption.background().style() == Qt::NoBrush
|
||||
? QString() : tfOption.background().color().name());
|
||||
ui->documentation->document()->setDefaultStyleSheet(css);
|
||||
m_documentation->document()->setDefaultStyleSheet(css);
|
||||
}
|
||||
|
||||
ConfigurationDialog::~ConfigurationDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
ConfigurationDialog::~ConfigurationDialog() = default;
|
||||
|
||||
void ConfigurationDialog::setSettings(AbstractSettings *settings)
|
||||
{
|
||||
m_settings = settings;
|
||||
ui->editor->setSettings(m_settings);
|
||||
m_editor->setSettings(m_settings);
|
||||
}
|
||||
|
||||
void ConfigurationDialog::clear()
|
||||
{
|
||||
ui->name->clear();
|
||||
ui->editor->clear();
|
||||
m_name->clear();
|
||||
m_editor->clear();
|
||||
m_currentKey.clear();
|
||||
updateOkButton();
|
||||
}
|
||||
|
||||
QString ConfigurationDialog::key() const
|
||||
{
|
||||
return ui->name->text().simplified();
|
||||
return m_name->text().simplified();
|
||||
}
|
||||
|
||||
void ConfigurationDialog::setKey(const QString &key)
|
||||
{
|
||||
m_currentKey = key;
|
||||
ui->name->setText(m_currentKey);
|
||||
m_name->setText(m_currentKey);
|
||||
if (m_settings)
|
||||
ui->editor->setPlainText(m_settings->style(m_currentKey));
|
||||
m_editor->setPlainText(m_settings->style(m_currentKey));
|
||||
else
|
||||
ui->editor->clear();
|
||||
m_editor->clear();
|
||||
}
|
||||
|
||||
QString ConfigurationDialog::value() const
|
||||
{
|
||||
return ui->editor->toPlainText();
|
||||
return m_editor->toPlainText();
|
||||
}
|
||||
|
||||
void ConfigurationDialog::updateOkButton()
|
||||
{
|
||||
const QString key = ui->name->text().simplified();
|
||||
const QString key = m_name->text().simplified();
|
||||
const bool exists = m_settings && key != m_currentKey && m_settings->styleExists(key);
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!(key.isEmpty() || exists));
|
||||
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!(key.isEmpty() || exists));
|
||||
}
|
||||
|
||||
void ConfigurationDialog::updateDocumentation(const QString &word, const QString &docu)
|
||||
{
|
||||
if (word.isEmpty())
|
||||
ui->documentationHeader->setText(tr("Documentation"));
|
||||
m_documentationHeader->setText(tr("Documentation"));
|
||||
else
|
||||
ui->documentationHeader->setText(tr("Documentation for \"%1\"").arg(word));
|
||||
ui->documentation->setHtml(docu);
|
||||
m_documentationHeader->setText(tr("Documentation for \"%1\"").arg(word));
|
||||
m_documentation->setHtml(docu);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Beautifier
|
||||
} // Beautifier::Internal
|
||||
|
@@ -26,13 +26,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDialogButtonBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QTextEdit;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Beautifier::Internal {
|
||||
|
||||
class AbstractSettings;
|
||||
namespace Ui { class ConfigurationDialog; }
|
||||
class ConfigurationEditor;
|
||||
|
||||
class ConfigurationDialog : public QDialog
|
||||
{
|
||||
@@ -51,11 +56,15 @@ public:
|
||||
private:
|
||||
void updateOkButton();
|
||||
void updateDocumentation(const QString &word = QString(), const QString &docu = QString());
|
||||
Ui::ConfigurationDialog *ui;
|
||||
|
||||
AbstractSettings *m_settings = nullptr;
|
||||
QString m_currentKey;
|
||||
|
||||
QLineEdit *m_name;
|
||||
ConfigurationEditor *m_editor;
|
||||
QLabel *m_documentationHeader;
|
||||
QTextEdit *m_documentation;
|
||||
QDialogButtonBox *m_buttonBox;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Beautifier
|
||||
} // Beautifier::Internal
|
||||
|
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Beautifier::Internal::ConfigurationDialog</class>
|
||||
<widget class="QDialog" name="Beautifier::Internal::ConfigurationDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>512</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="childrenCollapsible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="Beautifier::Internal::ConfigurationEditor" name="editor"/>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="documentationHeader">
|
||||
<property name="text">
|
||||
<string>Documentation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="documentation">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Beautifier::Internal::ConfigurationEditor</class>
|
||||
<extends>QPlainTextEdit</extends>
|
||||
<header location="global">beautifier/configurationeditor.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Beautifier::Internal::ConfigurationDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Beautifier::Internal::ConfigurationDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Reference in New Issue
Block a user