bool csFontResizer::eventFilter(QObject *watched, QEvent *event) { if( event->type() == QEvent::KeyPress ) { QKeyEvent *keyEvent = dynamic_cast<QKeyEvent*>(event); if( keyEvent->matches(QKeySequence::ZoomIn) || (keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == Qt::Key_BracketRight) ) { resizeFont(watched, 0, incSize); return true; } else if( keyEvent->matches(QKeySequence::ZoomOut) ) { resizeFont(watched, 0, -incSize); return true; } else if( keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == Qt::Key_0 ) { resizeFont(watched, defSize.value(dynamic_cast<QWidget*>(watched), 0)); return true; } } else if( event->type() == QEvent::Wheel ) { QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent*>(event); if( wheelEvent->modifiers() == Qt::ControlModifier && wheelEvent->delta() > 0 ) { resizeFont(watched, 0, incSize); return true; } else if( wheelEvent->modifiers() == Qt::ControlModifier && wheelEvent->delta() < 0 ) { resizeFont(watched, 0, -incSize); return true; } } return QObject::eventFilter(watched, event); }
void PathBubble0::paintPathWays(QPainter *painter, vector<QString> PathWayNames) { int width=this->realRect().width(); int height=this->realRect().height(); int num=PathWayNames.size(); int column=sqrt(float(num)); int low=num/column; if(column*low<num) column+=1; int l,c; float x,y; int w=width/column; int h=height/low; int rw,rh; for(int i=0; i<PathWayNames.size(); i++) { l=i/column; c=i%column; x=l*w-width/2.0; y=c*h-height/2.0; rw=w-2, rh=h-2; QString qstr=PathWayNames[i]; QString fontType="Arial"; int fontSize=20; int style=QFont::Bold; if(rw<5) rw=5; if(rh<5) rh=5; x=x+1, y=y+1; if(highlighted==i) { QLinearGradient linearGradient(x, y, x, y+h); linearGradient.setColorAt(0.0, QColor(150,150,150,255)); linearGradient.setColorAt(1.0, QColor(138,138,168,255)); painter->setPen(QColor(148,148,178,255)); painter->setBrush( linearGradient ); } else { painter->setPen(Qt::NoPen); painter->setBrush( QColor(128,128,128,255) ); } painter->drawRect( x, y, rw, rh); //rect resizeFont(qstr, fontType , fontSize, style, rw, rh); QFont f(fontType, fontSize, style); //Arial, Courier, Arial Narrow, MS Gothic painter->setFont (f); painter->setFont(f); painter->setPen( QColor(255,255,255,255) ); painter->drawText( x, y, rw, rh, Qt::AlignCenter, qstr); //rect XL.push_back(x), XR.push_back(x+rw), YB.push_back(y), YT.push_back(y+rh); } }