mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-23 07:16:15 +00:00
Changed: #1302 Added text edit property in qt property browser for NLLIGO::CPropertyStringArray.
This commit is contained in:
parent
3d1d9d3fca
commit
83db0f0adf
6 changed files with 285 additions and 0 deletions
|
@ -101,6 +101,13 @@
|
|||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QColorDialog>
|
||||
#include <QtGui/QFontDialog>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
#include <QtGui/QTextEdit>
|
||||
#include <QCompleter>
|
||||
#include <QColumnView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QtGui/QDialogButtonBox>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QtCore/QMap>
|
||||
|
||||
|
@ -2601,6 +2608,231 @@ void QtFontEditorFactory::disconnectPropertyManager(QtFontPropertyManager *manag
|
|||
disconnect(manager, SIGNAL(valueChanged(QtProperty*,QFont)), this, SLOT(slotPropertyChanged(QtProperty*,QFont)));
|
||||
}
|
||||
|
||||
class QtTextEditWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtTextEditWidget(QWidget *parent);
|
||||
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setValue(const QString &value);
|
||||
|
||||
private Q_SLOTS:
|
||||
void buttonClicked();
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged(const QString &value);
|
||||
|
||||
private:
|
||||
QLineEdit *m_lineEdit;
|
||||
QToolButton *m_defaultButton;
|
||||
QToolButton *m_button;
|
||||
};
|
||||
|
||||
QtTextEditWidget::QtTextEditWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_lineEdit(new QLineEdit),
|
||||
m_defaultButton(new QToolButton),
|
||||
m_button(new QToolButton)
|
||||
{
|
||||
QHBoxLayout *lt = new QHBoxLayout(this);
|
||||
lt->setContentsMargins(0, 0, 0, 0);
|
||||
lt->setSpacing(0);
|
||||
lt->addWidget(m_lineEdit);
|
||||
m_lineEdit->setReadOnly(true);
|
||||
|
||||
m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
|
||||
m_button->setFixedWidth(20);
|
||||
setFocusProxy(m_button);
|
||||
setFocusPolicy(m_button->focusPolicy());
|
||||
m_button->setText(tr("..."));
|
||||
m_button->installEventFilter(this);
|
||||
connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
||||
lt->addWidget(m_button);
|
||||
lt->addWidget(m_defaultButton);
|
||||
m_defaultButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void QtTextEditWidget::setValue(const QString &value)
|
||||
{
|
||||
if (m_lineEdit->text() != value)
|
||||
m_lineEdit->setText(value);
|
||||
}
|
||||
|
||||
void QtTextEditWidget::buttonClicked()
|
||||
{
|
||||
QGridLayout *gridLayout;
|
||||
QPlainTextEdit *plainTextEdit;
|
||||
QDialogButtonBox *buttonBox;
|
||||
QDialog *dialog;
|
||||
|
||||
dialog = new QDialog(this);
|
||||
dialog->resize(400, 300);
|
||||
gridLayout = new QGridLayout(dialog);
|
||||
plainTextEdit = new QPlainTextEdit(dialog);
|
||||
|
||||
gridLayout->addWidget(plainTextEdit, 0, 0, 1, 1);
|
||||
|
||||
buttonBox = new QDialogButtonBox(dialog);
|
||||
buttonBox->setOrientation(Qt::Horizontal);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||
|
||||
gridLayout->addWidget(buttonBox, 1, 0, 1, 1);
|
||||
|
||||
QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
|
||||
QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||
|
||||
plainTextEdit->textCursor().insertText(m_lineEdit->text());
|
||||
|
||||
dialog->setModal(true);
|
||||
dialog->show();
|
||||
int result = dialog->exec();
|
||||
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
QString newText = plainTextEdit->document()->toPlainText();
|
||||
|
||||
setValue(newText);
|
||||
if (plainTextEdit->document()->isModified())
|
||||
Q_EMIT valueChanged(newText);
|
||||
}
|
||||
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
bool QtTextEditWidget::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if (obj == m_button) {
|
||||
switch (ev->type()) {
|
||||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate
|
||||
switch (static_cast<const QKeyEvent*>(ev)->key()) {
|
||||
case Qt::Key_Escape:
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
ev->ignore();
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return QWidget::eventFilter(obj, ev);
|
||||
}
|
||||
|
||||
// QtLineEditFactory
|
||||
|
||||
class QtTextEditorFactoryPrivate : public EditorFactoryPrivate<QtTextEditWidget>
|
||||
{
|
||||
QtTextEditorFactory *q_ptr;
|
||||
Q_DECLARE_PUBLIC(QtTextEditorFactory)
|
||||
public:
|
||||
|
||||
void slotPropertyChanged(QtProperty *property, const QString &value);
|
||||
void slotSetValue(const QString &value);
|
||||
};
|
||||
|
||||
void QtTextEditorFactoryPrivate::slotPropertyChanged(QtProperty *property,
|
||||
const QString &value)
|
||||
{
|
||||
const PropertyToEditorListMap::iterator it = m_createdEditors.find(property);
|
||||
if (it == m_createdEditors.end())
|
||||
return;
|
||||
QListIterator<QtTextEditWidget *> itEditor(it.value());
|
||||
|
||||
while (itEditor.hasNext())
|
||||
itEditor.next()->setValue(value);
|
||||
}
|
||||
|
||||
void QtTextEditorFactoryPrivate::slotSetValue(const QString &value)
|
||||
{
|
||||
QObject *object = q_ptr->sender();
|
||||
const EditorToPropertyMap::ConstIterator ecend = m_editorToProperty.constEnd();
|
||||
for (EditorToPropertyMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor)
|
||||
if (itEditor.key() == object) {
|
||||
QtProperty *property = itEditor.value();
|
||||
QtTextPropertyManager *manager = q_ptr->propertyManager(property);
|
||||
if (!manager)
|
||||
return;
|
||||
manager->setValue(property, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*!
|
||||
\class QtTextEditFactory
|
||||
|
||||
\brief The QtTextEditFactory class provides QTextEdit widgets for
|
||||
properties created by QtStringPropertyManager objects.
|
||||
|
||||
\sa QtAbstractEditorFactory, QtStringPropertyManager
|
||||
*/
|
||||
|
||||
/*!
|
||||
Creates a factory with the given \a parent.
|
||||
*/
|
||||
QtTextEditorFactory::QtTextEditorFactory(QObject *parent)
|
||||
: QtAbstractEditorFactory<QtTextPropertyManager>(parent)
|
||||
{
|
||||
d_ptr = new QtTextEditorFactoryPrivate();
|
||||
d_ptr->q_ptr = this;
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
Destroys this factory, and all the widgets it has created.
|
||||
*/
|
||||
QtTextEditorFactory::~QtTextEditorFactory()
|
||||
{
|
||||
qDeleteAll(d_ptr->m_editorToProperty.keys());
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Reimplemented from the QtAbstractEditorFactory class.
|
||||
*/
|
||||
void QtTextEditorFactory::connectPropertyManager(QtTextPropertyManager *manager)
|
||||
{
|
||||
connect(manager, SIGNAL(valueChanged(QtProperty *, const QString &)),
|
||||
this, SLOT(slotPropertyChanged(QtProperty *, const QString &)));
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Reimplemented from the QtAbstractEditorFactory class.
|
||||
*/
|
||||
QWidget *QtTextEditorFactory::createEditor(QtTextPropertyManager *manager,
|
||||
QtProperty *property, QWidget *parent)
|
||||
{
|
||||
|
||||
QtTextEditWidget *editor = d_ptr->createEditor(property, parent);
|
||||
|
||||
editor->setValue(manager->value(property));
|
||||
|
||||
connect(editor, SIGNAL(valueChanged(QString)), this, SLOT(slotSetValue(QString)));
|
||||
connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *)));
|
||||
return editor;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Reimplemented from the QtAbstractEditorFactory class.
|
||||
*/
|
||||
void QtTextEditorFactory::disconnectPropertyManager(QtTextPropertyManager *manager)
|
||||
{
|
||||
disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QString &)),
|
||||
this, SLOT(slotPropertyChanged(QtProperty *, const QString &)));
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x040400
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
|
|
@ -441,6 +441,28 @@ private:
|
|||
Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QFont &))
|
||||
};
|
||||
|
||||
class QtTextEditorFactoryPrivate;
|
||||
|
||||
class QT_QTPROPERTYBROWSER_EXPORT QtTextEditorFactory : public QtAbstractEditorFactory<QtTextPropertyManager>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtTextEditorFactory(QObject *parent = 0);
|
||||
~QtTextEditorFactory();
|
||||
protected:
|
||||
void connectPropertyManager(QtTextPropertyManager *manager);
|
||||
QWidget *createEditor(QtTextPropertyManager *manager, QtProperty *property,
|
||||
QWidget *parent);
|
||||
void disconnectPropertyManager(QtTextPropertyManager *manager);
|
||||
private:
|
||||
QtTextEditorFactoryPrivate *d_ptr;
|
||||
Q_DECLARE_PRIVATE(QtTextEditorFactory)
|
||||
Q_DISABLE_COPY(QtTextEditorFactory)
|
||||
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QString &))
|
||||
Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QString &))
|
||||
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
|
||||
};
|
||||
|
||||
#if QT_VERSION >= 0x040400
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
|
|
@ -91,6 +91,7 @@
|
|||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QCheckBox>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QMenu>
|
||||
|
||||
|
@ -260,6 +261,7 @@ QString QtPropertyBrowserUtils::fontValueText(const QFont &f)
|
|||
QtBoolEdit::QtBoolEdit(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_checkBox(new QCheckBox(this)),
|
||||
m_defaultButton(new QToolButton(this)),
|
||||
m_textVisible(true)
|
||||
{
|
||||
QHBoxLayout *lt = new QHBoxLayout;
|
||||
|
@ -268,6 +270,8 @@ QtBoolEdit::QtBoolEdit(QWidget *parent) :
|
|||
else
|
||||
lt->setContentsMargins(0, 0, 4, 0);
|
||||
lt->addWidget(m_checkBox);
|
||||
lt->addWidget(m_defaultButton);
|
||||
m_defaultButton->setEnabled(false);
|
||||
setLayout(lt);
|
||||
connect(m_checkBox, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
|
||||
setFocusProxy(m_checkBox);
|
||||
|
|
|
@ -110,6 +110,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
class QMouseEvent;
|
||||
class QCheckBox;
|
||||
class QToolButton;
|
||||
class QLineEdit;
|
||||
|
||||
class QtCursorDatabase
|
||||
|
@ -168,6 +169,7 @@ protected:
|
|||
|
||||
private:
|
||||
QCheckBox *m_checkBox;
|
||||
QToolButton *m_defaultButton;
|
||||
bool m_textVisible;
|
||||
};
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@
|
|||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QStringRef>
|
||||
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
|
@ -6457,6 +6458,20 @@ void QtCursorPropertyManager::uninitializeProperty(QtProperty *property)
|
|||
d_ptr->m_values.remove(property);
|
||||
}
|
||||
|
||||
QString QtTextPropertyManager::valueText(const QtProperty *property) const
|
||||
{
|
||||
QString text = QtStringPropertyManager::valueText(property);
|
||||
for (int i = 0; i < text.size(); i++)
|
||||
{
|
||||
if (text.at(i) == '\n')
|
||||
{
|
||||
QStringRef ret(&text, 0, i);
|
||||
return ret.toString() + " ...";
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x040400
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
|
|
@ -789,6 +789,16 @@ private:
|
|||
Q_DISABLE_COPY(QtCursorPropertyManager)
|
||||
};
|
||||
|
||||
class QT_QTPROPERTYBROWSER_EXPORT QtTextPropertyManager : public QtStringPropertyManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtTextPropertyManager(QObject *parent = 0):QtStringPropertyManager(parent) {}
|
||||
|
||||
protected:
|
||||
virtual QString valueText(const QtProperty *property) const;
|
||||
};
|
||||
|
||||
#if QT_VERSION >= 0x040400
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue