Skip to content

Commit

Permalink
added save file as, select all
Browse files Browse the repository at this point in the history
  • Loading branch information
unruhschuh committed Jan 16, 2016
1 parent 6f61efe commit 1a11589
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
55 changes: 47 additions & 8 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ void MainWindow::createActions()
connect(saveFileAct, SIGNAL(triggered()), this, SLOT(saveFile()));
this->addAction(saveFileAct);

saveFileAsAct = new QAction(tr("&Save file as"), this);
saveFileAsAct->setShortcuts(QKeySequence::SaveAs);
saveFileAsAct->setStatusTip(tr("Save File as"));
connect(saveFileAsAct, SIGNAL(triggered()), this, SLOT(saveFileAs()));
this->addAction(saveFileAsAct);

exportPDFAct = new QAction(QIcon(":/images/savePDFIcon.png"), tr("Export PDF"), this);
exportPDFAct->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_E));
// zoomFitWidthAct->setShortcut(QKeySequence(Qt::Key_Z));
Expand Down Expand Up @@ -499,6 +505,7 @@ void MainWindow::createMenus()
fileMenu->addAction(newFileAct);
fileMenu->addAction(openFileAct);
fileMenu->addAction(saveFileAct);
fileMenu->addAction(saveFileAsAct);
fileMenu->addAction(exportPDFAct);
fileMenu->addAction(importXOJAct);
fileMenu->addAction(exportXOJAct);
Expand All @@ -513,6 +520,8 @@ void MainWindow::createMenus()
editMenu->addAction(copyAct);
editMenu->addAction(pasteAct);
editMenu->addSeparator();
editMenu->addAction(selectAllAct);
editMenu->addSeparator();
editMenu->addAction(rotateAct);

pageMenu = menuBar()->addMenu(tr("&Page"));
Expand Down Expand Up @@ -725,20 +734,48 @@ void MainWindow::openFile()
}
}

QString MainWindow::askForFileName()
{
QDateTime dateTime = QDateTime::currentDateTime();
QString dir = QDir::homePath();
dir.append("/");
dir.append(dateTime.toString("yyyy-MM-dd"));
dir.append("-Note-");
dir.append(dateTime.toString("HH-mm"));
dir.append(".moj");
QString fileName = QFileDialog::getSaveFileName(this, tr("Save MOJ"), dir, tr("MrWriter Files (*.moj)"));

return fileName;
}

bool MainWindow::saveFileAs()
{
QString fileName = askForFileName();

if (fileName.isNull())
{
return false;
}

if (mainWidget->currentDocument.saveMOJ(fileName))
{
modified();
setTitle();
return true;
}
else
{
return false;
}
}

bool MainWindow::saveFile()
{
QString dir;
QString fileName;
if (mainWidget->currentDocument.docName().isEmpty())
{
QDateTime dateTime = QDateTime::currentDateTime();
dir = QDir::homePath();
dir.append("/");
dir.append(dateTime.toString("yyyy-MM-dd"));
dir.append("-Note-");
dir.append(dateTime.toString("HH-mm"));
dir.append(".moj");
fileName = QFileDialog::getSaveFileName(this, tr("Save MOJ"), dir, tr("MrWriter Files (*.moj)"));
fileName = askForFileName();
}
else
{
Expand Down Expand Up @@ -1247,6 +1284,7 @@ void MainWindow::cloneWindow()
{
MainWindow *window = new MainWindow();
window->mainWidget->currentDocument = mainWidget->currentDocument;
window->mainWidget->currentDocument.setDocName("");
window->mainWidget->pageBuffer = mainWidget->pageBuffer;
window->mainWidget->currentSelection = mainWidget->currentSelection;
window->mainWidget->setCurrentState(mainWidget->getCurrentState());
Expand All @@ -1261,6 +1299,7 @@ void MainWindow::cloneWindow()
window->scrollArea->horizontalScrollBar()->setValue(scrollArea->horizontalScrollBar()->value());

window->mainWidget->update();
window->mainWidget->updateGUI();

static_cast<TabletApplication *>(qApp)->mainWindows.append(window);
}
Expand Down
5 changes: 5 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ private slots:
void cloneWindow();
void newFile();
void openFile();

bool saveFileAs();
bool saveFile();
void exportPDF();

Expand Down Expand Up @@ -98,6 +100,8 @@ private slots:
void createToolBars();
void createMenus();

QString askForFileName();

QLabel pageStatus;
QLabel penWidthStatus;
QLabel colorStatus;
Expand All @@ -109,6 +113,7 @@ private slots:
QAction *newFileAct;
QAction *openFileAct;
QAction *saveFileAct;
QAction *saveFileAsAct;
QAction *exportPDFAct;
QAction *exitAct;

Expand Down
19 changes: 16 additions & 3 deletions widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,12 @@ void Widget::setDocument(const MrDoc::Document &newDocument)

void Widget::selectAll()
{

if (currentState == state::SELECTED)
{
letGoSelection();
}

int pageNum = getCurrentPage();
QRectF selectRect;
for (auto &stroke : currentDocument.pages[pageNum].strokes())
Expand All @@ -1646,16 +1652,23 @@ void Widget::selectAll()
}
QPolygonF selectionPolygon = QPolygonF(selectRect);

currentSelection.setSelectionPolygon(selectionPolygon);
MrDoc::Selection selection;
selection.setPageNum(pageNum);
selection.setSelectionPolygon(selectionPolygon);

if (!currentDocument.pages[pageNum].getStrokes(currentSelection.selectionPolygon()).isEmpty())
if (!currentDocument.pages[pageNum].getStrokes(selection.selectionPolygon()).isEmpty())
{
CreateSelectionCommand *createSelectionCommand = new CreateSelectionCommand(this, pageNum, currentSelection);
currentSelection = selection;
CreateSelectionCommand *createSelectionCommand = new CreateSelectionCommand(this, pageNum, selection);
undoStack.push(createSelectionCommand);

emit updateGUI();
update();
}
else
{
setCurrentState(state::IDLE);
}
}

void Widget::copy()
Expand Down

0 comments on commit 1a11589

Please sign in to comment.