diff --git a/src/kiwixchoicebox.cpp b/src/kiwixchoicebox.cpp index e6d6cb7..6d3d15d 100644 --- a/src/kiwixchoicebox.cpp +++ b/src/kiwixchoicebox.cpp @@ -32,7 +32,8 @@ KiwixChoiceBox::KiwixChoiceBox(QWidget *parent) : choiceSelector = new KiwixListWidget(parent); choiceSelector->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); choiceSelector->setMaximumWidth(250); - choiceSelector->setMaximumHeight(200); + // allow maximum 6 elements + choiceSelector->setMaximumHeight(KListWidgetItem::getItemHeight() * 6); choiceSelector->setCursor(Qt::PointingHandCursor); choiceSelector->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); choiceSelector->setFocusPolicy(Qt::FocusPolicy::NoFocus); @@ -40,7 +41,7 @@ KiwixChoiceBox::KiwixChoiceBox(QWidget *parent) : choiceSelector->setStyleSheet(styleSheet); choiceSelector->setSelectionMode(QAbstractItemView::SelectionMode::MultiSelection); - currentChoicesLayout = new FlowLayout(ui->currentChoices, 2, 2, 2); + currentChoicesLayout = new FlowLayout(ui->currentChoices, 4, 2, 2); searcher = new KiwixLineEdit(); searcher->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); currentChoicesLayout->addWidget(searcher); @@ -100,6 +101,10 @@ KiwixChoiceBox::KiwixChoiceBox(QWidget *parent) : connect(this, &KiwixChoiceBox::choiceUpdated, [=]() { choiceSelector->setVisible(false); }); + + connect(this, &KiwixChoiceBox::clicked, [=]() { + searcher->setFocus(); + }); } KiwixChoiceBox::~KiwixChoiceBox() @@ -107,6 +112,13 @@ KiwixChoiceBox::~KiwixChoiceBox() delete ui; } +void KiwixChoiceBox::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + emit(clicked()); + } +} + void KiwixChoiceBox::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Escape) { diff --git a/src/kiwixchoicebox.h b/src/kiwixchoicebox.h index 313c0dd..3a49df7 100644 --- a/src/kiwixchoicebox.h +++ b/src/kiwixchoicebox.h @@ -36,9 +36,11 @@ public: protected: void keyPressEvent(QKeyEvent* event) override; + void mouseReleaseEvent(QMouseEvent *event) override; signals: void choiceUpdated(QStringList); + void clicked(); private: Ui::kiwixchoicebox *ui; diff --git a/ui/kiwixchoicebox.ui b/ui/kiwixchoicebox.ui index 140154b..e70b193 100644 --- a/ui/kiwixchoicebox.ui +++ b/ui/kiwixchoicebox.ui @@ -6,8 +6,8 @@ 0 0 - 274 - 325 + 268 + 50 @@ -26,6 +26,12 @@ Form + + 0 + + + 0 +