From 85f2b3faf0a52d14f91c721d0c92d33fb9210f77 Mon Sep 17 00:00:00 2001 From: Ruben Manuel Thoms Date: Fri, 4 Sep 2020 14:33:33 +0200 Subject: [PATCH] Removed cafUiStyleSheet and all references to it. --- .../UserInterface/RiuMainWindowBase.h | 2 - .../UserInterface/RiuMultiPlotBook.cpp | 10 - .../UserInterface/RiuMultiPlotBook.h | 1 - .../UserInterface/RiuMultiPlotPage.cpp | 33 --- .../UserInterface/RiuMultiPlotPage.h | 3 - .../UserInterface/RiuQwtPlotWidget.cpp | 59 ---- .../UserInterface/RiuQwtPlotWidget.h | 10 - Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 2 - .../cafUserInterface/cafUiStyleSheet.cpp | 257 ------------------ Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.h | 100 ------- 10 files changed, 477 deletions(-) delete mode 100644 Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.cpp delete mode 100644 Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.h diff --git a/ApplicationCode/UserInterface/RiuMainWindowBase.h b/ApplicationCode/UserInterface/RiuMainWindowBase.h index 69d3e7933c..7100d15da8 100644 --- a/ApplicationCode/UserInterface/RiuMainWindowBase.h +++ b/ApplicationCode/UserInterface/RiuMainWindowBase.h @@ -18,8 +18,6 @@ #pragma once -#include "cafUiStyleSheet.h" - #include class QMdiArea; diff --git a/ApplicationCode/UserInterface/RiuMultiPlotBook.cpp b/ApplicationCode/UserInterface/RiuMultiPlotBook.cpp index 57265475ef..6df1004a5f 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotBook.cpp +++ b/ApplicationCode/UserInterface/RiuMultiPlotBook.cpp @@ -327,11 +327,6 @@ void RiuMultiPlotBook::scheduleReplotOfAllPlots() //-------------------------------------------------------------------------------------------------- void RiuMultiPlotBook::renderTo( QPaintDevice* paintDevice ) { - for ( auto page : m_pages ) - { - page->stashWidgetStates(); - } - int resolution = paintDevice->logicalDpiX(); double scaling = resolution / static_cast( RiaGuiApplication::applicationResolution() ); @@ -350,11 +345,6 @@ void RiuMultiPlotBook::renderTo( QPaintDevice* paintDevice ) page->renderTo( &painter, scaling ); firstPage = false; } - - for ( auto page : m_pages ) - { - page->restoreWidgetStates(); - } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuMultiPlotBook.h b/ApplicationCode/UserInterface/RiuMultiPlotBook.h index 7689353d62..e664f93b65 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotBook.h +++ b/ApplicationCode/UserInterface/RiuMultiPlotBook.h @@ -19,7 +19,6 @@ #include "RiuInterfaceToViewWindow.h" #include "RiuMultiPlotPage.h" -#include "cafUiStyleSheet.h" #include "cafPdmPointer.h" #include "cafSelectionChangedReceiver.h" diff --git a/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp b/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp index 988358cf0a..9f3a427d2b 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp +++ b/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp @@ -352,7 +352,6 @@ void RiuMultiPlotPage::renderTo( QPaintDevice* paintDevice ) //-------------------------------------------------------------------------------------------------- void RiuMultiPlotPage::renderTo( QPainter* painter, double scalingFactor ) { - stashWidgetStates(); painter->fillRect( painter->viewport(), Qt::white ); m_plotTitle->render( painter ); @@ -386,8 +385,6 @@ void RiuMultiPlotPage::renderTo( QPainter* painter, double scalingFactor ) plotWidget->renderTo( painter, plotWidgetGeometry, scalingFactor ); } - - restoreWidgetStates(); } //-------------------------------------------------------------------------------------------------- @@ -531,14 +528,6 @@ void RiuMultiPlotPage::onSelectionManagerSelectionChanged( const std::set& { isSelected = isSelected || caf::SelectionManager::instance()->isSelected( plot, changedLevel ); } - if ( isSelected ) - { - plotWidget->setWidgetState( "selected" ); - } - else - { - caf::UiStyleSheet::clearWidgetStates( plotWidget ); - } } } @@ -819,28 +808,6 @@ std::pair return std::make_pair( availableRow, availableColumn ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuMultiPlotPage::stashWidgetStates() -{ - for ( RiuQwtPlotWidget* plotWidget : m_plotWidgets ) - { - plotWidget->stashWidgetStates(); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuMultiPlotPage::restoreWidgetStates() -{ - for ( RiuQwtPlotWidget* plotWidget : m_plotWidgets ) - { - plotWidget->restoreWidgetStates(); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuMultiPlotPage.h b/ApplicationCode/UserInterface/RiuMultiPlotPage.h index 5f18690180..8c8992f13f 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotPage.h +++ b/ApplicationCode/UserInterface/RiuMultiPlotPage.h @@ -21,7 +21,6 @@ #include "cafPdmPointer.h" #include "cafSelectionChangedReceiver.h" -#include "cafUiStyleSheet.h" #include #include @@ -124,8 +123,6 @@ protected: std::pair findAvailableRowAndColumn( int startRow, int startColumn, int columnSpan, int columnCount ) const; - void stashWidgetStates(); - void restoreWidgetStates(); void applyLook(); private slots: virtual void performUpdate(); diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp index fd1e318418..d18804e938 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp @@ -546,31 +546,6 @@ void RiuQwtPlotWidget::scheduleReplot() RiaPlotWindowRedrawScheduler::instance()->schedulePlotWidgetReplot( this ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuQwtPlotWidget::stashWidgetStates() -{ - m_plotStyleSheet.stashWidgetStates(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuQwtPlotWidget::restoreWidgetStates() -{ - m_plotStyleSheet.restoreWidgetStates(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuQwtPlotWidget::setWidgetState( const QString& widgetState ) -{ - caf::UiStyleSheet::clearWidgetStates( this ); - m_plotStyleSheet.setWidgetState( this, widgetState ); -} - //-------------------------------------------------------------------------------------------------- /// Adds an overlay frame. The overlay frame becomes the responsibility of the plot widget //-------------------------------------------------------------------------------------------------- @@ -685,12 +660,6 @@ void RiuQwtPlotWidget::hideEvent( QHideEvent* event ) //-------------------------------------------------------------------------------------------------- void RiuQwtPlotWidget::showEvent( QShowEvent* event ) { - m_plotStyleSheet = createPlotStyleSheet(); - m_plotStyleSheet.applyToWidget( this ); - - m_canvasStyleSheet = createCanvasStyleSheet(); - m_canvasStyleSheet.applyToWidget( canvas() ); - QwtPlot::showEvent( event ); } @@ -878,34 +847,6 @@ void RiuQwtPlotWidget::recalculateAxisExtents( QwtPlot::Axis axis ) } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::UiStyleSheet RiuQwtPlotWidget::createPlotStyleSheet() const -{ - QColor backgroundColor = QColor( "white" ); - QColor highlightColor = QApplication::palette().highlight().color(); - - caf::UiStyleSheet styleSheet; - styleSheet.set( "background-color", backgroundColor.name() ); - styleSheet.set( "border", "1 px solid transparent" ); - - styleSheet.property( "selected" ).set( "border", QString( "1px solid %1" ).arg( highlightColor.name() ) ); - - return styleSheet; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::UiStyleSheet RiuQwtPlotWidget::createCanvasStyleSheet() const -{ - caf::UiStyleSheet styleSheet; - styleSheet.set( "background-color", "#FAFAFA" ); - styleSheet.set( "border", "1px solid LightGray" ); - return styleSheet; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h index 24118a2921..8cafc9cc7b 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h @@ -23,7 +23,6 @@ #include "cafPdmObject.h" #include "cafPdmPointer.h" -#include "cafUiStyleSheet.h" #include "qwt_plot.h" @@ -123,9 +122,6 @@ public: QPoint dragStartPosition() const; void scheduleReplot(); - void stashWidgetStates(); - void restoreWidgetStates(); - void setWidgetState( const QString& widgetState ); void addOverlayFrame( RiuDraggableOverlayFrame* overlayWidget ); void removeOverlayFrame( RiuDraggableOverlayFrame* overlayWidget ); @@ -176,9 +172,6 @@ private: void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection ); void recalculateAxisExtents( QwtPlot::Axis axis ); - caf::UiStyleSheet createPlotStyleSheet() const; - caf::UiStyleSheet createCanvasStyleSheet() const; - void updateOverlayFrameLayout(); private: @@ -203,8 +196,5 @@ private: std::map m_originalCurveColors; std::map m_originalZValues; - caf::UiStyleSheet m_plotStyleSheet; - caf::UiStyleSheet m_canvasStyleSheet; - friend class RiaPlotWindowRedrawScheduler; }; diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index aa45b9436c..57717fb092 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -166,8 +166,6 @@ set( PROJECT_FILES cafStyleSheetTools.cpp cafPdmUiTabbedPropertyViewDialog.h cafPdmUiTabbedPropertyViewDialog.cpp - cafUiStyleSheet.h - cafUiStyleSheet.cpp ) add_library( ${PROJECT_NAME} diff --git a/Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.cpp b/Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.cpp deleted file mode 100644 index b43ce73e00..0000000000 --- a/Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.cpp +++ /dev/null @@ -1,257 +0,0 @@ -//################################################################################################## -// -// Custom Visualization Core library -// Copyright (C) 2019- Ceetron Solutions AS -// -// This library may be used under the terms of either the GNU General Public License or -// the GNU Lesser General Public License as follows: -// -// GNU General Public License Usage -// This library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 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 General Public License at <> -// for more details. -// -// GNU Lesser General Public License Usage -// This library 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. -// -// 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 Lesser General Public License at <> -// for more details. -// -//################################################################################################## -#include "cafUiStyleSheet.h" - -#include -#include -#include -#include - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::UiStyleSheet::State::State( const QString& stateTag, Type type ) - : m_type( type ) -{ - if ( type == PseudoState ) - { - if ( !stateTag.isEmpty() ) - { - m_stateTag = ":" + stateTag; - } - } - else - { - m_stateTag = QString( "[%1=true]" ).arg( stateTag ); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::UiStyleSheet::State::Type caf::UiStyleSheet::State::type() const -{ - return m_type; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::State::set( const QString& key, const QString& value ) -{ - m_content[key] = value; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString caf::UiStyleSheet::State::get( const QString& key ) const -{ - auto it = m_content.find( key ); - if ( it != m_content.end() ) - { - return it->second; - } - return ""; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString caf::UiStyleSheet::State::fullText( const QString& className, - const QString& objectName, - bool applyToSubClasses /*= true*/ ) const -{ - QString classNameTag = applyToSubClasses ? className : QString( ".%1" ).arg( className ); - QString objectNameTag = !objectName.isEmpty() ? QString( "#%1" ).arg( objectName ) : ""; - - QStringList content; - for ( auto keyValuePair : m_content ) - { - content << QString( " %1: %2" ).arg( keyValuePair.first ).arg( keyValuePair.second ); - } - - QString format( "%1%2%3\n{\n%4}" ); - QString stateStyleSheet = - format.arg( classNameTag ).arg( objectNameTag ).arg( m_stateTag ).arg( content.join( ";\n" ) ); - return stateStyleSheet; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::UiStyleSheet::UiStyleSheet() -{ - // Add a default state (blank tag) - m_states.insert( std::make_pair( "", State( "", State::PseudoState ) ) ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::set( const QString& key, const QString& value ) -{ - pseudoState( "" ).set( key, value ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString caf::UiStyleSheet::get( const QString& key ) const -{ - auto it = m_states.find( "" ); - if ( it != m_states.end() ) - { - return it->second.get( key ); - } - return ""; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::UiStyleSheet::State& caf::UiStyleSheet::property( QString stateTag ) -{ - auto itBoolResult = m_states.insert( std::make_pair( stateTag, State( stateTag, State::PropertyState ) ) ); - return itBoolResult.first->second; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::UiStyleSheet::State& caf::UiStyleSheet::pseudoState( QString stateTag ) -{ - auto itBoolResult = m_states.insert( std::make_pair( stateTag, State( stateTag, State::PseudoState ) ) ); - return itBoolResult.first->second; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::applyToWidget( QWidget* widget, bool applyToSubClasses /*= true*/ ) const -{ - if ( widget->objectName().isEmpty() ) - { - // If widget has no object name we use the pointer as a name. - widget->setObjectName( QString( "%1" ).arg( reinterpret_cast( widget ) ) ); - } - QString completeStyleSheet = - fullText( QString( widget->metaObject()->className() ), widget->objectName(), applyToSubClasses ); - widget->setStyleSheet( completeStyleSheet ); - refreshWidget( widget ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::applyToWidgetAndChildren( QWidget* widget ) -{ - QString completeStyleSheet = fullText( "*", "", false ); - widget->setStyleSheet( completeStyleSheet ); - refreshWidget( widget ); -} - -//-------------------------------------------------------------------------------------------------- -/// Clear all existing properties -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::clearWidgetStates( QWidget* widget ) -{ - for ( QByteArray existingProperty : widget->dynamicPropertyNames() ) - { - widget->setProperty( existingProperty, QVariant() ); - } - refreshWidget( widget ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::setWidgetState( QWidget* widget, QString stateTag, bool on /*= true*/ ) const -{ - // Set current property state to true - if ( !stateTag.isEmpty() ) - { - auto it = m_states.find( stateTag ); - if ( it != m_states.end() && it->second.type() == State::PropertyState ) - { - widget->setProperty( stateTag.toLatin1(), QVariant( on ) ); - } - } - - // Trigger style update - refreshWidget( widget ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::stashWidgetStates() -{ - m_stashedStates.swap( m_states ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::restoreWidgetStates() -{ - if ( !m_stashedStates.empty() ) - { - m_stashedStates.swap( m_states ); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString caf::UiStyleSheet::fullText( const QString& className, const QString& objectName, bool applyToSubClasses ) const -{ - QStringList stateTexts; - for ( auto it = m_states.begin(); it != m_states.end(); ++it ) - { - stateTexts << it->second.fullText( className, objectName, applyToSubClasses ); - } - return stateTexts.join( "\n" ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::UiStyleSheet::refreshWidget( QWidget* widget ) -{ - widget->style()->unpolish( widget ); - widget->style()->polish( widget ); -} diff --git a/Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.h b/Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.h deleted file mode 100644 index 40ea9e4e72..0000000000 --- a/Fwk/AppFwk/cafUserInterface/cafUiStyleSheet.h +++ /dev/null @@ -1,100 +0,0 @@ -//################################################################################################## -// -// Custom Visualization Core library -// Copyright (C) 2019- Ceetron Solutions AS -// -// This library may be used under the terms of either the GNU General Public License or -// the GNU Lesser General Public License as follows: -// -// GNU General Public License Usage -// This library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 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 General Public License at <> -// for more details. -// -// GNU Lesser General Public License Usage -// This library 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. -// -// 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 Lesser General Public License at <> -// for more details. -// -//################################################################################################## -#pragma once - -#include -#include - -class QWidget; - -namespace caf -{ -//================================================================================================== -// Class used to apply stylesheets to Qt widgets without "bleeding" into other widgets -//================================================================================================== -class UiStyleSheet -{ -public: - class State - { - public: - enum Type - { - // Qt Pseudo-states applied automatically by Qt: https://doc.qt.io/qt-5/stylesheet-reference.html - PseudoState, - // State set by property syntax - PropertyState - }; - State( const QString& stateTag, Type type ); - Type type() const; - void set( const QString& key, const QString& value ); - QString get( const QString& key ) const; - - private: - friend class UiStyleSheet; - QString fullText( const QString& className, const QString& objectName, bool applyToSubClasses ) const; - - private: - Type m_type; - QString m_stateTag; - std::map m_content; - }; - -public: - UiStyleSheet(); - - void set( const QString& key, const QString& value ); - QString get( const QString& key ) const; - - State& property( QString stateTag ); - State& pseudoState( QString stateTag ); - - void applyToWidget( QWidget* widget, bool applyToSubClasses = true ) const; - void applyToWidgetAndChildren( QWidget* widget ); - static void clearWidgetStates( QWidget* widget ); - void setWidgetState( QWidget* widget, QString stateTag, bool on = true ) const; - void stashWidgetStates(); - void restoreWidgetStates(); - -private: - QString fullText( const QString& className, const QString& objectName, bool applyToSubClasses ) const; - static void refreshWidget( QWidget* widget ); - -private: - std::map m_states; - std::map m_stashedStates; -}; -} // namespace caf