Sophie

Sophie

distrib > Mandriva > current > x86_64 > by-pkgid > 4272c97b1af3db3f39a3b697bcba7e48 > files > 353

albumshaper-2.1-7mdv2010.1.x86_64.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>AlbumShaper: addPhotosDialog.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.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</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>
    </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>
<h1>addPhotosDialog.cpp</h1><a href="addPhotosDialog_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">//  copyright            : (C) 2003-2005 by Will Stokes</span>
<a name="l00003"></a>00003 <span class="comment">//==============================================</span>
<a name="l00004"></a>00004 <span class="comment">//  This program is free software; you can redistribute it</span>
<a name="l00005"></a>00005 <span class="comment">//  and/or modify it under the terms of the GNU General</span>
<a name="l00006"></a>00006 <span class="comment">//  Public License as published by the Free Software</span>
<a name="l00007"></a>00007 <span class="comment">//  Foundation; either version 2 of the License, or</span>
<a name="l00008"></a>00008 <span class="comment">//  (at your option) any later version.</span>
<a name="l00009"></a>00009 <span class="comment">//==============================================</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="comment">//Systemwide includes</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;qlabel.h&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;qfiledialog.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;qcheckbox.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;qlayout.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;qpixmap.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;qimage.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;qlayout.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;qfileinfo.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;qmutex.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;qthread.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;qevent.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;qapplication.h&gt;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="comment">//Projectwide includes</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &quot;<a class="code" href="addPhotosDialog_8h.html">addPhotosDialog.h</a>&quot;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;../../config.h&quot;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;../../backend/tools/imageTools.h&quot;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="addPhotosDialog_8cpp.html#ad3ee0cc681d736cb6d41c4ebb04c0ae4">00030</a> <span class="preprocessor">#define MIN_WIDTH 240</span>
<a name="l00031"></a><a class="code" href="addPhotosDialog_8cpp.html#a1610a21b358c3531db64b3208fa70e5b">00031</a> <span class="preprocessor"></span><span class="preprocessor">#define MIN_HEIGHT 180</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span>
<a name="l00033"></a><a class="code" href="addPhotosDialog_8cpp.html#a52b0ff50913ad7c63e38a078a3e72a86">00033</a> <span class="preprocessor">#define UPDATE_PREVIEW_DETAILS QEvent::User</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span>
<a name="l00035"></a>00035 <span class="comment">//================================</span>
<a name="l00036"></a>00036 <span class="comment">//Qt requires us to pass information for GUI posting from the worker thread to the </span>
<a name="l00037"></a>00037 <span class="comment">//GUI thread via events as opposed to directly posting the events ourselves. in order</span>
<a name="l00038"></a>00038 <span class="comment">//to update the file preview we&#39;ll construct custom UpdatePreviewEvents that contain</span>
<a name="l00039"></a>00039 <span class="comment">//the updated preview image and file details.</span>
<a name="l00040"></a><a class="code" href="classUpdatePreviewEvent.html">00040</a> <span class="keyword">class </span><a class="code" href="classUpdatePreviewEvent.html">UpdatePreviewEvent</a> : <span class="keyword">public</span> <a class="code" href="classQCustomEvent.html">QCustomEvent</a>
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042 <span class="keyword">public</span>:
<a name="l00043"></a><a class="code" href="classUpdatePreviewEvent.html#a0d9256cefa172150c320b684a6b8b3e8">00043</a>   <a class="code" href="classUpdatePreviewEvent.html#a0d9256cefa172150c320b684a6b8b3e8">UpdatePreviewEvent</a>( QImage <a class="code" href="classUpdatePreviewEvent.html#ab72d0bbc5030c0d8c5825a62b187c348">image</a>, QString <a class="code" href="classUpdatePreviewEvent.html#a8f46ef75f1a95fc1bae8f4be67526f97">details</a> ) : <a class="code" href="classQCustomEvent.html">QCustomEvent</a>( <a class="code" href="addPhotosDialog_8cpp.html#a52b0ff50913ad7c63e38a078a3e72a86">UPDATE_PREVIEW_DETAILS</a> )
<a name="l00044"></a>00044   {
<a name="l00045"></a>00045     this-&gt;image = image;
<a name="l00046"></a>00046     this-&gt;details = details;
<a name="l00047"></a>00047   }
<a name="l00048"></a>00048 
<a name="l00049"></a>00049   <span class="comment">//returns the preview image</span>
<a name="l00050"></a><a class="code" href="classUpdatePreviewEvent.html#a4daef240d90dff70d9a0d2b999e5bd66">00050</a>   QImage <a class="code" href="classUpdatePreviewEvent.html#a4daef240d90dff70d9a0d2b999e5bd66">getImage</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classUpdatePreviewEvent.html#ab72d0bbc5030c0d8c5825a62b187c348">image</a>; }
<a name="l00051"></a>00051   
<a name="l00052"></a>00052   <span class="comment">//returns the file details string</span>
<a name="l00053"></a><a class="code" href="classUpdatePreviewEvent.html#a54909fc8f3acf59b1c7bc855559b7a6e">00053</a>   QString <a class="code" href="classUpdatePreviewEvent.html#a54909fc8f3acf59b1c7bc855559b7a6e">getDetails</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classUpdatePreviewEvent.html#a8f46ef75f1a95fc1bae8f4be67526f97">details</a>; }
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="keyword">private</span>:
<a name="l00056"></a><a class="code" href="classUpdatePreviewEvent.html#ab72d0bbc5030c0d8c5825a62b187c348">00056</a>   QImage <a class="code" href="classUpdatePreviewEvent.html#ab72d0bbc5030c0d8c5825a62b187c348">image</a>;
<a name="l00057"></a><a class="code" href="classUpdatePreviewEvent.html#a8f46ef75f1a95fc1bae8f4be67526f97">00057</a>   QString <a class="code" href="classUpdatePreviewEvent.html#a8f46ef75f1a95fc1bae8f4be67526f97">details</a>;
<a name="l00058"></a>00058 };
<a name="l00059"></a>00059 <span class="comment">//================================</span>
<a name="l00060"></a><a class="code" href="classGeneratePreviewThread.html#a07eb50f20a9a67448e8b2d33c1252328">00060</a> <a class="code" href="classGeneratePreviewThread.html#a07eb50f20a9a67448e8b2d33c1252328">GeneratePreviewThread::GeneratePreviewThread</a>( <a class="code" href="classFilePreview.html">FilePreview</a>* previewWidget )
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062   <span class="comment">//we&#39;ll need to store a previewWidget handle to </span>
<a name="l00063"></a>00063   <span class="comment">//posting update events when updates are</span>
<a name="l00064"></a>00064   <span class="comment">//ready to be shown</span>
<a name="l00065"></a>00065   this-&gt;previewWidget = previewWidget;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067   <span class="comment">//by default worker thread isn&#39;t busy yet</span>
<a name="l00068"></a>00068   <a class="code" href="classGeneratePreviewThread.html#a4809be79bf9c1c67561868fbcc88fd1f" title="is the worker thread currently generating a file preview?">updating</a> = <span class="keyword">false</span>;
<a name="l00069"></a>00069   <a class="code" href="classGeneratePreviewThread.html#ad7505a7bf8e25d9208d96ddb51f5ca65" title="next file to be processed by worker thread">queue</a> = QString::null;
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 <span class="comment">//================================</span>
<a name="l00072"></a><a class="code" href="classGeneratePreviewThread.html#a29affa3f16c4b04522de227d68ac2450">00072</a> <span class="keywordtype">void</span> <a class="code" href="classGeneratePreviewThread.html#a29affa3f16c4b04522de227d68ac2450">GeneratePreviewThread::start</a>( QString filename )
<a name="l00073"></a>00073 {
<a name="l00074"></a>00074   <span class="comment">//get lock</span>
<a name="l00075"></a>00075   <a class="code" href="classGeneratePreviewThread.html#a6611d14aeaa6173cc6e256a817865984" title="locking mutex - necessary to prevent multiple threads from accessing the updating...">lockingMutex</a>.lock();
<a name="l00076"></a>00076   
<a name="l00077"></a>00077   <span class="comment">//if currently animating then append job to queue</span>
<a name="l00078"></a>00078   <span class="keywordflow">if</span>(<a class="code" href="classGeneratePreviewThread.html#a4809be79bf9c1c67561868fbcc88fd1f" title="is the worker thread currently generating a file preview?">updating</a>)
<a name="l00079"></a>00079   {
<a name="l00080"></a>00080     <a class="code" href="classGeneratePreviewThread.html#ad7505a7bf8e25d9208d96ddb51f5ca65" title="next file to be processed by worker thread">queue</a> = filename;
<a name="l00081"></a>00081     <a class="code" href="classGeneratePreviewThread.html#a6611d14aeaa6173cc6e256a817865984" title="locking mutex - necessary to prevent multiple threads from accessing the updating...">lockingMutex</a>.unlock();
<a name="l00082"></a>00082     <span class="keywordflow">return</span>; 
<a name="l00083"></a>00083   }
<a name="l00084"></a>00084   <span class="comment">//else set animating to true, actually initiate job</span>
<a name="l00085"></a>00085   <span class="keywordflow">else</span>
<a name="l00086"></a>00086   {
<a name="l00087"></a>00087     <a class="code" href="classGeneratePreviewThread.html#a4809be79bf9c1c67561868fbcc88fd1f" title="is the worker thread currently generating a file preview?">updating</a> = <span class="keyword">true</span>;
<a name="l00088"></a>00088     this-&gt;filename = filename;
<a name="l00089"></a>00089     <a class="code" href="classGeneratePreviewThread.html#a6611d14aeaa6173cc6e256a817865984" title="locking mutex - necessary to prevent multiple threads from accessing the updating...">lockingMutex</a>.unlock();
<a name="l00090"></a>00090     <a class="code" href="classGeneratePreviewThread.html#a29affa3f16c4b04522de227d68ac2450">QThread::start</a>();
<a name="l00091"></a>00091   }
<a name="l00092"></a>00092 }
<a name="l00093"></a>00093 <span class="comment">//================================</span>
<a name="l00094"></a><a class="code" href="classGeneratePreviewThread.html#a1ea5bdb72a79bbc081829dd0fbcc6eb0">00094</a> <span class="keywordtype">void</span> <a class="code" href="classGeneratePreviewThread.html#a1ea5bdb72a79bbc081829dd0fbcc6eb0">GeneratePreviewThread::run</a>()
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096   <span class="comment">//since it is possible for another job</span>
<a name="l00097"></a>00097   <span class="comment">//to be added to the queue while processing this one, it is necessary</span>
<a name="l00098"></a>00098   <span class="comment">//to loop until the queue is empty</span>
<a name="l00099"></a>00099   <span class="keywordflow">while</span>(<span class="keyword">true</span>)
<a name="l00100"></a>00100   {
<a name="l00101"></a>00101     <span class="comment">//------------------------------------------</span>
<a name="l00102"></a>00102     <span class="comment">//Get image type extension and convert to caps  </span>
<a name="l00103"></a>00103     QString extension = QFileInfo(<a class="code" href="classGeneratePreviewThread.html#acd55c605c796212412940d4988f4253a" title="current file being processed">filename</a>).extension(<span class="keyword">false</span>).upper();
<a name="l00104"></a>00104     <span class="keywordtype">bool</span> validExtension = ( (extension.compare(<span class="stringliteral">&quot;GIF&quot;</span>) == 0) ||
<a name="l00105"></a>00105                             (extension.compare(<span class="stringliteral">&quot;JPG&quot;</span>) == 0) ||
<a name="l00106"></a>00106                             (extension.compare(<span class="stringliteral">&quot;JPEG&quot;</span>) == 0) ||
<a name="l00107"></a>00107                             (extension.compare(<span class="stringliteral">&quot;PNG&quot;</span>) == 0) ||
<a name="l00108"></a>00108                             (extension.compare(<span class="stringliteral">&quot;XPM&quot;</span>) == 0) );
<a name="l00109"></a>00109     <span class="comment">//------------------------------------------</span>
<a name="l00110"></a>00110     <span class="comment">//Scale the image to fit nicely on the screen, aka &lt; 300x225</span>
<a name="l00111"></a>00111     QImage scaledImage;
<a name="l00112"></a>00112     <span class="keywordflow">if</span>( validExtension )
<a name="l00113"></a>00113     {
<a name="l00114"></a>00114       <a class="code" href="imageTools_8cpp.html#a126e11984fb8124e78e3b1b68a24870c" title="Scale image and save copy to disk.">scaleImage</a>(<a class="code" href="classGeneratePreviewThread.html#acd55c605c796212412940d4988f4253a" title="current file being processed">filename</a>, scaledImage, <a class="code" href="addPhotosDialog_8cpp.html#ad3ee0cc681d736cb6d41c4ebb04c0ae4">MIN_WIDTH</a>, <a class="code" href="addPhotosDialog_8cpp.html#a1610a21b358c3531db64b3208fa70e5b">MIN_HEIGHT</a> );
<a name="l00115"></a>00115     }
<a name="l00116"></a>00116     <span class="comment">//------------------------------------------</span>
<a name="l00117"></a>00117     <span class="comment">//Get image resolution</span>
<a name="l00118"></a>00118     QString imageRes = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00119"></a>00119     <span class="keywordflow">if</span>(validExtension)
<a name="l00120"></a>00120     {
<a name="l00121"></a>00121       QSize res;
<a name="l00122"></a>00122       <a class="code" href="imageTools_8cpp.html#a2af7f0a9c4f931ad3213c36796e95288" title="Get image dimensions.">getImageSize</a>( <a class="code" href="classGeneratePreviewThread.html#acd55c605c796212412940d4988f4253a" title="current file being processed">filename</a>, res );
<a name="l00123"></a>00123       imageRes = QString(<span class="stringliteral">&quot;%1 x %2&quot;</span>).arg(res.width()).arg(res.height());
<a name="l00124"></a>00124     }
<a name="l00125"></a>00125     <span class="comment">//------------------------------------------</span>
<a name="l00126"></a>00126     <span class="comment">//Determine file size and construct a nicely formatted size string</span>
<a name="l00127"></a>00127     QString fileSize = <span class="stringliteral">&quot;?&quot;</span>;
<a name="l00128"></a>00128     QFileInfo info;
<a name="l00129"></a>00129     info.setFile( <a class="code" href="classGeneratePreviewThread.html#acd55c605c796212412940d4988f4253a" title="current file being processed">filename</a> );
<a name="l00130"></a>00130     <span class="keywordtype">int</span> sizeOnDisk = info.size();
<a name="l00131"></a>00131     
<a name="l00132"></a>00132     <span class="keywordflow">if</span>(sizeOnDisk &lt; 1024)
<a name="l00133"></a>00133       fileSize = QString(<span class="stringliteral">&quot;%1 Byte%2&quot;</span>).arg(sizeOnDisk).arg( sizeOnDisk == 0 || sizeOnDisk &gt; 1 ? <span class="stringliteral">&quot;s&quot;</span> : <span class="stringliteral">&quot;&quot;</span>);
<a name="l00134"></a>00134     <span class="keywordflow">else</span> <span class="keywordflow">if</span>( sizeOnDisk/1024 &lt; 1024)
<a name="l00135"></a>00135       <span class="comment">//    fileSize = QString(&quot;%1 Kb&quot;).arg( ((float)*sizeOnDisk)/1024 );</span>
<a name="l00136"></a>00136       fileSize = QString(<span class="stringliteral">&quot;%1 Kb&quot;</span>).arg( ((<span class="keywordtype">float</span>)((100*sizeOnDisk)/1024))/100 );
<a name="l00137"></a>00137     <span class="keywordflow">else</span> <span class="keywordflow">if</span>( sizeOnDisk/(1024*1024) &lt; 1024)
<a name="l00138"></a>00138       fileSize = QString(<span class="stringliteral">&quot;%1 Mb&quot;</span>).arg( ((<span class="keywordtype">float</span>)((100*sizeOnDisk)/(1024*1024)))/100 );
<a name="l00139"></a>00139     <span class="keywordflow">else</span>
<a name="l00140"></a>00140       fileSize = QString(<span class="stringliteral">&quot;%1 Gigs&quot;</span>).arg( ((<span class="keywordtype">float</span>)((100*sizeOnDisk)/(1024*1024*1024)))/100 );   
<a name="l00141"></a>00141     <span class="comment">//------------------------------------------</span>
<a name="l00142"></a>00142     <span class="comment">//Setup image details string  </span>
<a name="l00143"></a>00143     QString fileDetails = QString(<span class="stringliteral">&quot;%1 %2, %3&quot;</span>)
<a name="l00144"></a>00144                                   .arg(imageRes)
<a name="l00145"></a>00145                                   .arg(extension)
<a name="l00146"></a>00146                                   .arg(fileSize);
<a name="l00147"></a>00147     <span class="comment">//------------------------------------------</span>
<a name="l00148"></a>00148     <span class="comment">//Post UPDATE_PREVIEW_DETAILS event</span>
<a name="l00149"></a>00149     <a class="code" href="classUpdatePreviewEvent.html">UpdatePreviewEvent</a>* upe = <span class="keyword">new</span> <a class="code" href="classUpdatePreviewEvent.html">UpdatePreviewEvent</a>( scaledImage, fileDetails );
<a name="l00150"></a>00150     QApplication::postEvent( <a class="code" href="classGeneratePreviewThread.html#acced915beb70c76416f0518aea250104" title="handle on preview widget necessary for posting an update event once the current file...">previewWidget</a>, upe );
<a name="l00151"></a>00151     <span class="comment">//------------------------------------------</span>
<a name="l00152"></a>00152     <span class="comment">//get lock</span>
<a name="l00153"></a>00153     <a class="code" href="classGeneratePreviewThread.html#a6611d14aeaa6173cc6e256a817865984" title="locking mutex - necessary to prevent multiple threads from accessing the updating...">lockingMutex</a>.lock();
<a name="l00154"></a>00154     
<a name="l00155"></a>00155     <span class="comment">//if the queue is empty we&#39;re done!</span>
<a name="l00156"></a>00156     <span class="keywordflow">if</span>( <a class="code" href="classGeneratePreviewThread.html#ad7505a7bf8e25d9208d96ddb51f5ca65" title="next file to be processed by worker thread">queue</a>.isNull() )
<a name="l00157"></a>00157     {
<a name="l00158"></a>00158       <a class="code" href="classGeneratePreviewThread.html#a4809be79bf9c1c67561868fbcc88fd1f" title="is the worker thread currently generating a file preview?">updating</a> = <span class="keyword">false</span>;
<a name="l00159"></a>00159       <a class="code" href="classGeneratePreviewThread.html#a6611d14aeaa6173cc6e256a817865984" title="locking mutex - necessary to prevent multiple threads from accessing the updating...">lockingMutex</a>.unlock();
<a name="l00160"></a>00160       <span class="keywordflow">return</span>; 
<a name="l00161"></a>00161     }
<a name="l00162"></a>00162     <span class="comment">//clear queue and process pending job</span>
<a name="l00163"></a>00163     <span class="keywordflow">else</span>
<a name="l00164"></a>00164     {
<a name="l00165"></a>00165       <a class="code" href="classGeneratePreviewThread.html#acd55c605c796212412940d4988f4253a" title="current file being processed">filename</a> = <a class="code" href="classGeneratePreviewThread.html#ad7505a7bf8e25d9208d96ddb51f5ca65" title="next file to be processed by worker thread">queue</a>;
<a name="l00166"></a>00166       <a class="code" href="classGeneratePreviewThread.html#ad7505a7bf8e25d9208d96ddb51f5ca65" title="next file to be processed by worker thread">queue</a> = QString::null;
<a name="l00167"></a>00167       <a class="code" href="classGeneratePreviewThread.html#a6611d14aeaa6173cc6e256a817865984" title="locking mutex - necessary to prevent multiple threads from accessing the updating...">lockingMutex</a>.unlock();
<a name="l00168"></a>00168     }
<a name="l00169"></a>00169     
<a name="l00170"></a>00170   } <span class="comment">//end while(true)</span>
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172 <span class="comment">//================================</span>
<a name="l00173"></a><a class="code" href="classFilePreview.html#adbc18ed317e28adeed02779527168d9f">00173</a> <a class="code" href="classFilePreview.html#adbc18ed317e28adeed02779527168d9f">FilePreview::FilePreview</a>(<a class="code" href="classQWidget.html">QWidget</a>* parent) : <a class="code" href="classQWidget.html">QWidget</a>(parent) 
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175   <span class="comment">//create widgets for display preview image and details</span>
<a name="l00176"></a>00176   <a class="code" href="classFilePreview.html#a93c12f19e09638dd16f4df9acc5a93ef" title="preview of last selected file">filePreview</a> = <span class="keyword">new</span> <a class="code" href="classQLabel.html">QLabel</a>( <span class="keyword">this</span> );  
<a name="l00177"></a>00177   <a class="code" href="classFilePreview.html#a88cefa8ce11426e930e473142d940ad1" title="details about last selected file">fileDetails</a> = <span class="keyword">new</span> <a class="code" href="classQLabel.html">QLabel</a>( <span class="keyword">this</span> );  
<a name="l00178"></a>00178   
<a name="l00179"></a>00179   QGridLayout* grid = <span class="keyword">new</span> QGridLayout( <span class="keyword">this</span>, 4, 3 );
<a name="l00180"></a>00180   grid-&gt;setRowStretch( 0, 1 );
<a name="l00181"></a>00181   grid-&gt;addWidget( <a class="code" href="classFilePreview.html#a93c12f19e09638dd16f4df9acc5a93ef" title="preview of last selected file">filePreview</a>, 1, 1, Qt::AlignHCenter );
<a name="l00182"></a>00182   grid-&gt;addWidget( <a class="code" href="classFilePreview.html#a88cefa8ce11426e930e473142d940ad1" title="details about last selected file">fileDetails</a>, 2, 1, Qt::AlignHCenter );
<a name="l00183"></a>00183   grid-&gt;setRowStretch( 3, 1 );
<a name="l00184"></a>00184 
<a name="l00185"></a>00185   grid-&gt;setColStretch( 0, 1 );
<a name="l00186"></a>00186   grid-&gt;setColStretch( 2, 1 );
<a name="l00187"></a>00187  
<a name="l00188"></a>00188   <span class="comment">//create a generator thread that will be used for actually generating </span>
<a name="l00189"></a>00189   <span class="comment">//preview images and constructing details strings</span>
<a name="l00190"></a>00190   <a class="code" href="classFilePreview.html#abc98931b02f0a31e2cb17bf3da3e3e07" title="a worker thread that actually generates the file preview image and details information...">generatorThread</a> = <span class="keyword">new</span> <a class="code" href="classGeneratePreviewThread.html">GeneratePreviewThread</a>(<span class="keyword">this</span>);
<a name="l00191"></a>00191 }
<a name="l00192"></a>00192 <span class="comment">//==============================================</span>
<a name="l00193"></a><a class="code" href="classFilePreview.html#a92c81c8fe975be2d2b385274b13414ea">00193</a> <a class="code" href="classFilePreview.html#a92c81c8fe975be2d2b385274b13414ea">FilePreview::~FilePreview</a>()
<a name="l00194"></a>00194 {
<a name="l00195"></a>00195   <span class="comment">//make sure generator thread is done!</span>
<a name="l00196"></a>00196   <a class="code" href="classFilePreview.html#abc98931b02f0a31e2cb17bf3da3e3e07" title="a worker thread that actually generates the file preview image and details information...">generatorThread</a>-&gt;wait();
<a name="l00197"></a>00197   <span class="keyword">delete</span> <a class="code" href="classFilePreview.html#abc98931b02f0a31e2cb17bf3da3e3e07" title="a worker thread that actually generates the file preview image and details information...">generatorThread</a>;
<a name="l00198"></a>00198   <a class="code" href="classFilePreview.html#abc98931b02f0a31e2cb17bf3da3e3e07" title="a worker thread that actually generates the file preview image and details information...">generatorThread</a> = NULL;
<a name="l00199"></a>00199 }
<a name="l00200"></a>00200 <span class="comment">//==============================================</span>
<a name="l00201"></a><a class="code" href="classFilePreview.html#ab007946217dd7efc63b0e2ffdc88ecc9">00201</a> QSize <a class="code" href="classFilePreview.html#ab007946217dd7efc63b0e2ffdc88ecc9">FilePreview::minimumSizeHint</a> ()<span class="keyword"> const</span>
<a name="l00202"></a>00202 <span class="keyword"></span>{
<a name="l00203"></a>00203   QFontMetrics fm( font() );
<a name="l00204"></a>00204   <span class="keywordflow">return</span> QSize(<a class="code" href="addPhotosDialog_8cpp.html#ad3ee0cc681d736cb6d41c4ebb04c0ae4">MIN_WIDTH</a>, <a class="code" href="addPhotosDialog_8cpp.html#a1610a21b358c3531db64b3208fa70e5b">MIN_HEIGHT</a> + 2*fm.height() );
<a name="l00205"></a>00205 }
<a name="l00206"></a>00206 <span class="comment">//==============================================</span>
<a name="l00207"></a><a class="code" href="classFilePreview.html#a4011d44115502e66f28e1b9b5d866ca2">00207</a> <span class="keywordtype">void</span> <a class="code" href="classFilePreview.html#a4011d44115502e66f28e1b9b5d866ca2" title="handle update events that come from the GeneratePreviewThread">FilePreview::customEvent</a>( <a class="code" href="classQCustomEvent.html">QCustomEvent</a> * e )
<a name="l00208"></a>00208 {
<a name="l00209"></a>00209   <span class="comment">//handle UpdatePrevewEvents that are sent from the worker thread</span>
<a name="l00210"></a>00210   <span class="comment">//by update the preview image and details that are shown</span>
<a name="l00211"></a>00211   <span class="keywordflow">if</span> ( e-&gt;type() == <a class="code" href="addPhotosDialog_8cpp.html#a52b0ff50913ad7c63e38a078a3e72a86">UPDATE_PREVIEW_DETAILS</a> ) 
<a name="l00212"></a>00212   {  
<a name="l00213"></a>00213     <a class="code" href="classUpdatePreviewEvent.html">UpdatePreviewEvent</a>* upe = (<a class="code" href="classUpdatePreviewEvent.html">UpdatePreviewEvent</a>*)e;
<a name="l00214"></a>00214 
<a name="l00215"></a>00215     <span class="keywordflow">if</span>( !upe-&gt;<a class="code" href="classUpdatePreviewEvent.html#a4daef240d90dff70d9a0d2b999e5bd66">getImage</a>().isNull() )
<a name="l00216"></a>00216     {
<a name="l00217"></a>00217       QPixmap scaledPixmap;
<a name="l00218"></a>00218       scaledPixmap.convertFromImage( upe-&gt;<a class="code" href="classUpdatePreviewEvent.html#a4daef240d90dff70d9a0d2b999e5bd66">getImage</a>() );
<a name="l00219"></a>00219       <a class="code" href="classFilePreview.html#a93c12f19e09638dd16f4df9acc5a93ef" title="preview of last selected file">filePreview</a>-&gt;setPixmap( scaledPixmap );
<a name="l00220"></a>00220     }
<a name="l00221"></a>00221     
<a name="l00222"></a>00222     <a class="code" href="classFilePreview.html#a88cefa8ce11426e930e473142d940ad1" title="details about last selected file">fileDetails</a>-&gt;setText( upe-&gt;<a class="code" href="classUpdatePreviewEvent.html#a54909fc8f3acf59b1c7bc855559b7a6e">getDetails</a>() );
<a name="l00223"></a>00223   }
<a name="l00224"></a>00224 }
<a name="l00225"></a>00225 <span class="comment">//==============================================</span>
<a name="l00226"></a><a class="code" href="classFilePreview.html#adeef143a0e947ab5a45835e1a3062602">00226</a> <span class="keywordtype">void</span> <a class="code" href="classFilePreview.html#adeef143a0e947ab5a45835e1a3062602" title="call this function to update the file preview">FilePreview::updatePreview</a>( <span class="keyword">const</span> QString&amp; filename )
<a name="l00227"></a>00227 {
<a name="l00228"></a>00228   <span class="comment">//handle requests to update the preview information by asking</span>
<a name="l00229"></a>00229   <span class="comment">//the generator thread to handle them. by using</span>
<a name="l00230"></a>00230   <span class="comment">//an auxiallary thread we can process requests very quickly while</span>
<a name="l00231"></a>00231   <span class="comment">//any current work being done to generate an image preview continues</span>
<a name="l00232"></a>00232   <span class="keywordflow">if</span>( <a class="code" href="classFilePreview.html#abc98931b02f0a31e2cb17bf3da3e3e07" title="a worker thread that actually generates the file preview image and details information...">generatorThread</a> != NULL)
<a name="l00233"></a>00233   {
<a name="l00234"></a>00234     <a class="code" href="classFilePreview.html#abc98931b02f0a31e2cb17bf3da3e3e07" title="a worker thread that actually generates the file preview image and details information...">generatorThread</a>-&gt;<a class="code" href="classGeneratePreviewThread.html#a29affa3f16c4b04522de227d68ac2450">start</a>( filename );
<a name="l00235"></a>00235   }
<a name="l00236"></a>00236 }
<a name="l00237"></a>00237 <span class="comment">//==============================================</span>
<a name="l00238"></a><a class="code" href="classAddPhotosDialog.html#a6627eb29f74eddf8acd16649c25ab5ac">00238</a> <a class="code" href="classAddPhotosDialog.html#a6627eb29f74eddf8acd16649c25ab5ac">AddPhotosDialog::AddPhotosDialog</a>(QString path, <a class="code" href="classQWidget.html">QWidget</a> *parent, <span class="keyword">const</span> <span class="keywordtype">char</span>* name ) :
<a name="l00239"></a>00239                                  <a class="code" href="classQFileDialog.html">QFileDialog</a>(path,
<a name="l00240"></a>00240                                  tr(<span class="stringliteral">&quot;Images&quot;</span>) + <span class="stringliteral">&quot; (*.gif *.jpg *.jpeg *.png *.xpm *.GIF *.JPG *.JPEG *.PNG *.XPM)&quot;</span>,
<a name="l00241"></a>00241                                  parent,name)
<a name="l00242"></a>00242  {
<a name="l00243"></a>00243    <span class="comment">//setup filter filter and modes</span>
<a name="l00244"></a>00244    setMode( QFileDialog::ExistingFiles );
<a name="l00245"></a>00245    setViewMode( QFileDialog::List );
<a name="l00246"></a>00246  
<a name="l00247"></a>00247    <a class="code" href="classAddPhotosDialog.html#a437577da2a4b0c1948527663af70ee88" title="Used to preview selected files.">filePreview</a> = <span class="keyword">new</span> <a class="code" href="classFilePreview.html">FilePreview</a>();
<a name="l00248"></a>00248    setContentsPreviewEnabled( <span class="keyword">true</span> );
<a name="l00249"></a>00249    setContentsPreview( <a class="code" href="classAddPhotosDialog.html#a437577da2a4b0c1948527663af70ee88" title="Used to preview selected files.">filePreview</a>, <a class="code" href="classAddPhotosDialog.html#a437577da2a4b0c1948527663af70ee88" title="Used to preview selected files.">filePreview</a> );
<a name="l00250"></a>00250    setPreviewMode( QFileDialog::Contents );
<a name="l00251"></a>00251    
<a name="l00252"></a>00252    <span class="comment">//create label and checkbox asking user if they want to</span>
<a name="l00253"></a>00253    <span class="comment">//set image descriptions from filenames</span>
<a name="l00254"></a>00254    <a class="code" href="classAddPhotosDialog.html#a97045556080874842dc414eacd5306ea" title="Checkbox asking if filenames should be used to set image descriptions.">setDescriptions</a> = <span class="keyword">new</span> QCheckBox( tr(<span class="stringliteral">&quot;Use filenames for descriptions.&quot;</span>), <span class="keyword">this</span> );
<a name="l00255"></a>00255    <a class="code" href="classAddPhotosDialog.html#a97045556080874842dc414eacd5306ea" title="Checkbox asking if filenames should be used to set image descriptions.">setDescriptions</a>-&gt;setChecked( <span class="keyword">false</span> );
<a name="l00256"></a>00256    addWidgets( NULL, <a class="code" href="classAddPhotosDialog.html#a97045556080874842dc414eacd5306ea" title="Checkbox asking if filenames should be used to set image descriptions.">setDescriptions</a>, NULL );
<a name="l00257"></a>00257 
<a name="l00258"></a>00258    <span class="comment">//set window description</span>
<a name="l00259"></a>00259   setCaption( tr(<span class="stringliteral">&quot;Add Photos&quot;</span>) );
<a name="l00260"></a>00260   
<a name="l00261"></a>00261   connect( <span class="keyword">this</span>, SIGNAL( fileHighlighted(<span class="keyword">const</span> QString&amp;)),
<a name="l00262"></a>00262            <span class="keyword">this</span>, SLOT( <a class="code" href="classAddPhotosDialog.html#aa264f1c88fd5aa219c5de8c177d7ef5a" title="handle the user selecting items by updating the file preview fields">updatePreview</a>(<span class="keyword">const</span> QString&amp;)) );
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264 <span class="comment">//==============================================</span>
<a name="l00265"></a><a class="code" href="classAddPhotosDialog.html#ac65dc3e26f23e8db4fc50b53f281006b">00265</a> QStringList <a class="code" href="classAddPhotosDialog.html#ac65dc3e26f23e8db4fc50b53f281006b" title="returns the list of selected filenames, while setting setDescritions to the state...">AddPhotosDialog::getFilenames</a>(<span class="keywordtype">bool</span>&amp; setDescriptionsBool)
<a name="l00266"></a>00266 {
<a name="l00267"></a>00267   <span class="keywordflow">if</span>( exec() == QDialog::Accepted )
<a name="l00268"></a>00268   {
<a name="l00269"></a>00269     setDescriptionsBool = <a class="code" href="classAddPhotosDialog.html#a97045556080874842dc414eacd5306ea" title="Checkbox asking if filenames should be used to set image descriptions.">setDescriptions</a>-&gt;isChecked();
<a name="l00270"></a>00270     <span class="keywordflow">return</span> selectedFiles();
<a name="l00271"></a>00271   }
<a name="l00272"></a>00272   <span class="keywordflow">else</span> {  <span class="keywordflow">return</span> QStringList(); }
<a name="l00273"></a>00273 }
<a name="l00274"></a>00274 <span class="comment">//==============================================</span>
<a name="l00275"></a><a class="code" href="classAddPhotosDialog.html#aa264f1c88fd5aa219c5de8c177d7ef5a">00275</a> <span class="keywordtype">void</span> <a class="code" href="classAddPhotosDialog.html#aa264f1c88fd5aa219c5de8c177d7ef5a" title="handle the user selecting items by updating the file preview fields">AddPhotosDialog::updatePreview</a>(<span class="keyword">const</span> QString&amp; filename)
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277   <a class="code" href="classAddPhotosDialog.html#a437577da2a4b0c1948527663af70ee88" title="Used to preview selected files.">filePreview</a>-&gt;<a class="code" href="classFilePreview.html#adeef143a0e947ab5a45835e1a3062602" title="call this function to update the file preview">updatePreview</a>( filename ); 
<a name="l00278"></a>00278 }
<a name="l00279"></a>00279 <span class="comment">//==============================================</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>