#include "languageselectorbutton.h"

LanguageSelectorButton::LanguageSelectorButton(QWidget* parent) : QPushButton (parent)
{
    contextmenu = new QMenu(this);

    actRuss = new QAction(QIcon(":/res/language-russ.png"), tr("Рус"), this);
    actEng = new QAction(QIcon(":/res/language-eng.png"), tr("Анг"), this);

    actRuss->setCheckable(true);
    actEng->setCheckable(true);

    actRuss->setChecked(true);

    contextmenu->addAction(actRuss);
    contextmenu->addAction(actEng);

    contextmenu->setContextMenuPolicy(Qt::CustomContextMenu);

    connect(contextmenu, &QMenu::triggered, this, &LanguageSelectorButton::onActActivated);
}

void LanguageSelectorButton::mousePressEvent(QMouseEvent *event)
{
    contextmenu->exec(QCursor::pos());
}

void LanguageSelectorButton::onActActivated(QAction* _pAction)
{
    if (_pAction == actRuss)
    {
        emit sigSetRussianLanguage();
    }
    else if (_pAction == actEng)
    {
        emit sigSetEnglishLanguage();
    }
}

