#include "rusificationtreeitem.h"
#include <QSettings>
#include <QDebug>

RusificationTreeItem::RusificationTreeItem(QString name): QTreeWidgetItem(1000), name(name)
{
}

void RusificationTreeItem::parseSettingsItem(QSettings &patches_list)
{
    patches_list.beginGroup(name);
    title = patches_list.value("title").toString();
    description = patches_list.value("descr").toString();
    patchname = patches_list.value("patchname").toString();
    parent_name = patches_list.value("parent", "rusification").toString();

    setText(0, title);

    if (name.contains("patch")) {
        QStringList categories_list = patches_list.value("id").toString().split('|');
        for (QString category : categories_list)
            categories.push_back(category.toInt());
        setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
    }

    if (name.contains("group")) {
        setFlags(Qt::ItemIsAutoTristate | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
        if (parent_name == "rusification") {
            QFont font;
            font.setFamily(QStringLiteral("Trajan Pro 3"));
            font.setPixelSize(16);
            font.setBold(false);
            font.setUnderline(false);

            setFont(0, font);
            setTextColor(0, QColor(207, 166, 68));
        }
    }

    qDebug() << title << description << parent_name;
    patches_list.endGroup();
}
