Browse Source

updated save/load functions to keep a list of files last used

tags/1.3
Sven Oliver Moll 1 year ago
parent
commit
1f73eeb2e2

+ 2
- 0
src/fridgegrid/DragWidget.cpp View File

@@ -328,6 +328,7 @@ void DragWidget::save()
return;
}
settings.setValue( "Filename", fileName );
emit fileUsed( fileName );

QDomDocument domDoc;
QDomElement domRoot = domDoc.createElement( "FridgeGrid" );
@@ -382,6 +383,7 @@ void DragWidget::load( const QString &templateFileName )
else
{
settings.setValue( "Filename", fileName );
emit fileUsed( fileName );
}

QFile file( fileName );

+ 3
- 0
src/fridgegrid/DragWidget.hpp View File

@@ -110,6 +110,9 @@ public slots:
*/
void newElement( const QByteArray &d = QByteArray(), const QPoint &p = QPoint() );

signals:
void fileUsed( const QString &fileName );

protected:
/*!
\brief \todo

+ 40
- 0
src/fridgegrid/MainWindow.cpp View File

@@ -36,15 +36,26 @@

MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
, mpLastFilesMenu( new QMenu( this ) )
, mpLastFilesMapper( new QSignalMapper( this ) )
, mpSplitter( new QSplitter( Qt::Vertical, this ) )
, mpTextEdit( new QTextEdit( mpSplitter ) )
, mpDragWidget( new DragWidget( mpSplitter ) )
, mLastFilenames()
{
QCommonStyle style;
QSettings settings;
QMenu *templateMenu( new QMenu( this ) );
mLastFilenames = settings.value( "LastUsed" ).toStringList();
mpLastFilesMenu->setToolTipsVisible( true );

connect( mpLastFilesMapper, SIGNAL(mapped(QString)),
mpDragWidget, SLOT(load(QString)) );
connect( mpDragWidget, SIGNAL(fileUsed(QString)),
this, SLOT(fileUsed(QString)) );

templateMenu->setObjectName( "TemplateMenu" );
mpLastFilesMenu->setObjectName( "LastFileMenu" );

mpSplitter->setObjectName( "CentralSplitter" );
mpSplitter->addWidget( mpTextEdit );
@@ -104,6 +115,7 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )

action = new QAction( style.standardIcon( QStyle::SP_DialogOpenButton ), "Open File", this );
action->setShortcuts( QKeySequence::Open );
action->setMenu( mpLastFilesMenu );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(load()) );
toolBar->addAction( action );
@@ -145,6 +157,8 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
updateDelay, SLOT(start()) );
connect( updateDelay, SIGNAL(timeout()),
this, SLOT(commentChange()) );

fileUsed();
}


@@ -172,3 +186,29 @@ void MainWindow::commentChange()
setWindowTitle( QCoreApplication::applicationName() );
}
}


void MainWindow::fileUsed( const QString &fileName )
{
QSettings settings;

if( !fileName.isEmpty() )
{
mLastFilenames.removeAll( fileName );
mLastFilenames.prepend( fileName );
while( mLastFilenames.size() > 20 ) /* \todo TODO: make configurable */
{
mLastFilenames.takeLast();
}
settings.setValue( "LastUsed", mLastFilenames );
}

mpLastFilesMenu->clear();
foreach ( const QString &fileName, mLastFilenames ) {
QAction *entry = mpLastFilesMenu->addAction( fileName.mid(fileName.lastIndexOf("/")+1) );
entry->setToolTip( fileName );
connect( entry, SIGNAL(triggered()),
mpLastFilesMapper, SLOT(map()));
mpLastFilesMapper->setMapping( entry, fileName );
}
}

+ 11
- 0
src/fridgegrid/MainWindow.hpp View File

@@ -15,6 +15,7 @@
/* system headers */

/* Qt headers */
#include <QStringList>

/* local library headers */

@@ -23,8 +24,10 @@
/* forward declaration of Qt classes */
class QDockWidget;
class QLineEdit;
class QMenu;
class QModelIndex;
class QPushButton;
class QSignalMapper;
class QSplitter;
class QTextEdit;

@@ -62,6 +65,11 @@ public slots:
*/
void commentChange();

/*!
\brief \todo
*/
void fileUsed( const QString &fileName = QString() );

signals:

protected:
@@ -69,9 +77,12 @@ protected:
private:
Q_DISABLE_COPY( MainWindow )

QMenu *mpLastFilesMenu; /*!< \brief \todo TODO */
QSignalMapper *mpLastFilesMapper; /*!< \brief \todo TODO */
QSplitter *mpSplitter; /*!< \brief \todo TODO */
QTextEdit *mpTextEdit; /*!< \brief \todo TODO */
DragWidget *mpDragWidget; /*!< \brief the central widget */
QStringList mLastFilenames; /*!< \brief \todo TODO */
};

/*! @} */

Loading…
Cancel
Save