Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > by-pkgid > 9601c7beb4ff23e834bfa171795ed560 > files > 415

vidalia-0.2.9-1mdv2010.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Vidalia: VidaliaWindow.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_695ba8f8357372e02d38c40b3c6dbe81.html">vidalia</a>
  </div>
</div>
<div class="contents">
<h1>VidaliaWindow.cpp</h1><a href="_vidalia_window_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">**  This file is part of Vidalia, and is subject to the license terms in the</span>
<a name="l00003"></a>00003 <span class="comment">**  LICENSE file, found in the top level directory of this distribution. If you</span>
<a name="l00004"></a>00004 <span class="comment">**  did not receive the LICENSE file with this file, you may obtain it from the</span>
<a name="l00005"></a>00005 <span class="comment">**  Vidalia source package distributed by the Vidalia Project at</span>
<a name="l00006"></a>00006 <span class="comment">**  http://www.vidalia-project.net/. No part of Vidalia, including this file,</span>
<a name="l00007"></a>00007 <span class="comment">**  may be copied, modified, propagated, or distributed except according to the</span>
<a name="l00008"></a>00008 <span class="comment">**  terms described in the LICENSE file.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="comment">/*</span>
<a name="l00012"></a>00012 <span class="comment">** \file VidaliaWindow.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: VidaliaWindow.cpp 3735 2009-04-28 20:28:01Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Common superclass for all Vidalia windows</span>
<a name="l00015"></a>00015 <span class="comment">*/</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="_vidalia_window_8h.html">VidaliaWindow.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_vidalia_8h.html">Vidalia.h</a>&quot;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;QPoint&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;QSize&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;QShortcut&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;QByteArray&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;QKeySequence&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;QDesktopWidget&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment">/** Default constructor. */</span>
<a name="l00029"></a><a class="code" href="class_vidalia_window.html#a4aeff3e7f32ef5aeed2b816524888aa2">00029</a> <a class="code" href="class_vidalia_window.html#a4aeff3e7f32ef5aeed2b816524888aa2">VidaliaWindow::VidaliaWindow</a>(<span class="keyword">const</span> QString &amp;name, QWidget *parent,
<a name="l00030"></a>00030                             Qt::WFlags flags)
<a name="l00031"></a>00031  : QMainWindow(parent, flags)
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033   <a class="code" href="class_vidalia_window.html#a71c82c7cce36b85121d4813271b6fe11">_name</a>     = name;
<a name="l00034"></a>00034   <a class="code" href="class_vidalia_window.html#ae690c6b902d35ccb27e8943b2b5465d2">_settings</a> = <span class="keyword">new</span> <a class="code" href="class_v_settings.html">VSettings</a>(name);
<a name="l00035"></a>00035 } 
<a name="l00036"></a>00036 <span class="comment"></span>
<a name="l00037"></a>00037 <span class="comment">/** Destructor. */</span>
<a name="l00038"></a><a class="code" href="class_vidalia_window.html#a18ce7f4077c381b40b3ff912cc6dd205">00038</a> <a class="code" href="class_vidalia_window.html#a18ce7f4077c381b40b3ff912cc6dd205">VidaliaWindow::~VidaliaWindow</a>()
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040   <a class="code" href="class_vidalia_window.html#a9c881d6124c39386821ab31c9fd0f33e">saveWindowState</a>();
<a name="l00041"></a>00041   <span class="keyword">delete</span> <a class="code" href="class_vidalia_window.html#ae690c6b902d35ccb27e8943b2b5465d2">_settings</a>;
<a name="l00042"></a>00042 }
<a name="l00043"></a>00043 <span class="comment"></span>
<a name="l00044"></a>00044 <span class="comment">/** Associates a shortcut key sequence with a slot. */</span>
<a name="l00045"></a>00045 <span class="keywordtype">void</span>
<a name="l00046"></a><a class="code" href="class_vidalia_window.html#ad3d1892561bb67129fc1b1dccea92f5f">00046</a> <a class="code" href="class_vidalia_window.html#ad3d1892561bb67129fc1b1dccea92f5f">VidaliaWindow::setShortcut</a>(<span class="keyword">const</span> QString &amp;shortcut, <span class="keyword">const</span> <span class="keywordtype">char</span> *slot)
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048   <a class="code" href="_vidalia_8h.html#aef0a1c1e9430e6b86892ae28b1577294">vApp</a>-&gt;createShortcut(QKeySequence(shortcut), <span class="keyword">this</span>, <span class="keyword">this</span>, slot);
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 <span class="comment"></span>
<a name="l00051"></a>00051 <span class="comment">/** Saves the size and location of the window. */</span>
<a name="l00052"></a>00052 <span class="keywordtype">void</span>
<a name="l00053"></a><a class="code" href="class_vidalia_window.html#a9c881d6124c39386821ab31c9fd0f33e">00053</a> <a class="code" href="class_vidalia_window.html#a9c881d6124c39386821ab31c9fd0f33e">VidaliaWindow::saveWindowState</a>()
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055 <span class="preprocessor">#if QT_VERSION &gt;= 0x040200</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>  <a class="code" href="class_vidalia_window.html#a5974e59c9417724272354f08ef3eb1ac">saveSetting</a>(<span class="stringliteral">&quot;Geometry&quot;</span>, saveGeometry());
<a name="l00057"></a>00057 <span class="preprocessor">#else</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span>  <a class="code" href="class_vidalia_window.html#a5974e59c9417724272354f08ef3eb1ac">saveSetting</a>(<span class="stringliteral">&quot;Size&quot;</span>, size());
<a name="l00059"></a>00059   <a class="code" href="class_vidalia_window.html#a5974e59c9417724272354f08ef3eb1ac">saveSetting</a>(<span class="stringliteral">&quot;Position&quot;</span>, pos());
<a name="l00060"></a>00060 <span class="preprocessor">#endif</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span>}
<a name="l00062"></a>00062 <span class="comment"></span>
<a name="l00063"></a>00063 <span class="comment">/** Restores the last size and location of the window. */</span>
<a name="l00064"></a>00064 <span class="keywordtype">void</span>
<a name="l00065"></a><a class="code" href="class_vidalia_window.html#a341a41b759d18787a10e16c5a4f91005">00065</a> <a class="code" href="class_vidalia_window.html#a341a41b759d18787a10e16c5a4f91005">VidaliaWindow::restoreWindowState</a>()
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067 <span class="preprocessor">#if QT_VERSION &gt;= 0x040200</span>
<a name="l00068"></a>00068 <span class="preprocessor"></span>  QByteArray geometry = <a class="code" href="class_vidalia_window.html#a52dc2a258fe687778e49a1abf117fade">getSetting</a>(<span class="stringliteral">&quot;Geometry&quot;</span>, QByteArray()).toByteArray();
<a name="l00069"></a>00069   <span class="keywordflow">if</span> (geometry.isEmpty())
<a name="l00070"></a>00070     adjustSize();
<a name="l00071"></a>00071   <span class="keywordflow">else</span>
<a name="l00072"></a>00072     restoreGeometry(geometry);
<a name="l00073"></a>00073 <span class="preprocessor">#else</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span>  QRect screen = QDesktopWidget().availableGeometry();
<a name="l00075"></a>00075 
<a name="l00076"></a>00076   <span class="comment">/* Restore the window size. */</span>
<a name="l00077"></a>00077   QSize size = <a class="code" href="class_vidalia_window.html#a52dc2a258fe687778e49a1abf117fade">getSetting</a>(<span class="stringliteral">&quot;Size&quot;</span>, QSize()).toSize();
<a name="l00078"></a>00078   <span class="keywordflow">if</span> (!size.isEmpty()) {
<a name="l00079"></a>00079     size = size.boundedTo(screen.size());
<a name="l00080"></a>00080     resize(size);
<a name="l00081"></a>00081   }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083   <span class="comment">/* Restore the window position. */</span>
<a name="l00084"></a>00084   QPoint pos = <a class="code" href="class_vidalia_window.html#a52dc2a258fe687778e49a1abf117fade">getSetting</a>(<span class="stringliteral">&quot;Position&quot;</span>, QPoint()).toPoint();
<a name="l00085"></a>00085   <span class="keywordflow">if</span> (!pos.isNull() &amp;&amp; screen.contains(pos)) {
<a name="l00086"></a>00086     move(pos);
<a name="l00087"></a>00087   }
<a name="l00088"></a>00088 <span class="preprocessor">#endif</span>
<a name="l00089"></a>00089 <span class="preprocessor"></span>}
<a name="l00090"></a>00090 <span class="comment"></span>
<a name="l00091"></a>00091 <span class="comment">/** Gets the saved value of a property associated with this window object.</span>
<a name="l00092"></a>00092 <span class="comment"> * If no value was saved, the default value is returned. */</span>
<a name="l00093"></a>00093 QVariant
<a name="l00094"></a><a class="code" href="class_vidalia_window.html#a52dc2a258fe687778e49a1abf117fade">00094</a> <a class="code" href="class_vidalia_window.html#a52dc2a258fe687778e49a1abf117fade">VidaliaWindow::getSetting</a>(QString setting, QVariant defaultValue)
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096   <span class="keywordflow">return</span> <a class="code" href="class_vidalia_window.html#ae690c6b902d35ccb27e8943b2b5465d2">_settings</a>-&gt;<a class="code" href="class_v_settings.html#a62a887791657ba93e55fa98b71acde30">value</a>(setting, defaultValue);
<a name="l00097"></a>00097 }
<a name="l00098"></a>00098 <span class="comment"></span>
<a name="l00099"></a>00099 <span class="comment">/** Saves a value associated with a property name for this window object. */</span>
<a name="l00100"></a>00100 <span class="keywordtype">void</span>
<a name="l00101"></a><a class="code" href="class_vidalia_window.html#a5974e59c9417724272354f08ef3eb1ac">00101</a> <a class="code" href="class_vidalia_window.html#a5974e59c9417724272354f08ef3eb1ac">VidaliaWindow::saveSetting</a>(QString prop, QVariant value)
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103   <a class="code" href="class_vidalia_window.html#ae690c6b902d35ccb27e8943b2b5465d2">_settings</a>-&gt;<a class="code" href="class_v_settings.html#a44640c06071473ba0f484dd234593801">setValue</a>(prop, value);
<a name="l00104"></a>00104 }
<a name="l00105"></a>00105 <span class="comment"></span>
<a name="l00106"></a>00106 <span class="comment">/** Overloaded QWidget::setVisible(). If this window is already visible and</span>
<a name="l00107"></a>00107 <span class="comment"> * &lt;b&gt;visible&lt;/b&gt; is true, this window will be brought to the top and given </span>
<a name="l00108"></a>00108 <span class="comment"> * focus. If &lt;b&gt;visible&lt;/b&gt; is false, then the window state will be saved and</span>
<a name="l00109"></a>00109 <span class="comment"> * this window will be hidden. */</span>
<a name="l00110"></a>00110 <span class="keywordtype">void</span>
<a name="l00111"></a><a class="code" href="class_vidalia_window.html#a995603abfbdf5bcae8da22a7bc3f15d9">00111</a> <a class="code" href="class_vidalia_window.html#a995603abfbdf5bcae8da22a7bc3f15d9">VidaliaWindow::setVisible</a>(<span class="keywordtype">bool</span> visible)
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113   <span class="keywordflow">if</span> (visible) {
<a name="l00114"></a>00114     <span class="comment">/* Bring the window to the top, if it&#39;s already open. Otherwise, make the</span>
<a name="l00115"></a>00115 <span class="comment">     * window visible. */</span>
<a name="l00116"></a>00116     <span class="keywordflow">if</span> (isVisible()) {
<a name="l00117"></a>00117       activateWindow();
<a name="l00118"></a>00118       setWindowState(windowState() &amp; ~Qt::WindowMinimized | Qt::WindowActive);
<a name="l00119"></a>00119       <span class="keyword">raise</span>();
<a name="l00120"></a>00120     } <span class="keywordflow">else</span> {
<a name="l00121"></a>00121       <a class="code" href="class_vidalia_window.html#a341a41b759d18787a10e16c5a4f91005">restoreWindowState</a>();
<a name="l00122"></a>00122     }
<a name="l00123"></a>00123   } <span class="keywordflow">else</span> {
<a name="l00124"></a>00124     <span class="comment">/* Save the last size and position of this window. */</span>
<a name="l00125"></a>00125     <a class="code" href="class_vidalia_window.html#a9c881d6124c39386821ab31c9fd0f33e">saveWindowState</a>();
<a name="l00126"></a>00126   }
<a name="l00127"></a>00127   <a class="code" href="class_vidalia_window.html#a995603abfbdf5bcae8da22a7bc3f15d9">QMainWindow::setVisible</a>(visible);
<a name="l00128"></a>00128 }
<a name="l00129"></a>00129 <span class="comment"></span>
<a name="l00130"></a>00130 <span class="comment">/** Reimplement the windows&#39; changeEvent() method to check if the event</span>
<a name="l00131"></a>00131 <span class="comment"> * is a QEvent::LanguageChange event. If so, call retranslateUi(), which</span>
<a name="l00132"></a>00132 <span class="comment"> * subclasses of VidaliaWindow can reimplement to update their UI. */</span>
<a name="l00133"></a>00133 <span class="keywordtype">void</span>
<a name="l00134"></a><a class="code" href="class_vidalia_window.html#a1681cf6509f70efd00074aa8f5a2a4eb">00134</a> <a class="code" href="class_vidalia_window.html#a1681cf6509f70efd00074aa8f5a2a4eb">VidaliaWindow::changeEvent</a>(QEvent *e)
<a name="l00135"></a>00135 {
<a name="l00136"></a>00136   <span class="keywordflow">if</span> (e-&gt;type() == QEvent::LanguageChange) {
<a name="l00137"></a>00137     <a class="code" href="class_vidalia_window.html#a0be6339c19826f3473d558a9e11ced56">retranslateUi</a>();
<a name="l00138"></a>00138     e-&gt;accept();
<a name="l00139"></a>00139     <span class="keywordflow">return</span>;
<a name="l00140"></a>00140   }
<a name="l00141"></a>00141   <a class="code" href="class_vidalia_window.html#a1681cf6509f70efd00074aa8f5a2a4eb">QMainWindow::changeEvent</a>(e);
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143 <span class="comment"></span>
<a name="l00144"></a>00144 <span class="comment">/** Called when the user wants to change the currently visible language.</span>
<a name="l00145"></a>00145 <span class="comment"> * Subclasses can reimplement this to update their UI. */</span>
<a name="l00146"></a>00146 <span class="keywordtype">void</span>
<a name="l00147"></a><a class="code" href="class_vidalia_window.html#a0be6339c19826f3473d558a9e11ced56">00147</a> <a class="code" href="class_vidalia_window.html#a0be6339c19826f3473d558a9e11ced56">VidaliaWindow::retranslateUi</a>()
<a name="l00148"></a>00148 {
<a name="l00149"></a>00149   <span class="comment">/* The default retranslateUi() implementation does nothing */</span>
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:55 2010 for Vidalia by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>