2018-09-24 04:17:15 +02:00
|
|
|
|
|
|
|
|
|
First steps with the Final Cut widget toolkit
|
|
|
|
|
=============================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
How to use the library
|
|
|
|
|
----------------------
|
|
|
|
|
|
2018-09-26 18:01:44 +02:00
|
|
|
|
At the beginning of this introduction to the Final Cut
|
|
|
|
|
we will start with a small example.
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|
2018-11-01 00:49:13 +01:00
|
|
|
|
The following example creates an empty 30×10 character dialog.
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|
|
|
|
|
**File:** *dialog.cpp*
|
|
|
|
|
```cpp
|
|
|
|
|
#include <final/final.h>
|
|
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
finalcut::FApplication app(argc, argv);
|
|
|
|
|
finalcut::FDialog dialog(&app);
|
|
|
|
|
dialog.setText ("A dialog");
|
|
|
|
|
dialog.setGeometry (25, 5, 30, 10);
|
|
|
|
|
app.setMainWidget(&dialog);
|
|
|
|
|
dialog.show();
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|
|
|
|
|
```
|
2018-11-18 22:50:45 +01:00
|
|
|
|
*(Note: You can close the dialog with the mouse,
|
2018-12-03 03:22:36 +01:00
|
|
|
|
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|
|
|
|
|
|
2018-09-26 18:01:44 +02:00
|
|
|
|
After entering the source code in *dialog.cpp* you can compile
|
2018-09-24 04:17:15 +02:00
|
|
|
|
the above program with gcc:
|
|
|
|
|
```cpp
|
|
|
|
|
g++ -O2 -lfinal dialog.cpp -o dialog
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
How it works
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
#include <final/final.h>
|
|
|
|
|
```
|
2018-09-26 18:01:44 +02:00
|
|
|
|
All final cut programs must include the *final.h* header.
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
finalcut::FApplication app(argc, argv);
|
|
|
|
|
```
|
2018-11-01 00:49:13 +01:00
|
|
|
|
This line creates the `finalcut::FApplication` object `app` with
|
2018-09-26 18:01:44 +02:00
|
|
|
|
the command line arguments `argc` and `argv`. This object manages
|
|
|
|
|
the application main event loop. It receives keyboard and mouse events
|
2018-11-01 00:49:13 +01:00
|
|
|
|
and sends them to the target widgets. You must create an application
|
|
|
|
|
object before you can create a widgets object.
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|
|
|
|
|
The next line
|
|
|
|
|
```cpp
|
|
|
|
|
finalcut::FDialog dialog(&app);
|
|
|
|
|
```
|
2018-09-26 18:01:44 +02:00
|
|
|
|
creates the `finalcut::FDialog` object `dialog` with the object `app`
|
|
|
|
|
as parent object. The `finalcut::FDialog` class is the base class for
|
2018-09-24 04:17:15 +02:00
|
|
|
|
creating dialog windows.
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
dialog.setText ("A dialog");
|
|
|
|
|
```
|
|
|
|
|
The title bar of the dialog box gets the text "A dialog".
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
dialog.setGeometry (25, 5, 30, 10);
|
|
|
|
|
```
|
2018-11-01 00:49:13 +01:00
|
|
|
|
The dialog window gets a width of 30 and a height of 10 characters.
|
2018-11-03 01:32:51 +01:00
|
|
|
|
The position of the window in the terminal is at x=25 and
|
2018-11-01 00:49:13 +01:00
|
|
|
|
y=5 (note: x=1 and y=1 represents the upper left corner).
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
app.setMainWidget(&dialog);
|
|
|
|
|
```
|
2018-11-01 00:49:13 +01:00
|
|
|
|
The `dialog` object was now selected as the main widget for the application.
|
|
|
|
|
When you close the main widget, the entire application quits.
|
|
|
|
|
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
dialog.show();
|
|
|
|
|
```
|
|
|
|
|
A window or widget is not visible directly after its creation.
|
2018-09-26 18:01:44 +02:00
|
|
|
|
Only the call of `show()` makes it (and its child objects,
|
2018-09-24 04:17:15 +02:00
|
|
|
|
if available) visible.
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
return app.exec();
|
|
|
|
|
```
|
2018-09-26 18:01:44 +02:00
|
|
|
|
The last line calls `exec()` to start the application and return
|
2018-11-03 01:32:51 +01:00
|
|
|
|
the result to the operating system. The started application enters
|
|
|
|
|
the main event loop. This loop does not end until the window is
|
|
|
|
|
not closed.
|
2018-09-24 04:17:15 +02:00
|
|
|
|
|