| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/**************************************************************************** |
| 3 |
* * |
| 4 |
* Copyright (c) 2011 Jürgen Riegel <[email protected]> * |
| 5 |
* * |
| 6 |
* This file is part of FreeCAD. * |
| 7 |
* * |
| 8 |
* FreeCAD is free software: you can redistribute it and/or modify it * |
| 9 |
* under the terms of the GNU Lesser General Public License as * |
| 10 |
* published by the Free Software Foundation, either version 2.1 of the * |
| 11 |
* License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* FreeCAD is distributed in the hope that it will be useful, but * |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 16 |
* Lesser General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Lesser General Public * |
| 19 |
* License along with FreeCAD. If not, see * |
| 20 |
* <https://www.gnu.org/licenses/>. * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
#include <QAction> |
| 25 |
#include <QMenu> |
| 26 |
|
| 27 |
#include <Gui/Application.h> |
| 28 |
#include <Gui/BitmapFactory.h> |
| 29 |
#include <Gui/Command.h> |
| 30 |
#include <Gui/ViewProvider.h> |
| 31 |
|
| 32 |
#include "TaskSolverMessages.h" |
| 33 |
#include "ui_TaskSolverMessages.h" |
| 34 |
|
| 35 |
|
| 36 |
using namespace Gui; |
| 37 |
using namespace Gui::TaskView; |
| 38 |
namespace sp = std::placeholders; |
| 39 |
|
| 40 |
TaskSolverMessages::TaskSolverMessages(const QPixmap& icon, const QString& title) |
| 41 |
: TaskBox(icon, title, true, nullptr) |
| 42 |
, ui(new Ui_TaskSolverMessages) |
| 43 |
{ |
| 44 |
// we need a separate container widget to add all controls to |
| 45 |
auto* proxy = new QWidget(this); |
| 46 |
ui->setupUi(proxy); |
| 47 |
setupConnections(); |
| 48 |
|
| 49 |
this->groupLayout()->addWidget(proxy); |
| 50 |
|
| 51 |
ui->labelStatus->setOpenExternalLinks(false); |
| 52 |
|
| 53 |
// Set up the possible state values for the status label |
| 54 |
ui->labelStatus->setParameterGroup("User parameter:BaseApp/Preferences/Mod/Sketcher/General"); |
| 55 |
ui->labelStatus->registerState( |
| 56 |
QStringLiteral("empty"), |
| 57 |
palette().windowText().color(), |
| 58 |
std::string("EmptySketchMessageColor") |
| 59 |
); |
| 60 |
ui->labelStatus->registerState( |
| 61 |
QStringLiteral("under_constrained"), |
| 62 |
palette().windowText().color(), |
| 63 |
std::string("UnderconstrainedMessageColor") |
| 64 |
); |
| 65 |
ui->labelStatus->registerState( |
| 66 |
QStringLiteral("malformed_constraints"), |
| 67 |
QColor("red"), |
| 68 |
std::string("MalformedConstraintMessageColor") |
| 69 |
); |
| 70 |
ui->labelStatus->registerState( |
| 71 |
QStringLiteral("conflicting_constraints"), |
| 72 |
QColor("orangered"), |
| 73 |
std::string("ConflictingConstraintMessageColor") |
| 74 |
); |
| 75 |
ui->labelStatus->registerState( |
| 76 |
QStringLiteral("redundant_constraints"), |
| 77 |
QColor("red"), |
| 78 |
std::string("RedundantConstraintMessageColor") |
| 79 |
); |
| 80 |
ui->labelStatus->registerState( |
| 81 |
QStringLiteral("partially_redundant_constraints"), |
| 82 |
QColor("royalblue"), |
| 83 |
std::string("PartiallyRedundantConstraintMessageColor") |
| 84 |
); |
| 85 |
ui->labelStatus->registerState( |
| 86 |
QStringLiteral("solver_failed"), |
| 87 |
QColor("red"), |
| 88 |
std::string("SolverFailedMessageColor") |
| 89 |
); |
| 90 |
ui->labelStatus->registerState( |
| 91 |
QStringLiteral("fully_constrained"), |
| 92 |
QColor("green"), |
| 93 |
std::string("FullyConstrainedMessageColor") |
| 94 |
); |
| 95 |
|
| 96 |
ui->labelStatusLink->setLaunchExternal(false); |
| 97 |
|
| 98 |
createSettingsButtonActions(); |
| 99 |
} |
| 100 |
|
| 101 |
TaskSolverMessages::~TaskSolverMessages() = default; |
| 102 |
|
| 103 |
void TaskSolverMessages::setupConnections() |
| 104 |
{ |
| 105 |
connect( |
| 106 |
ui->labelStatusLink, |
| 107 |
&Gui::UrlLabel::linkClicked, |
| 108 |
this, |
| 109 |
&TaskSolverMessages::onLabelStatusLinkClicked |
| 110 |
); |
| 111 |
connect(ui->manualUpdate, &QToolButton::clicked, this, &TaskSolverMessages::onManualUpdateClicked); |
| 112 |
} |
| 113 |
|
| 114 |
void TaskSolverMessages::slotSetUp( |
| 115 |
const QString& state, |
| 116 |
const QString& msg, |
| 117 |
const QString& link, |
| 118 |
const QString& linkText |
| 119 |
) |
| 120 |
{ |
| 121 |
ui->labelStatus->setState(state); |
| 122 |
ui->labelStatus->setText(msg); |
| 123 |
ui->labelStatusLink->setUrl(link); |
| 124 |
ui->labelStatusLink->setText(linkText); |
| 125 |
updateToolTip(link); |
| 126 |
} |
| 127 |
|
| 128 |
void TaskSolverMessages::setLinkTooltip(const QString& tooltip) |
| 129 |
{ |
| 130 |
ui->labelStatusLink->setToolTip(tooltip); |
| 131 |
} |
| 132 |
|
| 133 |
QToolButton* TaskSolverMessages::getSettingsButton() |
| 134 |
{ |
| 135 |
return ui->settingsButton; |
| 136 |
} |
| 137 |
|
| 138 |
void TaskSolverMessages::onManualUpdateClicked(bool checked) |
| 139 |
{ |
| 140 |
Q_UNUSED(checked); |
| 141 |
Gui::Command::updateActive(); |
| 142 |
} |
| 143 |
|
| 144 |
void TaskSolverMessages::createSettingsButtonActions() |
| 145 |
{ |
| 146 |
ui->settingsButton->hide(); |
| 147 |
} |
| 148 |
|
| 149 |
#include "moc_TaskSolverMessages.cpp" |