#385 : final version

--HG--
branch : feature
This commit is contained in:
Thomas HOCEDEZ 2016-02-18 12:18:14 +01:00
parent ae1830617a
commit b449e16b81
2 changed files with 78 additions and 1 deletions

View File

@ -117,6 +117,12 @@ TMainWindow::TMainWindow(QWidget *parent)
ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu); ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu); ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu);
for (int i = 0; i < MaxRecentFiles; ++i)
{
recentFileActs[i] = nullptr;
}
separatorAct=nullptr;
SetupMenu(); SetupMenu();
setWindowTitle(tr("untitled %1").arg(qApp->MainWindows().size()+1)); setWindowTitle(tr("untitled %1").arg(qApp->MainWindows().size()+1));
@ -165,7 +171,7 @@ void TMainWindow::RetranslateTable()
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //--------separatorAct-------------------------------------------------------------------------------------------------------------
void TMainWindow::SetBaseMHeight(int height) void TMainWindow::SetBaseMHeight(int height)
{ {
if (m != nullptr) if (m != nullptr)
@ -1735,6 +1741,20 @@ void TMainWindow::SetupMenu()
connect(ui->actionReadOnly, &QAction::triggered, this, &TMainWindow::ReadOnly); connect(ui->actionReadOnly, &QAction::triggered, this, &TMainWindow::ReadOnly);
connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences); connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences);
for (int i = 0; i < MaxRecentFiles; ++i)
{
recentFileActs[i] = new QAction(this);
connect(recentFileActs[i], &QAction::triggered, this, &TMainWindow::OpenRecentFile);
ui->menuFile->insertAction(ui->actionPreferences, recentFileActs[i]);
recentFileActs[i]->setVisible(false);
}
separatorAct = new QAction(this);
separatorAct->setSeparator(true);
separatorAct->setVisible(false);
ui->menuFile->insertAction(ui->actionPreferences, separatorAct );
connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close); connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close);
ui->actionQuit->setShortcuts(QKeySequence::Quit); ui->actionQuit->setShortcuts(QKeySequence::Quit);
@ -1755,6 +1775,10 @@ void TMainWindow::SetupMenu()
// Help // Help
connect(ui->actionAboutQt, &QAction::triggered, this, &TMainWindow::AboutQt); connect(ui->actionAboutQt, &QAction::triggered, this, &TMainWindow::AboutQt);
connect(ui->actionAboutTape, &QAction::triggered, this, &TMainWindow::AboutApplication); connect(ui->actionAboutTape, &QAction::triggered, this, &TMainWindow::AboutApplication);
//Actions for recent files loaded by a tape window application.
UpdateRecentFileActions();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2025,6 +2049,16 @@ void TMainWindow::SetCurrentFile(const QString &fileName)
ui->lineEditPathToFile->setText(QDir::toNativeSeparators(curFile)); ui->lineEditPathToFile->setText(QDir::toNativeSeparators(curFile));
ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(curFile)); ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(curFile));
ui->pushButtonShowInExplorer->setEnabled(true); ui->pushButtonShowInExplorer->setEnabled(true);
VTapeSettings *settings = qApp->TapeSettings();
QStringList files = settings->GetRecentFileList();
files.removeAll(fileName);
files.prepend(fileName);
while (files.size() > MaxRecentFiles)
{
files.removeLast();
}
settings->SetRecentFileList(files);
UpdateRecentFileActions();
} }
shownName += "[*]"; shownName += "[*]";
setWindowTitle(shownName); setWindowTitle(shownName);
@ -2689,6 +2723,30 @@ bool TMainWindow::LoadFromExistingFile(const QString &path)
return true; return true;
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::UpdateRecentFileActions()
{
qCDebug(tMainWindow, "Updating recent file actions.");
const QStringList files = qApp->TapeSettings()->GetRecentFileList();
const int numRecentFiles = qMin(files.size(), static_cast<int>(MaxRecentFiles));
qCDebug(tMainWindow, "Updating recent file actions = %i ",numRecentFiles);
for (int i = 0; i < numRecentFiles; ++i)
{
QString text = QString("&%1. %2").arg(i + 1).arg(StrippedName(files.at(i)));
qCDebug(tMainWindow, "file %i = %s",numRecentFiles,text);
recentFileActs[i]->setText(text);
recentFileActs[i]->setData(files.at(i));
recentFileActs[i]->setVisible(true);
}
for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
{
recentFileActs[j]->setVisible(false);
}
separatorAct->setVisible(numRecentFiles>0);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::CreateWindowMenu(QMenu *menu) void TMainWindow::CreateWindowMenu(QMenu *menu)
@ -2722,6 +2780,19 @@ void TMainWindow::CreateWindowMenu(QMenu *menu)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::OpenRecentFile()
{
if (auto action=qobject_cast<QAction *>(sender()))
{
const QString filePath = action->data().toString();
if (not filePath.isEmpty())
{
LoadFile(filePath);
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool TMainWindow::IgnoreLocking(int error, const QString &path) bool TMainWindow::IgnoreLocking(int error, const QString &path)
{ {

View File

@ -69,6 +69,7 @@ public slots:
void OpenStandard(); void OpenStandard();
void OpenTemplate(); void OpenTemplate();
void CreateFromExisting(); void CreateFromExisting();
void OpenRecentFile();
protected: protected:
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
@ -152,6 +153,10 @@ private:
QAction *actionDockDiagram; QAction *actionDockDiagram;
bool dockDiagramVisible; bool dockDiagramVisible;
bool isInitialized; bool isInitialized;
enum { MaxRecentFiles = 5 };
QAction *recentFileActs[MaxRecentFiles];
QAction *separatorAct;
void SetupMenu(); void SetupMenu();
void InitWindow(); void InitWindow();
@ -163,6 +168,7 @@ private:
void ShowUnits(); void ShowUnits();
void ShowHeaderUnits(QTableWidget *table, int column, const QString &unit); void ShowHeaderUnits(QTableWidget *table, int column, const QString &unit);
void UpdateRecentFileActions();
void MeasurementsWasSaved(bool saved); void MeasurementsWasSaved(bool saved);
void SetCurrentFile(const QString &fileName); void SetCurrentFile(const QString &fileName);