Commit bd364ea4 authored by Laurent Montel's avatar Laurent Montel 😁

fix readonly support

parent 4af30493
...@@ -156,6 +156,7 @@ void SelectHeadersWidget::setListHeaders(const QMap<QString, QString> &lst, cons ...@@ -156,6 +156,7 @@ void SelectHeadersWidget::setListHeaders(const QMap<QString, QString> &lst, cons
QMapIterator<QString, QString> i(lst); QMapIterator<QString, QString> i(lst);
while (i.hasNext()) { while (i.hasNext()) {
i.next(); i.next();
if (!i.value().isEmpty()) {
QListWidgetItem *item = new QListWidgetItem(i.value(), this); QListWidgetItem *item = new QListWidgetItem(i.value(), this);
item->setData(HeaderId, i.key()); item->setData(HeaderId, i.key());
if (selectedHeaders.contains(i.key())) { if (selectedHeaders.contains(i.key())) {
...@@ -164,6 +165,7 @@ void SelectHeadersWidget::setListHeaders(const QMap<QString, QString> &lst, cons ...@@ -164,6 +165,7 @@ void SelectHeadersWidget::setListHeaders(const QMap<QString, QString> &lst, cons
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
} }
} }
}
Q_FOREACH (const QString &header, selectedHeaders) { Q_FOREACH (const QString &header, selectedHeaders) {
if (!lst.contains(header)) { if (!lst.contains(header)) {
QListWidgetItem *item = new QListWidgetItem(header, this); QListWidgetItem *item = new QListWidgetItem(header, this);
...@@ -195,9 +197,10 @@ QString SelectHeadersWidget::headers() const ...@@ -195,9 +197,10 @@ QString SelectHeadersWidget::headers() const
} }
SelectHeaderTypeComboBox::SelectHeaderTypeComboBox(bool onlyEnvelopType, QWidget *parent) SelectHeaderTypeComboBox::SelectHeaderTypeComboBox(bool onlyEnvelopType, QWidget *parent)
: KComboBox(parent) : QComboBox(parent)
{ {
setEditable(true); setEditable(true);
lineEdit()->setClearButtonEnabled(true);
//TODO add completion //TODO add completion
initialize(onlyEnvelopType); initialize(onlyEnvelopType);
connect(this, static_cast<void (SelectHeaderTypeComboBox::*)(const QString &)>(&SelectHeaderTypeComboBox::activated), this, &SelectHeaderTypeComboBox::slotSelectItem); connect(this, static_cast<void (SelectHeaderTypeComboBox::*)(const QString &)>(&SelectHeaderTypeComboBox::activated), this, &SelectHeaderTypeComboBox::slotSelectItem);
...@@ -209,9 +212,17 @@ SelectHeaderTypeComboBox::~SelectHeaderTypeComboBox() ...@@ -209,9 +212,17 @@ SelectHeaderTypeComboBox::~SelectHeaderTypeComboBox()
{ {
} }
void SelectHeaderTypeComboBox::changeReadOnlyStatus()
{
const bool readOnly = (currentIndex() > 0);
lineEdit()->setReadOnly(readOnly);
lineEdit()->setClearButtonEnabled(!readOnly);
}
void SelectHeaderTypeComboBox::slotSelectItem(const QString &str) void SelectHeaderTypeComboBox::slotSelectItem(const QString &str)
{ {
lineEdit()->setReadOnly(currentIndex() > 0); changeReadOnlyStatus();
if (str == i18n(selectMultipleHeaders)) { if (str == i18n(selectMultipleHeaders)) {
QPointer<SelectHeadersDialog> dlg = new SelectHeadersDialog(this); QPointer<SelectHeadersDialog> dlg = new SelectHeadersDialog(this);
dlg->setListHeaders(mHeaderMap, AutoCreateScriptUtil::createListFromString(mCode)); dlg->setListHeaders(mHeaderMap, AutoCreateScriptUtil::createListFromString(mCode));
...@@ -290,7 +301,7 @@ void SelectHeaderTypeComboBox::setCode(const QString &code) ...@@ -290,7 +301,7 @@ void SelectHeaderTypeComboBox::setCode(const QString &code)
setCurrentIndex(count() - 1); setCurrentIndex(count() - 1);
lineEdit()->setText(code); lineEdit()->setText(code);
} }
lineEdit()->setReadOnly(currentIndex() > 0);
mCode = code; mCode = code;
changeReadOnlyStatus();
} }
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#ifndef SELECTHEADERTYPECOMBOBOX_H #ifndef SELECTHEADERTYPECOMBOBOX_H
#define SELECTHEADERTYPECOMBOBOX_H #define SELECTHEADERTYPECOMBOBOX_H
#include <KComboBox> #include <QComboBox>
#include <QDialog> #include <QDialog>
#include <QListWidget> #include <QListWidget>
...@@ -68,7 +68,7 @@ private: ...@@ -68,7 +68,7 @@ private:
QPushButton *mAddNewHeader; QPushButton *mAddNewHeader;
}; };
class SelectHeaderTypeComboBox : public KComboBox class SelectHeaderTypeComboBox : public QComboBox
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -86,6 +86,7 @@ private Q_SLOTS: ...@@ -86,6 +86,7 @@ private Q_SLOTS:
private: private:
void initialize(bool onlyEnvelopType); void initialize(bool onlyEnvelopType);
void changeReadOnlyStatus();
void headerMap(bool onlyEnvelopType); void headerMap(bool onlyEnvelopType);
QMap<QString, QString> mHeaderMap; QMap<QString, QString> mHeaderMap;
QString mCode; QString mCode;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment