//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+// File: QtxMultiAction.cxx
+// Author: Sergey TELKOV
+//
#include "QtxMultiAction.h"
#include <QApplication>
#include <QStyleOptionButton>
+/*!
+ \class QtxMultiAction::Filter
+ \brief Waches for the buttons in the popup menu
+ to update the tool buttons state.
+ \internal
+*/
+
+class QtxMultiAction::Filter : public QObject
+{
+public:
+ //! \brief Constructor
+ Filter( QObject* parent ) : QObject( parent ) {}
+ //! \brief Destructor
+ ~Filter() {}
+ //! \brief Process events from the child tool buttons
+ bool eventFilter( QObject* o, QEvent* e )
+ {
+ if ( e->type() == QEvent::Leave ) {
+ QToolButton* tb = qobject_cast<QToolButton*>( o );
+ if ( tb )
+ tb->setDown( false );
+ }
+ return QObject::eventFilter( o, e );
+ }
+};
+
+/*!
+ \class QtxMultiAction::Button
+ \brief Custom button to be used in the toolbar.
+ \internal
+*/
+
class QtxMultiAction::Button : public QToolButton
{
public:
+ //! \brief Constructor
Button( QWidget* parent = 0 ) : QToolButton( parent ) {}
+ //! \brief Destructor
~Button() {};
protected:
+ //! \brief Paint the button
virtual void paintEvent( QPaintEvent* e )
{
QToolButton::paintEvent( e );
};
/*!
- Constructor
+ \class QtxMultiAction
+ \brief The class QtxMultiAction implements modifiable action.
+
+ The QtxMultiAction class provides a possibility to assign a set of actions
+ (insertAction() function). The action can be used in the toolbar (and even
+ in the menu) to show drop-down menu with the list of the assigned actions.
+
+ Initially the first action from the list becomes current and it is activated
+ when the tool button is clicked by the user. If user presses and holds the mouse
+ button at the tool button, it shows the popup menu with all the assigned actions.
+ When the user selects any action from the popup menu, it becames current.
+*/
+
+/*!
+ \brief Constructor.
+ \param parent parent object
*/
QtxMultiAction::QtxMultiAction( QObject* parent )
: QtxActionSet( parent ),
-myCurrent( 0 )
+ myCurrent( 0 )
{
setVisible( true );
setMenu( new QMenu( 0 ) );
connect( this, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) );
}
+/*!
+ \brief Constructor.
+ \param txt action menu text
+ \param parent parent object
+*/
QtxMultiAction::QtxMultiAction( const QString& txt, QObject* parent )
: QtxActionSet( parent ),
-myCurrent( 0 )
+ myCurrent( 0 )
{
setText( txt );
setVisible( true );
connect( this, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) );
}
+/*!
+ \brief Constructor.
+ \param ico action menu icon
+ \param txt action menu text
+ \param parent parent object
+*/
QtxMultiAction::QtxMultiAction( const QIcon& ico, const QString& txt, QObject* parent )
: QtxActionSet( parent ),
-myCurrent( 0 )
+ myCurrent( 0 )
{
setIcon( ico );
setText( txt );
connect( this, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) );
}
+/*!
+ \brief Destructor
+*/
QtxMultiAction::~QtxMultiAction()
{
}
-void QtxMultiAction::onClicked( bool )
+/*!
+ \brief Called when the user activates the current action
+ (for example by clicking the tool button).
+ \param on (not used)
+*/
+void QtxMultiAction::onClicked( bool /*on*/ )
{
if ( myCurrent )
myCurrent->activate( QAction::Trigger );
}
+/*!
+ \brief Called when user activates any action from the
+ dropdown menu.
+ \param a action being activated
+*/
void QtxMultiAction::onTriggered( QAction* a )
{
if ( !a )
}
}
+/*!
+ \brief Update action.
+*/
void QtxMultiAction::updateAction()
{
QtxActionSet::updateAction();
updateButton( ::qobject_cast<QToolButton*>( *it ) );
}
+/*!
+ \brief Update child (popup menu) action.
+ \param w widget menu widget
+*/
void QtxMultiAction::updateAction( QWidget* w )
{
if ( !w )
}
}
+/*!
+ \brief Check if the action itself should be invisible
+ (only child action are shown)
+ \return \c true if the action itself should be visible
+*/
bool QtxMultiAction::isEmptyAction() const
{
return false;
}
+/*!
+ \brief Create widget to be displayed in the toolbar.
+ \param parent parent widget (should be toolbar)
+ \return toolbar button
+*/
QWidget* QtxMultiAction::createWidget( QWidget* parent )
{
QToolBar* tb = ::qobject_cast<QToolBar*>( parent );
return w;
}
+/*!
+ \brief Called when the child action is added to this action.
+ \param a child action being added
+*/
void QtxMultiAction::actionAdded( QAction* a )
{
if ( !myCurrent )
myCurrent = a;
}
+/*!
+ \brief Called when the child action is removed from this action.
+ \param a child action being removed
+*/
void QtxMultiAction::actionRemoved( QAction* a )
{
if ( myCurrent != a )
updateAction();
}
+/*!
+ \brief Update toolbar button.
+ \param btn toolbar button
+*/
void QtxMultiAction::updateButton( QToolButton* btn )
{
if ( !btn )
QVBoxLayout* vbox = new QVBoxLayout( pm );
vbox->setMargin( 1 );
vbox->setSpacing( 0 );
-
+ Filter* filter = new Filter( vbox );
QList<QAction*> actList = actions();
for ( QList<QAction*>::iterator itr = actList.begin(); itr != actList.end(); ++itr )
{
b->setIconSize( btn->iconSize() );
b->setToolButtonStyle( btn->toolButtonStyle() );
b->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
+ b->installEventFilter( filter );
vbox->addWidget( b );
}
-
-/*
- QList<QAction*> actList = actions();
- for ( QList<QAction*>::iterator itr = actList.begin(); itr != actList.end(); ++itr )
- pm->addAction( *itr );
-*/
}
\param msg progress message
\param progress current progress (for example, in %)
*/
- ProgressEvent( const QString& msg, const int progress = 0 )
+ ProgressEvent( const QString& msg, const int progress )
: QEvent( (QEvent::Type)id() ),
myMessage( msg ),
myProgress( progress )
The displayed message text includes constant info and status message. The constant info
is set by setConstantInfo() method and status message is set by setMessage().
+
+ Sometimes it is useful to splay an error message above the splash screen window.
+ For example, it can be necessary if an error occurs when loading the application.
+ Method setError() can be used to show the error message and set the error code which
+ can be then retrieved with the error() function.
*/
//! The only one instance of splash screen
\brief Send the status message and (optionally) current progress
to the splash screen.
- This function can be used, for example, from an external thread
- which checks the application loading progress.
+ If the second parameter is less than 0 (default) than it is ignored
+ and only the status message is changed. If you want to modify progress
+ also, pass positive value to the \a progress parameter explicitly.
\param msg progress status message
\param progress current progress
\param error error message
\param title message box title
\param code error code
+ \sa error()
*/
-void QtxSplash::error( const QString& error, const QString& title, const int code )
+void QtxSplash::setError( const QString& error, const QString& title, const int code )
{
if ( mySplash ) {
mySplash->setError( code );
If no error code has been set, 0 is returned.
\return last error code
+ \sa setError()
*/
int QtxSplash::error() const
{
if ( ce->type() == ProgressEvent::id() ) {
ProgressEvent* pe = (ProgressEvent*)ce;
pe->message().isEmpty() ? clear() : setMessage( pe->message() );
- setProgress( pe->progress() );
+ if ( pe->progress() >= 0 )
+ setProgress( pe->progress() );
QApplication::instance()->processEvents();
}
}