I went one step further with Arthur. I introduced some new menu items and icons. I mainly used Designer for this. I had a little problem to find some icons. I mean, not the finding was the problem, but find some open source ones. Then it came to my mind that Designer has some icons itself and they should be in the qt sources somewhere
Let it be your homework where they are.
OK. So I added the icons to buttons, and had some action signals generated by the menu item and icon interactions. All what I had to do is to connect them to some slots which do something sensible. First of all I wanted to have image saving possibility. When the user clicks the corresponding icon the program should check whether we already have a filename. If yes, we save the file. If not we pop up a save as dialog.
The easiest place for the signal connection would be the ui class, but that is generated so I didn’t want to mess up with that. So, I created a new class for event handling: ArthurActions. It is in the arthur_actions.h file. The class is inherited from QObject in order to introduce slots. So far I added two slots: onSaveImageAs and onSaveImage. I also added a private pointer to the ui and its setUi method, since I need access to the ui elements when handling ui events. E.g. in this case I need access to the pixmap of ArthurCanvas if I want to save it. When adding signals and/or slots you have to use the Q_OBJECT macro. See my former post about the nightmare it can cause eh eh. Especially when you are stupid like me
You can check the implementation of the class in arthur_actions.cpp. You will be surprised how simple it is. Saving the pixmap is the following with QT:
ui->label->pixmap()->save(imageFileName);
The file extension in the imageFileName controls the file format. I checked *.png *.xpm *.jpg *.bmp *.tif so far. All works. I start to like QT
OK. Forgetting the vtable game will take long time but this compensates somewhat. I also like the ready made QFileDialog. Really cool.
Whe the implementation was ready I just connected the ui signals to the ArthurCanvas slots in main.cpp and that is it.
Here is an example JPG which I saved with Arthur:
You can download the sources from here: fractal008
