mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +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)
|
||||
{
|
||||
|
@ -88,7 +120,7 @@ KRecentFilesAction::~KRecentFilesAction()
|
|||
{
|
||||
}
|
||||
|
||||
void KRecentFilesActionPrivate::_k_urlSelected( QAction* action )
|
||||
void KRecentFilesActionPrivate::_k_urlSelected(QAction *action)
|
||||
{
|
||||
Q_Q(KRecentFilesAction);
|
||||
emit q->urlSelected(m_urls[action]);
|
||||
|
@ -100,50 +132,19 @@ int KRecentFilesAction::maxItems() const
|
|||
return d->m_maxItems;
|
||||
}
|
||||
|
||||
void KRecentFilesAction::setMaxItems( int maxItems )
|
||||
void KRecentFilesAction::setMaxItems(int maxItems)
|
||||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
// set new 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 )
|
||||
void KRecentFilesAction::addUrl(const KUrl &_url, const QString &name)
|
||||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
/**
|
||||
|
@ -151,25 +152,23 @@ void KRecentFilesAction::addUrl( const KUrl& _url, const QString& name )
|
|||
* urlSelected() signal, we will delete it in the removeAction() call below.
|
||||
* but access it again in the addAction call... => crash
|
||||
*/
|
||||
const KUrl url( _url );
|
||||
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());
|
||||
}
|
||||
|
@ -184,16 +183,17 @@ void KRecentFilesAction::addUrl( const KUrl& _url, const QString& name )
|
|||
addAction(action, url, tmpName);
|
||||
}
|
||||
|
||||
void KRecentFilesAction::addAction(QAction* action, const KUrl& url, const QString& name)
|
||||
void KRecentFilesAction::addAction(QAction *action, const KUrl &url, const QString &name)
|
||||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
//kDebug (129) << "KRecentFilesAction::addAction(" << action << ")";
|
||||
// kDebug (129) << "KRecentFilesAction::addAction(" << action << ")";
|
||||
|
||||
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);
|
||||
|
@ -204,31 +204,30 @@ void KRecentFilesAction::addAction(QAction* action, const KUrl& url, const QStri
|
|||
d->m_urls.insert( action, url );
|
||||
}
|
||||
|
||||
QAction* KRecentFilesAction::removeAction(QAction* action)
|
||||
QAction* KRecentFilesAction::removeAction(QAction *action)
|
||||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
KSelectAction::removeAction( action );
|
||||
|
||||
d->m_shortNames.remove( action );
|
||||
d->m_urls.remove( action );
|
||||
|
||||
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
|
||||
{
|
||||
Q_D(const KRecentFilesAction);
|
||||
return d->m_urls.values ();
|
||||
return d->m_urls.values();
|
||||
}
|
||||
|
||||
void KRecentFilesAction::clear()
|
||||
|
@ -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())
|
||||
cg = KConfigGroup(cg.config(),"RecentFiles");
|
||||
KConfigGroup cg = config;
|
||||
if (cg.name().isEmpty()) {
|
||||
cg = KConfigGroup(cg.config(), "RecentFiles");
|
||||
}
|
||||
|
||||
bool thereAreEntries=false;
|
||||
bool thereAreEntries = false;
|
||||
// read file list
|
||||
for( int i = 1 ; i <= d->m_maxItems ; i++ )
|
||||
{
|
||||
key = QString( "File%1" ).arg( i );
|
||||
value = cg.readPathEntry( key, QString() );
|
||||
if (value.isEmpty()) continue;
|
||||
url = KUrl( value );
|
||||
for(int i = 1; i <= d->m_maxItems; i++) {
|
||||
key = QString("File%1").arg(i);
|
||||
value = cg.readPathEntry(key, QString());
|
||||
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() );
|
||||
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);
|
||||
|
@ -301,7 +301,7 @@ void KRecentFilesAction::loadEntries( const KConfigGroup& _config)
|
|||
}
|
||||
}
|
||||
|
||||
void KRecentFilesAction::saveEntries( const KConfigGroup &_cg )
|
||||
void KRecentFilesAction::saveEntries(const KConfigGroup &_cg)
|
||||
{
|
||||
Q_D(KRecentFilesAction);
|
||||
QString key;
|
||||
|
@ -309,21 +309,21 @@ void KRecentFilesAction::saveEntries( const KConfigGroup &_cg )
|
|||
QStringList lst = items();
|
||||
|
||||
KConfigGroup cg = _cg;
|
||||
if (cg.name().isEmpty())
|
||||
cg = KConfigGroup(cg.config(),"RecentFiles");
|
||||
if (cg.name().isEmpty()) {
|
||||
cg = KConfigGroup(cg.config(), "RecentFiles");
|
||||
}
|
||||
|
||||
cg.deleteGroup();
|
||||
|
||||
// write file list
|
||||
for ( int i = 1 ; i <= selectableActionGroup()->actions().count() ; i++ )
|
||||
{
|
||||
key = QString( "File%1" ).arg( 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();
|
||||
cg.writePathEntry( key, value );
|
||||
key = QString( "Name%1" ).arg( i );
|
||||
value = d->m_shortNames[ selectableActionGroup()->actions()[ i - 1 ] ];
|
||||
cg.writePathEntry( key, value );
|
||||
value = d->m_urls[ selectableActionGroup()->actions()[i - 1]].pathOrUrl();
|
||||
cg.writePathEntry(key, value);
|
||||
key = QString("Name%1" ).arg(i);
|
||||
value = d->m_shortNames[selectableActionGroup()->actions()[i - 1]];
|
||||
cg.writePathEntry(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class KRecentFilesActionPrivate;
|
|||
class KDEUI_EXPORT KRecentFilesAction : public KSelectAction
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( int maxItems READ maxItems WRITE setMaxItems )
|
||||
Q_PROPERTY(int maxItems READ maxItems WRITE setMaxItems)
|
||||
Q_DECLARE_PRIVATE(KRecentFilesAction)
|
||||
|
||||
public:
|
||||
|
@ -95,12 +95,12 @@ public:
|
|||
* Do not use addAction(QAction*), as no url will be associated, and
|
||||
* consequently urlSelected() will not be emitted when \a action is selected.
|
||||
*/
|
||||
void addAction(QAction* action, const KUrl& url, const QString& name);
|
||||
void addAction(QAction *action, const KUrl &url, const QString &name);
|
||||
|
||||
/**
|
||||
* Reimplemented for internal reasons.
|
||||
*/
|
||||
virtual QAction* removeAction(QAction* action);
|
||||
virtual QAction* removeAction(QAction *action);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
|
@ -123,7 +123,7 @@ public:
|
|||
* in the recent files list the last items are deleted until
|
||||
* the number of items are equal to the new maximum.
|
||||
*/
|
||||
void setMaxItems( int maxItems );
|
||||
void setMaxItems(int maxItems);
|
||||
|
||||
/**
|
||||
* Loads the recent files entries from a given KConfigGroup object.
|
||||
|
@ -131,7 +131,7 @@ public:
|
|||
* If the groupname is empty, entries are load from a group called 'RecentFiles'
|
||||
*
|
||||
*/
|
||||
void loadEntries( const KConfigGroup &config );
|
||||
void loadEntries(const KConfigGroup &config);
|
||||
|
||||
/**
|
||||
* Saves the current recent files entries to a given KConfigGroup object.
|
||||
|
@ -139,7 +139,7 @@ public:
|
|||
* If the groupname is empty, entries are saved to a group called 'RecentFiles'
|
||||
*
|
||||
*/
|
||||
void saveEntries( const KConfigGroup &config );
|
||||
void saveEntries(const KConfigGroup &config);
|
||||
|
||||
/**
|
||||
* Add URL to recent files list.
|
||||
|
@ -147,14 +147,14 @@ public:
|
|||
* @param url The URL of the file
|
||||
* @param name The user visible pretty name that appears before the URL
|
||||
*/
|
||||
void addUrl( const KUrl& url, const QString& name = QString() );
|
||||
void addUrl(const KUrl &url, const QString &name = QString());
|
||||
|
||||
/**
|
||||
* Remove an URL from the recent files list.
|
||||
*
|
||||
* @param url The URL of the file
|
||||
*/
|
||||
void removeUrl( const KUrl& url );
|
||||
void removeUrl(const KUrl &url);
|
||||
|
||||
/**
|
||||
* Retrieve a list of all URLs in the recent files list.
|
||||
|
@ -167,7 +167,7 @@ Q_SIGNALS:
|
|||
*
|
||||
* @param url The URL thats the user selected.
|
||||
*/
|
||||
void urlSelected( const KUrl& url );
|
||||
void urlSelected(const KUrl &url);
|
||||
|
||||
/**
|
||||
* This signal gets emitted when the user clear list.
|
||||
|
@ -183,7 +183,7 @@ private:
|
|||
// addAction() says, addAction( QAction* ) should not be used.
|
||||
using KSelectAction::addAction;
|
||||
|
||||
Q_PRIVATE_SLOT( d_func(), void _k_urlSelected(QAction*) )
|
||||
Q_PRIVATE_SLOT(d_func(), void _k_urlSelected(QAction*))
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue