Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

guiTools.h File Reference

#include <qlabel.h>
#include <qfiledialog.h>

Include dependency graph for guiTools.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void centerWindow (QWidget *window)
QString clipText (QString string, int lines, int lineWidth)
 clip text to fit within numer of lines and max width

QString clipPhotoText (const QString in)
 clip photo text


Function Documentation

void centerWindow QWidget window  ) 
 

Definition at line 25 of file guiTools.cpp.

Referenced by TitleWidget::aboutProgram(), TitleWidget::albumStatistics(), TitleWidget::help(), main(), and TitleWidget::settings().

00026 { 00027 //--------------------------------------------------------- 00028 //get size and location of application window 00029 QRect appRec = qApp->mainWidget()->frameGeometry(); 00030 QRect windowRec = window->frameGeometry(); 00031 //--------------------------------------------------------- 00032 //if new window smaller then application window then center window 00033 //over application window, otherwise align left/top with application window 00034 int x, y; 00035 00036 //horizontal alignment 00037 if(windowRec.width() < appRec.width()) 00038 { x = appRec.x() + ((appRec.width() - windowRec.width())/2); } 00039 else 00040 { x = appRec.x(); } 00041 00042 //vertical alignment 00043 if(windowRec.height() < appRec.height()) 00044 { y = appRec.y() + ((appRec.height() - windowRec.height())/2); } 00045 else 00046 { y = appRec.y(); } 00047 //--------------------------------------------------------- 00048 //ensure window is not off screen, favor top/left sides of window is bigger than screen! 00049 QRect screen = QApplication::desktop()->availableGeometry(); 00050 00051 //right 00052 if(x + windowRec.width() > screen.width() ) 00053 x = screen.width() - windowRec.width(); 00054 00055 //left 00056 if(x < 0) 00057 x = 0; 00058 00059 //bottom 00060 if(y + windowRec.height() > screen.height() ) 00061 y = screen.height() - windowRec.height(); 00062 00063 //top 00064 if(y < 0) 00065 y = 0; 00066 //--------------------------------------------------------- 00067 //place window 00068 window->move( QPoint( x, y) ); 00069 }

QString clipPhotoText const QString  in  ) 
 

clip photo text

Definition at line 151 of file guiTools.cpp.

References PHOTO_TEXT_LENGTH.

00152 { 00153 if(in.length() > PHOTO_TEXT_LENGTH) 00154 { 00155 QString res = in; 00156 res.truncate(PHOTO_TEXT_LENGTH-3); res = res + "..."; 00157 return res; 00158 } 00159 else 00160 return in; 00161 }

QString clipText QString  string,
int  lines,
int  lineWidth
 

clip text to fit within numer of lines and max width

Definition at line 71 of file guiTools.cpp.

Referenced by SubalbumPreviewWidget::setText(), PhotoPreviewWidget::setText(), and SubalbumPreviewWidget::SubalbumPreviewWidget().

00072 { 00073 if(lineWidth == 0) 00074 { 00075 // cout << "ERROR: given 0 width when clipping: " << string << endl; 00076 return ""; 00077 } 00078 00079 QString result = ""; 00080 QString building = ""; 00081 QFontMetrics fm( qApp->font() ); 00082 00083 //decrement characters off head of string for each line 00084 while(string.length() > 0 && lines > 0) 00085 { 00086 bool spaceFound = false; 00087 QString line = ""; 00088 00089 //while there are character to be popped up 00090 while(string.length() > 0) 00091 { 00092 //if we can afford to add this character, add it to the building string 00093 //then update the character found, and space found strings 00094 if(fm.width( QString(line + building + string.at(0) ) ) < lineWidth ) 00095 { 00096 building = building + string.at(0); 00097 00098 //found a space, add this space and all built up words to the text for this line, no need 00099 //to wrap what has been found so far 00100 if(string.at(0) == ' ') // QChar::Separator_Space) 00101 { 00102 line = line + building; 00103 building = ""; 00104 spaceFound = true; 00105 string = string.remove(0, 1); 00106 continue; 00107 } 00108 00109 string = string.remove(0, 1); 00110 if(string.length() == 0) 00111 { 00112 line = line + building; 00113 building = ""; 00114 } 00115 00116 } 00117 //uh oh, can't add this character? move to next line 00118 else 00119 { 00120 //if no spaces found up to this point, suck up character so far, we're breaking on this one 00121 if(!spaceFound || lines == 1) 00122 { 00123 if(lines == 1) 00124 building = building + string; 00125 00126 //if this is the last line then make sure we have enough space for the ... 00127 line = line + building; 00128 if(fm.width( line ) > lineWidth ) 00129 { 00130 while( fm.width(line + "...") > lineWidth ) 00131 { 00132 line.truncate( line.length() - 1); 00133 } 00134 line = line + "..."; 00135 } 00136 building = ""; 00137 } 00138 break; 00139 } 00140 } 00141 00142 //move on to next line 00143 result = result + line; 00144 line = ""; 00145 lines--; 00146 } 00147 00148 return result; 00149 }


Generated on Sun Mar 4 19:42:59 2007 for AlbumShaper by doxygen 1.3.7