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:
Alfredo Monclus
2025-02-09 15:57:14 -03:00
committed by Chris Hennes
parent 3202dde7ca
commit da4f584a50
8 changed files with 271 additions and 345 deletions

View File

@@ -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