MCPcopy Create free account
hub / github.com/IENT/YUView / drawItemPathAndName

Method drawItemPathAndName

YUViewLib/src/ui/views/SplitViewWidget.cpp:1886–1950  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1884}
1885
1886void splitViewWidget::drawItemPathAndName(QPainter *painter, int posX, int width, QString path)
1887{
1888 DEBUG_LOAD_DRAW("splitViewWidget::drawItemPathAndName");
1889 QString drawString;
1890
1891 auto sep = QDir::separator();
1892 auto pathSplit = path.split(sep);
1893
1894 // The metrics for evaluating the width of the rendered text
1895 QFont valueFont = QFont(SPLITVIEWWIDGET_SPLITPATH_FONT, SPLITVIEWWIDGET_SPLITPATH_FONTSIZE);
1896 QFontMetrics metrics(valueFont);
1897
1898 QString currentLine = "";
1899 if (pathSplit.size() > 0)
1900 {
1901 for (auto it = pathSplit.begin(); it != pathSplit.end(); it++)
1902 {
1903 const bool isLast = (it == pathSplit.end() - 1);
1904 if (currentLine.isEmpty())
1905 {
1906 currentLine = *it;
1907 if (!isLast)
1908 currentLine += sep;
1909 }
1910 else
1911 {
1912 // Will the part fit into the the current line?
1913 QString lineTemp = currentLine + *it;
1914 if (!isLast)
1915 lineTemp += sep;
1916 QSize textSize = metrics.size(0, lineTemp);
1917 if (textSize.width() > width - SPLITVIEWWIDGET_SPLITPATH_PADDING)
1918 {
1919 // This won't fit. Put it to the next line
1920 drawString += currentLine + "\n";
1921 currentLine = *it;
1922 if (!isLast)
1923 currentLine += sep;
1924 }
1925 else
1926 currentLine = lineTemp;
1927 }
1928 }
1929 }
1930 if (!currentLine.isEmpty())
1931 drawString += currentLine;
1932
1933 // Create the QRect to draw to
1934 QSize textSize = metrics.size(0, drawString);
1935 QRect textRect;
1936 textRect.setSize(textSize);
1937 textRect.moveCenter(QPoint(posX + width / 2, 0));
1938 textRect.moveTop(SPLITVIEWWIDGET_SPLITPATH_TOP_OFFSET);
1939
1940 // Draw a rectangle around the text in white with a black border
1941 QRect boxRect = textRect + QMargins(5, 5, 5, 5);
1942 painter->setPen(QPen(Qt::black, 1));
1943 painter->fillRect(boxRect, Qt::white);

Callers

nothing calls this directly

Calls 3

setSizeMethod · 0.80
sizeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected