From: Viktor UZLOV Date: Thu, 19 Nov 2020 09:36:47 +0000 (+0300) Subject: Add TitleLabel. fix remove X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f3d829e62b6fbd39343081e876de6c2aca339746;p=modules%2Fgui.git Add TitleLabel. fix remove --- diff --git a/src/Qtx/QtxInfoPanel.cxx b/src/Qtx/QtxInfoPanel.cxx index e5d77db7d..43fde26a9 100644 --- a/src/Qtx/QtxInfoPanel.cxx +++ b/src/Qtx/QtxInfoPanel.cxx @@ -30,6 +30,9 @@ #include #include #include +#include +#include +#include #include #include @@ -56,6 +59,23 @@ private: QGroupBox* group; }; +class QtxInfoPanel::TitleLabel: public QLabel +{ +public: + TitleLabel(const QString &text, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : + QLabel(text, parent, f){ + this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + QString color_bg = this->palette().color(QPalette::Highlight).darker().name(); + QString color_fg = this->palette().color(QPalette::HighlightedText).name(); + this->setStyleSheet(QString("QLabel {{background:%1; color:%2;}}").arg(color_bg).arg(color_fg)); + this->setTextFormat(Qt::PlainText); + QFont font= QFont(); + font.setBold(true); + this->setFont(font); + this->setContentsMargins(2, 5, 2, 5); + } +}; + QtxInfoPanel::Container::Container( QWidget* parent ) : QWidget( parent ), group( 0 ) { @@ -154,9 +174,12 @@ QtxInfoPanel::QtxInfoPanel( QWidget* parent ) { container = new Container( this ); QVBoxLayout* layout = new QVBoxLayout(this); + title = new TitleLabel(""); layout->setMargin( 0 ); + layout->addWidget( title ); layout->addWidget( container ); layout->addStretch(); + title->setVisible(!title->text().isEmpty()); } QtxInfoPanel::~QtxInfoPanel() @@ -204,13 +227,24 @@ int QtxInfoPanel::addGroup( const QString& text, const int groupId ) return id; } +void QtxInfoPanel::setTitle( const QString& text ) +{ + title->setText(text); + title->setVisible(!title->text().isEmpty()); +} + void QtxInfoPanel::remove( const int id ) { QWidget* widget = find( id ); if ( widget ) { Container* group = dynamic_cast( widget->parentWidget() ); - if ( group ) + if ( !group ) + { + group = dynamic_cast( widget->parentWidget()->parentWidget() ); + group->remove( id ); + } + else group->remove( id ); } } diff --git a/src/Qtx/QtxInfoPanel.h b/src/Qtx/QtxInfoPanel.h index 5fcde4cef..3c725d33f 100644 --- a/src/Qtx/QtxInfoPanel.h +++ b/src/Qtx/QtxInfoPanel.h @@ -38,15 +38,17 @@ class QTX_EXPORT QtxInfoPanel : public QWidget Q_OBJECT class Container; + class TitleLabel; public: QtxInfoPanel( QWidget* = 0 ); ~QtxInfoPanel(); int addLabel( const QString&, const int = -1 ); - int addLabel( const QString&, Qt::Alignment = Qt::AlignLeft, const int = -1 ); + int addLabel( const QString&, Qt::Alignment, const int = -1 ); int addAction( QAction*, const int = -1 ); int addGroup( const QString&, const int = -1 ); + void setTitle( const QString& ); void remove( const int ); void clear( const int = -1 ); @@ -60,6 +62,7 @@ private: private: Container* container; + TitleLabel* title; }; #ifdef WIN32