<commit_before>// File:      QtxToolBar.cxx
// Author:    <NAME>

#include "QtxToolBar.h"

#include <qlayout.h>
#include <qpixmap.h>
#include <qdockarea.h>
#include <qobjectlist.h>
#include <qmainwindow.h>
#include <qapplication.h>

/*!
    Class: QtxToolBar::Watcher [Internal]
    Descr: Internal object with event filter.
*/

class QtxToolBar::Watcher : public QObject
{
public:
  Watcher( QtxToolBar* );

  void         shown( QtxToolBar* );
  void         hided( QtxToolBar* );

  virtual bool eventFilter( QObject*, QEvent* );

protected:
  virtual void customEvent( QCustomEvent* );

private:
  enum { Install = QEvent::User, Update };

private:
  void         installFilters();

  void         showContainer();
  void         hideContainer();

  void         updateIcon();
  void         updateCaption();
  void         updateVisibility();

private:
  QtxToolBar*  myCont;
  bool         myState;
  bool         myEmpty;
  bool         myVisible;
};

QtxToolBar::Watcher::Watcher( QtxToolBar* cont )
: QObject( cont ),
myCont( cont ),
myState( true ),
myEmpty( true )
{
  if ( myCont->mainWindow() )
    myState = myCont->mainWindow()->appropriate( myCont );

  myCont->installEventFilter( this );
  myVisible = myCont->isVisibleTo( myCont->parentWidget() );

  installFilters();
}

bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e )
{
  if ( o == myCont && e->type() == QEvent::ChildInserted )
    QApplication::postEvent( this, new QCustomEvent( Install ) );

  if ( o != myCont && e->type() == QEvent::IconChange )
    updateIcon();

  if ( o != myCont && e->type() == QEvent::CaptionChange )
    updateCaption();

  bool updVis = ( o != myCont && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
                                   e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) ||
                ( o == myCont && e->type() == QEvent::ChildRemoved );

  if ( updVis )
  {
    QtxToolBar* cont = myCont;
    myCont = 0;
    QApplication::sendPostedEvents( this, Update );
    myCont = cont;
    QApplication::postEvent( this, new QCustomEvent( Update ) );<commit_msg>Don't allow to empty toolbar will be shown<commit_after>// File:      QtxToolBar.cxx
// Author:    <NAME>

#include "QtxToolBar.h"

#include <qlayout.h>
#include <qpixmap.h>
#include <qdockarea.h>
#include <qobjectlist.h>
#include <qmainwindow.h>
#include <qapplication.h>

/*!
    Class: QtxToolBar::Watcher [Internal]
    Descr: Internal object with event filter.
*/

class QtxToolBar::Watcher : public QObject
{
public:
  Watcher( QtxToolBar* );

  void         shown( QtxToolBar* );
  void         hided( QtxToolBar* );

  virtual bool eventFilter( QObject*, QEvent* );

protected:
  virtual void customEvent( QCustomEvent* );

private:
  enum { Install = QEvent::User, Update };

private:
  void         installFilters();

  void         showContainer();
  void         hideContainer();

  void         updateIcon();
  void         updateCaption();
  void         updateVisibility();

private:
  QtxToolBar*  myCont;
  bool         myState;
  bool         myEmpty;
  bool         myVisible;
};

QtxToolBar::Watcher::Watcher( QtxToolBar* cont )
: QObject( cont ),
myCont( cont ),
myState( true ),
myEmpty( true )
{
  if ( myCont->mainWindow() )
    myState = myCont->mainWindow()->appropriate( myCont );

  myCont->installEventFilter( this );
  myVisible = myCont->isVisibleTo( myCont->parentWidget() );

  installFilters();
}

bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e )
{
  if ( o == myCont && e->type() == QEvent::ChildInserted )
    QApplication::postEvent( this, new QCustomEvent( Install ) );

  if ( o != myCont && e->type() == QEvent::IconChange )
    updateIcon();

  if ( o != myCont && e->type() == QEvent::CaptionChange )
    updateCaption();

  bool updVis = ( o != myCont && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
                                   e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) ||
                ( o == myCont && ( e->type() == QEvent::ChildRemoved || e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) );

  if ( updVis )
  {
    QtxToolBar* cont = myCont;
    myCont = 0;
    QApplication::sendPostedEvents( this, Update );
    myCont = cont;
    QApplication::postEvent( this, new QCustomEvent( Update ) );
{'fraction_non_alphanumeric': 0.1540050493458802, 'fraction_numerical': 0.0004590314436538903, 'mean_word_length': 3.035185185185185, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5487660', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1420, 'n_words': 333}