2020-06-01 17:11:56 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ComboInputDialog.h"
|
|
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
|
|
class CComboInputDialogPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CComboInputDialogPrivate(QDialog *q)
|
|
|
|
: clickedButton(0)
|
|
|
|
{
|
|
|
|
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
|
|
|
|
|
|
|
pixmapLabel = new QLabel(q);
|
|
|
|
sizePolicy.setHorizontalStretch(0);
|
|
|
|
sizePolicy.setVerticalStretch(0);
|
|
|
|
sizePolicy.setHeightForWidth(pixmapLabel->sizePolicy().hasHeightForWidth());
|
|
|
|
pixmapLabel->setSizePolicy(sizePolicy);
|
|
|
|
pixmapLabel->setVisible(false);
|
|
|
|
|
|
|
|
QSpacerItem *pixmapSpacer =
|
|
|
|
new QSpacerItem(0, 5, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
|
|
|
|
|
|
|
|
messageLabel = new QLabel(q);
|
|
|
|
messageLabel->setMinimumSize(QSize(300, 0));
|
|
|
|
messageLabel->setWordWrap(true);
|
|
|
|
messageLabel->setOpenExternalLinks(true);
|
|
|
|
messageLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse);
|
|
|
|
|
|
|
|
QSpacerItem *buttonSpacer =
|
|
|
|
new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
|
|
|
|
|
|
combo = new QComboBox(q);
|
|
|
|
|
2022-07-09 10:46:07 +01:00
|
|
|
infoLabel = new QLabel(q);
|
|
|
|
infoLabel->setVisible(false);
|
|
|
|
infoLabel->setWordWrap(true);
|
2020-06-01 17:11:56 +01:00
|
|
|
|
|
|
|
buttonBox = new QDialogButtonBox(q);
|
|
|
|
buttonBox->setOrientation(Qt::Horizontal);
|
|
|
|
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout = new QVBoxLayout();
|
|
|
|
verticalLayout->addWidget(pixmapLabel);
|
|
|
|
verticalLayout->addItem(pixmapSpacer);
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
|
|
|
horizontalLayout_2->addLayout(verticalLayout);
|
|
|
|
horizontalLayout_2->addWidget(messageLabel);
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout_2 = new QVBoxLayout(q);
|
|
|
|
verticalLayout_2->addLayout(horizontalLayout_2);
|
|
|
|
verticalLayout_2->addWidget(combo);
|
2022-07-09 10:46:07 +01:00
|
|
|
verticalLayout_2->addWidget(infoLabel);
|
2020-06-01 17:11:56 +01:00
|
|
|
verticalLayout_2->addItem(buttonSpacer);
|
|
|
|
verticalLayout_2->addWidget(buttonBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel *pixmapLabel;
|
|
|
|
QLabel *messageLabel;
|
2022-07-09 10:46:07 +01:00
|
|
|
QLabel *infoLabel;
|
2020-06-01 17:11:56 +01:00
|
|
|
QComboBox* combo;
|
|
|
|
QDialogButtonBox *buttonBox;
|
|
|
|
QAbstractButton *clickedButton;
|
2022-07-09 10:46:07 +01:00
|
|
|
QMap<int, QString> infos;
|
2020-06-01 17:11:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CComboInputDialog::CComboInputDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
d(new CComboInputDialogPrivate(this))
|
|
|
|
{
|
|
|
|
setModal(true);
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2021-02-01 19:13:09 +00:00
|
|
|
d->combo->setFocus();
|
2022-07-09 10:46:07 +01:00
|
|
|
connect(d->combo, SIGNAL(currentIndexChanged(int)), SLOT(onCmbIndex(int)));
|
2020-06-01 17:11:56 +01:00
|
|
|
connect(d->buttonBox, SIGNAL(accepted()), SLOT(accept()));
|
|
|
|
connect(d->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
|
|
|
connect(d->buttonBox, SIGNAL(clicked(QAbstractButton*)),
|
|
|
|
SLOT(slotClicked(QAbstractButton*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
CComboInputDialog::~CComboInputDialog()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2022-07-09 10:46:07 +01:00
|
|
|
void CComboInputDialog::onCmbIndex(int index)
|
|
|
|
{
|
|
|
|
QString info = d->infos[index];
|
|
|
|
if (!info.isEmpty())
|
|
|
|
d->infoLabel->setVisible(true);
|
|
|
|
d->infoLabel->setText(info);
|
|
|
|
}
|
|
|
|
|
2020-06-01 17:11:56 +01:00
|
|
|
void CComboInputDialog::slotClicked(QAbstractButton *b)
|
|
|
|
{
|
|
|
|
d->clickedButton = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractButton *CComboInputDialog::clickedButton() const
|
|
|
|
{
|
|
|
|
return d->clickedButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButton CComboInputDialog::clickedStandardButton() const
|
|
|
|
{
|
|
|
|
if (d->clickedButton)
|
|
|
|
return d->buttonBox->standardButton(d->clickedButton);
|
|
|
|
return QDialogButtonBox::NoButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CComboInputDialog::text() const
|
|
|
|
{
|
|
|
|
return d->messageLabel->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CComboInputDialog::setText(const QString &t)
|
|
|
|
{
|
|
|
|
d->messageLabel->setText(t);
|
|
|
|
}
|
|
|
|
|
2022-07-09 10:46:07 +01:00
|
|
|
void CComboInputDialog::addItem(const QString& t, const QVariant & v, const QString& info)
|
2020-06-01 17:11:56 +01:00
|
|
|
{
|
|
|
|
d->combo->addItem(t, v);
|
2022-07-09 10:46:07 +01:00
|
|
|
if (!info.isEmpty())
|
|
|
|
d->infos[d->combo->count() - 1] = info;
|
2020-06-01 17:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CComboInputDialog::setEditable(bool b)
|
|
|
|
{
|
|
|
|
d->combo->setEditable(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CComboInputDialog::value() const
|
|
|
|
{
|
|
|
|
return d->combo->currentText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CComboInputDialog::setValue(const QString &t)
|
|
|
|
{
|
|
|
|
int idx = d->combo->findText(t);
|
|
|
|
if(idx == -1)
|
|
|
|
d->combo->setEditText(t);
|
|
|
|
else
|
|
|
|
d->combo->setCurrentIndex(idx);
|
|
|
|
}
|
|
|
|
|
2020-07-19 21:09:02 +01:00
|
|
|
int CComboInputDialog::findValue(const QString &t) const
|
|
|
|
{
|
|
|
|
return d->combo->findText(t);
|
|
|
|
}
|
|
|
|
|
2020-06-01 17:11:56 +01:00
|
|
|
QVariant CComboInputDialog::data() const
|
|
|
|
{
|
|
|
|
return d->combo->currentData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CComboInputDialog::setData(const QVariant & v)
|
|
|
|
{
|
|
|
|
d->combo->setCurrentIndex(d->combo->findData(v));
|
|
|
|
}
|
|
|
|
|
2020-07-19 21:09:02 +01:00
|
|
|
int CComboInputDialog::findData(const QVariant & v) const
|
|
|
|
{
|
|
|
|
return d->combo->findData(v);
|
|
|
|
}
|
|
|
|
|
2020-06-01 17:11:56 +01:00
|
|
|
QPixmap CComboInputDialog::iconPixmap() const
|
|
|
|
{
|
2022-09-29 17:28:48 +01:00
|
|
|
return d->pixmapLabel->pixmap(Qt::ReturnByValue);
|
2020-06-01 17:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CComboInputDialog::setIconPixmap(const QPixmap &p)
|
|
|
|
{
|
|
|
|
d->pixmapLabel->setPixmap(p);
|
|
|
|
d->pixmapLabel->setVisible(!p.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButtons CComboInputDialog::standardButtons() const
|
|
|
|
{
|
|
|
|
return d->buttonBox->standardButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CComboInputDialog::setStandardButtons(QDialogButtonBox::StandardButtons s)
|
|
|
|
{
|
|
|
|
d->buttonBox->setStandardButtons(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton *CComboInputDialog::button(QDialogButtonBox::StandardButton b) const
|
|
|
|
{
|
|
|
|
return d->buttonBox->button(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton *CComboInputDialog::addButton(const QString &text, QDialogButtonBox::ButtonRole role)
|
|
|
|
{
|
|
|
|
return d->buttonBox->addButton(text, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButton CComboInputDialog::defaultButton() const
|
|
|
|
{
|
|
|
|
foreach (QAbstractButton *b, d->buttonBox->buttons())
|
|
|
|
if (QPushButton *pb = qobject_cast<QPushButton *>(b))
|
|
|
|
if (pb->isDefault())
|
|
|
|
return d->buttonBox->standardButton(pb);
|
|
|
|
return QDialogButtonBox::NoButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CComboInputDialog::setDefaultButton(QDialogButtonBox::StandardButton s)
|
|
|
|
{
|
|
|
|
if (QPushButton *b = d->buttonBox->button(s)) {
|
|
|
|
b->setDefault(true);
|
|
|
|
b->setFocus();
|
|
|
|
}
|
|
|
|
}
|