mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdeui: format and indent
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
312c5a6268
commit
9acda75f99
2 changed files with 229 additions and 229 deletions
|
@ -40,6 +40,38 @@
|
|||
|
||||
#include <limits.h>
|
||||
|
||||
static QString titleWithSensibleWidth(const QString &nameValue, const QString &value)
|
||||
{
|
||||
// Calculate 3/4 of screen geometry, we do not want
|
||||
// action titles to be bigger than that
|
||||
// Since we do not know in which screen we are going to show
|
||||
// we choose the min of all the screens
|
||||
const QDesktopWidget desktopWidget;
|
||||
int maxWidthForTitles = INT_MAX;
|
||||
for (int i = 0; i < desktopWidget.screenCount(); ++i) {
|
||||
maxWidthForTitles = qMin(maxWidthForTitles, desktopWidget.availableGeometry(i).width() * 3 / 4);
|
||||
}
|
||||
const QFontMetrics fontMetrics = QFontMetrics(QFont());
|
||||
|
||||
QString title = nameValue + " [" + value + ']';
|
||||
if (fontMetrics.width(title) > maxWidthForTitles){
|
||||
// If it does not fit, try to cut only the whole path, though if the
|
||||
// name is too long (more than 3/4 of the whole text) we cut it a bit too
|
||||
const int nameValueMaxWidth = maxWidthForTitles * 3 / 4;
|
||||
const int nameWidth = fontMetrics.width(nameValue);
|
||||
QString cutNameValue, cutValue;
|
||||
if (nameWidth > nameValueMaxWidth) {
|
||||
cutNameValue = fontMetrics.elidedText(nameValue, Qt::ElideMiddle, nameValueMaxWidth);
|
||||
cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameValueMaxWidth);
|
||||
} else {
|
||||
cutNameValue = nameValue;
|
||||
cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameWidth);
|
||||
}
|
||||
title = cutNameValue + " [" + cutValue + ']';
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
KRecentFilesAction::KRecentFilesAction(QObject *parent)
|
||||
: KSelectAction(*new KRecentFilesActionPrivate, parent)
|
||||
{
|
||||
|
@ -107,40 +139,9 @@ void KRecentFilesAction::setMaxItems( int maxItems )
|
|||
d->m_maxItems = maxItems;
|
||||
|
||||
// remove all excess items
|
||||
while( selectableActionGroup()->actions().count() > maxItems )
|
||||
while( selectableActionGroup()->actions().count() > maxItems) {
|
||||
delete removeAction(selectableActionGroup()->actions().last());
|
||||
}
|
||||
|
||||
static QString titleWithSensibleWidth(const QString& nameValue, const QString& value)
|
||||
{
|
||||
// Calculate 3/4 of screen geometry, we do not want
|
||||
// action titles to be bigger than that
|
||||
// Since we do not know in which screen we are going to show
|
||||
// we choose the min of all the screens
|
||||
const QDesktopWidget desktopWidget;
|
||||
int maxWidthForTitles = INT_MAX;
|
||||
for (int i = 0; i < desktopWidget.screenCount(); ++i) {
|
||||
maxWidthForTitles = qMin(maxWidthForTitles, desktopWidget.availableGeometry(i).width() * 3 / 4);
|
||||
}
|
||||
const QFontMetrics fontMetrics = QFontMetrics(QFont());
|
||||
|
||||
QString title = nameValue + " [" + value + ']';
|
||||
if (fontMetrics.width(title) > maxWidthForTitles){
|
||||
// If it does not fit, try to cut only the whole path, though if the
|
||||
// name is too long (more than 3/4 of the whole text) we cut it a bit too
|
||||
const int nameValueMaxWidth = maxWidthForTitles * 3 / 4;
|
||||
const int nameWidth = fontMetrics.width(nameValue);
|
||||
QString cutNameValue, cutValue;
|
||||
if (nameWidth > nameValueMaxWidth) {
|
||||
cutNameValue = fontMetrics.elidedText(nameValue, Qt::ElideMiddle, nameValueMaxWidth);
|
||||
cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameValueMaxWidth);
|
||||
} else {
|
||||
cutNameValue = nameValue;
|
||||
cutValue = fontMetrics.elidedText(value, Qt::ElideMiddle, maxWidthForTitles - nameWidth);
|
||||
}
|
||||
title = cutNameValue + " [" + cutValue + ']';
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
void KRecentFilesAction::addUrl(const KUrl &_url, const QString &name)
|
||||
|
@ -153,23 +154,21 @@ void KRecentFilesAction::addUrl( const KUrl& _url, const QString& name )
|
|||
*/
|
||||
const KUrl url(_url);
|
||||
|
||||
if ( url.isLocalFile() && KGlobal::dirs()->relativeLocation("tmp", url.toLocalFile()) != url.toLocalFile() )
|
||||
if (url.isLocalFile() && KGlobal::dirs()->relativeLocation("tmp", url.toLocalFile()) != url.toLocalFile()) {
|
||||
return;
|
||||
const QString tmpName = name.isEmpty() ? url.fileName() : name;
|
||||
}
|
||||
const QString tmpName = (name.isEmpty() ? url.fileName() : name);
|
||||
const QString file = url.pathOrUrl();
|
||||
|
||||
// remove file if already in list
|
||||
foreach (QAction* action, selectableActionGroup()->actions())
|
||||
{
|
||||
if ( d->m_urls[action].pathOrUrl().endsWith(file) )
|
||||
{
|
||||
foreach (QAction *action, selectableActionGroup()->actions()) {
|
||||
if ( d->m_urls[action].pathOrUrl().endsWith(file)) {
|
||||
removeAction(action)->deleteLater();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// remove oldest item if already maxitems in list
|
||||
if( d->m_maxItems && selectableActionGroup()->actions().count() == d->m_maxItems )
|
||||
{
|
||||
if( d->m_maxItems && selectableActionGroup()->actions().count() == d->m_maxItems) {
|
||||
// remove oldest added item
|
||||
delete removeAction(selectableActionGroup()->actions().first());
|
||||
}
|
||||
|
@ -192,8 +191,9 @@ void KRecentFilesAction::addAction(QAction* action, const KUrl& url, const QStri
|
|||
action->setActionGroup(selectableActionGroup());
|
||||
|
||||
// Keep in sync with createToolBarWidget()
|
||||
foreach (QToolButton* button, d->m_buttons)
|
||||
foreach (QToolButton* button, d->m_buttons) {
|
||||
button->insertAction(button->actions().value(0), action);
|
||||
}
|
||||
|
||||
foreach (KComboBox* comboBox, d->m_comboBoxes)
|
||||
comboBox->insertAction(comboBox->actions().value(0), action);
|
||||
|
@ -208,22 +208,21 @@ QAction* KRecentFilesAction::removeAction(QAction* action)
|
|||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
KSelectAction::removeAction(action);
|
||||
|
||||
d->m_shortNames.remove(action);
|
||||
d->m_urls.remove(action);
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
void KRecentFilesAction::removeUrl( const KUrl& url )
|
||||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
for (QMap<QAction*, KUrl>::ConstIterator it = d->m_urls.constBegin(); it != d->m_urls.constEnd(); ++it)
|
||||
for (QMap<QAction*, KUrl>::ConstIterator it = d->m_urls.constBegin(); it != d->m_urls.constEnd(); ++it) {
|
||||
if (it.value() == url) {
|
||||
delete removeAction(it.key());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KUrl::List KRecentFilesAction::urls() const
|
||||
{
|
||||
|
@ -249,7 +248,7 @@ void KRecentFilesAction::clearEntries()
|
|||
setEnabled(false);
|
||||
}
|
||||
|
||||
void KRecentFilesAction::loadEntries( const KConfigGroup& _config)
|
||||
void KRecentFilesAction::loadEntries(const KConfigGroup &config)
|
||||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
clearEntries();
|
||||
|
@ -261,39 +260,40 @@ void KRecentFilesAction::loadEntries( const KConfigGroup& _config)
|
|||
QString title;
|
||||
KUrl url;
|
||||
|
||||
KConfigGroup cg = _config;
|
||||
if ( cg.name().isEmpty())
|
||||
KConfigGroup cg = config;
|
||||
if (cg.name().isEmpty()) {
|
||||
cg = KConfigGroup(cg.config(), "RecentFiles");
|
||||
}
|
||||
|
||||
bool thereAreEntries = false;
|
||||
// read file list
|
||||
for( int i = 1 ; i <= d->m_maxItems ; i++ )
|
||||
{
|
||||
for(int i = 1; i <= d->m_maxItems; i++) {
|
||||
key = QString("File%1").arg(i);
|
||||
value = cg.readPathEntry(key, QString());
|
||||
if (value.isEmpty()) continue;
|
||||
if (value.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
url = KUrl(value);
|
||||
|
||||
// Don't restore if file doesn't exist anymore
|
||||
if (url.isLocalFile() && !QFile::exists(url.toLocalFile()))
|
||||
if (url.isLocalFile() && !QFile::exists(url.toLocalFile())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't restore where the url is already known (eg. broken config)
|
||||
if (d->m_urls.values().contains(url))
|
||||
if (d->m_urls.values().contains(url)) {
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
nameKey = QString("Name%1").arg(i);
|
||||
nameValue = cg.readPathEntry(nameKey, url.fileName());
|
||||
title = titleWithSensibleWidth(nameValue, value);
|
||||
if (!value.isNull())
|
||||
{
|
||||
if (!value.isNull()) {
|
||||
thereAreEntries=true;
|
||||
addAction(new QAction(title, selectableActionGroup()), url, nameValue);
|
||||
}
|
||||
}
|
||||
if (thereAreEntries)
|
||||
{
|
||||
if (thereAreEntries) {
|
||||
d->m_noEntriesAction->setVisible(false);
|
||||
d->clearSeparator->setVisible(true);
|
||||
d->clearAction->setVisible(true);
|
||||
|
@ -309,14 +309,14 @@ void KRecentFilesAction::saveEntries( const KConfigGroup &_cg )
|
|||
QStringList lst = items();
|
||||
|
||||
KConfigGroup cg = _cg;
|
||||
if (cg.name().isEmpty())
|
||||
if (cg.name().isEmpty()) {
|
||||
cg = KConfigGroup(cg.config(), "RecentFiles");
|
||||
}
|
||||
|
||||
cg.deleteGroup();
|
||||
|
||||
// write file list
|
||||
for ( int i = 1 ; i <= selectableActionGroup()->actions().count() ; i++ )
|
||||
{
|
||||
for (int i = 1 ; i <= selectableActionGroup()->actions().count(); i++) {
|
||||
key = QString("File%1").arg(i);
|
||||
// i - 1 because we started from 1
|
||||
value = d->m_urls[ selectableActionGroup()->actions()[i - 1]].pathOrUrl();
|
||||
|
|
Loading…
Add table
Reference in a new issue