119 lines
2.4 KiB
C++
Executable File
119 lines
2.4 KiB
C++
Executable File
|
|
|
|
|
|
#include "lts_combo_box.h"
|
|
#include "lts_selection_popup.h"
|
|
#include "lts_message_dialog.h"
|
|
|
|
#include <QGuiApplication>
|
|
#include <QShowEvent>
|
|
|
|
|
|
#ifdef NEVER
|
|
# include <QDebug>
|
|
#endif
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
|
|
bool LtsComboBox::s_useSelectionDialog = false;
|
|
|
|
LtsComboBox::LtsComboBox(QWidget *parent)
|
|
: QComboBox(parent)
|
|
, m_currentIndex(-1)
|
|
{
|
|
connect(this, &LtsComboBox::signalExternallyChanged,
|
|
this, &LtsComboBox::signalRefill);
|
|
}
|
|
|
|
void LtsComboBox::setUseSelectionDialog(bool bUseSelectionDialog)
|
|
{
|
|
s_useSelectionDialog = bUseSelectionDialog;
|
|
}
|
|
|
|
void LtsComboBox::showEvent(QShowEvent *e)
|
|
{
|
|
QComboBox::showEvent(e);
|
|
|
|
m_currentIndex = currentIndex();
|
|
}
|
|
|
|
void LtsComboBox::enterEvent(QEvent *e)
|
|
{
|
|
BaseClass::enterEvent(e);
|
|
emit signalEnterEvent();
|
|
}
|
|
|
|
void LtsComboBox::leaveEvent(QEvent *e)
|
|
{
|
|
BaseClass::leaveEvent(e);
|
|
emit signalLeaveEvent();
|
|
}
|
|
|
|
void LtsComboBox::showPopup()
|
|
{
|
|
bool bUseSelectionDialog = s_useSelectionDialog;
|
|
if (QGuiApplication::queryKeyboardModifiers() == Qt::ControlModifier)
|
|
bUseSelectionDialog = !bUseSelectionDialog;
|
|
if (!bUseSelectionDialog)
|
|
{
|
|
QComboBox::showPopup();
|
|
return;
|
|
}
|
|
|
|
if (!model()->rowCount())
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("There are no items available!"));
|
|
return;
|
|
}
|
|
|
|
|
|
LtsSelectionPopup* popup = new LtsSelectionPopup(model(), currentIndex(), this);
|
|
popup->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
#ifdef NEVER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(popup, static_cast<void (LtsSelectionPopup::*)(int)>(&LtsSelectionPopup::currentIndexChanged), this, [](int idx){
|
|
qCritical() << " LtsComboBox: called: currentIndexChanged(int), idx=" << idx;
|
|
});
|
|
|
|
|
|
connect(popup, static_cast<void (LtsSelectionPopup::*)(int)>(&LtsSelectionPopup::activated), this, [](int idx){
|
|
qCritical() << " LtsComboBox: called: activated(int), idx=" << idx;
|
|
});
|
|
|
|
#endif
|
|
|
|
|
|
|
|
connect(popup, &LtsSelectionPopup::currentIndexChanged,
|
|
this, &LtsComboBox::userChangedIndex);
|
|
connect(popup, &LtsSelectionPopup::activated,
|
|
this, static_cast<void (LtsComboBox::*)(int)>(&LtsComboBox::activated));
|
|
|
|
popup->show();
|
|
}
|
|
|
|
|
|
void LtsComboBox::userChangedIndex(int index)
|
|
{
|
|
m_currentIndex = index;
|
|
setCurrentIndex(index);
|
|
}
|
|
|
|
|
|
bool LtsComboBox::hasValueChanged() const
|
|
{
|
|
if (m_currentIndex == -1)
|
|
return false;
|
|
return !(currentIndex() == m_currentIndex);
|
|
}
|
|
|
|
}
|