118 ChartCarbonate::~ChartCarbonate() {} |
118 ChartCarbonate::~ChartCarbonate() {} |
119 |
119 |
120 |
120 |
121 void ChartCarbonate::savePNG() |
121 void ChartCarbonate::savePNG() |
122 { |
122 { |
123 QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), QDir::homePath() + "/carbonation.png", tr("Image (*.png)")); |
123 QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp"); |
|
124 QString dirName; |
|
125 |
|
126 /* |
|
127 * First check if the directory stored in the settings file exists. |
|
128 * It might be on a removable media that was last used ... |
|
129 * If so, fallback to the user's home directory. |
|
130 */ |
|
131 dirName = settings.value("paths/download").toString(); |
|
132 if (! QDir(dirName).exists()) { |
|
133 dirName = QDir::homePath(); |
|
134 } |
|
135 |
|
136 QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), dirName + "/carbonation.png", tr("Image (*.png)")); |
124 if (path.isEmpty()) { |
137 if (path.isEmpty()) { |
125 QMessageBox::warning(this, tr("Save File"), tr("No image file selected.")); |
138 QMessageBox::warning(this, tr("Save File"), tr("No image file selected.")); |
126 return; |
139 return; |
127 } |
140 } |
|
141 |
|
142 /* |
|
143 * Update to current selected path |
|
144 */ |
|
145 settings.setValue("paths/download", QFileInfo(path).absolutePath()); |
128 |
146 |
129 QImage img((chartView->size()), QImage::Format_ARGB32); |
147 QImage img((chartView->size()), QImage::Format_ARGB32); |
130 QPainter painter; |
148 QPainter painter; |
131 painter.begin(&img); |
149 painter.begin(&img); |
132 chartView->render(&painter); |
150 chartView->render(&painter); |