00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include <qwidget.h>
00013
#include <qapplication.h>
00014
#include <qstring.h>
00015
#include <qstringlist.h>
00016
#include <qpixmap.h>
00017
00018
00019
#include "guiTools.h"
00020
00021 #define SUBALBUM_TEXT_LENGTH 35
00022 #define PHOTO_TEXT_LENGTH 35
00023
00024
00025 void centerWindow(
QWidget* window)
00026 {
00027
00028
00029 QRect appRec = qApp->mainWidget()->frameGeometry();
00030 QRect windowRec = window->frameGeometry();
00031
00032
00033
00034
int x, y;
00035
00036
00037
if(windowRec.width() < appRec.width())
00038 { x = appRec.x() + ((appRec.width() - windowRec.width())/2); }
00039
else
00040 { x = appRec.x(); }
00041
00042
00043
if(windowRec.height() < appRec.height())
00044 { y = appRec.y() + ((appRec.height() - windowRec.height())/2); }
00045
else
00046 { y = appRec.y(); }
00047
00048
00049 QRect screen = QApplication::desktop()->availableGeometry();
00050
00051
00052
if(x + windowRec.width() > screen.width() )
00053 x = screen.width() - windowRec.width();
00054
00055
00056
if(x < 0)
00057 x = 0;
00058
00059
00060
if(y + windowRec.height() > screen.height() )
00061 y = screen.height() - windowRec.height();
00062
00063
00064
if(y < 0)
00065 y = 0;
00066
00067
00068 window->move( QPoint( x, y) );
00069 }
00070
00071 QString
clipText(QString string,
int lines,
int lineWidth)
00072 {
00073
if(lineWidth == 0)
00074 {
00075
00076
return "";
00077 }
00078
00079 QString result =
"";
00080 QString building =
"";
00081 QFontMetrics fm( qApp->font() );
00082
00083
00084
while(string.length() > 0 && lines > 0)
00085 {
00086
bool spaceFound =
false;
00087 QString line =
"";
00088
00089
00090
while(string.length() > 0)
00091 {
00092
00093
00094
if(fm.width( QString(line + building + string.at(0) ) ) < lineWidth )
00095 {
00096 building = building + string.at(0);
00097
00098
00099
00100
if(string.at(0) ==
' ')
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
00118
else
00119 {
00120
00121
if(!spaceFound || lines == 1)
00122 {
00123
if(lines == 1)
00124 building = building + string;
00125
00126
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
00143 result = result + line;
00144 line =
"";
00145 lines--;
00146 }
00147
00148
return result;
00149 }
00150
00151 QString
clipPhotoText(
const QString in)
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 }
00162