示例#1
0
	void FormatFileName(HDC dc, const QString &fileName, QString &dottedFileName, int boxWidth)
	{
		int stringWidth = StringWidth(fileName, dc);

		dottedFileName = fileName;

		// too small file name
		if( stringWidth < boxWidth ) return;

		// extract filename and path
		QString sPath = fileName;
		QString sFile = fileName;
		int i = sPath.ReverseFind('\\');
		if (i != -1)
		{
			sPath = sPath.Left(i);
			sFile.Delete(0, i);
		}
		else return; // nothing to format

		int pathWidth = StringWidth(sPath, dc);
		int fileWidth = stringWidth - pathWidth;
		if( fileWidth >= boxWidth )
		{
			dottedFileName = sFile;
			return; // too big file name
		}

		int dotsWidth = StringWidth(QString(L"...\\"), dc);
		int curWidth = dotsWidth;
		i = 0;
		while( (curWidth < (boxWidth - fileWidth)) && (i < sPath.GetLength()) )
		{
			curWidth += CharWidth(sPath[i++], dc);
		}
		if(curWidth >= boxWidth && i > 0)
			i--;

		sPath = sPath.Left(i);
		dottedFileName = sPath + L"..." + sFile;
	}