QSint Library  0.2.2
Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
QSint::RecentFiles Class Reference

Class representing recently opened files as a QMenu. More...

#include <recentfiles.h>

Inherits QObject.

Public Slots

virtual void add (const QString &filename, const QIcon &icon=QIcon())
 
virtual void remove (const QString &filename)
 
virtual void clear ()
 

Signals

void activated (const QString &filename)
 

Public Member Functions

 RecentFiles (QWidget *parent=0)
 
virtual ~RecentFiles ()
 
QMenu * menu () const
 
const QList< QPair< QString,
QIcon > > & 
recentFileList () const
 
void populateMenu (QMenu *menu)
 
int maxFileCount () const
 
void setMaxFileCount (int max)
 
virtual void readConfig (QSettings &set)
 
virtual void writeConfig (QSettings &set)
 

Protected Member Functions

virtual void updateMenu ()
 

Detailed Description

Class representing recently opened files as a QMenu.

Class provides easy API to add, remove and signal of the picking of the recent file item. Each item can have associated QIcon.

Class automatically maintains amount of the recent files and their order (i.e. most recently added and picked items always go to the top of the list).

Also class can store and load the list of the recent files through a QSetting object.

Usage of RecentFiles in the application

There are two ways of representation of the recent files: as a submenu and as an embedded list.

Usage as a submenu is very easy. Just create RecentFiles object and add its menu() to the appropriate action of the parent menu. Then connect activated() signal to the appropriate slot.

// assume that myRecentFiles is RecentFiles object, and actionRecent is an action
// in the parent menu
// incorporate Recent Files menu as actionRecent's submenu
actionRecent->setMenu(myRecentFiles.menu());
// connect activated() signal to the your handling slot, i.e. handleActivated()
connect(&myRecentFiles, SIGNAL(activated(QString)),
this, SLOT(handleActivated(QString)));

Usage as an embedded list requires handling of aboutToShow() signal of the menu where you'd like to show the recent files.

First, as usual, create RecentFiles object. Then connect activated() signal to the appropriate slot.

Second, in the slot associatiated with this signal, you have to create all the menu actions and in a mean time, call populateMenu() function to provide internal connections and insert recent files list into the menu.

// assume that fileMenu is QMenu where you want to embed recent files in,
// MyAppWindow is the class of your application,
// myRecentFiles is RecentFiles object
// connect activated() signal to the your handling slot, i.e. handleActivated()
connect(&myRecentFiles, SIGNAL(activated(QString)),
this, SLOT(handleActivated(QString)));
// this is the slot connected to fileMenu's aboutToShow() signal
void MyAppWindow::on_fileMenu_aboutToShow()
{
// first, clear our menu
fileMenu->clear();
// then, add some custom actions
// ...
// you probably want to add a separator before recent files
fileMenu->addSeparator();
// then, add recent files here
myRecentFiles.populate(fileMenu);
// you probably want to add a separator after recent files as well
fileMenu->addSeparator();
// then, add another custom actions
// ...
}

Constructor & Destructor Documentation

QSint::RecentFiles::RecentFiles ( QWidget *  parent = 0)
explicit

Constructor.

virtual QSint::RecentFiles::~RecentFiles ( )
inlinevirtual

Destructor.

Member Function Documentation

void QSint::RecentFiles::activated ( const QString &  filename)
signal

Emitted when user picks an item with filename from the recent files menu.

void QSint::RecentFiles::add ( const QString &  filename,
const QIcon &  icon = QIcon() 
)
virtualslot

Creates an entry in the recent files menu with filename and icon. If filename already exists, moves it to the beginning of the list.

void QSint::RecentFiles::clear ( )
virtualslot

Clears recent files list.

int QSint::RecentFiles::maxFileCount ( ) const
inline

Returns maximal amount of the recent files in the menu (default is 10).

QMenu* QSint::RecentFiles::menu ( ) const
inline

Returns a pointer to the QMenu contating recent files.

void QSint::RecentFiles::populateMenu ( QMenu *  menu)

Appends recent actions to menu. This is useful for embedding recent files list into existing QMenu.

void QSint::RecentFiles::readConfig ( QSettings &  set)
virtual

Fills recent files menu from the given set.

const QList<QPair<QString,QIcon> >& QSint::RecentFiles::recentFileList ( ) const
inline

Returns a const reference to the recent files names and icons.

void QSint::RecentFiles::remove ( const QString &  filename)
virtualslot

Removes an entry with filename from the recent files menu.

void QSint::RecentFiles::setMaxFileCount ( int  max)

Sets maximal amount of the recent files in the menu (default is 10).

void QSint::RecentFiles::updateMenu ( )
protectedvirtual

Builds up QMenu from the current recent files list.

void QSint::RecentFiles::writeConfig ( QSettings &  set)
virtual

Stores recent files menu entries to the given set.


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

© Sintegrial Technologies 2011-2014
http://www.sintegrial.com