cwidget.cpp
来自「Gambas is a graphical development enviro」· C++ 代码 · 共 1,522 行 · 第 1/3 页
CPP
1,522 行
}void CWidget::removeFilter(QObject *o){ QObjectList *children = (QObjectList *)(o->children()); QObject *child; if (!o->isWidgetType()) return; o->removeEventFilter(&manager); if (!children) return; child = children->first(); while (child) { //child->installEventFilter(&manager); CWidget::removeFilter(child); child = children->next(); }}void CWidget::removeFocusPolicy(QWidget *w){ QObjectList *children; QObject *child; w->setFocusPolicy(QWidget::NoFocus); children = (QObjectList *)(w->children()); if (!children) return; child = children->first(); while (child) { if (child->isWidgetType()) CWidget::removeFocusPolicy((QWidget *)child); child = children->next(); }}void CWidget::add(QObject *o, void *object, bool no_filter){ //if (!no_filter) QObject::connect(o, SIGNAL(destroyed()), &manager, SLOT(destroy())); dict.insert(o, (CWIDGET *)object); if (!no_filter) { haveChildren = false; CWidget::installFilter(o); if (haveChildren) CWIDGET_set_flag(object, WF_NO_EVENT); } GB.Ref(object);}CWIDGET *CWidget::get(QObject *o){ CWIDGET *ob; real = true; while (o) { ob = dict[o]; if (ob != NULL) return ob; o = o->parent(); real = false; } return NULL;}CWIDGET *CWidget::getReal(QObject *o){ return dict[o];}QWidget *CWidget::getContainerWidget(CCONTAINER *object){ if (GB.CheckObject(object)) GB.Propagate(); if (object->container == NULL) { GB.Error("Null container"); GB.Propagate(); } //qDebug("Container = %p", object->container); return (object->container);}#if 0void CWidget::setName(CWIDGET *object, const char *name){ QWidget *w = QWIDGET(object); CTOPLEVEL *top = (CTOPLEVEL *)CWidget::get(w->topLevelWidget()); if (QWIDGET(top) == w) return; if (w->name() != NULL) { /*qDebug("- %s", w->name());*/ top->dict->remove(w->name()); } if (name != NULL) { top->dict->insert((const char *)name, object); w->setName(name); /*qDebug("+ %s", w->name());*/ }}#endifvoid CWidget::resetTooltip(CWIDGET *_object){ QToolTip::remove(WIDGET); if (THIS->tooltip) QToolTip::add(WIDGET, TO_QSTRING(THIS->tooltip));}void CWidget::destroy(){ QWidget *w = (QWidget *)sender(); CWIDGET *ob = CWidget::get(w); //MyMainWindow *top = (MyMainWindow *)w->topLevelWidget(); //if (w->isTopLevel()) if (ob == NULL) return; //qDebug(">> CWidget::destroy %p (%p) :%p:%ld", ob, ob->widget, ob->ob.klass, ob->ob.ref); //w->blockSignals(TRUE); //w->disconnect(); if (CWIDGET_destroy_list == ob) CWIDGET_destroy_list = ob->next; if (CWIDGET_destroy_last == ob) CWIDGET_destroy_last = ob->prev; if (ob->prev) ob->prev->next = ob->next; if (ob->next) ob->next->prev = ob->prev; if (enter == ob) enter = NULL; //printf("#1\n"); /* if (w->inherits("QPushButton")) { qDebug("Inherits QPushButton"); top->setDefaultButton((QPushButton *)w, false); top->setCancelButton((QPushButton *)w, false); } */ //printf("#2\n"); //CWidget::setName(ob, NULL); dict.remove(w); QWIDGET(ob) = NULL; //printf("#3\n"); GB.StoreVariant(NULL, &ob->tag); GB.FreeString(&ob->tooltip); GB.Unref((void **)&ob->cursor); // Oblige les widgets n'h�itant pas de Control �poss�er cet ��ement en premier ! //GB.Raise(ob, EVENT_Destroy, 0); //qDebug(">> CWidget::destroy %p (%p) :%p:%ld #2", ob, ob->widget, ob->ob.klass, ob->ob.ref); GB.Detach(ob); //printf("#4\n"); //qDebug("<< CWidget::destroy %p (%p)", ob, ob->widget); GB.Unref((void **)&ob);}static void post_dblclick_event(void *control){ GB.Raise(control, EVENT_DblClick, 0); GB.Unref(&control);}bool CWidget::eventFilter(QObject *widget, QEvent *event){ CWIDGET *control; int event_id; int type = event->type(); bool real; bool design; bool original; int state; bool cancel; QPoint p; control = CWidget::get(widget); if (!control) goto _STANDARD; real = CWidget::real; design = CWIDGET_test_flag(control, WF_DESIGN); //child = (!real && (widget->children() == 0)) || !CWIDGET_test_flag(control, WF_NO_EVENT); original = event->spontaneous(); //QApplication::originalEvent; // event->accepted() || real; if (type == QEvent::Enter) { if (real) GB.Raise(control, EVENT_Enter, 0); } else if (type == QEvent::Leave) { if (real) GB.Raise(control, EVENT_Leave, 0); } else if (type == QEvent::FocusIn) { GB.Raise(control, EVENT_GotFocus, 0); } else if (type == QEvent::FocusOut) { GB.Raise(control, EVENT_LostFocus, 0); } else if (type == QEvent::ContextMenu) { // if (real && GB.CanRaise(control, EVENT_Menu)) if (GB.CanRaise(control, EVENT_Menu)) { ((QContextMenuEvent *)event)->accept(); GB.Raise(control, EVENT_Menu, 0); return true; } } else if ((type == QEvent::MouseButtonPress) || (type == QEvent::MouseButtonRelease) || (type == QEvent::MouseMove)) { QMouseEvent *mevent = (QMouseEvent *)event; //qDebug("Event on %p %s%s%s", widget, // real ? "REAL " : "", design ? "DESIGN " : "", child ? "CHILD " : ""); if (!original) goto _DESIGN; if (type == QEvent::MouseButtonPress) { event_id = EVENT_MouseDown; state = mevent->stateAfter(); //qDebug("MouseEvent: %d %d", mevent->x(), mevent->y()); } else { event_id = (type == QEvent::MouseButtonRelease) ? EVENT_MouseUp : EVENT_MouseMove; state = mevent->state(); } if (GB.CanRaise(control, event_id)) { p.setX(mevent->globalX()); p.setY(mevent->globalY()); //if (event_id != EVENT_MouseMove) // qDebug("X = %d Y = %d", p.x(), p.y()); //p = ((QWidget *)widget)->mapTo(QWIDGET(control), p); p = QWIDGET(control)->mapFromGlobal(p); //if (event_id != EVENT_MouseMove) // qDebug("=> X = %d Y = %d", p.x(), p.y()); CMOUSE_clear(true); CMOUSE_info.x = p.x(); CMOUSE_info.y = p.y(); CMOUSE_info.state = state; GB.Raise(control, event_id, 0); //, GB_T_INTEGER, p.x(), GB_T_INTEGER, p.y(), GB_T_INTEGER, state); CMOUSE_clear(false); } } else if (type == QEvent::MouseButtonDblClick) { if (!original) goto _DESIGN; if (GB.CanRaise(control, EVENT_DblClick)) { GB.Ref(control); GB.Post((void (*)())post_dblclick_event, (long)control); } } else if ((type == QEvent::KeyPress) || (type == QEvent::KeyRelease)) { QKeyEvent *kevent = (QKeyEvent *)event; /*if (type == QEvent::KeyPress) qDebug("QKeyEvent: %s %p (%d): %p (R%d S%d): %d %s", widget->className(), widget, ((QWidget *)widget)->isTopLevel(), control, real, original, kevent->key(), (char *)kevent->text().latin1());*/ #if QT_VERSION <= 0x030005 if (!real || !original) goto _DESIGN; #endif event_id = (type == QEvent::KeyPress) ? EVENT_KeyPress : EVENT_KeyRelease; #if QT_VERSION > 0x030005 if (!original) goto _ACCEL; #endif //if (type == QEvent::KeyPress) // qDebug("CWINDOW_main = %p", CWINDOW_Main); if (GB.CanRaise(control, event_id)) { CKEY_clear(true); GB.FreeString(&CKEY_info.text); GB.NewString(&CKEY_info.text, TO_UTF8(kevent->text()), 0); CKEY_info.state = kevent->state(); //qDebug("state = %d", CKEY_info.state); CKEY_info.code = kevent->key(); cancel = GB.Raise(control, event_id, 0); CKEY_clear(false); if (cancel && (type == QEvent::KeyPress)) return true; }_ACCEL: if (event_id == EVENT_KeyPress && CWINDOW_Main && ((QWidget *)widget)->isTopLevel()) { //CWIDGET *top = CWidget::get(((QWidget *)widget)->topLevelWidget()); CWIDGET *top = CWidget::get((QWidget *)widget); //qDebug("top = %p", top); if (!CWINDOW_Current && top && top != (CWIDGET *)CWINDOW_Main && QWIDGET(CWINDOW_Main)) { //qDebug("post Accel to %p", CWINDOW_Main); //QMAINWINDOW(CWINDOW_Main)->setState(MyMainWindow::StateNormal); qApp->postEvent(QWIDGET(CWINDOW_Main), new QKeyEvent(QEvent::Accel, kevent->key(), kevent->ascii(), kevent->state(), kevent->text(), kevent->isAutoRepeat(), kevent->count())); } } } else if (type == QEvent::Wheel) { QWheelEvent *ev = (QWheelEvent *)event; //qDebug("Event on %p %s%s%s", widget, // real ? "REAL " : "", design ? "DESIGN " : "", child ? "CHILD " : ""); if (!original) goto _DESIGN; if (GB.CanRaise(control, EVENT_MouseWheel)) { p.setX(ev->x()); p.setY(ev->y()); p = ((QWidget *)widget)->mapTo(QWIDGET(control), p); CMOUSE_clear(true); CMOUSE_info.x = p.x(); CMOUSE_info.y = p.y(); CMOUSE_info.state = ev->state(); CMOUSE_info.orientation = ev->orientation(); CMOUSE_info.delta = ev->delta(); GB.Raise(control, EVENT_MouseWheel, 0); //GB_T_INTEGER, p.x(), //GB_T_INTEGER, p.y(), //GB_T_INTEGER, ev->state(), //GB_T_INTEGER, ev->orientation(), //GB_T_FLOAT, (double)ev->delta() / 120); CMOUSE_clear(false); } } else if (type == QEvent::DragEnter) { if (GB.CanRaise(control, EVENT_Drag)) { CDRAG_clear(true); CDRAG_info.drop = (QDropEvent *)event; cancel = GB.Raise(control, EVENT_Drag, 0); CDRAG_info.drop->accept(!cancel); CDRAG_clear(false); } else ((QDropEvent *)event)->accept(); } else if (type == QEvent::DragMove) { if (GB.CanRaise(control, EVENT_DragMove)) { QDropEvent *ev = (QDropEvent *)event; CDRAG_clear(true); CDRAG_info.drop = (QDropEvent *)event; p = ev->pos(); p = ((QWidget *)widget)->mapTo(QWIDGET(control), p); CDRAG_info.x = p.x(); CDRAG_info.y = p.y(); cancel = GB.Raise(control, EVENT_DragMove, 0); CDRAG_info.drop->accept(!cancel); CDRAG_clear(false); } } else if (type == QEvent::Drop) { if (GB.CanRaise(control, EVENT_Drop)) { QDropEvent *ev = (QDropEvent *)event; CDRAG_clear(true); CDRAG_info.drop = ev; p = ev->pos(); p = ((QWidget *)widget)->mapTo(QWIDGET(control), p); CDRAG_info.x = p.x(); CDRAG_info.y = p.y(); GB.Raise(control, EVENT_Drop, 0); CDRAG_clear(false); } } if (CWIDGET_check(control)) { qDebug("CWidget::eventFilter: %p was destroyed", control); return true; }_DESIGN: if (design) { if ((type == QEvent::MouseButtonPress) || (type == QEvent::MouseButtonRelease) || (type == QEvent::MouseButtonDblClick) || (type == QEvent::MouseMove) || (type == QEvent::Wheel) || (type == QEvent::ContextMenu) || (type == QEvent::KeyPress) || (type == QEvent::KeyRelease) || (type == QEvent::Accel) || (type == QEvent::Enter) || (type == QEvent::Leave) || (type == QEvent::FocusIn) || (type == QEvent::FocusOut) || (type == QEvent::DragEnter) || (type == QEvent::DragMove) || (type == QEvent::DragLeave) || (type == QEvent::Drop) ) return true; }_STANDARD: return QObject::eventFilter(widget, event); // standard event processing}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?