Skip to content

Commit

Permalink
Allow the user to save his drawings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tstaerk committed Sep 6, 2011
1 parent 2ff5cdf commit 35201a0
Show file tree
Hide file tree
Showing 6 changed files with 3,861 additions and 3,789 deletions.
22 changes: 17 additions & 5 deletions mainwindow.cpp
Expand Up @@ -5,6 +5,7 @@
#include "drawscene.h"
#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QBuffer>

MainWindow::MainWindow(QWidget *parent) :
Expand Down Expand Up @@ -45,10 +46,12 @@ void MainWindow::setpencolor(QColor color)
void MainWindow::deletemoreform()
{
mf->deleteLater();
ui->graphicsView->show();
mf=0;
ui->morebutton->setText(tr("More"));
}

void MainWindow::saveactualpage()
void MainWindow::saveactualpage(QString filename)
{
QImage* image=new QImage(QSize((int)ui->graphicsView->scene()->width(),(int)ui->graphicsView->scene()->height()),QImage::Format_RGB32);
QPainter* painter=new QPainter(image);
Expand All @@ -58,7 +61,7 @@ void MainWindow::saveactualpage()
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image->save(&buffer, "PNG");
QString filename=QString("/tmp/quickpen-").append(QString::number(page).append(QString(".png")));
if (filename==QString()) filename=QString("/tmp/quickpen-").append(QString::number(page).append(QString(".png")));
QFile* file1=new QFile(filename);
file1->open(QIODevice::WriteOnly);
image->save(file1, "PNG");
Expand Down Expand Up @@ -93,12 +96,21 @@ void MainWindow::on_morebutton_clicked()
{
if (mf)
{
mf->deleteLater();
mf=0;
deletemoreform();
}
else
{
mf=new MoreForm(this);
ui->gridLayout->addWidget(mf,3,1);
ui->morebutton->setText(tr("Less"));
ui->graphicsView->hide();
ui->gridLayout->addWidget(mf,1,0,1,3);
}
}


void MainWindow::on_pushButton_2_clicked()
{
qDebug() << "entering";
QString filename=QFileDialog::getSaveFileName(0);

}
4 changes: 3 additions & 1 deletion mainwindow.h
Expand Up @@ -17,6 +17,7 @@ class MainWindow : public QMainWindow {
int page;
void setpencolor(QColor color);
void deletemoreform();
void saveactualpage(QString filename=QString());

protected:
void changeEvent(QEvent *e);
Expand All @@ -27,11 +28,12 @@ class MainWindow : public QMainWindow {
QColor pencolor;

private slots:
void saveactualpage();

void loadpage(int page);
void on_nextbutton_clicked();
void on_prevbutton_clicked();
void on_morebutton_clicked();
void on_pushButton_2_clicked();
};

#endif // MAINWINDOW_H
18 changes: 18 additions & 0 deletions mainwindow.ui
Expand Up @@ -21,6 +21,12 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCommandLinkButton" name="prevbutton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Previous page</string>
</property>
Expand All @@ -32,6 +38,12 @@
</item>
<item row="0" column="2">
<widget class="QCommandLinkButton" name="nextbutton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Next page</string>
</property>
Expand All @@ -46,6 +58,12 @@
</item>
<item row="0" column="1">
<widget class="QCommandLinkButton" name="morebutton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>More</string>
</property>
Expand Down
7 changes: 7 additions & 0 deletions moreform.cpp
Expand Up @@ -2,6 +2,7 @@
#include "moreform.h"
#include "ui_moreform.h"
#include <QDebug>
#include <QFileDialog>

MoreForm::MoreForm(MainWindow *parent1) :
ui(new Ui::MoreForm)
Expand Down Expand Up @@ -68,3 +69,9 @@ void MoreForm::on_turquoise_clicked()
parent->setpencolor(QColor("turquoise"));
parent->deletemoreform();
}

void MoreForm::on_savebutton_clicked()
{
//TODO: What if the user cancels the dialog?
parent->saveactualpage(QFileDialog::getSaveFileName(0));
}
2 changes: 2 additions & 0 deletions moreform.h
Expand Up @@ -35,6 +35,8 @@ private slots:

void on_turquoise_clicked();

void on_savebutton_clicked();

private:
Ui::MoreForm *ui;
MainWindow* parent;
Expand Down

0 comments on commit 35201a0

Please sign in to comment.