2019-09-08 22:27:57 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QStandardItem>
|
2021-05-08 15:57:00 +02:00
|
|
|
#include <QUrl>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2020-02-20 23:37:46 +01:00
|
|
|
static auto defaultItemFlags(bool selectable)
|
|
|
|
{
|
|
|
|
return Qt::ItemIsEnabled |
|
|
|
|
(selectable ? Qt::ItemIsSelectable | Qt::ItemIsDragEnabled |
|
|
|
|
Qt::ItemIsDropEnabled
|
|
|
|
: Qt::ItemFlag());
|
|
|
|
}
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
static void setBoolItem(QStandardItem *item, bool value,
|
|
|
|
bool userCheckable = true, bool selectable = true)
|
|
|
|
{
|
2020-02-20 23:37:46 +01:00
|
|
|
item->setFlags(
|
|
|
|
Qt::ItemFlags(defaultItemFlags(selectable) |
|
|
|
|
(userCheckable ? Qt::ItemIsUserCheckable : 0)));
|
2019-09-08 22:27:57 +02:00
|
|
|
item->setCheckState(value ? Qt::Checked : Qt::Unchecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setStringItem(QStandardItem *item, const QString &value,
|
|
|
|
bool editable = true, bool selectable = true)
|
|
|
|
{
|
|
|
|
item->setData(value, Qt::EditRole);
|
2020-02-20 23:37:46 +01:00
|
|
|
item->setFlags(Qt::ItemFlags(defaultItemFlags(selectable) |
|
2019-09-18 13:03:16 +02:00
|
|
|
(editable ? (Qt::ItemIsEditable) : 0)));
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
|
2020-02-20 00:10:10 +01:00
|
|
|
static void setFilePathItem(QStandardItem *item, const QUrl &value,
|
|
|
|
bool selectable = true)
|
2020-01-25 11:03:10 +01:00
|
|
|
{
|
|
|
|
item->setData(value, Qt::UserRole);
|
|
|
|
item->setData(value.fileName(), Qt::DisplayRole);
|
2020-02-20 00:10:10 +01:00
|
|
|
item->setFlags(
|
2020-02-20 23:37:46 +01:00
|
|
|
Qt::ItemFlags(defaultItemFlags(selectable) |
|
2020-02-20 00:10:10 +01:00
|
|
|
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
|
2020-01-25 11:03:10 +01:00
|
|
|
}
|
|
|
|
|
2020-02-20 00:10:10 +01:00
|
|
|
static void setColorItem(QStandardItem *item, const QColor &value,
|
|
|
|
bool selectable = true)
|
2020-01-25 11:03:10 +01:00
|
|
|
{
|
|
|
|
item->setData(value, Qt::DecorationRole);
|
2020-02-20 00:10:10 +01:00
|
|
|
item->setFlags(
|
2020-02-20 23:37:46 +01:00
|
|
|
Qt::ItemFlags(defaultItemFlags(selectable) |
|
2020-02-20 00:10:10 +01:00
|
|
|
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
|
2020-01-25 11:03:10 +01:00
|
|
|
}
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
static QStandardItem *emptyItem()
|
|
|
|
{
|
|
|
|
auto *item = new QStandardItem();
|
2020-02-20 23:37:46 +01:00
|
|
|
item->setFlags(Qt::ItemFlags());
|
2019-09-08 22:27:57 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|