PDA

View Full Version : how can we move an image?



sh123
23rd January 2009, 08:52
how can we move an image up & down

spirit
23rd January 2009, 08:54
what do you mean? using mouse? keyboard? or programmatically?
provide more information, please.

sh123
23rd January 2009, 09:34
programmatically.sorry for the incomplete information.

jpn
23rd January 2009, 11:24
You're still not being too clear. Remember that we don't know anything about the application you're writing. An image can be shown in many ways. It would be crucial information for us to know how you do it to be able to help you.

sh123
24th January 2009, 12:46
The following is the code:

Main::Main(QGraphicsScene& c, QWidget* parent, const char* name, Qt::WindowFlags f) :
Q3MainWindow(parent,name,f),
canvas(c)
{
editor = new FigureEditor(canvas,this);
QMenuBar* menu = menuBar();
QPushButton *rotate1 = new QPushButton(tr("Rotate->"), this);
rotate1->setGeometry(2, 0, 55, 20);
connect(rotate1, SIGNAL(clicked()), this, SLOT(rotateClockwise()));

QPushButton *rotate2 = new QPushButton(tr("Rotate<-"), this);
rotate2->setGeometry(2, 18, 55, 20);
connect(rotate2, SIGNAL(clicked()), this, SLOT(rotateCounterClockwise()));

QPushButton *zoom_in = new QPushButton(tr("zoom_in"), this);
zoom_in->setGeometry(2, 36, 55, 20);
connect(zoom_in, SIGNAL(clicked()), this, SLOT(zoomIn()));

QPushButton *zoom_out = new QPushButton(tr("zoom_out"), this);
zoom_out->setGeometry(2, 54, 55, 20);
connect(zoom_out, SIGNAL(clicked()), this, SLOT(zoomOut()));

QPushButton *moveup = new QPushButton(tr("moveUp"), this);
moveup->setGeometry(2, 72, 55, 20);
connect(moveup, SIGNAL(clicked()), this, SLOT(moveU()));

QPushButton *movedown = new QPushButton(tr("movedown"), this);
movedown->setGeometry(2, 90, 55, 20);
connect(movedown, SIGNAL(clicked()), this, SLOT(moveD()));

QPushButton *moveleft = new QPushButton(tr("moveleft"), this);
moveleft->setGeometry(2, 108, 55, 20);
connect(moveleft, SIGNAL(clicked()), this, SLOT(moveL()));

QPushButton *moveright = new QPushButton(tr("moveright"), this);
moveright->setGeometry(2, 126, 55, 20);
connect(moveright, SIGNAL(clicked()), this, SLOT(moveR()));

xval=0;
yval=0;

setCentralWidget(editor);

printer = 0;

init();
}
void Main::rotateClockwise()
{
editor->rotate( 5 );
}

void Main::rotateCounterClockwise()
{
editor->rotate( -5 );
}

void Main::zoomIn()
{

editor->scale( 1.1, 1.1 );
}

void Main::zoomOut()
{
editor->scale( 0.9, 0.9 );
}

void Main::mirror()
{
editor->scale( -1, 1 );
}

void Main::moveL()
{
editor->translate( -16, 0 );
}

void Main::moveR()
{
editor->translate( +16, 0 );
}

void Main::moveU()
{
yval++;
editor->translate( 0, -660 );
}

void Main::moveD()
{
xval++;
editor->translate( 0, +660 );
}
Here the image is getting rotated clockwise & anticlockwise but not moving up,down,left & right.sorry for not using code tags instead of 2 warnings.I followed the link given by you but i could'nt understand how to use code tags.