exporthtmldialog.cpp
author insilmaril
Mon, 15 Mar 2010 11:49:42 +0000
changeset 835 31841b366d5e
parent 829 832e96c9abb6
permissions -rw-r--r--
Fixes for autoLayout (later)
insilmaril@824
     1
#include "exporthtmldialog.h"
insilmaril@824
     2
insilmaril@824
     3
#include <QFileDialog>
insilmaril@824
     4
#include <QMessageBox>
insilmaril@824
     5
#include <QTextStream>
insilmaril@824
     6
insilmaril@824
     7
#include "options.h"
insilmaril@824
     8
#include "settings.h"
insilmaril@824
     9
#include "warningdialog.h"
insilmaril@824
    10
insilmaril@824
    11
insilmaril@824
    12
extern Options options;
insilmaril@824
    13
extern QDir vymBaseDir;
insilmaril@824
    14
extern Settings settings;
insilmaril@824
    15
extern bool debug;
insilmaril@824
    16
insilmaril@824
    17
ExportHTMLDialog::ExportHTMLDialog(QWidget* parent) : QDialog(parent)
insilmaril@824
    18
{
insilmaril@824
    19
    ui.setupUi(this);
insilmaril@824
    20
insilmaril@824
    21
	filepath="";
insilmaril@824
    22
	settingsChanged=false;
insilmaril@824
    23
insilmaril@824
    24
    // signals and slots connections
insilmaril@824
    25
    connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
insilmaril@824
    26
    connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
insilmaril@824
    27
    connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
insilmaril@824
    28
    connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
insilmaril@824
    29
    connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
insilmaril@824
    30
    connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
insilmaril@824
    31
    connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
insilmaril@824
    32
    connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
insilmaril@824
    33
    connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
insilmaril@824
    34
    connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
insilmaril@824
    35
}	
insilmaril@824
    36
insilmaril@824
    37
insilmaril@824
    38
void ExportHTMLDialog::readSettings()
insilmaril@824
    39
{
insilmaril@824
    40
insilmaril@824
    41
	dir=settings.readLocalEntry (filepath,"/export/html/exportDir",vymBaseDir.currentDirPath() );
insilmaril@824
    42
	ui.lineEditDir->setText(dir);
insilmaril@824
    43
	
insilmaril@824
    44
    if ( settings.readLocalEntry (filepath,"/export/html/useImage","yes")=="yes")
insilmaril@824
    45
		useImage=true;
insilmaril@824
    46
	else	
insilmaril@824
    47
		useImage=false;
insilmaril@824
    48
	ui.imageButton->setChecked(useImage);
insilmaril@824
    49
		
insilmaril@824
    50
	if ( settings.readLocalEntry (filepath,"/export/html/useTextColor","no")=="yes")
insilmaril@824
    51
		useTextColor=true;
insilmaril@824
    52
	else	
insilmaril@824
    53
		useTextColor=false;
insilmaril@824
    54
	ui.textColorButton->setChecked(useTextColor);
insilmaril@824
    55
	
insilmaril@824
    56
/* TODO this was used in old html export, is not yet in new stylesheet
insilmaril@824
    57
	if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
insilmaril@824
    58
		useHeading=true;
insilmaril@824
    59
	else	
insilmaril@824
    60
		useHeading=false;
insilmaril@824
    61
	checkBox4_2->setChecked(useHeading);
insilmaril@824
    62
*/		
insilmaril@824
    63
insilmaril@824
    64
	if ( settings.readLocalEntry (filepath,"/export/html/saveSettingsInMap","no")=="yes")
insilmaril@824
    65
		saveSettingsInMap=true;
insilmaril@824
    66
	else	
insilmaril@824
    67
		saveSettingsInMap=false;
insilmaril@824
    68
	ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
insilmaril@824
    69
insilmaril@824
    70
	if ( settings.readEntry ("/export/html/showOutput","no")=="yes")
insilmaril@824
    71
		showOutput=true;
insilmaril@824
    72
	else	
insilmaril@824
    73
		showOutput=false;
insilmaril@824
    74
	ui.outputButton->setChecked(showOutput);
insilmaril@824
    75
insilmaril@824
    76
	// For testing better use local styles
insilmaril@824
    77
    const QString defcss(vymBaseDir.path() + "/styles/vym.css");
insilmaril@824
    78
	if (options.isOn ("local"))
insilmaril@824
    79
	{
insilmaril@824
    80
		css=defcss;
insilmaril@824
    81
	} else
insilmaril@824
    82
	{
insilmaril@824
    83
		css=settings.readLocalEntry 
insilmaril@824
    84
			(filepath,"/export/html/css",defcss);	
insilmaril@824
    85
	}
insilmaril@824
    86
	ui.lineEditCSS->setText(css);
insilmaril@824
    87
	
insilmaril@824
    88
	postscript=settings.readLocalEntry
insilmaril@824
    89
		(filepath,"/export/html/postscript","");
insilmaril@824
    90
	ui.lineEditPostScript->setText (postscript);	
insilmaril@824
    91
insilmaril@825
    92
	if (!postscript.isEmpty())
insilmaril@824
    93
	{
insilmaril@824
    94
		QMessageBox::warning( 0, tr( "Warning" ),tr(
insilmaril@824
    95
		"The settings saved in the map "
insilmaril@825
    96
		"would like to run script:\n\n"
insilmaril@824
    97
		"%1\n\n"
insilmaril@824
    98
		"Please check, if you really\n"
insilmaril@825
    99
		"want to allow this in your system!").arg(postscript));
insilmaril@824
   100
		
insilmaril@824
   101
	}
insilmaril@824
   102
}
insilmaril@824
   103
insilmaril@824
   104
void ExportHTMLDialog::setDir(const QString &d)
insilmaril@824
   105
{
insilmaril@824
   106
	dir=d;
insilmaril@824
   107
	if (dir.right(1)!="/") dir+="/";
insilmaril@824
   108
}
insilmaril@824
   109
insilmaril@824
   110
void ExportHTMLDialog::dirChanged()
insilmaril@824
   111
{
insilmaril@824
   112
	setDir (ui.lineEditDir->text());
insilmaril@824
   113
	settingsChanged=true;
insilmaril@824
   114
}
insilmaril@824
   115
insilmaril@824
   116
void ExportHTMLDialog::browseDirectoryPressed()
insilmaril@824
   117
{
insilmaril@824
   118
   	QFileDialog fd( this);
insilmaril@824
   119
	fd.setMode (QFileDialog::DirectoryOnly);
insilmaril@824
   120
	fd.setCaption(tr("VYM - Export HTML to directory"));
insilmaril@824
   121
	fd.setModal (true);
insilmaril@824
   122
	fd.setDirectory (QDir::current());
insilmaril@824
   123
	fd.show();
insilmaril@824
   124
insilmaril@824
   125
	if ( fd.exec() == QDialog::Accepted )
insilmaril@824
   126
	{
insilmaril@824
   127
		QDir dir=fd.selectedFile();
insilmaril@824
   128
		ui.lineEditDir->setText (dir.path() );
insilmaril@824
   129
		settingsChanged=true;
insilmaril@824
   130
	}
insilmaril@824
   131
}
insilmaril@824
   132
insilmaril@824
   133
void ExportHTMLDialog::imageButtonPressed(bool b)
insilmaril@824
   134
{
insilmaril@824
   135
	useImage=b;
insilmaril@824
   136
	settingsChanged=true;
insilmaril@824
   137
}
insilmaril@824
   138
insilmaril@824
   139
void ExportHTMLDialog::textcolorButtonPressed(bool b)
insilmaril@824
   140
{
insilmaril@824
   141
	useTextColor=b;	
insilmaril@824
   142
	settingsChanged=true;
insilmaril@824
   143
}
insilmaril@824
   144
insilmaril@824
   145
void ExportHTMLDialog::saveSettingsInMapButtonPressed(bool b)
insilmaril@824
   146
{
insilmaril@824
   147
	saveSettingsInMap=b;	
insilmaril@824
   148
	settingsChanged=true;
insilmaril@824
   149
}
insilmaril@824
   150
insilmaril@824
   151
void ExportHTMLDialog::warningsButtonPressed(bool b)
insilmaril@824
   152
{
insilmaril@824
   153
	showWarnings=b;
insilmaril@824
   154
	settingsChanged=true;
insilmaril@824
   155
}
insilmaril@824
   156
insilmaril@824
   157
insilmaril@824
   158
void ExportHTMLDialog::outputButtonPressed(bool b)
insilmaril@824
   159
{
insilmaril@824
   160
	showOutput=b;
insilmaril@824
   161
	settingsChanged=true;
insilmaril@824
   162
}
insilmaril@824
   163
insilmaril@824
   164
void ExportHTMLDialog::cssChanged()
insilmaril@824
   165
{
insilmaril@824
   166
	css=ui.lineEditCSS->text();
insilmaril@824
   167
	settingsChanged=true;
insilmaril@824
   168
}
insilmaril@824
   169
insilmaril@824
   170
QString ExportHTMLDialog::getCSSPath()
insilmaril@824
   171
{
insilmaril@824
   172
	return css;
insilmaril@824
   173
}
insilmaril@824
   174
insilmaril@824
   175
void ExportHTMLDialog::browseCSSPressed()
insilmaril@824
   176
{
insilmaril@824
   177
   	QFileDialog fd( this);
insilmaril@824
   178
	fd.setModal (true);
insilmaril@824
   179
	fd.setFilter ("Cascading Stylesheet (*.css)");
insilmaril@824
   180
	fd.setDirectory (QDir::current());
insilmaril@824
   181
	fd.show();
insilmaril@824
   182
insilmaril@824
   183
	if ( fd.exec() == QDialog::Accepted )
insilmaril@824
   184
	{
insilmaril@824
   185
		css=fd.selectedFile();
insilmaril@824
   186
		ui.lineEditCSS->setText (css );
insilmaril@824
   187
		settingsChanged=true;
insilmaril@824
   188
	}
insilmaril@824
   189
}
insilmaril@824
   190
insilmaril@824
   191
void ExportHTMLDialog::postscriptChanged()
insilmaril@824
   192
{
insilmaril@824
   193
	postscript=ui.lineEditPostScript->text();
insilmaril@824
   194
	settingsChanged=true;
insilmaril@824
   195
}
insilmaril@824
   196
insilmaril@824
   197
void ExportHTMLDialog::browsePostExportButtonPressed()
insilmaril@824
   198
{
insilmaril@824
   199
	QFileDialog fd( this);
insilmaril@824
   200
	fd.setModal (true);
insilmaril@824
   201
	fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
insilmaril@824
   202
	fd.setDirectory (QDir::current());
insilmaril@824
   203
	fd.show();
insilmaril@824
   204
insilmaril@824
   205
	if ( fd.exec() == QDialog::Accepted )
insilmaril@824
   206
	{
insilmaril@824
   207
		postscript=fd.selectedFile();
insilmaril@824
   208
		ui.lineEditPostScript->setText (postscript );
insilmaril@824
   209
		settingsChanged=true;
insilmaril@824
   210
	}
insilmaril@824
   211
}
insilmaril@824
   212
insilmaril@824
   213
insilmaril@825
   214
void ExportHTMLDialog::saveSettings ()
insilmaril@824
   215
{
insilmaril@824
   216
insilmaril@824
   217
	// Save options to settings file 
insilmaril@824
   218
	// (but don't save at destructor, which
insilmaril@824
   219
	// is called for "cancel", too)
insilmaril@824
   220
	settings.setLocalEntry (filepath,"/export/html/exportDir",dir);
insilmaril@824
   221
	settings.setLocalEntry (filepath,"/export/html/postscript",postscript);
insilmaril@824
   222
insilmaril@824
   223
    if (useImage)
insilmaril@824
   224
		settings.setLocalEntry (filepath,"/export/html/useImage","yes");
insilmaril@824
   225
    else
insilmaril@824
   226
		settings.setLocalEntry (filepath,"/export/html/useImage","no");	
insilmaril@824
   227
	
insilmaril@824
   228
  if (useTextColor)
insilmaril@824
   229
		settings.setLocalEntry (filepath,"/export/html/useTextColor","yes");
insilmaril@824
   230
    else
insilmaril@824
   231
		settings.setLocalEntry (filepath,"/export/html/useTextColor","no");	
insilmaril@824
   232
	
insilmaril@824
   233
   if (showWarnings)
insilmaril@824
   234
		settings.writeEntry ("/export/html/showWarnings","yes");
insilmaril@824
   235
    else
insilmaril@824
   236
		settings.writeEntry ("/export/html/showWarnings","no");	
insilmaril@824
   237
			
insilmaril@824
   238
	if (showOutput)
insilmaril@824
   239
		settings.writeEntry ("/export/html/showOutput","yes");
insilmaril@824
   240
	else
insilmaril@824
   241
		settings.writeEntry ("/export/html/showOutput","no");	
insilmaril@824
   242
insilmaril@824
   243
	QString ipath;	
insilmaril@824
   244
	ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
insilmaril@824
   245
	if (!options.isOn ("local"))
insilmaril@824
   246
	{
insilmaril@824
   247
		settings.setLocalEntry 
insilmaril@824
   248
			(filepath,"/export/html/css",css);	
insilmaril@824
   249
	}
insilmaril@824
   250
insilmaril@824
   251
	if (!saveSettingsInMap)
insilmaril@824
   252
		settings.clearLocal("/export/html");
insilmaril@824
   253
	else	
insilmaril@824
   254
		settings.setLocalEntry 
insilmaril@824
   255
			(filepath,"/export/html/saveSettingsInMap","yes");
insilmaril@824
   256
insilmaril@829
   257
	// Provide a smaller URL-icon to improve Layout //FIXME-2 add option to choose this
insilmaril@824
   258
	QPixmap pm;
insilmaril@824
   259
	if (!pm.load(ipath,"PNG") )
insilmaril@824
   260
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
insilmaril@824
   261
		
insilmaril@824
   262
		
insilmaril@824
   263
	if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
insilmaril@824
   264
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
insilmaril@824
   265
insilmaril@824
   266
}
insilmaril@824
   267
insilmaril@824
   268
void ExportHTMLDialog::setFilePath(const QString &s)
insilmaril@824
   269
{
insilmaril@824
   270
	filepath=s;
insilmaril@824
   271
}
insilmaril@824
   272
insilmaril@824
   273
void ExportHTMLDialog::setMapName(const QString &s)
insilmaril@824
   274
{
insilmaril@824
   275
	mapname=s;
insilmaril@824
   276
}
insilmaril@824
   277
insilmaril@824
   278
QString ExportHTMLDialog::getDir()
insilmaril@824
   279
{
insilmaril@824
   280
	return dir;
insilmaril@824
   281
}
insilmaril@824
   282
insilmaril@824
   283
bool ExportHTMLDialog::warnings()
insilmaril@824
   284
{
insilmaril@824
   285
	return showWarnings;
insilmaril@824
   286
}
insilmaril@824
   287
insilmaril@824
   288
bool ExportHTMLDialog::hasChanged()
insilmaril@824
   289
{
insilmaril@824
   290
	return settingsChanged;
insilmaril@824
   291
}
insilmaril@824
   292
insilmaril@824
   293