It worked, thanks for your help!
I have another question about my Level Editor, but it does not relate to the mouse-selection issue. I dunno if I can ask it here or if I'll have to make an entirely new topic.
The issue is about copying and pasting using the QClipboard. In my editor, each Tile (re-implemented QTableWidgetItem) has a QImage for the tile image and an unsigned long for the tile's map number.
What I want is, when my Level (re-implemented QTableWidget) has its copy slot called, it copies both the image and the code to the clipboard, for each tile in the selection range. And when paste is called, it puts the copied Qimage and unsigned long for each tile, in the correct tile.
Now, I know absolutely nothing about the specifics of clipboard and QMimeData. And I dunno if something like this would work for each tile;
void copy()
{
...
//For each tile t in the selection range
//The following is most probably wrong, since I don't think I can set both text
//data and image data for the same QMimeData...
data->setImageData( t->image() );
data
->setText
( QString::number( t
->mapNumber
(),
16 ).
toUpper() ) );
...
}
void PasteCommand::redo()
{
...
//For each tile t in the selection range
//Again, the inclusion of two different types of data in the same QMimeData
//is most probably wrong...
if( data->hasImage() )
t->setImage( data->imageData() );
if( data->hasText() )
t->setMapNum( numberFromText( data->text() ) );
...
}
void copy()
{
...
//For each tile t in the selection range
QMimeData *data = new QMimeData;
//The following is most probably wrong, since I don't think I can set both text
//data and image data for the same QMimeData...
data->setImageData( t->image() );
data->setText( QString::number( t->mapNumber(), 16 ).toUpper() ) );
QApplication::clipboard()->setMimeData( data );
...
}
void PasteCommand::redo()
{
...
//For each tile t in the selection range
QMimeData *data = QApplication::clipboard()->mimeData();
//Again, the inclusion of two different types of data in the same QMimeData
//is most probably wrong...
if( data->hasImage() )
t->setImage( data->imageData() );
if( data->hasText() )
t->setMapNum( numberFromText( data->text() ) );
...
}
To copy to clipboard, switch view to plain text mode
I really have no clue on how to go about doing this.
I had an idea to copy only the map numbers to the clipboard, and then include the images corresponding to the number from my tile boxes (they hold the tiles imported from the tile sheets) when paste is called, but the code to get the image for each map number would be impractical. Furthermore, I allow the editor to place one type of tile on top of the other, creating a new tile with a new number. So, if I encounter such a tile, I'll first have to separate the number and get individual tiles and then set one on top of the other again.
I can always not include copy() and paste() functionality since I'm the only one using the editor, but I guess I shouldn't do things by half standards. And besides, it'll be a good learning experience.
Thanks for your help! And please tell me if I should make a new topic for this question.
Bookmarks