Krita Source Code Documentation
Loading...
Searching...
No Matches
KRecentFilesAction Class Reference

Recent files action. More...

#include <krecentfilesaction.h>

+ Inheritance diagram for KRecentFilesAction:

Signals

void urlSelected (const QUrl &url)
 

Public Member Functions

void addAction (QAction *action, const QUrl &url, const QString &name)
 
 KRecentFilesAction (const QIcon &icon, const QString &text, QObject *parent)
 
 KRecentFilesAction (const QString &text, QObject *parent)
 
 KRecentFilesAction (QObject *parent)
 
QAction * removeAction (QAction *action) override
 
void setRecentFilesModel (const QStandardItemModel *model)
 
 ~KRecentFilesAction () override
 

Private Slots

virtual void clearActionTriggered ()
 
void fileAdded (const QUrl &url)
 
void fileRemoved (const QUrl &url)
 
void listRenewed ()
 
void menuAboutToShow ()
 
void modelItemChanged (QStandardItem *item)
 
void modelRowsInserted (const QModelIndex &parent, int first, int last)
 

Private Member Functions

void clearEntries ()
 
 Q_PRIVATE_SLOT (d_func(), void _k_urlSelected(QAction *)) void rebuildEntries()
 

Private Attributes

KRecentFilesActionPrivated_ptr
 

Detailed Description

Recent files action.

This class is an action to handle a recent files submenu. The best way to create the action is to use KStandardAction::openRecent. Then you simply need to call loadEntries on startup, saveEntries on shutdown, addURL when your application loads/saves a file.

Author
Michael Koch

Definition at line 40 of file krecentfilesaction.h.

Constructor & Destructor Documentation

◆ KRecentFilesAction() [1/3]

KRecentFilesAction::KRecentFilesAction ( QObject * parent)
explicit

Constructs an action with the specified parent.

Parameters
parentThe parent of this action.

Definition at line 53 of file krecentfilesaction.cpp.

54 : KSelectAction(parent),
56{
58 d->init();
59}
Recent files action.
KRecentFilesActionPrivate * d_ptr

◆ KRecentFilesAction() [2/3]

KRecentFilesAction::KRecentFilesAction ( const QString & text,
QObject * parent )

Constructs an action with text; a shortcut may be specified by the ampersand character (e.g. "&Option" creates a shortcut with key O )

This is the most common KAction used when you do not have a corresponding icon (note that it won't appear in the current version of the "Edit ToolBar" dialog, because an action needs an icon to be plugged in a toolbar...).

Parameters
textThe text that will be displayed.
parentThe parent of this action.

Definition at line 61 of file krecentfilesaction.cpp.

62 : KSelectAction(parent),
64{
66 d->init();
67
68 // Want to keep the ampersands
69 setText(text);
70}
void setText(QSpinBox *spinBox, const QStringView textTemplate)

◆ KRecentFilesAction() [3/3]

KRecentFilesAction::KRecentFilesAction ( const QIcon & icon,
const QString & text,
QObject * parent )

Constructs an action with text and an icon; a shortcut may be specified by the ampersand character (e.g. "&Option" creates a shortcut with key O )

This is the other common KAction used. Use it when you do have a corresponding icon.

Parameters
iconThe icon to display.
textThe text that will be displayed.
parentThe parent of this action.

Definition at line 72 of file krecentfilesaction.cpp.

73 : KSelectAction(parent),
75{
77 d->init();
78
79 setIcon(icon);
80 // Want to keep the ampersands
81 setText(text);
82}

◆ ~KRecentFilesAction()

KRecentFilesAction::~KRecentFilesAction ( )
override

Destructor.

Definition at line 135 of file krecentfilesaction.cpp.

136{
137 delete d_ptr;
138}

References d_ptr.

Member Function Documentation

◆ addAction()

void KRecentFilesAction::addAction ( QAction * action,
const QUrl & url,
const QString & name )

Adds action to the list of URLs, with url and title name.

Do not use addAction(QAction*), as no url will be associated, and consequently urlSelected() will not be emitted when action is selected.

Definition at line 198 of file krecentfilesaction.cpp.

199{
201
202 menu()->insertAction(menu()->actions().value(0), action);
203 d->m_urls.insert(action, url);
204}
float value(const T *src, size_t ch)

References value().

◆ clearActionTriggered

void KRecentFilesAction::clearActionTriggered ( )
privatevirtualslot

Clears the recent files list. Note that there is also an action shown to the user for clearing the list.

Definition at line 262 of file krecentfilesaction.cpp.

References KisRecentFilesManager::clear(), and KisRecentFilesManager::instance().

◆ clearEntries()

void KRecentFilesAction::clearEntries ( )
private

Definition at line 267 of file krecentfilesaction.cpp.

268{
270 KSelectAction::clear();
271 d->m_urls.clear();
272 d->m_noEntriesAction->setVisible(true);
273 d->clearSeparator->setVisible(false);
274 d->clearAction->setVisible(false);
275 setEnabled(false);
276}

◆ fileAdded

void KRecentFilesAction::fileAdded ( const QUrl & url)
privateslot

Definition at line 317 of file krecentfilesaction.cpp.

318{
320 const QString name; // Dummy
321
322 if (d->m_visibleItemsCount <= 0) {
323 return;
324 }
325
326 // remove oldest item if already maxitems in list
327 if (selectableActionGroup()->actions().count() >= d->m_visibleItemsCount) {
328 // remove oldest added item
329 delete removeAction(selectableActionGroup()->actions().first());
330 }
331
332 const QString tmpName = name.isEmpty() ? url.fileName() : name;
333 const QString pathOrUrl(url.toDisplayString(QUrl::PreferLocalFile));
334
335#ifdef Q_OS_WIN
336 const QString file = url.isLocalFile() ? QDir::toNativeSeparators(pathOrUrl) : pathOrUrl;
337#else
338 const QString file = pathOrUrl;
339#endif
340
341 d->m_noEntriesAction->setVisible(false);
342 d->clearSeparator->setVisible(true);
343 d->clearAction->setVisible(true);
344 setEnabled(true);
345 // add file to list
346 const QString title = titleWithSensibleWidth(tmpName, file);
347 QAction *action = new QAction(title, selectableActionGroup());
348 addAction(action, url, tmpName);
349}
void addAction(QAction *action, const QUrl &url, const QString &name)
QAction * removeAction(QAction *action) override
static QString titleWithSensibleWidth(const QString &nameValue, const QString &value)
const char * name(StandardAction id)

References addAction(), removeAction(), and titleWithSensibleWidth().

◆ fileRemoved

void KRecentFilesAction::fileRemoved ( const QUrl & url)
privateslot

Definition at line 351 of file krecentfilesaction.cpp.

352{
354 for (QMap<QAction *, QUrl>::ConstIterator it = d->m_urls.constBegin(); it != d->m_urls.constEnd(); ++it) {
355 if (it.value() == url) {
356 delete removeAction(it.key());
357 return;
358 }
359 }
360}

References removeAction().

◆ listRenewed

void KRecentFilesAction::listRenewed ( )
privateslot

Definition at line 362 of file krecentfilesaction.cpp.

363{
364 rebuildEntries();
365}

◆ menuAboutToShow

void KRecentFilesAction::menuAboutToShow ( )
privateslot

Definition at line 244 of file krecentfilesaction.cpp.

245{
247 if (!d->m_fileIconsPopulated) {
248 d->m_fileIconsPopulated = true;
249 connect(d->m_recentFilesModel, SIGNAL(itemChanged(QStandardItem *)),
250 SLOT(modelItemChanged(QStandardItem *)));
251 connect(d->m_recentFilesModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
252 SLOT(modelRowsInserted(const QModelIndex &, int, int)));
253 // Populate the file icons only on first showing the menu, so lazy
254 // loading actually works.
255 const int count = d->m_recentFilesModel->rowCount();
256 for (int i = 0; i < count; i++) {
257 d->updateIcon(d->m_recentFilesModel->item(i));
258 }
259 }
260}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void modelItemChanged(QStandardItem *item)
void modelRowsInserted(const QModelIndex &parent, int first, int last)

References connect(), modelItemChanged(), and modelRowsInserted().

◆ modelItemChanged

void KRecentFilesAction::modelItemChanged ( QStandardItem * item)
privateslot

Definition at line 230 of file krecentfilesaction.cpp.

231{
233 d->updateIcon(item);
234}

◆ modelRowsInserted

void KRecentFilesAction::modelRowsInserted ( const QModelIndex & parent,
int first,
int last )
privateslot

Definition at line 236 of file krecentfilesaction.cpp.

237{
239 for (int i = first; i <= last; i++) {
240 d->updateIcon(d->m_recentFilesModel->item(i));
241 }
242}

◆ Q_PRIVATE_SLOT()

KRecentFilesAction::Q_PRIVATE_SLOT ( d_func() ,
void _k_urlSelectedQAction * )
private

◆ removeAction()

QAction * KRecentFilesAction::removeAction ( QAction * action)
override

Reimplemented for internal reasons.

Definition at line 206 of file krecentfilesaction.cpp.

207{
209 KSelectAction::removeAction(action);
210
211 d->m_urls.remove(action);
212
213 return action;
214}

◆ setRecentFilesModel()

void KRecentFilesAction::setRecentFilesModel ( const QStandardItemModel * model)

Definition at line 216 of file krecentfilesaction.cpp.

217{
219
220 if (d->m_recentFilesModel) {
221 disconnect(d->m_recentFilesModel, nullptr, this, nullptr);
222 }
223
224 d->m_recentFilesModel = model;
225 // Do not connect the signals or populate the icons now, because we want
226 // them to be lazy-loaded only when the menu is opened for the first time.
227 d->m_fileIconsPopulated = false;
228}

◆ urlSelected

void KRecentFilesAction::urlSelected ( const QUrl & url)
signal

This signal gets emitted when the user selects a URL.

Parameters
urlThe URL that the user selected.

Member Data Documentation

◆ d_ptr

KRecentFilesActionPrivate* KRecentFilesAction::d_ptr
private

Definition at line 123 of file krecentfilesaction.h.


The documentation for this class was generated from the following files: