QTfrontend/ui/page/pagedrawmap.cpp
branchios-develop
changeset 13418 ba39a1d396c0
parent 13217 e9e4cc867b6e
equal deleted inserted replaced
13416:6e8b807bda4b 13418:ba39a1d396c0
    19 #include <QGridLayout>
    19 #include <QGridLayout>
    20 #include <QPushButton>
    20 #include <QPushButton>
    21 #include <QFileDialog>
    21 #include <QFileDialog>
    22 #include <QCheckBox>
    22 #include <QCheckBox>
    23 #include <QRadioButton>
    23 #include <QRadioButton>
       
    24 #include <QSpinBox>
       
    25 #include <QDir>
    24 
    26 
    25 #include "pagedrawmap.h"
    27 #include "pagedrawmap.h"
    26 #include "drawmapwidget.h"
    28 #include "drawmapwidget.h"
       
    29 #include "hwconsts.h"
    27 
    30 
    28 
    31 
    29 QLayout * PageDrawMap::bodyLayoutDefinition()
    32 QLayout * PageDrawMap::bodyLayoutDefinition()
    30 {
    33 {
    31     QGridLayout * pageLayout = new QGridLayout();
    34     QGridLayout * pageLayout = new QGridLayout();
    32 
    35 
    33     cbEraser = new QCheckBox(tr("Eraser"), this);
    36     cbEraser = new QCheckBox(tr("Eraser"), this);
    34     pageLayout->addWidget(cbEraser, 0, 0);
    37     pageLayout->addWidget(cbEraser, 0, 0);
    35     pbUndo = addButton(tr("Undo"), pageLayout, 1, 0);
       
    36 
    38 
    37     rbPolyline = new QRadioButton(tr("Polyline"), this);
    39     rbPolyline = new QRadioButton(tr("Polyline"), this);
    38     pageLayout->addWidget(rbPolyline, 2, 0);
    40     pageLayout->addWidget(rbPolyline, 1, 0);
    39     rbRectangle = new QRadioButton(tr("Rectangle"), this);
    41     rbRectangle = new QRadioButton(tr("Rectangle"), this);
    40     pageLayout->addWidget(rbRectangle, 3, 0);
    42     pageLayout->addWidget(rbRectangle, 2, 0);
    41     rbEllipse = new QRadioButton(tr("Ellipse"), this);
    43     rbEllipse = new QRadioButton(tr("Ellipse"), this);
    42     pageLayout->addWidget(rbEllipse, 4, 0);
    44     pageLayout->addWidget(rbEllipse, 3, 0);
    43 
    45 
    44     rbPolyline->setChecked(true);
    46     rbPolyline->setChecked(true);
    45 
    47 
    46     pbClear = addButton(tr("Clear"), pageLayout, 5, 0);
    48     sbBrushSize = new QSpinBox(this);
    47     pbOptimize = addButton(tr("Optimize"), pageLayout, 6, 0);
    49     sbBrushSize->setWhatsThis(tr("Brush size"));
       
    50     sbBrushSize->setRange(DRAWN_MAP_BRUSH_SIZE_MIN, DRAWN_MAP_BRUSH_SIZE_MAX);
       
    51     sbBrushSize->setValue(DRAWN_MAP_BRUSH_SIZE_START);
       
    52     sbBrushSize->setSingleStep(DRAWN_MAP_BRUSH_SIZE_STEP);
       
    53     pageLayout->addWidget(sbBrushSize, 4, 0);
       
    54 
       
    55     pbUndo = addButton(tr("Undo"), pageLayout, 5, 0);
       
    56     pbClear = addButton(tr("Clear"), pageLayout, 6, 0);
       
    57 
       
    58     pbOptimize = addButton(tr("Optimize"), pageLayout, 7, 0);
       
    59     // The optimize button is quite buggy, so we disable it for now.
       
    60     // TODO: Re-enable optimize button when it's finished.
    48     pbOptimize->setVisible(false);
    61     pbOptimize->setVisible(false);
    49     pbLoad = addButton(tr("Load"), pageLayout, 7, 0);
       
    50     pbSave = addButton(tr("Save"), pageLayout, 8, 0);
       
    51 
    62 
    52     drawMapWidget = new DrawMapWidget(this);
    63     drawMapWidget = new DrawMapWidget(this);
    53     pageLayout->addWidget(drawMapWidget, 0, 1, 10, 1);
    64     pageLayout->addWidget(drawMapWidget, 0, 1, 10, 1);
    54 
    65 
    55     return pageLayout;
    66     return pageLayout;
       
    67 }
       
    68 
       
    69 QLayout * PageDrawMap::footerLayoutDefinition()
       
    70 {
       
    71     QHBoxLayout * bottomLayout = new QHBoxLayout();
       
    72 
       
    73     bottomLayout->addStretch();
       
    74 
       
    75     pbLoad = addButton(":/res/Load.png", bottomLayout, 0, true, Qt::AlignBottom);
       
    76     pbLoad ->setWhatsThis(tr("Load"));
       
    77     pbLoad->setStyleSheet("QPushButton{margin: 24px 0 0 0;}");
       
    78 
       
    79     pbSave = addButton(":/res/Save.png", bottomLayout, 0, true, Qt::AlignBottom);
       
    80     pbSave ->setWhatsThis(tr("Save"));
       
    81     pbSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}");
       
    82 
       
    83     return bottomLayout;
    56 }
    84 }
    57 
    85 
    58 void PageDrawMap::connectSignals()
    86 void PageDrawMap::connectSignals()
    59 {
    87 {
    60     connect(cbEraser, SIGNAL(toggled(bool)), drawMapWidget, SLOT(setErasing(bool)));
    88     connect(cbEraser, SIGNAL(toggled(bool)), drawMapWidget, SLOT(setErasing(bool)));
    61     connect(pbUndo, SIGNAL(clicked()), drawMapWidget, SLOT(undo()));
    89     connect(pbUndo, SIGNAL(clicked()), drawMapWidget, SLOT(undo()));
    62     connect(pbClear, SIGNAL(clicked()), drawMapWidget, SLOT(clear()));
    90     connect(pbClear, SIGNAL(clicked()), drawMapWidget, SLOT(clear()));
    63     connect(pbOptimize, SIGNAL(clicked()), drawMapWidget, SLOT(optimize()));
    91     connect(pbOptimize, SIGNAL(clicked()), drawMapWidget, SLOT(optimize()));
       
    92     connect(sbBrushSize, SIGNAL(valueChanged(int)), drawMapWidget, SLOT(setBrushSize(int)));
       
    93 
       
    94     connect(drawMapWidget, SIGNAL(brushSizeChanged(int)), this, SLOT(brushSizeChanged(int)));
       
    95 
    64     connect(pbLoad, SIGNAL(clicked()), this, SLOT(load()));
    96     connect(pbLoad, SIGNAL(clicked()), this, SLOT(load()));
    65     connect(pbSave, SIGNAL(clicked()), this, SLOT(save()));
    97     connect(pbSave, SIGNAL(clicked()), this, SLOT(save()));
    66 
    98 
    67     connect(rbPolyline, SIGNAL(toggled(bool)), this, SLOT(pathTypeSwitched(bool)));
    99     connect(rbPolyline, SIGNAL(toggled(bool)), this, SLOT(pathTypeSwitched(bool)));
    68     connect(rbRectangle, SIGNAL(toggled(bool)), this, SLOT(pathTypeSwitched(bool)));
   100     connect(rbRectangle, SIGNAL(toggled(bool)), this, SLOT(pathTypeSwitched(bool)));
    74     initPage();
   106     initPage();
    75 }
   107 }
    76 
   108 
    77 void PageDrawMap::load()
   109 void PageDrawMap::load()
    78 {
   110 {
    79     QString fileName = QFileDialog::getOpenFileName(NULL, tr("Load drawn map"), ".", tr("Drawn Maps") + " (*.hwmap);;" + tr("All files") + " (*)");
   111     QString loadDir = QDir(cfgdir->absolutePath() + "/DrawnMaps").absolutePath();
       
   112     QString fileName = QFileDialog::getOpenFileName(this, tr("Load drawn map"), loadDir, tr("Drawn Maps") + " (*.hwmap);;" + tr("All files") + " (*)");
    80 
   113 
    81     if(!fileName.isEmpty())
   114     if(!fileName.isEmpty())
    82         drawMapWidget->load(fileName);
   115         drawMapWidget->load(fileName);
    83 }
   116 }
    84 
   117 
    85 void PageDrawMap::save()
   118 void PageDrawMap::save()
    86 {
   119 {
    87     QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save drawn map"), "./map.hwmap", tr("Drawn Maps") + " (*.hwmap);;" + tr("All files") + " (*)");
   120     QString saveDir = QDir(cfgdir->absolutePath() + "/DrawnMaps/map.hwmap").absolutePath();
       
   121     QString fileName = QFileDialog::getSaveFileName(this, tr("Save drawn map"), saveDir, tr("Drawn Maps") + " (*.hwmap);;" + tr("All files") + " (*)");
    88 
   122 
    89     if(!fileName.isEmpty())
   123     if(!fileName.isEmpty())
    90         drawMapWidget->save(fileName);
   124         drawMapWidget->save(fileName);
    91 }
   125 }
    92 
   126 
    97         if(rbPolyline->isChecked()) drawMapWidget->setPathType(DrawMapScene::Polyline);
   131         if(rbPolyline->isChecked()) drawMapWidget->setPathType(DrawMapScene::Polyline);
    98         else if(rbRectangle->isChecked()) drawMapWidget->setPathType(DrawMapScene::Rectangle);
   132         else if(rbRectangle->isChecked()) drawMapWidget->setPathType(DrawMapScene::Rectangle);
    99         else if(rbEllipse->isChecked()) drawMapWidget->setPathType(DrawMapScene::Ellipse);
   133         else if(rbEllipse->isChecked()) drawMapWidget->setPathType(DrawMapScene::Ellipse);
   100     }
   134     }
   101 }
   135 }
       
   136 
       
   137 void PageDrawMap::brushSizeChanged(int brushSize)
       
   138 {
       
   139     sbBrushSize->setValue(brushSize);
       
   140 }