/*
 * Copyright (C) 2020, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#include "selectmorecommand.h"
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDialog>
#include <QLabel>
#include <QMouseEvent>
#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnection>
#include <QDebug>
#include <QMenu>
#include <QTimer>
#include <QQmlContext>
#include "mypushbutton.h"
#include <kysdk/kysdk-system/libkydatacollect.h>
#include <ukuistylehelper/ukuistylehelper.h>
#include <kysdk/applications/kwidget.h>
#include <ukuiwindowhelper/ukuiwindowhelper.h>

SelectMoreCommandWidget::SelectMoreCommandWidget(QWidget *parent)
{
    kdk::UkuiStyleHelper::self()->removeHeader(this);
#ifdef UKUI_WINDOWHELPER_SUPPORT
    UkuiWindowHelper *ukuiWindowHelper = new UkuiWindowHelper(this);
    ukuiWindowHelper->removeTitleBar();
    ukuiWindowHelper->setSkipTaskBar(true);
#else
    kdk::UkuiStyleHelper::self()->removeHeader(this);
    kdk::WindowManager::setSkipTaskBar(this->windowHandle(), true);
#endif
    this->setFixedSize(180,172);
    //初始化更多指令面板
    initSelectMoreCommandWidget();
}

void SelectMoreCommandWidget::initSelectMoreCommandWidget()
{
    m_hLayoutMain = new QHBoxLayout();
    this->setContentsMargins(0,0,0,0);
    m_quickWidget = new QQuickWidget(this);
    m_quickWidget->setAccessibleName("kylin-aiassistant_QQuickWidget_m_quickWidget");
    m_quickWidget->setContentsMargins(0,0,0,0);
    //添加指令模
    m_quickWidget->rootContext()->setContextProperty("commandTemplateListModel", CommandTemplateList::originalCommandListModel);
    m_quickWidget->rootContext()->setContextProperty("selectMoreCommand", this);
    m_quickWidget->setSource(QUrl("qrc:/qml/qml/SelectMoreCommand.qml"));
}

void SelectMoreCommandWidget::setWidgetWidth(const int width)
{
    qDebug() << "设置当前宽度为"<< width;
    this->setFixedWidth(width);
    QQuickItem *item=m_quickWidget->rootObject();
    if(item){
        QMetaObject::invokeMethod(item, "onSetWidget",Q_ARG(QVariant ,width));

         QMetaObject::invokeMethod(item, "onSetHeight");
    }
}

void SelectMoreCommandWidget::setWidgetHeight(const int height)
{
    KyInfo() << "设置当前高度为"<< height;
    this->setFixedHeight(height);
}

void SelectMoreCommandWidget::sendButtonText(const QString &currentButtonText, const int currentId)
{
    //填充当前按钮文本
    if(!currentButtonText.isEmpty() && currentId != -1 )
    {
        KyInfo() << "currentButtonText" << currentButtonText;
        emit sigCurrentCommandText(currentButtonText,currentId);
    }

}

