#include "QtxWorkstack.h"
#include <qstyle.h>
+#include <qaction.h>
#include <qlayout.h>
#include <qpixmap.h>
#include <qiconset.h>
myWin( 0 ),
myArea( 0 )
{
+ myActionsMap.insert( SplitVertical, new QAction( tr( "Split vertically" ), 0, this ));
+ myActionsMap.insert( SplitHorizontal, new QAction( tr( "Split horizontally" ), 0, this ));
+ myActionsMap.insert( Close, new QAction( tr( "Close" ), 0, this ));
+
+ connect( myActionsMap[SplitVertical], SIGNAL( activated() ), this, SLOT( splitVertical() ) );
+ connect( myActionsMap[SplitHorizontal], SIGNAL( activated() ), this, SLOT( splitHorizontal() ) );
+ connect( myActionsMap[Close], SIGNAL( activated() ), this, SLOT( onCloseWindow() ) );
+
QVBoxLayout* base = new QVBoxLayout( this );
mySplit = new QSplitter( this );
mySplit->setChildrenCollapsible( false );
}
}
+
+void QtxWorkstack::setAccel( const int id, const int accel )
+{
+ if (!myActionsMap.contains(id))
+ return;
+ myActionsMap[id]->setAccel(accel);
+}
+
+int QtxWorkstack::accel (const int id) const
+{
+ if (!myActionsMap.contains(id))
+ return 0;
+ return myActionsMap[id]->accel();
+}
+
static int positionSimple (QIntList& szList, const int nb, const int splitter_size,
const int item_ind, const int item_rel_pos,
const int need_pos, const int splitter_pos)
split( Qt::Horizontal );
}
+void QtxWorkstack::onCloseWindow()
+{
+ if ( activeWindow() )
+ activeWindow()->close();
+}
+
QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area )
{
if ( !area )
itr.current()->reparent( pWid, QPoint( 0, 0 ), map.contains( itr.current() ) ? map[itr.current()] : false );
}
-void QtxWorkstack::onPopupActivated( int id )
-{
- switch ( id )
- {
- case SplitVertical:
- splitVertical();
- break;
- case SplitHorizontal:
- splitHorizontal();
- break;
- case Close:
- if ( activeWindow() )
- activeWindow()->close();
- break;
- }
-}
-
void QtxWorkstack::onDestroyed( QObject* obj )
{
QtxWorkstackArea* area = (QtxWorkstackArea*)obj;
return;
QPopupMenu* pm = new QPopupMenu();
- connect( pm, SIGNAL( activated( int ) ), this, SLOT( onPopupActivated( int ) ) );
-
+
if ( lst.count() > 1 )
{
- pm->insertItem( tr( "Split vertically" ), SplitVertical );
- pm->insertItem( tr( "Split horizontally" ), SplitHorizontal );
+ myActionsMap[SplitVertical]->addTo( pm );
+ myActionsMap[SplitHorizontal]->addTo( pm );
pm->insertSeparator();
}
- pm->insertItem( tr( "Close" ), Close );
-
+ myActionsMap[Close]->addTo( pm );
+
pm->exec( p );
delete pm;
#include <qtabbar.h>
#include <qwidgetlist.h>
+class QAction;
class QTabBar;
class QPainter;
class QSplitter;
class QTX_EXPORT QtxWorkstack : public QWidget
{
Q_OBJECT
-
- enum { SplitVertical, SplitHorizontal, Close };
-
+
public:
QtxWorkstack( QWidget* = 0 );
void split( const int );
+ enum { SplitVertical, SplitHorizontal, Close };
+
// begin: jfa 06.07.2005
enum SplitType {
SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one
void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
// end: jfa 06.07.2005
+ /*!
+ * \brief Sets the action's accelerator key to accel.
+ * \param id - the key of the action in the actions map.
+ * \param accel - action's accelerator key.
+ */
+ void setAccel( const int id, const int accel );
+
+ /*!
+ * \brief Returns the action's accelerator key.
+ * \param id - the key of the action in the actions map.
+ * \retval int - action's accelerator key.
+ */
+ int accel (const int id) const;
+
signals:
void windowActivated( QWidget* );
public slots:
void splitVertical();
void splitHorizontal();
-
+
private slots:
- void onPopupActivated( int );
void onDestroyed( QObject* );
void onWindowActivated( QWidget* );
void onContextMenuRequested( QPoint );
void onDeactivated( QtxWorkstackArea* );
+ /*!
+ * \brief Closes the active window.
+ */
+ void onCloseWindow();
protected:
virtual void childEvent( QChildEvent* );
QtxWorkstackArea* myArea;
QSplitter* mySplit;
+ QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
+
friend class QtxWorkstackArea;
friend class QtxWorkstackDrag;
};
int myTab;
QtxWorkstackArea* myArea;
QPainter* myPainter;
+
};
#endif