17 #include <QMouseEvent>
18 #include <QPixmapCache>
19 #include <QPainterPath>
26 m_arrowPressed( Qt::NoArrow ),
29 m_imagePath(
"marble/navigation/navigational_arrows" )
31 setMouseTracking(
true );
33 m_initialPressTimer.setSingleShot(
true );
34 connect( &m_initialPressTimer, SIGNAL(timeout()), SLOT(startPressRepeat()) );
35 connect( &m_repeatPressTimer, SIGNAL(timeout()), SLOT(repeatPress()) );
40 QPixmapCache::remove(
"marble/navigation/navigational_arrows" );
41 QPixmapCache::remove(
"marble/navigation/navigational_arrows_hover_bottom" );
42 QPixmapCache::remove(
"marble/navigation/navigational_arrows_hover_left" );
43 QPixmapCache::remove(
"marble/navigation/navigational_arrows_hover_right" );
44 QPixmapCache::remove(
"marble/navigation/navigational_arrows_hover_top" );
45 QPixmapCache::remove(
"marble/navigation/navigational_arrows_press_bottom" );
46 QPixmapCache::remove(
"marble/navigation/navigational_arrows_press_left" );
47 QPixmapCache::remove(
"marble/navigation/navigational_arrows_press_right" );
48 QPixmapCache::remove(
"marble/navigation/navigational_arrows_press_top" );
53 m_marbleWidget = marbleWidget;
59 if ( !QPixmapCache::find(
id, result ) ) {
60 result = QPixmap( QString(
":/%1.png" ).arg(
id ) );
61 QPixmapCache::insert(
id, result );
68 if ( mouseEvent->button() == Qt::LeftButton ) {
70 if ( !m_initialPressTimer.isActive() && !m_repeatPressTimer.isActive() ) {
72 m_initialPressTimer.start( 300 );
75 m_arrowPressed = arrowUnderMouse( mouseEvent->pos() );
76 switch ( m_arrowPressed ) {
78 m_imagePath =
"marble/navigation/navigational_arrows";
81 m_imagePath =
"marble/navigation/navigational_arrows_press_top";
85 m_imagePath =
"marble/navigation/navigational_arrows_press_bottom";
89 m_imagePath =
"marble/navigation/navigational_arrows_press_left";
93 m_imagePath =
"marble/navigation/navigational_arrows_press_right";
104 m_initialPressTimer.stop();
105 m_repeatPressTimer.stop();
111 if ( m_imagePath !=
"marble/navigation/navigational_arrows" ) {
112 m_imagePath =
"marble/navigation/navigational_arrows";
116 m_initialPressTimer.stop();
117 m_repeatPressTimer.stop();
120 void ArrowDiscWidget::startPressRepeat()
124 if ( m_arrowPressed != Qt::NoArrow ) {
125 m_repeatPressTimer.start( 100 );
129 void ArrowDiscWidget::repeatPress()
131 if ( m_repetitions <= 200 ) {
133 switch ( m_arrowPressed ) {
150 m_repeatPressTimer.stop();
156 QString
const oldPath = m_imagePath;
157 switch ( arrowUnderMouse( mouseEvent->pos() ) ) {
159 m_imagePath =
"marble/navigation/navigational_arrows";
162 m_imagePath =
"marble/navigation/navigational_arrows_hover_top";
163 m_arrowPressed = Qt::UpArrow;
166 m_imagePath =
"marble/navigation/navigational_arrows_hover_bottom";
167 m_arrowPressed = Qt::DownArrow;
170 m_imagePath =
"marble/navigation/navigational_arrows_hover_left";
171 m_arrowPressed = Qt::LeftArrow;
174 m_imagePath =
"marble/navigation/navigational_arrows_hover_right";
175 m_arrowPressed = Qt::RightArrow;
179 if ( m_imagePath != oldPath ) {
189 Qt::ArrowType ArrowDiscWidget::arrowUnderMouse(
const QPoint &position)
const
191 const int min_radius_pow2 = 5*5;
192 const int max_radius_pow2 = 28*28;
195 int mx = position.x();
196 int my = position.y();
205 int const distance_pow2 = px*px + py*py;
207 if ( distance_pow2 >= min_radius_pow2 && distance_pow2 <= max_radius_pow2 ) {
209 Q_ASSERT( -180 <= angle && angle <= 180 );
211 if ( angle >= 135 || angle < -135 ) {
212 return Qt::LeftArrow;
213 }
else if ( angle < -45 ) {
215 }
else if ( angle < 45 ) {
216 return Qt::RightArrow;
218 return Qt::DownArrow;
227 Q_ASSERT( !
pixmap( m_imagePath ).isNull() );
229 painter.drawPixmap( 0, 0,
pixmap( m_imagePath ) );
235 #include "ArrowDiscWidget.moc"
double angle(double vec1[3], double vec2[3])