File indexing completed on 2024-12-22 04:17:31
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "exportgraphicsdialog.h" 0014 #include "dialogdefaults.h" 0015 0016 #include "mainwindow.h" 0017 #include <QDir> 0018 #include <QPictureIO> 0019 #include <QDebug> 0020 #include <QImageWriter> 0021 #include <QTimer> 0022 #include <QFileInfo> 0023 #include <QPushButton> 0024 #include <QLineEdit> 0025 0026 namespace Kst { 0027 0028 ExportGraphicsDialog::ExportGraphicsDialog(MainWindow *parent) 0029 : QDialog(parent) { 0030 setupUi(this); 0031 0032 _saveLocation->setFile(dialogDefaults().value("export/filename",QDir::currentPath()).toString()); 0033 0034 _listVectorFormats->setChecked(dialogDefaults().value("export/useVectors",true).toBool()); 0035 _listBitmapFormats->setChecked(dialogDefaults().value("export/useBitmaps",true).toBool()); 0036 0037 updateFormats(); 0038 0039 _xSize->setValue(dialogDefaults().value("export/xsize","1024").toInt()); 0040 _ySize->setValue(dialogDefaults().value("export/ysize","768").toInt()); 0041 0042 _comboBoxSizeOption->setCurrentIndex(dialogDefaults().value("export/sizeOption","0").toInt()); 0043 enableWidthHeight(); 0044 0045 _saveLocationLabel->setBuddy(_saveLocation->_fileEdit); 0046 0047 connect(_comboBoxSizeOption, SIGNAL(currentIndexChanged(int)), this, SLOT(enableWidthHeight())); 0048 0049 connect(_buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); 0050 connect(_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(OKClicked())); 0051 connect(_buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply())); 0052 connect(_listVectorFormats, SIGNAL(clicked()), this, SLOT(updateFormats())); 0053 connect(_listBitmapFormats, SIGNAL(clicked()), this, SLOT(updateFormats())); 0054 connect(_comboBoxFormats, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilenameLabel())); 0055 connect(_saveLocation, SIGNAL(changed(QString)), this, SLOT(updateFilenameLabel())); 0056 connect(_autoExtension, SIGNAL(toggled(bool)), this, SLOT(updateFilenameLabel())); 0057 connect(_exportAll, SIGNAL(clicked(bool)), this, SLOT(updateFilenameLabel())); 0058 0059 updateFilenameLabel(); 0060 } 0061 0062 0063 ExportGraphicsDialog::~ExportGraphicsDialog() { 0064 } 0065 0066 void ExportGraphicsDialog::updateFormats() { 0067 QStringList formats;// = QPictureIO::outputFormats(); 0068 0069 if (_listBitmapFormats->isChecked()) { 0070 foreach(const QByteArray &array, QImageWriter::supportedImageFormats()) { 0071 formats.append(QString(array)); 0072 } 0073 formats.removeAll(QString("eps")); 0074 formats.removeAll(QString("EPS")); 0075 } 0076 0077 if (_listVectorFormats->isChecked()) { 0078 formats.append(QString("svg")); 0079 formats.append(QString("eps")); 0080 formats.append(QString("pdf")); 0081 } 0082 0083 0084 _comboBoxFormats->clear(); 0085 _comboBoxFormats->addItems(formats); 0086 0087 int index = _comboBoxFormats->findText(dialogDefaults().value("export/format","png").toString()); 0088 if (index<0) { 0089 if (_listBitmapFormats->isChecked()) { 0090 index = _comboBoxFormats->findText("png"); 0091 } else { 0092 index = _comboBoxFormats->findText("svg"); 0093 } 0094 } 0095 _comboBoxFormats->setCurrentIndex(index); 0096 0097 } 0098 0099 void ExportGraphicsDialog::updateFilenameLabel() { 0100 QString filename; 0101 QString format = _comboBoxFormats->currentText(); 0102 filename = _saveLocation->file(); 0103 0104 if (_autoExtension->isChecked()) { 0105 if (QFileInfo(filename).suffix().toLower() != format.toLower()) { 0106 filename += '.' + format; 0107 } 0108 } 0109 0110 if (_exportAll->isChecked()) { 0111 QFileInfo QFI(filename); 0112 filename = QFI.dir().path() + '/' + QFI.completeBaseName() + 0113 tr("_<tabname>") +'.' + 0114 QFI.suffix(); 0115 } 0116 0117 _filenameLabel->setText(tr("Exporting to ") + filename); 0118 } 0119 0120 void ExportGraphicsDialog::enableWidthHeight() { 0121 int displayOption = _comboBoxSizeOption->currentIndex(); 0122 0123 switch (displayOption) { 0124 case 0: // Width and Maintain Aspect Ratio 0125 _xSize->setEnabled(true); 0126 _ySize->setEnabled(false); 0127 _widthLabel->setEnabled(true); 0128 _heightLabel->setEnabled(false); 0129 break; 0130 case 1: // Height and Maintain Aspect Ratio 0131 _xSize->setEnabled(false); 0132 _ySize->setEnabled(true); 0133 _widthLabel->setEnabled(false); 0134 _heightLabel->setEnabled(true); 0135 break; 0136 case 2: // Width and Height 0137 _xSize->setEnabled(true); 0138 _ySize->setEnabled(true); 0139 _widthLabel->setEnabled(true); 0140 _heightLabel->setEnabled(true); 0141 break; 0142 case 3: // Size of Square 0143 _xSize->setEnabled(true); 0144 _ySize->setEnabled(false); 0145 _widthLabel->setEnabled(true); 0146 _heightLabel->setEnabled(false); 0147 break; 0148 } 0149 } 0150 0151 0152 void ExportGraphicsDialog::apply() { 0153 int autosave_period = 0; 0154 QString filename = _saveLocation->file(); 0155 QString format = _comboBoxFormats->currentText(); 0156 if (_autoExtension->isChecked()) { 0157 if (QFileInfo(filename).suffix().toLower() != format.toLower()) { 0158 filename += '.' + format; 0159 } 0160 } 0161 if (_autosave->isChecked()) { 0162 autosave_period = _period->value()*1000; 0163 } 0164 0165 dialogDefaults().setValue("export/useVectors", _listVectorFormats->isChecked()); 0166 dialogDefaults().setValue("export/useBitmaps", _listBitmapFormats->isChecked()); 0167 emit exportGraphics(filename, format, _xSize->value(), _ySize->value(), _comboBoxSizeOption->currentIndex(), exportAll(), autosave_period); 0168 } 0169 0170 0171 void ExportGraphicsDialog::updateButtons() { 0172 bool valid = QFileInfo(_saveLocation->file()).isFile(); 0173 _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid); 0174 _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(valid); 0175 } 0176 0177 0178 void ExportGraphicsDialog::OKClicked() { 0179 apply(); 0180 accept(); 0181 } 0182 0183 } 0184 0185 // vim: ts=2 sw=2 et