summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Price <[email protected]>2018-01-16 00:09:34 +0100
committerAlbert Astals Cid <[email protected]>2018-01-16 00:10:06 +0100
commitcb6d38cadfc1225e164f596ce73bef42222d35a8 (patch)
tree002a327ec373caa6e3b8f8fef453b02666a66a25
parentc1ad66a8f152f9f14f0ab0ea70d0384bbee7c886 (diff)
Added an option under the settings menu to enable a cursor under the mouse
BUGS: 363660 Contains some tweaks by Albert Astals Cid (whitespaces et al)
-rw-r--r--kbbgraphicsitemball.cpp2
-rw-r--r--kbbgraphicsitemblackbox.cpp17
-rw-r--r--kbbgraphicsitemblackbox.h15
-rw-r--r--kbbgraphicsitemcursor.h3
-rw-r--r--kbblevelconfigurationpreview.cpp2
-rw-r--r--kbbmainwindow.cpp9
-rw-r--r--kbbmainwindow.h2
-rw-r--r--kbbscalablegraphicwidget.cpp25
-rw-r--r--kbbscalablegraphicwidget.h4
-rw-r--r--kblackboxui.rc5
10 files changed, 71 insertions, 13 deletions
diff --git a/kbbgraphicsitemball.cpp b/kbbgraphicsitemball.cpp
index 26cf4ea..859cf29 100644
--- a/kbbgraphicsitemball.cpp
+++ b/kbbgraphicsitemball.cpp
@@ -135,6 +135,8 @@ void KBBGraphicsItemBall::hoverEnterEvent (QGraphicsSceneHoverEvent*)
connect(m_timer, &QTimer::timeout, this, &KBBGraphicsItemBall::showInteractions);
m_timer->start(TIME_TO_WAIT_BEFORE_SHOWING_INTERACTIONS);
}
+
+ m_widget->hoverMovePosition(position());
}
diff --git a/kbbgraphicsitemblackbox.cpp b/kbbgraphicsitemblackbox.cpp
index 8d63b3d..e860814 100644
--- a/kbbgraphicsitemblackbox.cpp
+++ b/kbbgraphicsitemblackbox.cpp
@@ -48,7 +48,7 @@
// Constructor / Destructor
//
-KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager) : QGraphicsRectItem (0)
+KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager, bool isPreview) : QGraphicsRectItem (0)
{
scene->addItem(this);
m_columns = 1;
@@ -64,6 +64,9 @@ KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphic
m_penLines.setColor(themeManager->color(g));
m_penLines.setStyle(themeManager->style(g));
m_penLines.setWidthF(themeManager->width(g));
+ //accept hover events unless the central widget is a preview (crashes the program)
+ if (!isPreview)
+ setAcceptHoverEvents(true);
}
@@ -131,3 +134,15 @@ void KBBGraphicsItemBlackBox::mousePressEvent (QGraphicsSceneMouseEvent* event)
if (m_widget!=0)
m_widget->mouseBoxClick(event->button(), x + y*m_columns);
}
+
+void KBBGraphicsItemBlackBox::hoverLeaveEvent(QGraphicsSceneHoverEvent*)
+{
+ m_widget->cursorOff();
+}
+
+void KBBGraphicsItemBlackBox::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
+{
+ int x = (int)(event->pos().x() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
+ int y = (int)(event->pos().y() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
+ emit hoverMoved(x + y*m_columns);
+}
diff --git a/kbbgraphicsitemblackbox.h b/kbbgraphicsitemblackbox.h
index 9dd9cfe..82dada7 100644
--- a/kbbgraphicsitemblackbox.h
+++ b/kbbgraphicsitemblackbox.h
@@ -43,19 +43,20 @@ class QGraphicsView;
class KBBGraphicsItem;
#include "kbbscalablegraphicwidget.h"
-
+#include <QObject>
/**
* @brief The black box in the scalable graphic widget
*/
-class KBBGraphicsItemBlackBox : public QGraphicsRectItem
+class KBBGraphicsItemBlackBox : public QObject, public QGraphicsRectItem
{
+Q_OBJECT
public:
/**
* @brief Constructor
*/
- KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager);
+ KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager, bool isPreview);
/**
@@ -73,7 +74,9 @@ class KBBGraphicsItemBlackBox : public QGraphicsRectItem
private:
void mousePressEvent (QGraphicsSceneMouseEvent* event) Q_DECL_OVERRIDE;
-
+ void hoverMoveEvent (QGraphicsSceneHoverEvent* event) Q_DECL_OVERRIDE;
+ void hoverLeaveEvent (QGraphicsSceneHoverEvent* event) Q_DECL_OVERRIDE;
+
KBBGraphicsItem* m_background;
int m_columns;
QList<QGraphicsLineItem*> m_lines;
@@ -82,6 +85,10 @@ class KBBGraphicsItemBlackBox : public QGraphicsRectItem
QGraphicsScene* m_scene;
KBBScalableGraphicWidget* m_widget;
int m_zValueLines;
+ public:
+ signals:
+ void hoverMoved(int);
+ void hoverExit();
};
#endif // KBBGRAPHICSITEMBLACKBOX_H
diff --git a/kbbgraphicsitemcursor.h b/kbbgraphicsitemcursor.h
index 8045ef0..0bf2407 100644
--- a/kbbgraphicsitemcursor.h
+++ b/kbbgraphicsitemcursor.h
@@ -67,14 +67,13 @@ class KBBGraphicsItemCursor : public KBBGraphicsItem
void setBoardSize(const int columns, const int rows);
void setBorderPosition(const int borderPosition);
void setBoxPosition(const int boxPosition);
-
+ void updatePositions();
signals:
void cursorAtNewPosition(const int borderPosition);
private:
- void updatePositions();
int m_boxPosition;
int m_borderPosition;
diff --git a/kbblevelconfigurationpreview.cpp b/kbblevelconfigurationpreview.cpp
index 165a19e..dffbe4e 100644
--- a/kbblevelconfigurationpreview.cpp
+++ b/kbblevelconfigurationpreview.cpp
@@ -31,7 +31,7 @@ KBBLevelConfigurationPreview::KBBLevelConfigurationPreview(QWidget *parent, KBBT
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(new QGraphicsScene(0, 0, 2*KBBScalableGraphicWidget::BORDER_SIZE, 2*KBBScalableGraphicWidget::BORDER_SIZE, this));
- m_blackbox = new KBBGraphicsItemBlackBox(this, scene(), themeManager);
+ m_blackbox = new KBBGraphicsItemBlackBox(this, scene(), themeManager, true);
m_themeManager = themeManager;
}
diff --git a/kbbmainwindow.cpp b/kbbmainwindow.cpp
index f436aba..5c32c34 100644
--- a/kbbmainwindow.cpp
+++ b/kbbmainwindow.cpp
@@ -124,7 +124,10 @@ KBBMainWindow::KBBMainWindow()
// Menu "Settings"
KStandardAction::preferences(this, SLOT(settingsDialog()), actionCollection());
-
+ QAction* cursor = actionCollection()->addAction( QLatin1String( "toggle_cursor" ));
+ cursor->setText(i18n("Enable cursor under mouse"));
+ cursor->setCheckable(true);
+ connect(cursor, &QAction::triggered, this, &KBBMainWindow::toggleCursor);
// Theme manager
QString svgzFile = KBBPrefs::theme();
@@ -473,6 +476,10 @@ void KBBMainWindow::startTutorial()
}
}
+void KBBMainWindow::toggleCursor()
+{
+ m_gameWidget->toggleCursor();
+}
//
diff --git a/kbbmainwindow.h b/kbbmainwindow.h
index 65e5348..e3e6720 100644
--- a/kbbmainwindow.h
+++ b/kbbmainwindow.h
@@ -72,7 +72,6 @@ class KBBMainWindow : public KXmlGuiWindow
*/
void updateStats();
-
private slots:
/**
* @brief Ends the current game
@@ -125,6 +124,7 @@ class KBBMainWindow : public KXmlGuiWindow
*/
void startTutorial();
+ void toggleCursor();
private:
/**
diff --git a/kbbscalablegraphicwidget.cpp b/kbbscalablegraphicwidget.cpp
index d40cd89..02534e4 100644
--- a/kbbscalablegraphicwidget.cpp
+++ b/kbbscalablegraphicwidget.cpp
@@ -73,7 +73,7 @@ KBBScalableGraphicWidget::KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBTheme
m_pause = false;
m_ballNumber = 0;
m_doneAction = done;
-
+ m_cursorFollowsMouse = false;
setFrameStyle(QFrame::NoFrame);
setCacheMode(QGraphicsView::CacheBackground);
@@ -82,7 +82,7 @@ KBBScalableGraphicWidget::KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBTheme
m_scene = new QGraphicsScene( 0, 0, 2*BORDER_SIZE, 2*BORDER_SIZE, this );
- m_blackbox = new KBBGraphicsItemBlackBox(this, m_scene, m_themeManager);
+ m_blackbox = new KBBGraphicsItemBlackBox(this, m_scene, m_themeManager, false);
m_blackbox->setKBBScalableGraphicWidget(this);
m_balls = new KBBGraphicsItemSet(m_scene);
m_cursor = new KBBGraphicsItemCursor(this, m_themeManager);
@@ -123,6 +123,7 @@ KBBScalableGraphicWidget::KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBTheme
// TODO: not displayed... :(
setWhatsThis(i18n("<qt><p>This is the <b>main game area</b>.</p><ul><li>The <b>black box</b> is in the center.</li><li>On the left, there are the <b>balls</b> you have to place over the black box.</li><li>Around the black box, there are <b>lasers</b> that are replaced with <b>interaction information</b> if you use them.</li></ul></qt>"));
+ connect(m_blackbox, &KBBGraphicsItemBlackBox::hoverMoved, this, &KBBScalableGraphicWidget::hoverMovePosition);
}
@@ -600,5 +601,25 @@ void KBBScalableGraphicWidget::useLaser(const int incomingPosition)
}
}
+void KBBScalableGraphicWidget::hoverMovePosition(int pos)
+{
+ if (m_cursorFollowsMouse)
+ {
+ m_cursor->show();
+ m_cursor->setBoxPosition(pos);
+ m_cursor->updatePositions();
+ }
+}
+
+void KBBScalableGraphicWidget::toggleCursor()
+{
+ m_cursorFollowsMouse = !m_cursorFollowsMouse;
+ if (m_cursorFollowsMouse == false){
+ m_cursor->hide();
+ }
+}
+void KBBScalableGraphicWidget::cursorOff() {
+ m_cursor->hide();
+}
diff --git a/kbbscalablegraphicwidget.h b/kbbscalablegraphicwidget.h
index d8e71ff..62864c9 100644
--- a/kbbscalablegraphicwidget.h
+++ b/kbbscalablegraphicwidget.h
@@ -162,8 +162,11 @@ class KBBScalableGraphicWidget : public QGraphicsView
*/
void solve(const bool continueGame);
+ void toggleCursor();
public slots:
+ void cursorOff();
+ void hoverMovePosition(int newPosition);
void cursorAtNewPosition(int borderPosition);
void keyboardEnter();
void keyboardMoveDown();
@@ -236,6 +239,7 @@ class KBBScalableGraphicWidget : public QGraphicsView
QGraphicsScene* m_scene; //TODO: Remove it because scene() already gives it back.
QLCDNumber* m_score;
KBBThemeManager* m_themeManager;
+ bool m_cursorFollowsMouse; //enable cursor following
};
#endif // KBBSCALABLEGRAPHICWIDGET_H
diff --git a/kblackboxui.rc b/kblackboxui.rc
index 1836968..3be8859 100644
--- a/kblackboxui.rc
+++ b/kblackboxui.rc
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gui name="kblackbox"
- version="14"
+ version="15"
xmlns="http://www.kde.org/standards/kxmlgui/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0
@@ -13,6 +13,9 @@
<Menu name="move">
<Action name="move_done" />
</Menu>
+ <Menu name="settings">
+ <Action name="toggle_cursor" />
+ </Menu>
</MenuBar>
<ToolBar name="mainToolBar">
<Action name="game_new" />