#include "BaseWidget.h"
#include "menu/BaseWidgetMenu.h"
#include "BackEnd/MainWidget.h"
#include "Global.h"



Base_Widget::Base_Widget(QWidget *parent) : QWidget(parent) {
//    setAttribute(Qt::WA_OpaquePaintEvent);
    base_widget_menu = new Base_Widget_Menu(this);
    base_widget_menu->setObjectName("属性菜单");
    hide();
}


void Base_Widget::resizeEvent(QResizeEvent *event) {
    int base_height = (int)((double)height() * 0.2);
    base_widget_menu->setGeometry(0, height() - base_height, width(), base_height);
    QWidget::resizeEvent(event);
}

void Base_Widget::reserver_menu() {
    if(!base_widget_menu->isVisible()){
        QWidget* cur_widget = Main_Widget::instance()->current_hover_widget();
        if(cur_widget) cur_widget->hide();
        base_widget_menu->raise();
        base_widget_menu->show();
        cur_widget = base_widget_menu;
        base_widget_menu->setFocus();
    } else {
        base_widget_menu->hide();
        setFocus();
    }
}

void Base_Widget::keyPressEvent(QKeyEvent *event) {
    if (event->type() == QEvent::KeyPress) {
        Global *g = Global::instance();
        auto *key_event = dynamic_cast<QKeyEvent *>(event);
        //qDebug() << key_event;
//        if(g->match(key_event, "属性菜单")){
//            reserver_menu();
//            event->accept();
//            return;
//        }

    }
    event->ignore();

}




