PD(hole taskpanel): apply review suggestions
* refactor: change to ternary op * refactor: apply recommendations to widgets * refactor: use QSignalBlocker * refactor: address some compiler complaints * refactor: add namespace Gui to new widgets
This commit is contained in:
committed by
Chris Hennes
parent
9e53b103a8
commit
8e676641b0
@@ -1,30 +1,35 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
// This custom widget adds the missing ellipsize functionality in QT5
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "ElideCheckBox.h"
|
||||
|
||||
const int CheckboxSpacing = 25;
|
||||
namespace Gui {
|
||||
|
||||
const int CheckboxSpacing = 18;
|
||||
|
||||
ElideCheckBox::ElideCheckBox(QWidget *parent)
|
||||
: QCheckBox(parent) {
|
||||
@@ -41,9 +46,9 @@ void ElideCheckBox::paintEvent(QPaintEvent *event) {
|
||||
style()->drawControl(QStyle::CE_CheckBox, &option, &painter, this);
|
||||
|
||||
QRect textRect = option.rect;
|
||||
int padding = 4;
|
||||
textRect.setX(textRect.x() + 25);
|
||||
textRect.setX(textRect.x() + CheckboxSpacing);
|
||||
|
||||
constexpr int padding = 4;
|
||||
QFontMetrics fm(font());
|
||||
QString elidedText = fm.elidedText(text(), Qt::ElideRight, textRect.width() - padding);
|
||||
|
||||
@@ -55,7 +60,7 @@ QSize ElideCheckBox::sizeHint() const {
|
||||
QFontMetrics fm(font());
|
||||
int width = fm.horizontalAdvance(this->text()) + CheckboxSpacing;
|
||||
int height = fm.height();
|
||||
return QSize(width, height);
|
||||
return {width, height};
|
||||
}
|
||||
|
||||
QSize ElideCheckBox::minimumSizeHint() const {
|
||||
@@ -63,6 +68,9 @@ QSize ElideCheckBox::minimumSizeHint() const {
|
||||
QString minimumText = QStringLiteral("A...");
|
||||
int width = fm.horizontalAdvance(minimumText) + CheckboxSpacing;
|
||||
int height = fm.height();
|
||||
return QSize(width, height);
|
||||
return {width, height};
|
||||
}
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#include "moc_ElideCheckBox.cpp" // NOLINT
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
// This custom widget adds the missing ellipsize functionality in QT5
|
||||
@@ -25,7 +26,6 @@
|
||||
#ifndef ELIDECHECKBOX_H
|
||||
#define ELIDECHECKBOX_H
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <QCheckBox>
|
||||
#include <QPainter>
|
||||
@@ -33,6 +33,9 @@
|
||||
#include <QStyleOptionButton>
|
||||
#endif
|
||||
|
||||
#include <FCGlobal.h>
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class GuiExport ElideCheckBox : public QCheckBox {
|
||||
Q_OBJECT
|
||||
@@ -47,5 +50,7 @@ protected:
|
||||
QSize minimumSizeHint() const override;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#endif // ELIDECHECKBOX_H
|
||||
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
// This custom widget adds the missing ellipsize functionality in QT5
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "ElideLabel.h"
|
||||
|
||||
namespace Gui {
|
||||
|
||||
ElideLabel::ElideLabel(QWidget *parent)
|
||||
: QLabel(parent) {
|
||||
}
|
||||
@@ -34,20 +39,25 @@ void ElideLabel::paintEvent(QPaintEvent *event) {
|
||||
painter.setPen(palette().color(QPalette::WindowText));
|
||||
painter.setFont(font());
|
||||
|
||||
QFontMetrics fm(font());
|
||||
QString text = this->text();
|
||||
int availableWidth = width() - 4; // Account for padding
|
||||
constexpr int padding = 4;
|
||||
QFontMetrics fm(painter.fontMetrics());
|
||||
|
||||
QString elidedText = fm.elidedText(text, Qt::ElideRight, availableWidth);
|
||||
int availableWidth = width() - padding * 2;
|
||||
if (availableWidth < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
painter.drawText(2, 2, availableWidth, height(), Qt::AlignLeft | Qt::AlignVCenter, elidedText);
|
||||
QString elidedText = fm.elidedText(text(), Qt::ElideRight, availableWidth);
|
||||
|
||||
QRect textRect = rect().adjusted(padding, 0, -padding, 0);
|
||||
painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, elidedText);
|
||||
}
|
||||
|
||||
QSize ElideLabel::sizeHint() const {
|
||||
QFontMetrics fm(font());
|
||||
int width = fm.horizontalAdvance(this->text());
|
||||
int height = fm.height();
|
||||
return QSize(width, height);
|
||||
return {width, height};
|
||||
}
|
||||
|
||||
QSize ElideLabel::minimumSizeHint() const {
|
||||
@@ -55,5 +65,9 @@ QSize ElideLabel::minimumSizeHint() const {
|
||||
QString minimumText = QStringLiteral("A...");
|
||||
int width = fm.horizontalAdvance(minimumText);
|
||||
int height = fm.height();
|
||||
return QSize(width, height);
|
||||
return {width, height};
|
||||
}
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#include "moc_ElideLabel.cpp" // NOLINT
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
// This custom widget adds the missing ellipsize functionality in QT5
|
||||
@@ -25,13 +26,15 @@
|
||||
#ifndef ELIDELABEL_H
|
||||
#define ELIDELABEL_H
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
#include <QFontMetrics>
|
||||
#endif
|
||||
|
||||
#include <FCGlobal.h>
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class GuiExport ElideLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
@@ -46,4 +49,6 @@ protected:
|
||||
QSize minimumSizeHint() const override;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#endif // ELIDELABEL_H
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
// This custom widget scales an svg according to fonts
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "FontScaledSVG.h"
|
||||
|
||||
namespace Gui {
|
||||
|
||||
FontScaledSVG::FontScaledSVG(QWidget *parent)
|
||||
: QWidget(parent), m_svgRenderer(new QSvgRenderer(this)) {
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
@@ -56,10 +61,13 @@ void FontScaledSVG::updateScaledSize() {
|
||||
|
||||
QFontMetrics metrics(font());
|
||||
qreal spacing = metrics.lineSpacing();
|
||||
int baseFactor = 18;
|
||||
constexpr int baseFactor = 18;
|
||||
qreal scalingFactor = spacing / baseFactor;
|
||||
|
||||
QSize targetSize = baseSize * scalingFactor;
|
||||
setFixedSize(targetSize);
|
||||
}
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#include "moc_FontScaledSVG.cpp" // NOLINT
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
|
||||
* Fifth Floor, Boston, MA 02110-1301, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
// This custom widget scales an svg according to fonts
|
||||
@@ -25,7 +26,6 @@
|
||||
#ifndef FONTSCALEDSVG_H
|
||||
#define FONTSCALEDSVG_H
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <QWidget>
|
||||
#include <QSvgRenderer>
|
||||
@@ -33,6 +33,10 @@
|
||||
#include <QFontMetrics>
|
||||
#endif
|
||||
|
||||
#include <FCGlobal.h>
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class GuiExport FontScaledSVG : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -50,4 +54,6 @@ private:
|
||||
void updateScaledSize();
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#endif // FONTSCALEDSVG_H
|
||||
|
||||
Reference in New Issue
Block a user