#include "mypushbutton.h"
#include <QApplication>
#include <QMenu>
#include <QClipboard>
#include <QDebug>
#include "clipboard.h"

MyPushButton::MyPushButton(QWidget *parent) :
    QPushButton(parent)
{
    settingRightClickMenu= new QMenu(this);

    homePageAction = settingRightClickMenu->addAction(tr("kylin-aiassistant HomePage"));
    disableAction = settingRightClickMenu->addAction(tr("Disable Floating Bar For Scribe Words"));
    settingAction = settingRightClickMenu->addAction(tr("Setting"));
    closeAction = settingRightClickMenu->addAction(tr("Close"));

}


void MyPushButton::mousePressEvent(QMouseEvent *event){

        if (event->button() == Qt::RightButton) {
            emit rightButtonClicked();
            // 右键点击事件
            if(event->type() == QEvent::ContextMenu){
               QMenu menu(this);
               menu.show();
           }
        } else if (event->button() == Qt::LeftButton) {
            // 左键点击事件
            emit leftButtonClicked();
        }
        QPushButton::mousePressEvent(event); // 调用基类的mousePressEvent
}

void MyPushButton::contextMenuEvent(QContextMenuEvent *event){

    selectedAction = settingRightClickMenu->exec(event->globalPos());

    if (selectedAction == homePageAction) {
        // 处理 "麒思妙想首页show出" 的点击事件
        emit sigHomePageShow();
    } else if (selectedAction == disableAction) {
        // 处理 "禁用划词悬浮条" 的点击事件
        emit sigDisableScribe();
    }else if (selectedAction == settingAction) {
        // 处理 "设置页面弹出" 的点击事件
        emit sigSettingShow();
    }else if (selectedAction == closeAction) {
        // 处理 "划词界面关闭" 的点击事件
        emit sigSelectWidgetClose();
    }
}
