| 15 | #include "private/ElaMultiSelectComboBoxPrivate.h" |
| 16 | Q_PROPERTY_CREATE_Q_CPP(ElaMultiSelectComboBox, int, BorderRadius) |
| 17 | ElaMultiSelectComboBox::ElaMultiSelectComboBox(QWidget* parent) |
| 18 | : QComboBox(parent), d_ptr(new ElaMultiSelectComboBoxPrivate()) |
| 19 | { |
| 20 | Q_D(ElaMultiSelectComboBox); |
| 21 | d->q_ptr = this; |
| 22 | d->_pBorderRadius = 3; |
| 23 | d->_pExpandIconRotate = 0; |
| 24 | d->_pExpandMarkWidth = 0; |
| 25 | d->_themeMode = eTheme->getThemeMode(); |
| 26 | setFixedHeight(35); |
| 27 | |
| 28 | d->_comboBoxStyle = new ElaComboBoxStyle(style()); |
| 29 | setStyle(d->_comboBoxStyle); |
| 30 | |
| 31 | //调用view 让container初始化 |
| 32 | d->_comboView = new ElaComboBoxView(this); |
| 33 | setView(d->_comboView); |
| 34 | QAbstractItemView* comboBoxView = this->view(); |
| 35 | comboBoxView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); |
| 36 | ElaScrollBar* scrollBar = new ElaScrollBar(this); |
| 37 | comboBoxView->setVerticalScrollBar(scrollBar); |
| 38 | ElaScrollBar* floatVScrollBar = new ElaScrollBar(scrollBar, comboBoxView); |
| 39 | floatVScrollBar->setIsAnimation(true); |
| 40 | comboBoxView->setAutoScroll(false); |
| 41 | comboBoxView->setSelectionMode(QAbstractItemView::NoSelection); |
| 42 | comboBoxView->setSelectionBehavior(QAbstractItemView::SelectRows); |
| 43 | comboBoxView->setObjectName("ElaComboBoxView"); |
| 44 | comboBoxView->setStyleSheet("#ElaComboBoxView{background-color:transparent;}"); |
| 45 | comboBoxView->setStyle(d->_comboBoxStyle); |
| 46 | QWidget* container = this->findChild<QFrame*>(); |
| 47 | if (container) |
| 48 | { |
| 49 | container->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); |
| 50 | container->setAttribute(Qt::WA_TranslucentBackground); |
| 51 | container->setObjectName("ElaComboBoxContainer"); |
| 52 | container->setStyle(d->_comboBoxStyle); |
| 53 | QLayout* layout = container->layout(); |
| 54 | while (layout->count()) |
| 55 | { |
| 56 | layout->takeAt(0); |
| 57 | } |
| 58 | layout->addWidget(view()); |
| 59 | layout->setContentsMargins(6, 0, 6, 6); |
| 60 | #ifndef Q_OS_WIN |
| 61 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 62 | container->setStyleSheet("background-color:transparent;"); |
| 63 | #endif |
| 64 | #endif |
| 65 | } |
| 66 | QComboBox::setMaxVisibleItems(5); |
| 67 | connect(d->_comboView, &ElaComboBoxView::itemPressed, d, &ElaMultiSelectComboBoxPrivate::onItemPressed); |
| 68 | connect(this, QOverload<int>::of(&ElaMultiSelectComboBox::currentIndexChanged), d, &ElaMultiSelectComboBoxPrivate::_refreshCurrentIndexs); |
| 69 | d->_itemSelection.resize(32); |
| 70 | d->_itemSelection.fill(false); |
| 71 | d->_itemSelection[0] = true; |
| 72 | QComboBox::setMaxVisibleItems(5); |
| 73 | connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { |
| 74 | d->_themeMode = themeMode; |
nothing calls this directly
no test coverage detected