Commit c3ab0f36 authored by Laurent Montel's avatar Laurent Montel
Browse files

Use clang-format for cc files too

parent 91bfe713
......@@ -9,15 +9,15 @@
#include "../misc/kigfiledialog.h"
#include <QFile>
#include <QTextStream>
#include <QStandardPaths>
#include <QTextStream>
#include <KMessageBox>
#ifdef HAVE_TRUNC
#define KDE_TRUNC(a) trunc(a)
#define KDE_TRUNC(a) trunc(a)
#else
#define KDE_TRUNC(a) rint(a)
#define KDE_TRUNC(a) rint(a)
#endif
AsyExporter::~AsyExporter()
......@@ -26,117 +26,110 @@ AsyExporter::~AsyExporter()
QString AsyExporter::exportToStatement() const
{
return i18n( "Export to &Asymptote..." );
return i18n("Export to &Asymptote...");
}
QString AsyExporter::menuEntryName() const
{
return i18n( "&Asymptote..." );
return i18n("&Asymptote...");
}
QString AsyExporter::menuIcon() const
{
return QStringLiteral("text-plain");
return QStringLiteral("text-plain");
}
void AsyExporter::run( const KigPart& doc, KigWidget& w )
void AsyExporter::run(const KigPart &doc, KigWidget &w)
{
KigFileDialog* kfd = new KigFileDialog(
QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ), i18n( "Asymptote Documents (*.asy)" ),
i18n( "Export as Asymptote script" ), &w );
kfd->setOptionCaption( i18n( "Asymptote Options" ) );
AsyExporterOptions* opts = new AsyExporterOptions( nullptr );
kfd->setOptionsWidget( opts );
opts->setGrid( true );
opts->setAxes( true );
opts->setExtraFrame( false );
if ( !kfd->exec() ) {
delete kfd;
return;
}
QString file_name = kfd->selectedFile();
bool showgrid = opts->showGrid();
bool showaxes = opts->showAxes();
bool showframe = opts->showExtraFrame();
delete opts;
delete kfd;
QFile file( file_name );
if ( ! file.open( QIODevice::WriteOnly ) )
{
KMessageBox::error( &w, i18n( "The file \"%1\" could not be opened. Please "
"check if the file permissions are set correctly." ,
file_name ) );
return;
};
const double bottom = w.showingRect().bottom();
const double left = w.showingRect().left();
const double height = w.showingRect().height();
const double width = w.showingRect().width();
std::vector<ObjectHolder*> os = doc.document().objects();
QTextStream stream( &file );
AsyExporterImpVisitor visitor( stream, w );
// Start building the output stream containing the asymptote script commands
// The file header for pure asymptote
stream << "settings.outformat=\"pdf\";\n";
stream << "\n";
stream << "import math;\n";
stream << "import graph;\n";
stream << "\n";
stream << "size(" << 25*width << "," << 25*height << ");\n";
stream << "\n";
stream << "real textboxmargin = 2mm;\n";
stream << "\n";
// Grid
if ( showgrid )
{
// TODO: Polar grid
// Vertical lines
double startingpoint = static_cast<double>( KDE_TRUNC( left ) );
for ( double i = startingpoint; i < left+width; ++i )
{
stream << "draw((" << i << "," << bottom << ")--(" << i << "," << bottom+height << "),gray);\n";
KigFileDialog *kfd = new KigFileDialog(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
i18n("Asymptote Documents (*.asy)"),
i18n("Export as Asymptote script"),
&w);
kfd->setOptionCaption(i18n("Asymptote Options"));
AsyExporterOptions *opts = new AsyExporterOptions(nullptr);
kfd->setOptionsWidget(opts);
opts->setGrid(true);
opts->setAxes(true);
opts->setExtraFrame(false);
if (!kfd->exec()) {
delete kfd;
return;
}
QString file_name = kfd->selectedFile();
bool showgrid = opts->showGrid();
bool showaxes = opts->showAxes();
bool showframe = opts->showExtraFrame();
delete opts;
delete kfd;
QFile file(file_name);
if (!file.open(QIODevice::WriteOnly)) {
KMessageBox::error(&w,
i18n("The file \"%1\" could not be opened. Please "
"check if the file permissions are set correctly.",
file_name));
return;
};
const double bottom = w.showingRect().bottom();
const double left = w.showingRect().left();
const double height = w.showingRect().height();
const double width = w.showingRect().width();
std::vector<ObjectHolder *> os = doc.document().objects();
QTextStream stream(&file);
AsyExporterImpVisitor visitor(stream, w);
// Start building the output stream containing the asymptote script commands
// The file header for pure asymptote
stream << "settings.outformat=\"pdf\";\n";
stream << "\n";
stream << "import math;\n";
stream << "import graph;\n";
stream << "\n";
stream << "size(" << 25 * width << "," << 25 * height << ");\n";
stream << "\n";
stream << "real textboxmargin = 2mm;\n";
stream << "\n";
// Grid
if (showgrid) {
// TODO: Polar grid
// Vertical lines
double startingpoint = static_cast<double>(KDE_TRUNC(left));
for (double i = startingpoint; i < left + width; ++i) {
stream << "draw((" << i << "," << bottom << ")--(" << i << "," << bottom + height << "),gray);\n";
}
// Horizontal lines
startingpoint = static_cast<double>(KDE_TRUNC(bottom));
for (double i = startingpoint; i < bottom + height; ++i) {
stream << "draw((" << left << "," << i << ")--(" << left + width << "," << i << "),gray);\n";
}
}
// Horizontal lines
startingpoint = static_cast<double>( KDE_TRUNC( bottom ) );
for ( double i = startingpoint; i < bottom+height; ++i )
{
stream << "draw((" << left << "," << i << ")--(" << left+width << "," << i << "),gray);\n";
// Axes
if (showaxes) {
stream << "draw((" << left << ",0)--(" << left + width << ",0), black, Arrow);\n";
stream << "draw((0," << bottom << ")--(0," << bottom + height << "), black, Arrow);\n";
}
}
// Axes
if ( showaxes )
{
stream << "draw(("<<left<<",0)--("<<left+width<<",0), black, Arrow);\n";
stream << "draw((0,"<<bottom<<")--(0,"<<bottom+height<<"), black, Arrow);\n";
}
// Visit all the objects
for ( std::vector<ObjectHolder*>::const_iterator i = os.begin(); i != os.end(); ++i )
{
visitor.visit( *i );
}
stream << "path frame = ("<<left<<","<<bottom<<")--("
<<left<<","<<bottom+height<<")--("
<<left+width<<","<<bottom+height<<")--("
<<left+width<<","<<bottom<<")--cycle;\n";
// Extra frame
if ( showframe )
{
stream << "draw(frame, black);\n";
}
stream << "clip(frame);\n";
// And close the output file
file.close();
// Visit all the objects
for (std::vector<ObjectHolder *>::const_iterator i = os.begin(); i != os.end(); ++i) {
visitor.visit(*i);
}
stream << "path frame = (" << left << "," << bottom << ")--(" << left << "," << bottom + height << ")--(" << left + width << "," << bottom + height
<< ")--(" << left + width << "," << bottom << ")--cycle;\n";
// Extra frame
if (showframe) {
stream << "draw(frame, black);\n";
}
stream << "clip(frame);\n";
// And close the output file
file.close();
}
This diff is collapsed.
......@@ -9,46 +9,46 @@
#include <QCheckBox>
#include <QLayout>
AsyExporterOptions::AsyExporterOptions( QWidget* parent )
: QWidget( parent )
AsyExporterOptions::AsyExporterOptions(QWidget *parent)
: QWidget(parent)
{
expwidget = new Ui_AsyExporterOptionsWidget();
expwidget->setupUi( this );
expwidget = new Ui_AsyExporterOptionsWidget();
expwidget->setupUi(this);
layout()->setContentsMargins( 0, 0, 0, 0 );
layout()->setContentsMargins(0, 0, 0, 0);
}
AsyExporterOptions::~AsyExporterOptions()
{
delete expwidget;
delete expwidget;
}
void AsyExporterOptions::setGrid( bool grid )
void AsyExporterOptions::setGrid(bool grid)
{
expwidget->showGridCheckBox->setChecked( grid );
expwidget->showGridCheckBox->setChecked(grid);
}
bool AsyExporterOptions::showGrid() const
{
return expwidget->showGridCheckBox->isChecked();
return expwidget->showGridCheckBox->isChecked();
}
void AsyExporterOptions::setAxes( bool axes )
void AsyExporterOptions::setAxes(bool axes)
{
expwidget->showAxesCheckBox->setChecked( axes );
expwidget->showAxesCheckBox->setChecked(axes);
}
bool AsyExporterOptions::showAxes() const
{
return expwidget->showAxesCheckBox->isChecked();
return expwidget->showAxesCheckBox->isChecked();
}
void AsyExporterOptions::setExtraFrame( bool frame )
void AsyExporterOptions::setExtraFrame(bool frame)
{
expwidget->showFrameCheckBox->setChecked( frame );
expwidget->showFrameCheckBox->setChecked(frame);
}
bool AsyExporterOptions::showExtraFrame() const
{
return expwidget->showFrameCheckBox->isChecked();
return expwidget->showFrameCheckBox->isChecked();
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,9 +4,9 @@
#include "exporter.h"
#include "asyexporter.h"
#include "imageexporteroptions.h"
#include "latexexporter.h"
#include "asyexporter.h"
#include "svgexporter.h"
#include "xfigexporter.h"
......@@ -21,27 +21,28 @@
#include <QMimeDatabase>
#include <QStandardPaths>
#include <KIconEngine>
#include <KActionMenu>
#include <KActionCollection>
#include <KActionMenu>
#include <KIconEngine>
#include <KMessageBox>
ExporterAction::ExporterAction( const KigPart* doc, KigWidget* w,
KActionCollection* parent, KigExporter* exp )
: QAction( exp->menuEntryName(), parent),
mexp( exp ), mdoc( doc ), mw( w )
ExporterAction::ExporterAction(const KigPart *doc, KigWidget *w, KActionCollection *parent, KigExporter *exp)
: QAction(exp->menuEntryName(), parent)
, mexp(exp)
, mdoc(doc)
, mw(w)
{
QString iconstr = exp->menuIcon();
if ( !iconstr.isEmpty() )
setIcon( QIcon( new KIconEngine( iconstr, const_cast<KigPart*>( doc )->iconLoader() ) ) );
connect( this, &QAction::triggered, this, &ExporterAction::slotActivated );
if(parent)
parent->addAction(QStringLiteral("action"), this );
QString iconstr = exp->menuIcon();
if (!iconstr.isEmpty())
setIcon(QIcon(new KIconEngine(iconstr, const_cast<KigPart *>(doc)->iconLoader())));
connect(this, &QAction::triggered, this, &ExporterAction::slotActivated);
if (parent)
parent->addAction(QStringLiteral("action"), this);
}
void ExporterAction::slotActivated()
{
mexp->run( *mdoc, *mw );
mexp->run(*mdoc, *mw);
}
KigExporter::~KigExporter()
......@@ -54,110 +55,102 @@ ImageExporter::~ImageExporter()
QString ImageExporter::exportToStatement() const
{
return i18n( "&Export to image" );
return i18n("&Export to image");
}
QString ImageExporter::menuEntryName() const
{
return i18n( "&Image..." );
return i18n("&Image...");
}
QString ImageExporter::menuIcon() const
{
return QStringLiteral("image-x-generic");
return QStringLiteral("image-x-generic");
}
void ImageExporter::run( const KigPart& doc, KigWidget& w )
void ImageExporter::run(const KigPart &doc, KigWidget &w)
{
KigFileDialog* kfd = new KigFileDialog(
QStandardPaths::writableLocation( QStandardPaths::PicturesLocation ), QString(),
i18n( "Export as Image" ), &w );
const QList<QByteArray> mimeFilters = QImageWriter::supportedMimeTypes();
QStringList mimeFiltersConverted;
// Since someone didn't get the memo about what's the type of a mime name...
for (const auto &mimeFilter : mimeFilters) {
mimeFiltersConverted.append( QString::fromUtf8( mimeFilter ) );
}
kfd->setMimeTypeFilters( mimeFiltersConverted );
kfd->setOptionCaption( i18n( "Image Options" ) );
ImageExporterOptions* opts = new ImageExporterOptions( nullptr );
kfd->setOptionsWidget( opts );
opts->setImageSize( w.size() );
opts->setGrid( doc.document().grid() );
opts->setAxes( doc.document().axes() );
if ( !kfd->exec() )
return;
QString filename = kfd->selectedFile();
bool showgrid = opts->showGrid();
bool showaxes = opts->showAxes();
QSize imgsize = opts->imageSize();
delete opts;
delete kfd;
QMimeDatabase db;
QMimeType mimeType = db.mimeTypeForFile( filename );
qDebug() << "mimetype: " << mimeType.name();
if ( !QImageWriter::supportedMimeTypes().contains( mimeType.name().toUtf8() ) )
{
KMessageBox::error( &w, i18n( "Sorry, this file format is not supported." ) );
return;
};
QFile file( filename );
if ( ! file.open( QIODevice::WriteOnly ) )
{
KMessageBox::error( &w,
i18n( "The file \"%1\" could not be opened. Please check if the file permissions are set correctly." ,
filename ) );
return;
};
QPixmap img( imgsize );
img.fill( Qt::white );
KigPainter p( ScreenInfo( w.screenInfo().shownRect(), img.rect() ), &img, doc.document() );
p.setWholeWinOverlay();
p.drawGrid( doc.document().coordinateSystem(), showgrid, showaxes );
// FIXME: show the selections ?
p.drawObjects( doc.document().objects(), false );
const QStringList types = mimeType.suffixes();
if ( types.isEmpty() ) return; // TODO error dialog?
if ( !img.save( filename, types.at(0).toLatin1() ) )
{
KMessageBox::error( &w, i18n( "Sorry, something went wrong while saving to image \"%1\"", filename ) );
}
KigFileDialog *kfd = new KigFileDialog(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation), QString(), i18n("Export as Image"), &w);
const QList<QByteArray> mimeFilters = QImageWriter::supportedMimeTypes();
QStringList mimeFiltersConverted;
// Since someone didn't get the memo about what's the type of a mime name...
for (const auto &mimeFilter : mimeFilters) {
mimeFiltersConverted.append(QString::fromUtf8(mimeFilter));
}
kfd->setMimeTypeFilters(mimeFiltersConverted);
kfd->setOptionCaption(i18n("Image Options"));
ImageExporterOptions *opts = new ImageExporterOptions(nullptr);
kfd->setOptionsWidget(opts);
opts->setImageSize(w.size());
opts->setGrid(doc.document().grid());
opts->setAxes(doc.document().axes());
if (!kfd->exec())
return;
QString filename = kfd->selectedFile();
bool showgrid = opts->showGrid();
bool showaxes = opts->showAxes();
QSize imgsize = opts->imageSize();
delete opts;
delete kfd;
QMimeDatabase db;
QMimeType mimeType = db.mimeTypeForFile(filename);
qDebug() << "mimetype: " << mimeType.name();
if (!QImageWriter::supportedMimeTypes().contains(mimeType.name().toUtf8())) {
KMessageBox::error(&w, i18n("Sorry, this file format is not supported."));
return;
};
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
KMessageBox::error(&w, i18n("The file \"%1\" could not be opened. Please check if the file permissions are set correctly.", filename));
return;
};
QPixmap img(imgsize);
img.fill(Qt::white);
KigPainter p(ScreenInfo(w.screenInfo().shownRect(), img.rect()), &img, doc.document());
p.setWholeWinOverlay();
p.drawGrid(doc.document().coordinateSystem(), showgrid, showaxes);
// FIXME: show the selections ?
p.drawObjects(doc.document().objects(), false);
const QStringList types = mimeType.suffixes();
if (types.isEmpty())
return; // TODO error dialog?
if (!img.save(filename, types.at(0).toLatin1())) {
KMessageBox::error(&w, i18n("Sorry, something went wrong while saving to image \"%1\"", filename));
}
}
KigExportManager::KigExportManager()
{
mexporters.push_back( new ImageExporter );
mexporters.push_back( new XFigExporter );
mexporters.push_back( new LatexExporter );
mexporters.push_back( new AsyExporter );
mexporters.push_back( new SVGExporter );
mexporters.push_back(new ImageExporter);
mexporters.push_back(new XFigExporter);
mexporters.push_back(new LatexExporter);
mexporters.push_back(new AsyExporter);
mexporters.push_back(new SVGExporter);
}
KigExportManager::~KigExportManager()
{
for ( uint i = 0; i < mexporters.size(); ++i )
delete mexporters[i];
for (uint i = 0; i < mexporters.size(); ++i)
delete mexporters[i];
}
void KigExportManager::addMenuAction( const KigPart* doc, KigWidget* w,
KActionCollection* coll )
void KigExportManager::addMenuAction(const KigPart *doc, KigWidget *w, KActionCollection *coll)
{
KActionMenu* m = new KActionMenu( i18n( "&Export To" ), w );
m->setIcon( QIcon( new KIconEngine( "document-export", const_cast<KigPart*>( doc )->iconLoader() ) ) );
for ( uint i = 0; i < mexporters.size(); ++i )
m->addAction( new ExporterAction( doc, w, coll, mexporters[i] ) );
if(coll)
coll->addAction(QStringLiteral("file_export"), m );
KActionMenu *m = new KActionMenu(i18n("&Export To"), w);
m->setIcon(QIcon(new KIconEngine("document-export", const_cast<KigPart *>(doc)->iconLoader())));
for (uint i = 0; i < mexporters.size(); ++i)
m->addAction(new ExporterAction(doc, w, coll, mexporters[i]));
if (coll)
coll->addAction(QStringLiteral("file_export"), m);
}
KigExportManager* KigExportManager::instance()
KigExportManager *KigExportManager::instance()
{
static KigExportManager m;
return &m;
static KigExportManager m;
return &m;
}
......@@ -7,44 +7,44 @@
#include "filter.h"
#include "kgeo-filter.h"
#include "cabri-filter.h"
#include "native-filter.h"
#include "kseg-filter.h"
#include "drgeo-filter.h"
#include "kgeo-filter.h"
#include "kseg-filter.h"
#include "native-filter.h"
#ifdef WITH_GEOGEBRA
#include "geogebra-filter.h"
#endif //WITH_GEOGEBRA
#endif // WITH_GEOGEBRA
#include <KLocalizedString>
#include <KMessageBox>
KigFilters* KigFilters::sThis;
KigFilters *KigFilters::sThis;
KigFilter* KigFilters::find(const QString& mime)
KigFilter *KigFilters::find(const QString &mime)
{
for (vect::iterator i = mFilters.begin(); i != mFilters.end(); ++i)
{
if ((*i)->supportMime(mime)) return *i;
for (vect::iterator i = mFilters.begin(); i != mFilters.end(); ++i) {
if ((*i)->supportMime(mime))
return *i;
};
return nullptr;
return nullptr;
}
KigFilters::KigFilters()
{
mFilters.push_back( KigFilterKGeo::instance() );
mFilters.push_back( KigFilterKSeg::instance() );
mFilters.push_back( KigFilterCabri::instance() );
mFilters.push_back( KigFilterNative::instance() );
mFilters.push_back( KigFilterDrgeo::instance() );
mFilters.push_back(KigFilterKGeo::instance());
mFilters.push_back(KigFilterKSeg::instance());
mFilters.push_back(KigFilterCabri::instance());
mFilters.push_back(KigFilterNative::instance());
mFilters.push_back(KigFilterDrgeo::instance());
#ifdef WITH_GEOGEBRA
mFilters.push_back( KigFilterGeogebra::instance() );
#endif //WITH_GEOGEBRA
mFilters.push_back(KigFilterGeogebra::instance());
#endif // WITH_GEOGEBRA
}
KigFilters* KigFilters::instance()
KigFilters *KigFilters::instance()
{
return sThis ? sThis : ( sThis = new KigFilters() );
return sThis ? sThis : (sThis = new KigFilters());