Added recent files menu
This commit is contained in:
parent
ff1e5698ef
commit
f920d00c0a
@ -21,6 +21,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->extruderlcd->setPalette(Qt::red);
|
ui->extruderlcd->setPalette(Qt::red);
|
||||||
ui->bedlcd->setPalette(Qt::red);
|
ui->bedlcd->setPalette(Qt::red);
|
||||||
ui->sendtext->installEventFilter(this);
|
ui->sendtext->installEventFilter(this);
|
||||||
|
recentMenu = new QMenu(this);
|
||||||
|
recentMenu->setTitle("Recent files");
|
||||||
|
ui->menuFile->insertMenu(ui->actionSettings, recentMenu);
|
||||||
|
ui->menuFile->insertSeparator(ui->actionSettings);
|
||||||
|
|
||||||
//Init baudrate combobox
|
//Init baudrate combobox
|
||||||
ui->baudbox->addItem(QString::number(4800));
|
ui->baudbox->addItem(QString::number(4800));
|
||||||
@ -46,6 +50,13 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
firmware = settings.value("printer/firmware", OtherFirmware).toInt();
|
firmware = settings.value("printer/firmware", OtherFirmware).toInt();
|
||||||
statusTimer.setInterval(settings.value("core/statusinterval", 3000).toInt());
|
statusTimer.setInterval(settings.value("core/statusinterval", 3000).toInt());
|
||||||
sendTimer.setInterval(settings.value("core/senderinterval", 2).toInt());
|
sendTimer.setInterval(settings.value("core/senderinterval", 2).toInt());
|
||||||
|
int size = settings.beginReadArray("user/recentfiles");
|
||||||
|
for(int i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
|
settings.setArrayIndex(i);
|
||||||
|
recentFiles.append(settings.value("user/file").toString());
|
||||||
|
}
|
||||||
|
settings.endArray();
|
||||||
|
|
||||||
//Init values
|
//Init values
|
||||||
sending = false;
|
sending = false;
|
||||||
@ -98,6 +109,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
if(chekingSDStatus) progressSDTimer.start();
|
if(chekingSDStatus) progressSDTimer.start();
|
||||||
sinceLastTemp.start();
|
sinceLastTemp.start();
|
||||||
sinceLastSDStatus.start();
|
sinceLastSDStatus.start();
|
||||||
|
|
||||||
|
updateRecent();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -110,10 +123,10 @@ MainWindow::~MainWindow()
|
|||||||
settings.setValue("user/bedtemp", ui->btmpspin->value());
|
settings.setValue("user/bedtemp", ui->btmpspin->value());
|
||||||
|
|
||||||
settings.beginWriteArray("user/recentfiles");
|
settings.beginWriteArray("user/recentfiles");
|
||||||
for(int i = 0; i < recentFiles.size(); i++)
|
for(int i = 0; i < recentFiles.size(); ++i)
|
||||||
{
|
{
|
||||||
settings.setArrayIndex(i);
|
settings.setArrayIndex(i);
|
||||||
settings.setValue("user/recentfile", recentFiles.at(i));
|
settings.setValue("user/file", recentFiles.at(i));
|
||||||
}
|
}
|
||||||
settings.endArray();
|
settings.endArray();
|
||||||
|
|
||||||
@ -135,27 +148,24 @@ void MainWindow::open()
|
|||||||
tr("Open GCODE"),
|
tr("Open GCODE"),
|
||||||
home.home().absolutePath(),
|
home.home().absolutePath(),
|
||||||
tr("GCODE (*.g *.gcode *.nc)"));
|
tr("GCODE (*.g *.gcode *.nc)"));
|
||||||
|
|
||||||
gfile.setFileName(filename);
|
gfile.setFileName(filename);
|
||||||
if(!recentFiles.contains(filename))
|
if(!recentFiles.contains(filename))
|
||||||
{
|
{
|
||||||
if(recentFiles.size() < 5) recentFiles.append(filename);
|
recentFiles.prepend(filename);
|
||||||
else
|
if(recentFiles.size() == 5) recentFiles.removeAt(5);
|
||||||
{
|
|
||||||
recentFiles.push_front(filename);
|
|
||||||
recentFiles.removeAt(5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseFile(gfile);
|
updateRecent();
|
||||||
|
parseFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::parseFile(QFile &file)
|
void MainWindow::parseFile(QString filename)
|
||||||
{
|
{
|
||||||
|
gfile.setFileName(filename);
|
||||||
gcode.clear();
|
gcode.clear();
|
||||||
if (file.open(QIODevice::ReadOnly))
|
if (gfile.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
QTextStream in(&file);
|
QTextStream in(&gfile);
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (!in.atEnd())
|
while (!in.atEnd())
|
||||||
{
|
{
|
||||||
@ -176,11 +186,11 @@ void MainWindow::parseFile(QFile &file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
file.close();
|
gfile.close();
|
||||||
ui->fileBox->setEnabled(true);
|
ui->fileBox->setEnabled(true);
|
||||||
ui->progressBar->setEnabled(true);
|
ui->progressBar->setEnabled(true);
|
||||||
ui->sendBtn->setText("Send");
|
ui->sendBtn->setText("Send");
|
||||||
ui->filename->setText(file.fileName().split("/").last());
|
ui->filename->setText(gfile.fileName().split("/").last());
|
||||||
ui->filelines->setText(QString::number(gcode.size()) + QString("/0 lines"));
|
ui->filelines->setText(QString::number(gcode.size()) + QString("/0 lines"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -628,7 +638,21 @@ void MainWindow::injectCommand(QString command)
|
|||||||
|
|
||||||
void MainWindow::updateRecent()
|
void MainWindow::updateRecent()
|
||||||
{
|
{
|
||||||
//TODO
|
if(!recentFiles.isEmpty())
|
||||||
|
{
|
||||||
|
recentMenu->clear();
|
||||||
|
foreach (QString str, recentFiles)
|
||||||
|
{
|
||||||
|
if (!str.isEmpty())
|
||||||
|
{
|
||||||
|
QAction *action = new QAction(this);
|
||||||
|
action->setText(str);
|
||||||
|
action->setObjectName(str);
|
||||||
|
recentMenu->addAction(action);
|
||||||
|
connect(action, SIGNAL(triggered()), this, SLOT(recentClicked()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::serialError(QSerialPort::SerialPortError error)
|
void MainWindow::serialError(QSerialPort::SerialPortError error)
|
||||||
@ -880,3 +904,8 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
|||||||
}
|
}
|
||||||
return QMainWindow::eventFilter(obj, event);
|
return QMainWindow::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::recentClicked()
|
||||||
|
{
|
||||||
|
parseFile(sender()->objectName());
|
||||||
|
}
|
||||||
|
|||||||
@ -52,12 +52,13 @@ protected:
|
|||||||
QStringList recentFiles;
|
QStringList recentFiles;
|
||||||
QStringList EEPROMSettings;
|
QStringList EEPROMSettings;
|
||||||
QStringList userHistory;
|
QStringList userHistory;
|
||||||
|
QMenu *recentMenu;
|
||||||
|
|
||||||
bool eventFilter(QObject *target, QEvent *event);
|
bool eventFilter(QObject *target, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
void parseFile(QFile &file);
|
|
||||||
QSerialPort printer;
|
QSerialPort printer;
|
||||||
QSerialPortInfo printerinfo;
|
QSerialPortInfo printerinfo;
|
||||||
bool firstrun;
|
bool firstrun;
|
||||||
@ -103,6 +104,8 @@ private slots:
|
|||||||
void recievedError();
|
void recievedError();
|
||||||
void recievedSDDone();
|
void recievedSDDone();
|
||||||
void recievedResend(int num);
|
void recievedResend(int num);
|
||||||
|
void parseFile(QString filename);
|
||||||
|
void recentClicked();
|
||||||
|
|
||||||
void xplus();
|
void xplus();
|
||||||
void yplus();
|
void yplus();
|
||||||
|
|||||||
@ -1096,8 +1096,6 @@ STOP</string>
|
|||||||
<string>File</string>
|
<string>File</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionOpen"/>
|
<addaction name="actionOpen"/>
|
||||||
<addaction name="actionRecent"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="actionSettings"/>
|
<addaction name="actionSettings"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExit"/>
|
<addaction name="actionExit"/>
|
||||||
@ -1170,6 +1168,9 @@ STOP</string>
|
|||||||
<addaction name="actionSettings"/>
|
<addaction name="actionSettings"/>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionOpen">
|
<action name="actionOpen">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="graphics.qrc">
|
<iconset resource="graphics.qrc">
|
||||||
<normaloff>:/icons/g.png</normaloff>:/icons/g.png</iconset>
|
<normaloff>:/icons/g.png</normaloff>:/icons/g.png</iconset>
|
||||||
@ -1181,14 +1182,6 @@ STOP</string>
|
|||||||
<string>Ctrl+O</string>
|
<string>Ctrl+O</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionRecent">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Recent</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionExit">
|
<action name="actionExit">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="graphics.qrc">
|
<iconset resource="graphics.qrc">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user