mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
DisplaySettings+LibGUI: Move ItemListModel into LibGUI
Without this model, comboboxes are abysmal to work with, so let's not redefine it every time.
This commit is contained in:
parent
2f9a071072
commit
e75247a75b
2 changed files with 17 additions and 13 deletions
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
#include "DisplaySettings.h"
|
||||
#include "ItemListModel.h"
|
||||
#include <LibGUI/ItemListModel.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
|
@ -122,7 +122,7 @@ void DisplaySettingsWidget::create_frame()
|
|||
m_wallpaper_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_wallpaper_combo->set_preferred_size(0, 22);
|
||||
m_wallpaper_combo->set_only_allow_values_from_model(true);
|
||||
m_wallpaper_combo->set_model(*ItemListModel<AK::String>::create(m_wallpapers));
|
||||
m_wallpaper_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_wallpapers));
|
||||
m_wallpaper_combo->on_change = [this](auto& text, const GUI::ModelIndex& index) {
|
||||
String path = text;
|
||||
if (m_monitor_widget->set_wallpaper(path)) {
|
||||
|
@ -180,7 +180,7 @@ void DisplaySettingsWidget::create_frame()
|
|||
m_mode_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_mode_combo->set_preferred_size(0, 22);
|
||||
m_mode_combo->set_only_allow_values_from_model(true);
|
||||
m_mode_combo->set_model(*ItemListModel<AK::String>::create(m_modes));
|
||||
m_mode_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_modes));
|
||||
m_mode_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
|
||||
this->m_monitor_widget->set_wallpaper_mode(m_modes.at(index.row()));
|
||||
this->m_monitor_widget->update();
|
||||
|
@ -203,7 +203,7 @@ void DisplaySettingsWidget::create_frame()
|
|||
m_resolution_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_resolution_combo->set_preferred_size(0, 22);
|
||||
m_resolution_combo->set_only_allow_values_from_model(true);
|
||||
m_resolution_combo->set_model(*ItemListModel<Gfx::IntSize>::create(m_resolutions));
|
||||
m_resolution_combo->set_model(*GUI::ItemListModel<Gfx::IntSize>::create(m_resolutions));
|
||||
m_resolution_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
|
||||
this->m_monitor_widget->set_desktop_resolution(m_resolutions.at(index.row()));
|
||||
this->m_monitor_widget->update();
|
||||
|
|
|
@ -30,19 +30,21 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Model.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
template<typename T>
|
||||
class ItemListModel final : public GUI::Model {
|
||||
class ItemListModel final : public Model {
|
||||
public:
|
||||
static NonnullRefPtr<ItemListModel> create(Vector<T>& data) { return adopt(*new ItemListModel<T>(data)); }
|
||||
static NonnullRefPtr<ItemListModel> create(const Vector<T>& data) { return adopt(*new ItemListModel<T>(data)); }
|
||||
|
||||
virtual ~ItemListModel() override { }
|
||||
|
||||
virtual int row_count(const GUI::ModelIndex&) const override
|
||||
virtual int row_count(const ModelIndex&) const override
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
virtual int column_count(const GUI::ModelIndex&) const override
|
||||
virtual int column_count(const ModelIndex&) const override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -52,11 +54,11 @@ public:
|
|||
return "Data";
|
||||
}
|
||||
|
||||
virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override
|
||||
virtual Variant data(const ModelIndex& index, ModelRole role) const override
|
||||
{
|
||||
if (role == GUI::ModelRole::TextAlignment)
|
||||
if (role == ModelRole::TextAlignment)
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
if (role == GUI::ModelRole::Display)
|
||||
if (role == ModelRole::Display)
|
||||
return m_data.at(index.row());
|
||||
|
||||
return {};
|
||||
|
@ -68,10 +70,12 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
explicit ItemListModel(Vector<T>& data)
|
||||
explicit ItemListModel(const Vector<T>& data)
|
||||
: m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
Vector<T>& m_data;
|
||||
const Vector<T>& m_data;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue