#include <QMenu>
#include <list>
#include <display/QtViewer/QtMouseToolBar.qo.h>
#include <display/QtViewer/QtDisplayPanel.qo.h>
using namespace casacore;
namespace casa {
QtMouseToolButton::QtMouseToolButton( const std::string &type, QWidget *parent ) : QToolButton(parent), tool_(type) { }
void QtMouseToolButton::mousePressEvent( QMouseEvent *event ) {
Int btn = (event->button() == Qt::LeftButton)? 1 :
(event->button() == Qt::MidButton)? 2 :
(event->button() == Qt::RightButton)? 3 : 0;
if(btn!=0) emit mouseToolBtnPress(text().toStdString(), btn);
}
std::string QtMouseToolButton::getIconStr(Int button) const {
using namespace QtMouseToolNames;
char buf[128];
sprintf(buf,"%d",button);
std::string result = std::string(":/icons/") + std::string(iconName(tool_)) + std::string(buf) + std::string(".png");
return result;
}
QtPointToolButton::QtPointToolButton( QWidget *parent ) : QtMouseToolButton(QtMouseToolNames::POINT,parent),
rc(viewer::getrc( )), timer(new QTimer( )) {
connect( timer, SIGNAL(timeout( )), SLOT(popup_options_menu( )) );
}
void QtPointToolButton::popup_options_menu( ) {
timer->stop( );
show_context_menu(popup_menu_pos);
}
void QtPointToolButton::mousePressEvent( QMouseEvent *event ) {
popup_menu_pos = event->globalPos( );
timer->start( 750 );
QtMouseToolButton::mousePressEvent(event);
}
void QtPointToolButton::mouseReleaseEvent( QMouseEvent *event ) {
timer->stop( );
QtMouseToolButton::mouseReleaseEvent(event);
}
class PopupMenu : public QMenu {
public:
PopupMenu( ) : QMenu( ) { }
protected:
void leaveEvent(QEvent*);
};
void PopupMenu::leaveEvent( QEvent * ) {
QKeyEvent kev( QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier );
event(&kev);
}
void QtPointToolButton::show_context_menu( const QPoint &global_pos ) {