<li>Queries and stores interfaces implemented in other modules. The <tt>iGenerator</tt> interface must be implemented;
the <tt>iStorage</tt> interface is optional and we can work without it.</li>
<li>Gets the main window interface <tt>iSdiWindow</tt>.</li>
- <li>Creates the layout for the main window widget and adds our widgets to the layout.</li>
+ <li>Adds our widgets to the main window layout.</li>
<li>Connects signals on widgets to slots in this class.</li>
<li>Uses actions <tt>QAction</tt> to add keyboard shortcuts -- <tt>Enter</tt> key generates a password and <tt>Esc</tt> key
quits the application.</li>
<li>Sets the <tt>mReady</tt> flag to true when all this is done.</li>
</ol>
+ <p>The main window has an empty <tt>QVBoxLayout</tt> layout and we could add our widgets directly to this layout, but for keyboard
+ shortcuts to work properly, we need a widget that fills the main window. We create a master widget, add it to the main window
+ layout and then fill the master widget with other widgets.</p>
+
<pre class="hl"><span class="hl kwb">bool</span> Module<span class="hl opt">::</span><span class="hl kwd">init</span><span class="hl opt">(</span>QString <span class="hl kwb">const</span> <span class="hl opt">&</span> args<span class="hl opt">)</span>
<span class="hl opt">{</span>
<span class="hl kwd">Q_UNUSED</span><span class="hl opt">(</span>args<span class="hl opt">);</span>
<span class="hl kwa">if</span> <span class="hl opt">(!</span>mStorage<span class="hl opt">)</span>
<span class="hl kwd">EVAF_WARNING</span><span class="hl opt">(</span><span class="hl str">"No iStorage interface"</span><span class="hl opt">);</span>
- <span class="hl slc">// Get the main window interface and fill it with widgets</span>
+ <span class="hl slc">// Get the main window interface and fill it with the widgets</span>
SdiWindow<span class="hl opt">::</span>iSdiWindow <span class="hl opt">*</span> win <span class="hl opt">=</span> evafQueryInterface<span class="hl opt"><</span>SdiWindow<span class="hl opt">::</span>iSdiWindow<span class="hl opt">>(</span><span class="hl str">"iSdiWindow"</span><span class="hl opt">);</span>
<span class="hl kwd">EVAF_TEST_X</span><span class="hl opt">(</span>win<span class="hl opt">,</span> <span class="hl str">"No iSdiWindow interface"</span><span class="hl opt">);</span>
+ QWidget <span class="hl opt">*</span> masterWidget <span class="hl opt">=</span> <span class="hl kwa">new</span> QWidget<span class="hl opt">;</span>
+ win<span class="hl opt">-></span><span class="hl kwd">addWidget</span><span class="hl opt">(</span>masterWidget<span class="hl opt">);</span>
+
QVBoxLayout <span class="hl opt">*</span> v <span class="hl opt">=</span> <span class="hl kwa">new</span> QVBoxLayout<span class="hl opt">;</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">setLayout</span><span class="hl opt">(</span>v<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">setLayout</span><span class="hl opt">(</span>v<span class="hl opt">);</span>
QGridLayout <span class="hl opt">*</span> g <span class="hl opt">=</span> <span class="hl kwa">new</span> QGridLayout<span class="hl opt">;</span>
v<span class="hl opt">-></span><span class="hl kwd">addLayout</span><span class="hl opt">(</span>g<span class="hl opt">);</span>
<span class="hl opt">}</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>wName<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">textChanged</span><span class="hl opt">(</span>QString<span class="hl opt">)),</span> <span class="hl kwa">this</span><span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">textChanged</span><span class="hl opt">(</span>QString<span class="hl opt">)));</span>
g<span class="hl opt">-></span><span class="hl kwd">addWidget</span><span class="hl opt">(</span>wName<span class="hl opt">,</span> <span class="hl num">1</span><span class="hl opt">,</span> <span class="hl num">1</span><span class="hl opt">,</span> <span class="hl num">1</span><span class="hl opt">,</span> <span class="hl num">2</span><span class="hl opt">);</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">setFocusProxy</span><span class="hl opt">(</span>wName<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">setFocusProxy</span><span class="hl opt">(</span>wName<span class="hl opt">);</span>
l <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QLabel</span><span class="hl opt">(</span><span class="hl kwd">tr</span><span class="hl opt">(</span><span class="hl str">"&Length of the password:"</span><span class="hl opt">,</span> VER_MODULE_NAME_STR<span class="hl opt">));</span>
l<span class="hl opt">-></span><span class="hl kwd">setAlignment</span><span class="hl opt">(</span>Qt<span class="hl opt">::</span>AlignRight<span class="hl opt">);</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>wCopy<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">clicked</span><span class="hl opt">()),</span> <span class="hl kwa">this</span><span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">copyClicked</span><span class="hl opt">()));</span>
h<span class="hl opt">-></span><span class="hl kwd">addWidget</span><span class="hl opt">(</span>wCopy<span class="hl opt">);</span>
- QAction <span class="hl opt">*</span> a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">());</span>
+ QAction <span class="hl opt">*</span> a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>masterWidget<span class="hl opt">);</span>
a<span class="hl opt">-></span><span class="hl kwd">setShortcut</span><span class="hl opt">(</span>Qt<span class="hl opt">::</span>Key_Return<span class="hl opt">);</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>a<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">triggered</span><span class="hl opt">()),</span> <span class="hl kwa">this</span><span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">generateClicked</span><span class="hl opt">()));</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
- a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">());</span>
+ a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>masterWidget<span class="hl opt">);</span>
a<span class="hl opt">-></span><span class="hl kwd">setShortcut</span><span class="hl opt">(</span>Qt<span class="hl opt">::</span>Key_Escape<span class="hl opt">);</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>a<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">triggered</span><span class="hl opt">()),</span> qApp<span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">quit</span><span class="hl opt">()));</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
mReady <span class="hl opt">=</span> <span class="hl kwa">true</span><span class="hl opt">;</span>
SdiWindow<span class="hl opt">::</span>iSdiWindow <span class="hl opt">*</span> win <span class="hl opt">=</span> evafQueryInterface<span class="hl opt"><</span>SdiWindow<span class="hl opt">::</span>iSdiWindow<span class="hl opt">>(</span><span class="hl str">"iSdiWindow"</span><span class="hl opt">);</span>
<span class="hl kwd">EVAF_TEST_X</span><span class="hl opt">(</span>win<span class="hl opt">,</span> <span class="hl str">"No iSdiWindow interface"</span><span class="hl opt">);</span>
+ QWidget <span class="hl opt">*</span> masterWidget <span class="hl opt">=</span> <span class="hl kwa">new</span> QWidget<span class="hl opt">;</span>
+ win<span class="hl opt">-></span><span class="hl kwd">addWidget</span><span class="hl opt">(</span>masterWidget<span class="hl opt">);</span>
+
QVBoxLayout <span class="hl opt">*</span> v <span class="hl opt">=</span> <span class="hl kwa">new</span> QVBoxLayout<span class="hl opt">;</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">setLayout</span><span class="hl opt">(</span>v<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">setLayout</span><span class="hl opt">(</span>v<span class="hl opt">);</span>
QGridLayout <span class="hl opt">*</span> g <span class="hl opt">=</span> <span class="hl kwa">new</span> QGridLayout<span class="hl opt">;</span>
v<span class="hl opt">-></span><span class="hl kwd">addLayout</span><span class="hl opt">(</span>g<span class="hl opt">);</span>
<span class="hl opt">}</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>wName<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">textChanged</span><span class="hl opt">(</span>QString<span class="hl opt">)),</span> <span class="hl kwa">this</span><span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">textChanged</span><span class="hl opt">(</span>QString<span class="hl opt">)));</span>
g<span class="hl opt">-></span><span class="hl kwd">addWidget</span><span class="hl opt">(</span>wName<span class="hl opt">,</span> <span class="hl num">1</span><span class="hl opt">,</span> <span class="hl num">1</span><span class="hl opt">,</span> <span class="hl num">1</span><span class="hl opt">,</span> <span class="hl num">2</span><span class="hl opt">);</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">setFocusProxy</span><span class="hl opt">(</span>wName<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">setFocusProxy</span><span class="hl opt">(</span>wName<span class="hl opt">);</span>
l <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QLabel</span><span class="hl opt">(</span><span class="hl kwd">tr</span><span class="hl opt">(</span><span class="hl str">"&Length of the password:"</span><span class="hl opt">,</span> VER_MODULE_NAME_STR<span class="hl opt">));</span>
l<span class="hl opt">-></span><span class="hl kwd">setAlignment</span><span class="hl opt">(</span>Qt<span class="hl opt">::</span>AlignRight<span class="hl opt">);</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>wCopy<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">clicked</span><span class="hl opt">()),</span> <span class="hl kwa">this</span><span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">copyClicked</span><span class="hl opt">()));</span>
h<span class="hl opt">-></span><span class="hl kwd">addWidget</span><span class="hl opt">(</span>wCopy<span class="hl opt">);</span>
- QAction <span class="hl opt">*</span> a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">());</span>
+ QAction <span class="hl opt">*</span> a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>masterWidget<span class="hl opt">);</span>
a<span class="hl opt">-></span><span class="hl kwd">setShortcut</span><span class="hl opt">(</span>Qt<span class="hl opt">::</span>Key_Return<span class="hl opt">);</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>a<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">triggered</span><span class="hl opt">()),</span> <span class="hl kwa">this</span><span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">generateClicked</span><span class="hl opt">()));</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
- a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">());</span>
+ a <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">QAction</span><span class="hl opt">(</span>masterWidget<span class="hl opt">);</span>
a<span class="hl opt">-></span><span class="hl kwd">setShortcut</span><span class="hl opt">(</span>Qt<span class="hl opt">::</span>Key_Escape<span class="hl opt">);</span>
<span class="hl kwd">connect</span><span class="hl opt">(</span>a<span class="hl opt">,</span> <span class="hl kwd">SIGNAL</span><span class="hl opt">(</span><span class="hl kwd">triggered</span><span class="hl opt">()),</span> qApp<span class="hl opt">,</span> <span class="hl kwd">SLOT</span><span class="hl opt">(</span><span class="hl kwd">quit</span><span class="hl opt">()));</span>
- win<span class="hl opt">-></span><span class="hl kwd">widget</span><span class="hl opt">()-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
+ masterWidget<span class="hl opt">-></span><span class="hl kwd">addAction</span><span class="hl opt">(</span>a<span class="hl opt">);</span>
mReady <span class="hl opt">=</span> <span class="hl kwa">true</span><span class="hl opt">;</span>