bool MultiLayer::eventFilter(QObject *object, QEvent *e) { if ( object != (QObject *)canvas) return FALSE; switch(e->type()) { case QEvent::MouseButtonPress: { const QMouseEvent *me = (const QMouseEvent *)e; if (me->button()==QMouseEvent::LeftButton && addTextOn) addTextLayer(me->pos()); return TRUE; } case QEvent::Resize: { const QResizeEvent *re = (const QResizeEvent *)e; resizeLayers(re); } default: ; } return QObject::eventFilter(object, e); }
bool MultiLayer::eventFilter(QObject *object, QEvent *e) { if (e->type() == QEvent::MouseButtonPress && object == (QObject *)canvas) { const QMouseEvent *me = (const QMouseEvent *)e; if (me->button() == Qt::LeftButton && addTextOn) addTextLayer(me->pos()); return false; } else if (e->type() == QEvent::Resize && object == (QObject *)canvas) { resizeLayers((const QResizeEvent *)e); } else if (e->type() == QEvent::ContextMenu && object == titleBar) { emit showTitleBarMenu(); ((QContextMenuEvent *)e)->accept(); return true; } return MyWidget::eventFilter(object, e); }
void MultiLayer::resizeLayers(const QResizeEvent *re) { QSize oldSize = re->oldSize(); QSize size = re->size(); if (!oldSize.isValid()) { if (lastSize.isValid() && isVisible()) { oldSize = lastSize; } else { // TODO: for maximized windows, the size of the layers should be // saved in % of the workspace area in order to restore // the layers properly! For the moment just resize the layers to occupy // the whole canvas, although the restored geometry might be altered! oldSize = QSize(canvas->childrenRect().width() + left_margin + right_margin, canvas->childrenRect().height() + top_margin + bottom_margin); } } resizeLayers(size, oldSize, false); }