Changeset View
Changeset View
Standalone View
Standalone View
src/krecentfilesaction.cpp
Show All 25 Lines | |||||
26 | */ | 26 | */ | ||
27 | 27 | | |||
28 | #include "krecentfilesaction.h" | 28 | #include "krecentfilesaction.h" | ||
29 | #include "krecentfilesaction_p.h" | 29 | #include "krecentfilesaction_p.h" | ||
30 | 30 | | |||
31 | #include <QFile> | 31 | #include <QFile> | ||
32 | #include <QDesktopWidget> | 32 | #include <QDesktopWidget> | ||
33 | #include <QDir> | 33 | #include <QDir> | ||
34 | #include <QGuiApplication> | ||||
34 | #include <QMenu> | 35 | #include <QMenu> | ||
36 | #include <QScreen> | ||||
35 | 37 | | |||
36 | #include <kconfig.h> | 38 | #include <kconfig.h> | ||
37 | #include <kconfiggroup.h> | 39 | #include <kconfiggroup.h> | ||
38 | #include <klocalizedstring.h> | 40 | #include <klocalizedstring.h> | ||
39 | 41 | | |||
40 | KRecentFilesAction::KRecentFilesAction(QObject *parent) | 42 | KRecentFilesAction::KRecentFilesAction(QObject *parent) | ||
41 | : KSelectAction(parent), | 43 | : KSelectAction(parent), | ||
42 | d_ptr(new KRecentFilesActionPrivate(this)) | 44 | d_ptr(new KRecentFilesActionPrivate(this)) | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | |||||
117 | } | 119 | } | ||
118 | 120 | | |||
119 | static QString titleWithSensibleWidth(const QString &nameValue, const QString &value) | 121 | static QString titleWithSensibleWidth(const QString &nameValue, const QString &value) | ||
120 | { | 122 | { | ||
121 | // Calculate 3/4 of screen geometry, we do not want | 123 | // Calculate 3/4 of screen geometry, we do not want | ||
122 | // action titles to be bigger than that | 124 | // action titles to be bigger than that | ||
123 | // Since we do not know in which screen we are going to show | 125 | // Since we do not know in which screen we are going to show | ||
124 | // we choose the min of all the screens | 126 | // we choose the min of all the screens | ||
125 | const QDesktopWidget desktopWidget; | | |||
126 | int maxWidthForTitles = INT_MAX; | 127 | int maxWidthForTitles = INT_MAX; | ||
127 | for (int i = 0; i < desktopWidget.screenCount(); ++i) { | 128 | const auto screens = QGuiApplication::screens(); | ||
128 | maxWidthForTitles = qMin(maxWidthForTitles, desktopWidget.availableGeometry(i).width() * 3 / 4); | 129 | for (QScreen *screen : screens) { | ||
130 | maxWidthForTitles = qMin(maxWidthForTitles, screen->availableGeometry().width() * 3 / 4); | ||||
129 | } | 131 | } | ||
130 | const QFontMetrics fontMetrics = QFontMetrics(QFont()); | 132 | const QFontMetrics fontMetrics = QFontMetrics(QFont()); | ||
131 | 133 | | |||
132 | QString title = nameValue + QLatin1String(" [") + value + QLatin1Char(']'); | 134 | QString title = nameValue + QLatin1String(" [") + value + QLatin1Char(']'); | ||
133 | if (fontMetrics.width(title) > maxWidthForTitles) { | 135 | const int nameWidth = fontMetrics.boundingRect(title).width(); | ||
136 | if (nameWidth > maxWidthForTitles) { | ||||
134 | // If it does not fit, try to cut only the whole path, though if the | 137 | // If it does not fit, try to cut only the whole path, though if the | ||
135 | // name is too long (more than 3/4 of the whole text) we cut it a bit too | 138 | // name is too long (more than 3/4 of the whole text) we cut it a bit too | ||
136 | const int nameValueMaxWidth = maxWidthForTitles * 3 / 4; | 139 | const int nameValueMaxWidth = maxWidthForTitles * 3 / 4; | ||
137 | const int nameWidth = fontMetrics.width(nameValue); | | |||
138 | QString cutNameValue, cutValue; | 140 | QString cutNameValue, cutValue; | ||
139 | if (nameWidth > nameValueMaxWidth) { | 141 | if (nameWidth > nameValueMaxWidth) { | ||
140 | cutNameValue = fontMetrics.elidedText(nameValue, Qt::ElideMiddle, nameValueMaxWidth); | 142 | cutNameValue = fontMetrics.elidedText(nameValue, Qt::ElideMiddle, nameValueMaxWidth); | ||
141 | cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameValueMaxWidth); | 143 | cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameValueMaxWidth); | ||
142 | } else { | 144 | } else { | ||
143 | cutNameValue = nameValue; | 145 | cutNameValue = nameValue; | ||
144 | cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameWidth); | 146 | cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameWidth); | ||
145 | } | 147 | } | ||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |