Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 4f45e7bdfd4a5ff17f5f8eaab90d017f > files > 1487

albumshaper-2.1-6mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AlbumShaper: recentAlbumMenuItem.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.5.9 -->
<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>recentAlbumMenuItem.cpp</h1><a href="recentAlbumMenuItem_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;qdir.h&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;qpainter.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;qapplication.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;qkeysequence.h&gt;</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="comment">//Projectwide includes</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="recentAlbumMenuItem_8h.html">recentAlbumMenuItem.h</a>"</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include "../backend/tools/imageTools.h"</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="comment">//==============================================</span>
<a name="l00022"></a><a class="code" href="classRecentAlbumMenuItem.html#354ab25f0544318701dcfef55e905ebb">00022</a> <a class="code" href="classRecentAlbumMenuItem.html#354ab25f0544318701dcfef55e905ebb">RecentAlbumMenuItem::RecentAlbumMenuItem</a>( Key acceleratorKey ) : <a class="code" href="classQCustomMenuItem.html">QCustomMenuItem</a>()
<a name="l00023"></a>00023 {
<a name="l00024"></a>00024   this-&gt;acceleratorKey = acceleratorKey;
<a name="l00025"></a>00025   <a class="code" href="classRecentAlbumMenuItem.html#8f24dece7400a13da2e48ab8a70b29d2" title="updates entry as per arguments passed (used by constructor during intiailization...">changeItem</a>( <span class="stringliteral">"unitialized"</span>, <span class="stringliteral">"unitialized"</span>, <span class="stringliteral">"unitialized"</span> );
<a name="l00026"></a>00026 }
<a name="l00027"></a>00027 <span class="comment">//==============================================</span>
<a name="l00028"></a><a class="code" href="classRecentAlbumMenuItem.html#8f24dece7400a13da2e48ab8a70b29d2">00028</a> <span class="keywordtype">void</span> <a class="code" href="classRecentAlbumMenuItem.html#8f24dece7400a13da2e48ab8a70b29d2" title="updates entry as per arguments passed (used by constructor during intiailization...">RecentAlbumMenuItem::changeItem</a>( QString albumName, 
<a name="l00029"></a>00029                                       QString albumLocation,
<a name="l00030"></a>00030                                       QString numPhotos )
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032   <span class="comment">//set name, and number of photos</span>
<a name="l00033"></a>00033   this-&gt;albumName = albumName;
<a name="l00034"></a>00034   this-&gt;numPhotos = numPhotos;
<a name="l00035"></a>00035   
<a name="l00036"></a>00036   <span class="comment">//compute height</span>
<a name="l00037"></a>00037   QFontMetrics fm( qApp-&gt;font() );
<a name="l00038"></a>00038   <a class="code" href="classRecentAlbumMenuItem.html#fa0cbaf725a37f20af94b10b02a8a73c" title="computed size">size</a>.setHeight( 2 + fm.leading() + 2*fm.height() + 2);
<a name="l00039"></a>00039   
<a name="l00040"></a>00040   <span class="comment">//attempt to set album image   </span>
<a name="l00041"></a>00041   QString albumImageLocation = QDir::convertSeparators( albumLocation + <span class="stringliteral">"/img/album.jpg"</span> );
<a name="l00042"></a>00042   QDir tempDir;
<a name="l00043"></a>00043   <span class="keywordflow">if</span>( tempDir.exists( albumImageLocation ) )
<a name="l00044"></a>00044   {       
<a name="l00045"></a>00045     <span class="comment">//ideal image width assuming 4:3 aspect ratio</span>
<a name="l00046"></a>00046     <a class="code" href="classRecentAlbumMenuItem.html#37540412a8fd5ee7add7ebfea246e0f7" title="used for painting purposes">idealImageWidth</a> = (4 * (<a class="code" href="classRecentAlbumMenuItem.html#fa0cbaf725a37f20af94b10b02a8a73c" title="computed size">size</a>.height()-4) ) / 3;
<a name="l00047"></a>00047     
<a name="l00048"></a>00048     <span class="comment">//scale image</span>
<a name="l00049"></a>00049     <a class="code" href="imageTools_8cpp.html#126e11984fb8124e78e3b1b68a24870c" title="Scale image and save copy to disk.">scaleImage</a>( albumImageLocation, <a class="code" href="classRecentAlbumMenuItem.html#947ab36fc08c87e0997e9237ee237554" title="album image">albumImage</a>, <a class="code" href="classRecentAlbumMenuItem.html#37540412a8fd5ee7add7ebfea246e0f7" title="used for painting purposes">idealImageWidth</a>, <a class="code" href="classRecentAlbumMenuItem.html#fa0cbaf725a37f20af94b10b02a8a73c" title="computed size">size</a>.height() );
<a name="l00050"></a>00050   }
<a name="l00051"></a>00051   <span class="keywordflow">else</span>
<a name="l00052"></a>00052   {
<a name="l00053"></a>00053     <a class="code" href="classRecentAlbumMenuItem.html#37540412a8fd5ee7add7ebfea246e0f7" title="used for painting purposes">idealImageWidth</a> = 0;
<a name="l00054"></a>00054   }
<a name="l00055"></a>00055   
<a name="l00056"></a>00056   <span class="comment">//compute menu entry width</span>
<a name="l00057"></a>00057   <a class="code" href="classRecentAlbumMenuItem.html#fa0cbaf725a37f20af94b10b02a8a73c" title="computed size">size</a>.setWidth( <a class="code" href="classRecentAlbumMenuItem.html#37540412a8fd5ee7add7ebfea246e0f7" title="used for painting purposes">idealImageWidth</a> + 2 + fm.width(albumName) );
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 <span class="comment">//==============================================</span>
<a name="l00060"></a><a class="code" href="classRecentAlbumMenuItem.html#dbae14ce02aab6186cc91ce1a02600fc">00060</a> <span class="keywordtype">void</span> <a class="code" href="classRecentAlbumMenuItem.html#dbae14ce02aab6186cc91ce1a02600fc" title="paints entry">RecentAlbumMenuItem::paint</a>(  QPainter* p, 
<a name="l00061"></a>00061                                   <span class="keyword">const</span> QColorGroup&amp;, 
<a name="l00062"></a>00062                                   <span class="keywordtype">bool</span>, <span class="keywordtype">bool</span>, 
<a name="l00063"></a>00063                                   <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y, <span class="keywordtype">int</span>, <span class="keywordtype">int</span> )
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065   <span class="comment">//move down and right by two for spacing purposes</span>
<a name="l00066"></a>00066   y+=2;
<a name="l00067"></a>00067   x+=2;
<a name="l00068"></a>00068   <span class="keywordtype">int</span> xOffset = 0;
<a name="l00069"></a>00069   <span class="keywordtype">int</span> yOffset = 0;
<a name="l00070"></a>00070 
<a name="l00071"></a>00071   <span class="comment">//paint album image first if not null</span>
<a name="l00072"></a>00072   <span class="keywordflow">if</span>(!<a class="code" href="classRecentAlbumMenuItem.html#947ab36fc08c87e0997e9237ee237554" title="album image">albumImage</a>.isNull())
<a name="l00073"></a>00073   {
<a name="l00074"></a>00074     p-&gt;drawImage( x + (<a class="code" href="classRecentAlbumMenuItem.html#37540412a8fd5ee7add7ebfea246e0f7" title="used for painting purposes">idealImageWidth</a> - <a class="code" href="classRecentAlbumMenuItem.html#947ab36fc08c87e0997e9237ee237554" title="album image">albumImage</a>.width()) / 2, 
<a name="l00075"></a>00075                   y + (<a class="code" href="classRecentAlbumMenuItem.html#fa0cbaf725a37f20af94b10b02a8a73c" title="computed size">size</a>.height() - <a class="code" href="classRecentAlbumMenuItem.html#947ab36fc08c87e0997e9237ee237554" title="album image">albumImage</a>.height() - 4)/2, 
<a name="l00076"></a>00076                   <a class="code" href="classRecentAlbumMenuItem.html#947ab36fc08c87e0997e9237ee237554" title="album image">albumImage</a> );
<a name="l00077"></a>00077     xOffset+=(<a class="code" href="classRecentAlbumMenuItem.html#37540412a8fd5ee7add7ebfea246e0f7" title="used for painting purposes">idealImageWidth</a> + 2);
<a name="l00078"></a>00078   }
<a name="l00079"></a>00079   
<a name="l00080"></a>00080   <span class="comment">//paint album name + photo count</span>
<a name="l00081"></a>00081   QFontMetrics fm( qApp-&gt;font() );
<a name="l00082"></a>00082   yOffset+=fm.ascent();
<a name="l00083"></a>00083   p-&gt;drawText( x+xOffset, y+yOffset, <a class="code" href="classRecentAlbumMenuItem.html#99a2324b66081f9fda0716880905c157" title="album name">albumName</a> ); 
<a name="l00084"></a>00084 
<a name="l00085"></a>00085   <span class="comment">//if photo count available print it as well</span>
<a name="l00086"></a>00086   <span class="keywordflow">if</span>(<a class="code" href="classRecentAlbumMenuItem.html#569129eb48599392a7b8e090ad4217c9" title="number of photos">numPhotos</a>.compare(<span class="stringliteral">"-1"</span>) != 0)
<a name="l00087"></a>00087   {
<a name="l00088"></a>00088     yOffset+=fm.descent() + 1 + fm.leading() + fm.ascent();
<a name="l00089"></a>00089     p-&gt;drawText( x+xOffset, y+yOffset, 
<a name="l00090"></a>00090                qApp-&gt;translate(<span class="stringliteral">"RecentAlbumMenuItem"</span>, <span class="stringliteral">"%1 Photos"</span>).arg(<a class="code" href="classRecentAlbumMenuItem.html#569129eb48599392a7b8e090ad4217c9" title="number of photos">numPhotos</a>) );
<a name="l00091"></a>00091   }
<a name="l00092"></a>00092 
<a name="l00093"></a>00093   <span class="comment">//paint accelerator key</span>
<a name="l00094"></a>00094   <span class="keywordflow">if</span>( <a class="code" href="classRecentAlbumMenuItem.html#36498fbf466c609c7d1d7900c093682b">acceleratorKey</a> != Key_unknown )
<a name="l00095"></a>00095   {
<a name="l00096"></a>00096     xOffset = <a class="code" href="classRecentAlbumMenuItem.html#24a7b428c635dce4efe51dd27dad6cd3" title="max element width">maxWidth</a> + 24;
<a name="l00097"></a>00097     yOffset = fm.ascent() + fm.height()/2;
<a name="l00098"></a>00098     QKeySequence seq( CTRL+<a class="code" href="classRecentAlbumMenuItem.html#36498fbf466c609c7d1d7900c093682b">acceleratorKey</a> );
<a name="l00099"></a>00099     QString str = (QString)seq;
<a name="l00100"></a>00100     p-&gt;drawText( x+xOffset, y+yOffset,
<a name="l00101"></a>00101                  str);
<a name="l00102"></a>00102   }
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 <span class="comment">//==============================================</span>
<a name="l00105"></a><a class="code" href="classRecentAlbumMenuItem.html#42a7d14255eb18be7b52009921c4d6ad">00105</a> QSize <a class="code" href="classRecentAlbumMenuItem.html#42a7d14255eb18be7b52009921c4d6ad" title="returns menu entry size">RecentAlbumMenuItem::sizeHint</a> ()
<a name="l00106"></a>00106 { <span class="keywordflow">return</span> <a class="code" href="classRecentAlbumMenuItem.html#fa0cbaf725a37f20af94b10b02a8a73c" title="computed size">size</a>; }
<a name="l00107"></a>00107 <span class="comment">//==============================================</span>
<a name="l00108"></a><a class="code" href="classRecentAlbumMenuItem.html#43fb3d3e87cfcd20190f051228134ebb">00108</a> <span class="keywordtype">bool</span> <a class="code" href="classRecentAlbumMenuItem.html#43fb3d3e87cfcd20190f051228134ebb" title="no icon necessary since album image painted here">RecentAlbumMenuItem::fullSpan</a>()<span class="keyword"> const</span>
<a name="l00109"></a>00109 <span class="keyword"></span>{ <span class="keywordflow">return</span> <span class="keyword">true</span>; }
<a name="l00110"></a>00110 <span class="comment">//==============================================</span>
<a name="l00111"></a><a class="code" href="classRecentAlbumMenuItem.html#8fbcd4bb687b9a6ca0e1171fe0848a1f">00111</a> <span class="keywordtype">void</span> <a class="code" href="classRecentAlbumMenuItem.html#8fbcd4bb687b9a6ca0e1171fe0848a1f" title="after all menu items have been refreshed hint at maximum width so we can adequately...">RecentAlbumMenuItem::setMaxWidth</a>( <span class="keywordtype">int</span> val )
<a name="l00112"></a>00112 { <a class="code" href="classRecentAlbumMenuItem.html#24a7b428c635dce4efe51dd27dad6cd3" title="max element width">maxWidth</a> = val; }
<a name="l00113"></a>00113 <span class="comment">//==============================================</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Aug 23 02:34:27 2009 for AlbumShaper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>