diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 65a2e9d369772c54aba197639efbd99566d1c186..b4efe2df8d3c62d8a571c2f5ea9cc34567138f65 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -62,6 +62,7 @@ SET(CampvisApplicationToBeMocced gui/properties/propertycollectionwidget.h gui/properties/simpletransferfunctioneditor.h gui/properties/stringpropertywidget.h + gui/properties/statuspropertywidget.h gui/properties/transferfunctionpropertywidget.h tools/qtexteditlog.h tools/bufferinglog.h diff --git a/application/gui/properties/abstractpropertywidget.cpp b/application/gui/properties/abstractpropertywidget.cpp index 1726826e7bfb38980e4e2359b1321b67cb72be57..6d7488853a52ec0b53873c300095acc64447936d 100644 --- a/application/gui/properties/abstractpropertywidget.cpp +++ b/application/gui/properties/abstractpropertywidget.cpp @@ -67,8 +67,8 @@ namespace campvis { _property->s_changed.disconnect(this); } - void AbstractPropertyWidget::addWidget(QWidget* widget) { - _layout->addWidget(widget, 1); + void AbstractPropertyWidget::addWidget(QWidget* widget, int stretch) { + _layout->addWidget(widget, stretch); } void AbstractPropertyWidget::onPropertyChanged(const AbstractProperty* property) { diff --git a/application/gui/properties/abstractpropertywidget.h b/application/gui/properties/abstractpropertywidget.h index c554b23fd737f0982898c2e9cf1dae2681772d5c..815775b1c44045dad8688a05eeb4140ac8abb5ae 100644 --- a/application/gui/properties/abstractpropertywidget.h +++ b/application/gui/properties/abstractpropertywidget.h @@ -63,7 +63,7 @@ namespace campvis { /** * Adds a widget to the local Qt layout. */ - void addWidget(QWidget* widget); + void addWidget(QWidget* widget, int stretch = 1); AbstractProperty* _property; ///< The property this widget handles DataContainer* _dataContainer; ///< DataContainer to use (e.g. to populate GUI), may be 0! diff --git a/application/gui/properties/statuspropertywidget.cpp b/application/gui/properties/statuspropertywidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9708983a65087367d630a61ac897c4944f0a47bb --- /dev/null +++ b/application/gui/properties/statuspropertywidget.cpp @@ -0,0 +1,73 @@ +// ================================================================================================ +// +// This file is part of the CAMPVis Software Framework. +// +// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved, +// Christian Schulte zu Berge +// Chair for Computer Aided Medical Procedures +// Technische Universitaet Muenchen +// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany +// +// For a full list of authors and contributors, please refer to the file "AUTHORS.txt". +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the +// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +// either express or implied. See the License for the specific language governing permissions +// and limitations under the License. +// +// ================================================================================================ + +#include "statuspropertywidget.h" + +#include + +namespace campvis { + const char * StatusPropertyWidget::baseStyle = "text-align: center; padding: 1px; font-weight: bold;"; + + StatusPropertyWidget::StatusPropertyWidget(StatusProperty * property, DataContainer* dataContainer /*= nullptr*/, QWidget* parent /*= 0*/) + : AbstractPropertyWidget(property, false, dataContainer, parent) + { + _statusLabel = new QLabel(this); + _statusLabel->setText(QString::fromStdString(property->getValue().string)); + _statusLabel->setStyleSheet(getStyleFromStatusType(property->getValue().status)); + _statusLabel->setMinimumWidth(100); + _statusLabel->setMaximumWidth(100); + _statusLabel->setAlignment(Qt::AlignCenter); + + addWidget(new QWidget(this), 1); //spacer item to force right-alignment + addWidget(_statusLabel, 0); + //_statusLabel->setStyleSheet(); + } + + StatusPropertyWidget::~StatusPropertyWidget() { + + } + + void StatusPropertyWidget::updateWidgetFromProperty() { + StatusProperty * prop = static_cast(_property); + QString qs = QString::fromStdString(prop->getValue().string); + _statusLabel->setText(qs); + _statusLabel->setStyleSheet(getStyleFromStatusType(prop->getValue().status)); + } + + QString StatusPropertyWidget::getStyleFromStatusType(Status::StatusType type) const { + switch (type) { + case Status::UNKNOWN: + return QString("color: black; background-color: grey; border: 1px solid black;") + baseStyle; + case Status::OK: + return QString("color: black; background-color: green; border: 1px solid darkgreen;") + baseStyle; + case Status::WARNING: + return QString("color: black; background-color: orange; border: 1px solid darkorange;") + baseStyle; + case Status::CRITICAL: + return QString("color: black; background-color: red; border: 1px solid darkred; text-align: center; padding: 2px;") + baseStyle; + default: + return QString("color: black; background-color: white; border: 1px solid grey;") + baseStyle; + } + }; + +} \ No newline at end of file diff --git a/application/gui/properties/statuspropertywidget.h b/application/gui/properties/statuspropertywidget.h new file mode 100644 index 0000000000000000000000000000000000000000..6b5031f7941c3990abfd2bdadc5523cb9f1bda95 --- /dev/null +++ b/application/gui/properties/statuspropertywidget.h @@ -0,0 +1,71 @@ +// ================================================================================================ +// +// This file is part of the CAMPVis Software Framework. +// +// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved, +// Christian Schulte zu Berge +// Chair for Computer Aided Medical Procedures +// Technische Universitaet Muenchen +// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany +// +// For a full list of authors and contributors, please refer to the file "AUTHORS.txt". +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the +// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +// either express or implied. See the License for the specific language governing permissions +// and limitations under the License. +// +// ================================================================================================ + +#ifndef STATUSPROPERTYWIDGET_H__ +#define STATUSPROPERTYWIDGET_H__ + +#include "application/gui/properties/abstractpropertywidget.h" +#include "application/gui/properties/propertywidgetfactory.h" +#include "core/properties/statusproperty.h" + +namespace campvis { + /** + * Widget for a StringProperty + */ + class StatusPropertyWidget : public AbstractPropertyWidget { + Q_OBJECT; + + public: + /** + * Creates a new PropertyWidget for the property \a property. + * \param property The property the widget shall handle + * \param dataContainer DataContainer to use (optional), defaults to nullptr. + * \param parent Parent Qt widget + */ + StatusPropertyWidget(StatusProperty * property, DataContainer* dataContainer = nullptr, QWidget* parent = 0); + + /** + * Destructor + */ + virtual ~StatusPropertyWidget(); + + protected: + /** + * Gets called when the property has changed, so that widget can update its state. + */ + virtual void updateWidgetFromProperty(); + + private: + static const char* baseStyle; + + QString getStyleFromStatusType(Status::StatusType type) const; + + QLabel * _statusLabel; + + }; + + // explicitly instantiate template, so that it gets registered also over DLL boundaries. + template class PropertyWidgetRegistrar; +} +#endif // STATUSPROPERTYWIDGET_H__ diff --git a/core/properties/allproperties.h b/core/properties/allproperties.h index 9456e299c9dfe38cdbb293d4a263addf36c28dcc..382c4c09463d6d0e931b6bc88d96e630340275ee 100644 --- a/core/properties/allproperties.h +++ b/core/properties/allproperties.h @@ -34,5 +34,6 @@ #include "core/properties/optionproperty.h" #include "core/properties/stringproperty.h" #include "core/properties/transferfunctionproperty.h" +#include "core/properties/statusproperty.h" #endif // ALLPROPERTIES_H__ \ No newline at end of file diff --git a/core/properties/statusproperty.cpp b/core/properties/statusproperty.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3150b7e1dda0c30800903ed3f2588a65544fe988 --- /dev/null +++ b/core/properties/statusproperty.cpp @@ -0,0 +1,39 @@ +// ================================================================================================ +// +// This file is part of the CAMPVis Software Framework. +// +// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved, +// Christian Schulte zu Berge +// Chair for Computer Aided Medical Procedures +// Technische Universitaet Muenchen +// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany +// +// For a full list of authors and contributors, please refer to the file "AUTHORS.txt". +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the +// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +// either express or implied. See the License for the specific language governing permissions +// and limitations under the License. +// +// ================================================================================================ + +#include "statusproperty.h" + +namespace campvis { + + + const std::string StatusProperty::loggerCat_ = "CAMPVis.core.datastructures.StatusProperty"; + + StatusProperty::StatusProperty(const std::string& name, const std::string& title, const Status & value) + : GenericProperty(name, title, value) + { + } + + StatusProperty::~StatusProperty() { + } +} diff --git a/core/properties/statusproperty.h b/core/properties/statusproperty.h new file mode 100644 index 0000000000000000000000000000000000000000..e3d8341405a01b969f21dd6a788308ec82db76ef --- /dev/null +++ b/core/properties/statusproperty.h @@ -0,0 +1,95 @@ +// ================================================================================================ +// +// This file is part of the CAMPVis Software Framework. +// +// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved, +// Christian Schulte zu Berge +// Chair for Computer Aided Medical Procedures +// Technische Universitaet Muenchen +// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany +// +// For a full list of authors and contributors, please refer to the file "AUTHORS.txt". +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the +// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +// either express or implied. See the License for the specific language governing permissions +// and limitations under the License. +// +// ================================================================================================ + +#ifndef STATUSPROPERTY_H__ +#define STATUSPROPERTY_H__ + +#include "core/properties/genericproperty.h" +#include +#include + +namespace campvis { + + // simple class to store status as a combination of string and type + struct Status { + public: + /// Enumeration of the possible status types + enum StatusType { + UNKNOWN, + OK, + WARNING, + CRITICAL + }; + + + Status(std::string string_arg, StatusType status_arg) + : string(string_arg) + , status(status_arg) + {}; + + + bool operator==(const Status & rhs) { + return status == rhs.status && string == rhs.string; + }; + + bool operator!=(const Status &rhs) { + return status != rhs.status || string != rhs.string; + }; + + std::string string; + StatusType status; + }; + + class CAMPVIS_CORE_API StatusProperty : public GenericProperty { + public: + + + /** + * Creates a new StatusProperty + * \param name Property name (unchangable!) + * \param title Property title (e.g. used for GUI) + * \param value Initial value + */ + StatusProperty(const std::string& name, const std::string& title, const Status & value = Status(std::string(""), Status::UNKNOWN)); + + /** + * Virtual Destructor + **/ + virtual ~StatusProperty(); + + // convenience setter + void setStatus(std::string str, Status::StatusType status) + { + setValue(Status(str, status)); + }; + + + protected: + + static const std::string loggerCat_; + }; + +} + +#endif // STATUSPROPERTY_H__