Krita Source Code Documentation
Loading...
Searching...
No Matches
krecentfilesaction.cpp File Reference
#include "krecentfilesaction.h"
#include "krecentfilesaction_p.h"
#include <QFile>
#include <QGuiApplication>
#include <QDir>
#include <QMenu>
#include <QScreen>
#include <QProxyStyle>
#include <QStandardItemModel>
#include <QStyleFactory>
#include <QActionGroup>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <klocalizedstring.h>
#include "KisRecentFilesManager.h"
#include "moc_krecentfilesaction.cpp"

Go to the source code of this file.

Classes

class  KRecentFilesIconProxyStyle
 

Functions

static QString titleWithSensibleWidth (const QString &nameValue, const QString &value)
 

Function Documentation

◆ titleWithSensibleWidth()

static QString titleWithSensibleWidth ( const QString & nameValue,
const QString & value )
static

Definition at line 167 of file krecentfilesaction.cpp.

168{
169 // Calculate 3/4 of screen geometry, we do not want
170 // action titles to be bigger than that
171 // Since we do not know in which screen we are going to show
172 // we choose the min of all the screens
173 int maxWidthForTitles = INT_MAX;
174 Q_FOREACH(const QScreen *screen, QGuiApplication::screens()) {
175 maxWidthForTitles = qMin(maxWidthForTitles, screen->availableGeometry().width() * 3 / 4);
176 }
177 const QFontMetrics fontMetrics = QFontMetrics(QFont());
178
179 QString title = nameValue + " [" + value + ']';
180 if (fontMetrics.boundingRect(title).width() > maxWidthForTitles) {
181 // If it does not fit, try to cut only the whole path, though if the
182 // name is too long (more than 3/4 of the whole text) we cut it a bit too
183 const int nameValueMaxWidth = maxWidthForTitles * 3 / 4;
184 const int nameWidth = fontMetrics.boundingRect(nameValue).width();
185 QString cutNameValue, cutValue;
186 if (nameWidth > nameValueMaxWidth) {
187 cutNameValue = fontMetrics.elidedText(nameValue, Qt::ElideMiddle, nameValueMaxWidth);
188 cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameValueMaxWidth);
189 } else {
190 cutNameValue = nameValue;
191 cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameWidth);
192 }
193 title = cutNameValue + " [" + cutValue + ']';
194 }
195 return title;
196}
float value(const T *src, size_t ch)

References value().