Drawing: Apply clang format

This commit is contained in:
wmayer
2023-09-10 12:33:49 +02:00
committed by wwmayer
parent ebcd846d09
commit 789912d745
52 changed files with 2650 additions and 2106 deletions

View File

@@ -22,27 +22,27 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cmath>
#include <cmath>
# include <QAction>
# include <QApplication>
# include <QContextMenuEvent>
# include <QFileInfo>
# include <QFileDialog>
# include <QGLWidget>
# include <QGraphicsRectItem>
# include <QGraphicsSvgItem>
# include <QGridLayout>
# include <QGroupBox>
# include <QListWidget>
# include <QMenu>
# include <QMessageBox>
# include <QPainter>
# include <QPaintEvent>
# include <QPrinter>
# include <QPrintDialog>
# include <QPrintPreviewDialog>
# include <QWheelEvent>
#include <QAction>
#include <QApplication>
#include <QContextMenuEvent>
#include <QFileDialog>
#include <QFileInfo>
#include <QGLWidget>
#include <QGraphicsRectItem>
#include <QGraphicsSvgItem>
#include <QGridLayout>
#include <QGroupBox>
#include <QListWidget>
#include <QMenu>
#include <QMessageBox>
#include <QPaintEvent>
#include <QPainter>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include <QPrinter>
#include <QWheelEvent>
#endif
@@ -59,7 +59,7 @@
using namespace DrawingGui;
SvgView::SvgView(QWidget *parent)
SvgView::SvgView(QWidget* parent)
: QGraphicsView(parent)
, m_renderer(Native)
, m_svgItem(nullptr)
@@ -83,7 +83,7 @@ SvgView::SvgView(QWidget *parent)
setBackgroundBrush(tilePixmap);
}
void SvgView::drawBackground(QPainter *p, const QRectF &)
void SvgView::drawBackground(QPainter* p, const QRectF&)
{
p->save();
p->resetTransform();
@@ -91,12 +91,13 @@ void SvgView::drawBackground(QPainter *p, const QRectF &)
p->restore();
}
void SvgView::openFile(const QFile &file)
void SvgView::openFile(const QFile& file)
{
if (!file.exists())
if (!file.exists()) {
return;
}
QGraphicsScene *s = scene();
QGraphicsScene* s = scene();
bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : true);
bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : false);
@@ -140,7 +141,8 @@ void SvgView::setRenderer(RendererType type)
#ifndef QT_NO_OPENGL
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
#endif
} else {
}
else {
setViewport(new QWidget);
}
}
@@ -156,21 +158,23 @@ void SvgView::setHighQualityAntialiasing(bool highQualityAntialiasing)
void SvgView::setViewBackground(bool enable)
{
if (!m_backgroundItem)
if (!m_backgroundItem) {
return;
}
m_backgroundItem->setVisible(enable);
}
void SvgView::setViewOutline(bool enable)
{
if (!m_outlineItem)
if (!m_outlineItem) {
return;
}
m_outlineItem->setVisible(enable);
}
void SvgView::paintEvent(QPaintEvent *event)
void SvgView::paintEvent(QPaintEvent* event)
{
if (m_renderer == Image) {
if (m_image.size() != viewport()->size()) {
@@ -183,17 +187,18 @@ void SvgView::paintEvent(QPaintEvent *event)
QPainter p(viewport());
p.drawImage(0, 0, m_image);
} else {
}
else {
QGraphicsView::paintEvent(event);
}
}
void SvgView::wheelEvent(QWheelEvent *event)
void SvgView::wheelEvent(QWheelEvent* event)
{
int delta = -event->angleDelta().y();
if (m_invertZoom)
if (m_invertZoom) {
delta = -delta;
}
qreal factor = std::pow(1.2, delta / 240.0);
scale(factor, factor);
event->accept();
@@ -204,7 +209,8 @@ void SvgView::wheelEvent(QWheelEvent *event)
/* TRANSLATOR DrawingGui::DrawingView */
DrawingView::DrawingView(Gui::Document* doc, QWidget* parent)
: Gui::MDIView(doc, parent), m_view(new SvgView)
: Gui::MDIView(doc, parent)
, m_view(new SvgView)
{
m_backgroundAction = new QAction(tr("&Background"), this);
m_backgroundAction->setEnabled(false);
@@ -233,41 +239,42 @@ DrawingView::DrawingView(Gui::Document* doc, QWidget* parent)
m_highQualityAntialiasingAction->setEnabled(false);
m_highQualityAntialiasingAction->setCheckable(true);
m_highQualityAntialiasingAction->setChecked(false);
connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)),
m_view, SLOT(setHighQualityAntialiasing(bool)));
connect(m_highQualityAntialiasingAction,
SIGNAL(toggled(bool)),
m_view,
SLOT(setHighQualityAntialiasing(bool)));
#endif
QActionGroup *rendererGroup = new QActionGroup(this);
QActionGroup* rendererGroup = new QActionGroup(this);
rendererGroup->addAction(m_nativeAction);
#ifndef QT_NO_OPENGL
rendererGroup->addAction(m_glAction);
#endif
rendererGroup->addAction(m_imageAction);
connect(rendererGroup, SIGNAL(triggered(QAction *)),
this, SLOT(setRenderer(QAction *)));
connect(rendererGroup, SIGNAL(triggered(QAction*)), this, SLOT(setRenderer(QAction*)));
setCentralWidget(m_view);
//setWindowTitle(tr("SVG Viewer"));
// setWindowTitle(tr("SVG Viewer"));
m_orientation = QPageLayout::Landscape;
m_pageSize = QPageSize::A4;
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");
ParameterGrp::handle hGrp =
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
bool on = hGrp->GetBool("InvertZoom", true);
m_view->setZoomInverted(on);
}
DrawingView::~DrawingView()
{
}
{}
void DrawingView::load (const QString & fileName)
void DrawingView::load(const QString& fileName)
{
if (!fileName.isEmpty()) {
QFile file(fileName);
if (!file.exists()) {
QMessageBox::critical(this, tr("Open SVG File"),
tr("Could not open file '%1'.").arg(fileName));
QMessageBox::critical(this,
tr("Open SVG File"),
tr("Could not open file '%1'.").arg(fileName));
m_outlineAction->setEnabled(false);
m_backgroundAction->setEnabled(false);
@@ -278,7 +285,7 @@ void DrawingView::load (const QString & fileName)
if (!fileName.startsWith(QLatin1String(":/"))) {
m_currentPath = fileName;
//setWindowTitle(tr("%1 - SVG Viewer").arg(m_currentPath));
// setWindowTitle(tr("%1 - SVG Viewer").arg(m_currentPath));
}
m_outlineAction->setEnabled(true);
@@ -318,7 +325,9 @@ void DrawingView::findPrinterSettings(const QString& fileName)
pageSizes[QPageSize::B7] = QString::fromLatin1("B7");
pageSizes[QPageSize::B8] = QString::fromLatin1("B8");
pageSizes[QPageSize::B9] = QString::fromLatin1("B9");
for (QMap<QPageSize::PageSizeId, QString>::iterator it = pageSizes.begin(); it != pageSizes.end(); ++it) {
for (QMap<QPageSize::PageSizeId, QString>::iterator it = pageSizes.begin();
it != pageSizes.end();
++it) {
if (fileName.startsWith(it.value(), Qt::CaseInsensitive)) {
m_pageSize = it.key();
break;
@@ -334,8 +343,9 @@ void DrawingView::setDocumentObject(const std::string& name)
void DrawingView::closeEvent(QCloseEvent* ev)
{
MDIView::closeEvent(ev);
if (!ev->isAccepted())
if (!ev->isAccepted()) {
return;
}
// when closing the view from GUI notify the view provider to mark it invisible
if (_pcDocument && !m_objectName.empty()) {
@@ -343,13 +353,14 @@ void DrawingView::closeEvent(QCloseEvent* ev)
if (doc) {
App::DocumentObject* obj = doc->getObject(m_objectName.c_str());
Gui::ViewProvider* vp = _pcDocument->getViewProvider(obj);
if (vp)
if (vp) {
vp->hide();
}
}
}
}
void DrawingView::contextMenuEvent(QContextMenuEvent *event)
void DrawingView::contextMenuEvent(QContextMenuEvent* event)
{
QMenu menu;
menu.addAction(this->m_backgroundAction);
@@ -363,14 +374,15 @@ void DrawingView::contextMenuEvent(QContextMenuEvent *event)
menu.exec(event->globalPos());
}
void DrawingView::setRenderer(QAction *action)
void DrawingView::setRenderer(QAction* action)
{
#ifndef QT_NO_OPENGL
m_highQualityAntialiasingAction->setEnabled(false);
#endif
if (action == m_nativeAction)
if (action == m_nativeAction) {
m_view->setRenderer(SvgView::Native);
}
#ifndef QT_NO_OPENGL
else if (action == m_glAction) {
m_highQualityAntialiasingAction->setEnabled(true);
@@ -382,35 +394,35 @@ void DrawingView::setRenderer(QAction *action)
}
}
bool DrawingView::onMsg(const char* pMsg, const char** )
bool DrawingView::onMsg(const char* pMsg, const char**)
{
if (strcmp("ViewFit",pMsg) == 0) {
if (strcmp("ViewFit", pMsg) == 0) {
viewAll();
return true;
}
else if (strcmp("Save",pMsg) == 0) {
Gui::Document *doc = getGuiDocument();
else if (strcmp("Save", pMsg) == 0) {
Gui::Document* doc = getGuiDocument();
if (doc) {
doc->save();
return true;
}
}
else if (strcmp("SaveAs",pMsg) == 0) {
Gui::Document *doc = getGuiDocument();
else if (strcmp("SaveAs", pMsg) == 0) {
Gui::Document* doc = getGuiDocument();
if (doc) {
doc->saveAs();
return true;
}
}
else if(strcmp("Undo",pMsg) == 0 ) {
Gui::Document *doc = getGuiDocument();
else if (strcmp("Undo", pMsg) == 0) {
Gui::Document* doc = getGuiDocument();
if (doc) {
doc->undo(1);
return true;
}
}
else if(strcmp("Redo",pMsg) == 0 ) {
Gui::Document *doc = getGuiDocument();
else if (strcmp("Redo", pMsg) == 0) {
Gui::Document* doc = getGuiDocument();
if (doc) {
doc->redo(1);
return true;
@@ -421,35 +433,41 @@ bool DrawingView::onMsg(const char* pMsg, const char** )
bool DrawingView::onHasMsg(const char* pMsg) const
{
if (strcmp("ViewFit",pMsg) == 0)
if (strcmp("ViewFit", pMsg) == 0) {
return true;
else if (strcmp("Save",pMsg) == 0)
}
else if (strcmp("Save", pMsg) == 0) {
return getGuiDocument() != nullptr;
else if (strcmp("SaveAs",pMsg) == 0)
}
else if (strcmp("SaveAs", pMsg) == 0) {
return getGuiDocument() != nullptr;
else if (strcmp("Undo",pMsg) == 0) {
}
else if (strcmp("Undo", pMsg) == 0) {
App::Document* doc = getAppDocument();
return doc && doc->getAvailableUndos() > 0;
}
else if (strcmp("Redo",pMsg) == 0) {
else if (strcmp("Redo", pMsg) == 0) {
App::Document* doc = getAppDocument();
return doc && doc->getAvailableRedos() > 0;
}
else if (strcmp("Print",pMsg) == 0)
else if (strcmp("Print", pMsg) == 0) {
return true;
else if (strcmp("PrintPreview",pMsg) == 0)
}
else if (strcmp("PrintPreview", pMsg) == 0) {
return true;
else if (strcmp("PrintPdf",pMsg) == 0)
}
else if (strcmp("PrintPdf", pMsg) == 0) {
return true;
}
return false;
}
void DrawingView::onRelabel(Gui::Document *pDoc)
void DrawingView::onRelabel(Gui::Document* pDoc)
{
if (!bIsPassive && pDoc) {
QString cap = QString::fromLatin1("%1 : %2[*]")
.arg(QString::fromUtf8(pDoc->getDocument()->Label.getValue()),
objectName());
QString cap =
QString::fromLatin1("%1 : %2[*]")
.arg(QString::fromUtf8(pDoc->getDocument()->Label.getValue()), objectName());
setWindowTitle(cap);
}
}
@@ -462,12 +480,12 @@ void DrawingView::printPdf()
dlg.setWindowTitle(tr("Export PDF"));
dlg.setNameFilters(QStringList() << QString::fromLatin1("%1 (*.pdf)").arg(tr("PDF file")));
QGridLayout *gridLayout;
QGridLayout *formLayout;
QGroupBox *groupBox;
QListWidget *listWidget;
QGridLayout* gridLayout;
QGridLayout* formLayout;
QGroupBox* groupBox;
QListWidget* listWidget;
QListWidgetItem* item;
QWidget *form = new QWidget(&dlg);
QWidget* form = new QWidget(&dlg);
form->resize(40, 300);
formLayout = new QGridLayout(form);
groupBox = new QGroupBox(form);
@@ -489,8 +507,8 @@ void DrawingView::printPdf()
item->setData(Qt::UserRole, QVariant(QPageSize::A4));
item = new QListWidgetItem(tr("A5"), listWidget);
item->setData(Qt::UserRole, QVariant(QPageSize::A5));
int index = 4; // by default A4
for (int i=0; i<listWidget->count(); i++) {
int index = 4;// by default A4
for (int i = 0; i < listWidget->count(); i++) {
if (listWidget->item(i)->data(Qt::UserRole).toInt() == m_pageSize) {
index = i;
break;
@@ -540,8 +558,7 @@ void DrawingView::printPreview()
printer.setPageOrientation(m_orientation);
QPrintPreviewDialog dlg(&printer, this);
connect(&dlg, SIGNAL(paintRequested (QPrinter *)),
this, SLOT(print(QPrinter *)));
connect(&dlg, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
dlg.exec();
}
@@ -570,35 +587,46 @@ void DrawingView::print(QPrinter* printer)
bool doPrint = paintType != QPaintEngine::Picture;
if (doPrint && printer->pageLayout().orientation() != this->m_orientation) {
int ret = QMessageBox::warning(this, tr("Different orientation"),
int ret = QMessageBox::warning(
this,
tr("Different orientation"),
tr("The printer uses a different orientation than the drawing.\n"
"Do you want to continue?"),
QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes)
QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes) {
return;
}
}
else if (doPrint && realPaperSize != this->m_pageSize) {
int ret = QMessageBox::warning(this, tr("Different paper size"),
int ret = QMessageBox::warning(
this,
tr("Different paper size"),
tr("The printer uses a different paper size than the drawing.\n"
"Do you want to continue?"),
QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes)
QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes) {
return;
}
}
else if (doPrint && curPaperSize != this->m_pageSize) {
int ret = QMessageBox::warning(this, tr("Different paper size"),
int ret = QMessageBox::warning(
this,
tr("Different paper size"),
tr("The printer uses a different paper size than the drawing.\n"
"Do you want to continue?"),
QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes)
QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes) {
return;
}
}
}
QPainter p(printer);
if (!p.isActive() && !printer->outputFileName().isEmpty()) {
qApp->setOverrideCursor(Qt::ArrowCursor);
QMessageBox::critical(this, tr("Opening file failed"),
QMessageBox::critical(
this,
tr("Opening file failed"),
tr("Can't open file '%1' for writing.").arg(printer->outputFileName()));
qApp->restoreOverrideCursor();
return;
@@ -607,8 +635,9 @@ void DrawingView::print(QPrinter* printer)
#ifdef Q_OS_WIN32
// On Windows the preview looks broken when using paperRect as render area.
// Although the picture is scaled when using pageRect, it looks just fine.
if (paintType == QPaintEngine::Picture)
if (paintType == QPaintEngine::Picture) {
rect = printer->pageLayout().paintRectPixels(printer->resolution());
}
#endif
this->m_view->scene()->render(&p, rect);
p.end();
@@ -617,48 +646,45 @@ void DrawingView::print(QPrinter* printer)
QPageSize::PageSizeId DrawingView::getPageSize(int w, int h) const
{
static const float paperSizes[][2] = {
{210, 297}, // A4
{176, 250}, // B5
{215.9f, 279.4f}, // Letter
{215.9f, 355.6f}, // Legal
{190.5f, 254}, // Executive
{841, 1189}, // A0
{594, 841}, // A1
{420, 594}, // A2
{297, 420}, // A3
{148, 210}, // A5
{105, 148}, // A6
{74, 105}, // A7
{52, 74}, // A8
{37, 52}, // A8
{1000, 1414}, // B0
{707, 1000}, // B1
{31, 44}, // B10
{500, 707}, // B2
{353, 500}, // B3
{250, 353}, // B4
{125, 176}, // B6
{88, 125}, // B7
{62, 88}, // B8
{33, 62}, // B9
{163, 229}, // C5E
{105, 241}, // US Common
{110, 220}, // DLE
{210, 330}, // Folio
{431.8f, 279.4f}, // Ledger
{210, 297}, // A4
{176, 250}, // B5
{215.9f, 279.4f},// Letter
{215.9f, 355.6f},// Legal
{190.5f, 254}, // Executive
{841, 1189}, // A0
{594, 841}, // A1
{420, 594}, // A2
{297, 420}, // A3
{148, 210}, // A5
{105, 148}, // A6
{74, 105}, // A7
{52, 74}, // A8
{37, 52}, // A8
{1000, 1414}, // B0
{707, 1000}, // B1
{31, 44}, // B10
{500, 707}, // B2
{353, 500}, // B3
{250, 353}, // B4
{125, 176}, // B6
{88, 125}, // B7
{62, 88}, // B8
{33, 62}, // B9
{163, 229}, // C5E
{105, 241}, // US Common
{110, 220}, // DLE
{210, 330}, // Folio
{431.8f, 279.4f},// Ledger
{279.4f, 431.8f} // Tabloid
};
QPageSize::PageSizeId ps = QPageSize::Custom;
for (int i=0; i<30; i++) {
if (std::abs(paperSizes[i][0]-w) <= 1 &&
std::abs(paperSizes[i][1]-h) <= 1) {
for (int i = 0; i < 30; i++) {
if (std::abs(paperSizes[i][0] - w) <= 1 && std::abs(paperSizes[i][1] - h) <= 1) {
ps = static_cast<QPageSize::PageSizeId>(i);
break;
}
else
if (std::abs(paperSizes[i][0]-h) <= 1 &&
std::abs(paperSizes[i][1]-w) <= 1) {
else if (std::abs(paperSizes[i][0] - h) <= 1 && std::abs(paperSizes[i][1] - w) <= 1) {
ps = static_cast<QPageSize::PageSizeId>(i);
break;