public function eventListener($sender, $event) { switch ($event->type) { case QEvent::Resize: c('___pqcreator_mainwidget_')->unselectObject(); $this->parent->setMinimumSize($this->width, $this->height); return true; case QEvent::Show: if ($this->sizeCtrl != null && is_object($this->sizeCtrl)) { $this->sizeCtrl->__destruct(); } $this->sizeCtrl = new PQSizeCtrl($this, $this->parent, $this, 8, 10); $this->sizeCtrl->unmovable($this->sizeCtrl->lt); $this->sizeCtrl->unmovable($this->sizeCtrl->lm); $this->sizeCtrl->unmovable($this->sizeCtrl->lb); $this->sizeCtrl->unmovable($this->sizeCtrl->rt); $this->sizeCtrl->unmovable($this->sizeCtrl->tm); return true; case QEvent::ContextMenu: $menu = new QMenu(); $menu_layout = $menu->addMenu(tr('Layout')); $action = $menu_layout->addAction(c(PQNAME)->qticonsPath . '/editbreaklayout.png', tr('Break layout')); $action->connect(SIGNAL('triggered(bool)'), $this, SLOT('menuLayoutAction(bool)')); $action->objectName = 'menuLayoutAction_NoLayout'; $action = $menu_layout->addAction(c(PQNAME)->qticonsPath . '/editvlayout.png', tr('Vertical layout')); $action->connect(SIGNAL('triggered(bool)'), $this, SLOT('menuLayoutAction(bool)')); $action->objectName = 'menuLayoutAction_QVBoxLayout'; $action = $menu_layout->addAction(c(PQNAME)->qticonsPath . '/edithlayout.png', tr('Horizontal layout')); $action->connect(SIGNAL('triggered(bool)'), $this, SLOT('menuLayoutAction(bool)')); $action->objectName = 'menuLayoutAction_QHBoxLayout'; $menu->exec(mousePos()['x'], mousePos()['y']); $menu->free(); return true; case QEvent::Paint: $painter = new QPainter($sender); $painter->setPen("#aaaaaa", 1, $this->penStyle); $painter->drawPointBackground(8, 8, $this->width, $this->height); $painter->free(); return true; case QEvent::MouseButtonRelease: if ($event->button === Qt::LeftButton) { // $this->designer->unselectObject(); } } return true; }
protected function paintEvent($event) { $painter = new QPainter($this); $painter->setPen(Qt::NoPen); $painter->setBrush(new QBrush(new QColor(0, 0, 255))); $painter->translate(0, $this->rect()->height()); $painter->drawPie(new QRect(-35, -35, 70, 70), 0, 90 * 16); $painter->rotate(-$this->currentAngle); $painter->drawRect(new QRect(30, -5, 20, 10)); $painter->end(); }
protected function paintEvent($event) { $painter = new QPainter($this); $painter->drawText(200, 200, tr("Angle = ") . QString::number($this->currentAngle)); $painter->end(); }
public function dynObjectEventListener($sender, $event) { switch ($event->type) { case QEvent::ContextMenu: // Запретить открывать меню, если указатель был смещен с объекта if ($sender != widgetAt(mousePos()['x'], mousePos()['y'])) { return true; } $this->selectObject($sender); $menu = new QMenu(); $this->createGotoSlotAction($menu, $sender->objectName); $menu->addSeparator(); $raiseAction = $menu->addAction(c(PQNAME)->qticonsPath . '/editraise.png', tr('To front')); $raiseAction->connect(SIGNAL('triggered(bool)'), $this, SLOT('raiseObject(bool)')); $raiseAction->__pq_objectName_ = $sender->objectName; $lowerAction = $menu->addAction(c(PQNAME)->qticonsPath . '/editlower.png', tr('To back')); $lowerAction->connect(SIGNAL('triggered(bool)'), $this, SLOT('lowerObject(bool)')); $lowerAction->__pq_objectName_ = $sender->objectName; $component = get_class($sender); if ($component == 'QWidget' || $component == 'QGroupBox' || $component == 'QFrame' || $component == 'QMainWindow') { $menu_layout = $menu->addMenu(tr('Layout')); $action = $menu_layout->addAction(c(PQNAME)->qticonsPath . '/editbreaklayout.png', tr('Break layout')); $action->connect(SIGNAL('triggered(bool)'), $this, SLOT('menuLayoutAction(bool)')); $action->objectName = 'menuLayoutAction_NoLayout'; $action = $menu_layout->addAction(c(PQNAME)->qticonsPath . '/editvlayout.png', tr('Vertical layout')); $action->connect(SIGNAL('triggered(bool)'), $this, SLOT('menuLayoutAction(bool)')); $action->objectName = 'menuLayoutAction_QVBoxLayout'; $action = $menu_layout->addAction(c(PQNAME)->qticonsPath . '/edithlayout.png', tr('Horizontal layout')); $action->connect(SIGNAL('triggered(bool)'), $this, SLOT('menuLayoutAction(bool)')); $action->objectName = 'menuLayoutAction_QHBoxLayout'; } $menu->exec(mousePos()['x'], mousePos()['y']); $menu->free(); return true; case QEvent::KeyPress: if ($event->key === 16777223) { // Delete button $this->deleteObject($sender); $this->createPropertiesPanel(); } return true; case QEvent::MouseButtonPress: if ($event->button === Qt::LeftButton) { $this->startDrag($sender, $event->x, $event->y, $event->globalX, $event->globalY, $event->button); return true; } case QEvent::MouseButtonRelease: if ($event->button === Qt::LeftButton) { $this->stopDrag($sender, $event->x, $event->y, $event->globalX, $event->globalY, $event->button); return true; } case QEvent::MouseMove: $this->moveObject($sender, $event->x, $event->y, $event->globalX, $event->globalY); return true; case QEvent::Paint: $painter = new QPainter($sender); $painter->setPen("#888", 1, Qt::SolidLine); $painter->drawPointBackground(8, 8, $sender->width, $sender->height); $painter->free(); $sender->autoFillBackground = true; break; case QEvent::Resize: if ($sender->isMainWidget === true) { $sender->parent->resize($sender->x + $sender->width + $this->gridSize, $sender->y + $sender->height + $this->gridSize); } break; default: return false; } return false; }