Exemplo n.º 1
0
KeyEvent::KeyEvent(QWidget *parent)
    : QWidget(parent)
{
    setWindowTitle(tr("键盘事件"));
    setAutoFillBackground(true);

    QPalette palette = this->palette();
    palette.setColor(QPalette::Window,Qt::white);
    setPalette(palette);

    setMinimumSize(512,256);
    setMaximumSize(512,256);

    width=size().width();
    height=size().height();

    pix = new QPixmap(width,height);
    pix->fill(Qt::white);

    image.load(":/image.png");

    startX=0;
    startY=0;
    step=20;
    drawPix();

    resize(512,256);
}
Exemplo n.º 2
0
TrayIcon::TrayIcon(QObject *parent)
        : QSystemTrayIcon(parent)
{
    yhenda();
    suurus = QSize(100,100);
	qDebug()<<"suurus.height() = "<<suurus.height();
    font = QFont("Verdana narrow",((suurus.height()-3)/2), QFont::DemiBold);

    pmap = new QPixmap(suurus);
    drawPix();

    taimer.setInterval(1200);
    taimer.start();

    connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(clicked(QSystemTrayIcon::ActivationReason)));
    connect(&taimer, SIGNAL(timeout()), this, SLOT(drawPix()));
}
void line_pattern_plot(int x, int y){
	drawPix(x,y,
		current_line_pattern.R[current_line_pattern_idx],
		current_line_pattern.G[current_line_pattern_idx],
		current_line_pattern.B[current_line_pattern_idx],
		current_line_pattern.Alpha[current_line_pattern_idx]);
	current_line_pattern_idx ++;
	if (current_line_pattern_idx>=current_line_pattern.length) current_line_pattern_idx=0;
}
	//fungsi helper
bool kapalterbang::lineIntersectsSquare(int x1, int y1, int x2, int y2, int xBL, int yBL, int xTR, int yTR){

	for (int x=xBL;x<=xTR;x++){
		long y = ((long)x-(long)x1)*((long)y2-(long)y1)/((long)x2-(long)x1)+y1;
		if (y>=yBL && y<= yTR) return true;
		drawPix(x-1,y-1,255,255,255,255);
	}
	return false;

}
Exemplo n.º 5
0
void KeyEvent::keyPressEvent(QKeyEvent *event)
{
    if(event->modifiers()==Qt::ControlModifier)
    {
        if(event->key()==Qt::Key_Left)
        {
            startX=(startX-1<0)?startX:startX-1;
        }
        if(event->key()==Qt::Key_Right)
        {
            startX=(startX+1+image.width()>width)?startX:startX+1;
        }
        if(event->key()==Qt::Key_Up)
        {
            startY=(startY-1<0)?startY:startY-1;
        }
        if(event->key()==Qt::Key_Down)
        {
            startY=(startY+1+image.height()>height)?startY:startY+1;
        }
    }
    else
    {
        startX=startX-startX%step;
        startY=startY-startY%step;
        if(event->key()==Qt::Key_Left)
        {
            startX=(startX-step<0)?startX:startX-step;
        }
        if(event->key()==Qt::Key_Right)
        {
            startX=(startX+step+image.width()>width)?startX:startX+step;
        }
        if(event->key()==Qt::Key_Up)
        {
            startY=(startY-step<0)?startY:startY-step;
        }
        if(event->key()==Qt::Key_Down)
        {
            startY=(startY+step+image.height()>height)?startY:startY+step;
        }
        if(event->key()==Qt::Key_Home)
        {
            startX=0;
            startY=0;
        }
        if(event->key()==Qt::Key_End)
        {
            startX=width-image.width();
            startY=height-image.height();
        }
    }
    drawPix();
    update();
}
Exemplo n.º 6
0
void TrayIcon::clicked(QSystemTrayIcon::ActivationReason reason)
{
    switch (reason)
    {
    case(QSystemTrayIcon::Trigger):
        {
            drawPix();
            break;
        }
    case(QSystemTrayIcon::MiddleClick):
        {
            qApp->quit();
            break;
        }
    default:
        break;
    }
}