GComboBox.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <LibGUI/GListView.h>
  3. #include <LibGUI/GWidget.h>
  4. class GButton;
  5. class GTextEditor;
  6. class GComboBox : public GWidget {
  7. C_OBJECT(GComboBox)
  8. public:
  9. virtual ~GComboBox() override;
  10. String text() const;
  11. void set_text(const String&);
  12. void open();
  13. void close();
  14. void select_all();
  15. GModel* model() { return m_list_view->model(); }
  16. const GModel* model() const { return m_list_view->model(); }
  17. void set_model(NonnullRefPtr<GModel>);
  18. bool only_allow_values_from_model() const { return m_only_allow_values_from_model; }
  19. void set_only_allow_values_from_model(bool);
  20. int model_column() const { return m_list_view->model_column(); }
  21. void set_model_column(int column) { m_list_view->set_model_column(column); }
  22. Function<void(const String&, const GModelIndex&)> on_change;
  23. Function<void()> on_return_pressed;
  24. protected:
  25. explicit GComboBox(GWidget* parent = nullptr);
  26. virtual void resize_event(GResizeEvent&) override;
  27. private:
  28. RefPtr<GTextEditor> m_editor;
  29. RefPtr<GButton> m_open_button;
  30. RefPtr<GWindow> m_list_window;
  31. RefPtr<GListView> m_list_view;
  32. bool m_only_allow_values_from_model { false };
  33. };